@rosoftlab/core 1.0.0-alpha-0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. package/README.md +27 -0
  2. package/esm2022/lib/base-components/base-form-edit.component.mjs +239 -0
  3. package/esm2022/lib/base-components/field-error-display/field-error-display.component.mjs +15 -0
  4. package/esm2022/lib/base-components/index.mjs +4 -0
  5. package/esm2022/lib/base-components/page-not-found/page-not-found.component.mjs +15 -0
  6. package/esm2022/lib/base-components/under-construction/under-construction.component.mjs +12 -0
  7. package/esm2022/lib/configurations.mjs +8 -0
  8. package/esm2022/lib/constants/symbols.mjs +3 -0
  9. package/esm2022/lib/converters/date/date.converter.mjs +20 -0
  10. package/esm2022/lib/core.mjs +8 -0
  11. package/esm2022/lib/decorators/attribute.decorator.mjs +87 -0
  12. package/esm2022/lib/decorators/base-datastore-config.decorator.mjs +7 -0
  13. package/esm2022/lib/decorators/base-model-config.decorator.mjs +10 -0
  14. package/esm2022/lib/decorators/custom.type.decorator.mjs +11 -0
  15. package/esm2022/lib/directives/translated-content.directive.mjs +97 -0
  16. package/esm2022/lib/directives/translated-element.directive.mjs +20 -0
  17. package/esm2022/lib/grid-layout-format.enum.mjs +15 -0
  18. package/esm2022/lib/index.mjs +26 -0
  19. package/esm2022/lib/interceptors/cache.interceptor.mjs +52 -0
  20. package/esm2022/lib/interceptors/index.mjs +2 -0
  21. package/esm2022/lib/interfaces/attribute-decorator-options.interface.mjs +2 -0
  22. package/esm2022/lib/interfaces/datastore-config.interface.mjs +2 -0
  23. package/esm2022/lib/interfaces/model-config.interface.mjs +2 -0
  24. package/esm2022/lib/interfaces/overrides.interface.mjs +2 -0
  25. package/esm2022/lib/interfaces/property-converter.interface.mjs +2 -0
  26. package/esm2022/lib/models/base-meta.model.mjs +7 -0
  27. package/esm2022/lib/models/base-query-data.mjs +13 -0
  28. package/esm2022/lib/models/base.model.mjs +158 -0
  29. package/esm2022/lib/models/error-response.model.mjs +9 -0
  30. package/esm2022/lib/models/rule.mjs +6 -0
  31. package/esm2022/lib/pipes/Nl2brPipe.pipe.mjs +21 -0
  32. package/esm2022/lib/pipes/input-error.pipe.mjs +38 -0
  33. package/esm2022/lib/providers.mjs +12 -0
  34. package/esm2022/lib/resolvers/dynamically-class-resolver.mjs +22 -0
  35. package/esm2022/lib/resolvers/dynamically-service-resolver.mjs +22 -0
  36. package/esm2022/lib/resolvers/index.mjs +3 -0
  37. package/esm2022/lib/rsl-base-module.mjs +64 -0
  38. package/esm2022/lib/services/base-datastore.service.mjs +342 -0
  39. package/esm2022/lib/services/base.service.mjs +99 -0
  40. package/esm2022/lib/services/cache.service.mjs +35 -0
  41. package/esm2022/lib/services/datastore.service.mjs +26 -0
  42. package/esm2022/lib/services/dialog.service.mjs +150 -0
  43. package/esm2022/lib/services/index.mjs +6 -0
  44. package/esm2022/lib/services/translate-loader.service.mjs +34 -0
  45. package/esm2022/lib/utils.mjs +27 -0
  46. package/esm2022/lib/validators/pattern-validator.mjs +15 -0
  47. package/esm2022/public-api.mjs +5 -0
  48. package/esm2022/rosoftlab-core.mjs +5 -0
  49. package/fesm2022/rosoftlab-core.mjs +1637 -0
  50. package/fesm2022/rosoftlab-core.mjs.map +1 -0
  51. package/index.d.ts +5 -0
  52. package/lib/base-components/base-form-edit.component.d.ts +56 -0
  53. package/lib/base-components/field-error-display/field-error-display.component.d.ts +7 -0
  54. package/lib/base-components/index.d.ts +3 -0
  55. package/lib/base-components/page-not-found/page-not-found.component.d.ts +8 -0
  56. package/lib/base-components/under-construction/under-construction.component.d.ts +6 -0
  57. package/lib/configurations.d.ts +6 -0
  58. package/lib/constants/symbols.d.ts +1 -0
  59. package/lib/converters/date/date.converter.d.ts +5 -0
  60. package/lib/core.d.ts +7 -0
  61. package/lib/decorators/attribute.decorator.d.ts +3 -0
  62. package/lib/decorators/base-datastore-config.decorator.d.ts +1 -0
  63. package/lib/decorators/base-model-config.decorator.d.ts +1 -0
  64. package/lib/decorators/custom.type.decorator.d.ts +1 -0
  65. package/lib/directives/translated-content.directive.d.ts +21 -0
  66. package/lib/directives/translated-element.directive.d.ts +10 -0
  67. package/lib/grid-layout-format.enum.d.ts +12 -0
  68. package/lib/index.d.ts +25 -0
  69. package/lib/interceptors/cache.interceptor.d.ts +13 -0
  70. package/lib/interceptors/index.d.ts +1 -0
  71. package/lib/interfaces/attribute-decorator-options.interface.d.ts +8 -0
  72. package/lib/interfaces/datastore-config.interface.d.ts +8 -0
  73. package/lib/interfaces/model-config.interface.d.ts +10 -0
  74. package/lib/interfaces/overrides.interface.d.ts +5 -0
  75. package/lib/interfaces/property-converter.interface.d.ts +4 -0
  76. package/lib/models/base-meta.model.d.ts +5 -0
  77. package/lib/models/base-query-data.d.ts +7 -0
  78. package/lib/models/base.model.d.ts +31 -0
  79. package/lib/models/error-response.model.d.ts +17 -0
  80. package/lib/models/rule.d.ts +5 -0
  81. package/lib/pipes/Nl2brPipe.pipe.d.ts +7 -0
  82. package/lib/pipes/input-error.pipe.d.ts +10 -0
  83. package/lib/providers.d.ts +2 -0
  84. package/lib/resolvers/dynamically-class-resolver.d.ts +3 -0
  85. package/lib/resolvers/dynamically-service-resolver.d.ts +3 -0
  86. package/lib/resolvers/index.d.ts +2 -0
  87. package/lib/rsl-base-module.d.ts +13 -0
  88. package/lib/services/base-datastore.service.d.ts +47 -0
  89. package/lib/services/base.service.d.ts +27 -0
  90. package/lib/services/cache.service.d.ts +11 -0
  91. package/lib/services/datastore.service.d.ts +12 -0
  92. package/lib/services/dialog.service.d.ts +21 -0
  93. package/lib/services/index.d.ts +5 -0
  94. package/lib/services/translate-loader.service.d.ts +14 -0
  95. package/lib/utils.d.ts +2 -0
  96. package/lib/validators/pattern-validator.d.ts +4 -0
  97. package/package.json +36 -0
  98. package/public-api.d.ts +1 -0
@@ -0,0 +1,1637 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Component, Input, Injectable, Directive, ContentChildren, Inject, Pipe, Optional, NgModule } from '@angular/core';
3
+ import * as i6 from '@angular/common';
4
+ import { DatePipe, DecimalPipe, PercentPipe, CommonModule } from '@angular/common';
5
+ import * as i1$1 from '@angular/forms';
6
+ import { UntypedFormGroup, UntypedFormControl, Validators, ReactiveFormsModule } from '@angular/forms';
7
+ import * as i2 from '@angular/router';
8
+ import * as i1$2 from '@ngx-translate/core';
9
+ import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
10
+ import { Observable, throwError, from, merge, BehaviorSubject, combineLatest, of } from 'rxjs';
11
+ import * as i1 from '@angular/common/http';
12
+ import { HttpHeaders, HttpParams, HttpErrorResponse, HttpResponse, HttpClientModule, HttpClient } from '@angular/common/http';
13
+ import { compare } from 'fast-json-patch';
14
+ import * as qs from 'qs';
15
+ import { map, catchError, switchMap, tap } from 'rxjs/operators';
16
+ import Swal from 'sweetalert2';
17
+ import 'reflect-metadata';
18
+ import { parseISO } from 'date-fns';
19
+
20
+ class FieldErrorDisplayComponent {
21
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: FieldErrorDisplayComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
22
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.1", type: FieldErrorDisplayComponent, selector: "rsl-field-error-display", inputs: { errorMsg: "errorMsg", displayError: "displayError" }, ngImport: i0, template: "<div *ngIf=\"displayError\" >\n <!-- <span class=\"glyphicon glyphicon-remove form-control-feedback fix-error-icon\"></span> -->\n <span class=\"sr-only\">(error)</span>\n <div class=\"error-msg\">\n {{ errorMsg }}\n </div>\n</div>\n", styles: [".error-msg{color:red}.fix-error-icon{top:27px}\n"] }); }
23
+ }
24
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: FieldErrorDisplayComponent, decorators: [{
25
+ type: Component,
26
+ args: [{ selector: 'rsl-field-error-display', template: "<div *ngIf=\"displayError\" >\n <!-- <span class=\"glyphicon glyphicon-remove form-control-feedback fix-error-icon\"></span> -->\n <span class=\"sr-only\">(error)</span>\n <div class=\"error-msg\">\n {{ errorMsg }}\n </div>\n</div>\n", styles: [".error-msg{color:red}.fix-error-icon{top:27px}\n"] }]
27
+ }], propDecorators: { errorMsg: [{
28
+ type: Input
29
+ }], displayError: [{
30
+ type: Input
31
+ }] } });
32
+
33
+ class PageNotFoundComponent {
34
+ constructor() {
35
+ }
36
+ ngOnInit() {
37
+ }
38
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: PageNotFoundComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
39
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.1", type: PageNotFoundComponent, selector: "rsl-page-not-found", ngImport: i0, template: "<div class=\"forms-view-container\">\n <div class=\"under-construction-view-container\">\n Page not found\n </div>\n</div>", styles: [".under-construction-view-container{height:calc(100vh - 250px);margin:60px 0 0;padding:0;display:flex;justify-content:center;align-items:center;box-sizing:border-box;font-size:1.8em;line-height:1.3em;font-weight:300;color:#58585b;text-align:center}\n"] }); }
40
+ }
41
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: PageNotFoundComponent, decorators: [{
42
+ type: Component,
43
+ args: [{ selector: 'rsl-page-not-found', template: "<div class=\"forms-view-container\">\n <div class=\"under-construction-view-container\">\n Page not found\n </div>\n</div>", styles: [".under-construction-view-container{height:calc(100vh - 250px);margin:60px 0 0;padding:0;display:flex;justify-content:center;align-items:center;box-sizing:border-box;font-size:1.8em;line-height:1.3em;font-weight:300;color:#58585b;text-align:center}\n"] }]
44
+ }], ctorParameters: function () { return []; } });
45
+
46
+ class UnderConstructionComponent {
47
+ constructor() { }
48
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: UnderConstructionComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
49
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.1", type: UnderConstructionComponent, selector: "rsl-under-construction", ngImport: i0, template: "<div class=\"forms-view-container\">\n <div class=\"under-construction-view-container\">\n Page under construction\n </div>\n</div>", styles: [".under-construction-view-container{height:calc(100vh - 250px);margin:60px 0 0;padding:0;display:flex;justify-content:center;align-items:center;box-sizing:border-box;font-size:1.8em;line-height:1.3em;font-weight:300;color:#58585b;text-align:center}\n"] }); }
50
+ }
51
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: UnderConstructionComponent, decorators: [{
52
+ type: Component,
53
+ args: [{ selector: 'rsl-under-construction', template: "<div class=\"forms-view-container\">\n <div class=\"under-construction-view-container\">\n Page under construction\n </div>\n</div>", styles: [".under-construction-view-container{height:calc(100vh - 250px);margin:60px 0 0;padding:0;display:flex;justify-content:center;align-items:center;box-sizing:border-box;font-size:1.8em;line-height:1.3em;font-weight:300;color:#58585b;text-align:center}\n"] }]
54
+ }], ctorParameters: function () { return []; } });
55
+
56
+ class BaseQueryData {
57
+ constructor(jsonApiModels, metaData) {
58
+ this.jsonApiModels = jsonApiModels;
59
+ this.metaData = metaData;
60
+ }
61
+ getModels() {
62
+ return this.jsonApiModels;
63
+ }
64
+ getMeta() {
65
+ return this.metaData;
66
+ }
67
+ }
68
+
69
+ class CacheService {
70
+ constructor() {
71
+ this.cache = {};
72
+ }
73
+ get(key) {
74
+ const cachedItem = this.cache[key];
75
+ if (cachedItem && cachedItem.expiration > Date.now()) {
76
+ return cachedItem.data;
77
+ }
78
+ this.delete(key);
79
+ return null;
80
+ }
81
+ set(key, data, expiresInMs) {
82
+ const expiration = Date.now() + expiresInMs;
83
+ this.cache[key] = { data, expiration };
84
+ }
85
+ delete(key) {
86
+ delete this.cache[key];
87
+ }
88
+ clearCacheContainingKeyword(keyword) {
89
+ const keysToDelete = Object.keys(this.cache).filter(key => key.includes(keyword));
90
+ keysToDelete.forEach(key => this.delete(key));
91
+ }
92
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: CacheService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
93
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: CacheService, providedIn: 'root' }); }
94
+ }
95
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: CacheService, decorators: [{
96
+ type: Injectable,
97
+ args: [{
98
+ providedIn: 'root'
99
+ }]
100
+ }], ctorParameters: function () { return []; } });
101
+
102
+ class BaseDatastore {
103
+ // tslint:enable:max-line-length
104
+ get getDirtyAttributes() {
105
+ if (this.datastoreConfig.overrides
106
+ && this.datastoreConfig.overrides.getDirtyAttributes) {
107
+ return this.datastoreConfig.overrides.getDirtyAttributes;
108
+ }
109
+ else {
110
+ return BaseDatastore.getDirtyAttributes;
111
+ }
112
+ }
113
+ get getAllAttributes() {
114
+ if (this.datastoreConfig.overrides
115
+ && this.datastoreConfig.overrides.getAllAttributes) {
116
+ return this.datastoreConfig.overrides.getAllAttributes;
117
+ }
118
+ else {
119
+ return BaseDatastore.getAllAttributes;
120
+ }
121
+ }
122
+ // protected config: DatastoreConfig;
123
+ static getDirtyAttributes(attributesMetadata) {
124
+ const dirtyData = {};
125
+ for (const propertyName in attributesMetadata) {
126
+ if (attributesMetadata.hasOwnProperty(propertyName)) {
127
+ const metadata = attributesMetadata[propertyName];
128
+ if (metadata.hasDirtyAttributes) {
129
+ const attributeName = metadata.serializedName != null ? metadata.serializedName : propertyName;
130
+ dirtyData[attributeName] = metadata.serialisationValue ? metadata.serialisationValue : metadata.newValue;
131
+ }
132
+ }
133
+ }
134
+ return dirtyData;
135
+ }
136
+ static getAllAttributes(attributesMetadata) {
137
+ const dirtyData = {};
138
+ for (const propertyName in attributesMetadata) {
139
+ if (attributesMetadata.hasOwnProperty(propertyName)) {
140
+ const metadata = attributesMetadata[propertyName];
141
+ const attributeName = metadata.serializedName != null ? metadata.serializedName : propertyName;
142
+ dirtyData[attributeName] = metadata.serialisationValue ? metadata.serialisationValue : metadata.newValue;
143
+ }
144
+ }
145
+ return dirtyData;
146
+ }
147
+ constructor(httpClient, cacheService) {
148
+ this.httpClient = httpClient;
149
+ this.cacheService = cacheService;
150
+ // tslint:disable-next-line:variable-name
151
+ this._store = {};
152
+ // tslint:enable:max-line-length
153
+ // tslint:disable-next-line:ban-types
154
+ this.toQueryString = this.datastoreConfig.overrides
155
+ && this.datastoreConfig.overrides.toQueryString ?
156
+ this.datastoreConfig.overrides.toQueryString : this._toQueryString;
157
+ }
158
+ findAll(modelType, params, headers, customUrl) {
159
+ const customHeadhers = this.buildHeaders(headers);
160
+ const htmlParams = this.buildParams(modelType, params);
161
+ const url = this.buildUrl(modelType, customUrl);
162
+ const response = this.httpClient.get(url, { headers: customHeadhers, params: htmlParams, withCredentials: true })
163
+ .pipe(map(res => this.extractQueryData(res, modelType)), catchError(this.handleError));
164
+ return response;
165
+ }
166
+ findRecord(modelType, id, params, headers, customUrl) {
167
+ const customHeadhers = this.buildHeaders(headers);
168
+ let url = this.buildUrl(modelType, customUrl);
169
+ if (id) {
170
+ url += '/' + id;
171
+ }
172
+ const htmlParams = this.buildParams(modelType, params);
173
+ const response = this.httpClient.get(url, { headers: customHeadhers, params: htmlParams, withCredentials: true })
174
+ .pipe(map(res => this.entityToModel(res, modelType, undefined)), catchError(this.handleError));
175
+ return response;
176
+ }
177
+ getCustom(modelType, params, headers, customUrl, customResponseType) {
178
+ const customHeadhers = this.buildHeaders(headers);
179
+ const url = this.buildUrl(modelType, customUrl);
180
+ const htmlParams = this.buildParams(modelType, params);
181
+ if (!customResponseType)
182
+ customResponseType = 'json';
183
+ return this.httpClient.get(url, { headers: customHeadhers, params: htmlParams, withCredentials: true, responseType: customResponseType });
184
+ }
185
+ postCustom(modelType, body, params, headers, customUrl) {
186
+ const customHeadhers = this.buildHeaders(headers);
187
+ const url = this.buildUrl(modelType, customUrl);
188
+ const htmlParams = this.buildParams(modelType, params);
189
+ return this.httpClient.post(url, body, { headers: customHeadhers, params: htmlParams, reportProgress: true, withCredentials: true });
190
+ }
191
+ patchCustom(modelType, body, params, headers, customUrl) {
192
+ const customHeadhers = this.buildHeaders(headers);
193
+ const url = this.buildUrl(modelType, customUrl);
194
+ const htmlParams = this.buildParams(modelType, params);
195
+ return this.httpClient.patch(url, body, { headers: customHeadhers, params: htmlParams, withCredentials: true });
196
+ }
197
+ createRecord(modelType, data) {
198
+ return new modelType(this, data);
199
+ }
200
+ saveRecord(attributesMetadata, model, params, headers, customUrl, customBody) {
201
+ const modelType = model.constructor;
202
+ const modelConfig = model.modelConfig;
203
+ const customHeadhers = this.buildHeaders(headers);
204
+ const url = this.buildUrl(modelType, customUrl);
205
+ const htmlParams = this.buildParams(modelType, params);
206
+ let httpCall;
207
+ const body = customBody || this.modelToEntity(model, attributesMetadata);
208
+ if (model.id) {
209
+ // tslint:disable-next-line:max-line-length
210
+ httpCall = this.httpClient.patch(url + '/' + model.id, body, { headers: customHeadhers, params: htmlParams, withCredentials: true });
211
+ }
212
+ else {
213
+ httpCall = this.httpClient.post(url, body, { headers: customHeadhers, params: htmlParams, withCredentials: true });
214
+ }
215
+ return httpCall
216
+ .pipe(map(res => {
217
+ this.cacheService.clearCacheContainingKeyword(url);
218
+ const data = this.resetMetadataAttributes(res, attributesMetadata, modelType);
219
+ return this.entityToModel(data, modelType);
220
+ }), catchError(this.handleError));
221
+ }
222
+ patchRecord(attributesMetadata, model, origModel, params, headers, customUrl) {
223
+ const modelType = model.constructor;
224
+ const modelConfig = model.modelConfig;
225
+ const customHeadhers = this.buildHeaders(headers);
226
+ const url = this.buildUrl(modelType, customUrl);
227
+ const htmlParams = this.buildParams(modelType, params);
228
+ let httpCall;
229
+ let origData = { id: '' };
230
+ if (origModel)
231
+ origData = this.modelToEntity(origModel, origModel.attributeMetadata, true);
232
+ const newData = this.modelToEntity(model, attributesMetadata, true);
233
+ newData.id = origData.id;
234
+ const patch = compare(origData, newData);
235
+ if (patch.length > 0) {
236
+ httpCall = this.httpClient.patch(url + '/' + model.id, patch, { headers: customHeadhers, params: htmlParams, withCredentials: true });
237
+ return httpCall
238
+ .pipe(map(res => {
239
+ this.cacheService.clearCacheContainingKeyword(url);
240
+ const data = this.resetMetadataAttributes(res, attributesMetadata, modelType);
241
+ return this.entityToModel(data, modelType);
242
+ }), catchError(this.handleError));
243
+ }
244
+ else {
245
+ return new Observable((observer) => {
246
+ observer.next(model);
247
+ observer.complete();
248
+ });
249
+ }
250
+ }
251
+ // getPatch<T extends BaseModel>(
252
+ // model: T,
253
+ // origModel: T): any {
254
+ // }
255
+ replaceRecord(attributesMetadata, model, params, headers, customUrl, customBody) {
256
+ const modelType = model.constructor;
257
+ const modelConfig = model.modelConfig;
258
+ const customHeadhers = this.buildHeaders(headers);
259
+ const url = this.buildUrl(modelType, customUrl);
260
+ const htmlParams = this.buildParams(modelType, params);
261
+ let httpCall;
262
+ const body = customBody || this.modelToEntity(model, attributesMetadata, true);
263
+ if (model.id) {
264
+ httpCall = this.httpClient.put(url + '/' + model.id, body, { headers: customHeadhers, params: htmlParams, withCredentials: true });
265
+ }
266
+ else {
267
+ httpCall = this.httpClient.post(url, body, { headers: customHeadhers, params: htmlParams, withCredentials: true });
268
+ }
269
+ return httpCall
270
+ .pipe(map(res => {
271
+ this.cacheService.clearCacheContainingKeyword(url);
272
+ const data = this.resetMetadataAttributes(res, attributesMetadata, modelType);
273
+ return this.entityToModel(data, modelType);
274
+ }), catchError(this.handleError));
275
+ }
276
+ deleteRecord(modelType, id, headers, customUrl) {
277
+ const customHeadhers = this.buildHeaders(headers);
278
+ let url = this.buildUrl(modelType, customUrl);
279
+ if (!url.includes('share')) {
280
+ url = url + '/' + id;
281
+ }
282
+ // const idParam = new HttpParams().set('id', id);
283
+ return this.httpClient.delete(url, { headers: customHeadhers, withCredentials: true })
284
+ .pipe(map(res => {
285
+ this.cacheService.clearCacheContainingKeyword(url);
286
+ return res;
287
+ }), catchError(this.handleError));
288
+ }
289
+ buildUrl(modelType, customUrl) {
290
+ if (customUrl) {
291
+ return customUrl;
292
+ }
293
+ const modelConfig = Reflect.getMetadata('BaseModelConfig', modelType);
294
+ const baseUrl = modelConfig.baseUrl || this.datastoreConfig.baseUrl;
295
+ const apiVersion = modelConfig.apiVersion || this.datastoreConfig.apiVersion;
296
+ const modelEndpointUrl = modelConfig.modelEndpointUrl || modelConfig.type;
297
+ const url = [baseUrl, apiVersion, modelEndpointUrl].filter((x) => x).join('/');
298
+ return url;
299
+ }
300
+ extractQueryData(res, modelType) {
301
+ let result;
302
+ const body = res;
303
+ const models = [];
304
+ for (const data of body.data) {
305
+ const model = this.entityToModel(data, modelType, undefined);
306
+ models.push(model);
307
+ }
308
+ result = new BaseQueryData(models, this.parseMeta(body, modelType));
309
+ return result;
310
+ }
311
+ deserializeModel(modelType, data) {
312
+ data = this.transformSerializedNamesToPropertyNames(modelType, data);
313
+ return new modelType(this, data);
314
+ }
315
+ handleError(error) {
316
+ if (error.error instanceof ErrorEvent) {
317
+ // A client-side or network error occurred. Handle it accordingly.
318
+ // console.error('An error occurred:', error.error.message);
319
+ }
320
+ else {
321
+ // The backend returned an unsuccessful response code.
322
+ // The response body may contain clues as to what went wrong,
323
+ // console.error(
324
+ // 'Backend returned code ${error.status}, ' +
325
+ // 'body was: ${error.error}');
326
+ }
327
+ // return an observable with a user-facing error message
328
+ return throwError(error);
329
+ }
330
+ parseMeta(body, modelType) {
331
+ const metaModel = Reflect.getMetadata('BaseModelConfig', modelType).meta;
332
+ return new metaModel(body);
333
+ }
334
+ resetMetadataAttributes(res, attributesMetadata, modelType) {
335
+ // TODO check why is attributesMetadata from the arguments never used
336
+ for (const propertyName in attributesMetadata) {
337
+ if (attributesMetadata.hasOwnProperty(propertyName)) {
338
+ const metadata = attributesMetadata[propertyName];
339
+ if (metadata.hasDirtyAttributes) {
340
+ metadata.hasDirtyAttributes = false;
341
+ }
342
+ }
343
+ }
344
+ if (res) {
345
+ res.attributeMetadata = attributesMetadata;
346
+ }
347
+ return res;
348
+ }
349
+ get datastoreConfig() {
350
+ const configFromDecorator = Reflect.getMetadata('BaseDatastoreConfig', this.constructor);
351
+ return Object.assign(configFromDecorator, this.config);
352
+ }
353
+ transformSerializedNamesToPropertyNames(modelType, attributes) {
354
+ const serializedNameToPropertyName = this.getModelPropertyNames(modelType.prototype);
355
+ const properties = {};
356
+ Object.keys(serializedNameToPropertyName).forEach((serializedName) => {
357
+ if (attributes[serializedName] !== null && attributes[serializedName] !== undefined) {
358
+ properties[serializedNameToPropertyName[serializedName]] = attributes[serializedName];
359
+ }
360
+ });
361
+ return properties;
362
+ }
363
+ getModelPropertyNames(model) {
364
+ return Reflect.getMetadata('AttributeMapping', model);
365
+ }
366
+ buildHeaders(customHeaders) {
367
+ const headers = {
368
+ Accept: 'application/json-patch+json',
369
+ // 'Content-Type': 'application/vnd.api+json',
370
+ 'Content-Type': 'application/json-patch+json'
371
+ };
372
+ if (customHeaders && customHeaders.keys().length) {
373
+ // tslint:disable-next-line:variable-name
374
+ Object.assign({}, headers, customHeaders.keys().map(header_name => {
375
+ headers['' + header_name] = customHeaders.get(header_name);
376
+ }));
377
+ }
378
+ return new HttpHeaders(headers);
379
+ }
380
+ buildParams(modelType, params) {
381
+ let httpParams = new HttpParams();
382
+ if (params) {
383
+ Object.keys(params)
384
+ .filter(key => {
385
+ const v = params[key];
386
+ return (Array.isArray(v) || typeof v === 'string') ?
387
+ (v.length > 0) :
388
+ (v !== null && v !== undefined);
389
+ })
390
+ .forEach(key => {
391
+ httpParams = httpParams.set(key, params[key]);
392
+ });
393
+ }
394
+ const modelConfig = Reflect.getMetadata('BaseModelConfig', modelType);
395
+ httpParams = httpParams.set('bypassCache', modelConfig.bypassCache || false);
396
+ return httpParams;
397
+ }
398
+ entityToModel(res, modelType, model) {
399
+ return this.extractRecordDataJson(res, modelType, model);
400
+ }
401
+ extractRecordDataJson(res, modelType, model) {
402
+ const body = res;
403
+ if (!body) {
404
+ throw new Error('no body in response');
405
+ }
406
+ if (model) {
407
+ Object.assign(model, body);
408
+ }
409
+ const deserializedModel = model || this.deserializeModel(modelType, body.data || body);
410
+ return deserializedModel;
411
+ }
412
+ modelToEntity(model, attributesMetadata, allAttributes = false) {
413
+ let attributes;
414
+ if (allAttributes) {
415
+ attributes = this.getAllAttributes(attributesMetadata, model);
416
+ }
417
+ else {
418
+ attributes = this.getDirtyAttributes(attributesMetadata, model);
419
+ }
420
+ // this.getRelationships(model, attributes);
421
+ return attributes;
422
+ }
423
+ _toQueryString(params) {
424
+ return qs.stringify(params, { arrayFormat: 'brackets' });
425
+ }
426
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseDatastore, deps: [{ token: i1.HttpClient }, { token: CacheService }], target: i0.ɵɵFactoryTarget.Injectable }); }
427
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseDatastore }); }
428
+ }
429
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseDatastore, decorators: [{
430
+ type: Injectable
431
+ }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: CacheService }]; } });
432
+
433
+ class BaseService {
434
+ constructor(datastore) {
435
+ this.datastore = datastore;
436
+ }
437
+ setModelType(modelType) {
438
+ this.modelType = modelType;
439
+ }
440
+ get(id, customInclude = '') {
441
+ const response = this.datastore.findRecord(this.modelType, id, { customInclude });
442
+ return response;
443
+ }
444
+ getAll(page, pageSize, sort = '', filters = '', customInclude = '') {
445
+ const response = this.datastore.findAll(this.modelType, {
446
+ Page: page,
447
+ PageSize: pageSize,
448
+ Sorts: sort,
449
+ Filters: filters,
450
+ customInclude
451
+ });
452
+ return response;
453
+ }
454
+ delete(id) {
455
+ const response = this.datastore.deleteRecord(this.modelType, id);
456
+ return response;
457
+ }
458
+ getCustom(params, headers, customUrl, customResponseType) {
459
+ return this.datastore.getCustom(this.modelType, params, headers, customUrl, customResponseType);
460
+ }
461
+ postCustom(body, params, headers, customUrl) {
462
+ return this.datastore.postCustom(this.modelType, body, params, headers, customUrl);
463
+ }
464
+ patchCustom(body, params, headers, customUrl) {
465
+ return this.datastore.patchCustom(this.modelType, body, params, headers, customUrl);
466
+ }
467
+ // checkIfPropertyUnique(property: string, value: any): Observable<boolean> {
468
+ // }
469
+ save(docTypeOrFormGroup, id, origModel) {
470
+ if (id == null) {
471
+ let fromModel;
472
+ if (docTypeOrFormGroup instanceof UntypedFormGroup) {
473
+ fromModel = this.fromFormGroup(docTypeOrFormGroup, id);
474
+ }
475
+ else {
476
+ fromModel = docTypeOrFormGroup;
477
+ }
478
+ const data = this.datastore.createRecord(this.modelType, fromModel);
479
+ return data.save();
480
+ }
481
+ else {
482
+ return this.patch(docTypeOrFormGroup, origModel, id);
483
+ }
484
+ }
485
+ patch(docTypeOrFormGroup, origModel, id) {
486
+ let fromModel;
487
+ if (docTypeOrFormGroup instanceof UntypedFormGroup) {
488
+ fromModel = this.fromFormGroup(docTypeOrFormGroup, id);
489
+ }
490
+ else {
491
+ fromModel = docTypeOrFormGroup;
492
+ }
493
+ const data = this.datastore.createRecord(this.modelType, fromModel);
494
+ return data.patch(origModel);
495
+ }
496
+ newModel(data) {
497
+ return new this.modelType(this.datastore, data);
498
+ }
499
+ toFormGroup(fb, fromModel) {
500
+ if (fromModel === undefined) {
501
+ fromModel = this.newModel();
502
+ }
503
+ return fromModel.getFromGroup(fb);
504
+ }
505
+ fromFormGroup(formGroup, id) {
506
+ // const saveModel = this.newModel(formGroup.getRawValue());
507
+ // saveModel.id = id ? id : null;
508
+ // return saveModel;
509
+ const saveModel = this.newModel();
510
+ saveModel.getModelFromFormGroup(formGroup);
511
+ saveModel.id = id ? id : null;
512
+ return saveModel;
513
+ }
514
+ getSelectValues(property) {
515
+ return null;
516
+ }
517
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseService, deps: [{ token: BaseDatastore }], target: i0.ɵɵFactoryTarget.Injectable }); }
518
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseService, providedIn: 'root' }); }
519
+ }
520
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseService, decorators: [{
521
+ type: Injectable,
522
+ args: [{
523
+ providedIn: 'root'
524
+ }]
525
+ }], ctorParameters: function () { return [{ type: BaseDatastore }]; } });
526
+
527
+ /**
528
+ * Async modal dialog service
529
+ * DialogService makes this app easier to test by faking this service.
530
+ * TODO: better modal implementation that doesn't use window.confirm
531
+ */
532
+ class DialogService {
533
+ /**
534
+ * Ask user to confirm an action. `message` explains the action and choices.
535
+ * Returns observable resolving to `true`=confirm or `false`=cancel
536
+ */
537
+ constructor() { }
538
+ confirm(message, text, confirmButtonText = 'Delete', cancelButtonText = 'Cancel') {
539
+ const confirmation = Swal.fire({
540
+ title: message || 'Are you sure?',
541
+ icon: 'warning',
542
+ text: text || '',
543
+ showCancelButton: true,
544
+ confirmButtonText: confirmButtonText,
545
+ cancelButtonText: cancelButtonText,
546
+ customClass: {
547
+ confirmButton: 'btn btn-red btn-fill btn-wd',
548
+ cancelButton: 'btn btn-grey btn-fill btn-wd',
549
+ },
550
+ buttonsStyling: false,
551
+ reverseButtons: true
552
+ })
553
+ .then((result) => {
554
+ if (result.value) {
555
+ return true;
556
+ }
557
+ else {
558
+ return false;
559
+ }
560
+ }).catch();
561
+ return from(confirmation);
562
+ }
563
+ showSaveMessage(message, title) {
564
+ const confirmation = Swal.fire({
565
+ icon: 'success',
566
+ title: message,
567
+ timer: 2000,
568
+ showConfirmButton: false,
569
+ // customClass: 'overflow-hidden',
570
+ buttonsStyling: false
571
+ }).then(() => {
572
+ return true;
573
+ }, () => {
574
+ return false;
575
+ }).catch();
576
+ return from(confirmation);
577
+ }
578
+ showRegisteredMessage(message, title) {
579
+ const confirmation = Swal.fire({
580
+ icon: 'success',
581
+ title: message,
582
+ showConfirmButton: true,
583
+ customClass: {
584
+ confirmButton: 'btn btn-success',
585
+ },
586
+ buttonsStyling: false
587
+ }).then(() => {
588
+ return true;
589
+ }, () => {
590
+ return false;
591
+ }).catch();
592
+ return from(confirmation);
593
+ }
594
+ // notification(message?: string, type?: NotificationType, fromPosition?: NotificationFrom, align?: NotificationAlign, timer?: number) {
595
+ // if (!type) {
596
+ // type = NotificationType.success;
597
+ // }
598
+ // if (!fromPosition) {
599
+ // fromPosition = NotificationFrom.bottom;
600
+ // }
601
+ // if (!align) {
602
+ // align = NotificationAlign.center;
603
+ // }
604
+ // if (!timer) {
605
+ // timer = 3000;
606
+ // }
607
+ // $.notify({
608
+ // icon: 'notifications',
609
+ // message: message
610
+ // }, {
611
+ // type: type,
612
+ // timer: 3000,
613
+ // placement: {
614
+ // from: from,
615
+ // align: align
616
+ // }
617
+ // });
618
+ // }
619
+ showErrorMessage(e, message) {
620
+ if (!message) {
621
+ message = 'Validation errors';
622
+ }
623
+ if (e instanceof HttpErrorResponse) {
624
+ // Validation errors
625
+ if (e.status === 400) {
626
+ const errors = e.error.errors;
627
+ if (errors) {
628
+ errors.forEach(error => {
629
+ message += error.field + ' ' + error.detail + '\n';
630
+ });
631
+ // message = errors.detail;
632
+ // if (detail.relationships) {
633
+ // detail.relationships.forEach(relation => {
634
+ // console.log(relation);
635
+ // });
636
+ // }
637
+ }
638
+ }
639
+ }
640
+ const confirmation = Swal.fire({
641
+ icon: 'error',
642
+ title: message,
643
+ // timer: 2000,
644
+ showConfirmButton: true,
645
+ customClass: {
646
+ confirmButton: 'btn btn-success',
647
+ },
648
+ buttonsStyling: false
649
+ }).then(() => {
650
+ return true;
651
+ }, () => {
652
+ return false;
653
+ }).catch();
654
+ return from(confirmation);
655
+ }
656
+ getTextTranslation(translationKey) {
657
+ // // const result = await promise;
658
+ // // return result;
659
+ // const result = this.translate.instant(translationKey);
660
+ // if (result === translationKey) {
661
+ return translationKey;
662
+ // }
663
+ // return result;
664
+ }
665
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: DialogService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
666
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: DialogService }); }
667
+ }
668
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: DialogService, decorators: [{
669
+ type: Injectable
670
+ }], ctorParameters: function () { return []; } });
671
+
672
+ class BaseFormEditComponent {
673
+ constructor(fb, router, route, modelService, dialogService, translate, location) {
674
+ this.fb = fb;
675
+ this.router = router;
676
+ this.route = route;
677
+ this.modelService = modelService;
678
+ this.dialogService = dialogService;
679
+ this.translate = translate;
680
+ this.location = location;
681
+ this.isLoading = true;
682
+ this.changeUrlRoute = true;
683
+ this.generateForm(this.modelService.newModel());
684
+ }
685
+ afterSave(model) {
686
+ return new Observable((observer) => {
687
+ observer.next(model);
688
+ observer.complete();
689
+ });
690
+ }
691
+ beforeSave(model) {
692
+ return new Observable((observer) => {
693
+ observer.next(model);
694
+ observer.complete();
695
+ });
696
+ }
697
+ ngOnInit() {
698
+ this.initForm();
699
+ }
700
+ initForm(customInclude = '', newModelId = null, model = null) {
701
+ if (model === null) {
702
+ this.modelId = this.route.snapshot.paramMap.get('id') ?? newModelId;
703
+ this.isEdit = false;
704
+ if (this.modelId) {
705
+ this.modelService.get(this.modelId, customInclude).subscribe((value) => {
706
+ this.isEdit = true;
707
+ this.generateForm(value);
708
+ });
709
+ }
710
+ else {
711
+ if (this.changeUrlRoute) {
712
+ const addUrl = this.router.createUrlTree([]).toString();
713
+ this.editRoute = this.router.createUrlTree([addUrl.replace('add', 'edit')]).toString();
714
+ }
715
+ // }
716
+ this.generateForm(this.modelService.newModel());
717
+ }
718
+ }
719
+ else {
720
+ this.modelId = model.id;
721
+ this.isEdit = true;
722
+ this.generateForm(model);
723
+ }
724
+ }
725
+ generateForm(model) {
726
+ this.isLoading = false;
727
+ this.modelId = model.id;
728
+ this.model = model;
729
+ this.baseForm = this.modelService.toFormGroup(this.fb, model);
730
+ this.afterFormGenerated();
731
+ }
732
+ afterFormGenerated() {
733
+ }
734
+ getFromGroup(formGroup = null) {
735
+ if (!formGroup)
736
+ return this.baseForm;
737
+ if (formGroup instanceof UntypedFormGroup)
738
+ return formGroup;
739
+ return this.baseForm.controls[formGroup];
740
+ }
741
+ validateAllFormFields(formGroup = null) {
742
+ const fg = this.getFromGroup(formGroup);
743
+ Object.keys(fg.controls).forEach(field => {
744
+ // console.log(field);
745
+ const control = fg.get(field);
746
+ if (control instanceof UntypedFormControl) {
747
+ control.markAsTouched({ onlySelf: true });
748
+ }
749
+ else if (control instanceof UntypedFormGroup) {
750
+ this.validateAllFormFields(control);
751
+ }
752
+ });
753
+ }
754
+ isFieldValid(field, formGroup = null) {
755
+ const fg = this.getFromGroup(formGroup);
756
+ const filedControl = fg.get(field);
757
+ return !filedControl.valid && filedControl.touched;
758
+ }
759
+ isFieldValidFromArray(arrayIndex, field, arrayName = 'formArray') {
760
+ const fieldControl = this.baseForm.get(arrayName).get([arrayIndex]).get(field);
761
+ return !fieldControl.valid && fieldControl.touched;
762
+ }
763
+ displayFieldCss(field) {
764
+ return {
765
+ 'has-error': this.isFieldValid(field),
766
+ 'has-feedback': this.isFieldValid(field)
767
+ };
768
+ }
769
+ onCancel() {
770
+ this.router.navigate([this.cancelRoute]);
771
+ }
772
+ onSave() {
773
+ this.saveModel(this.baseForm);
774
+ }
775
+ saveModel(formGroup = null) {
776
+ const fg = this.getFromGroup(formGroup);
777
+ const that = this;
778
+ if (fg) {
779
+ if (fg.valid) {
780
+ this.beforeSave(this.model).subscribe(_ => {
781
+ this.modelService.save(this.baseForm, this.modelId, this.model).subscribe((newModel) => {
782
+ this.model = newModel;
783
+ this.modelId = newModel.id;
784
+ if (this.editRoute) {
785
+ this.isEdit = true;
786
+ if (this.changeUrlRoute) {
787
+ const url = this.router.createUrlTree([this.editRoute, this.modelId]).toString();
788
+ this.location.replaceState(url);
789
+ }
790
+ }
791
+ this.afterSave(newModel).subscribe((val) => {
792
+ this.dialogService.showSaveMessage('Your changes were saved successfully.').subscribe(d => {
793
+ fg.markAsPristine();
794
+ });
795
+ });
796
+ }, err => {
797
+ this.serverErrors(err);
798
+ });
799
+ });
800
+ }
801
+ else {
802
+ this.validateAllFormFields(formGroup);
803
+ }
804
+ }
805
+ }
806
+ serverErrors(err) {
807
+ if (err.error) {
808
+ if (err.error.errors) {
809
+ const validationErrors = err.error.errors;
810
+ if (Array.isArray(validationErrors)) {
811
+ validationErrors.forEach(prop => {
812
+ const formControl = this.baseForm.get(prop);
813
+ if (formControl) {
814
+ // activate the error message
815
+ formControl.setErrors({
816
+ serverError: validationErrors[prop].join('\n')
817
+ });
818
+ }
819
+ });
820
+ }
821
+ else {
822
+ const keys = Object.keys(validationErrors);
823
+ keys.forEach(prop => {
824
+ const formControl = this.baseForm.get(prop);
825
+ if (formControl) {
826
+ // activate the error message
827
+ formControl.setErrors({
828
+ serverError: validationErrors[prop].join('\n')
829
+ });
830
+ }
831
+ });
832
+ }
833
+ }
834
+ }
835
+ }
836
+ canDeactivate() {
837
+ // Allow synchronous navigation (`true`) if no crisis or the crisis is unchanged
838
+ if (!this.baseForm.dirty) {
839
+ return true;
840
+ }
841
+ // Otherwise ask the user with the dialog service and return its
842
+ // observable which resolves to true or false when the user decides
843
+ return this.dialogService.confirm('Discard changes ?', null, 'Discard');
844
+ }
845
+ getFiledName(filedTranslationKey) {
846
+ return { field: this.translate.instant(filedTranslationKey) };
847
+ }
848
+ getCustomErrorMessage(error, fieldLabel) {
849
+ return '';
850
+ }
851
+ getErrorMessageFromArray(arrayIndex, field, filedTranslationKey, arrayName = 'formArray') {
852
+ const fieldControl = this.baseForm.get(arrayName).get([arrayIndex]).get(field);
853
+ return this.getErrorMessageForField(fieldControl, filedTranslationKey);
854
+ }
855
+ getErrorMessage(field, filedTranslationKey, formGroup = null) {
856
+ const fg = this.getFromGroup(formGroup);
857
+ return this.getErrorMessageForField(fg.get(field), filedTranslationKey);
858
+ }
859
+ getErrorMessageForField(fieldControl, filedTranslationKey) {
860
+ const error = fieldControl.errors;
861
+ const fieldLabel = this.translate.instant(filedTranslationKey);
862
+ let rvalue = '';
863
+ if (error !== null) {
864
+ if (error['required'] === true) {
865
+ rvalue = this.translate.instant('General.Field.Required', { field: fieldLabel });
866
+ }
867
+ if (error['minlength']) {
868
+ rvalue = this.translate.instant('General.Field.MinLength', { field: fieldLabel, requiredLength: error.minlength.requiredLength });
869
+ }
870
+ if (error['email'] === true) {
871
+ rvalue = this.translate.instant('General.Field.InvalidEmail');
872
+ }
873
+ if (error['url'] === true) {
874
+ rvalue = this.translate.instant('General.Field.InvalidUrl');
875
+ }
876
+ if (error['serverError']) {
877
+ rvalue = error['serverError'];
878
+ }
879
+ if (rvalue === '') {
880
+ rvalue = this.getCustomErrorMessage(error, fieldLabel);
881
+ }
882
+ }
883
+ return rvalue;
884
+ }
885
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseFormEditComponent, deps: [{ token: i1$1.UntypedFormBuilder }, { token: i2.Router }, { token: i2.ActivatedRoute }, { token: BaseService }, { token: DialogService }, { token: i1$2.TranslateService }, { token: i6.Location }], target: i0.ɵɵFactoryTarget.Component }); }
886
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.1", type: BaseFormEditComponent, selector: "app-base.form.edit", ngImport: i0, template: '', isInline: true }); }
887
+ }
888
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: BaseFormEditComponent, decorators: [{
889
+ type: Component,
890
+ args: [{
891
+ selector: 'app-base.form.edit',
892
+ template: ''
893
+ }]
894
+ }], ctorParameters: function () { return [{ type: i1$1.UntypedFormBuilder }, { type: i2.Router }, { type: i2.ActivatedRoute }, { type: BaseService }, { type: DialogService }, { type: i1$2.TranslateService }, { type: i6.Location }]; } });
895
+
896
+ var GridLayoutFormat;
897
+ (function (GridLayoutFormat) {
898
+ GridLayoutFormat[GridLayoutFormat["none"] = 0] = "none";
899
+ GridLayoutFormat[GridLayoutFormat["date"] = 1] = "date";
900
+ GridLayoutFormat[GridLayoutFormat["number"] = 2] = "number";
901
+ GridLayoutFormat[GridLayoutFormat["percent"] = 3] = "percent";
902
+ GridLayoutFormat[GridLayoutFormat["picture"] = 4] = "picture";
903
+ })(GridLayoutFormat || (GridLayoutFormat = {}));
904
+ var CellTextAlign;
905
+ (function (CellTextAlign) {
906
+ CellTextAlign["left"] = "left";
907
+ CellTextAlign["center"] = "center";
908
+ CellTextAlign["right"] = "right";
909
+ })(CellTextAlign || (CellTextAlign = {}));
910
+
911
+ // tslint:disable-next-line:variable-name
912
+ const AttributeMetadata = Symbol('AttributeMetadata');
913
+
914
+ class DateConverter {
915
+ mask(value) {
916
+ if (value instanceof Date && !isNaN(value.getTime())) {
917
+ return value;
918
+ }
919
+ const d = parseISO(value);
920
+ if (d instanceof Date && !isNaN(d.getTime())) {
921
+ return d;
922
+ }
923
+ else {
924
+ return value;
925
+ }
926
+ }
927
+ unmask(value) {
928
+ // const result = format(value, 'YYYY-MM-DDTHH:mm:ssZ');
929
+ return value;
930
+ }
931
+ }
932
+
933
+ function Attribute(options = {}) {
934
+ return (target, propertyName) => {
935
+ const converter = (dataType, value, forSerialisation = false) => {
936
+ let attrConverter;
937
+ if (dataType) {
938
+ if (options.converter) {
939
+ attrConverter = options.converter;
940
+ }
941
+ else if (dataType === Date) {
942
+ attrConverter = new DateConverter();
943
+ }
944
+ else {
945
+ const datatype = new dataType();
946
+ if (datatype.mask && datatype.unmask) {
947
+ attrConverter = datatype;
948
+ }
949
+ }
950
+ if (attrConverter) {
951
+ if (!forSerialisation) {
952
+ return attrConverter.mask(value);
953
+ }
954
+ return attrConverter.unmask(value);
955
+ }
956
+ }
957
+ return value;
958
+ };
959
+ const saveAnnotations = () => {
960
+ const metadata = Reflect.getMetadata('Attribute', target) || {};
961
+ metadata[propertyName] = {
962
+ marked: true
963
+ };
964
+ Reflect.defineMetadata('Attribute', metadata, target);
965
+ const mappingMetadata = Reflect.getMetadata('AttributeMapping', target) || {};
966
+ const serializedPropertyName = options.serializedName !== undefined ? options.serializedName : propertyName;
967
+ mappingMetadata[serializedPropertyName] = propertyName;
968
+ Reflect.defineMetadata('AttributeMapping', mappingMetadata, target);
969
+ const requiredMetadata = Reflect.getMetadata('AttributeRequired', target) || {};
970
+ requiredMetadata[serializedPropertyName] = options.required !== undefined ? options.required : false;
971
+ Reflect.defineMetadata('AttributeRequired', requiredMetadata, target);
972
+ const defaultMetadata = Reflect.getMetadata('AttributedefaultValue', target) || {};
973
+ defaultMetadata[serializedPropertyName] = options.defaultValue !== undefined ? options.defaultValue : null;
974
+ Reflect.defineMetadata('AttributedefaultValue', defaultMetadata, target);
975
+ const formSubGroupMetadata = Reflect.getMetadata('AttributeformSubGroup', target) || {};
976
+ formSubGroupMetadata[serializedPropertyName] = options.formSubGroup !== undefined ? options.formSubGroup : null;
977
+ Reflect.defineMetadata('AttributeformSubGroup', formSubGroupMetadata, target);
978
+ };
979
+ const setMetadata = (hasDirtyAttributes, instance, oldValue, newValue, isNew) => {
980
+ const targetType = Reflect.getMetadata('design:type', target, propertyName);
981
+ if (!instance[AttributeMetadata]) {
982
+ instance[AttributeMetadata] = {};
983
+ }
984
+ const propertyHasDirtyAttributes = typeof oldValue === 'undefined' && !isNew ? false : hasDirtyAttributes;
985
+ instance[AttributeMetadata][propertyName] = {
986
+ newValue,
987
+ oldValue,
988
+ serializedName: options.serializedName,
989
+ hasDirtyAttributes: propertyHasDirtyAttributes,
990
+ serialisationValue: converter(targetType, newValue, true)
991
+ };
992
+ };
993
+ const getter = function () {
994
+ return this['_' + propertyName];
995
+ };
996
+ const setter = function (newVal) {
997
+ const targetType = Reflect.getMetadata('design:type', target, propertyName);
998
+ const convertedValue = converter(targetType, newVal);
999
+ if (convertedValue !== this['_' + propertyName]) {
1000
+ setMetadata(true, this, this['_' + propertyName], newVal, !this.id);
1001
+ this['_' + propertyName] = convertedValue;
1002
+ }
1003
+ };
1004
+ if (delete target[propertyName]) {
1005
+ saveAnnotations();
1006
+ Object.defineProperty(target, propertyName, {
1007
+ get: getter,
1008
+ set: setter,
1009
+ enumerable: true,
1010
+ configurable: true
1011
+ });
1012
+ }
1013
+ };
1014
+ }
1015
+
1016
+ function BaseDatastoreConfig(config = {}) {
1017
+ // tslint:disable-next-line:only-arrow-functions
1018
+ return (target) => {
1019
+ Reflect.defineMetadata('BaseDatastoreConfig', config, target);
1020
+ };
1021
+ }
1022
+
1023
+ class BaseMetaModel {
1024
+ constructor(response) {
1025
+ this.links = response.links || [];
1026
+ this.meta = response.meta;
1027
+ }
1028
+ }
1029
+
1030
+ function BaseModelConfig(config = {}) {
1031
+ return (target) => {
1032
+ if (typeof config['meta'] === 'undefined' || config['meta'] == null) {
1033
+ config['meta'] = BaseMetaModel;
1034
+ }
1035
+ Reflect.defineMetadata('BaseModelConfig', config, target);
1036
+ };
1037
+ }
1038
+
1039
+ function CustomType(config = {}) {
1040
+ return (target, propertyName) => {
1041
+ const annotations = Reflect.getMetadata('CustomType', target) || [];
1042
+ annotations.push({
1043
+ propertyName,
1044
+ relationship: config.key || propertyName
1045
+ });
1046
+ Reflect.defineMetadata('CustomType', annotations, target);
1047
+ };
1048
+ }
1049
+
1050
+ class TranslatedElementDirective {
1051
+ constructor(viewRef, templateRef) {
1052
+ this.viewRef = viewRef;
1053
+ this.templateRef = templateRef;
1054
+ }
1055
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: TranslatedElementDirective, deps: [{ token: i0.ViewContainerRef }, { token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive }); }
1056
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.1", type: TranslatedElementDirective, selector: "[translatedElement]", inputs: { elementKey: ["translatedElement", "elementKey"] }, ngImport: i0 }); }
1057
+ }
1058
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: TranslatedElementDirective, decorators: [{
1059
+ type: Directive,
1060
+ args: [{
1061
+ selector: '[translatedElement]',
1062
+ }]
1063
+ }], ctorParameters: function () { return [{ type: i0.ViewContainerRef }, { type: i0.TemplateRef }]; }, propDecorators: { elementKey: [{
1064
+ type: Input,
1065
+ args: ['translatedElement']
1066
+ }] } });
1067
+
1068
+ const TOKEN_START_DEMARC = '{{';
1069
+ const TOKEN_END_DEMARC = '}}';
1070
+ // adapted from @kasperlauge's solution in https://github.com/ngx-translate/core/issues/223
1071
+ class TranslatedContentDirective {
1072
+ constructor(viewRef, renderer, translateService, changeDetectorRef) {
1073
+ this.viewRef = viewRef;
1074
+ this.renderer = renderer;
1075
+ this.translateService = translateService;
1076
+ this.changeDetectorRef = changeDetectorRef;
1077
+ this.subs = [];
1078
+ }
1079
+ ngOnInit() {
1080
+ this.rawTranslation = merge(this.translateService.get(this.translationKey), this.translateService.onLangChange.asObservable().pipe(switchMap(() => this.translateService.get(this.translationKey))));
1081
+ }
1082
+ ngAfterContentInit() {
1083
+ // QueryList.changes doesn't re-emit after its initial value, which we have by now
1084
+ // BehaviorSubjects re-emit their initial value on subscription, so we get what we need by merging
1085
+ // the BehaviorSubject and the QueryList.changes observable
1086
+ const elementsSubject = new BehaviorSubject(this.elements.toArray());
1087
+ const elementsChanges = merge(elementsSubject, this.elements.changes);
1088
+ this.translationData = combineLatest(this.rawTranslation, elementsChanges)
1089
+ .pipe(map(([rawTranslation]) => {
1090
+ return {
1091
+ elements: this.elements.toArray(),
1092
+ rawTranslation,
1093
+ };
1094
+ }));
1095
+ this.subs.push(this.translationData.subscribe(this.render.bind(this)));
1096
+ }
1097
+ render(translationData) {
1098
+ if (!translationData.rawTranslation || translationData.rawTranslation === this.translationKey) {
1099
+ throw new Error(`No resource matching the key '${this.translationKey}'`);
1100
+ }
1101
+ while (this.viewRef.element.nativeElement.firstChild) {
1102
+ this.renderer.removeChild(this.viewRef.element.nativeElement, this.viewRef.element.nativeElement.firstChild);
1103
+ }
1104
+ let lastTokenEnd = 0;
1105
+ while (lastTokenEnd < translationData.rawTranslation.length) {
1106
+ const tokenStartDemarc = translationData.rawTranslation.indexOf(TOKEN_START_DEMARC, lastTokenEnd);
1107
+ if (tokenStartDemarc < 0) {
1108
+ break;
1109
+ }
1110
+ const tokenStart = tokenStartDemarc + TOKEN_START_DEMARC.length;
1111
+ const tokenEnd = translationData.rawTranslation.indexOf(TOKEN_END_DEMARC, tokenStart);
1112
+ if (tokenEnd < 0) {
1113
+ throw new Error(`Encountered unterminated token in translation string '${this.translationKey}'`);
1114
+ }
1115
+ const tokenEndDemarc = tokenEnd + TOKEN_END_DEMARC.length;
1116
+ const precedingText = translationData.rawTranslation.substring(lastTokenEnd, tokenStartDemarc);
1117
+ const precedingTextElement = this.renderer.createText(precedingText);
1118
+ this.renderer.appendChild(this.viewRef.element.nativeElement, precedingTextElement);
1119
+ const elementKey = translationData.rawTranslation.substring(tokenStart, tokenEnd);
1120
+ const embeddedElementTemplate = translationData.elements.find(element => element.elementKey === elementKey);
1121
+ if (embeddedElementTemplate) {
1122
+ const embeddedElementView = embeddedElementTemplate.viewRef.createEmbeddedView(embeddedElementTemplate.templateRef);
1123
+ this.renderer.appendChild(this.viewRef.element.nativeElement, embeddedElementView.rootNodes[0]);
1124
+ }
1125
+ else {
1126
+ const missingTokenText = translationData.rawTranslation.substring(tokenStartDemarc, tokenEndDemarc);
1127
+ const missingTokenElement = this.renderer.createText(missingTokenText);
1128
+ this.renderer.appendChild(this.viewRef.element.nativeElement, missingTokenElement);
1129
+ }
1130
+ lastTokenEnd = tokenEndDemarc;
1131
+ }
1132
+ const trailingText = translationData.rawTranslation.substring(lastTokenEnd);
1133
+ const trailingTextElement = this.renderer.createText(trailingText);
1134
+ this.renderer.appendChild(this.viewRef.element.nativeElement, trailingTextElement);
1135
+ // in case the rendering happens outside of a change detection event, this ensures that any translations in the
1136
+ // embedded elements are rendered
1137
+ this.changeDetectorRef.detectChanges();
1138
+ }
1139
+ ngOnDestroy() {
1140
+ this.subs.forEach(sub => sub.unsubscribe());
1141
+ }
1142
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: TranslatedContentDirective, deps: [{ token: i0.ViewContainerRef }, { token: i0.Renderer2 }, { token: i1$2.TranslateService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); }
1143
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.1", type: TranslatedContentDirective, selector: "[appTranslatedContent]", inputs: { translationKey: ["appTranslatedContent", "translationKey"] }, queries: [{ propertyName: "elements", predicate: TranslatedElementDirective }], ngImport: i0 }); }
1144
+ }
1145
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: TranslatedContentDirective, decorators: [{
1146
+ type: Directive,
1147
+ args: [{
1148
+ selector: '[appTranslatedContent]',
1149
+ }]
1150
+ }], ctorParameters: function () { return [{ type: i0.ViewContainerRef }, { type: i0.Renderer2 }, { type: i1$2.TranslateService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { translationKey: [{
1151
+ type: Input,
1152
+ args: ['appTranslatedContent']
1153
+ }], elements: [{
1154
+ type: ContentChildren,
1155
+ args: [TranslatedElementDirective]
1156
+ }] } });
1157
+
1158
+ class CacheInterceptor {
1159
+ constructor(expirationTime, cacheService) {
1160
+ this.expirationTime = expirationTime;
1161
+ this.cacheService = cacheService;
1162
+ this.cache = new Map();
1163
+ }
1164
+ intercept(request, next) {
1165
+ const bypassCache = request.params.get('bypassCache') || false;
1166
+ if (bypassCache || request.method !== 'GET') {
1167
+ return next.handle(request);
1168
+ }
1169
+ if (!bypassCache) {
1170
+ const cachedResponse = this.cacheService.get(request.urlWithParams);
1171
+ if (cachedResponse) {
1172
+ return of(cachedResponse.clone());
1173
+ //return cachedResponse;
1174
+ }
1175
+ }
1176
+ return next.handle(request).pipe(tap((event) => {
1177
+ if (event instanceof HttpResponse) {
1178
+ this.cacheService.set(request.urlWithParams, event.clone(), this.expirationTime);
1179
+ }
1180
+ }));
1181
+ // const cachedItem = this.cache.get(request.url);
1182
+ // if (cachedItem && cachedItem.expiration > Date.now()) {
1183
+ // return of(cachedItem.response.clone());
1184
+ // }
1185
+ // return next.handle(request).pipe(
1186
+ // tap(event => {
1187
+ // if (event instanceof HttpResponse) {
1188
+ // this.cache.set(request.url, { response: event.clone(), expiration: Date.now() + this.expirationTime });
1189
+ // }
1190
+ // })
1191
+ // );
1192
+ }
1193
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: CacheInterceptor, deps: [{ token: 'CACHE_EXPIRATION_TIME' }, { token: CacheService }], target: i0.ɵɵFactoryTarget.Injectable }); }
1194
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: CacheInterceptor }); }
1195
+ }
1196
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: CacheInterceptor, decorators: [{
1197
+ type: Injectable
1198
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1199
+ type: Inject,
1200
+ args: ['CACHE_EXPIRATION_TIME']
1201
+ }] }, { type: CacheService }]; } });
1202
+
1203
+ class BaseModel {
1204
+ // tslint:disable-next-line:variable-name
1205
+ constructor(_datastore, data) {
1206
+ this._datastore = _datastore;
1207
+ if (data) {
1208
+ if (data.id) {
1209
+ this.id = data.id;
1210
+ }
1211
+ Object.assign(this, data);
1212
+ }
1213
+ }
1214
+ save(params, headers, customUrl, customBody) {
1215
+ const attributesMetadata = this[AttributeMetadata];
1216
+ return this._datastore.saveRecord(attributesMetadata, this, params, headers, customUrl, customBody);
1217
+ }
1218
+ patch(origModel, params, headers, customUrl) {
1219
+ const attributesMetadata = this[AttributeMetadata];
1220
+ return this._datastore.patchRecord(attributesMetadata, this, origModel, params, headers, customUrl);
1221
+ }
1222
+ replace(params, headers, customUrl, customBody) {
1223
+ const attributesMetadata = this[AttributeMetadata];
1224
+ return this._datastore.replaceRecord(attributesMetadata, this, params, headers, customUrl, customBody);
1225
+ }
1226
+ get attributeMetadata() {
1227
+ const attributesMetadata = this[AttributeMetadata];
1228
+ return attributesMetadata;
1229
+ }
1230
+ set attributeMetadata(val) {
1231
+ this[AttributeMetadata] = val;
1232
+ }
1233
+ get hasDirtyAttributes() {
1234
+ const attributesMetadata = this[AttributeMetadata];
1235
+ let hasDirtyAttributes = false;
1236
+ for (const propertyName in attributesMetadata) {
1237
+ if (attributesMetadata.hasOwnProperty(propertyName)) {
1238
+ const metadata = attributesMetadata[propertyName];
1239
+ if (metadata.hasDirtyAttributes) {
1240
+ hasDirtyAttributes = true;
1241
+ break;
1242
+ }
1243
+ }
1244
+ }
1245
+ return hasDirtyAttributes;
1246
+ }
1247
+ rollbackAttributes() {
1248
+ const attributesMetadata = this[AttributeMetadata];
1249
+ let metadata;
1250
+ for (const propertyName in attributesMetadata) {
1251
+ if (attributesMetadata.hasOwnProperty(propertyName)) {
1252
+ if (attributesMetadata[propertyName].hasDirtyAttributes) {
1253
+ this[propertyName] = attributesMetadata[propertyName].oldValue;
1254
+ metadata = {
1255
+ hasDirtyAttributes: false,
1256
+ newValue: attributesMetadata[propertyName].oldValue,
1257
+ oldValue: undefined
1258
+ };
1259
+ attributesMetadata[propertyName] = metadata;
1260
+ }
1261
+ }
1262
+ }
1263
+ this[AttributeMetadata] = attributesMetadata;
1264
+ }
1265
+ get modelConfig() {
1266
+ return Reflect.getMetadata('BaseModelConfig', this.constructor);
1267
+ }
1268
+ deserializeModel(modelType, data) {
1269
+ data = this.transformSerializedNamesToPropertyNames(modelType, data);
1270
+ return new modelType(this._datastore, data);
1271
+ }
1272
+ transformSerializedNamesToPropertyNames(modelType, attributes) {
1273
+ const serializedNameToPropertyName = this.getModelPropertyNames(modelType.prototype);
1274
+ const properties = {};
1275
+ Object.keys(serializedNameToPropertyName).forEach((serializedName) => {
1276
+ if (attributes[serializedName] !== null && attributes[serializedName] !== undefined) {
1277
+ properties[serializedNameToPropertyName[serializedName]] = attributes[serializedName];
1278
+ }
1279
+ });
1280
+ return properties;
1281
+ }
1282
+ getModelPropertyNames(model) {
1283
+ return Reflect.getMetadata('AttributeMapping', model);
1284
+ }
1285
+ getModelRequiredPropertyNames(model) {
1286
+ return Reflect.getMetadata('AttributeRequired', model);
1287
+ }
1288
+ getModelDefaultPropertyValues(model) {
1289
+ return Reflect.getMetadata('AttributedefaultValue', model);
1290
+ }
1291
+ getModelSubGroupPropertyNames(model) {
1292
+ return Reflect.getMetadata('AttributeformSubGroup', model);
1293
+ }
1294
+ getFromGroup(fb) {
1295
+ const props = Object.keys(this.getModelPropertyNames(this));
1296
+ const requiredProps = this.getModelRequiredPropertyNames(this);
1297
+ const defaultValues = this.getModelDefaultPropertyValues(this);
1298
+ const formSubGroupsValues = this.getModelSubGroupPropertyNames(this);
1299
+ const controlsConfig = {};
1300
+ const that = this;
1301
+ if (props) {
1302
+ props.forEach(property => {
1303
+ const value = that[property] !== undefined ? that[property] : defaultValues[property];
1304
+ const formSubGroup = formSubGroupsValues[property] ?? null;
1305
+ if (requiredProps[property]) {
1306
+ if (formSubGroup)
1307
+ this.getSubFromGroup(fb, controlsConfig, formSubGroup).addControl(property, fb.control(value, Validators.required));
1308
+ else
1309
+ controlsConfig[property] = [value, Validators.required];
1310
+ }
1311
+ else {
1312
+ if (formSubGroup)
1313
+ this.getSubFromGroup(fb, controlsConfig, formSubGroup).addControl(property, fb.control(value));
1314
+ else
1315
+ controlsConfig[property] = value;
1316
+ }
1317
+ });
1318
+ }
1319
+ return fb.group(controlsConfig);
1320
+ }
1321
+ getSubFromGroup(fb, controlsConfig, subGroup) {
1322
+ if (!controlsConfig[subGroup])
1323
+ controlsConfig[subGroup] = fb.group({});
1324
+ return controlsConfig[subGroup];
1325
+ }
1326
+ getModelFromFormGroup(formGroup, id) {
1327
+ const props = Object.keys(this.getModelPropertyNames(this));
1328
+ const formSubGroupsValues = this.getModelSubGroupPropertyNames(this);
1329
+ const data = {};
1330
+ if (id) {
1331
+ data.id = id;
1332
+ }
1333
+ const that = this;
1334
+ if (props) {
1335
+ props.forEach(property => {
1336
+ const formSubGroup = formSubGroupsValues[property] ?? null;
1337
+ if (!formSubGroup)
1338
+ data[property] = formGroup.controls[property].value ?? null;
1339
+ else
1340
+ data[property] = formGroup.controls[formSubGroup].controls[property].value ?? null;
1341
+ });
1342
+ }
1343
+ if (data) {
1344
+ if (id) {
1345
+ this.id = id;
1346
+ }
1347
+ Object.assign(this, data);
1348
+ }
1349
+ }
1350
+ getSerializedModel() {
1351
+ const attributesMetadata = this[AttributeMetadata];
1352
+ return this._datastore.modelToEntity(this, attributesMetadata, true);
1353
+ }
1354
+ getCellClass(property) {
1355
+ return '';
1356
+ }
1357
+ }
1358
+
1359
+ class ErrorResponse {
1360
+ constructor(errors) {
1361
+ this.errors = [];
1362
+ if (errors) {
1363
+ this.errors = errors;
1364
+ }
1365
+ }
1366
+ }
1367
+
1368
+ class Rule {
1369
+ constructor() {
1370
+ this.parameters = [];
1371
+ }
1372
+ }
1373
+
1374
+ class Nl2brPipe {
1375
+ transform(value, args) {
1376
+ // return value.replace(/\n/g, '<br />');
1377
+ if (value) {
1378
+ value = value.replace(/(?:\r\n\r\n|\r\r|\n\n)/g, '</p><p>');
1379
+ return '<p>' + value.replace(/(?:\r\n|\r|\n)/g, '<br>') + '</p>';
1380
+ }
1381
+ return value;
1382
+ }
1383
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: Nl2brPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
1384
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.1", ngImport: i0, type: Nl2brPipe, name: "nl2br" }); }
1385
+ }
1386
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: Nl2brPipe, decorators: [{
1387
+ type: Pipe,
1388
+ args: [{
1389
+ name: 'nl2br'
1390
+ }]
1391
+ }] });
1392
+
1393
+ class InputErrorPipe {
1394
+ constructor(translate) {
1395
+ this.translate = translate;
1396
+ }
1397
+ transform(value, filedTranslationKey) {
1398
+ let rvalue = '';
1399
+ if (value !== null) {
1400
+ if (value['invalid'] === true) {
1401
+ rvalue = 'ERROR.INVALID';
1402
+ }
1403
+ if (value['mustMatch'] === true) {
1404
+ rvalue = 'Account.Password.MustMach';
1405
+ }
1406
+ if (value['required'] === true) {
1407
+ const field = this.translate.instant(filedTranslationKey.field);
1408
+ rvalue = this.translate.instant('General.Field.Required', { field });
1409
+ }
1410
+ if (value['minlength']) {
1411
+ const field = this.translate.instant(filedTranslationKey.field);
1412
+ rvalue = this.translate.instant('General.Field.MinLength', { field, requiredLength: value.minlength.requiredLength });
1413
+ }
1414
+ }
1415
+ return rvalue;
1416
+ }
1417
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: InputErrorPipe, deps: [{ token: i1$2.TranslateService }], target: i0.ɵɵFactoryTarget.Pipe }); }
1418
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.1", ngImport: i0, type: InputErrorPipe, name: "inputError" }); }
1419
+ }
1420
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: InputErrorPipe, decorators: [{
1421
+ type: Pipe,
1422
+ args: [{
1423
+ name: 'inputError'
1424
+ }]
1425
+ }], ctorParameters: function () { return [{ type: i1$2.TranslateService }]; } });
1426
+
1427
+ class Configurations {
1428
+ constructor() {
1429
+ this.baseUrl = '';
1430
+ this.authUrl = '';
1431
+ this.apiVersion = 'api/v1';
1432
+ }
1433
+ }
1434
+
1435
+ class DatastoreCore extends BaseDatastore {
1436
+ constructor(http, cacheService, configExt) {
1437
+ super(http, cacheService);
1438
+ this.configExt = configExt;
1439
+ this.customConfig = {
1440
+ apiVersion: configExt.apiVersion,
1441
+ baseUrl: configExt.baseUrl
1442
+ };
1443
+ this.config = this.customConfig;
1444
+ }
1445
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: DatastoreCore, deps: [{ token: i1.HttpClient }, { token: CacheService }, { token: Configurations }], target: i0.ɵɵFactoryTarget.Injectable }); }
1446
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: DatastoreCore }); }
1447
+ }
1448
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: DatastoreCore, decorators: [{
1449
+ type: Injectable
1450
+ }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: CacheService }, { type: Configurations }]; } });
1451
+
1452
+ const PROVIDERS = [
1453
+ BaseDatastore,
1454
+ DatastoreCore,
1455
+ DatePipe,
1456
+ DecimalPipe,
1457
+ PercentPipe,
1458
+ ];
1459
+
1460
+ function DynamicallyModelResolver(modelsImport, className = undefined) {
1461
+ return (route, state) => {
1462
+ if (className == undefined)
1463
+ className = route.paramMap.get('className');
1464
+ const instance = getInstance$1(className, modelsImport);
1465
+ if (!instance) {
1466
+ throw new Error(`Invalid className: ${className}`);
1467
+ }
1468
+ return instance;
1469
+ };
1470
+ }
1471
+ function getInstance$1(className, modelsImport) {
1472
+ return modelsImport.then((module) => module[toProperCase$1(className)]);
1473
+ // return modelsImport.then((module) => ({ modelInstance: module[toProperCase(className)] })
1474
+ // );
1475
+ }
1476
+ function toProperCase$1(str) {
1477
+ return str.replace(/\w\S*/g, (txt) => {
1478
+ return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
1479
+ });
1480
+ }
1481
+
1482
+ function DynamicallyServiceResolver(serviceImport, serviceName) {
1483
+ return (route, state) => {
1484
+ const instance = getInstance(serviceName, serviceImport);
1485
+ if (!instance) {
1486
+ throw new Error(`Invalid className: ${serviceName}`);
1487
+ }
1488
+ return instance;
1489
+ };
1490
+ }
1491
+ function getInstance(serviceName, serviceImport) {
1492
+ return serviceImport.then((module) => module[toProperCase(serviceName)]); // return Promise.all([serviceImport]).then(
1493
+ // (module) => ({
1494
+ // serviceInstance: module[toProperCase(serviceName)],
1495
+ // })
1496
+ // );
1497
+ }
1498
+ function toProperCase(str) {
1499
+ return str.replace(/\w\S*/g, (txt) => {
1500
+ return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
1501
+ });
1502
+ }
1503
+
1504
+ class TranslateloaderService {
1505
+ constructor(httpClient, config) {
1506
+ this.httpClient = httpClient;
1507
+ this._apiUrl = 'No Value';
1508
+ this.headers = new HttpHeaders({
1509
+ Accept: 'application/json',
1510
+ 'Content-Type': 'application/json'
1511
+ });
1512
+ if (config) {
1513
+ this._apiUrl = config.baseUrl;
1514
+ }
1515
+ }
1516
+ getTranslation(lang) {
1517
+ const url = this._apiUrl + '/api/v1/language/' + lang + '/translationlist';
1518
+ return this.httpClient.get(url, { headers: this.headers });
1519
+ }
1520
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: TranslateloaderService, deps: [{ token: i1.HttpClient }, { token: Configurations, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
1521
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: TranslateloaderService, providedIn: 'root' }); }
1522
+ }
1523
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: TranslateloaderService, decorators: [{
1524
+ type: Injectable,
1525
+ args: [{
1526
+ providedIn: 'root'
1527
+ }]
1528
+ }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: Configurations, decorators: [{
1529
+ type: Optional
1530
+ }] }]; } });
1531
+
1532
+ class RslBaseModule {
1533
+ static forRoot(config) {
1534
+ return {
1535
+ ngModule: RslBaseModule,
1536
+ providers: [
1537
+ PROVIDERS,
1538
+ { provide: Configurations, useValue: config }
1539
+ ]
1540
+ };
1541
+ }
1542
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: RslBaseModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
1543
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.1", ngImport: i0, type: RslBaseModule, imports: [CommonModule, i1$2.TranslateModule, ReactiveFormsModule], exports: [HttpClientModule,
1544
+ TranslateModule] }); }
1545
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: RslBaseModule, providers: [
1546
+ PROVIDERS
1547
+ ], imports: [CommonModule,
1548
+ TranslateModule.forRoot({
1549
+ loader: {
1550
+ provide: TranslateLoader,
1551
+ useClass: TranslateloaderService,
1552
+ deps: [HttpClient]
1553
+ },
1554
+ // missingTranslationHandler: { provide: MissingTranslationHandler, useClass: MyMissingTranslationHandler },
1555
+ useDefaultLang: false,
1556
+ }),
1557
+ ReactiveFormsModule, HttpClientModule,
1558
+ TranslateModule] }); }
1559
+ }
1560
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: RslBaseModule, decorators: [{
1561
+ type: NgModule,
1562
+ args: [{
1563
+ imports: [
1564
+ CommonModule,
1565
+ TranslateModule.forRoot({
1566
+ loader: {
1567
+ provide: TranslateLoader,
1568
+ useClass: TranslateloaderService,
1569
+ deps: [HttpClient]
1570
+ },
1571
+ // missingTranslationHandler: { provide: MissingTranslationHandler, useClass: MyMissingTranslationHandler },
1572
+ useDefaultLang: false,
1573
+ }),
1574
+ ReactiveFormsModule
1575
+ ],
1576
+ providers: [
1577
+ PROVIDERS
1578
+ ],
1579
+ exports: [
1580
+ HttpClientModule,
1581
+ TranslateModule,
1582
+ ]
1583
+ }]
1584
+ }] });
1585
+
1586
+ class CustomValidators {
1587
+ static patternValidator(regex, error) {
1588
+ return (control) => {
1589
+ if (!control.value) {
1590
+ // if control is empty return no error
1591
+ return null;
1592
+ }
1593
+ // test the value of the control against the regexp supplied
1594
+ const valid = regex.test(control.value);
1595
+ // if true, return no error (no error), else return error passed in the second parameter
1596
+ return valid ? null : error;
1597
+ };
1598
+ }
1599
+ }
1600
+
1601
+ function readFileAsync(file) {
1602
+ return new Promise((resolve, reject) => {
1603
+ const reader = new FileReader();
1604
+ reader.onload = (event) => {
1605
+ resolve(event.target.result);
1606
+ };
1607
+ reader.onerror = (event) => {
1608
+ reject(event.target.error);
1609
+ };
1610
+ reader.readAsArrayBuffer(file);
1611
+ });
1612
+ }
1613
+ function getValueFromJsonData(jsonData, key) {
1614
+ // Convert the key and all JSON keys to lowercase
1615
+ const lowercaseKey = key.toLowerCase();
1616
+ const lowercaseKeys = Object.keys(jsonData).map(k => k.toLowerCase());
1617
+ // Find the lowercase key in the lowercase keys array
1618
+ const index = lowercaseKeys.indexOf(lowercaseKey);
1619
+ // If found, use the original (proper case) key to access the value
1620
+ if (index !== -1) {
1621
+ const originalKey = Object.keys(jsonData)[index];
1622
+ return jsonData[originalKey];
1623
+ }
1624
+ // Key not found
1625
+ return undefined;
1626
+ }
1627
+
1628
+ /*
1629
+ * Public API Surface of core
1630
+ */
1631
+
1632
+ /**
1633
+ * Generated bundle index. Do not edit.
1634
+ */
1635
+
1636
+ export { Attribute, BaseDatastore, BaseDatastoreConfig, BaseFormEditComponent, BaseMetaModel, BaseModel, BaseModelConfig, BaseQueryData, BaseService, CacheInterceptor, CacheService, CellTextAlign, CustomType, CustomValidators, DatastoreCore, DialogService, DynamicallyModelResolver, DynamicallyServiceResolver, ErrorResponse, FieldErrorDisplayComponent, GridLayoutFormat, InputErrorPipe, Nl2brPipe, PROVIDERS, PageNotFoundComponent, RslBaseModule, Rule, TranslatedContentDirective, TranslatedElementDirective, UnderConstructionComponent, getValueFromJsonData, readFileAsync };
1637
+ //# sourceMappingURL=rosoftlab-core.mjs.map