1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var core_1 = require("@angular/core");
|
4 | var http_1 = require("@angular/common/http");
|
5 | var Rx_1 = require("rxjs/Rx");
|
6 | var models_1 = require("../models");
|
7 | var store_1 = require("@ngrx/store");
|
8 | var actions_1 = require("../actions");
|
9 | var module_configuration_1 = require("./module-configuration");
|
10 | var ConfigService = (function () {
|
11 | function ConfigService(http, store, configurationService) {
|
12 | var _this = this;
|
13 | this.http = http;
|
14 | this.store = store;
|
15 | this.configurationService = configurationService;
|
16 | setTimeout(function () {
|
17 | _this.store.dispatch(new actions_1.GetConfigAction());
|
18 | }, 999);
|
19 | }
|
20 | ConfigService.prototype.getConfigs = function () {
|
21 | var _this = this;
|
22 | var configsEndpoint = this.configurationService.config.env.production
|
23 | ? this.configurationService.config.prod_api_host
|
24 | : this.configurationService.config.dev_api_host;
|
25 | return (this.http
|
26 | .get(configsEndpoint + "/api/config")
|
27 | .take(1)
|
28 | .map(function (response) {
|
29 | if (_this.configurationService.config.env.production) {
|
30 | var dev_api_host = _this.configurationService.config.dev_api_host;
|
31 | var prod_api_host = _this.configurationService.config.prod_api_host;
|
32 | return JSON.parse(JSON.stringify(response).replace(new RegExp(dev_api_host, "g"), prod_api_host)).Result;
|
33 | }
|
34 | else {
|
35 | return response.Result;
|
36 | }
|
37 | })
|
38 | .catch(function (err) {
|
39 | return Rx_1.Observable.throw(err);
|
40 | }));
|
41 | };
|
42 | ConfigService.prototype.getConfigByName = function (name) {
|
43 | return this.http.get("http://localhost:3000/api/config/" + name).map(function (response) { return response; }).catch(function (err) {
|
44 | return Rx_1.Observable.throw(err);
|
45 | });
|
46 | };
|
47 | ConfigService.prototype.editConfig = function (body) {
|
48 | var model = new models_1.EditConfigApiModel.Request(body);
|
49 | return this.http
|
50 | .put("http://localhost:3000/api/config/" + model.Name, model.getRequestBody(), { withCredentials: false })
|
51 | .map(function (response) { return response; })
|
52 | .catch(function (err) {
|
53 | return Rx_1.Observable.throw(err);
|
54 | });
|
55 | };
|
56 | ConfigService.prototype.getLayoutConfigs = function () {
|
57 | return this.http
|
58 | .get("http://localhost:3000/api/layout-config")
|
59 | .map(function (response) { return response; })
|
60 | .catch(function (err) {
|
61 | return Rx_1.Observable.throw(err);
|
62 | });
|
63 | };
|
64 | ConfigService.decorators = [
|
65 | { type: core_1.Injectable },
|
66 | ];
|
67 |
|
68 | ConfigService.ctorParameters = function () { return [
|
69 | { type: http_1.HttpClient, },
|
70 | { type: store_1.Store, },
|
71 | { type: module_configuration_1.ConfigurationService, },
|
72 | ]; };
|
73 | return ConfigService;
|
74 | }());
|
75 | exports.ConfigService = ConfigService;
|
76 |
|
\ | No newline at end of file |