harbor-angular
Version:
Harbor shared components based on Clarity and Angular2s
125 lines (116 loc) • 4.71 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/http'), require('rxjs/add/operator/toPromise')) :
typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/common', '@angular/http', 'rxjs/add/operator/toPromise'], factory) :
(factory((global.harborangular = global.harborangular || {}),global.ng.core,global._angular_common,global._angular_http));
}(this, (function (exports,_angular_core,_angular_common,_angular_http) { 'use strict';
var SERVICE_CONFIG = new _angular_core.OpaqueToken("service.config");
var SystemInfoService = (function () {
function SystemInfoService(http, config) {
this.http = http;
this.config = config;
this.httpOptions = new _angular_http.RequestOptions({
headers: new _angular_http.Headers({
"Content-Type": 'application/json'
})
});
}
SystemInfoService.prototype.getSystemInfo = function () {
if (this.config.systemInfoEndpoint.trim() === "") {
return Promise.reject("500: Internal error");
}
return this.http.get(this.config.systemInfoEndpoint, this.httpOptions).toPromise()
.then(function (response) { return response.json(); })
.catch(function (error) { return console.error("Get systeminfo error: ", error); });
};
SystemInfoService.decorators = [
{ type: _angular_core.Injectable },
];
/** @nocollapse */
SystemInfoService.ctorParameters = function () { return [
{ type: _angular_http.Http, },
{ type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] },
]; };
return SystemInfoService;
}());
var SystemComponent = (function () {
function SystemComponent(systemService) {
this.systemService = systemService;
this._systemInfo = "Loading...";
}
Object.defineProperty(SystemComponent.prototype, "info", {
get: function () {
return this._systemInfo;
},
enumerable: true,
configurable: true
});
SystemComponent.prototype.ngOnInit = function () {
this.getInfo();
};
SystemComponent.prototype.getInfo = function () {
var _this = this;
this.systemService.getSystemInfo()
.then(function (res) { return _this._systemInfo = JSON.stringify(res); })
.catch(function (error) { return console.error("Retrieve system info error: ", error); });
};
SystemComponent.decorators = [
{ type: _angular_core.Component, args: [{
selector: 'hbr-system',
template: "\n <pre>\n {{info}}\n </pre>\n ",
styles: [],
providers: [SystemInfoService]
},] },
];
/** @nocollapse */
SystemComponent.ctorParameters = function () { return [
{ type: SystemInfoService, },
]; };
return SystemComponent;
}());
var SYSTEMINFO_DIRECTIVES = [
SystemComponent
];
var DefaultServiceConfig = {
systemInfoEndpoint: "/api/system"
};
var HarborLibraryModule = (function () {
function HarborLibraryModule() {
}
HarborLibraryModule.forRoot = function (config) {
if (config === void 0) { config = {}; }
return {
ngModule: HarborLibraryModule,
providers: [
config.config || { provide: SERVICE_CONFIG, useValue: DefaultServiceConfig }
]
};
};
HarborLibraryModule.forChild = function (config) {
if (config === void 0) { config = {}; }
return {
ngModule: HarborLibraryModule,
providers: [
config.config || { provide: SERVICE_CONFIG, useValue: DefaultServiceConfig }
]
};
};
HarborLibraryModule.decorators = [
{ type: _angular_core.NgModule, args: [{
imports: [
_angular_common.CommonModule
],
declarations: [SYSTEMINFO_DIRECTIVES],
exports: [SYSTEMINFO_DIRECTIVES]
},] },
];
/** @nocollapse */
HarborLibraryModule.ctorParameters = function () { return []; };
return HarborLibraryModule;
}());
exports.DefaultServiceConfig = DefaultServiceConfig;
exports.HarborLibraryModule = HarborLibraryModule;
exports.SYSTEMINFO_DIRECTIVES = SYSTEMINFO_DIRECTIVES;
exports.SystemComponent = SystemComponent;
exports.SERVICE_CONFIG = SERVICE_CONFIG;
Object.defineProperty(exports, '__esModule', { value: true });
})));