@stemy/ngx-dynamic-form 10.2.22 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/bundles/stemy-ngx-dynamic-form.umd.js +1781 -902
  2. package/bundles/stemy-ngx-dynamic-form.umd.js.map +1 -1
  3. package/esm2015/ngx-dynamic-form/common-types.js +463 -7
  4. package/esm2015/ngx-dynamic-form/components/base/dynamic-form-base.component.js +87 -0
  5. package/esm2015/ngx-dynamic-form/components/dynamic-form/dynamic-form.component.js +91 -0
  6. package/esm2015/ngx-dynamic-form/components/dynamic-form-file/dynamic-form-file.component.js +112 -0
  7. package/esm2015/ngx-dynamic-form/components/dynamic-form-group/dynamic-form-group.component.js +19 -0
  8. package/esm2015/ngx-dynamic-form/components/dynamic-form-input/dynamic-form-input.component.js +69 -0
  9. package/esm2015/ngx-dynamic-form/components/dynamic-form-model/dynamic-form-model.component.js +23 -0
  10. package/esm2015/ngx-dynamic-form/components/dynamic-form-select/dynamic-form-select.component.js +73 -0
  11. package/esm2015/ngx-dynamic-form/components/dynamic-form-static/dynamic-form-static.component.js +20 -0
  12. package/esm2015/ngx-dynamic-form/components/dynamic-forms/dynamic-forms.component.js +134 -0
  13. package/esm2015/ngx-dynamic-form/directives/async-submit.directive.js +6 -17
  14. package/esm2015/ngx-dynamic-form/directives/dynamic-form-control.directive.js +32 -0
  15. package/esm2015/ngx-dynamic-form/directives/dynamic-form-group.directive.js +40 -0
  16. package/esm2015/ngx-dynamic-form/directives/dynamic-form-template.directive.js +38 -0
  17. package/esm2015/ngx-dynamic-form/ngx-dynamic-form.module.js +36 -35
  18. package/esm2015/ngx-dynamic-form/services/dynamic-form.service.js +41 -386
  19. package/esm2015/ngx-dynamic-form/services/form-utilities.js +108 -0
  20. package/esm2015/ngx-dynamic-form/services/open-api.service.js +130 -0
  21. package/esm2015/public_api.js +15 -6
  22. package/esm2015/stemy-ngx-dynamic-form.js +4 -3
  23. package/fesm2015/stemy-ngx-dynamic-form.js +1357 -594
  24. package/fesm2015/stemy-ngx-dynamic-form.js.map +1 -1
  25. package/ngx-dynamic-form/common-types.d.ts +181 -27
  26. package/ngx-dynamic-form/components/base/dynamic-form-base.component.d.ts +44 -0
  27. package/ngx-dynamic-form/components/dynamic-form/dynamic-form.component.d.ts +21 -0
  28. package/ngx-dynamic-form/components/dynamic-form-file/dynamic-form-file.component.d.ts +16 -0
  29. package/ngx-dynamic-form/components/dynamic-form-group/dynamic-form-group.component.d.ts +6 -0
  30. package/ngx-dynamic-form/components/dynamic-form-input/dynamic-form-input.component.d.ts +12 -0
  31. package/ngx-dynamic-form/components/dynamic-form-model/dynamic-form-model.component.d.ts +6 -0
  32. package/ngx-dynamic-form/components/dynamic-form-select/dynamic-form-select.component.d.ts +9 -0
  33. package/ngx-dynamic-form/components/dynamic-form-static/dynamic-form-static.component.d.ts +5 -0
  34. package/ngx-dynamic-form/components/dynamic-forms/dynamic-forms.component.d.ts +26 -0
  35. package/ngx-dynamic-form/directives/async-submit.directive.d.ts +1 -5
  36. package/ngx-dynamic-form/directives/dynamic-form-control.directive.d.ts +12 -0
  37. package/ngx-dynamic-form/directives/dynamic-form-group.directive.d.ts +14 -0
  38. package/ngx-dynamic-form/directives/dynamic-form-template.directive.d.ts +16 -0
  39. package/ngx-dynamic-form/ngx-dynamic-form.module.d.ts +15 -5
  40. package/ngx-dynamic-form/services/dynamic-form.service.d.ts +11 -39
  41. package/ngx-dynamic-form/services/form-utilities.d.ts +19 -0
  42. package/ngx-dynamic-form/services/open-api.service.d.ts +37 -0
  43. package/package.json +16 -17
  44. package/public_api.d.ts +14 -5
  45. package/stemy-ngx-dynamic-form.d.ts +3 -2
  46. package/stemy-ngx-dynamic-form.metadata.json +1 -1
  47. package/bundles/stemy-ngx-dynamic-form.umd.min.js +0 -16
  48. package/bundles/stemy-ngx-dynamic-form.umd.min.js.map +0 -1
  49. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-control-container.component.js +0 -91
  50. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form.component.js +0 -129
  51. package/esm2015/ngx-dynamic-form/services/dynamic-form-validation.service.js +0 -11
  52. package/esm2015/ngx-dynamic-form/utils/dynamic-form-array.model.js +0 -8
  53. package/esm2015/ngx-dynamic-form/utils/form-subject.js +0 -18
  54. package/esm2015/ngx-dynamic-form/utils/validators.js +0 -28
  55. package/ngx-dynamic-form/components/base/dynamic-base-form-control-container.component.d.ts +0 -37
  56. package/ngx-dynamic-form/components/base/dynamic-base-form.component.d.ts +0 -37
  57. package/ngx-dynamic-form/services/dynamic-form-validation.service.d.ts +0 -5
  58. package/ngx-dynamic-form/utils/dynamic-form-array.model.d.ts +0 -12
  59. package/ngx-dynamic-form/utils/form-subject.d.ts +0 -8
  60. package/ngx-dynamic-form/utils/validators.d.ts +0 -4
@@ -1,169 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@stemy/ngx-utils'), require('rxjs'), require('@angular/core'), require('@angular/forms'), require('@ng-dynamic-forms/core'), require('rxjs/operators'), require('@angular/common')) :
3
- typeof define === 'function' && define.amd ? define('@stemy/ngx-dynamic-form', ['exports', '@stemy/ngx-utils', 'rxjs', '@angular/core', '@angular/forms', '@ng-dynamic-forms/core', 'rxjs/operators', '@angular/common'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy['ngx-dynamic-form'] = {}), global.ngxUtils, global.rxjs, global.ng.core, global.ng.forms, global.core, global.rxjs.operators, global.ng.common));
5
- }(this, (function (exports, ngxUtils, rxjs, core$1, forms, core, operators, common) { 'use strict';
6
-
7
- // --- Decorator functions ---
8
- var emptyArray = [];
9
- var emptyTester = function () {
10
- return Promise.resolve(false);
11
- };
12
- var ɵ0 = emptyTester;
13
- function defaultSerializer(id, parent) {
14
- var control = parent.get(id);
15
- return !control ? null : control.value;
16
- }
17
- function FormSerializable(serializer) {
18
- return function (target, propertyKey) {
19
- ngxUtils.ReflectUtils.defineMetadata("dynamicFormSerializer", serializer || defaultSerializer, target, propertyKey);
20
- };
21
- }
22
- function FormInput(data) {
23
- return function (target, propertyKey) {
24
- var meta = ngxUtils.ReflectUtils.getOwnMetadata("design:type", target, propertyKey);
25
- var type = meta ? meta.name : "";
26
- var inputType = propertyKey.indexOf("password") < 0 ? "text" : "password";
27
- switch (type) {
28
- case "Number":
29
- inputType = "number";
30
- break;
31
- case "Boolean":
32
- inputType = "checkbox";
33
- break;
34
- }
35
- defineFormControl(target, propertyKey, createFormInput(propertyKey, data, inputType));
36
- };
37
- }
38
- function FormSelect(data) {
39
- return function (target, propertyKey) {
40
- defineFormControl(target, propertyKey, createFormSelect(propertyKey, data));
41
- };
42
- }
43
- function FormStatic(data) {
44
- return function (target, propertyKey) {
45
- defineFormControl(target, propertyKey, createFormStatic(propertyKey, data));
46
- };
47
- }
48
- function FormModel(data) {
49
- return function (target, propertyKey) {
50
- defineFormControl(target, propertyKey, createFormModel(propertyKey, data));
51
- };
52
- }
53
- function FormFile(data) {
54
- return function (target, propertyKey) {
55
- defineFormControl(target, propertyKey, createFormFile(propertyKey, data));
56
- };
57
- }
58
- function FormFieldSet(data) {
59
- return function (target) {
60
- var sets = getFormFieldSets(target);
61
- data.classes = data.classes || "";
62
- sets[data.id] = data;
63
- ngxUtils.ReflectUtils.defineMetadata("dynamicFormFieldSets", sets, target);
64
- };
65
- }
66
- function defineFormControl(target, propertyKey, control) {
67
- ngxUtils.ReflectUtils.defineMetadata("dynamicFormControl", control, target, propertyKey);
68
- }
69
- function getFormFieldSets(target) {
70
- return ngxUtils.ReflectUtils.getMetadata("dynamicFormFieldSets", target) || {};
71
- }
72
- function getFormControl(target, propertyKey) {
73
- return ngxUtils.ReflectUtils.getMetadata("dynamicFormControl", target, propertyKey);
74
- }
75
- function getFormSerializer(target, propertyKey) {
76
- return ngxUtils.ReflectUtils.getMetadata("dynamicFormSerializer", target, propertyKey);
77
- }
78
- function createFormControl(id, type, data) {
79
- data = data || {};
80
- data.label = ngxUtils.ObjectUtils.isNullOrUndefined(data.label) ? id : data.label;
81
- data.labelAlign = data.labelAlign || "left";
82
- data.fieldSet = data.fieldSet || ngxUtils.UniqueUtils.uuid();
83
- data.classes = data.classes || "";
84
- data.readonly = data.readonly || emptyTester;
85
- data.hidden = data.hidden || emptyTester;
86
- data.validators = data.validators || emptyArray;
87
- return {
88
- id: id,
89
- type: type,
90
- data: data
91
- };
92
- }
93
- function createFormInput(id, data, type) {
94
- if (type === void 0) { type = "text"; }
95
- var control = createFormControl(id, "input", data);
96
- data = control.data;
97
- data.type = data.type || type;
98
- data.classes = !data.classes ? "form-group-" + data.type : data.classes + " form-group-" + data.type;
99
- data.placeholder = data.placeholder || (data.type == "mask" ? "_" : "");
100
- data.step = data.step || 1;
101
- data.mask = data.mask || [/\w*/gi];
102
- return control;
103
- }
104
- function createFormSelect(id, data) {
105
- var control = createFormControl(id, "select", data);
106
- data = control.data;
107
- data.options = data.options || [];
108
- data.type = data.type || "select";
109
- var classType = data.type == "select" ? "select" : "select-" + data.type;
110
- data.classes = !data.classes ? "form-group-" + classType : data.classes + " form-group-" + classType;
111
- return control;
112
- }
113
- function createFormStatic(id, data) {
114
- var control = createFormControl(id, "static", data);
115
- data = control.data;
116
- data.style = data.style || "table";
117
- return control;
118
- }
119
- function createFormModel(id, data) {
120
- var control = createFormControl(id, "model", data);
121
- data = control.data;
122
- data.name = data.name || "";
123
- return control;
124
- }
125
- function createFormFile(id, data) {
126
- var control = createFormControl(id, "file", data);
127
- data = control.data;
128
- data.accept = data.accept || ".jpg,.jpeg,.png";
129
- data.multi = data.multi || false;
130
- data.baseUrl = ngxUtils.ObjectUtils.isString(data.baseUrl) ? data.baseUrl : "assets/";
131
- data.uploadUrl = ngxUtils.ObjectUtils.isString(data.uploadUrl) ? data.uploadUrl : "assets";
132
- data.createUploadData = data.createUploadData || (function (file) {
133
- var form = new FormData();
134
- form.append("file", file);
135
- return form;
136
- });
137
- return control;
138
- }
139
-
140
- function validateJSON(control) {
141
- var value = control.value;
142
- if (!value)
143
- return null;
144
- try {
145
- JSON.parse(value);
146
- return null;
147
- }
148
- catch (e) {
149
- return { json: true };
150
- }
151
- }
152
- function validateRequiredTranslation(control) {
153
- var value = control.value;
154
- if (!value || value.length == 0)
155
- return { requiredTranslation: true };
156
- return value.findIndex(function (t) { return (t.lang == "de" || t.lang == "en") && !t.translation; }) < 0
157
- ? null
158
- : { requiredTranslation: true };
159
- }
160
- function validatePhone(control) {
161
- var value = control.value;
162
- if (!value)
163
- return Promise.resolve(null);
164
- var phoneRegexp = /^(?:\d){10,12}$/;
165
- return phoneRegexp.test(value) ? null : { phone: true };
166
- }
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@stemy/ngx-utils'), require('@angular/common'), require('rxjs/operators')) :
3
+ typeof define === 'function' && define.amd ? define('@stemy/ngx-dynamic-form', ['exports', '@angular/core', '@angular/forms', '@stemy/ngx-utils', '@angular/common', 'rxjs/operators'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy["ngx-dynamic-form"] = {}), global.ng.core, global.ng.forms, global["@stemy/ngx-utils"], global.ng.common, global.rxjs.operators));
5
+ })(this, (function (exports, core, forms, ngxUtils, common, operators) { 'use strict';
167
6
 
168
7
  /*! *****************************************************************************
169
8
  Copyright (c) Microsoft Corporation.
@@ -189,6 +28,8 @@
189
28
  return extendStatics(d, b);
190
29
  };
191
30
  function __extends(d, b) {
31
+ if (typeof b !== "function" && b !== null)
32
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
192
33
  extendStatics(d, b);
193
34
  function __() { this.constructor = d; }
194
35
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -374,11 +215,13 @@
374
215
  }
375
216
  return ar;
376
217
  }
218
+ /** @deprecated */
377
219
  function __spread() {
378
220
  for (var ar = [], i = 0; i < arguments.length; i++)
379
221
  ar = ar.concat(__read(arguments[i]));
380
222
  return ar;
381
223
  }
224
+ /** @deprecated */
382
225
  function __spreadArrays() {
383
226
  for (var s = 0, i = 0, il = arguments.length; i < il; i++)
384
227
  s += arguments[i].length;
@@ -387,7 +230,11 @@
387
230
  r[k] = a[j];
388
231
  return r;
389
232
  }
390
- ;
233
+ function __spreadArray(to, from) {
234
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
235
+ to[j] = from[i];
236
+ return to;
237
+ }
391
238
  function __await(v) {
392
239
  return this instanceof __await ? (this.v = v, this) : new __await(v);
393
240
  }
@@ -466,536 +313,1053 @@
466
313
  return value;
467
314
  }
468
315
 
469
- var FormSubject = /** @class */ (function (_super) {
470
- __extends(FormSubject, _super);
471
- function FormSubject(notifyCallback) {
472
- var _this = _super.call(this) || this;
473
- _this.notifyCallback = notifyCallback;
474
- return _this;
475
- }
476
- FormSubject.prototype.notify = function (controlModel, control) {
477
- return __awaiter(this, void 0, void 0, function () {
478
- var value;
479
- return __generator(this, function (_a) {
480
- switch (_a.label) {
481
- case 0:
482
- value = this.notifyCallback(controlModel, control);
483
- if (!(value instanceof Promise)) return [3 /*break*/, 2];
484
- return [4 /*yield*/, value];
485
- case 1:
486
- value = _a.sent();
487
- _a.label = 2;
488
- case 2:
489
- this.next(value);
490
- return [2 /*return*/];
491
- }
492
- });
493
- });
494
- };
495
- return FormSubject;
496
- }(rxjs.Subject));
497
-
498
- var DynamicFormArrayModel = /** @class */ (function (_super) {
499
- __extends(DynamicFormArrayModel, _super);
500
- function DynamicFormArrayModel(config, layout) {
501
- var _this = _super.call(this, config, layout) || this;
502
- _this.additional = config.additional || {};
503
- return _this;
504
- }
505
- return DynamicFormArrayModel;
506
- }(core.DynamicFormArrayModel));
507
-
508
- var DynamicFormService = /** @class */ (function (_super) {
509
- __extends(DynamicFormService, _super);
510
- function DynamicFormService(cs, vs, openApi) {
511
- var _this = _super.call(this, cs, vs) || this;
512
- _this.openApi = openApi;
513
- _this.onDetectChanges = new core$1.EventEmitter();
514
- return _this;
316
+ var FORM_GROUP_TYPE = new core.InjectionToken("form-group-provider");
317
+ var FORM_CONTROL_PROVIDER = new core.InjectionToken("form-control-provider");
318
+ var FormControlComponent = /** @class */ (function () {
319
+ function FormControlComponent() {
515
320
  }
516
- Object.defineProperty(DynamicFormService.prototype, "api", {
321
+ Object.defineProperty(FormControlComponent.prototype, "form", {
517
322
  get: function () {
518
- return this.openApi.api;
323
+ return !this.control ? null : this.control.form;
519
324
  },
520
325
  enumerable: false,
521
326
  configurable: true
522
327
  });
523
- Object.defineProperty(DynamicFormService.prototype, "language", {
328
+ Object.defineProperty(FormControlComponent.prototype, "data", {
524
329
  get: function () {
525
- return this.api.language;
330
+ return (!this.control ? {} : this.control.data);
526
331
  },
527
332
  enumerable: false,
528
333
  configurable: true
529
334
  });
530
- DynamicFormService.prototype.patchGroup = function (value, formModel, formGroup) {
531
- this.patchValueRecursive(value, formModel, formGroup);
532
- this.detectChanges();
533
- formGroup.patchValue(ngxUtils.ObjectUtils.copy(value));
534
- };
535
- DynamicFormService.prototype.patchForm = function (value, component) {
536
- this.patchValueRecursive(value, component.model, component.group);
537
- this.detectChanges(component);
538
- component.group.patchValue(value);
539
- };
540
- DynamicFormService.prototype.serialize = function (formModel, formGroup) {
541
- return this.serializeRecursive(formModel, formGroup);
542
- };
543
- DynamicFormService.prototype.notifyChanges = function (formModel, formGroup) {
544
- this.notifyChangesRecursive(formModel, formGroup);
545
- };
546
- DynamicFormService.prototype.updateSelectOptions = function (formControlModel, formControl) {
547
- if (formControlModel instanceof core.DynamicSelectModel) {
548
- var options = formControlModel.options$;
549
- if (options instanceof FormSubject) {
550
- options.notify(formControlModel, formControl);
551
- return;
552
- }
553
- while (options instanceof rxjs.Subject && options.source) {
554
- options = options.source;
555
- if (options instanceof FormSubject) {
556
- options.notify(formControlModel, formControl);
557
- }
558
- }
559
- }
560
- };
561
- DynamicFormService.prototype.showErrors = function (form) {
562
- this.showErrorsForGroup(form.group);
563
- this.detectChanges(form);
564
- };
565
- DynamicFormService.prototype.detectChanges = function (formComponent) {
566
- _super.prototype.detectChanges.call(this, formComponent);
567
- this.onDetectChanges.emit(formComponent);
568
- };
569
- DynamicFormService.prototype.patchValueRecursive = function (value, formModel, formGroup) {
570
- var _this = this;
571
- Object.keys(value).forEach(function (key) {
572
- var subModel = _this.findModelById(key, formModel);
573
- var subValue = value[key];
574
- if (!subModel)
575
- return;
576
- var subControl = _this.findControlByModel(subModel, formGroup);
577
- if (subModel instanceof core.DynamicSelectModel && ngxUtils.ObjectUtils.isObject(subValue)) {
578
- value[key] = subValue.id || subValue._id || subValue;
579
- return;
580
- }
581
- if (subModel instanceof core.DynamicFormArrayModel) {
582
- var length = Array.isArray(subValue) ? subValue.length : 0;
583
- var subArray = subControl;
584
- while (subModel.size > length) {
585
- _this.removeFormArrayGroup(0, subArray, subModel);
586
- }
587
- while (subModel.size < length) {
588
- _this.insertFormArrayGroup(subModel.size, subArray, subModel);
589
- }
590
- for (var i = 0; i < length; i++) {
591
- var itemModel = subModel.get(i);
592
- _this.patchValueRecursive(subValue[i], itemModel.group, subArray.at(i));
593
- }
335
+ Object.defineProperty(FormControlComponent.prototype, "value", {
336
+ get: function () {
337
+ return !this.control ? null : this.control.value;
338
+ },
339
+ enumerable: false,
340
+ configurable: true
341
+ });
342
+ Object.defineProperty(FormControlComponent.prototype, "meta", {
343
+ get: function () {
344
+ return !this.control ? null : this.control.meta;
345
+ },
346
+ enumerable: false,
347
+ configurable: true
348
+ });
349
+ Object.defineProperty(FormControlComponent.prototype, "inputClass", {
350
+ get: function () {
351
+ return true;
352
+ },
353
+ enumerable: false,
354
+ configurable: true
355
+ });
356
+ return FormControlComponent;
357
+ }());
358
+ FormControlComponent.decorators = [
359
+ { type: core.Directive }
360
+ ];
361
+ FormControlComponent.propDecorators = {
362
+ inputClass: [{ type: core.HostBinding, args: ["class.form-input",] }]
363
+ };
364
+ function createValidator(control) {
365
+ var data = control.data || {};
366
+ var validators = [data.validator].concat(data.validators || []).filter(ngxUtils.ObjectUtils.isDefined).map(function (v) {
367
+ return ngxUtils.ReflectUtils.resolve(v, control.injector);
368
+ });
369
+ return function (ctrl) { return new Promise(function (resolve) {
370
+ var control = ctrl;
371
+ control.shouldValidate().then(function (should) {
372
+ if (!should) {
373
+ resolve(null);
594
374
  return;
595
375
  }
596
- if (subModel instanceof core.DynamicFormGroupModel) {
597
- _this.patchValueRecursive(subValue, subModel.group, subControl);
376
+ var validate = validators.map(function (v) { return v(control); });
377
+ var metaValidator = control.meta.validator;
378
+ if (ngxUtils.ObjectUtils.isFunction(metaValidator)) {
379
+ validate.push(metaValidator(control));
598
380
  }
599
- });
600
- };
601
- DynamicFormService.prototype.serializeRecursive = function (formModel, formGroup) {
602
- var _a;
603
- return __awaiter(this, void 0, void 0, function () {
604
- var result, _c, _d, _i, i, subModel, subControl, serializer, _e, _f, length, subArray, resArray, i_1, itemModel, _g, _h, _j, _k;
605
- return __generator(this, function (_l) {
606
- switch (_l.label) {
607
- case 0:
608
- result = {};
609
- if (!formModel || !formGroup || !formGroup.value)
610
- return [2 /*return*/, result];
611
- _c = [];
612
- for (_d in formModel)
613
- _c.push(_d);
614
- _i = 0;
615
- _l.label = 1;
616
- case 1:
617
- if (!(_i < _c.length)) return [3 /*break*/, 12];
618
- i = _c[_i];
619
- subModel = formModel[i];
620
- subControl = this.findControlByModel(subModel, formGroup);
621
- serializer = (_a = subModel.additional) === null || _a === void 0 ? void 0 : _a.serializer;
622
- if (!ngxUtils.ObjectUtils.isFunction(serializer)) return [3 /*break*/, 3];
623
- _e = result;
624
- _f = subModel.id;
625
- return [4 /*yield*/, serializer(subModel, subControl)];
626
- case 2:
627
- _e[_f] = _l.sent();
628
- return [3 /*break*/, 11];
629
- case 3:
630
- if (!(subModel instanceof core.DynamicFormArrayModel)) return [3 /*break*/, 8];
631
- length = Array.isArray(subControl.value) ? subControl.value.length : 0;
632
- subArray = subControl;
633
- resArray = [];
634
- i_1 = 0;
635
- _l.label = 4;
636
- case 4:
637
- if (!(i_1 < length)) return [3 /*break*/, 7];
638
- itemModel = subModel.get(i_1);
639
- _h = (_g = resArray).push;
640
- return [4 /*yield*/, this.serializeRecursive(itemModel.group, subArray.at(i_1))];
641
- case 5:
642
- _h.apply(_g, [_l.sent()]);
643
- _l.label = 6;
644
- case 6:
645
- i_1++;
646
- return [3 /*break*/, 4];
647
- case 7:
648
- result[subModel.id] = resArray;
649
- return [3 /*break*/, 11];
650
- case 8:
651
- if (!(subModel instanceof core.DynamicFormGroupModel)) return [3 /*break*/, 10];
652
- _j = result;
653
- _k = subModel.id;
654
- return [4 /*yield*/, this.serializeRecursive(subModel.group, subControl)];
655
- case 9:
656
- _j[_k] = _l.sent();
657
- return [3 /*break*/, 11];
658
- case 10:
659
- if (subModel instanceof core.DynamicInputModel && !ngxUtils.ObjectUtils.isNullOrUndefined(subControl.value)) {
660
- result[subModel.id] = subModel.inputType == "number"
661
- ? parseFloat(("" + subControl.value || "0").replace(/,/gi, ".")) || null
662
- : subControl.value;
663
- return [3 /*break*/, 11];
381
+ Promise.all(validate).then(function (results) {
382
+ results = results.filter(function (error) { return ngxUtils.ObjectUtils.isObject(error) || ngxUtils.ObjectUtils.isString(error); });
383
+ var result = null;
384
+ if (results.length > 0) {
385
+ result = {};
386
+ results.forEach(function (error) {
387
+ if (ngxUtils.ObjectUtils.isString(error)) {
388
+ result[error] = {};
389
+ return;
664
390
  }
665
- result[subModel.id] = subControl.value;
666
- _l.label = 11;
667
- case 11:
668
- _i++;
669
- return [3 /*break*/, 1];
670
- case 12: return [2 /*return*/, result];
391
+ result = Object.assign(result, error);
392
+ });
671
393
  }
394
+ resolve(result);
672
395
  });
673
396
  });
674
- };
675
- DynamicFormService.prototype.notifyChangesRecursive = function (formModel, formGroup) {
676
- if (!formModel || !formGroup)
677
- return;
678
- for (var i in formModel) {
679
- var subModel = formModel[i];
680
- var subControl = this.findControlByModel(subModel, formGroup);
681
- if (subModel instanceof core.DynamicFormArrayModel) {
682
- var length = Array.isArray(subControl.value) ? subControl.value.length : 0;
683
- var subArray = subControl;
684
- for (var i_2 = 0; i_2 < length; i_2++) {
685
- var itemModel = subModel.get(i_2);
686
- this.notifyChangesRecursive(itemModel.group, subArray.at(i_2));
687
- }
688
- continue;
689
- }
690
- if (subModel instanceof core.DynamicFormGroupModel) {
691
- this.notifyChangesRecursive(subModel.group, subControl);
692
- continue;
693
- }
694
- this.updateSelectOptions(subModel, subControl);
695
- }
696
- };
697
- DynamicFormService.prototype.showErrorsForGroup = function (formGroup) {
698
- if (!formGroup)
699
- return;
700
- formGroup.markAsTouched({ onlySelf: true });
701
- var controls = Object.keys(formGroup.controls).map(function (id) { return formGroup.controls[id]; });
702
- this.showErrorsForControls(controls);
703
- };
704
- DynamicFormService.prototype.showErrorsForControls = function (controls) {
705
- var _this = this;
706
- controls.forEach(function (control) {
707
- if (control instanceof forms.FormGroup) {
708
- _this.showErrorsForGroup(control);
709
- return;
710
- }
711
- control.markAsTouched({ onlySelf: true });
712
- if (control instanceof forms.FormArray) {
713
- _this.showErrorsForControls(control.controls);
714
- }
397
+ }); };
398
+ }
399
+ var DynamicFormControlHelper = /** @class */ (function () {
400
+ function DynamicFormControlHelper(form, control) {
401
+ if (control === void 0) { control = null; }
402
+ this.form = form;
403
+ this.control = control;
404
+ this.formId = ngxUtils.UniqueUtils.uuid();
405
+ this.meta = {};
406
+ this.hidden = false;
407
+ this.dummyData = {};
408
+ this.readonlyTester = this.createTester("readonly");
409
+ this.hideTester = this.createTester("hidden");
410
+ this.serializeTester = this.createTester("shouldSerialize", function (control) {
411
+ return Promise.resolve(control.visible);
412
+ });
413
+ this.validateTester = this.createTester("shouldValidate", function (control) {
414
+ return Promise.resolve(control.visible);
715
415
  });
416
+ }
417
+ Object.defineProperty(DynamicFormControlHelper.prototype, "id", {
418
+ get: function () {
419
+ return !this.control ? null : this.control.id;
420
+ },
421
+ enumerable: false,
422
+ configurable: true
423
+ });
424
+ Object.defineProperty(DynamicFormControlHelper.prototype, "type", {
425
+ get: function () {
426
+ return !this.control ? "" : this.control.type;
427
+ },
428
+ enumerable: false,
429
+ configurable: true
430
+ });
431
+ Object.defineProperty(DynamicFormControlHelper.prototype, "data", {
432
+ get: function () {
433
+ return !this.control ? this.dummyData : this.control.data || this.dummyData;
434
+ },
435
+ enumerable: false,
436
+ configurable: true
437
+ });
438
+ Object.defineProperty(DynamicFormControlHelper.prototype, "visible", {
439
+ get: function () {
440
+ return !this.hidden;
441
+ },
442
+ enumerable: false,
443
+ configurable: true
444
+ });
445
+ Object.defineProperty(DynamicFormControlHelper.prototype, "provider", {
446
+ get: function () {
447
+ return this.ctrlProvider;
448
+ },
449
+ enumerable: false,
450
+ configurable: true
451
+ });
452
+ DynamicFormControlHelper.prototype.load = function (control) {
453
+ return !this.ctrlProvider ? Promise.resolve(null) : this.ctrlProvider.loader(control);
716
454
  };
717
- DynamicFormService.prototype.getFormModelForSchema = function (name) {
718
- return __awaiter(this, void 0, void 0, function () {
719
- var _c;
720
- return __generator(this, function (_d) {
721
- switch (_d.label) {
722
- case 0:
723
- this.api.cache = {};
724
- _c = this;
725
- return [4 /*yield*/, this.openApi.getSchemas()];
726
- case 1:
727
- _c.schemas = _d.sent();
728
- return [2 /*return*/, this.getFormModelForSchemaDef(this.schemas[name])];
729
- }
455
+ DynamicFormControlHelper.prototype.check = function (control) {
456
+ var _this = this;
457
+ return new Promise(function (resolve) {
458
+ _this.hideTester(control).then(function (hide) {
459
+ _this.hidden = hide;
460
+ _this.readonlyTester(control).then(function (readonly) {
461
+ resolve(control.form.readonly || readonly);
462
+ });
730
463
  });
731
464
  });
732
465
  };
733
- DynamicFormService.prototype.getFormModelForSchemaDef = function (schema) {
734
- var _this = this;
735
- if (!schema)
736
- return [];
737
- return Object.keys(schema.properties || {}).map(function (p) {
738
- var property = schema.properties[p];
739
- return _this.getFormControlModel(property, schema);
740
- }).filter(function (t) { return null !== t; });
466
+ DynamicFormControlHelper.prototype.shouldSerialize = function (control) {
467
+ return this.serializeTester(control);
741
468
  };
742
- DynamicFormService.prototype.getFormControlModel = function (property, schema) {
743
- var _a, _b;
744
- if (Array.isArray(property.enum) || ngxUtils.ObjectUtils.isString(property.optionsPath)) {
745
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
746
- }
747
- switch (property.type) {
748
- case "string":
749
- case "number":
750
- case "integer":
751
- return new core.DynamicInputModel(this.getFormInputConfig(property, schema));
752
- case "textarea":
753
- return new core.DynamicTextAreaModel(this.getFormTextareaConfig(property, schema));
754
- case "boolean":
755
- return new core.DynamicCheckboxModel(this.getFormCheckboxConfig(property, schema));
756
- case "list":
757
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
758
- case "array":
759
- if (((_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref) || property.$ref) {
760
- return new DynamicFormArrayModel(this.getFormArrayConfig(property, schema));
761
- }
762
- else if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.enum) || property.enum) {
763
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
764
- }
765
- else {
766
- return new core.DynamicInputModel(this.getFormInputConfig(property, schema));
767
- }
469
+ DynamicFormControlHelper.prototype.shouldValidate = function (control) {
470
+ return this.validateTester(control);
471
+ };
472
+ DynamicFormControlHelper.prototype.findProvider = function (control) {
473
+ this.ctrlProvider = !this.control || !this.control.type ? null : this.form.findProvider(control);
474
+ };
475
+ DynamicFormControlHelper.prototype.createTester = function (test, defaultFunc) {
476
+ if (defaultFunc === void 0) { defaultFunc = null; }
477
+ var tester = this.data[test]
478
+ ? ngxUtils.ReflectUtils.resolve(this.data[test], this.form.injector)
479
+ : (defaultFunc || (function () { return Promise.resolve(false); }));
480
+ return function (control) { return tester(control); };
481
+ };
482
+ return DynamicFormControlHelper;
483
+ }());
484
+ var DynamicFormGroup = /** @class */ (function (_super) {
485
+ __extends(DynamicFormGroup, _super);
486
+ function DynamicFormGroup(form, control) {
487
+ if (control === void 0) { control = null; }
488
+ var _this = _super.call(this, {}, { updateOn: ((!control || !control.data) ? null : control.data.updateOn) || form.updateOn || "blur" }) || this;
489
+ _this.form = form;
490
+ _this.mName = "";
491
+ _this.mModel = {};
492
+ _this.mControls = [];
493
+ _this.mSerializers = [];
494
+ _this.mFieldSets = {};
495
+ _this.helper = new DynamicFormControlHelper(form, control);
496
+ _this.helper.findProvider(_this);
497
+ _this.initialized = false;
498
+ _this.loading = false;
499
+ _this.changeTimer = ngxUtils.TimerUtils.createTimeout();
500
+ _this.statusChanges.subscribe(function () {
501
+ var root = _this.form.root;
502
+ root.onStatusChange.emit(root);
503
+ });
504
+ _this.setAsyncValidators(createValidator(_this));
505
+ return _this;
506
+ }
507
+ Object.defineProperty(DynamicFormGroup.prototype, "id", {
508
+ get: function () {
509
+ return this.helper.id;
510
+ },
511
+ enumerable: false,
512
+ configurable: true
513
+ });
514
+ Object.defineProperty(DynamicFormGroup.prototype, "type", {
515
+ get: function () {
516
+ return this.helper.type;
517
+ },
518
+ enumerable: false,
519
+ configurable: true
520
+ });
521
+ Object.defineProperty(DynamicFormGroup.prototype, "data", {
522
+ get: function () {
523
+ return this.helper.data;
524
+ },
525
+ enumerable: false,
526
+ configurable: true
527
+ });
528
+ Object.defineProperty(DynamicFormGroup.prototype, "visible", {
529
+ get: function () {
530
+ return this.helper.visible;
531
+ },
532
+ enumerable: false,
533
+ configurable: true
534
+ });
535
+ Object.defineProperty(DynamicFormGroup.prototype, "meta", {
536
+ get: function () {
537
+ return this.helper.meta;
538
+ },
539
+ enumerable: false,
540
+ configurable: true
541
+ });
542
+ Object.defineProperty(DynamicFormGroup.prototype, "injector", {
543
+ get: function () {
544
+ return this.form.injector;
545
+ },
546
+ enumerable: false,
547
+ configurable: true
548
+ });
549
+ Object.defineProperty(DynamicFormGroup.prototype, "label", {
550
+ get: function () {
551
+ return this.data.label !== "" ? "" + this.prefix + this.data.label : "";
552
+ },
553
+ enumerable: false,
554
+ configurable: true
555
+ });
556
+ Object.defineProperty(DynamicFormGroup.prototype, "provider", {
557
+ get: function () {
558
+ return this.helper.provider;
559
+ },
560
+ enumerable: false,
561
+ configurable: true
562
+ });
563
+ Object.defineProperty(DynamicFormGroup.prototype, "model", {
564
+ get: function () {
565
+ return this.mModel;
566
+ },
567
+ enumerable: false,
568
+ configurable: true
569
+ });
570
+ Object.defineProperty(DynamicFormGroup.prototype, "formId", {
571
+ get: function () {
572
+ return this.helper.formId;
573
+ },
574
+ enumerable: false,
575
+ configurable: true
576
+ });
577
+ Object.defineProperty(DynamicFormGroup.prototype, "formControls", {
578
+ get: function () {
579
+ return this.mControls || [];
580
+ },
581
+ enumerable: false,
582
+ configurable: true
583
+ });
584
+ Object.defineProperty(DynamicFormGroup.prototype, "formFields", {
585
+ get: function () {
586
+ return this.mFieldSets || {};
587
+ },
588
+ enumerable: false,
589
+ configurable: true
590
+ });
591
+ Object.defineProperty(DynamicFormGroup.prototype, "prefix", {
592
+ get: function () {
593
+ return !this.name ? "" : this.name + ".";
594
+ },
595
+ enumerable: false,
596
+ configurable: true
597
+ });
598
+ Object.defineProperty(DynamicFormGroup.prototype, "name", {
599
+ get: function () {
600
+ return this.mName;
601
+ },
602
+ enumerable: false,
603
+ configurable: true
604
+ });
605
+ Object.defineProperty(DynamicFormGroup.prototype, "state", {
606
+ get: function () {
607
+ return (this.loading ? "LOADING" : this.status);
608
+ },
609
+ enumerable: false,
610
+ configurable: true
611
+ });
612
+ DynamicFormGroup.createFormControls = function (group, controls) {
613
+ if (!controls && ngxUtils.ObjectUtils.isObject(group.model)) {
614
+ var props = Object.keys(group.model);
615
+ controls = props.map(function (id) {
616
+ return getFormControl(group.model, id);
617
+ }).filter(ngxUtils.ObjectUtils.isDefined);
618
+ }
619
+ if (!controls)
620
+ return [];
621
+ return controls.map(function (ctrl) {
622
+ if (ctrl.type == "model") {
623
+ var subGroup = new DynamicFormGroup(group.form, ctrl);
624
+ var model = group.model[ctrl.id] || {};
625
+ var data = subGroup.getData();
626
+ data.name = data.name || group.name;
627
+ subGroup.setup(model, data);
628
+ group.model[ctrl.id] = model;
629
+ group.addControl(subGroup.id, subGroup);
630
+ return subGroup;
631
+ }
632
+ return new DynamicFormControl(ctrl, group);
633
+ });
634
+ };
635
+ DynamicFormGroup.createFormSerializers = function (group, serializers) {
636
+ if (!serializers && ngxUtils.ObjectUtils.isObject(group.model)) {
637
+ var props = Object.keys(group.model);
638
+ serializers = props.reduce(function (result, id) {
639
+ var serializer = getFormSerializer(group.model, id);
640
+ if (!serializer)
641
+ return result;
642
+ result[id] = serializer;
643
+ return result;
644
+ }, {});
645
+ }
646
+ if (!serializers)
647
+ return [];
648
+ return Object.keys(serializers).map(function (id) {
649
+ var serializer = serializers[id] || defaultSerializer;
650
+ return !serializer ? null : {
651
+ id: id,
652
+ func: ngxUtils.ReflectUtils.resolve(serializer, group.injector)
653
+ };
654
+ });
655
+ };
656
+ DynamicFormGroup.prototype.getData = function () {
657
+ return this.data;
658
+ };
659
+ DynamicFormGroup.prototype.getControl = function (id) {
660
+ return this.get(id);
661
+ };
662
+ DynamicFormGroup.prototype.load = function () {
663
+ var promises = this.mControls.map(function (c) { return c.load(); });
664
+ promises.push(this.helper.load(this));
665
+ return Promise.all(promises);
666
+ };
667
+ DynamicFormGroup.prototype.check = function () {
668
+ var _this = this;
669
+ return new Promise(function (resolve) {
670
+ _this.helper.check(_this).then(function (readonly) {
671
+ if (readonly)
672
+ _this.disable({ emitEvent: false });
673
+ else
674
+ _this.enable({ emitEvent: false });
675
+ var promises = _this.mControls.map(function (c) { return c.check(); });
676
+ Promise.all(promises).then(resolve);
677
+ });
678
+ });
679
+ };
680
+ DynamicFormGroup.prototype.shouldSerialize = function () {
681
+ return this.helper.shouldSerialize(this);
682
+ };
683
+ DynamicFormGroup.prototype.shouldValidate = function () {
684
+ return this.helper.shouldValidate(this);
685
+ };
686
+ DynamicFormGroup.prototype.serialize = function () {
687
+ var _this = this;
688
+ return new Promise(function (resolve) {
689
+ var result = {};
690
+ var serializers = _this.mSerializers.map(function (s) {
691
+ return new Promise(function (resolve) {
692
+ s.func(s.id, _this).then(function (res) {
693
+ var ctrl = _this.getControl(s.id);
694
+ var promise = !ctrl ? Promise.resolve(true) : ctrl.shouldSerialize();
695
+ promise.then(function (should) {
696
+ if (should)
697
+ result[s.id] = res;
698
+ resolve(null);
699
+ });
700
+ });
701
+ });
702
+ });
703
+ Promise.all(serializers).then(function () { return resolve(result); });
704
+ });
705
+ };
706
+ DynamicFormGroup.prototype.onFocus = function () {
707
+ this.markAsUntouched({ onlySelf: true });
708
+ };
709
+ DynamicFormGroup.prototype.onBlur = function () {
710
+ this.markAsTouched({ onlySelf: true });
711
+ };
712
+ DynamicFormGroup.prototype.showErrors = function () {
713
+ this.markAsTouched({ onlySelf: true });
714
+ this.mControls.forEach(function (ctrl) { return ctrl.showErrors(); });
715
+ };
716
+ DynamicFormGroup.prototype.reloadControls = function () {
717
+ var _this = this;
718
+ var callback = function () { };
719
+ if (this.initialized === false) {
720
+ this.initialized = true;
721
+ this.loading = true;
722
+ callback = function () {
723
+ _this.loading = false;
724
+ // this.cdr.detectChanges();
725
+ var root = _this.form.root;
726
+ root.onInit.emit(root);
727
+ root.onStatusChange.emit(root);
728
+ // https://github.com/angular/angular/issues/14542
729
+ var statusTimer = ngxUtils.TimerUtils.createInterval();
730
+ statusTimer.set(function () {
731
+ if (_this.status == "PENDING")
732
+ return;
733
+ statusTimer.clear();
734
+ root.onStatusChange.emit(root);
735
+ }, 50);
736
+ setTimeout(statusTimer.clear, 5000);
737
+ };
738
+ }
739
+ var promise = new Promise(function (resolve) {
740
+ _this.load().then(function () { return _this.check().then(resolve); });
741
+ });
742
+ promise.then(callback, callback);
743
+ return promise;
744
+ };
745
+ DynamicFormGroup.prototype.setup = function (model, info) {
746
+ var _this = this;
747
+ this.mName = info.name || "";
748
+ this.mModel = model;
749
+ this.mControls.forEach(function (ctrl) { return _this.removeControl(ctrl.id); });
750
+ this.mControls = DynamicFormGroup.createFormControls(this, info.controls);
751
+ this.mControls.forEach(function (ctrl) { return _this.addControl(ctrl.id, ctrl); });
752
+ this.mSerializers = DynamicFormGroup.createFormSerializers(this, info.serializers);
753
+ this.mFieldSets = info.fieldSets ? info.fieldSets.reduce(function (result, fs) {
754
+ result[fs.id] = fs;
755
+ return result;
756
+ }, {}) : getFormFieldSets(Object.getPrototypeOf(model).constructor);
757
+ };
758
+ DynamicFormGroup.prototype.updateModel = function (control) {
759
+ var _this = this;
760
+ this.model[control.id] = control.value;
761
+ this.changeTimer.clear();
762
+ this.changeTimer.set(function () {
763
+ _this.check().then(function () { return _this.reloadControlsFrom(control, new Set()).then(function () {
764
+ _this.form.root.onChange.emit(control);
765
+ }); });
766
+ }, 250);
767
+ };
768
+ DynamicFormGroup.prototype.reloadControlsFrom = function (control, controls) {
769
+ var _this = this;
770
+ var data = control.data;
771
+ if (!data || !data.reload)
772
+ return Promise.resolve(null);
773
+ var reload = ngxUtils.ObjectUtils.isArray(data.reload) ? data.reload : [data.reload];
774
+ return Promise.all(reload.map(function (id) {
775
+ var nextControl = _this.getControl(id);
776
+ if (!nextControl || controls.has(nextControl))
777
+ return Promise.resolve(null);
778
+ controls.add(nextControl);
779
+ return new Promise(function (resolve) {
780
+ nextControl.load().then(function () {
781
+ _this.reloadControlsFrom(nextControl, controls).then(resolve);
782
+ });
783
+ });
784
+ }));
785
+ };
786
+ return DynamicFormGroup;
787
+ }(forms.FormGroup));
788
+ var DynamicFormControl = /** @class */ (function (_super) {
789
+ __extends(DynamicFormControl, _super);
790
+ function DynamicFormControl(control, group) {
791
+ var _this = _super.call(this, group.model[control.id], { updateOn: control.data.updateOn || group.updateOn }) || this;
792
+ _this.control = control;
793
+ _this.group = group;
794
+ _this.group.addControl(control.id, _this);
795
+ _this.helper = new DynamicFormControlHelper(_this.form, control);
796
+ _this.helper.findProvider(_this);
797
+ _this.valueChanges.subscribe(function () { return _this.group.updateModel(_this); });
798
+ _this.setAsyncValidators(createValidator(_this));
799
+ return _this;
800
+ }
801
+ Object.defineProperty(DynamicFormControl.prototype, "id", {
802
+ get: function () {
803
+ return this.helper.id;
804
+ },
805
+ enumerable: false,
806
+ configurable: true
807
+ });
808
+ Object.defineProperty(DynamicFormControl.prototype, "type", {
809
+ get: function () {
810
+ return this.helper.type;
811
+ },
812
+ enumerable: false,
813
+ configurable: true
814
+ });
815
+ Object.defineProperty(DynamicFormControl.prototype, "data", {
816
+ get: function () {
817
+ return this.helper.data;
818
+ },
819
+ enumerable: false,
820
+ configurable: true
821
+ });
822
+ Object.defineProperty(DynamicFormControl.prototype, "visible", {
823
+ get: function () {
824
+ return this.helper.visible;
825
+ },
826
+ enumerable: false,
827
+ configurable: true
828
+ });
829
+ Object.defineProperty(DynamicFormControl.prototype, "meta", {
830
+ get: function () {
831
+ return this.helper.meta;
832
+ },
833
+ enumerable: false,
834
+ configurable: true
835
+ });
836
+ Object.defineProperty(DynamicFormControl.prototype, "form", {
837
+ get: function () {
838
+ return this.group.form;
839
+ },
840
+ enumerable: false,
841
+ configurable: true
842
+ });
843
+ Object.defineProperty(DynamicFormControl.prototype, "injector", {
844
+ get: function () {
845
+ return this.form.injector;
846
+ },
847
+ enumerable: false,
848
+ configurable: true
849
+ });
850
+ Object.defineProperty(DynamicFormControl.prototype, "label", {
851
+ get: function () {
852
+ return this.data.label !== "" ? "" + this.group.prefix + this.data.label : "";
853
+ },
854
+ enumerable: false,
855
+ configurable: true
856
+ });
857
+ Object.defineProperty(DynamicFormControl.prototype, "provider", {
858
+ get: function () {
859
+ return this.helper.provider;
860
+ },
861
+ enumerable: false,
862
+ configurable: true
863
+ });
864
+ Object.defineProperty(DynamicFormControl.prototype, "model", {
865
+ get: function () {
866
+ return this.group.model;
867
+ },
868
+ enumerable: false,
869
+ configurable: true
870
+ });
871
+ Object.defineProperty(DynamicFormControl.prototype, "formId", {
872
+ get: function () {
873
+ return this.helper.formId;
874
+ },
875
+ enumerable: false,
876
+ configurable: true
877
+ });
878
+ DynamicFormControl.prototype.getData = function () {
879
+ return this.data;
880
+ };
881
+ DynamicFormControl.prototype.getControl = function (id) {
882
+ return null;
883
+ };
884
+ DynamicFormControl.prototype.load = function () {
885
+ return this.helper.load(this);
886
+ };
887
+ DynamicFormControl.prototype.check = function () {
888
+ var _this = this;
889
+ var check = this.helper.check(this);
890
+ check.then(function (readonly) {
891
+ if (readonly || _this.group.disabled)
892
+ _this.disable({ emitEvent: false });
893
+ else
894
+ _this.enable({ emitEvent: false });
895
+ });
896
+ return check;
897
+ };
898
+ DynamicFormControl.prototype.shouldSerialize = function () {
899
+ return this.helper.shouldSerialize(this);
900
+ };
901
+ DynamicFormControl.prototype.shouldValidate = function () {
902
+ return this.helper.shouldValidate(this);
903
+ };
904
+ DynamicFormControl.prototype.serialize = function () {
905
+ return Promise.resolve(this.value);
906
+ };
907
+ DynamicFormControl.prototype.onFocus = function () {
908
+ this.markAsUntouched({ onlySelf: true });
909
+ };
910
+ DynamicFormControl.prototype.onBlur = function () {
911
+ this.markAsTouched({ onlySelf: true });
912
+ };
913
+ DynamicFormControl.prototype.showErrors = function () {
914
+ this.markAsTouched({ onlySelf: true });
915
+ };
916
+ return DynamicFormControl;
917
+ }(forms.FormControl));
918
+ // --- Decorator functions ---
919
+ var emptyArray = [];
920
+ var emptyTester = function () {
921
+ return Promise.resolve(false);
922
+ };
923
+ var ɵ0 = emptyTester;
924
+ function defaultSerializer(id, parent) {
925
+ var control = parent.getControl(id);
926
+ return !control ? Promise.resolve(parent.model[id]) : control.serialize();
927
+ }
928
+ function FormSerializable(serializer) {
929
+ return function (target, propertyKey) {
930
+ ngxUtils.ReflectUtils.defineMetadata("dynamicFormSerializer", serializer || defaultSerializer, target, propertyKey);
931
+ };
932
+ }
933
+ function FormInput(data) {
934
+ return function (target, propertyKey) {
935
+ var meta = ngxUtils.ReflectUtils.getOwnMetadata("design:type", target, propertyKey);
936
+ var type = meta ? meta.name : "";
937
+ var inputType = propertyKey.indexOf("password") < 0 ? "text" : "password";
938
+ switch (type) {
939
+ case "Number":
940
+ inputType = "number";
941
+ break;
942
+ case "Boolean":
943
+ inputType = "checkbox";
944
+ break;
945
+ }
946
+ defineFormControl(target, propertyKey, createFormInput(propertyKey, data, inputType));
947
+ };
948
+ }
949
+ function FormSelect(data) {
950
+ return function (target, propertyKey) {
951
+ defineFormControl(target, propertyKey, createFormSelect(propertyKey, data));
952
+ };
953
+ }
954
+ function FormStatic(data) {
955
+ return function (target, propertyKey) {
956
+ defineFormControl(target, propertyKey, createFormStatic(propertyKey, data));
957
+ };
958
+ }
959
+ function FormModel(data) {
960
+ return function (target, propertyKey) {
961
+ defineFormControl(target, propertyKey, createFormModel(propertyKey, data));
962
+ };
963
+ }
964
+ function FormFile(data) {
965
+ return function (target, propertyKey) {
966
+ defineFormControl(target, propertyKey, createFormFile(propertyKey, data));
967
+ };
968
+ }
969
+ function FormFieldSet(data) {
970
+ return function (target) {
971
+ var sets = getFormFieldSets(target);
972
+ data.classes = data.classes || "";
973
+ sets[data.id] = data;
974
+ ngxUtils.ReflectUtils.defineMetadata("dynamicFormFieldSets", sets, target);
975
+ };
976
+ }
977
+ function provideFormGroup(component) {
978
+ return {
979
+ provide: FORM_GROUP_TYPE,
980
+ useValue: component
981
+ };
982
+ }
983
+ function provideFormControl(component, acceptor, loader, priority) {
984
+ if (priority === void 0) { priority = 0; }
985
+ return {
986
+ provide: FORM_CONTROL_PROVIDER,
987
+ multi: true,
988
+ useValue: {
989
+ component: component,
990
+ priority: priority,
991
+ acceptor: acceptor,
992
+ loader: loader
993
+ }
994
+ };
995
+ }
996
+ function defineFormControl(target, propertyKey, control) {
997
+ ngxUtils.ReflectUtils.defineMetadata("dynamicFormControl", control, target, propertyKey);
998
+ }
999
+ function getFormFieldSets(target) {
1000
+ return ngxUtils.ReflectUtils.getMetadata("dynamicFormFieldSets", target) || {};
1001
+ }
1002
+ function getFormControl(target, propertyKey) {
1003
+ return ngxUtils.ReflectUtils.getMetadata("dynamicFormControl", target, propertyKey);
1004
+ }
1005
+ function getFormSerializer(target, propertyKey) {
1006
+ return ngxUtils.ReflectUtils.getMetadata("dynamicFormSerializer", target, propertyKey);
1007
+ }
1008
+ function createFormControl(id, type, data) {
1009
+ data = data || {};
1010
+ data.label = ngxUtils.ObjectUtils.isNullOrUndefined(data.label) ? id : data.label;
1011
+ data.labelAlign = data.labelAlign || "left";
1012
+ data.fieldSet = data.fieldSet || ngxUtils.UniqueUtils.uuid();
1013
+ data.classes = data.classes || "";
1014
+ data.readonly = data.readonly || emptyTester;
1015
+ data.hidden = data.hidden || emptyTester;
1016
+ data.validators = data.validators || emptyArray;
1017
+ return {
1018
+ id: id,
1019
+ type: type,
1020
+ data: data
1021
+ };
1022
+ }
1023
+ function createFormInput(id, data, type) {
1024
+ if (type === void 0) { type = "text"; }
1025
+ var control = createFormControl(id, "input", data);
1026
+ data = control.data;
1027
+ data.type = data.type || type;
1028
+ data.classes = !data.classes ? "form-group-" + data.type : data.classes + " form-group-" + data.type;
1029
+ data.placeholder = data.placeholder || "";
1030
+ data.step = data.step || 1;
1031
+ return control;
1032
+ }
1033
+ function createFormSelect(id, data) {
1034
+ var control = createFormControl(id, "select", data);
1035
+ data = control.data;
1036
+ data.options = data.options || (function () { return Promise.resolve([]); });
1037
+ data.type = data.type || "select";
1038
+ var classType = data.type == "select" ? "select" : "select-" + data.type;
1039
+ data.classes = !data.classes ? "form-group-" + classType : data.classes + " form-group-" + classType;
1040
+ return control;
1041
+ }
1042
+ function createFormStatic(id, data) {
1043
+ var control = createFormControl(id, "static", data);
1044
+ data = control.data;
1045
+ data.style = data.style || "table";
1046
+ return control;
1047
+ }
1048
+ function createFormModel(id, data) {
1049
+ var control = createFormControl(id, "model", data);
1050
+ data = control.data;
1051
+ data.name = data.name || "";
1052
+ return control;
1053
+ }
1054
+ function createFormFile(id, data) {
1055
+ var control = createFormControl(id, "file", data);
1056
+ data = control.data;
1057
+ data.accept = data.accept || ".jpg,.jpeg,.png";
1058
+ data.multi = data.multi || false;
1059
+ data.baseUrl = ngxUtils.ObjectUtils.isString(data.baseUrl) ? data.baseUrl : "assets/";
1060
+ data.uploadUrl = ngxUtils.ObjectUtils.isString(data.uploadUrl) ? data.uploadUrl : "assets";
1061
+ data.createUploadData = data.createUploadData || (function (file) {
1062
+ var form = new FormData();
1063
+ form.append("file", file);
1064
+ return form;
1065
+ });
1066
+ return control;
1067
+ }
1068
+
1069
+ var DynamicFormService = /** @class */ (function () {
1070
+ function DynamicFormService(components, groupType, resolver, injector) {
1071
+ this.components = components;
1072
+ this.groupType = groupType;
1073
+ this.resolver = resolver;
1074
+ this.injector = injector;
1075
+ }
1076
+ DynamicFormService.prototype.findProvider = function (control) {
1077
+ if (!control)
1078
+ return null;
1079
+ var providers = this.components.filter(function (p) { return p.acceptor(control); });
1080
+ if (providers.length == 0) {
1081
+ throw new Error("No component provider for control: " + JSON.stringify({
1082
+ id: control.id,
1083
+ type: control.type,
1084
+ data: control.data
1085
+ }));
1086
+ }
1087
+ // Sort providers
1088
+ providers.sort(function (a, b) { return ngxUtils.ObjectUtils.compare(a.priority, b.priority); });
1089
+ return providers[0];
1090
+ };
1091
+ DynamicFormService.prototype.createComponent = function (vcr, provider) {
1092
+ vcr.clear();
1093
+ if (!provider)
1094
+ return null;
1095
+ var factory = this.resolver.resolveComponentFactory(provider.component);
1096
+ return vcr.createComponent(factory).instance;
1097
+ };
1098
+ DynamicFormService.prototype.createGroup = function (vcr) {
1099
+ vcr.clear();
1100
+ var factory = this.resolver.resolveComponentFactory(this.groupType);
1101
+ return vcr.createComponent(factory).instance;
1102
+ };
1103
+ return DynamicFormService;
1104
+ }());
1105
+ DynamicFormService.decorators = [
1106
+ { type: core.Injectable }
1107
+ ];
1108
+ DynamicFormService.ctorParameters = function () { return [
1109
+ { type: Array, decorators: [{ type: core.Inject, args: [FORM_CONTROL_PROVIDER,] }] },
1110
+ { type: core.Type, decorators: [{ type: core.Inject, args: [FORM_GROUP_TYPE,] }] },
1111
+ { type: core.ComponentFactoryResolver },
1112
+ { type: core.Injector }
1113
+ ]; };
1114
+
1115
+ var FormUtilities = /** @class */ (function () {
1116
+ function FormUtilities() {
1117
+ }
1118
+ FormUtilities.checkField = function (expression) {
1119
+ if (expression === void 0) { expression = "true"; }
1120
+ // @dynamic
1121
+ var lambda = function (control) {
1122
+ return Promise.resolve(ngxUtils.ObjectUtils.evaluate(expression, { control: control }));
1123
+ };
1124
+ return lambda;
1125
+ };
1126
+ FormUtilities.checkReadonly = function (control) {
1127
+ return Promise.resolve(control.visible && !control.disabled);
1128
+ };
1129
+ FormUtilities.readonly = function () {
1130
+ return Promise.resolve(true);
1131
+ };
1132
+ FormUtilities.validateJSON = function (control) {
1133
+ var value = control.value;
1134
+ if (!value)
1135
+ return Promise.resolve(null);
1136
+ try {
1137
+ JSON.parse(value);
1138
+ return Promise.resolve(null);
1139
+ }
1140
+ catch (e) {
1141
+ return Promise.resolve("error.not-valid-json");
1142
+ }
1143
+ };
1144
+ FormUtilities.validateRequired = function (control) {
1145
+ var value = control.value;
1146
+ return Promise.resolve(!ngxUtils.ObjectUtils.isNumber(value) && !value ? "error.required" : null);
1147
+ };
1148
+ FormUtilities.validateMinLength = function (length) {
1149
+ // @dynamic
1150
+ var lambda = function (control) {
1151
+ var value = control.value;
1152
+ if (!ngxUtils.ObjectUtils.isString(value) || value.length < length) {
1153
+ return Promise.resolve({ "error.min-length": { length: length } });
1154
+ }
1155
+ return Promise.resolve(null);
1156
+ };
1157
+ return lambda;
1158
+ };
1159
+ FormUtilities.validateMaxLength = function (length) {
1160
+ // @dynamic
1161
+ var lambda = function (control) {
1162
+ var value = control.value;
1163
+ if (!ngxUtils.ObjectUtils.isString(value) || value.length > length) {
1164
+ return Promise.resolve({ "error.max-length": { length: length } });
1165
+ }
1166
+ return Promise.resolve(null);
1167
+ };
1168
+ return lambda;
1169
+ };
1170
+ FormUtilities.validateRequiredTranslation = function (control) {
1171
+ var value = control.value;
1172
+ if (!value || value.length == 0)
1173
+ return Promise.resolve("error.required");
1174
+ return Promise.resolve(value.findIndex(function (t) { return (t.lang == "de" || t.lang == "en") && !t.translation; }) < 0 ? null : "error.required");
1175
+ };
1176
+ FormUtilities.validateEmail = function (control) {
1177
+ var value = control.value;
1178
+ if (!value)
1179
+ return Promise.resolve(null);
1180
+ var emailRegexp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1181
+ return Promise.resolve(emailRegexp.test(value) ? null : "error.invalid-email");
1182
+ };
1183
+ FormUtilities.validatePhone = function (control) {
1184
+ var value = control.value;
1185
+ if (!value)
1186
+ return Promise.resolve(null);
1187
+ var phoneRegexp = /^(?:\d){10,12}$/;
1188
+ return Promise.resolve(phoneRegexp.test(value) ? null : "error.invalid-phone");
1189
+ };
1190
+ FormUtilities.serializeLogo = function (id, parent) {
1191
+ var value = parent.model[id];
1192
+ return Promise.resolve(!value || value.length == 0 ? null : value);
1193
+ };
1194
+ FormUtilities.serializeFile = function (id, parent) {
1195
+ var value = parent.model[id];
1196
+ if (ngxUtils.ObjectUtils.isBlob(value))
1197
+ return Promise.resolve(value);
1198
+ return Promise.resolve(!ngxUtils.ObjectUtils.isString(value) || !value.startsWith("data:") ? null : ngxUtils.FileUtils.dataToBlob(value));
1199
+ };
1200
+ FormUtilities.serializeNumber = function (id, parent) {
1201
+ var value = parent.model[id];
1202
+ return Promise.resolve(!value || value.length == 0 ? 0 : parseFloat(value));
1203
+ };
1204
+ FormUtilities.serializeJSON = function (id, parent) {
1205
+ var value = parent.model[id];
1206
+ return Promise.resolve(!value ? {} : JSON.parse(value));
1207
+ };
1208
+ FormUtilities.serializeDate = function (date, format, defaultValue) {
1209
+ if (format === void 0) { format = "yyyy-MM-dd"; }
1210
+ if (defaultValue === void 0) { defaultValue = ""; }
1211
+ // @dynamic
1212
+ var lambda = function (id, parent) {
1213
+ var value = parent.model[id];
1214
+ if (!ngxUtils.ObjectUtils.isDate(value))
1215
+ return Promise.resolve(value || defaultValue);
1216
+ return Promise.resolve(!format ? value : date.transform(value, format));
1217
+ };
1218
+ return lambda;
1219
+ };
1220
+ return FormUtilities;
1221
+ }());
1222
+ __decorate([
1223
+ ngxUtils.FactoryDependencies(common.DatePipe)
1224
+ ], FormUtilities, "serializeDate", null);
1225
+
1226
+ var OpenApiService = /** @class */ (function () {
1227
+ function OpenApiService(api) {
1228
+ var _this = this;
1229
+ this.api = api;
1230
+ var baseUrl = this.api.url("").replace("api/", "api-docs");
1231
+ this.schemas = {};
1232
+ this.schemasPromise = new Promise((function (resolve) {
1233
+ _this.api.client.get(baseUrl).subscribe(function (res) {
1234
+ _this.schemas = res.definitions || {};
1235
+ resolve(_this.schemas);
1236
+ }, function () {
1237
+ resolve({});
1238
+ });
1239
+ }));
1240
+ }
1241
+ OpenApiService.prototype.getFormInputsForSchema = function (name) {
1242
+ var _this = this;
1243
+ this.api.cache = {};
1244
+ return this.schemasPromise.then(function (schemas) {
1245
+ var schema = schemas[name];
1246
+ var inputs = _this.getFormInputsForSchemaDef(schema);
1247
+ return inputs;
1248
+ });
1249
+ };
1250
+ OpenApiService.prototype.getFormInputsForSchemaDef = function (schema) {
1251
+ var _this = this;
1252
+ var inputs = {};
1253
+ if (!schema)
1254
+ return inputs;
1255
+ inputs.schema = schema;
1256
+ inputs.serializers = {};
1257
+ inputs.controls = Object.keys(schema.properties || {}).map(function (p) {
1258
+ var property = schema.properties[p];
1259
+ property.id = p;
1260
+ inputs.serializers[p] = function (id, parent) {
1261
+ return Promise.resolve(parent.model[id]);
1262
+ };
1263
+ return _this.getFormControlForProperty(property, schema);
1264
+ }).filter(function (t) { return null !== t; });
1265
+ return inputs;
1266
+ };
1267
+ OpenApiService.prototype.getFormControlForProperty = function (property, schema) {
1268
+ if (Array.isArray(property.enum)) {
1269
+ return createFormSelect(property.id, this.getFormSelectData(property, schema));
1270
+ }
1271
+ switch (property.type) {
1272
+ case "string":
1273
+ case "number":
1274
+ case "boolean":
1275
+ case "textarea":
1276
+ return createFormInput(property.id, this.getFormInputData(property, schema));
1277
+ case "list":
1278
+ return createFormSelect(property.id, this.getFormSelectData(property, schema));
768
1279
  case "file":
769
- return new core.DynamicFileUploadModel(this.getFormUploadConfig(property, schema));
770
- }
771
- if (property.$ref) {
772
- return new core.DynamicFormGroupModel(this.getFormGroupConfig(property, schema));
1280
+ return createFormFile(property.id, this.getFormFileData(property, schema));
773
1281
  }
774
1282
  return null;
775
1283
  };
776
- DynamicFormService.prototype.getFormControlConfig = function (property, schema) {
777
- var validators = this.getValidators(property, schema);
778
- var errorMessages = Object.keys(validators).reduce(function (res, key) {
779
- res[key] = "error." + key;
780
- return res;
781
- }, {});
1284
+ OpenApiService.prototype.getBaseFormData = function (property, schema) {
782
1285
  return {
783
- id: property.id,
784
- label: ngxUtils.ObjectUtils.isString(property.label) ? property.label : property.id,
785
- hidden: property.hidden,
786
- disabled: property.disabled,
787
- validators: validators,
788
- errorMessages: errorMessages,
789
- additional: Object.assign({}, property)
1286
+ readonly: property.readonly ? FormUtilities.readonly : null,
1287
+ shouldSerialize: FormUtilities.checkReadonly,
1288
+ validators: this.getValidators(property, schema)
790
1289
  };
791
1290
  };
792
- DynamicFormService.prototype.getFormArrayConfig = function (property, schema) {
793
- var _this = this;
794
- var _a;
795
- var ref = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref) || property.$ref || "";
796
- var subSchema = this.schemas[ref.split("/").pop()];
797
- return Object.assign(this.getFormControlConfig(property, schema), { groupFactory: function () { return _this.getFormModelForSchemaDef(subSchema); } });
798
- };
799
- DynamicFormService.prototype.getFormGroupConfig = function (property, schema) {
800
- var ref = property.$ref || "";
801
- var subSchema = this.schemas[ref.split("/").pop()];
802
- return Object.assign(this.getFormControlConfig(property, schema), { group: this.getFormModelForSchemaDef(subSchema) });
803
- };
804
- DynamicFormService.prototype.getFormInputConfig = function (property, schema) {
805
- var _a;
806
- var inputType = ngxUtils.StringUtils.has(property.id, "password", "Password") ? "password" : (((_a = property.items) === null || _a === void 0 ? void 0 : _a.type) || property.type);
807
- switch (inputType) {
1291
+ OpenApiService.prototype.getFormInputData = function (property, schema) {
1292
+ var type = ngxUtils.StringUtils.has(property.id, "password", "Password") ? "password" : property.type;
1293
+ switch (property.type) {
808
1294
  case "boolean":
809
- inputType = "checkbox";
1295
+ type = "checkbox";
810
1296
  break;
811
1297
  case "textarea":
812
- inputType = "textarea";
813
- break;
814
- case "integer":
815
- inputType = "number";
1298
+ type = "textarea";
816
1299
  break;
817
1300
  }
818
- return Object.assign(this.getFormControlConfig(property, schema), {
819
- inputType: inputType,
820
- autoComplete: property.autoComplete || "off",
821
- multiple: property.type == "array",
822
- accept: ngxUtils.ObjectUtils.isString(property.accept) ? property.accept : null,
823
- mask: ngxUtils.ObjectUtils.isString(property.mask) ? property.mask : null,
824
- pattern: ngxUtils.ObjectUtils.isString(property.pattern) ? property.pattern : null,
825
- step: isNaN(property.step) ? 1 : property.step,
826
- min: isNaN(property.min) ? Number.MIN_SAFE_INTEGER : property.min,
827
- max: isNaN(property.max) ? Number.MAX_SAFE_INTEGER : property.max,
828
- });
829
- };
830
- DynamicFormService.prototype.getFormTextareaConfig = function (property, schema) {
831
- return Object.assign(this.getFormControlConfig(property, schema), {
832
- cols: property.cols || null,
833
- rows: property.rows || 10,
834
- wrap: property.wrap || false,
835
- autoComplete: property.autoComplete || "off",
836
- multiple: property.type == "array"
837
- });
838
- };
839
- DynamicFormService.prototype.getFormSelectConfig = function (property, schema) {
840
- return Object.assign(this.getFormControlConfig(property, schema), {
841
- options: this.getFormSelectOptions(property, schema),
842
- multiple: property.type == "array"
843
- });
844
- };
845
- DynamicFormService.prototype.getFormCheckboxConfig = function (property, schema) {
846
- return Object.assign(this.getFormControlConfig(property, schema), {
847
- indeterminate: property.indeterminate === true
848
- });
849
- };
850
- DynamicFormService.prototype.translateOptions = function (options) {
851
- return __awaiter(this, void 0, void 0, function () {
852
- var options_1, options_1_1, option, _c, e_1_1;
853
- var e_1, _d;
854
- return __generator(this, function (_e) {
855
- switch (_e.label) {
856
- case 0:
857
- if (!options)
858
- return [2 /*return*/, []];
859
- _e.label = 1;
860
- case 1:
861
- _e.trys.push([1, 6, 7, 8]);
862
- options_1 = __values(options), options_1_1 = options_1.next();
863
- _e.label = 2;
864
- case 2:
865
- if (!!options_1_1.done) return [3 /*break*/, 5];
866
- option = options_1_1.value;
867
- _c = option;
868
- return [4 /*yield*/, this.language.getTranslation(option.label)];
869
- case 3:
870
- _c.label = _e.sent();
871
- _e.label = 4;
872
- case 4:
873
- options_1_1 = options_1.next();
874
- return [3 /*break*/, 2];
875
- case 5: return [3 /*break*/, 8];
876
- case 6:
877
- e_1_1 = _e.sent();
878
- e_1 = { error: e_1_1 };
879
- return [3 /*break*/, 8];
880
- case 7:
881
- try {
882
- if (options_1_1 && !options_1_1.done && (_d = options_1.return)) _d.call(options_1);
883
- }
884
- finally { if (e_1) throw e_1.error; }
885
- return [7 /*endfinally*/];
886
- case 8: return [2 /*return*/, options];
887
- }
888
- });
889
- });
1301
+ return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { type: type });
890
1302
  };
891
- DynamicFormService.prototype.getFormSelectOptions = function (property, schema) {
1303
+ OpenApiService.prototype.getFormSelectData = function (property, schema) {
892
1304
  var _this = this;
893
- var _a;
894
- var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
895
- if (property.optionsPath) {
896
- return new FormSubject(function (formModel, control) {
897
- var path = property.optionsPath;
898
- var target = control;
899
- if (path.startsWith("$root")) {
900
- path = path.substr(5);
901
- while (target.parent) {
902
- target = target.parent;
903
- }
904
- }
905
- while (path.startsWith(".")) {
906
- path = path.substr(1);
907
- if (target.parent) {
908
- target = target.parent;
909
- }
910
- }
911
- var value = ngxUtils.ObjectUtils.getValue(target.value, path);
912
- var options = (!ngxUtils.ObjectUtils.isArray(value) ? [] : value).map(function (value) { return ({ value: value, label: value }); });
913
- return _this.translateOptions(options);
914
- });
915
- }
916
- if (ngxUtils.ObjectUtils.isArray($enum)) {
917
- return new FormSubject(function () {
918
- var options = $enum.map(function (value) {
919
- var label = property.translatable ? property.id + "." + value : value;
920
- return { value: value, label: label };
1305
+ var options = Array.isArray(property.enum)
1306
+ ? function () {
1307
+ return Promise.resolve(property.enum.map(function (id) { return ({ id: id, label: property.id + "." + id }); }));
1308
+ }
1309
+ : function () {
1310
+ _this.api.cache[property.endpoint] = _this.api.cache[property.endpoint] || _this.api.list(property.endpoint, _this.api.makeListParams(1, -1)).then(function (result) {
1311
+ return result.items.map(function (i) {
1312
+ return { id: i._id, label: i.name };
1313
+ });
921
1314
  });
922
- return _this.translateOptions(options);
923
- });
924
- }
925
- return new FormSubject(function () { return __awaiter(_this, void 0, void 0, function () {
926
- var options;
927
- return __generator(this, function (_c) {
928
- switch (_c.label) {
929
- case 0:
930
- this.api.cache[property.endpoint] = this.api.cache[property.endpoint] || this.api.list(property.endpoint, this.api.makeListParams(1, -1)).then(function (result) {
931
- return result.items.map(function (i) {
932
- return { value: i.id || i._id, label: i[property.labelField] || i.label || i.id || i._id };
933
- });
934
- });
935
- return [4 /*yield*/, this.api.cache[property.endpoint]];
936
- case 1:
937
- options = (_c.sent()).map(function (t) { return Object.assign({}, t); });
938
- return [2 /*return*/, this.translateOptions(options)];
939
- }
940
- });
941
- }); });
942
- };
943
- DynamicFormService.prototype.getFormUploadConfig = function (property, schema) {
944
- var url = this.api.url(property.url || "assets");
945
- var accept = property.accept, autoUpload = property.autoUpload, maxSize = property.maxSize, minSize = property.minSize, removeUrl = property.removeUrl, showFileList = property.showFileList;
946
- return Object.assign(this.getFormControlConfig(property, schema), {
947
- url: url,
948
- accept: accept,
949
- autoUpload: autoUpload,
950
- maxSize: maxSize,
951
- minSize: minSize,
952
- removeUrl: removeUrl,
953
- showFileList: showFileList
954
- });
1315
+ return _this.api.cache[property.endpoint];
1316
+ };
1317
+ return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { options: options });
1318
+ };
1319
+ OpenApiService.prototype.getFormFileData = function (property, schema) {
1320
+ return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { multi: property.multi });
955
1321
  };
956
- DynamicFormService.prototype.getValidators = function (property, schema) {
957
- var validators = {};
958
- if (ngxUtils.ObjectUtils.isArray(schema.required) && schema.required.indexOf(property.id) >= 0) {
959
- validators.required = null;
1322
+ OpenApiService.prototype.getValidators = function (property, schema) {
1323
+ var validators = [];
1324
+ if (schema.required.indexOf(property.id) >= 0) {
1325
+ validators.push(FormUtilities.validateRequired);
960
1326
  }
961
1327
  if (property.minLength) {
962
- validators.minLength = property.minLength;
1328
+ validators.push({
1329
+ type: FormUtilities,
1330
+ func: FormUtilities.validateMinLength,
1331
+ params: [property.minLength]
1332
+ });
963
1333
  }
964
1334
  if (property.maxLength) {
965
- validators.maxLength = property.maxLength;
966
- }
967
- if (property.min) {
968
- validators.min = property.min;
969
- }
970
- if (property.max) {
971
- validators.max = property.max;
1335
+ validators.push({
1336
+ type: FormUtilities,
1337
+ func: FormUtilities.validateMaxLength,
1338
+ params: [property.maxLength]
1339
+ });
972
1340
  }
973
1341
  switch (property.format) {
974
1342
  case "email":
975
- validators.email = null;
1343
+ validators.push(FormUtilities.validateEmail);
976
1344
  break;
977
1345
  }
978
1346
  return validators;
979
1347
  };
980
- return DynamicFormService;
981
- }(core.DynamicFormService));
982
- DynamicFormService.decorators = [
983
- { type: core$1.Injectable }
1348
+ return OpenApiService;
1349
+ }());
1350
+ OpenApiService.decorators = [
1351
+ { type: core.Injectable }
984
1352
  ];
985
- DynamicFormService.ctorParameters = function () { return [
986
- { type: core.DynamicFormComponentService },
987
- { type: core.DynamicFormValidationService },
988
- { type: ngxUtils.OpenApiService }
1353
+ OpenApiService.ctorParameters = function () { return [
1354
+ { type: ngxUtils.ApiService }
989
1355
  ]; };
990
1356
 
991
1357
  var AsyncSubmitDirective = /** @class */ (function () {
992
1358
  function AsyncSubmitDirective(toaster, cdr, elem, renderer) {
993
1359
  this.toaster = toaster;
994
1360
  this.cdr = cdr;
995
- this.elem = elem;
996
- this.renderer = renderer;
997
- this.onSuccess = new core$1.EventEmitter();
998
- this.onError = new core$1.EventEmitter();
1361
+ this.onSuccess = new core.EventEmitter();
1362
+ this.onError = new core.EventEmitter();
999
1363
  if (elem.nativeElement.tagName !== "BUTTON")
1000
1364
  return;
1001
1365
  renderer.setAttribute(elem.nativeElement, "type", "button");
@@ -1004,14 +1368,6 @@
1004
1368
  get: function () {
1005
1369
  return this.disabled;
1006
1370
  },
1007
- set: function (value) {
1008
- this.disabled = value;
1009
- if (value) {
1010
- this.renderer.setAttribute(this.elem.nativeElement, "disabled", "disabled");
1011
- return;
1012
- }
1013
- this.renderer.removeAttribute(this.elem.nativeElement, "disabled");
1014
- },
1015
1371
  enumerable: false,
1016
1372
  configurable: true
1017
1373
  });
@@ -1026,12 +1382,12 @@
1026
1382
  var _this = this;
1027
1383
  if (!this.form)
1028
1384
  return;
1029
- this.isDisabled = this.form.status !== "VALID";
1385
+ this.disabled = this.form.status !== "VALID";
1030
1386
  this.cdr.detectChanges();
1031
- this.onStatusChange = this.form.onStatusChange.subscribe(function () {
1032
- _this.isDisabled = _this.form.status !== "VALID";
1387
+ this.onStatusChange = this.form.onStatusChange.subscribe(function (form) {
1388
+ _this.disabled = form.status !== "VALID";
1033
1389
  _this.cdr.detectChanges();
1034
- if (!_this.callback || _this.form.status == "PENDING")
1390
+ if (!_this.callback || form.status == "PENDING")
1035
1391
  return;
1036
1392
  if (!_this.disabled) {
1037
1393
  _this.callback();
@@ -1059,7 +1415,7 @@
1059
1415
  if (this.loading)
1060
1416
  return;
1061
1417
  this.loading = true;
1062
- this.method(this.form, this.context).then(function (result) {
1418
+ this.method(this.form).then(function (result) {
1063
1419
  _this.loading = false;
1064
1420
  if (result) {
1065
1421
  _this.onSuccess.emit(result);
@@ -1076,110 +1432,229 @@
1076
1432
  return AsyncSubmitDirective;
1077
1433
  }());
1078
1434
  AsyncSubmitDirective.decorators = [
1079
- { type: core$1.Directive, args: [{
1435
+ { type: core.Directive, args: [{
1080
1436
  selector: "[async-submit]",
1081
1437
  exportAs: "async-submit"
1082
1438
  },] }
1083
1439
  ];
1084
1440
  AsyncSubmitDirective.ctorParameters = function () { return [
1085
- { type: undefined, decorators: [{ type: core$1.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] },
1086
- { type: core$1.ChangeDetectorRef },
1087
- { type: core$1.ElementRef },
1088
- { type: core$1.Renderer2 }
1441
+ { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] },
1442
+ { type: core.ChangeDetectorRef },
1443
+ { type: core.ElementRef },
1444
+ { type: core.Renderer2 }
1089
1445
  ]; };
1090
1446
  AsyncSubmitDirective.propDecorators = {
1091
- method: [{ type: core$1.Input, args: ["async-submit",] }],
1092
- form: [{ type: core$1.Input }],
1093
- context: [{ type: core$1.Input }],
1094
- onSuccess: [{ type: core$1.Output }],
1095
- onError: [{ type: core$1.Output }],
1096
- isDisabled: [{ type: core$1.HostBinding, args: ["class.disabled",] }],
1097
- isLoading: [{ type: core$1.HostBinding, args: ["class.loading",] }],
1098
- click: [{ type: core$1.HostListener, args: ["click",] }]
1447
+ method: [{ type: core.Input, args: ["async-submit",] }],
1448
+ form: [{ type: core.Input }],
1449
+ onSuccess: [{ type: core.Output }],
1450
+ onError: [{ type: core.Output }],
1451
+ isDisabled: [{ type: core.HostBinding, args: ["class.disabled",] }],
1452
+ isLoading: [{ type: core.HostBinding, args: ["class.loading",] }],
1453
+ click: [{ type: core.HostListener, args: ["click",] }]
1099
1454
  };
1100
1455
 
1101
- var DynamicBaseFormComponent = /** @class */ (function (_super) {
1102
- __extends(DynamicBaseFormComponent, _super);
1103
- function DynamicBaseFormComponent(formService, events, changeDetectorRef, componentService) {
1104
- var _this = _super.call(this, changeDetectorRef, componentService) || this;
1105
- _this.formService = formService;
1106
- _this.events = events;
1107
- _this.blur = new core$1.EventEmitter();
1108
- _this.change = new core$1.EventEmitter();
1109
- _this.focus = new core$1.EventEmitter();
1110
- _this.onStatusChange = new core$1.EventEmitter();
1111
- _this.onValueChange = new core$1.EventEmitter();
1112
- _this.onSubmit = new core$1.EventEmitter();
1113
- _this.templates = new core$1.QueryList();
1114
- _this.subscription = new rxjs.Subscription();
1115
- _this.groupSubscription = new rxjs.Subscription();
1116
- _this.labelPrefix = "label";
1117
- return _this;
1456
+ var DynamicFormControlDirective = /** @class */ (function () {
1457
+ function DynamicFormControlDirective(vcr, forms) {
1458
+ this.vcr = vcr;
1459
+ this.forms = forms;
1118
1460
  }
1119
- Object.defineProperty(DynamicBaseFormComponent.prototype, "status", {
1461
+ Object.defineProperty(DynamicFormControlDirective.prototype, "component", {
1120
1462
  get: function () {
1121
- return !this.group ? null : this.group.status;
1463
+ return this.comp;
1122
1464
  },
1123
1465
  enumerable: false,
1124
1466
  configurable: true
1125
1467
  });
1126
- DynamicBaseFormComponent.prototype.ngOnChanges = function (changes) {
1127
- var _this = this;
1128
- this.groupSubscription.unsubscribe();
1129
- if (this.group) {
1130
- this.groupSubscription = ngxUtils.ObservableUtils.multiSubscription(this.group.statusChanges.subscribe(function () {
1131
- _this.onStatusChange.emit(_this);
1132
- }), this.group.valueChanges.subscribe(function () {
1133
- _this.onValueChange.emit(_this);
1134
- _this.formService.notifyChanges(_this.model, _this.group);
1135
- }));
1468
+ DynamicFormControlDirective.prototype.ngOnChanges = function (changes) {
1469
+ if (changes.control) {
1470
+ this.comp = this.forms.createComponent(this.vcr, this.control.provider);
1136
1471
  }
1472
+ if (!this.comp)
1473
+ return;
1474
+ this.comp.control = this.control;
1137
1475
  };
1138
- DynamicBaseFormComponent.prototype.ngAfterViewInit = function () {
1139
- var _this = this;
1140
- this.subscription = ngxUtils.ObservableUtils.multiSubscription(ngxUtils.ObservableUtils.subscribe({
1141
- subjects: [this.contentTemplates.changes, this.viewTemplates.changes],
1142
- cb: function () {
1143
- var templates = _this.contentTemplates.toArray().concat(_this.viewTemplates.toArray());
1144
- _this.templates.reset(templates);
1476
+ return DynamicFormControlDirective;
1477
+ }());
1478
+ DynamicFormControlDirective.decorators = [
1479
+ { type: core.Directive, args: [{
1480
+ selector: "[form-control]",
1481
+ },] }
1482
+ ];
1483
+ DynamicFormControlDirective.ctorParameters = function () { return [
1484
+ { type: core.ViewContainerRef },
1485
+ { type: DynamicFormService }
1486
+ ]; };
1487
+ DynamicFormControlDirective.propDecorators = {
1488
+ control: [{ type: core.Input, args: ["form-control",] }]
1489
+ };
1490
+
1491
+ var DynamicFormTemplateDirective = /** @class */ (function () {
1492
+ function DynamicFormTemplateDirective(template) {
1493
+ this.template = template;
1494
+ }
1495
+ return DynamicFormTemplateDirective;
1496
+ }());
1497
+ DynamicFormTemplateDirective.decorators = [
1498
+ { type: core.Directive, args: [{
1499
+ selector: "ng-template[control],\n ng-template[label],\n ng-template[input],\n ng-template[prefix],\n ng-template[suffix],\n ng-template[setPrefix],\n ng-template[setSuffix],\n ng-template[formPrefix],\n ng-template[formSuffix],\n ng-template[innerFormPrefix],\n ng-template[innerFormSuffix]"
1500
+ },] }
1501
+ ];
1502
+ DynamicFormTemplateDirective.ctorParameters = function () { return [
1503
+ { type: core.TemplateRef }
1504
+ ]; };
1505
+ DynamicFormTemplateDirective.propDecorators = {
1506
+ control: [{ type: core.Input }],
1507
+ label: [{ type: core.Input }],
1508
+ input: [{ type: core.Input }],
1509
+ prefix: [{ type: core.Input }],
1510
+ suffix: [{ type: core.Input }],
1511
+ setPrefix: [{ type: core.Input }],
1512
+ setSuffix: [{ type: core.Input }],
1513
+ formPrefix: [{ type: core.Input }],
1514
+ formSuffix: [{ type: core.Input }],
1515
+ innerFormPrefix: [{ type: core.Input }],
1516
+ innerFormSuffix: [{ type: core.Input }]
1517
+ };
1518
+
1519
+ var DynamicFormBaseComponent = /** @class */ (function () {
1520
+ function DynamicFormBaseComponent(cdr, formService) {
1521
+ this.formService = formService;
1522
+ this.name = "";
1523
+ this.controlTemplates = {};
1524
+ this.labelTemplates = {};
1525
+ this.inputTemplates = {};
1526
+ this.prefixTemplates = {};
1527
+ this.suffixTemplates = {};
1528
+ this.onChange = new core.EventEmitter();
1529
+ this.onStatusChange = new core.EventEmitter();
1530
+ this.onInit = new core.EventEmitter();
1531
+ this.onSubmit = new core.EventEmitter();
1532
+ this.injector = formService.injector;
1533
+ this.cdr = cdr;
1534
+ }
1535
+ Object.defineProperty(DynamicFormBaseComponent.prototype, "root", {
1536
+ get: function () {
1537
+ var form = this;
1538
+ while (ngxUtils.ObjectUtils.isDefined(form.parent)) {
1539
+ form = form.parent;
1145
1540
  }
1146
- }), this.events.languageChanged.subscribe(function () {
1147
- _this.formService.detectChanges(_this);
1148
- }), this.ngForm.ngSubmit.subscribe(function () {
1149
- _this.onSubmit.emit(_this);
1150
- }));
1151
- };
1152
- DynamicBaseFormComponent.prototype.ngOnDestroy = function () {
1153
- _super.prototype.ngOnDestroy.call(this);
1154
- this.subscription.unsubscribe();
1155
- this.groupSubscription.unsubscribe();
1541
+ return form;
1542
+ },
1543
+ enumerable: false,
1544
+ configurable: true
1545
+ });
1546
+ DynamicFormBaseComponent.prototype.findProvider = function (control) {
1547
+ return this.formService.findProvider(control);
1156
1548
  };
1157
- DynamicBaseFormComponent.prototype.insertFormArrayGroup = function (index, formArray, formArrayModel) {
1158
- this.formService.insertFormArrayGroup(index, formArray, formArrayModel);
1159
- this.changeDetectorRef.detectChanges();
1549
+ // --- Lifecycle hooks
1550
+ DynamicFormBaseComponent.prototype.ngAfterContentInit = function () {
1551
+ this.wrapperTemplate = this.wrapperTemplate || this.cWrapperTemplate;
1552
+ this.fieldSetTemplate = this.fieldSetTemplate || this.cFieldSetTemplate;
1553
+ this.controlTemplate = this.controlTemplate || this.cControlTemplate;
1554
+ this.controlTemplates = this.filterTemplates(this.controlTemplates, "control");
1555
+ this.labelTemplates = this.filterTemplates(this.labelTemplates, "label");
1556
+ this.inputTemplates = this.filterTemplates(this.inputTemplates, "input");
1557
+ this.prefixTemplates = this.filterTemplates(this.prefixTemplates, "prefix");
1558
+ this.suffixTemplates = this.filterTemplates(this.suffixTemplates, "suffix");
1559
+ this.setPrefixTemplates = this.filterTemplates(this.setPrefixTemplates, "setPrefix");
1560
+ this.setSuffixTemplates = this.filterTemplates(this.setSuffixTemplates, "setSuffix");
1160
1561
  };
1161
- DynamicBaseFormComponent.prototype.removeFormArrayGroup = function (index, formArray, formArrayModel) {
1162
- this.formService.removeFormArrayGroup(index, formArray, formArrayModel);
1163
- this.changeDetectorRef.detectChanges();
1562
+ DynamicFormBaseComponent.prototype.filterTemplates = function (templates, type) {
1563
+ if (ngxUtils.ObjectUtils.isObject(templates) && Object.keys(templates).length > 0)
1564
+ return templates;
1565
+ return this.templates.filter(function (t) { return !!t[type]; }).reduce(function (result, directive) {
1566
+ result[directive[type]] = directive.template;
1567
+ return result;
1568
+ }, {});
1164
1569
  };
1165
- DynamicBaseFormComponent.prototype.moveFormArrayGroup = function (index, step, formArray, formArrayModel) {
1166
- this.formService.moveFormArrayGroup(index, step, formArray, formArrayModel);
1167
- this.changeDetectorRef.detectChanges();
1570
+ return DynamicFormBaseComponent;
1571
+ }());
1572
+ DynamicFormBaseComponent.decorators = [
1573
+ { type: core.Directive }
1574
+ ];
1575
+ DynamicFormBaseComponent.ctorParameters = function () { return [
1576
+ { type: core.ChangeDetectorRef },
1577
+ { type: DynamicFormService }
1578
+ ]; };
1579
+ DynamicFormBaseComponent.propDecorators = {
1580
+ name: [{ type: core.Input }],
1581
+ readonly: [{ type: core.Input }],
1582
+ updateOn: [{ type: core.Input }],
1583
+ classes: [{ type: core.Input }],
1584
+ parent: [{ type: core.Input }],
1585
+ wrapperTemplate: [{ type: core.Input }],
1586
+ fieldSetTemplate: [{ type: core.Input }],
1587
+ controlTemplate: [{ type: core.Input }],
1588
+ controlTemplates: [{ type: core.Input }],
1589
+ labelTemplates: [{ type: core.Input }],
1590
+ inputTemplates: [{ type: core.Input }],
1591
+ prefixTemplates: [{ type: core.Input }],
1592
+ suffixTemplates: [{ type: core.Input }],
1593
+ setPrefixTemplates: [{ type: core.Input }],
1594
+ setSuffixTemplates: [{ type: core.Input }],
1595
+ onChange: [{ type: core.Output }],
1596
+ onStatusChange: [{ type: core.Output }],
1597
+ onInit: [{ type: core.Output }],
1598
+ onSubmit: [{ type: core.Output }],
1599
+ prefixTemplate: [{ type: core.ContentChild, args: ["prefixTemplate",] }],
1600
+ suffixTemplate: [{ type: core.ContentChild, args: ["suffixTemplate",] }],
1601
+ templates: [{ type: core.ContentChildren, args: [DynamicFormTemplateDirective,] }],
1602
+ cWrapperTemplate: [{ type: core.ContentChild, args: ["wrapperTemplate",] }],
1603
+ cFieldSetTemplate: [{ type: core.ContentChild, args: ["fieldSetTemplate",] }],
1604
+ cControlTemplate: [{ type: core.ContentChild, args: ["controlTemplate",] }]
1605
+ };
1606
+
1607
+ var DynamicFormComponent = /** @class */ (function (_super) {
1608
+ __extends(DynamicFormComponent, _super);
1609
+ function DynamicFormComponent(cdr, forms) {
1610
+ var _this = _super.call(this, cdr, forms) || this;
1611
+ _this.group = new DynamicFormGroup(_this);
1612
+ _this.defaultFieldSet = {
1613
+ id: "",
1614
+ title: "",
1615
+ classes: ""
1616
+ };
1617
+ return _this;
1618
+ }
1619
+ Object.defineProperty(DynamicFormComponent.prototype, "status", {
1620
+ get: function () {
1621
+ return this.group.state;
1622
+ },
1623
+ enumerable: false,
1624
+ configurable: true
1625
+ });
1626
+ Object.defineProperty(DynamicFormComponent.prototype, "formControls", {
1627
+ get: function () {
1628
+ return this.group.formControls;
1629
+ },
1630
+ enumerable: false,
1631
+ configurable: true
1632
+ });
1633
+ // --- Lifecycle hooks
1634
+ DynamicFormComponent.prototype.ngOnChanges = function (changes) {
1635
+ if (!this.data)
1636
+ return;
1637
+ if (changes.data || changes.controls || changes.serializers || changes.formGroup) {
1638
+ if (this.group.id)
1639
+ return;
1640
+ this.group.setup(this.data, this);
1641
+ this.group.reloadControls();
1642
+ }
1168
1643
  };
1169
- DynamicBaseFormComponent.prototype.clearFormArray = function (formArray, formArrayModel) {
1170
- this.formService.clearFormArray(formArray, formArrayModel);
1171
- this.changeDetectorRef.detectChanges();
1644
+ // --- Custom ---
1645
+ DynamicFormComponent.prototype.onFormSubmit = function () {
1646
+ var _this = this;
1647
+ var root = this.root;
1648
+ root.validate().then(function () { return root.onSubmit.emit(_this); }, function () { });
1172
1649
  };
1173
- DynamicBaseFormComponent.prototype.validate = function (showErrors) {
1650
+ // --- IDynamicForm ---
1651
+ DynamicFormComponent.prototype.validate = function (showErrors) {
1174
1652
  var _this = this;
1175
1653
  if (showErrors === void 0) { showErrors = true; }
1176
- if (!this.group)
1177
- return Promise.resolve();
1178
1654
  return new Promise(function (resolve, reject) {
1179
1655
  _this.group.statusChanges.pipe(operators.first(function (status) { return status == "VALID" || status == "INVALID"; })).subscribe(function (status) {
1180
- if (showErrors) {
1181
- _this.formService.showErrors(_this);
1182
- }
1656
+ if (showErrors)
1657
+ _this.group.showErrors();
1183
1658
  if (status == "VALID") {
1184
1659
  resolve(null);
1185
1660
  return;
@@ -1189,238 +1664,628 @@
1189
1664
  _this.group.updateValueAndValidity();
1190
1665
  });
1191
1666
  };
1192
- DynamicBaseFormComponent.prototype.serialize = function (validate) {
1193
- return __awaiter(this, void 0, void 0, function () {
1194
- return __generator(this, function (_a) {
1195
- switch (_a.label) {
1196
- case 0:
1197
- if (!this.group)
1198
- return [2 /*return*/, null];
1199
- if (!validate) return [3 /*break*/, 2];
1200
- return [4 /*yield*/, this.validate()];
1201
- case 1:
1202
- _a.sent();
1203
- _a.label = 2;
1204
- case 2: return [4 /*yield*/, this.formService.serialize(this.model, this.group)];
1205
- case 3: return [2 /*return*/, _a.sent()];
1206
- }
1207
- });
1667
+ DynamicFormComponent.prototype.serialize = function (validate) {
1668
+ var _this = this;
1669
+ return new Promise(function (resolve, reject) {
1670
+ var serialize = function () {
1671
+ _this.group.serialize().then(resolve);
1672
+ };
1673
+ if (validate) {
1674
+ _this.validate().then(serialize, reject);
1675
+ return;
1676
+ }
1677
+ serialize();
1208
1678
  });
1209
1679
  };
1210
- return DynamicBaseFormComponent;
1211
- }(core.DynamicFormComponent));
1212
- DynamicBaseFormComponent.decorators = [
1213
- { type: core$1.Component, args: [{
1214
- selector: "dynamic-base-form",
1215
- template: "",
1216
- changeDetection: core$1.ChangeDetectionStrategy.Default
1680
+ DynamicFormComponent.prototype.check = function () {
1681
+ return this.group.check();
1682
+ };
1683
+ DynamicFormComponent.prototype.getControl = function (id) {
1684
+ return this.group.getControl(id);
1685
+ };
1686
+ return DynamicFormComponent;
1687
+ }(DynamicFormBaseComponent));
1688
+ DynamicFormComponent.decorators = [
1689
+ { type: core.Component, args: [{
1690
+ moduleId: module.id,
1691
+ selector: "dynamic-form, [dynamic-form]",
1692
+ template: "<ng-template #defaultFieldSetTemplate let-id=\"id\" let-controls=\"controls\" let-fieldSet=\"fieldSet\">\r\n <div [ngClass]=\"['form-fields', 'form-fields-' + id, fieldSet.classes]\">\r\n <ng-container [ngxTemplateOutlet]=\"setPrefixTemplates[fieldSet.id]\" [context]=\"fieldSet\"></ng-container>\r\n <div *ngIf=\"fieldSet.title\" [ngClass]=\"['form-title', fieldSet.titleClasses || '']\">\r\n {{ group.prefix + fieldSet.title | translate }}\r\n </div>\r\n <ng-template #subControls>\r\n <ng-container *ngFor=\"let control of controls\" [form-group]=\"control\" [visible]=\"control.visible\" [form]=\"this\">\r\n\r\n </ng-container>\r\n </ng-template>\r\n <div *ngIf=\"fieldSet.setClasses; else subControls\" [ngClass]=\"fieldSet.setClasses\">\r\n <div *ngIf=\"fieldSet.controlClasses; else subControls\" [ngClass]=\"fieldSet.controlClasses\">\r\n <ng-container [ngTemplateOutlet]=\"subControls\"></ng-container>\r\n </div>\r\n </div>\r\n <ng-container [ngxTemplateOutlet]=\"setSuffixTemplates[fieldSet.id]\" [context]=\"fieldSet\"></ng-container>\r\n </div>\r\n</ng-template>\r\n\r\n<ng-template #fieldSetsTemplate>\r\n <ng-container *ngFor=\"let fs of formControls | groupBy:'data.fieldSet'\"\r\n [ngxTemplateOutlet]=\"fieldSetTemplate || defaultFieldSetTemplate\"\r\n [context]=\"{form: this, id: fs.group, controls: fs.items, fieldSet: group.formFields[fs.group] || defaultFieldSet}\">\r\n </ng-container>\r\n</ng-template>\r\n<ng-template #defaultWrapperTemplate let-form=\"form\" let-fieldSetsTemplate=\"fieldSetsTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"prefixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: form, fieldSetsTemplate: fieldSetsTemplate}\"></ng-container>\r\n <form class=\"dynamic-form\" [ngClass]=\"form.classes || ''\" [formGroup]=\"group\" (submit)=\"onFormSubmit()\">\r\n <ng-container [ngTemplateOutlet]=\"fieldSetsTemplate\"></ng-container>\r\n <ng-content></ng-content>\r\n <div *ngIf=\"form.status == 'PENDING'\" class=\"dynamic-form-validator\">\r\n {{ group.prefix + 'message.pending' | translate }}\r\n </div>\r\n <button [ngStyle]=\"{display: 'none'}\">Submit</button>\r\n </form>\r\n <ng-container [ngTemplateOutlet]=\"suffixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: form, fieldSetsTemplate: fieldSetsTemplate}\"></ng-container>\r\n</ng-template>\r\n<ng-template #loadingTemplate>\r\n <div *ngIf=\"status == 'LOADING'\" class=\"dynamic-form-loader\">\r\n {{ group.prefix + 'message.loading' | translate }}\r\n </div>\r\n</ng-template>\r\n<ng-container [ngTemplateOutlet]=\"wrapperTemplate || defaultWrapperTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this, fieldSetsTemplate: fieldSetsTemplate}\"\r\n *ngIf=\"status !== 'LOADING'; else loadingTemplate\">\r\n</ng-container>\r\n",
1693
+ providers: [{ provide: DynamicFormBaseComponent, useExisting: DynamicFormComponent }]
1217
1694
  },] }
1218
1695
  ];
1219
- DynamicBaseFormComponent.ctorParameters = function () { return [
1220
- { type: DynamicFormService, decorators: [{ type: core$1.Inject, args: [DynamicFormService,] }] },
1221
- { type: ngxUtils.EventsService, decorators: [{ type: core$1.Inject, args: [ngxUtils.EventsService,] }] },
1222
- { type: core$1.ChangeDetectorRef },
1223
- { type: core.DynamicFormComponentService }
1696
+ DynamicFormComponent.ctorParameters = function () { return [
1697
+ { type: core.ChangeDetectorRef },
1698
+ { type: DynamicFormService }
1224
1699
  ]; };
1225
- DynamicBaseFormComponent.propDecorators = {
1226
- group: [{ type: core$1.Input }],
1227
- model: [{ type: core$1.Input }],
1228
- layout: [{ type: core$1.Input }],
1229
- labelPrefix: [{ type: core$1.Input }],
1230
- blur: [{ type: core$1.Output }],
1231
- change: [{ type: core$1.Output }],
1232
- focus: [{ type: core$1.Output }],
1233
- contentTemplates: [{ type: core$1.ContentChildren, args: [core.DynamicTemplateDirective,] }],
1234
- viewTemplates: [{ type: core$1.ViewChildren, args: [core.DynamicTemplateDirective,] }],
1235
- onStatusChange: [{ type: core$1.Output }],
1236
- onValueChange: [{ type: core$1.Output }],
1237
- onSubmit: [{ type: core$1.Output }],
1238
- ngForm: [{ type: core$1.ViewChild, args: [forms.NgForm,] }]
1700
+ DynamicFormComponent.propDecorators = {
1701
+ group: [{ type: core.Input }],
1702
+ controls: [{ type: core.Input }],
1703
+ serializers: [{ type: core.Input }],
1704
+ fieldSets: [{ type: core.Input }],
1705
+ data: [{ type: core.Input }]
1239
1706
  };
1240
1707
 
1241
- var DynamicBaseFormControlContainerComponent = /** @class */ (function (_super) {
1242
- __extends(DynamicBaseFormControlContainerComponent, _super);
1243
- function DynamicBaseFormControlContainerComponent(form, changeDetectorRef, componentFactoryResolver, layoutService, validationService, componentService, relationService) {
1244
- var _this = _super.call(this, changeDetectorRef, componentFactoryResolver, layoutService, validationService, componentService, relationService) || this;
1245
- _this.form = form;
1246
- _this.changeDetectorRef = changeDetectorRef;
1247
- _this.componentFactoryResolver = componentFactoryResolver;
1248
- _this.layoutService = layoutService;
1249
- _this.validationService = validationService;
1250
- _this.componentService = componentService;
1251
- _this.relationService = relationService;
1252
- _this.context = null;
1253
- _this.blur = new core$1.EventEmitter();
1254
- _this.change = new core$1.EventEmitter();
1255
- _this.focus = new core$1.EventEmitter();
1708
+ var statusPriority = ["LOADING", "PENDING", "DISABLED", "INVALID"];
1709
+ var DynamicFormsComponent = /** @class */ (function (_super) {
1710
+ __extends(DynamicFormsComponent, _super);
1711
+ function DynamicFormsComponent(cdr, formService) {
1712
+ var _this = _super.call(this, cdr, formService) || this;
1713
+ _this.formPrefixTemplates = {};
1714
+ _this.formSuffixTemplates = {};
1715
+ _this.innerFormPrefixTemplates = {};
1716
+ _this.innerFormSuffixTemplates = {};
1256
1717
  return _this;
1257
1718
  }
1258
- Object.defineProperty(DynamicBaseFormControlContainerComponent.prototype, "componentType", {
1259
- get: function () {
1260
- var _a;
1261
- return (_a = this.componentService.getCustomComponentType(this.model)) !== null && _a !== void 0 ? _a : this.getComponentType(this.model);
1262
- },
1263
- enumerable: false,
1264
- configurable: true
1265
- });
1266
- Object.defineProperty(DynamicBaseFormControlContainerComponent.prototype, "startTemplate", {
1719
+ Object.defineProperty(DynamicFormsComponent.prototype, "status", {
1267
1720
  get: function () {
1268
- return (this.model.type == core.DYNAMIC_FORM_CONTROL_TYPE_ARRAY)
1269
- ? this.layoutService.getAlignedTemplate(this.model, this.templates, "ARRAY_START")
1270
- : this.layoutService.getStartTemplate(this.model, this.templates);
1721
+ var _loop_1 = function (i) {
1722
+ var status = statusPriority[i];
1723
+ if (this_1.checkForms(function (f) { return f.status == status; }))
1724
+ return { value: status };
1725
+ };
1726
+ var this_1 = this;
1727
+ for (var i = 0; i < statusPriority.length; i++) {
1728
+ var state_1 = _loop_1(i);
1729
+ if (typeof state_1 === "object")
1730
+ return state_1.value;
1731
+ }
1732
+ return "VALID";
1271
1733
  },
1272
1734
  enumerable: false,
1273
1735
  configurable: true
1274
1736
  });
1275
- Object.defineProperty(DynamicBaseFormControlContainerComponent.prototype, "endTemplate", {
1737
+ // --- Lifecycle hooks
1738
+ DynamicFormsComponent.prototype.ngAfterContentInit = function () {
1739
+ _super.prototype.ngAfterContentInit.call(this);
1740
+ this.containerTemplate = this.containerTemplate || this.cContainerTemplate;
1741
+ this.formPrefixTemplates = this.filterTemplates(this.formPrefixTemplates, "formPrefix");
1742
+ this.formSuffixTemplates = this.filterTemplates(this.formSuffixTemplates, "formSuffix");
1743
+ this.innerFormPrefixTemplates = this.filterTemplates(this.innerFormPrefixTemplates, "innerFormPrefix");
1744
+ this.innerFormSuffixTemplates = this.filterTemplates(this.innerFormSuffixTemplates, "innerFormSuffix");
1745
+ };
1746
+ DynamicFormsComponent.prototype.ngOnChanges = function (changes) {
1747
+ this.configs = this.createFormGroups(this.data);
1748
+ };
1749
+ // --- IDynamicFormBase ---
1750
+ DynamicFormsComponent.prototype.validate = function (showErrors) {
1751
+ if (showErrors === void 0) { showErrors = true; }
1752
+ if (!this.forms)
1753
+ return Promise.reject(null);
1754
+ return Promise.all(this.forms.map(function (f) { return f.validate(showErrors); }));
1755
+ };
1756
+ DynamicFormsComponent.prototype.serialize = function (validate) {
1757
+ var _this = this;
1758
+ if (!this.forms)
1759
+ return validate ? Promise.reject(null) : Promise.resolve({});
1760
+ return new Promise(function (resolve, reject) {
1761
+ var promises = _this.forms.map(function (f) { return f.serialize(validate); });
1762
+ Promise.all(promises).then(function (results) {
1763
+ var result = {};
1764
+ results.forEach(function (data, ix) {
1765
+ var config = _this.data[ix];
1766
+ var path = null;
1767
+ if (ngxUtils.ObjectUtils.isArray(config.path) && config.path.length > 0) {
1768
+ path = config.path;
1769
+ }
1770
+ else if (ngxUtils.ObjectUtils.isString(config.path) && config.path.length > 0) {
1771
+ path = config.path.split(".");
1772
+ }
1773
+ else if (ngxUtils.ObjectUtils.isNumber(config.path)) {
1774
+ path = [config.path];
1775
+ }
1776
+ if (!path) {
1777
+ result = ngxUtils.ObjectUtils.assign(result, data);
1778
+ return;
1779
+ }
1780
+ result = ngxUtils.ObjectUtils.mapToPath(result, data, path.map(function (p) { return "" + p; }));
1781
+ });
1782
+ resolve(result);
1783
+ }, reject);
1784
+ });
1785
+ };
1786
+ DynamicFormsComponent.prototype.check = function () {
1787
+ if (!this.forms)
1788
+ return Promise.resolve(null);
1789
+ return Promise.all(this.forms.map(function (t) { return t.check(); }));
1790
+ };
1791
+ DynamicFormsComponent.prototype.getControl = function (id) {
1792
+ return this.getFromValue(function (f) { return f.getControl(id); });
1793
+ };
1794
+ DynamicFormsComponent.prototype.checkForms = function (check) {
1795
+ this.cdr.detectChanges();
1796
+ if (!this.forms)
1797
+ return false;
1798
+ return ngxUtils.ObjectUtils.isDefined(this.forms.find(check));
1799
+ };
1800
+ DynamicFormsComponent.prototype.getFromValue = function (check) {
1801
+ if (!this.forms)
1802
+ return null;
1803
+ var value = null;
1804
+ this.forms.find(function (f) {
1805
+ value = check(f);
1806
+ return ngxUtils.ObjectUtils.isDefined(value);
1807
+ });
1808
+ return value;
1809
+ };
1810
+ DynamicFormsComponent.prototype.createFormGroups = function (configs) {
1811
+ var _this = this;
1812
+ return (configs || []).map(function (c) {
1813
+ if (c.multi)
1814
+ return c;
1815
+ var config = c;
1816
+ var group = new DynamicFormGroup(_this, {
1817
+ id: config.id || ngxUtils.UniqueUtils.uuid(),
1818
+ type: "model",
1819
+ data: config.controlData
1820
+ });
1821
+ config.group = group;
1822
+ config.name = config.name || _this.name;
1823
+ group.setup(config.data, config);
1824
+ group.reloadControls();
1825
+ return config;
1826
+ });
1827
+ };
1828
+ return DynamicFormsComponent;
1829
+ }(DynamicFormBaseComponent));
1830
+ DynamicFormsComponent.decorators = [
1831
+ { type: core.Component, args: [{
1832
+ moduleId: module.id,
1833
+ selector: "dynamic-forms, [dynamic-forms]",
1834
+ template: "<ng-template #configTemplate let-formTemplate=\"formTemplate\" let-form=\"form\" let-config=\"config\" let-configTemplate>\r\n <div [ngClass]=\"config.classes || ''\">\r\n <ng-container [ngTemplateOutlet]=\"formPrefixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: form}\"></ng-container>\r\n <ng-template #singleFormTemplate>\r\n <div dynamic-form\r\n [hidden]=\"!config.group?.visible\"\r\n [ngClass]=\"config.formClasses || ''\"\r\n [name]=\"config.name || form.name\"\r\n [readonly]=\"form.readonly\"\r\n [updateOn]=\"form.updateOn\"\r\n [classes]=\"config.innerFormClasses\"\r\n [parent]=\"form\"\r\n\r\n [wrapperTemplate]=\"form.wrapperTemplate\"\r\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\r\n [controlTemplates]=\"form.controlTemplates\"\r\n\r\n [controlTemplate]=\"form.controlTemplate\"\r\n [labelTemplates]=\"form.labelTemplates\"\r\n [inputTemplates]=\"form.inputTemplates\"\r\n [prefixTemplates]=\"form.prefixTemplates\"\r\n [suffixTemplates]=\"form.suffixTemplates\"\r\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\r\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\r\n\r\n [group]=\"config.group\"\r\n [fieldSets]=\"config.fieldSets\">\r\n <ng-template #prefixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormPrefixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n <ng-template #suffixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormSuffixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n </div>\r\n </ng-template>\r\n <div dynamic-forms\r\n [ngClass]=\"config.formClasses || ''\"\r\n [name]=\"config.name || name\"\r\n [readonly]=\"form.readonly\"\r\n [updateOn]=\"form.updateOn\"\r\n [classes]=\"config.innerFormClasses\"\r\n [parent]=\"form\"\r\n\r\n [wrapperTemplate]=\"form.wrapperTemplate\"\r\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\r\n [controlTemplates]=\"form.controlTemplates\"\r\n\r\n [controlTemplate]=\"form.controlTemplate\"\r\n [labelTemplates]=\"form.labelTemplates\"\r\n [inputTemplates]=\"form.inputTemplates\"\r\n [prefixTemplates]=\"form.prefixTemplates\"\r\n [suffixTemplates]=\"form.suffixTemplates\"\r\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\r\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\r\n\r\n [data]=\"config.data\"\r\n [containerTemplate]=\"form.containerTemplate\"\r\n [formPrefixTemplates]=\"form.formPrefixTemplates\"\r\n [formSuffixTemplates]=\"form.formSuffixTemplates\"\r\n [innerFormPrefixTemplates]=\"form.innerFormPrefixTemplates\"\r\n [innerFormSuffixTemplates]=\"form.innerFormSuffixTemplates\"\r\n\r\n *ngIf=\"config.multi; else singleFormTemplate\">\r\n <ng-template #prefixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormPrefixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n <ng-template #suffixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormSuffixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n </div>\r\n <ng-container [ngTemplateOutlet]=\"formSuffixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: form}\"></ng-container>\r\n </div>\r\n</ng-template>\r\n<ng-template let-form=\"form\" let-configTemplate=\"configTemplate\" #defaultContainerTemplate>\r\n <div class=\"dynamic-forms\" [ngClass]=\"classes || ''\">\r\n <ng-container *ngFor=\"let config of form.configs\"\r\n [ngTemplateOutlet]=\"configTemplate\"\r\n [ngTemplateOutletContext]=\"{form: form, config: config}\"></ng-container>\r\n <ng-content></ng-content>\r\n </div>\r\n</ng-template>\r\n<ng-container [ngTemplateOutlet]=\"prefixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this}\"></ng-container>\r\n<ng-container [ngTemplateOutlet]=\"containerTemplate || defaultContainerTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this, configTemplate: configTemplate, defaultContainerTemplate: defaultContainerTemplate}\">\r\n</ng-container>\r\n<ng-container [ngTemplateOutlet]=\"suffixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this}\"></ng-container>\r\n",
1835
+ providers: [{ provide: DynamicFormBaseComponent, useExisting: DynamicFormsComponent }]
1836
+ },] }
1837
+ ];
1838
+ DynamicFormsComponent.ctorParameters = function () { return [
1839
+ { type: core.ChangeDetectorRef },
1840
+ { type: DynamicFormService }
1841
+ ]; };
1842
+ DynamicFormsComponent.propDecorators = {
1843
+ data: [{ type: core.Input }],
1844
+ containerTemplate: [{ type: core.Input }],
1845
+ formPrefixTemplates: [{ type: core.Input }],
1846
+ formSuffixTemplates: [{ type: core.Input }],
1847
+ innerFormPrefixTemplates: [{ type: core.Input }],
1848
+ innerFormSuffixTemplates: [{ type: core.Input }],
1849
+ cContainerTemplate: [{ type: core.ContentChild, args: ["containerTemplate",] }],
1850
+ forms: [{ type: core.ViewChildren, args: [DynamicFormBaseComponent,] }]
1851
+ };
1852
+
1853
+ var DynamicFormGroupComponent = /** @class */ (function () {
1854
+ function DynamicFormGroupComponent() {
1855
+ }
1856
+ Object.defineProperty(DynamicFormGroupComponent.prototype, "classes", {
1276
1857
  get: function () {
1277
- return (this.model.type == core.DYNAMIC_FORM_CONTROL_TYPE_ARRAY)
1278
- ? this.layoutService.getAlignedTemplate(this.model, this.templates, "ARRAY_END")
1279
- : this.layoutService.getEndTemplate(this.model, this.templates);
1858
+ if (!this.control)
1859
+ return "form-group";
1860
+ return ["form-group", "form-group-" + this.control.id, this.control.data.classes, this.control.errors && this.control.touched ? "form-group-invalid" : ""].join(" ");
1280
1861
  },
1281
1862
  enumerable: false,
1282
1863
  configurable: true
1283
1864
  });
1284
- Object.defineProperty(DynamicBaseFormControlContainerComponent.prototype, "formService", {
1865
+ return DynamicFormGroupComponent;
1866
+ }());
1867
+ DynamicFormGroupComponent.decorators = [
1868
+ { type: core.Component, args: [{
1869
+ moduleId: module.id,
1870
+ selector: "div[dynamic-form-group]",
1871
+ template: "<ng-template #labelTemplate>\r\n <label [ngClass]=\"'control-label control-label-' + control.data.labelAlign\" [attr.for]=\"control.formId\">\r\n {{ control.label | translate: control.model }}\r\n </label>\r\n</ng-template>\r\n<ng-template #errorTemplate>\r\n <div class=\"error-message\" *ngIf=\"control.errors && control.touched\">\r\n <span class=\"help-block\" *ngFor=\"let error of control.errors | entries\">\r\n {{ error.key | translate: error.value }}\r\n </span>\r\n </div>\r\n</ng-template>\r\n<ng-template #inputTemplate let-control=\"control\">\r\n <ng-container [form-control]=\"control\"></ng-container>\r\n</ng-template>\r\n<ng-template #defaultControlTemplate\r\n let-context\r\n let-control=\"control\"\r\n let-data=\"control.data\"\r\n let-labelTemplate=\"labelTemplate\"\r\n let-inputTemplate=\"inputTemplate\"\r\n let-prefixTemplate=\"prefixTemplate\"\r\n let-suffixTemplate=\"suffixTemplate\"\r\n let-errorTemplate=\"errorTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"prefixTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n <ng-container *ngIf=\"control.label && data.labelAlign == 'left'\"\r\n [ngTemplateOutlet]=\"labelTemplate\"\r\n [ngTemplateOutletContext]=\"context\">\r\n </ng-container>\r\n <ng-container [ngTemplateOutlet]=\"inputTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n <ng-container *ngIf=\"control.label && data.labelAlign == 'right'\"\r\n [ngTemplateOutlet]=\"labelTemplate\"\r\n [ngTemplateOutletContext]=\"context\">\r\n </ng-container>\r\n <ng-container [ngTemplateOutlet]=\"suffixTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n <ng-container [ngTemplateOutlet]=\"errorTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n</ng-template>\r\n\r\n<ng-container [ngxTemplateOutlet]=\"form.controlTemplates[control.id] || form.controlTemplate || defaultControlTemplate\"\r\n [context]=\"{\r\n control: control,\r\n labelTemplate: form.labelTemplates[control.id] || labelTemplate,\r\n inputTemplate: form.inputTemplates[control.id] || inputTemplate,\r\n prefixTemplate: form.prefixTemplates[control.id],\r\n suffixTemplate: form.suffixTemplates[control.id],\r\n errorTemplate: errorTemplate\r\n }\">\r\n</ng-container>\r\n"
1872
+ },] }
1873
+ ];
1874
+ DynamicFormGroupComponent.propDecorators = {
1875
+ classes: [{ type: core.HostBinding, args: ["class",] }]
1876
+ };
1877
+
1878
+ var DynamicFormFileComponent = /** @class */ (function (_super) {
1879
+ __extends(DynamicFormFileComponent, _super);
1880
+ function DynamicFormFileComponent(api, toaster) {
1881
+ var _this = _super.call(this) || this;
1882
+ _this.api = api;
1883
+ _this.toaster = toaster;
1884
+ _this.fileImageCache = [];
1885
+ return _this;
1886
+ }
1887
+ // Acceptor for provider
1888
+ DynamicFormFileComponent.acceptor = function (control) {
1889
+ return control.type == "file";
1890
+ };
1891
+ // Loader for provider
1892
+ DynamicFormFileComponent.loader = function () {
1893
+ return Promise.resolve();
1894
+ };
1895
+ DynamicFormFileComponent.prototype.onSelect = function (input) {
1896
+ this.processFiles(input.files);
1897
+ input.value = "";
1898
+ };
1899
+ DynamicFormFileComponent.prototype.processFiles = function (fileList) {
1900
+ var files = [];
1901
+ var accept = this.data.accept;
1902
+ var types = ngxUtils.ObjectUtils.isString(accept) && accept.length > 0 ? accept.toLowerCase().split(",") : null;
1903
+ if (fileList.length == 0)
1904
+ return;
1905
+ for (var i = 0; i < fileList.length; i++) {
1906
+ var file = fileList.item(i);
1907
+ var type = file.type.toLowerCase();
1908
+ var ext = ngxUtils.FileUtils.getExtension(file);
1909
+ if (types && !ngxUtils.ArrayUtils.has(types, type, ext))
1910
+ continue;
1911
+ files.push(file);
1912
+ }
1913
+ if (files.length == 0) {
1914
+ this.toaster.error("message.error.wrong-files");
1915
+ return;
1916
+ }
1917
+ this.upload(files);
1918
+ };
1919
+ DynamicFormFileComponent.prototype.upload = function (files) {
1920
+ var _this = this;
1921
+ var single = !this.data.multi;
1922
+ if (single)
1923
+ files.length = Math.min(files.length, 1);
1924
+ var promises = [];
1925
+ files.forEach(function (file, ix) {
1926
+ if (_this.data.asDataUrl) {
1927
+ promises.push(ngxUtils.FileUtils.readFileAsDataURL(file));
1928
+ return;
1929
+ }
1930
+ if (_this.data.asFile) {
1931
+ promises.push(Promise.resolve(file));
1932
+ return;
1933
+ }
1934
+ promises.push(_this.api.upload(_this.data.uploadUrl, _this.data.createUploadData(file), console.log, _this.data.uploadOptions).then(function (asset) { return asset._id || asset; }, function () { return null; }));
1935
+ });
1936
+ Promise.all(promises).then(function (assets) {
1937
+ if (single) {
1938
+ _this.control.setValue(assets[0]);
1939
+ return;
1940
+ }
1941
+ var current = _this.value || [];
1942
+ _this.control.setValue(current.concat(assets.filter(function (t) { return !!t; })));
1943
+ });
1944
+ };
1945
+ DynamicFormFileComponent.prototype.delete = function (index) {
1946
+ if (this.data.multi) {
1947
+ var current = Array.from(this.value || []);
1948
+ current.splice(index, 1);
1949
+ this.control.setValue(current);
1950
+ return;
1951
+ }
1952
+ this.control.setValue(null);
1953
+ };
1954
+ DynamicFormFileComponent.prototype.getUrl = function (image) {
1955
+ return "url('" + this.getImgUrl(image) + "')";
1956
+ };
1957
+ DynamicFormFileComponent.prototype.getImgUrl = function (image) {
1958
+ if (ngxUtils.ObjectUtils.isBlob(image)) {
1959
+ var cache = this.fileImageCache.find(function (t) { return t.file == image; });
1960
+ if (!cache) {
1961
+ cache = { file: image, url: URL.createObjectURL(image) };
1962
+ this.fileImageCache.push(cache);
1963
+ }
1964
+ return cache.url;
1965
+ }
1966
+ var url = !image ? null : image.imageUrl || image;
1967
+ if (!ngxUtils.ObjectUtils.isString(url))
1968
+ return null;
1969
+ if (url.startsWith("data:"))
1970
+ return url;
1971
+ if (!this.data.baseUrl) {
1972
+ var subUrl = url.startsWith("/") ? url.substr(1) : url;
1973
+ return this.api.url(subUrl);
1974
+ }
1975
+ return this.api.url("" + this.data.baseUrl + url);
1976
+ };
1977
+ return DynamicFormFileComponent;
1978
+ }(FormControlComponent));
1979
+ DynamicFormFileComponent.decorators = [
1980
+ { type: core.Component, args: [{
1981
+ selector: "dynamic-form-file",
1982
+ template: "<div class=\"upload\">\r\n <input type=\"file\" (change)=\"onSelect($event.target)\" [attr.accept]=\"data.accept\" multiple=\"multiple\"/>\r\n <ul class=\"images\" *ngIf=\"!data.multi\">\r\n <li class=\"image\" *ngIf=\"value\" [ngStyle]=\"{backgroundImage: getUrl(value)}\">\r\n <a class=\"btn btn-delete\" (click)=\"delete()\"></a>\r\n </li>\r\n </ul>\r\n <ul class=\"images\" *ngIf=\"data.multi\">\r\n <li class=\"image\" *ngFor=\"let image of value; let i = index\" [ngStyle]=\"{backgroundImage: getUrl(image)}\">\r\n <a class=\"btn btn-delete\" (click)=\"delete(i)\"></a>\r\n </li>\r\n </ul>\r\n</div>\r\n",
1983
+ styles: [".upload{display:inline-block}.upload ul{display:inline-flex;list-style:none;margin:10px 0 0;padding:0}.upload ul li{height:100px;width:100px;background:repeating-linear-gradient(45deg,gray,gray 10px,lightgray 10px,lightgray 20px) center center;background-size:cover;border:1px gray solid;margin-right:5px;position:relative}.upload .btn-delete{background:linear-gradient(to bottom,#c8607a,#a64d5a);border-color:#a64d5a;color:#fff;position:absolute;padding:0;right:5px;top:5px;width:20px;height:20px}.upload .btn-delete:before{color:#fff;display:block;position:absolute;top:0;right:6px;content:\"x\"}\n"]
1984
+ },] }
1985
+ ];
1986
+ DynamicFormFileComponent.ctorParameters = function () { return [
1987
+ { type: ngxUtils.ApiService },
1988
+ { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] }
1989
+ ]; };
1990
+
1991
+ var DynamicFormInputComponent = /** @class */ (function (_super) {
1992
+ __extends(DynamicFormInputComponent, _super);
1993
+ function DynamicFormInputComponent(language) {
1994
+ var _this = _super.call(this) || this;
1995
+ _this.language = language;
1996
+ return _this;
1997
+ }
1998
+ // Acceptor for provider
1999
+ DynamicFormInputComponent.acceptor = function (control) {
2000
+ return control.type == "input";
2001
+ };
2002
+ // Loader for provider
2003
+ DynamicFormInputComponent.loader = function () {
2004
+ return Promise.resolve();
2005
+ };
2006
+ Object.defineProperty(DynamicFormInputComponent.prototype, "isChecked", {
1285
2007
  get: function () {
1286
- return this.form.formService;
2008
+ return this.data.type == "checkbox" && this.value;
1287
2009
  },
1288
2010
  enumerable: false,
1289
2011
  configurable: true
1290
2012
  });
1291
- DynamicBaseFormControlContainerComponent.prototype.ngOnInit = function () {
1292
- var _this = this;
1293
- this.onDetectChanges = this.formService.onDetectChanges.subscribe(function (form) {
1294
- if (form !== _this.form)
1295
- return;
1296
- _this.changeDetectorRef.detectChanges();
1297
- _this.formService.updateSelectOptions(_this.model, _this.control);
1298
- });
1299
- };
1300
- DynamicBaseFormControlContainerComponent.prototype.ngOnDestroy = function () {
1301
- _super.prototype.ngOnDestroy.call(this);
1302
- this.onDetectChanges.unsubscribe();
2013
+ DynamicFormInputComponent.prototype.onDateChange = function (value) {
2014
+ var date = new Date(value);
2015
+ var dateValue = date.valueOf();
2016
+ if (isNaN(dateValue) || dateValue < -30610224000000)
2017
+ return;
2018
+ this.control.setValue(date);
1303
2019
  };
1304
- DynamicBaseFormControlContainerComponent.prototype.createFormControlComponent = function () {
1305
- var _a;
1306
- _super.prototype.createFormControlComponent.call(this);
1307
- var component = (_a = this.componentRef) === null || _a === void 0 ? void 0 : _a.instance;
1308
- if (!component || !ngxUtils.ObjectUtils.isFunction(component.onCreated))
2020
+ DynamicFormInputComponent.prototype.onTextChange = function (value) {
2021
+ var _this = this;
2022
+ if (!this.data.useLanguage) {
2023
+ this.control.setValue(value);
1309
2024
  return;
1310
- component.onCreated();
2025
+ }
2026
+ var translations = ngxUtils.ObjectUtils.isArray(this.value) ? Array.from(this.value) : [];
2027
+ var translation = translations.find(function (t) { return t.lang == _this.language.editLanguage; });
2028
+ if (translation) {
2029
+ translation.translation = value;
2030
+ }
2031
+ else {
2032
+ translations.push({
2033
+ lang: this.language.editLanguage,
2034
+ translation: value
2035
+ });
2036
+ }
2037
+ this.control.setValue(translations);
1311
2038
  };
1312
- DynamicBaseFormControlContainerComponent.prototype.getComponentType = function (model) {
1313
- return null;
2039
+ DynamicFormInputComponent.prototype.onNumberBlur = function () {
2040
+ var value = this.value;
2041
+ if (ngxUtils.ObjectUtils.isNumber(this.data.max) && this.data.max < value) {
2042
+ this.control.setValue(this.data.max);
2043
+ }
2044
+ else if (ngxUtils.ObjectUtils.isNumber(this.data.min) && this.data.min > value) {
2045
+ this.control.setValue(this.data.min);
2046
+ }
2047
+ this.control.onBlur();
1314
2048
  };
1315
- return DynamicBaseFormControlContainerComponent;
1316
- }(core.DynamicFormControlContainerComponent));
1317
- DynamicBaseFormControlContainerComponent.decorators = [
1318
- { type: core$1.Component, args: [{
1319
- selector: "dynamic-base-form-control",
1320
- template: "",
1321
- changeDetection: core$1.ChangeDetectionStrategy.OnPush
2049
+ return DynamicFormInputComponent;
2050
+ }(FormControlComponent));
2051
+ DynamicFormInputComponent.decorators = [
2052
+ { type: core.Component, args: [{
2053
+ moduleId: module.id,
2054
+ selector: "dynamic-form-input",
2055
+ template: "<ng-container [ngSwitch]=\"data.type\">\r\n <ng-container *ngSwitchCase=\"'textarea'\">\r\n <textarea class=\"form-control\"\r\n rows=\"5\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">{{ data.placeholder | translate }}</textarea>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'date'\">\r\n <input class=\"form-control\"\r\n type=\"date\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value | date: 'y-MM-dd'\"\r\n (ngModelChange)=\"onDateChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'number'\">\r\n <input class=\"form-control\"\r\n type=\"number\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [min]=\"data.min\"\r\n [max]=\"data.max\"\r\n [step]=\"data.step\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"onNumberBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'checkbox'\">\r\n <input class=\"form-control\"\r\n type=\"checkbox\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'text'\">\r\n <input class=\"form-control\"\r\n type=\"text\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [minlength]=\"data.min\"\r\n [maxlength]=\"data.max\"\r\n [placeholder]=\"data.placeholder | translate\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"data.useLanguage ? (value | translate) : value\"\r\n (ngModelChange)=\"onTextChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchDefault>\r\n <input class=\"form-control\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [minlength]=\"data.min\"\r\n [maxlength]=\"data.max\"\r\n [placeholder]=\"data.placeholder | translate\"\r\n [type]=\"data.type\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n</ng-container>\r\n"
1322
2056
  },] }
1323
2057
  ];
1324
- DynamicBaseFormControlContainerComponent.ctorParameters = function () { return [
1325
- { type: DynamicBaseFormComponent },
1326
- { type: core$1.ChangeDetectorRef },
1327
- { type: core$1.ComponentFactoryResolver },
1328
- { type: core.DynamicFormLayoutService },
1329
- { type: core.DynamicFormValidationService },
1330
- { type: core.DynamicFormComponentService },
1331
- { type: core.DynamicFormRelationService }
2058
+ DynamicFormInputComponent.ctorParameters = function () { return [
2059
+ { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.LANGUAGE_SERVICE,] }] }
1332
2060
  ]; };
1333
- DynamicBaseFormControlContainerComponent.propDecorators = {
1334
- contentTemplateList: [{ type: core$1.ContentChildren, args: [core.DynamicTemplateDirective,] }],
1335
- klass: [{ type: core$1.HostBinding, args: ["class",] }],
1336
- context: [{ type: core$1.Input }],
1337
- group: [{ type: core$1.Input }],
1338
- hostClass: [{ type: core$1.Input }],
1339
- inputTemplateList: [{ type: core$1.Input, args: ["templates",] }],
1340
- layout: [{ type: core$1.Input }],
1341
- model: [{ type: core$1.Input }],
1342
- blur: [{ type: core$1.Output }],
1343
- change: [{ type: core$1.Output }],
1344
- focus: [{ type: core$1.Output }],
1345
- componentViewContainerRef: [{ type: core$1.ViewChild, args: ["componentViewContainer", { read: core$1.ViewContainerRef, static: true },] }]
2061
+ DynamicFormInputComponent.propDecorators = {
2062
+ isChecked: [{ type: core.HostBinding, args: ["class.checked",] }]
1346
2063
  };
1347
2064
 
1348
- var DynamicFormValidationService = /** @class */ (function (_super) {
1349
- __extends(DynamicFormValidationService, _super);
1350
- function DynamicFormValidationService() {
2065
+ var DynamicFormSelectComponent = /** @class */ (function (_super) {
2066
+ __extends(DynamicFormSelectComponent, _super);
2067
+ function DynamicFormSelectComponent() {
2068
+ return _super !== null && _super.apply(this, arguments) || this;
2069
+ }
2070
+ // Acceptor for provider
2071
+ DynamicFormSelectComponent.acceptor = function (control) {
2072
+ return control.type == "select";
2073
+ };
2074
+ // Loader for provider
2075
+ DynamicFormSelectComponent.loader = function (control) {
2076
+ var data = control.getData();
2077
+ if (data.type == "radio" && data.multi) {
2078
+ return Promise.reject("Radio group doesn't support multi select!");
2079
+ }
2080
+ return new Promise(function (resolve) {
2081
+ var getOptions = ngxUtils.ReflectUtils.resolve(data.options, control.form.injector);
2082
+ getOptions(control).then(function (options) {
2083
+ if (data.emptyOption)
2084
+ options.unshift({ id: null, label: "" });
2085
+ control.meta.options = options;
2086
+ DynamicFormSelectComponent.fillOptions(control, options);
2087
+ resolve(options);
2088
+ });
2089
+ });
2090
+ };
2091
+ DynamicFormSelectComponent.fillOptions = function (control, options) {
2092
+ var data = control.getData();
2093
+ var selected = control.value;
2094
+ if (data.multi || options.length == 0 || options.findIndex(function (t) { return t.id == selected; }) >= 0)
2095
+ return;
2096
+ control.setValue(options[0].id);
2097
+ };
2098
+ DynamicFormSelectComponent.prototype.onSelectChange = function (value) {
2099
+ var isArray = ngxUtils.ObjectUtils.isArray(value);
2100
+ var current = this.value;
2101
+ if (this.data.multi) {
2102
+ if (isArray) {
2103
+ this.control.setValue(value);
2104
+ return;
2105
+ }
2106
+ if (ngxUtils.ObjectUtils.isArray(current)) {
2107
+ this.control.setValue(current.indexOf(value) < 0
2108
+ ? current.concat([value])
2109
+ : current.filter(function (c) { return c !== value; }));
2110
+ return;
2111
+ }
2112
+ this.control.setValue([value]);
2113
+ return;
2114
+ }
2115
+ if (isArray)
2116
+ value = value[0];
2117
+ if (current == value) {
2118
+ var option = this.meta.options.find(function (o) { return o.id !== value; });
2119
+ value = option ? option.id : null;
2120
+ }
2121
+ this.control.setValue(value);
2122
+ };
2123
+ DynamicFormSelectComponent.prototype.checkValue = function (option) {
2124
+ var value = this.value;
2125
+ return ngxUtils.ObjectUtils.isArray(value) ? value.indexOf(option.id) >= 0 : option.id == value;
2126
+ };
2127
+ DynamicFormSelectComponent.prototype.findOption = function (option, index, id) {
2128
+ return option.id == id;
2129
+ };
2130
+ return DynamicFormSelectComponent;
2131
+ }(FormControlComponent));
2132
+ DynamicFormSelectComponent.decorators = [
2133
+ { type: core.Component, args: [{
2134
+ moduleId: module.id,
2135
+ selector: "dynamic-form-select",
2136
+ template: "<ng-template #selectTemplate let-selected=\"selected\">\r\n <select class=\"form-control\"\r\n [multiple]=\"data.multi\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"data.multi ? value : [value]\"\r\n (ngModelChange)=\"onSelectChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">\r\n <option *ngFor=\"let option of meta.options\" [value]=\"option.id\" [disabled]=\"option.selectable == false\">\r\n {{ option.label | translate }}\r\n </option>\r\n </select>\r\n <label class=\"form-control-description\" [attr.for]=\"control.formId\" *ngIf=\"!data.multi && selected?.description\">\r\n {{ selected?.description | translate }}\r\n </label>\r\n</ng-template>\r\n<ng-container [ngSwitch]=\"data.type\">\r\n <ng-container *ngSwitchCase=\"'radio'\">\r\n <ul class=\"radio-group\">\r\n <li *ngFor=\"let option of meta.options\" class=\"radio\">\r\n <label [ngClass]=\"{checked: value == option.id}\">\r\n <input type=\"radio\"\r\n [id]=\"control.formId + '-' + option.id\"\r\n [name]=\"control.formId + '-' + option.id\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled || option.selectable == false\"\r\n [value]=\"option.id\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"onSelectChange(option.id)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">\r\n {{ option.label | translate }}\r\n </label>\r\n </li>\r\n </ul>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'checkbox'\">\r\n <ul class=\"checkbox-group\">\r\n <li *ngFor=\"let option of meta.options\" class=\"checkbox\">\r\n <label [ngClass]=\"{checked: checkValue(option)}\">\r\n <input type=\"checkbox\"\r\n [id]=\"control.formId + '-' + option.id\"\r\n [name]=\"control.formId + '-' + option.id\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled || option.selectable == false\"\r\n [ngModel]=\"checkValue(option)\"\r\n (ngModelChange)=\"onSelectChange(option.id)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">\r\n {{ option.label | translate }}\r\n </label>\r\n </li>\r\n </ul>\r\n </ng-container>\r\n <ng-container *ngSwitchDefault [ngTemplateOutlet]=\"selectTemplate\" [ngTemplateOutletContext]=\"{selected: meta?.options | find:findOption:value}\">\r\n\r\n </ng-container>\r\n</ng-container>\r\n"
2137
+ },] }
2138
+ ];
2139
+
2140
+ var DynamicFormStaticComponent = /** @class */ (function (_super) {
2141
+ __extends(DynamicFormStaticComponent, _super);
2142
+ function DynamicFormStaticComponent() {
1351
2143
  return _super !== null && _super.apply(this, arguments) || this;
1352
2144
  }
1353
- DynamicFormValidationService.prototype.showErrorMessages = function (control, model, hasFocus) {
1354
- return _super.prototype.showErrorMessages.call(this, control, model, hasFocus);
2145
+ // Acceptor for provider
2146
+ DynamicFormStaticComponent.acceptor = function (control) {
2147
+ return control.type == "static";
2148
+ };
2149
+ // Loader for provider
2150
+ DynamicFormStaticComponent.loader = function () {
2151
+ return Promise.resolve();
1355
2152
  };
1356
- return DynamicFormValidationService;
1357
- }(core.DynamicFormValidationService));
1358
- DynamicFormValidationService.decorators = [
1359
- { type: core$1.Injectable }
2153
+ return DynamicFormStaticComponent;
2154
+ }(FormControlComponent));
2155
+ DynamicFormStaticComponent.decorators = [
2156
+ { type: core.Component, args: [{
2157
+ moduleId: module.id,
2158
+ selector: "dynamic-form-static",
2159
+ template: "<unordered-list [listStyle]=\"data.style\" [ngClass]=\"{disabled: control.disabled}\"\r\n [data]=\"!data.properties ? {value: value} : data.properties | remap: value\">\r\n <ng-template [type]=\"!data.properties ? 'key' : null\" selector=\"level == 0\" let-item=\"item\"></ng-template>\r\n <ng-template type=\"value\" selector=\"valueType == 'date'\" let-item=\"item\">\r\n {{ item.value | date }}\r\n </ng-template>\r\n</unordered-list>\r\n"
2160
+ },] }
1360
2161
  ];
1361
2162
 
2163
+ var DynamicFormModelComponent = /** @class */ (function (_super) {
2164
+ __extends(DynamicFormModelComponent, _super);
2165
+ function DynamicFormModelComponent() {
2166
+ return _super !== null && _super.apply(this, arguments) || this;
2167
+ }
2168
+ // Acceptor for provider
2169
+ DynamicFormModelComponent.acceptor = function (control) {
2170
+ return control.type == "model";
2171
+ };
2172
+ // Loader for provider
2173
+ DynamicFormModelComponent.loader = function () {
2174
+ return Promise.resolve();
2175
+ };
2176
+ return DynamicFormModelComponent;
2177
+ }(FormControlComponent));
2178
+ DynamicFormModelComponent.decorators = [
2179
+ { type: core.Component, args: [{
2180
+ moduleId: module.id,
2181
+ selector: "dynamic-form-model",
2182
+ template: "<dynamic-form [name]=\"data.name || form.name\"\r\n [group]=\"control\"\r\n [data]=\"value\"\r\n [updateOn]=\"control.updateOn\"\r\n [parent]=\"form\"\r\n\r\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\r\n [controlTemplates]=\"form.controlTemplates\"\r\n\r\n [controlTemplate]=\"form.controlTemplate\"\r\n [labelTemplates]=\"form.labelTemplates\"\r\n [inputTemplates]=\"form.inputTemplates\"\r\n [prefixTemplates]=\"form.prefixTemplates\"\r\n [suffixTemplates]=\"form.suffixTemplates\"\r\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\r\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\r\n\r\n #subForm>\r\n <ng-template #wrapperTemplate let-form=\"form\" let-fieldSetsTemplate=\"fieldSetsTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"fieldSetsTemplate\"></ng-container>\r\n </ng-template>\r\n</dynamic-form>\r\n"
2183
+ },] }
2184
+ ];
2185
+ DynamicFormModelComponent.propDecorators = {
2186
+ subForm: [{ type: core.ViewChild, args: ["subForm",] }]
2187
+ };
2188
+
2189
+ var DynamicFormGroupDirective = /** @class */ (function () {
2190
+ function DynamicFormGroupDirective(vcr, forms) {
2191
+ this.vcr = vcr;
2192
+ this.forms = forms;
2193
+ }
2194
+ Object.defineProperty(DynamicFormGroupDirective.prototype, "component", {
2195
+ get: function () {
2196
+ return this.comp;
2197
+ },
2198
+ enumerable: false,
2199
+ configurable: true
2200
+ });
2201
+ DynamicFormGroupDirective.prototype.ngOnChanges = function (changes) {
2202
+ if (changes.control || changes.form || changes.visible) {
2203
+ if (!this.visible) {
2204
+ this.vcr.clear();
2205
+ this.comp = null;
2206
+ return;
2207
+ }
2208
+ this.comp = this.forms.createGroup(this.vcr);
2209
+ }
2210
+ if (!this.comp)
2211
+ return;
2212
+ this.comp.form = this.form;
2213
+ this.comp.control = this.control;
2214
+ };
2215
+ return DynamicFormGroupDirective;
2216
+ }());
2217
+ DynamicFormGroupDirective.decorators = [
2218
+ { type: core.Directive, args: [{
2219
+ selector: "[form-group]",
2220
+ },] }
2221
+ ];
2222
+ DynamicFormGroupDirective.ctorParameters = function () { return [
2223
+ { type: core.ViewContainerRef },
2224
+ { type: DynamicFormService }
2225
+ ]; };
2226
+ DynamicFormGroupDirective.propDecorators = {
2227
+ control: [{ type: core.Input, args: ["form-group",] }],
2228
+ form: [{ type: core.Input }],
2229
+ visible: [{ type: core.Input }]
2230
+ };
2231
+
1362
2232
  // --- Components ---
1363
2233
  var components = [
1364
- DynamicBaseFormComponent,
1365
- DynamicBaseFormControlContainerComponent
2234
+ DynamicFormsComponent,
2235
+ DynamicFormComponent,
2236
+ DynamicFormGroupComponent,
2237
+ DynamicFormFileComponent,
2238
+ DynamicFormInputComponent,
2239
+ DynamicFormSelectComponent,
2240
+ DynamicFormStaticComponent,
2241
+ DynamicFormModelComponent
1366
2242
  ];
1367
2243
  // --- Directives ---
1368
2244
  var directives = [
1369
2245
  AsyncSubmitDirective,
2246
+ DynamicFormControlDirective,
2247
+ DynamicFormGroupDirective,
2248
+ DynamicFormTemplateDirective
1370
2249
  ];
1371
2250
  // --- Pipes ---
1372
2251
  var pipes = [];
1373
- var ɵ0$1 = validateJSON, ɵ1 = validateRequiredTranslation, ɵ2 = validatePhone, ɵ3 = new Map([
1374
- ["validateJSON", validateJSON],
1375
- ["validateRequiredTranslation", validateRequiredTranslation],
1376
- ["validatePhone", validatePhone],
1377
- ]);
1378
2252
  var NgxDynamicFormModule = /** @class */ (function () {
1379
2253
  function NgxDynamicFormModule() {
1380
2254
  }
1381
- NgxDynamicFormModule.forRoot = function () {
2255
+ NgxDynamicFormModule.forRoot = function (controlProviders, groupProvider) {
1382
2256
  return {
1383
2257
  ngModule: NgxDynamicFormModule,
1384
- providers: [
2258
+ providers: __spreadArray(__spreadArray([
1385
2259
  DynamicFormService,
1386
- DynamicFormValidationService,
1387
- {
1388
- provide: core.DynamicFormService,
1389
- useExisting: DynamicFormService
1390
- },
1391
- {
1392
- provide: core.DynamicFormValidationService,
1393
- useExisting: DynamicFormValidationService
1394
- }
1395
- ]
2260
+ OpenApiService,
2261
+ provideFormControl(DynamicFormFileComponent, DynamicFormFileComponent.acceptor, DynamicFormFileComponent.loader),
2262
+ provideFormControl(DynamicFormInputComponent, DynamicFormInputComponent.acceptor, DynamicFormInputComponent.loader),
2263
+ provideFormControl(DynamicFormSelectComponent, DynamicFormSelectComponent.acceptor, DynamicFormSelectComponent.loader),
2264
+ provideFormControl(DynamicFormStaticComponent, DynamicFormStaticComponent.acceptor, DynamicFormStaticComponent.loader),
2265
+ provideFormControl(DynamicFormModelComponent, DynamicFormModelComponent.acceptor, DynamicFormModelComponent.loader)
2266
+ ], __read((controlProviders || []))), [
2267
+ groupProvider || provideFormGroup(DynamicFormGroupComponent)
2268
+ ])
1396
2269
  };
1397
2270
  };
1398
2271
  return NgxDynamicFormModule;
1399
2272
  }());
1400
2273
  NgxDynamicFormModule.decorators = [
1401
- { type: core$1.NgModule, args: [{
1402
- declarations: __spread(components, directives, pipes),
2274
+ { type: core.NgModule, args: [{
2275
+ declarations: __spreadArray(__spreadArray(__spreadArray([], __read(components)), __read(directives)), __read(pipes)),
1403
2276
  imports: [
1404
2277
  common.CommonModule,
1405
2278
  forms.FormsModule,
1406
2279
  forms.ReactiveFormsModule,
1407
2280
  ngxUtils.NgxUtilsModule
1408
2281
  ],
1409
- exports: __spread(components, directives, pipes, [
2282
+ exports: __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(components)), __read(directives)), __read(pipes)), [
1410
2283
  forms.FormsModule,
1411
2284
  forms.ReactiveFormsModule,
1412
2285
  ngxUtils.NgxUtilsModule
1413
2286
  ]),
1414
2287
  entryComponents: components,
1415
- providers: __spread(pipes, [
1416
- { provide: forms.NG_VALIDATORS, useValue: ɵ0$1, multi: true },
1417
- { provide: forms.NG_VALIDATORS, useValue: ɵ1, multi: true },
1418
- { provide: forms.NG_VALIDATORS, useValue: ɵ2, multi: true },
1419
- {
1420
- provide: core.DYNAMIC_VALIDATORS,
1421
- useValue: ɵ3
1422
- }
1423
- ])
2288
+ providers: pipes
1424
2289
  },] }
1425
2290
  ];
1426
2291
 
@@ -1429,9 +2294,22 @@
1429
2294
  */
1430
2295
 
1431
2296
  exports.AsyncSubmitDirective = AsyncSubmitDirective;
1432
- exports.DynamicBaseFormComponent = DynamicBaseFormComponent;
1433
- exports.DynamicBaseFormControlContainerComponent = DynamicBaseFormControlContainerComponent;
2297
+ exports.DynamicFormBaseComponent = DynamicFormBaseComponent;
2298
+ exports.DynamicFormComponent = DynamicFormComponent;
2299
+ exports.DynamicFormControl = DynamicFormControl;
2300
+ exports.DynamicFormControlDirective = DynamicFormControlDirective;
2301
+ exports.DynamicFormFileComponent = DynamicFormFileComponent;
2302
+ exports.DynamicFormGroup = DynamicFormGroup;
2303
+ exports.DynamicFormGroupComponent = DynamicFormGroupComponent;
2304
+ exports.DynamicFormInputComponent = DynamicFormInputComponent;
2305
+ exports.DynamicFormModelComponent = DynamicFormModelComponent;
2306
+ exports.DynamicFormSelectComponent = DynamicFormSelectComponent;
1434
2307
  exports.DynamicFormService = DynamicFormService;
2308
+ exports.DynamicFormStaticComponent = DynamicFormStaticComponent;
2309
+ exports.DynamicFormTemplateDirective = DynamicFormTemplateDirective;
2310
+ exports.DynamicFormsComponent = DynamicFormsComponent;
2311
+ exports.FORM_CONTROL_PROVIDER = FORM_CONTROL_PROVIDER;
2312
+ exports.FormControlComponent = FormControlComponent;
1435
2313
  exports.FormFieldSet = FormFieldSet;
1436
2314
  exports.FormFile = FormFile;
1437
2315
  exports.FormInput = FormInput;
@@ -1439,8 +2317,9 @@
1439
2317
  exports.FormSelect = FormSelect;
1440
2318
  exports.FormSerializable = FormSerializable;
1441
2319
  exports.FormStatic = FormStatic;
1442
- exports.FormSubject = FormSubject;
2320
+ exports.FormUtilities = FormUtilities;
1443
2321
  exports.NgxDynamicFormModule = NgxDynamicFormModule;
2322
+ exports.OpenApiService = OpenApiService;
1444
2323
  exports.createFormControl = createFormControl;
1445
2324
  exports.createFormInput = createFormInput;
1446
2325
  exports.createFormModel = createFormModel;
@@ -1451,15 +2330,15 @@
1451
2330
  exports.getFormControl = getFormControl;
1452
2331
  exports.getFormFieldSets = getFormFieldSets;
1453
2332
  exports.getFormSerializer = getFormSerializer;
1454
- exports.validateJSON = validateJSON;
1455
- exports.validatePhone = validatePhone;
1456
- exports.validateRequiredTranslation = validateRequiredTranslation;
1457
- exports.ɵa = components;
1458
- exports.ɵb = directives;
1459
- exports.ɵc = pipes;
1460
- exports.ɵd = DynamicFormValidationService;
2333
+ exports.provideFormControl = provideFormControl;
2334
+ exports.provideFormGroup = provideFormGroup;
2335
+ exports["ɵa"] = FORM_GROUP_TYPE;
2336
+ exports["ɵb"] = components;
2337
+ exports["ɵc"] = directives;
2338
+ exports["ɵd"] = pipes;
2339
+ exports["ɵe"] = DynamicFormGroupDirective;
1461
2340
 
1462
2341
  Object.defineProperty(exports, '__esModule', { value: true });
1463
2342
 
1464
- })));
2343
+ }));
1465
2344
  //# sourceMappingURL=stemy-ngx-dynamic-form.umd.js.map