1 | import { ChangeDetectionStrategy, Component, Injectable, Input, NgModule } from '@angular/core';
|
2 | import { CommonModule } from '@angular/common';
|
3 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
4 | import { HttpClient } from '@angular/common/http';
|
5 | import { Router } from '@angular/router';
|
6 | import { Store } from '@ngrx/store';
|
7 | import { Observable } from 'rxjs';
|
8 | import 'rxjs/add/operator/share';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var ApiErrorComponent = (function () {
|
20 | function ApiErrorComponent() {
|
21 | |
22 |
|
23 |
|
24 | this.message = 'An unknown error occured';
|
25 | |
26 |
|
27 |
|
28 | this.showDetails = true;
|
29 | |
30 |
|
31 |
|
32 | this.ignoreProps = ['headers', 'errorMsg'];
|
33 | }
|
34 | |
35 |
|
36 |
|
37 | ApiErrorComponent.prototype.ngOnInit = |
38 |
|
39 |
|
40 | function () {
|
41 | };
|
42 | |
43 |
|
44 |
|
45 | ApiErrorComponent.prototype.ngOnChanges = |
46 |
|
47 |
|
48 | function () {
|
49 | if (this.error) {
|
50 | this.createError();
|
51 | }
|
52 | };
|
53 | |
54 |
|
55 |
|
56 | ApiErrorComponent.prototype.createError = |
57 |
|
58 |
|
59 | function () {
|
60 | var _this = this;
|
61 |
|
62 | this.errorOfKeys = Object.keys(this.error).filter(function (key) {
|
63 | if (_this.ignoreProps.indexOf(key) == -1) {
|
64 | return key;
|
65 | }
|
66 | });
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | if (!this.errorMessage && this.error.status == 404) {
|
73 | this.errorMessage = '404 Error. Unable to connect to the Api.';
|
74 | }
|
75 | else if (!this.errorMessage) {
|
76 | this.errorMessage = 'Unknown error. Please see error details for more information.';
|
77 | }
|
78 | };
|
79 | |
80 |
|
81 |
|
82 |
|
83 | ApiErrorComponent.prototype.closeAlert = |
84 |
|
85 |
|
86 |
|
87 | function () {
|
88 | this.error = null;
|
89 | };
|
90 | ApiErrorComponent.decorators = [
|
91 | { type: Component, args: [{
|
92 | selector: 'error',
|
93 | template: "<div class=\"alert alert-danger icon p-2 pl-3 pr-3\" *ngIf=\"error\"> <button type=\"button\" class=\"close\" aria-label=\"Close\" (click)=\"closeAlert()\"> <span aria-hidden=\"true\">×</span> </button> <i class=\"fa fa-alert\"></i> {{message}} <ng-container *ngIf=\"showDetails && errorOfKeys.length\"> <hr class=\"mt-2 mb-2\"/> <ngb-accordion #acc=\"ngbAccordion\" class=\"accordion-inline\"> <ngb-panel> <ng-template ngbPanelTitle> <span>See error details:</span> </ng-template> <ng-template ngbPanelContent> <table class=\"table table-sm\"> <tbody> <tr *ngFor=\"let key of errorOfKeys\"> <td><strong>{{key}}</strong></td> <td style=\"word-break: break-all;\">{{error[key]}}</td> </tr> </tbody> </table> </ng-template> </ngb-panel> </ngb-accordion> </ng-container> </div> ",
|
94 | changeDetection: ChangeDetectionStrategy.OnPush
|
95 | },] },
|
96 | ];
|
97 |
|
98 | ApiErrorComponent.ctorParameters = function () { return []; };
|
99 | ApiErrorComponent.propDecorators = {
|
100 | "error": [{ type: Input },],
|
101 | "message": [{ type: Input },],
|
102 | "showDetails": [{ type: Input },],
|
103 | };
|
104 | return ApiErrorComponent;
|
105 | }());
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | var ApiStateComponent = (function () {
|
119 | function ApiStateComponent() {
|
120 | |
121 |
|
122 |
|
123 | this.toaster = true;
|
124 | |
125 |
|
126 |
|
127 | this.showSuccess = true;
|
128 | |
129 |
|
130 |
|
131 | this.initialLoadComplete = false;
|
132 | |
133 |
|
134 |
|
135 | this.successVisible = true;
|
136 | }
|
137 | |
138 |
|
139 |
|
140 | ApiStateComponent.prototype.ngOnInit = |
141 |
|
142 |
|
143 | function () { };
|
144 | |
145 |
|
146 |
|
147 | ApiStateComponent.prototype.ngOnChanges = |
148 |
|
149 |
|
150 | function () {
|
151 | if (this.state.loaded) {
|
152 | this.initialLoadComplete = true;
|
153 | }
|
154 | this.successVisible = true;
|
155 | };
|
156 | |
157 |
|
158 |
|
159 |
|
160 | ApiStateComponent.prototype.closeSuccess = |
161 |
|
162 |
|
163 |
|
164 | function () {
|
165 | this.successVisible = false;
|
166 |
|
167 | };
|
168 | |
169 |
|
170 |
|
171 | ApiStateComponent.prototype.ngOnDestroy = |
172 |
|
173 |
|
174 | function () { };
|
175 | ApiStateComponent.decorators = [
|
176 | { type: Component, args: [{
|
177 | selector: 'api-state',
|
178 | template: "<ng-container *ngIf=\"state\"> <!--GET/loading --> <div *ngIf=\"state.loading && !initialLoadComplete\" class=\"p-3\"><i class=\"fa fa-spinner fa-spin\"></i> Loading data from server...</div> <div *ngIf=\"state.loading && initialLoadComplete\" class=\"p-3\" [ngClass]=\"{'toaster': toaster }\"> <i class=\"fa fa-spinner fa-spin\" [ngClass]=\"{'toaster-lg': toaster }\"></i> <ng-container *ngIf=\"!toaster\"> Refreshing data from server... </ng-container> </div> <error *ngIf=\"state.loadError\" [error]=\"state.loadError\" [ngClass]=\"{'toaster': toaster && initialLoadComplete }\"></error> <!-- Create/Update/Delete --> <div *ngIf=\"state.modified && showSuccess && successVisible\" class=\"alert alert-success icon p-2\" [ngClass]=\"{'toaster': toaster }\"> <button type=\"button\" class=\"close\" aria-label=\"Close\" (click)=\"closeSuccess()\" *ngIf=\"!toaster\"> <span aria-hidden=\"true\">×</span> </button> Success! </div> <error *ngIf=\"state.modifyError\" [error]=\"state.modifyError\" [ngClass]=\"{'toaster': toaster }\"></error> <!-- Content --> <ng-container *ngIf=\"state.loaded || (initialLoadComplete && toaster)\"> <ng-content></ng-content> </ng-container> </ng-container> ",
|
179 | styles: ["\n .toaster{position:fixed;bottom:10px;right:20px;z-index:1000;}\n .toaster-lg{font-size:3rem;}\n "],
|
180 | changeDetection: ChangeDetectionStrategy.OnPush
|
181 | },] },
|
182 | ];
|
183 |
|
184 | ApiStateComponent.ctorParameters = function () { return []; };
|
185 | ApiStateComponent.propDecorators = {
|
186 | "state": [{ type: Input },],
|
187 | "toaster": [{ type: Input },],
|
188 | "showSuccess": [{ type: Input },],
|
189 | };
|
190 | return ApiStateComponent;
|
191 | }());
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 | var ApiActions = {
|
199 | RESET: 'RESET',
|
200 | STATE_CHANGE: 'STATE_CHANGE',
|
201 | RESET_ERRORS: 'RESET_ERRORS',
|
202 | RESET_SUCCESS: 'RESET_SUCCESS',
|
203 | GET_COMPLETE: 'GET_COMPLETE',
|
204 | POST_COMPLETE: 'POST_COMPLETE',
|
205 | PUT_COMPLETE: 'PUT_COMPLETE',
|
206 | DELETE_COMPLETE: 'DELETE_COMPLETE',
|
207 | };
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 | var ApiHttpService = (function () {
|
214 | function ApiHttpService(httpSvc, storeSvc, routerSvc) {
|
215 | this.httpSvc = httpSvc;
|
216 | this.storeSvc = storeSvc;
|
217 | this.routerSvc = routerSvc;
|
218 | |
219 |
|
220 |
|
221 | this.cache = {};
|
222 | }
|
223 | |
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | ApiHttpService.prototype.get = |
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | function (url, updateCache) {
|
238 | if (updateCache === void 0) { updateCache = false; }
|
239 |
|
240 | if (!this.cache[url] || updateCache) {
|
241 | this.cache[url] = this.httpSvc.get(url)
|
242 | .publishReplay(1)
|
243 | .refCount();
|
244 | }
|
245 | return this.cache[url];
|
246 | };
|
247 | |
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | |
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 | ApiHttpService.prototype.getStore = |
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 | function (url, apiMap, updateCache) {
|
270 | var _this = this;
|
271 | if (updateCache === void 0) { updateCache = false; }
|
272 |
|
273 | if (this.cache[url] == null || updateCache) {
|
274 |
|
275 | var newState_1 = { loading: true, loadError: false, loaded: false };
|
276 | this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState_1 } });
|
277 | this.cache[url] = this.httpSvc.get(url)
|
278 | .share()
|
279 | .map(function (res) {
|
280 |
|
281 |
|
282 | newState_1 = { loading: false, loadError: false, loaded: true };
|
283 | _this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState_1 } });
|
284 | var data = apiMap.map ? apiMap.map(res) : res;
|
285 | _this.storeSvc.dispatch({ type: ApiActions.GET_COMPLETE, payload: { apiMap: apiMap, data: data } });
|
286 | return data;
|
287 | }).catch(function (error) {
|
288 | if (error.status == 401 || error.status == 403) {
|
289 | error.errorMsg = 'Please log in ';
|
290 | return _this.endSession(error);
|
291 | }
|
292 | else {
|
293 | newState_1 = { loading: false, loadError: error, loaded: false };
|
294 | _this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState_1 } });
|
295 | return Observable.throw(error);
|
296 | }
|
297 | });
|
298 | return this.cache[url];
|
299 | }
|
300 | else {
|
301 | return Observable.of( (true));
|
302 | }
|
303 |
|
304 | };
|
305 | |
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 | |
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 | ApiHttpService.prototype.postStore = |
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 | function (url, apiMap, data) {
|
328 | var _this = this;
|
329 |
|
330 | var newState = { modifying: true, modified: false, modifyError: false };
|
331 | this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState } });
|
332 | return this.httpSvc.post(url, data)
|
333 | .map(function (res) {
|
334 |
|
335 | var newState = { modifying: false, modified: true, modifyError: false };
|
336 | _this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState } });
|
337 |
|
338 | var dataNew = res ? res : data;
|
339 | _this.storeSvc.dispatch({ type: ApiActions.POST_COMPLETE, payload: { apiMap: apiMap, data: dataNew } });
|
340 | return Observable.of(res);
|
341 | }).catch(function (error) {
|
342 | if (error.status == 401 || error.status == 403) {
|
343 | error.errorMsg = 'Please log in ';
|
344 | return _this.endSession(error);
|
345 | }
|
346 | else {
|
347 | error.errorMsg = 'Unable to create ' + apiMap.storeProperty;
|
348 |
|
349 | var newState_2 = { modifying: false, modified: false, modifyError: error };
|
350 | _this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState_2 } });
|
351 | return Observable.throw(error);
|
352 | }
|
353 | });
|
354 | };
|
355 | |
356 |
|
357 |
|
358 |
|
359 |
|
360 | |
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 | ApiHttpService.prototype.putStore = |
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 | function (url, apiMap, data) {
|
377 | var _this = this;
|
378 |
|
379 |
|
380 | var newState = { modifying: true, modified: false, modifyError: false };
|
381 | this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState } });
|
382 | return this.httpSvc.put(url, data)
|
383 | .map(function (res) {
|
384 |
|
385 | var newState = { modifying: false, modified: true, modifyError: false };
|
386 | _this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState } });
|
387 |
|
388 | var dataNew = res ? res : data;
|
389 | _this.storeSvc.dispatch({ type: ApiActions.PUT_COMPLETE, payload: { apiMap: apiMap, data: dataNew } });
|
390 | return Observable.of(res);
|
391 | }).catch(function (error) {
|
392 | console.warn('PUT Error, handle 403 unauth errors here', error);
|
393 | if (error.status == 401 || error.status == 403) {
|
394 | error.errorMsg = 'Please log in ';
|
395 | return _this.endSession(error);
|
396 | }
|
397 | else {
|
398 | error.errorMsg = 'Unable to update ' + apiMap.storeProperty;
|
399 |
|
400 | var newState_3 = { modifying: false, modified: false, modifyError: error };
|
401 | _this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState_3 } });
|
402 | return Observable.throw(error);
|
403 | }
|
404 | });
|
405 | };
|
406 | |
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 | |
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 | ApiHttpService.prototype.deleteStore = |
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 | function (url, apiMap, element) {
|
429 | var _this = this;
|
430 |
|
431 | var newState = { modifying: true, modified: false, modifyError: false };
|
432 | this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState } });
|
433 |
|
434 | return this.httpSvc.request('delete', url, { body: element })
|
435 | .map(function (res) {
|
436 |
|
437 | var newState = { modifying: false, modified: true, modifyError: false };
|
438 | _this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState } });
|
439 | _this.storeSvc.dispatch({ type: ApiActions.DELETE_COMPLETE, payload: { apiMap: apiMap, data: element } });
|
440 | return Observable.of(res);
|
441 | }).catch(function (error) {
|
442 | console.warn('DELETE Error, handle 403 unauth errors here', error);
|
443 | if (error.status == 401 || error.status == 403) {
|
444 | error.errorMsg = 'Please log in ';
|
445 | return _this.endSession(error);
|
446 | }
|
447 | else {
|
448 | error.errorMsg = 'Unable to delete ' + apiMap.storeProperty;
|
449 |
|
450 | var newState_4 = { modifying: false, modified: false, modifyError: error };
|
451 | _this.storeSvc.dispatch({ type: ApiActions.STATE_CHANGE, payload: { apiMap: apiMap, newState: newState_4 } });
|
452 | return Observable.throw(error);
|
453 | }
|
454 | });
|
455 | };
|
456 | |
457 |
|
458 |
|
459 |
|
460 |
|
461 | ApiHttpService.prototype.endSession = |
462 |
|
463 |
|
464 |
|
465 |
|
466 | function (error) {
|
467 | this.cache = {};
|
468 | window.localStorage.removeItem('token');
|
469 | window.sessionStorage.clear();
|
470 | this.routerSvc.navigate(['/login'], { queryParams: { session: 'expired' } });
|
471 | return Observable.throw(error);
|
472 | };
|
473 | ApiHttpService.decorators = [
|
474 | { type: Injectable },
|
475 | ];
|
476 |
|
477 | ApiHttpService.ctorParameters = function () { return [
|
478 | { type: HttpClient, },
|
479 | { type: Store, },
|
480 | { type: Router, },
|
481 | ]; };
|
482 | return ApiHttpService;
|
483 | }());
|
484 |
|
485 | var __assign = (undefined && undefined.__assign) || Object.assign || function(t) {
|
486 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
487 | s = arguments[i];
|
488 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
489 | t[p] = s[p];
|
490 | }
|
491 | return t;
|
492 | };
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 | function ApiReducer(state, _a) {
|
503 | if (state === void 0) { state = {}; }
|
504 | var type = _a.type, payload = _a.payload;
|
505 |
|
506 | var srcData;
|
507 | switch (type) {
|
508 |
|
509 | case ApiActions.RESET:
|
510 | return {};
|
511 |
|
512 | case ApiActions.GET_COMPLETE:
|
513 |
|
514 | if (Array.isArray(payload.data)) {
|
515 | state[payload.apiMap.storeProperty] = payload.data.slice();
|
516 | }
|
517 | else if (typeof payload.data == 'object') {
|
518 | state[payload.apiMap.storeProperty] = __assign({}, payload.data);
|
519 | }
|
520 | else if (typeof payload.data == 'string') {
|
521 | state[payload.apiMap.storeProperty][payload.apiMap.data] = payload.data;
|
522 | }
|
523 | else {
|
524 | console.error('GET_COMPLETE was not an object/array/string, please write a condition for this in the api.reducer', type, payload);
|
525 | }
|
526 | break;
|
527 |
|
528 | case ApiActions.POST_COMPLETE:
|
529 |
|
530 | srcData = (payload.apiMap.map && payload.apiMap.mapSrc) ? state[payload.apiMap.storeProperty][payload.apiMap.mapSrc] : state[payload.apiMap.storeProperty];
|
531 |
|
532 | if (Array.isArray(srcData) && Array.isArray(payload.data)) {
|
533 | srcData = payload.data.concat(srcData);
|
534 | }
|
535 | else if (srcData && typeof payload.data === 'object') {
|
536 | |
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 | srcData = [payload.data].concat(srcData);
|
544 | }
|
545 | else if (typeof srcData === 'object' && typeof payload.data === 'object') {
|
546 | srcData = __assign({}, payload.data);
|
547 | }
|
548 | else {
|
549 | console.error('POST_COMPLETE was not an object or an array, please write a condition for this in the api.reducer');
|
550 | }
|
551 |
|
552 | state[payload.apiMap.storeProperty] = (payload.apiMap.map && payload.apiMap.mapSrc) ? payload.apiMap.map(srcData) : srcData;
|
553 | break;
|
554 |
|
555 | case ApiActions.PUT_COMPLETE:
|
556 |
|
557 |
|
558 | srcData = (payload.apiMap.map && payload.apiMap.mapSrc) ? state[payload.apiMap.storeProperty][payload.apiMap.mapSrc] : state[payload.apiMap.storeProperty];
|
559 |
|
560 | if (Array.isArray(srcData) && Array.isArray(payload.data)) {
|
561 |
|
562 | for (var i = 0; i < payload.data.length; i++) {
|
563 |
|
564 | for (var j = 0; j < srcData.length; j++) {
|
565 |
|
566 | if (payload.data[i][payload.apiMap.uniqueId] == srcData[j][payload.apiMap.uniqueId]) {
|
567 | srcData[j] = payload.data[i];
|
568 | srcData = srcData.slice();
|
569 | j = srcData.length + 1;
|
570 | }
|
571 | }
|
572 | }
|
573 | }
|
574 | else if (Array.isArray(srcData) && typeof payload.data === 'object') {
|
575 |
|
576 |
|
577 | for (var i = 0; i < srcData.length; i++) {
|
578 | if (srcData[i][payload.apiMap.uniqueId] == payload.data[payload.apiMap.uniqueId]) {
|
579 | srcData[i] = payload.data;
|
580 | srcData = srcData.slice();
|
581 | break;
|
582 | }
|
583 | }
|
584 | }
|
585 | else if (typeof srcData === 'object' && typeof payload.data === 'object') {
|
586 |
|
587 | srcData = __assign({}, payload.data);
|
588 | }
|
589 | else {
|
590 | console.error('PUT_COMPLETE was not an object or an array, please write a condition for this in the api.reducer');
|
591 | }
|
592 |
|
593 | state[payload.apiMap.storeProperty] = (payload.apiMap.map && payload.apiMap.mapSrc) ? payload.apiMap.map(srcData) : srcData;
|
594 | break;
|
595 |
|
596 | case ApiActions.DELETE_COMPLETE:
|
597 |
|
598 |
|
599 | srcData = (payload.apiMap.map && payload.apiMap.mapSrc) ? state[payload.apiMap.storeProperty][payload.apiMap.mapSrc] : state[payload.apiMap.storeProperty];
|
600 |
|
601 | if (Array.isArray(srcData) && Array.isArray(payload.data)) {
|
602 |
|
603 | for (var i = 0; i < payload.data.length; i++) {
|
604 |
|
605 | for (var j = 0; j < srcData.length; j++) {
|
606 |
|
607 |
|
608 | if (payload.data[i][payload.apiMap.uniqueId] == srcData[j][payload.apiMap.uniqueId]) {
|
609 | srcData.splice(j, 1);
|
610 | srcData = srcData.slice();
|
611 | j = srcData.length + 1;
|
612 | }
|
613 | }
|
614 | }
|
615 | }
|
616 | else if (Array.isArray(srcData)) {
|
617 |
|
618 | if (typeof payload.apiMap.uniqueId == 'string') {
|
619 | srcData = srcData.filter(function (element) { return element[payload.apiMap.uniqueId] != payload.data[payload.apiMap.uniqueId]; });
|
620 | }
|
621 | else if (payload.apiMap.uniqueId.length) {
|
622 | srcData = srcData.filter(function (element, index) {
|
623 |
|
624 | var hasMatches = 0;
|
625 | payload.apiMap.uniqueId.forEach(function (id) {
|
626 | if (element[id] == payload.data[id]) {
|
627 | hasMatches++;
|
628 | }
|
629 | });
|
630 | return hasMatches != payload.apiMap.uniqueId.length ? true : false;
|
631 | });
|
632 | }
|
633 | }
|
634 | else if (typeof srcData === 'object' && typeof payload.data === 'object') {
|
635 | delete srcData[payload.data];
|
636 | }
|
637 | else {
|
638 | console.error('DELETE_COMPLETE was not an object or an array, please write a condition for this in the api.reducer');
|
639 | }
|
640 |
|
641 | state[payload.apiMap.storeProperty] = (payload.apiMap.map && payload.apiMap.mapSrc) ? payload.apiMap.map(srcData) : srcData;
|
642 | break;
|
643 | }
|
644 | return state;
|
645 | }
|
646 |
|
647 | var __assign$1 = (undefined && undefined.__assign) || Object.assign || function(t) {
|
648 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
649 | s = arguments[i];
|
650 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
651 | t[p] = s[p];
|
652 | }
|
653 | return t;
|
654 | };
|
655 |
|
656 |
|
657 |
|
658 |
|
659 | var ApiStatusStore = {};
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 | function ApiStatusReducer(state, _a) {
|
666 | if (state === void 0) { state = ApiStatusStore; }
|
667 | var type = _a.type, payload = _a.payload;
|
668 |
|
669 | switch (type) {
|
670 |
|
671 | case ApiActions.RESET:
|
672 | return ApiStatusStore;
|
673 |
|
674 | case ApiActions.STATE_CHANGE:
|
675 | state[payload.apiMap.storeProperty] = __assign$1({}, state[payload.apiMap.storeProperty], payload.newState);
|
676 | break;
|
677 |
|
678 | case ApiActions.RESET_ERRORS:
|
679 | Object.keys(state).forEach(function (key) {
|
680 | state[key].modifyError = false;
|
681 | state[key] = __assign$1({}, state[key]);
|
682 | });
|
683 | break;
|
684 |
|
685 | case ApiActions.RESET_SUCCESS:
|
686 | Object.keys(state).forEach(function (key) {
|
687 | state[key].modified = false;
|
688 | state[key] = __assign$1({}, state[key]);
|
689 | });
|
690 | break;
|
691 | }
|
692 | return state;
|
693 | }
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 | var ApiToolsModule = (function () {
|
700 | function ApiToolsModule() {
|
701 | }
|
702 | |
703 |
|
704 |
|
705 | ApiToolsModule.forRoot = |
706 |
|
707 |
|
708 | function () {
|
709 | return {
|
710 | ngModule: ApiToolsModule,
|
711 | providers: []
|
712 | };
|
713 | };
|
714 | ApiToolsModule.decorators = [
|
715 | { type: NgModule, args: [{
|
716 | imports: [
|
717 | CommonModule,
|
718 | NgbModule.forRoot()
|
719 | ],
|
720 | declarations: [
|
721 | ApiErrorComponent,
|
722 | ApiStateComponent
|
723 | ],
|
724 | exports: [
|
725 | ApiErrorComponent,
|
726 | ApiStateComponent
|
727 | ]
|
728 | },] },
|
729 | ];
|
730 |
|
731 | ApiToolsModule.ctorParameters = function () { return []; };
|
732 | return ApiToolsModule;
|
733 | }());
|
734 |
|
735 | export { ApiToolsModule, ApiErrorComponent, ApiStateComponent, ApiActions, ApiHttpService, ApiReducer, ApiStatusReducer };
|