1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/http'), require('rxjs/Rx'), require('rxjs/Subject'), require('angular-2-local-storage')) :
|
3 | typeof define === 'function' && define.amd ? define('easy-core', ['exports', '@angular/core', '@angular/http', 'rxjs/Rx', 'rxjs/Subject', 'angular-2-local-storage'], factory) :
|
4 | (factory((global['easy-core'] = {}),global.ng.core,global.ng.http,global.Rx,global.Rx,global.angular2LocalStorage));
|
5 | }(this, (function (exports,core,http,Rx,Subject,angular2LocalStorage) { 'use strict';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | var extendStatics = Object.setPrototypeOf ||
|
21 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
22 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
23 | function __extends(d, b) {
|
24 | extendStatics(d, b);
|
25 | function __() { this.constructor = d; }
|
26 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | function __values(o) {
|
37 | var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
38 | if (m) return m.call(o);
|
39 | return {
|
40 | next: function () {
|
41 | if (o && i >= o.length) o = void 0;
|
42 | return { value: o && o[i++], done: !o };
|
43 | }
|
44 | };
|
45 | }
|
46 |
|
47 | var Setting = (function () {
|
48 | function Setting(key, value) {
|
49 | this.key = key;
|
50 | this.value = value;
|
51 | }
|
52 | return Setting;
|
53 | }());
|
54 | var AppConfig = (function () {
|
55 | function AppConfig(http$$1) {
|
56 | this.http = http$$1;
|
57 | this.paths = [];
|
58 | this.config = [];
|
59 | this.env = null;
|
60 | this.subject = new Rx.Subject();
|
61 | this.initialized = this.subject.asObservable();
|
62 | }
|
63 | AppConfig.prototype.getPresentationConfigs = function () {
|
64 | return this.config.filter(function (x) { return x.key.toLowerCase().endsWith("config"); });
|
65 | };
|
66 | AppConfig.prototype.get = function (key) {
|
67 | var setting = this.config.filter(function (x) { return x.key.toLowerCase() == key.toLowerCase(); });
|
68 | return setting.length > 0 ? setting[0].value : null;
|
69 | };
|
70 | AppConfig.prototype.getEnv = function (key) {
|
71 | return this.env[key];
|
72 | };
|
73 | AppConfig.prototype.addNavigationItems = function (applicationName, paths) {
|
74 | var _loop_1 = function (path) {
|
75 | if (this_1.paths.filter(function (x) { return x.value.name == path.name; }).length == 0) {
|
76 | this_1.paths.push(new Setting(applicationName, { name: path.name, route: path.route }));
|
77 | }
|
78 | };
|
79 | var this_1 = this;
|
80 | try {
|
81 | for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
|
82 | var path = paths_1_1.value;
|
83 | _loop_1(path);
|
84 | }
|
85 | }
|
86 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
87 | finally {
|
88 | try {
|
89 | if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
|
90 | }
|
91 | finally { if (e_1) throw e_1.error; }
|
92 | }
|
93 | var e_1, _a;
|
94 | };
|
95 | AppConfig.prototype.fetchNavigationItems = function (applicationName) {
|
96 | return this.paths.filter(function (x) { return x.key === applicationName; }).map(function (x) { return new Setting(x.value.name, x.value.route); });
|
97 | };
|
98 | AppConfig.prototype.initialize = function (settings, env) {
|
99 | this.config = this.config.concat(settings);
|
100 | this.env = env;
|
101 | this.subject.next(true);
|
102 | };
|
103 | return AppConfig;
|
104 | }());
|
105 | AppConfig.decorators = [
|
106 | { type: core.Injectable },
|
107 | ];
|
108 | AppConfig.ctorParameters = function () { return [
|
109 | { type: http.Http, },
|
110 | ]; };
|
111 | var contentHeaders = new http.Headers();
|
112 | contentHeaders.append('Accept', 'application/json');
|
113 | contentHeaders.append('Content-Type', 'application/json');
|
114 | var LoaderService = (function () {
|
115 | function LoaderService() {
|
116 | this.loaderSubject = new Subject.Subject();
|
117 | this.loaderState = this.loaderSubject.asObservable();
|
118 | }
|
119 | LoaderService.prototype.show = function () {
|
120 | this.loaderSubject.next(({ show: true }));
|
121 | };
|
122 | LoaderService.prototype.hide = function () {
|
123 | this.loaderSubject.next(({ show: false }));
|
124 | };
|
125 | return LoaderService;
|
126 | }());
|
127 | LoaderService.decorators = [
|
128 | { type: core.Injectable },
|
129 | ];
|
130 | LoaderService.ctorParameters = function () { return []; };
|
131 | var LoaderComponent = (function () {
|
132 | function LoaderComponent(loaderService) {
|
133 | this.loaderService = loaderService;
|
134 | this.show = false;
|
135 | }
|
136 | LoaderComponent.prototype.ngOnInit = function () {
|
137 | var _this = this;
|
138 | this.subscription = this.loaderService.loaderState
|
139 | .subscribe(function (state) {
|
140 | _this.show = state.show;
|
141 | });
|
142 | };
|
143 | LoaderComponent.prototype.ngOnDestroy = function () {
|
144 | this.subscription.unsubscribe();
|
145 | };
|
146 | return LoaderComponent;
|
147 | }());
|
148 | LoaderComponent.decorators = [
|
149 | { type: core.Component, args: [{
|
150 | selector: 'angular-loader',
|
151 | template: "<div [class.loader-hidden]=\"!show\">\n <div class=\"loader-overlay\">\n <div>\n <mat-progress-bar color=\"warn\" mode=\"indeterminate\" *ngIf=\"show\"></mat-progress-bar>\n </div>\n </div>\n </div>",
|
152 | styles: [".loader-hidden {\n visibility: hidden;\n }\n .loader-overlay {\n position: absolute;\n width:100%;\n top:0;\n left: 0;\n opacity: 1;\n z-index: 9999999999;\n }"],
|
153 | },] },
|
154 | ];
|
155 | LoaderComponent.ctorParameters = function () { return [
|
156 | { type: LoaderService, },
|
157 | ]; };
|
158 | var HttpIntegrationService = (function () {
|
159 | function HttpIntegrationService() {
|
160 | this.subject = new Subject.Subject();
|
161 | this.OnError = this.subject.asObservable();
|
162 | }
|
163 | HttpIntegrationService.prototype.error = function (res) {
|
164 | this.subject.next(res);
|
165 | };
|
166 | return HttpIntegrationService;
|
167 | }());
|
168 | HttpIntegrationService.decorators = [
|
169 | { type: core.Injectable },
|
170 | ];
|
171 | var InterceptedHttp = (function (_super) {
|
172 | __extends(InterceptedHttp, _super);
|
173 | function InterceptedHttp(backend, defaultOptions, localStorageService, loaderService, httpIntegrationService) {
|
174 | var _this = _super.call(this, backend, defaultOptions) || this;
|
175 | _this.localStorageService = localStorageService;
|
176 | _this.loaderService = loaderService;
|
177 | _this.httpIntegrationService = httpIntegrationService;
|
178 | return _this;
|
179 | }
|
180 | InterceptedHttp.prototype.get = function (url, options) {
|
181 | var _this = this;
|
182 | this.showLoader();
|
183 | return _super.prototype.get.call(this, url, this.getRequestOptionArgs(options))
|
184 | .do(function (res) {
|
185 | _this.onSuccess(res);
|
186 | }, function (error) {
|
187 | _this.onError(error);
|
188 | })
|
189 | .finally(function () {
|
190 | _this.onEnd();
|
191 | });
|
192 | };
|
193 | InterceptedHttp.prototype.post = function (url, body, options) {
|
194 | var _this = this;
|
195 | this.showLoader();
|
196 | return _super.prototype.post.call(this, url, body, this.getRequestOptionArgs(options))
|
197 | .do(function (res) {
|
198 | _this.onSuccess(res);
|
199 | }, function (error) {
|
200 | _this.onError(error);
|
201 | })
|
202 | .finally(function () {
|
203 | _this.onEnd();
|
204 | });
|
205 | };
|
206 | InterceptedHttp.prototype.put = function (url, body, options) {
|
207 | var _this = this;
|
208 | this.showLoader();
|
209 | return _super.prototype.put.call(this, url, body, this.getRequestOptionArgs(options))
|
210 | .do(function (res) {
|
211 | _this.onSuccess(res);
|
212 | }, function (error) {
|
213 | _this.onError(error);
|
214 | })
|
215 | .finally(function () {
|
216 | _this.onEnd();
|
217 | });
|
218 | };
|
219 | InterceptedHttp.prototype.delete = function (url, options) {
|
220 | var _this = this;
|
221 | this.showLoader();
|
222 | return _super.prototype.delete.call(this, url, this.getRequestOptionArgs(options))
|
223 | .do(function (res) {
|
224 | _this.onSuccess(res);
|
225 | }, function (error) {
|
226 | _this.onError(error);
|
227 | })
|
228 | .finally(function () {
|
229 | _this.onEnd();
|
230 | });
|
231 | };
|
232 | InterceptedHttp.prototype.getRequestOptionArgs = function (options) {
|
233 | if (options == null) {
|
234 | options = new http.RequestOptions();
|
235 | }
|
236 | if (options.headers == null) {
|
237 | options.headers = new http.Headers();
|
238 | }
|
239 | if (!options.withCredentials)
|
240 | this.createAuthorizationHeader(options.headers);
|
241 | return options;
|
242 | };
|
243 | InterceptedHttp.prototype.createAuthorizationHeader = function (headers) {
|
244 | if (this.localStorageService.get('id_token') != null) {
|
245 | headers.append('Authorization', this.localStorageService.get('id_token'));
|
246 | }
|
247 | };
|
248 | InterceptedHttp.prototype.onSuccess = function (res) {
|
249 | console.log('Request successful');
|
250 | };
|
251 | InterceptedHttp.prototype.onError = function (res) {
|
252 | console.log('Error, status code: ' + res.status);
|
253 | this.httpIntegrationService.error(res);
|
254 | };
|
255 | InterceptedHttp.prototype.onEnd = function () {
|
256 | this.hideLoader();
|
257 | };
|
258 | InterceptedHttp.prototype.showLoader = function () {
|
259 | this.loaderService.show();
|
260 | };
|
261 | InterceptedHttp.prototype.hideLoader = function () {
|
262 | this.loaderService.hide();
|
263 | };
|
264 | return InterceptedHttp;
|
265 | }(http.Http));
|
266 | InterceptedHttp.decorators = [
|
267 | { type: core.Injectable },
|
268 | ];
|
269 | InterceptedHttp.ctorParameters = function () { return [
|
270 | { type: http.ConnectionBackend, },
|
271 | { type: http.RequestOptions, },
|
272 | { type: angular2LocalStorage.LocalStorageService, },
|
273 | { type: LoaderService, },
|
274 | { type: HttpIntegrationService, },
|
275 | ]; };
|
276 | function httpFactory(xhrBackend, requestOptions, localStorageService, loaderService, httpIntegrationService) {
|
277 | return new InterceptedHttp(xhrBackend, requestOptions, localStorageService, loaderService, httpIntegrationService);
|
278 | }
|
279 | if (!Array.prototype.add) {
|
280 | Array.prototype.add = function (item) {
|
281 | this.push(item);
|
282 | };
|
283 | }
|
284 | if (!Array.prototype.addRange) {
|
285 | Array.prototype.addRange = function (items) {
|
286 | var _this = this;
|
287 | items.forEach(function (x) { return _this.push(x); });
|
288 | };
|
289 | }
|
290 | if (!Array.prototype.remove) {
|
291 | Array.prototype.remove = function (item) {
|
292 | var index = this.indexOf(item);
|
293 | this.splice(index, 0);
|
294 | return index != -1;
|
295 | };
|
296 | }
|
297 | if (!Array.prototype.where) {
|
298 | Array.prototype.where = function (func) {
|
299 | var items = (this.filter(func));
|
300 | return items;
|
301 | };
|
302 | }
|
303 | if (!Array.prototype.orderBy) {
|
304 | Array.prototype.orderBy = function (propertyExpression) {
|
305 | var result = Array();
|
306 | var compareFunction = function (item1, item2) {
|
307 | if (propertyExpression(item1) > propertyExpression(item2))
|
308 | return 1;
|
309 | if (propertyExpression(item2) > propertyExpression(item1))
|
310 | return -1;
|
311 | return 0;
|
312 | };
|
313 | for (var i = 0; i < ((this)).length; i++) {
|
314 | return ((this)).sort(compareFunction);
|
315 | }
|
316 | return result;
|
317 | };
|
318 | }
|
319 | if (!Array.prototype.orderByDescending) {
|
320 | Array.prototype.orderByDescending = function (propertyExpression) {
|
321 | var result = Array();
|
322 | var compareFunction = function (item1, item2) {
|
323 | if (propertyExpression(item1) > propertyExpression(item2))
|
324 | return -1;
|
325 | if (propertyExpression(item2) > propertyExpression(item1))
|
326 | return 1;
|
327 | return 0;
|
328 | };
|
329 | for (var i = 0; i < ((this)).length; i++) {
|
330 | return ((this)).sort(compareFunction);
|
331 | }
|
332 | return result;
|
333 | };
|
334 | }
|
335 | if (!Array.prototype.single) {
|
336 | Array.prototype.single = function (func) {
|
337 | if (func === void 0) { func = null; }
|
338 | var items = this;
|
339 | if (func != null)
|
340 | items = (this.filter(func));
|
341 | if (items.length > 1)
|
342 | throw new SequenceContainsMoreThanOneElementException();
|
343 | if (items.length == 0)
|
344 | throw new SequenceDoesNotContainException();
|
345 | return items[0];
|
346 | };
|
347 | }
|
348 | if (!Array.prototype.singleOrDefault) {
|
349 | Array.prototype.singleOrDefault = function (func) {
|
350 | if (func === void 0) { func = null; }
|
351 | var items = this;
|
352 | if (func != null)
|
353 | items = (this.filter(func));
|
354 | if (items.length > 1)
|
355 | throw new SequenceContainsMoreThanOneElementException();
|
356 | if (items.length == 0)
|
357 | return null;
|
358 | return items[0];
|
359 | };
|
360 | }
|
361 | if (!Array.prototype.first) {
|
362 | Array.prototype.first = function (func) {
|
363 | if (func === void 0) { func = null; }
|
364 | var items = this;
|
365 | if (func != null)
|
366 | items = (this.filter(func));
|
367 | if (items.any())
|
368 | return items[0];
|
369 | else
|
370 | throw new SequenceDoesNotContainException();
|
371 | };
|
372 | }
|
373 | if (!Array.prototype.firstOrDefault) {
|
374 | Array.prototype.firstOrDefault = function (func) {
|
375 | if (func === void 0) { func = null; }
|
376 | var items = this;
|
377 | if (func != null)
|
378 | items = (this.filter(func));
|
379 | if (items.length > 0)
|
380 | return items[0];
|
381 | else
|
382 | return null;
|
383 | };
|
384 | }
|
385 | if (!Array.prototype.last) {
|
386 | Array.prototype.last = function (func) {
|
387 | if (func === void 0) { func = null; }
|
388 | var items = this.reverse();
|
389 | if (func != null)
|
390 | items = (this.filter(func));
|
391 | items = (this.filter(func));
|
392 | if (items.length > 1)
|
393 | return items[0];
|
394 | else
|
395 | throw new SequenceDoesNotContainException();
|
396 | };
|
397 | }
|
398 | if (!Array.prototype.lastOrDefault) {
|
399 | Array.prototype.lastOrDefault = function (func) {
|
400 | if (func === void 0) { func = null; }
|
401 | var items = this.reverse();
|
402 | if (func != null)
|
403 | items = (this.filter(func));
|
404 | if (items.length > 0)
|
405 | return items[0];
|
406 | else
|
407 | return null;
|
408 | };
|
409 | }
|
410 | if (!Array.prototype.any) {
|
411 | Array.prototype.any = function (func) {
|
412 | if (func === void 0) { func = null; }
|
413 | var items = this;
|
414 | if (func != null)
|
415 | items = (this.filter(func));
|
416 | return items.length > 0;
|
417 | };
|
418 | }
|
419 | if (!Array.prototype.all) {
|
420 | Array.prototype.all = function (func) {
|
421 | var items = (this.filter(func));
|
422 | return items.length == this.length;
|
423 | };
|
424 | }
|
425 | var SequenceDoesNotContainException = (function (_super) {
|
426 | __extends(SequenceDoesNotContainException, _super);
|
427 | function SequenceDoesNotContainException() {
|
428 | var _this = _super.call(this) || this;
|
429 | Object.setPrototypeOf(_this, SequenceDoesNotContainException.prototype);
|
430 | return _this;
|
431 | }
|
432 | return SequenceDoesNotContainException;
|
433 | }(Error));
|
434 | var SequenceContainsMoreThanOneElementException = (function (_super) {
|
435 | __extends(SequenceContainsMoreThanOneElementException, _super);
|
436 | function SequenceContainsMoreThanOneElementException() {
|
437 | var _this = _super.call(this) || this;
|
438 | Object.setPrototypeOf(_this, SequenceContainsMoreThanOneElementException.prototype);
|
439 | return _this;
|
440 | }
|
441 | return SequenceContainsMoreThanOneElementException;
|
442 | }(Error));
|
443 | var ArrayExtensions = (function () {
|
444 | function ArrayExtensions() {
|
445 | }
|
446 | return ArrayExtensions;
|
447 | }());
|
448 | if (!String.prototype.fromCamelCase) {
|
449 | String.prototype.fromCamelCase = function () {
|
450 | return this.replace(/([a-z](?=[A-Z]))/g, '$1 ');
|
451 | };
|
452 | }
|
453 | var StringExtensions = (function () {
|
454 | function StringExtensions() {
|
455 | }
|
456 | return StringExtensions;
|
457 | }());
|
458 | var CoreModule = (function () {
|
459 | function CoreModule() {
|
460 | }
|
461 | return CoreModule;
|
462 | }());
|
463 | CoreModule.decorators = [
|
464 | { type: core.NgModule, args: [{
|
465 | imports: [AppConfig, http.HttpModule],
|
466 | declarations: [],
|
467 | providers: [AppConfig],
|
468 | exports: [LoaderComponent]
|
469 | },] },
|
470 | ];
|
471 |
|
472 | exports.CoreModule = CoreModule;
|
473 | exports.LoaderComponent = LoaderComponent;
|
474 | exports.httpFactory = httpFactory;
|
475 | exports.AppConfig = AppConfig;
|
476 | exports.Setting = Setting;
|
477 | exports.contentHeaders = contentHeaders;
|
478 | exports.LoaderService = LoaderService;
|
479 | exports.HttpIntegrationService = HttpIntegrationService;
|
480 | exports.InterceptedHttp = InterceptedHttp;
|
481 | exports.ArrayExtensions = ArrayExtensions;
|
482 | exports.StringExtensions = StringExtensions;
|
483 |
|
484 | Object.defineProperty(exports, '__esModule', { value: true });
|
485 |
|
486 | })));
|
487 |
|