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