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