@stemy/ngx-dynamic-form 12.0.0 → 13.0.2
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.
- package/esm2020/ngx-dynamic-form/common-types.mjs +97 -0
- package/esm2020/ngx-dynamic-form/components/base/dynamic-base-form-array.component.mjs +85 -0
- package/esm2020/ngx-dynamic-form/components/base/dynamic-base-form-control-container.component.mjs +109 -0
- package/esm2020/ngx-dynamic-form/components/base/dynamic-base-form-group.component.mjs +74 -0
- package/esm2020/ngx-dynamic-form/components/base/dynamic-base-form.component.mjs +158 -0
- package/esm2020/ngx-dynamic-form/directives/async-submit.directive.mjs +111 -0
- package/esm2020/ngx-dynamic-form/ngx-dynamic-form.imports.mjs +22 -0
- package/esm2020/ngx-dynamic-form/ngx-dynamic-form.module.mjs +115 -0
- package/esm2020/ngx-dynamic-form/services/dynamic-form.service.mjs +451 -0
- package/esm2020/ngx-dynamic-form/utils/dynamic-form-array.model.mjs +16 -0
- package/esm2020/ngx-dynamic-form/utils/form-select-subject.mjs +23 -0
- package/esm2020/ngx-dynamic-form/utils/form-subject.mjs +29 -0
- package/esm2020/ngx-dynamic-form/utils/misc.mjs +20 -0
- package/esm2020/ngx-dynamic-form/utils/validators.mjs +56 -0
- package/esm2020/public_api.mjs +14 -0
- package/esm2020/stemy-ngx-dynamic-form.mjs +5 -0
- package/fesm2015/stemy-ngx-dynamic-form.mjs +1341 -0
- package/fesm2015/stemy-ngx-dynamic-form.mjs.map +1 -0
- package/fesm2020/stemy-ngx-dynamic-form.mjs +1313 -0
- package/fesm2020/stemy-ngx-dynamic-form.mjs.map +1 -0
- package/ngx-dynamic-form/common-types.d.ts +42 -262
- package/ngx-dynamic-form/components/base/dynamic-base-form-array.component.d.ts +29 -0
- package/ngx-dynamic-form/components/base/dynamic-base-form-control-container.component.d.ts +41 -0
- package/ngx-dynamic-form/components/base/dynamic-base-form-group.component.d.ts +24 -0
- package/ngx-dynamic-form/components/base/dynamic-base-form.component.d.ts +41 -0
- package/ngx-dynamic-form/directives/async-submit.directive.d.ts +10 -3
- package/ngx-dynamic-form/ngx-dynamic-form.imports.d.ts +10 -0
- package/ngx-dynamic-form/ngx-dynamic-form.module.d.ts +14 -17
- package/ngx-dynamic-form/services/dynamic-form.service.d.ts +47 -10
- package/ngx-dynamic-form/utils/dynamic-form-array.model.d.ts +22 -0
- package/ngx-dynamic-form/utils/form-select-subject.d.ts +6 -0
- package/ngx-dynamic-form/utils/form-subject.d.ts +10 -0
- package/ngx-dynamic-form/utils/misc.d.ts +5 -0
- package/ngx-dynamic-form/utils/validators.d.ts +8 -0
- package/package.json +42 -22
- package/public_api.d.ts +10 -14
- package/stemy-ngx-dynamic-form.d.ts +1 -3
- package/bundles/stemy-ngx-dynamic-form.umd.js +0 -2344
- package/bundles/stemy-ngx-dynamic-form.umd.js.map +0 -1
- package/esm2015/ngx-dynamic-form/common-types.js +0 -590
- package/esm2015/ngx-dynamic-form/components/base/dynamic-form-base.component.js +0 -87
- package/esm2015/ngx-dynamic-form/components/dynamic-form/dynamic-form.component.js +0 -91
- package/esm2015/ngx-dynamic-form/components/dynamic-form-file/dynamic-form-file.component.js +0 -112
- package/esm2015/ngx-dynamic-form/components/dynamic-form-group/dynamic-form-group.component.js +0 -19
- package/esm2015/ngx-dynamic-form/components/dynamic-form-input/dynamic-form-input.component.js +0 -69
- package/esm2015/ngx-dynamic-form/components/dynamic-form-model/dynamic-form-model.component.js +0 -23
- package/esm2015/ngx-dynamic-form/components/dynamic-form-select/dynamic-form-select.component.js +0 -73
- package/esm2015/ngx-dynamic-form/components/dynamic-form-static/dynamic-form-static.component.js +0 -20
- package/esm2015/ngx-dynamic-form/components/dynamic-forms/dynamic-forms.component.js +0 -134
- package/esm2015/ngx-dynamic-form/directives/async-submit.directive.js +0 -89
- package/esm2015/ngx-dynamic-form/directives/dynamic-form-control.directive.js +0 -32
- package/esm2015/ngx-dynamic-form/directives/dynamic-form-group.directive.js +0 -40
- package/esm2015/ngx-dynamic-form/directives/dynamic-form-template.directive.js +0 -38
- package/esm2015/ngx-dynamic-form/ngx-dynamic-form.module.js +0 -83
- package/esm2015/ngx-dynamic-form/services/dynamic-form.service.js +0 -48
- package/esm2015/ngx-dynamic-form/services/form-utilities.js +0 -108
- package/esm2015/ngx-dynamic-form/services/open-api.service.js +0 -130
- package/esm2015/public_api.js +0 -18
- package/esm2015/stemy-ngx-dynamic-form.js +0 -8
- package/fesm2015/stemy-ngx-dynamic-form.js +0 -1731
- package/fesm2015/stemy-ngx-dynamic-form.js.map +0 -1
- package/ngx-dynamic-form/components/base/dynamic-form-base.component.d.ts +0 -44
- package/ngx-dynamic-form/components/dynamic-form/dynamic-form.component.d.ts +0 -21
- package/ngx-dynamic-form/components/dynamic-form-file/dynamic-form-file.component.d.ts +0 -16
- package/ngx-dynamic-form/components/dynamic-form-group/dynamic-form-group.component.d.ts +0 -6
- package/ngx-dynamic-form/components/dynamic-form-input/dynamic-form-input.component.d.ts +0 -12
- package/ngx-dynamic-form/components/dynamic-form-model/dynamic-form-model.component.d.ts +0 -6
- package/ngx-dynamic-form/components/dynamic-form-select/dynamic-form-select.component.d.ts +0 -9
- package/ngx-dynamic-form/components/dynamic-form-static/dynamic-form-static.component.d.ts +0 -5
- package/ngx-dynamic-form/components/dynamic-forms/dynamic-forms.component.d.ts +0 -26
- package/ngx-dynamic-form/directives/dynamic-form-control.directive.d.ts +0 -12
- package/ngx-dynamic-form/directives/dynamic-form-group.directive.d.ts +0 -14
- package/ngx-dynamic-form/directives/dynamic-form-template.directive.d.ts +0 -16
- package/ngx-dynamic-form/services/form-utilities.d.ts +0 -19
- package/ngx-dynamic-form/services/open-api.service.d.ts +0 -37
- package/stemy-ngx-dynamic-form.metadata.json +0 -1
|
@@ -0,0 +1,1341 @@
|
|
|
1
|
+
import * as i2 from '@stemy/ngx-utils';
|
|
2
|
+
import { ReflectUtils, ObjectUtils, StringUtils, OpenApiService, TOASTER_SERVICE, ObservableUtils, EventsService, NgxUtilsModule } from '@stemy/ngx-utils';
|
|
3
|
+
import * as i1 from '@ng-dynamic-forms/core';
|
|
4
|
+
import { DynamicFormArrayModel as DynamicFormArrayModel$1, DynamicFormService as DynamicFormService$1, DynamicSelectModel, DynamicFormGroupModel, DynamicInputModel, DynamicFileUploadModel, DynamicCheckboxModel, DynamicTextAreaModel, DynamicFormComponent, DynamicTemplateDirective, DynamicFormArrayComponent, DynamicFormValueControlModel, DynamicFormControlContainerComponent, DYNAMIC_FORM_CONTROL_TYPE_ARRAY, DynamicFormGroupComponent, DYNAMIC_FORM_CONTROL_MAP_FN, DYNAMIC_VALIDATORS } from '@ng-dynamic-forms/core';
|
|
5
|
+
import { Subject, Subscription } from 'rxjs';
|
|
6
|
+
import { __awaiter } from 'tslib';
|
|
7
|
+
import * as i0 from '@angular/core';
|
|
8
|
+
import { EventEmitter, Injector, Injectable, Inject, Directive, Input, Output, HostBinding, HostListener, QueryList, Component, ChangeDetectionStrategy, ContentChildren, ViewChildren, ViewChild, forwardRef, ViewContainerRef, NgModule } from '@angular/core';
|
|
9
|
+
import { FormGroup, FormArray, NgForm, FormsModule, ReactiveFormsModule, NG_VALIDATORS } from '@angular/forms';
|
|
10
|
+
import { first } from 'rxjs/operators';
|
|
11
|
+
import { CommonModule } from '@angular/common';
|
|
12
|
+
|
|
13
|
+
// --- Decorator functions ---
|
|
14
|
+
function defaultSerializer(id, parent) {
|
|
15
|
+
const control = parent.get(id);
|
|
16
|
+
return !control ? null : control.value;
|
|
17
|
+
}
|
|
18
|
+
function FormSerializable(serializer) {
|
|
19
|
+
return (target, propertyKey) => {
|
|
20
|
+
ReflectUtils.defineMetadata("dynamicFormSerializer", serializer || defaultSerializer, target, propertyKey);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function FormInput(data) {
|
|
24
|
+
return (target, propertyKey) => {
|
|
25
|
+
const meta = ReflectUtils.getOwnMetadata("design:type", target, propertyKey);
|
|
26
|
+
const type = meta ? meta.name : "";
|
|
27
|
+
let inputType = propertyKey.indexOf("password") < 0 ? "text" : "password";
|
|
28
|
+
switch (type) {
|
|
29
|
+
case "Number":
|
|
30
|
+
inputType = "number";
|
|
31
|
+
break;
|
|
32
|
+
case "Boolean":
|
|
33
|
+
inputType = "checkbox";
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
defineFormControl(target, propertyKey, createFormInput(propertyKey, data, inputType));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function FormSelect(data) {
|
|
40
|
+
return (target, propertyKey) => {
|
|
41
|
+
defineFormControl(target, propertyKey, createFormSelect(propertyKey, data));
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function FormStatic(data) {
|
|
45
|
+
return (target, propertyKey) => {
|
|
46
|
+
defineFormControl(target, propertyKey, createFormStatic(propertyKey, data));
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function FormModel(data) {
|
|
50
|
+
return (target, propertyKey) => {
|
|
51
|
+
defineFormControl(target, propertyKey, createFormModel(propertyKey, data));
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function FormFile(data) {
|
|
55
|
+
return (target, propertyKey) => {
|
|
56
|
+
defineFormControl(target, propertyKey, createFormFile(propertyKey, data));
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function defineFormControl(target, propertyKey, control) {
|
|
60
|
+
ReflectUtils.defineMetadata("dynamicFormControl", control, target, propertyKey);
|
|
61
|
+
}
|
|
62
|
+
function getFormControl(target, propertyKey) {
|
|
63
|
+
return ReflectUtils.getMetadata("dynamicFormControl", target, propertyKey);
|
|
64
|
+
}
|
|
65
|
+
function getFormSerializer(target, propertyKey) {
|
|
66
|
+
return ReflectUtils.getMetadata("dynamicFormSerializer", target, propertyKey);
|
|
67
|
+
}
|
|
68
|
+
function createFormControl(id, type, config) {
|
|
69
|
+
config = config || { id };
|
|
70
|
+
config.id = id;
|
|
71
|
+
config.label = ObjectUtils.isNullOrUndefined(config.label) ? id : config.label;
|
|
72
|
+
config.disabled = config.disabled || false;
|
|
73
|
+
config.hidden = config.hidden || false;
|
|
74
|
+
return { id, type, config };
|
|
75
|
+
}
|
|
76
|
+
function createFormInput(id, config, type = "text") {
|
|
77
|
+
const control = createFormControl(id, "input", config);
|
|
78
|
+
config = control.config;
|
|
79
|
+
config.inputType = config.inputType || type;
|
|
80
|
+
config.placeholder = config.placeholder || (config.inputType == "mask" ? "_" : "");
|
|
81
|
+
config.step = config.step || 1;
|
|
82
|
+
config.mask = config.mask || null;
|
|
83
|
+
return control;
|
|
84
|
+
}
|
|
85
|
+
function createFormSelect(id, data) {
|
|
86
|
+
const control = createFormControl(id, "select", data);
|
|
87
|
+
data = control.config;
|
|
88
|
+
data.options = data.options || [];
|
|
89
|
+
return control;
|
|
90
|
+
}
|
|
91
|
+
function createFormStatic(id, config) {
|
|
92
|
+
return createFormControl(id, "static", config);
|
|
93
|
+
}
|
|
94
|
+
function createFormModel(id, data) {
|
|
95
|
+
const control = createFormControl(id, "group", data);
|
|
96
|
+
data = control.config;
|
|
97
|
+
data.name = data.name || "";
|
|
98
|
+
return control;
|
|
99
|
+
}
|
|
100
|
+
function createFormFile(id, data) {
|
|
101
|
+
const control = createFormControl(id, "file", data);
|
|
102
|
+
data = control.config;
|
|
103
|
+
data.accept = data.accept || ["jpg", "jpeg", "png"];
|
|
104
|
+
data.multiple = data.multiple || false;
|
|
105
|
+
data.url = ObjectUtils.isString(data.url) ? data.url : "assets";
|
|
106
|
+
return control;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isStringWithVal(val) {
|
|
110
|
+
return typeof val == "string" && val.length > 0;
|
|
111
|
+
}
|
|
112
|
+
function collectPathAble(start, getter) {
|
|
113
|
+
if (!start || !getter(start))
|
|
114
|
+
return [];
|
|
115
|
+
const parts = [];
|
|
116
|
+
let currentPath = start;
|
|
117
|
+
while (currentPath) {
|
|
118
|
+
const val = getter(currentPath);
|
|
119
|
+
if (val) {
|
|
120
|
+
parts.unshift(val);
|
|
121
|
+
}
|
|
122
|
+
currentPath = currentPath.parent;
|
|
123
|
+
}
|
|
124
|
+
return parts;
|
|
125
|
+
}
|
|
126
|
+
const MIN_INPUT_NUM = -99999999999999;
|
|
127
|
+
const MAX_INPUT_NUM = 99999999999999;
|
|
128
|
+
|
|
129
|
+
function validateJSON(control) {
|
|
130
|
+
const value = control.value;
|
|
131
|
+
if (!value)
|
|
132
|
+
return null;
|
|
133
|
+
try {
|
|
134
|
+
JSON.parse(value);
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
return { json: true };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function validateRequiredTranslation(control) {
|
|
142
|
+
const value = control.value;
|
|
143
|
+
if (!value || value.length == 0)
|
|
144
|
+
return { requiredTranslation: true };
|
|
145
|
+
return value.findIndex(t => (t.lang == "de" || t.lang == "en") && !t.translation) < 0
|
|
146
|
+
? null
|
|
147
|
+
: { requiredTranslation: true };
|
|
148
|
+
}
|
|
149
|
+
function validatePhone(control) {
|
|
150
|
+
const value = control.value;
|
|
151
|
+
if (!value)
|
|
152
|
+
return Promise.resolve(null);
|
|
153
|
+
const phoneRegexp = /^(?:\d){10,12}$/;
|
|
154
|
+
return phoneRegexp.test(value) ? null : { phone: true };
|
|
155
|
+
}
|
|
156
|
+
function validateItemsMinLength(minLength) {
|
|
157
|
+
return (control) => {
|
|
158
|
+
const value = control.value;
|
|
159
|
+
return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length >= minLength))
|
|
160
|
+
? null : { itemsMinLength: minLength };
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function validateItemsMaxLength(maxLength) {
|
|
164
|
+
return (control) => {
|
|
165
|
+
const value = control.value;
|
|
166
|
+
return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length <= maxLength))
|
|
167
|
+
? null : { itemsMaxLength: maxLength };
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function validateItemsMinValue(min) {
|
|
171
|
+
return (control) => {
|
|
172
|
+
const value = control.value;
|
|
173
|
+
return (Array.isArray(value) && value.every(v => typeof v == "number" && v >= min))
|
|
174
|
+
? null : { itemsMinValue: min };
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function validateItemsMaxValue(max) {
|
|
178
|
+
return (control) => {
|
|
179
|
+
const value = control.value;
|
|
180
|
+
return (Array.isArray(value) && value.every(v => typeof v == "number" && v <= max))
|
|
181
|
+
? null : { itemsMaxValue: max };
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
class DynamicFormArrayModel extends DynamicFormArrayModel$1 {
|
|
186
|
+
constructor(config, layout) {
|
|
187
|
+
super(config, layout);
|
|
188
|
+
this.useTabs = config.useTabs || false;
|
|
189
|
+
this.saveTab = ObjectUtils.isFunction(config.saveTab) ? config.saveTab : ((index, model) => {
|
|
190
|
+
model.tabIndex = index;
|
|
191
|
+
});
|
|
192
|
+
this.restoreTab = ObjectUtils.isFunction(config.restoreTab) ? config.restoreTab : ((model) => {
|
|
193
|
+
return model.tabIndex;
|
|
194
|
+
});
|
|
195
|
+
this.additional = config.additional || {};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const indexLabels = ["$ix", "$pix"];
|
|
200
|
+
class FormSubject extends Subject {
|
|
201
|
+
constructor(notifyCallback) {
|
|
202
|
+
super();
|
|
203
|
+
this.notifyCallback = notifyCallback;
|
|
204
|
+
}
|
|
205
|
+
handleNotifiedValue(controlModel, control, val) {
|
|
206
|
+
val.then(v => this.next(v));
|
|
207
|
+
}
|
|
208
|
+
notify(controlModel, control, root) {
|
|
209
|
+
const indexes = {};
|
|
210
|
+
let path = controlModel;
|
|
211
|
+
let ix = 0;
|
|
212
|
+
while (path) {
|
|
213
|
+
if (!isNaN(path.index)) {
|
|
214
|
+
const key = indexLabels[ix++] || `$pix${ix}`;
|
|
215
|
+
indexes[key] = path.index;
|
|
216
|
+
}
|
|
217
|
+
path = path.parent;
|
|
218
|
+
}
|
|
219
|
+
let value = this.notifyCallback(controlModel, control, root, indexes);
|
|
220
|
+
if (!(value instanceof Promise)) {
|
|
221
|
+
value = Promise.resolve(value);
|
|
222
|
+
}
|
|
223
|
+
this.handleNotifiedValue(controlModel, control, value);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
class FormSelectSubject extends FormSubject {
|
|
228
|
+
handleNotifiedValue(controlModel, control, val) {
|
|
229
|
+
val.then(options => {
|
|
230
|
+
var _a, _b;
|
|
231
|
+
this.next(options);
|
|
232
|
+
if (options.length == 0)
|
|
233
|
+
return;
|
|
234
|
+
const currentVal = control.value;
|
|
235
|
+
if (controlModel.multiple) {
|
|
236
|
+
const correctVal = (currentVal || []).filter(t => options.findIndex(o => o.value == t) >= 0);
|
|
237
|
+
if (correctVal.length !== (currentVal === null || currentVal === void 0 ? void 0 : currentVal.length)) {
|
|
238
|
+
control.setValue(correctVal, { onlySelf: true, emitEvent: false });
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const option = options.find(t => t.value == currentVal);
|
|
243
|
+
if (!option) {
|
|
244
|
+
control.setValue((_b = (_a = options[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null, { onlySelf: true, emitEvent: false });
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
class DynamicFormService extends DynamicFormService$1 {
|
|
251
|
+
constructor(cs, vs, openApi, injector) {
|
|
252
|
+
super(cs, vs);
|
|
253
|
+
this.openApi = openApi;
|
|
254
|
+
this.injector = injector;
|
|
255
|
+
this.onDetectChanges = new EventEmitter();
|
|
256
|
+
}
|
|
257
|
+
get api() {
|
|
258
|
+
return this.openApi.api;
|
|
259
|
+
}
|
|
260
|
+
get language() {
|
|
261
|
+
return this.api.language;
|
|
262
|
+
}
|
|
263
|
+
patchGroup(value, formModel, formGroup) {
|
|
264
|
+
this.patchValueRecursive(value, formModel, formGroup);
|
|
265
|
+
this.detectChanges();
|
|
266
|
+
formGroup.patchValue(ObjectUtils.copy(value));
|
|
267
|
+
}
|
|
268
|
+
patchForm(value, component) {
|
|
269
|
+
this.patchValueRecursive(value, component.model, component.group);
|
|
270
|
+
this.detectChanges(component);
|
|
271
|
+
component.group.patchValue(value);
|
|
272
|
+
}
|
|
273
|
+
serialize(formModel, formGroup) {
|
|
274
|
+
return this.serializeRecursive(formModel, formGroup);
|
|
275
|
+
}
|
|
276
|
+
notifyChanges(formModel, formGroup, root) {
|
|
277
|
+
this.notifyChangesRecursive(formModel, formGroup, root);
|
|
278
|
+
}
|
|
279
|
+
updateSelectOptions(formControlModel, formControl, root) {
|
|
280
|
+
if (formControlModel instanceof DynamicSelectModel) {
|
|
281
|
+
let options = formControlModel.options$;
|
|
282
|
+
if (options instanceof FormSubject) {
|
|
283
|
+
options.notify(formControlModel, formControl, root);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
while (options instanceof Subject && options.source) {
|
|
287
|
+
options = options.source;
|
|
288
|
+
if (options instanceof FormSubject) {
|
|
289
|
+
options.notify(formControlModel, formControl, root);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
showErrors(form) {
|
|
295
|
+
this.showErrorsForGroup(form.group);
|
|
296
|
+
this.detectChanges(form);
|
|
297
|
+
}
|
|
298
|
+
detectChanges(formComponent) {
|
|
299
|
+
super.detectChanges(formComponent);
|
|
300
|
+
this.onDetectChanges.emit(formComponent);
|
|
301
|
+
}
|
|
302
|
+
patchValueRecursive(value, formModel, formGroup) {
|
|
303
|
+
Object.keys(value).forEach(key => {
|
|
304
|
+
const subModel = this.findModelById(key, formModel);
|
|
305
|
+
const subValue = value[key];
|
|
306
|
+
if (!subModel)
|
|
307
|
+
return;
|
|
308
|
+
const subControl = this.findControlByModel(subModel, formGroup);
|
|
309
|
+
if (subModel instanceof DynamicSelectModel && ObjectUtils.isObject(subValue)) {
|
|
310
|
+
value[key] = subValue.id || subValue._id || subValue;
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (subModel instanceof DynamicFormArrayModel$1) {
|
|
314
|
+
const length = Array.isArray(subValue) ? subValue.length : 0;
|
|
315
|
+
const subArray = subControl;
|
|
316
|
+
while (subModel.size > length) {
|
|
317
|
+
this.removeFormArrayGroup(0, subArray, subModel);
|
|
318
|
+
}
|
|
319
|
+
while (subModel.size < length) {
|
|
320
|
+
this.insertFormArrayGroup(subModel.size, subArray, subModel);
|
|
321
|
+
}
|
|
322
|
+
for (let i = 0; i < length; i++) {
|
|
323
|
+
const itemModel = subModel.get(i);
|
|
324
|
+
this.patchValueRecursive(subValue[i], itemModel.group, subArray.at(i));
|
|
325
|
+
}
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (subModel instanceof DynamicFormGroupModel) {
|
|
329
|
+
this.patchValueRecursive(subValue, subModel.group, subControl);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
serializeRecursive(formModel, formGroup) {
|
|
334
|
+
var _a, _b;
|
|
335
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
336
|
+
const result = {};
|
|
337
|
+
if (!formModel || !formGroup || !formGroup.value)
|
|
338
|
+
return result;
|
|
339
|
+
for (const i in formModel) {
|
|
340
|
+
const subModel = formModel[i];
|
|
341
|
+
const subControl = this.findControlByModel(subModel, formGroup);
|
|
342
|
+
const serializer = (_a = subModel.additional) === null || _a === void 0 ? void 0 : _a.serializer;
|
|
343
|
+
if (ObjectUtils.isFunction(serializer)) {
|
|
344
|
+
result[subModel.id] = yield serializer(subModel, subControl);
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (subModel instanceof DynamicFormArrayModel$1) {
|
|
348
|
+
const length = Array.isArray(subControl.value) ? subControl.value.length : 0;
|
|
349
|
+
const subArray = subControl;
|
|
350
|
+
const resArray = [];
|
|
351
|
+
for (let i = 0; i < length; i++) {
|
|
352
|
+
const itemModel = subModel.get(i);
|
|
353
|
+
resArray.push(yield this.serializeRecursive(itemModel.group, subArray.at(i)));
|
|
354
|
+
}
|
|
355
|
+
result[subModel.id] = resArray;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
if (subModel instanceof DynamicFormGroupModel) {
|
|
359
|
+
result[subModel.id] = yield this.serializeRecursive(subModel.group, subControl);
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (subModel instanceof DynamicInputModel && !ObjectUtils.isNullOrUndefined(subControl.value)) {
|
|
363
|
+
result[subModel.id] = subModel.inputType == "number"
|
|
364
|
+
? (_b = parseFloat((`${subControl.value}` || "0").replace(/,/gi, "."))) !== null && _b !== void 0 ? _b : null
|
|
365
|
+
: subControl.value;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
result[subModel.id] = subControl.value;
|
|
369
|
+
}
|
|
370
|
+
return result;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
notifyChangesRecursive(formModel, formGroup, root) {
|
|
374
|
+
if (!formModel || !formGroup)
|
|
375
|
+
return;
|
|
376
|
+
for (const i in formModel) {
|
|
377
|
+
const subModel = formModel[i];
|
|
378
|
+
const subControl = this.findControlByModel(subModel, formGroup);
|
|
379
|
+
if (subModel instanceof DynamicFormArrayModel$1) {
|
|
380
|
+
const length = Array.isArray(subControl.value) ? subControl.value.length : 0;
|
|
381
|
+
const subArray = subControl;
|
|
382
|
+
for (let i = 0; i < length; i++) {
|
|
383
|
+
const itemModel = subModel.get(i);
|
|
384
|
+
this.notifyChangesRecursive(itemModel.group, subArray.at(i), root);
|
|
385
|
+
}
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
if (subModel instanceof DynamicFormGroupModel) {
|
|
389
|
+
this.notifyChangesRecursive(subModel.group, subControl, root);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
this.updateSelectOptions(subModel, subControl, root);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
showErrorsForGroup(formGroup) {
|
|
396
|
+
if (!formGroup)
|
|
397
|
+
return;
|
|
398
|
+
formGroup.markAsTouched({ onlySelf: true });
|
|
399
|
+
const controls = Object.keys(formGroup.controls).map(id => formGroup.controls[id]);
|
|
400
|
+
this.showErrorsForControls(controls);
|
|
401
|
+
}
|
|
402
|
+
showErrorsForControls(controls) {
|
|
403
|
+
controls.forEach(control => {
|
|
404
|
+
if (control instanceof FormGroup) {
|
|
405
|
+
this.showErrorsForGroup(control);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
control.markAsTouched({ onlySelf: true });
|
|
409
|
+
if (control instanceof FormArray) {
|
|
410
|
+
this.showErrorsForControls(control.controls);
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
getFormModelForSchema(name, customizeModel) {
|
|
415
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
416
|
+
this.api.cache = {};
|
|
417
|
+
this.schemas = yield this.openApi.getSchemas();
|
|
418
|
+
const customizeModels = (property, schema, modelType, config) => {
|
|
419
|
+
const model = new modelType(config);
|
|
420
|
+
if (!ObjectUtils.isFunction(customizeModel))
|
|
421
|
+
return [model];
|
|
422
|
+
const res = customizeModel(property, schema, model, config, this.injector);
|
|
423
|
+
return Array.isArray(res) ? res : [res];
|
|
424
|
+
};
|
|
425
|
+
return this.getFormModelForSchemaDef(this.schemas[name], customizeModels);
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
getFormModelForSchemaDef(schema, customizeModels) {
|
|
429
|
+
if (!schema)
|
|
430
|
+
return [];
|
|
431
|
+
const keys = Object.keys(schema.properties || {});
|
|
432
|
+
const controls = [];
|
|
433
|
+
for (const p of keys) {
|
|
434
|
+
const property = schema.properties[p];
|
|
435
|
+
controls.push(...this.getFormControlModels(property, schema, customizeModels));
|
|
436
|
+
}
|
|
437
|
+
return controls.filter(t => null !== t);
|
|
438
|
+
}
|
|
439
|
+
getFormControlModels(property, schema, customizeModels) {
|
|
440
|
+
var _a, _b;
|
|
441
|
+
const $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
|
|
442
|
+
if (Array.isArray($enum) || isStringWithVal(property.optionsPath) || isStringWithVal(property.endpoint)) {
|
|
443
|
+
return customizeModels(property, schema, DynamicSelectModel, this.getFormSelectConfig(property, schema));
|
|
444
|
+
}
|
|
445
|
+
switch (property.type) {
|
|
446
|
+
case "string":
|
|
447
|
+
case "number":
|
|
448
|
+
case "integer":
|
|
449
|
+
return customizeModels(property, schema, DynamicInputModel, this.getFormInputConfig(property, schema));
|
|
450
|
+
case "textarea":
|
|
451
|
+
return customizeModels(property, schema, DynamicTextAreaModel, this.getFormTextareaConfig(property, schema));
|
|
452
|
+
case "boolean":
|
|
453
|
+
return customizeModels(property, schema, DynamicCheckboxModel, this.getFormCheckboxConfig(property, schema));
|
|
454
|
+
case "array":
|
|
455
|
+
if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.$ref) || property.$ref) {
|
|
456
|
+
return customizeModels(property, schema, DynamicFormArrayModel, this.getFormArrayConfig(property, schema, customizeModels));
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
return customizeModels(property, schema, DynamicInputModel, this.getFormInputConfig(property, schema));
|
|
460
|
+
}
|
|
461
|
+
case "file":
|
|
462
|
+
return customizeModels(property, schema, DynamicFileUploadModel, this.getFormUploadConfig(property, schema));
|
|
463
|
+
}
|
|
464
|
+
if (property.$ref) {
|
|
465
|
+
return customizeModels(property, schema, DynamicFormGroupModel, this.getFormGroupConfig(property, schema, customizeModels));
|
|
466
|
+
}
|
|
467
|
+
return [];
|
|
468
|
+
}
|
|
469
|
+
findModelByPath(parent, path) {
|
|
470
|
+
if (path.length == 0)
|
|
471
|
+
return parent;
|
|
472
|
+
const next = path.shift();
|
|
473
|
+
if (Array.isArray(parent)) {
|
|
474
|
+
return this.findModelByPath(parent.find(t => t.id == next), path);
|
|
475
|
+
}
|
|
476
|
+
if (parent instanceof DynamicFormGroupModel) {
|
|
477
|
+
return this.findModelByPath(parent.group.find(t => t.id == next), path);
|
|
478
|
+
}
|
|
479
|
+
if (parent instanceof DynamicFormArrayModel) {
|
|
480
|
+
return this.findModelByPath(parent.groups.find(t => t.index == next), path);
|
|
481
|
+
}
|
|
482
|
+
return parent;
|
|
483
|
+
}
|
|
484
|
+
getFormControlConfig(property, schema) {
|
|
485
|
+
const validators = this.getValidators(property, schema);
|
|
486
|
+
const errorMessages = Object.keys(validators).reduce((res, key) => {
|
|
487
|
+
res[key] = `error.${key}`;
|
|
488
|
+
return res;
|
|
489
|
+
}, {});
|
|
490
|
+
return {
|
|
491
|
+
id: property.id,
|
|
492
|
+
label: ObjectUtils.isString(property.label) ? property.label : property.id,
|
|
493
|
+
hidden: property.hidden,
|
|
494
|
+
disabled: property.disabled,
|
|
495
|
+
validators,
|
|
496
|
+
errorMessages,
|
|
497
|
+
additional: Object.assign({}, property)
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
getFormArrayConfig(property, schema, customizeModels) {
|
|
501
|
+
var _a;
|
|
502
|
+
const ref = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref) || property.$ref || "";
|
|
503
|
+
const subSchema = this.schemas[ref.split("/").pop()];
|
|
504
|
+
return Object.assign(this.getFormControlConfig(property, schema), {
|
|
505
|
+
groupFactory: () => this.getFormModelForSchemaDef(subSchema, customizeModels),
|
|
506
|
+
useTabs: property.useTabs || false
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
getFormGroupConfig(property, schema, customizeModels) {
|
|
510
|
+
const ref = property.$ref || "";
|
|
511
|
+
const subSchema = this.schemas[ref.split("/").pop()];
|
|
512
|
+
return Object.assign(this.getFormControlConfig(property, schema), { group: this.getFormModelForSchemaDef(subSchema, customizeModels) });
|
|
513
|
+
}
|
|
514
|
+
getFormInputConfig(property, schema) {
|
|
515
|
+
var _a;
|
|
516
|
+
let inputType = StringUtils.has(property.id, "password", "Password") ? "password" : (property.format || ((_a = property.items) === null || _a === void 0 ? void 0 : _a.type) || property.type);
|
|
517
|
+
switch (inputType) {
|
|
518
|
+
case "boolean":
|
|
519
|
+
inputType = "checkbox";
|
|
520
|
+
break;
|
|
521
|
+
case "textarea":
|
|
522
|
+
inputType = "textarea";
|
|
523
|
+
break;
|
|
524
|
+
case "integer":
|
|
525
|
+
inputType = "number";
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
const sub = property.type == "array" ? property.items || property : property;
|
|
529
|
+
return Object.assign(this.getFormControlConfig(property, schema), {
|
|
530
|
+
inputType,
|
|
531
|
+
autoComplete: property.autoComplete || "off",
|
|
532
|
+
multiple: property.type == "array",
|
|
533
|
+
accept: ObjectUtils.isString(property.accept) ? property.accept : null,
|
|
534
|
+
mask: ObjectUtils.isString(property.mask) ? property.mask : null,
|
|
535
|
+
pattern: ObjectUtils.isString(property.pattern) ? property.pattern : null,
|
|
536
|
+
step: isNaN(sub.step) ? (isNaN(property.step) ? 1 : property.step) : sub.step,
|
|
537
|
+
min: isNaN(sub.minimum) ? MIN_INPUT_NUM : sub.minimum,
|
|
538
|
+
max: isNaN(sub.maximum) ? MAX_INPUT_NUM : sub.maximum,
|
|
539
|
+
minLength: isNaN(sub.minLength) ? MIN_INPUT_NUM : sub.minLength,
|
|
540
|
+
maxLength: isNaN(sub.maxLength) ? MAX_INPUT_NUM : sub.maxLength,
|
|
541
|
+
placeholder: property.placeholder || ""
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
getFormTextareaConfig(property, schema) {
|
|
545
|
+
return Object.assign(this.getFormControlConfig(property, schema), {
|
|
546
|
+
cols: property.cols || null,
|
|
547
|
+
rows: property.rows || 10,
|
|
548
|
+
wrap: property.wrap || false,
|
|
549
|
+
autoComplete: property.autoComplete || "off",
|
|
550
|
+
multiple: property.type == "array"
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
getFormSelectConfig(property, schema) {
|
|
554
|
+
return Object.assign(this.getFormControlConfig(property, schema), {
|
|
555
|
+
options: this.getFormSelectOptions(property, schema),
|
|
556
|
+
multiple: property.type == "array"
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
getFormCheckboxConfig(property, schema) {
|
|
560
|
+
return Object.assign(this.getFormControlConfig(property, schema), {
|
|
561
|
+
indeterminate: property.indeterminate === true
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
translateOptions(options) {
|
|
565
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
566
|
+
if (!options)
|
|
567
|
+
return [];
|
|
568
|
+
for (const option of options) {
|
|
569
|
+
option.label = yield this.language.getTranslation(option.label);
|
|
570
|
+
}
|
|
571
|
+
return options;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
getFormSelectOptions(property, schema) {
|
|
575
|
+
var _a;
|
|
576
|
+
const $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
|
|
577
|
+
if (Array.isArray($enum)) {
|
|
578
|
+
return new FormSelectSubject(() => {
|
|
579
|
+
const options = $enum.map(value => {
|
|
580
|
+
const label = property.translatable ? `${property.id}.${value}` : `${value}`;
|
|
581
|
+
return { value, label };
|
|
582
|
+
});
|
|
583
|
+
return this.translateOptions(options);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
if (isStringWithVal(property.optionsPath)) {
|
|
587
|
+
return new FormSelectSubject((formModel, control, root, indexes) => {
|
|
588
|
+
let path = property.optionsPath;
|
|
589
|
+
let target = control;
|
|
590
|
+
let model = formModel;
|
|
591
|
+
if (path.startsWith("$root")) {
|
|
592
|
+
path = path.substr(5);
|
|
593
|
+
while (target.parent) {
|
|
594
|
+
target = target.parent;
|
|
595
|
+
}
|
|
596
|
+
model = root;
|
|
597
|
+
}
|
|
598
|
+
while (path.startsWith(".")) {
|
|
599
|
+
path = path.substr(1);
|
|
600
|
+
if (target.parent) {
|
|
601
|
+
target = target.parent;
|
|
602
|
+
}
|
|
603
|
+
model = model.parent || root;
|
|
604
|
+
}
|
|
605
|
+
Object.keys(indexes).forEach(key => {
|
|
606
|
+
path = path.replace(key, indexes[key]);
|
|
607
|
+
});
|
|
608
|
+
model = this.findModelByPath(model, path.split("."));
|
|
609
|
+
const modelOptions = (model instanceof DynamicSelectModel ? model.options : []);
|
|
610
|
+
const value = ObjectUtils.getValue(target.value, path);
|
|
611
|
+
const options = (!ObjectUtils.isArray(value) ? [] : value).map(value => {
|
|
612
|
+
const modelOption = modelOptions.find(t => t.value == value);
|
|
613
|
+
return { value, label: (modelOption === null || modelOption === void 0 ? void 0 : modelOption.label) || value };
|
|
614
|
+
});
|
|
615
|
+
return this.translateOptions(options);
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
return new FormSelectSubject(() => __awaiter(this, void 0, void 0, function* () {
|
|
619
|
+
this.api.cache[property.endpoint] = this.api.cache[property.endpoint] || this.api.list(property.endpoint, this.api.makeListParams(1, -1)).then(result => {
|
|
620
|
+
return result.items.map(i => {
|
|
621
|
+
return { value: i.id || i._id, label: i[property.labelField] || i.label || i.id || i._id };
|
|
622
|
+
});
|
|
623
|
+
});
|
|
624
|
+
const options = (yield this.api.cache[property.endpoint]).map(t => Object.assign({}, t));
|
|
625
|
+
return this.translateOptions(options);
|
|
626
|
+
}));
|
|
627
|
+
}
|
|
628
|
+
getFormUploadConfig(property, schema) {
|
|
629
|
+
const url = this.api.url(property.url || "assets");
|
|
630
|
+
const { accept, autoUpload, maxSize, minSize, removeUrl, showFileList } = property;
|
|
631
|
+
return Object.assign(this.getFormControlConfig(property, schema), {
|
|
632
|
+
url,
|
|
633
|
+
accept,
|
|
634
|
+
autoUpload,
|
|
635
|
+
maxSize,
|
|
636
|
+
minSize,
|
|
637
|
+
removeUrl,
|
|
638
|
+
showFileList
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
getValidators(property, schema) {
|
|
642
|
+
const validators = {};
|
|
643
|
+
if (ObjectUtils.isArray(schema.required) && schema.required.indexOf(property.id) >= 0) {
|
|
644
|
+
validators.required = null;
|
|
645
|
+
}
|
|
646
|
+
this.addPropertyValidators(validators, property);
|
|
647
|
+
this.addItemsValidators(validators, property.items);
|
|
648
|
+
return validators;
|
|
649
|
+
}
|
|
650
|
+
addPropertyValidators(validators, property) {
|
|
651
|
+
if (!property)
|
|
652
|
+
return;
|
|
653
|
+
if (!isNaN(property.minLength)) {
|
|
654
|
+
validators.minLength = property.minLength;
|
|
655
|
+
}
|
|
656
|
+
if (!isNaN(property.maxLength)) {
|
|
657
|
+
validators.maxLength = property.maxLength;
|
|
658
|
+
}
|
|
659
|
+
if (!isNaN(property.minimum)) {
|
|
660
|
+
validators.min = property.minimum;
|
|
661
|
+
}
|
|
662
|
+
if (!isNaN(property.maximum)) {
|
|
663
|
+
validators.max = property.maximum;
|
|
664
|
+
}
|
|
665
|
+
switch (property.format) {
|
|
666
|
+
case "email":
|
|
667
|
+
validators.email = null;
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
addItemsValidators(validators, items) {
|
|
672
|
+
if (!items)
|
|
673
|
+
return;
|
|
674
|
+
if (!isNaN(items.minLength)) {
|
|
675
|
+
validators.itemsMinLength = items.minLength;
|
|
676
|
+
}
|
|
677
|
+
if (!isNaN(items.maxLength)) {
|
|
678
|
+
validators.itemsMaxLength = items.maxLength;
|
|
679
|
+
}
|
|
680
|
+
if (!isNaN(items.minimum)) {
|
|
681
|
+
validators.itemsMinValue = items.minimum;
|
|
682
|
+
}
|
|
683
|
+
if (!isNaN(items.maximum)) {
|
|
684
|
+
validators.itemsMaxValue = items.maximum;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
DynamicFormService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicFormService, deps: [{ token: i1.DynamicFormComponentService }, { token: i1.DynamicFormValidationService }, { token: OpenApiService }, { token: Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
689
|
+
DynamicFormService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicFormService });
|
|
690
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicFormService, decorators: [{
|
|
691
|
+
type: Injectable
|
|
692
|
+
}], ctorParameters: function () {
|
|
693
|
+
return [{ type: i1.DynamicFormComponentService }, { type: i1.DynamicFormValidationService }, { type: i2.OpenApiService, decorators: [{
|
|
694
|
+
type: Inject,
|
|
695
|
+
args: [OpenApiService]
|
|
696
|
+
}] }, { type: i0.Injector, decorators: [{
|
|
697
|
+
type: Inject,
|
|
698
|
+
args: [Injector]
|
|
699
|
+
}] }];
|
|
700
|
+
} });
|
|
701
|
+
|
|
702
|
+
class AsyncSubmitDirective {
|
|
703
|
+
constructor(toaster, cdr, elem, renderer) {
|
|
704
|
+
this.toaster = toaster;
|
|
705
|
+
this.cdr = cdr;
|
|
706
|
+
this.elem = elem;
|
|
707
|
+
this.renderer = renderer;
|
|
708
|
+
this.onSuccess = new EventEmitter();
|
|
709
|
+
this.onError = new EventEmitter();
|
|
710
|
+
if (elem.nativeElement.tagName !== "BUTTON")
|
|
711
|
+
return;
|
|
712
|
+
renderer.setAttribute(elem.nativeElement, "type", "button");
|
|
713
|
+
}
|
|
714
|
+
get isDisabled() {
|
|
715
|
+
return this.disabled;
|
|
716
|
+
}
|
|
717
|
+
set isDisabled(value) {
|
|
718
|
+
this.disabled = value;
|
|
719
|
+
if (value) {
|
|
720
|
+
this.renderer.setAttribute(this.elem.nativeElement, "disabled", "disabled");
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
this.renderer.removeAttribute(this.elem.nativeElement, "disabled");
|
|
724
|
+
}
|
|
725
|
+
get isLoading() {
|
|
726
|
+
return this.loading;
|
|
727
|
+
}
|
|
728
|
+
ngOnInit() {
|
|
729
|
+
if (!this.form)
|
|
730
|
+
return;
|
|
731
|
+
this.isDisabled = this.form.status !== "VALID";
|
|
732
|
+
this.cdr.detectChanges();
|
|
733
|
+
this.onStatusChange = this.form.onStatusChange.subscribe(() => {
|
|
734
|
+
this.isDisabled = this.form.status !== "VALID";
|
|
735
|
+
this.cdr.detectChanges();
|
|
736
|
+
if (!this.callback || this.form.status == "PENDING")
|
|
737
|
+
return;
|
|
738
|
+
if (!this.disabled) {
|
|
739
|
+
this.callback();
|
|
740
|
+
}
|
|
741
|
+
this.callback = null;
|
|
742
|
+
});
|
|
743
|
+
this.onSubmit = this.form.onSubmit.subscribe(() => this.callMethod());
|
|
744
|
+
}
|
|
745
|
+
ngOnDestroy() {
|
|
746
|
+
if (this.onStatusChange)
|
|
747
|
+
this.onStatusChange.unsubscribe();
|
|
748
|
+
if (this.onSubmit)
|
|
749
|
+
this.onSubmit.unsubscribe();
|
|
750
|
+
}
|
|
751
|
+
click() {
|
|
752
|
+
this.callback = () => this.callMethod();
|
|
753
|
+
if (this.form.status !== "VALID" && this.form.status !== "INVALID")
|
|
754
|
+
return;
|
|
755
|
+
this.callback();
|
|
756
|
+
this.callback = null;
|
|
757
|
+
}
|
|
758
|
+
callMethod() {
|
|
759
|
+
if (this.loading)
|
|
760
|
+
return;
|
|
761
|
+
this.loading = true;
|
|
762
|
+
this.method(this.form, this.context).then(result => {
|
|
763
|
+
this.loading = false;
|
|
764
|
+
if (result) {
|
|
765
|
+
this.onSuccess.emit(result);
|
|
766
|
+
this.toaster.success(result.message, result.context);
|
|
767
|
+
}
|
|
768
|
+
}, reason => {
|
|
769
|
+
if (!reason || !reason.message)
|
|
770
|
+
throw new Error("Reason must implement IAsyncMessage interface");
|
|
771
|
+
this.loading = false;
|
|
772
|
+
this.onError.emit(reason);
|
|
773
|
+
this.toaster.error(reason.message, reason.context);
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
AsyncSubmitDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AsyncSubmitDirective, deps: [{ token: TOASTER_SERVICE }, { token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
|
|
778
|
+
AsyncSubmitDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.8", type: AsyncSubmitDirective, selector: "[async-submit]", inputs: { method: ["async-submit", "method"], form: "form", context: "context" }, outputs: { onSuccess: "onSuccess", onError: "onError" }, host: { listeners: { "click": "click()" }, properties: { "class.disabled": "this.isDisabled", "class.loading": "this.isLoading" } }, exportAs: ["async-submit"], ngImport: i0 });
|
|
779
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AsyncSubmitDirective, decorators: [{
|
|
780
|
+
type: Directive,
|
|
781
|
+
args: [{
|
|
782
|
+
selector: "[async-submit]",
|
|
783
|
+
exportAs: "async-submit"
|
|
784
|
+
}]
|
|
785
|
+
}], ctorParameters: function () {
|
|
786
|
+
return [{ type: undefined, decorators: [{
|
|
787
|
+
type: Inject,
|
|
788
|
+
args: [TOASTER_SERVICE]
|
|
789
|
+
}] }, { type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i0.Renderer2 }];
|
|
790
|
+
}, propDecorators: { method: [{
|
|
791
|
+
type: Input,
|
|
792
|
+
args: ["async-submit"]
|
|
793
|
+
}], form: [{
|
|
794
|
+
type: Input
|
|
795
|
+
}], context: [{
|
|
796
|
+
type: Input
|
|
797
|
+
}], onSuccess: [{
|
|
798
|
+
type: Output
|
|
799
|
+
}], onError: [{
|
|
800
|
+
type: Output
|
|
801
|
+
}], isDisabled: [{
|
|
802
|
+
type: HostBinding,
|
|
803
|
+
args: ["class.disabled"]
|
|
804
|
+
}], isLoading: [{
|
|
805
|
+
type: HostBinding,
|
|
806
|
+
args: ["class.loading"]
|
|
807
|
+
}], click: [{
|
|
808
|
+
type: HostListener,
|
|
809
|
+
args: ["click"]
|
|
810
|
+
}] } });
|
|
811
|
+
|
|
812
|
+
class DynamicBaseFormComponent extends DynamicFormComponent {
|
|
813
|
+
constructor(formService, events, changeDetectorRef, componentService) {
|
|
814
|
+
super(changeDetectorRef, componentService);
|
|
815
|
+
this.formService = formService;
|
|
816
|
+
this.events = events;
|
|
817
|
+
this.blur = new EventEmitter();
|
|
818
|
+
this.change = new EventEmitter();
|
|
819
|
+
this.focus = new EventEmitter();
|
|
820
|
+
this.onValueChange = new EventEmitter();
|
|
821
|
+
this.onStatusChange = new EventEmitter();
|
|
822
|
+
this.onSubmit = new EventEmitter();
|
|
823
|
+
this.templates = new QueryList();
|
|
824
|
+
this.subscription = new Subscription();
|
|
825
|
+
this.groupSubscription = new Subscription();
|
|
826
|
+
this.labelPrefix = "label";
|
|
827
|
+
}
|
|
828
|
+
get status() {
|
|
829
|
+
return !this.group ? null : this.group.status;
|
|
830
|
+
}
|
|
831
|
+
ngOnChanges(changes) {
|
|
832
|
+
this.groupSubscription.unsubscribe();
|
|
833
|
+
if (this.group) {
|
|
834
|
+
this.groupSubscription = ObservableUtils.multiSubscription(this.group.statusChanges.subscribe(() => {
|
|
835
|
+
this.onStatusChange.emit(this);
|
|
836
|
+
}), this.group.valueChanges.subscribe(() => {
|
|
837
|
+
this.formService.notifyChanges(this.model, this.group, this.model);
|
|
838
|
+
}), this.change.subscribe(ev => {
|
|
839
|
+
this.onValueChange.emit(Object.assign(Object.assign({}, ev), { form: this }));
|
|
840
|
+
}));
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
ngAfterViewInit() {
|
|
844
|
+
this.subscription = ObservableUtils.multiSubscription(ObservableUtils.subscribe({
|
|
845
|
+
subjects: [this.contentTemplates.changes, this.viewTemplates.changes],
|
|
846
|
+
cb: () => {
|
|
847
|
+
const templates = this.contentTemplates.toArray().concat(this.viewTemplates.toArray());
|
|
848
|
+
this.templates.reset(templates);
|
|
849
|
+
}
|
|
850
|
+
}), this.events.languageChanged.subscribe(() => {
|
|
851
|
+
this.formService.detectChanges(this);
|
|
852
|
+
}), this.ngForm.ngSubmit.subscribe(() => {
|
|
853
|
+
this.onSubmit.emit(this);
|
|
854
|
+
}));
|
|
855
|
+
}
|
|
856
|
+
ngOnDestroy() {
|
|
857
|
+
super.ngOnDestroy();
|
|
858
|
+
this.subscription.unsubscribe();
|
|
859
|
+
this.groupSubscription.unsubscribe();
|
|
860
|
+
}
|
|
861
|
+
insertFormArrayGroup(index, formArray, formArrayModel) {
|
|
862
|
+
this.formService.insertFormArrayGroup(index, formArray, formArrayModel);
|
|
863
|
+
this.changeDetectorRef.detectChanges();
|
|
864
|
+
}
|
|
865
|
+
removeFormArrayGroup(index, formArray, formArrayModel) {
|
|
866
|
+
this.formService.removeFormArrayGroup(index, formArray, formArrayModel);
|
|
867
|
+
this.changeDetectorRef.detectChanges();
|
|
868
|
+
}
|
|
869
|
+
moveFormArrayGroup(index, step, formArray, formArrayModel) {
|
|
870
|
+
this.formService.moveFormArrayGroup(index, step, formArray, formArrayModel);
|
|
871
|
+
this.changeDetectorRef.detectChanges();
|
|
872
|
+
}
|
|
873
|
+
clearFormArray(formArray, formArrayModel) {
|
|
874
|
+
this.formService.clearFormArray(formArray, formArrayModel);
|
|
875
|
+
this.changeDetectorRef.detectChanges();
|
|
876
|
+
}
|
|
877
|
+
getClass(model) {
|
|
878
|
+
const parts = collectPathAble(model, p => p.id);
|
|
879
|
+
if (parts.length == 0)
|
|
880
|
+
return "";
|
|
881
|
+
if (model instanceof DynamicFormGroupModel) {
|
|
882
|
+
return `form-group-${parts.join("-")}`;
|
|
883
|
+
}
|
|
884
|
+
return `form-control-${parts.join("-")}`;
|
|
885
|
+
}
|
|
886
|
+
validate(showErrors = true) {
|
|
887
|
+
if (!this.group)
|
|
888
|
+
return Promise.resolve();
|
|
889
|
+
return new Promise((resolve, reject) => {
|
|
890
|
+
this.group.statusChanges.pipe(first(status => status == "VALID" || status == "INVALID")).subscribe(status => {
|
|
891
|
+
if (showErrors) {
|
|
892
|
+
this.formService.showErrors(this);
|
|
893
|
+
}
|
|
894
|
+
if (status == "VALID") {
|
|
895
|
+
resolve(null);
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
reject(null);
|
|
899
|
+
});
|
|
900
|
+
this.group.updateValueAndValidity();
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
serialize(validate) {
|
|
904
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
905
|
+
if (!this.group)
|
|
906
|
+
return null;
|
|
907
|
+
if (validate) {
|
|
908
|
+
yield this.validate();
|
|
909
|
+
}
|
|
910
|
+
return yield this.formService.serialize(this.model, this.group);
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
DynamicBaseFormComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicBaseFormComponent, deps: [{ token: DynamicFormService }, { token: EventsService }, { token: i0.ChangeDetectorRef }, { token: i1.DynamicFormComponentService }], target: i0.ɵɵFactoryTarget.Component });
|
|
915
|
+
DynamicBaseFormComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.8", type: DynamicBaseFormComponent, selector: "dynamic-base-form", inputs: { group: "group", model: "model", layout: "layout", labelPrefix: "labelPrefix" }, outputs: { blur: "blur", change: "change", focus: "focus", onValueChange: "onValueChange", onStatusChange: "onStatusChange", onSubmit: "onSubmit" }, queries: [{ propertyName: "contentTemplates", predicate: DynamicTemplateDirective }], viewQueries: [{ propertyName: "ngForm", first: true, predicate: NgForm, descendants: true }, { propertyName: "viewTemplates", predicate: DynamicTemplateDirective, descendants: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "", isInline: true, changeDetection: i0.ChangeDetectionStrategy.Default });
|
|
916
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicBaseFormComponent, decorators: [{
|
|
917
|
+
type: Component,
|
|
918
|
+
args: [{
|
|
919
|
+
selector: "dynamic-base-form",
|
|
920
|
+
template: "",
|
|
921
|
+
changeDetection: ChangeDetectionStrategy.Default
|
|
922
|
+
}]
|
|
923
|
+
}], ctorParameters: function () {
|
|
924
|
+
return [{ type: DynamicFormService, decorators: [{
|
|
925
|
+
type: Inject,
|
|
926
|
+
args: [DynamicFormService]
|
|
927
|
+
}] }, { type: i2.EventsService, decorators: [{
|
|
928
|
+
type: Inject,
|
|
929
|
+
args: [EventsService]
|
|
930
|
+
}] }, { type: i0.ChangeDetectorRef }, { type: i1.DynamicFormComponentService }];
|
|
931
|
+
}, propDecorators: { group: [{
|
|
932
|
+
type: Input
|
|
933
|
+
}], model: [{
|
|
934
|
+
type: Input
|
|
935
|
+
}], layout: [{
|
|
936
|
+
type: Input
|
|
937
|
+
}], labelPrefix: [{
|
|
938
|
+
type: Input
|
|
939
|
+
}], blur: [{
|
|
940
|
+
type: Output
|
|
941
|
+
}], change: [{
|
|
942
|
+
type: Output
|
|
943
|
+
}], focus: [{
|
|
944
|
+
type: Output
|
|
945
|
+
}], contentTemplates: [{
|
|
946
|
+
type: ContentChildren,
|
|
947
|
+
args: [DynamicTemplateDirective]
|
|
948
|
+
}], viewTemplates: [{
|
|
949
|
+
type: ViewChildren,
|
|
950
|
+
args: [DynamicTemplateDirective]
|
|
951
|
+
}], onValueChange: [{
|
|
952
|
+
type: Output
|
|
953
|
+
}], onStatusChange: [{
|
|
954
|
+
type: Output
|
|
955
|
+
}], onSubmit: [{
|
|
956
|
+
type: Output
|
|
957
|
+
}], ngForm: [{
|
|
958
|
+
type: ViewChild,
|
|
959
|
+
args: [NgForm]
|
|
960
|
+
}] } });
|
|
961
|
+
|
|
962
|
+
class DynamicBaseFormArrayComponent extends DynamicFormArrayComponent {
|
|
963
|
+
constructor(layoutService, validationService, injector) {
|
|
964
|
+
super(layoutService, validationService);
|
|
965
|
+
this.layoutService = layoutService;
|
|
966
|
+
this.validationService = validationService;
|
|
967
|
+
this.injector = injector;
|
|
968
|
+
this.blur = new EventEmitter();
|
|
969
|
+
this.change = new EventEmitter();
|
|
970
|
+
this.customEvent = new EventEmitter();
|
|
971
|
+
this.focus = new EventEmitter();
|
|
972
|
+
}
|
|
973
|
+
get useTabs() {
|
|
974
|
+
var _a;
|
|
975
|
+
return (_a = this.model) === null || _a === void 0 ? void 0 : _a.useTabs;
|
|
976
|
+
}
|
|
977
|
+
saveTab(index) {
|
|
978
|
+
this.model.saveTab(index, this.model, this.injector);
|
|
979
|
+
}
|
|
980
|
+
restoreTab() {
|
|
981
|
+
return this.model.restoreTab(this.model, this.injector);
|
|
982
|
+
}
|
|
983
|
+
getClass(context, place, model) {
|
|
984
|
+
var _a;
|
|
985
|
+
return [
|
|
986
|
+
context == "element" ? this.getModelClass(model) : null,
|
|
987
|
+
context == "element" ? this.getAdditionalClass(model) : null,
|
|
988
|
+
super.getClass(context, place, model),
|
|
989
|
+
model instanceof DynamicFormValueControlModel ? (_a = model.additional) === null || _a === void 0 ? void 0 : _a.classes : null
|
|
990
|
+
].filter(cls => !!cls).join(" ");
|
|
991
|
+
}
|
|
992
|
+
getModelClass(model) {
|
|
993
|
+
const parts = collectPathAble(model, p => p.id);
|
|
994
|
+
if (parts.length == 0)
|
|
995
|
+
return "";
|
|
996
|
+
if (model instanceof DynamicFormGroupModel) {
|
|
997
|
+
return `form-group-${parts.join("-")}`;
|
|
998
|
+
}
|
|
999
|
+
return `form-control-${parts.join("-")}`;
|
|
1000
|
+
}
|
|
1001
|
+
getAdditionalClass(model) {
|
|
1002
|
+
var _a, _b;
|
|
1003
|
+
if (model instanceof DynamicFormArrayModel) {
|
|
1004
|
+
return (_a = model.additional) === null || _a === void 0 ? void 0 : _a.classes;
|
|
1005
|
+
}
|
|
1006
|
+
if (model instanceof DynamicFormValueControlModel) {
|
|
1007
|
+
return (_b = model.additional) === null || _b === void 0 ? void 0 : _b.classes;
|
|
1008
|
+
}
|
|
1009
|
+
return null;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
DynamicBaseFormArrayComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicBaseFormArrayComponent, deps: [{ token: i1.DynamicFormLayoutService }, { token: i1.DynamicFormValidationService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component });
|
|
1013
|
+
DynamicBaseFormArrayComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.8", type: DynamicBaseFormArrayComponent, selector: "dynamic-base-form-array", inputs: { formLayout: "formLayout", group: "group", layout: "layout", model: "model", templates: "templates" }, outputs: { blur: "blur", change: "change", customEvent: "customEvent", focus: "focus" }, viewQueries: [{ propertyName: "components", predicate: i0.forwardRef(function () { return DynamicFormControlContainerComponent; }), descendants: true }], usesInheritance: true, ngImport: i0, template: "", isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1014
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicBaseFormArrayComponent, decorators: [{
|
|
1015
|
+
type: Component,
|
|
1016
|
+
args: [{
|
|
1017
|
+
selector: "dynamic-base-form-array",
|
|
1018
|
+
template: "",
|
|
1019
|
+
changeDetection: ChangeDetectionStrategy.OnPush
|
|
1020
|
+
}]
|
|
1021
|
+
}], ctorParameters: function () { return [{ type: i1.DynamicFormLayoutService }, { type: i1.DynamicFormValidationService }, { type: i0.Injector }]; }, propDecorators: { formLayout: [{
|
|
1022
|
+
type: Input
|
|
1023
|
+
}], group: [{
|
|
1024
|
+
type: Input
|
|
1025
|
+
}], layout: [{
|
|
1026
|
+
type: Input
|
|
1027
|
+
}], model: [{
|
|
1028
|
+
type: Input
|
|
1029
|
+
}], templates: [{
|
|
1030
|
+
type: Input
|
|
1031
|
+
}], blur: [{
|
|
1032
|
+
type: Output
|
|
1033
|
+
}], change: [{
|
|
1034
|
+
type: Output
|
|
1035
|
+
}], customEvent: [{
|
|
1036
|
+
type: Output
|
|
1037
|
+
}], focus: [{
|
|
1038
|
+
type: Output
|
|
1039
|
+
}], components: [{
|
|
1040
|
+
type: ViewChildren,
|
|
1041
|
+
args: [forwardRef(() => DynamicFormControlContainerComponent)]
|
|
1042
|
+
}] } });
|
|
1043
|
+
|
|
1044
|
+
class DynamicBaseFormControlContainerComponent extends DynamicFormControlContainerComponent {
|
|
1045
|
+
constructor(form, changeDetectorRef, componentFactoryResolver, layoutService, validationService, componentService, relationService) {
|
|
1046
|
+
super(changeDetectorRef, componentFactoryResolver, layoutService, validationService, componentService, relationService);
|
|
1047
|
+
this.form = form;
|
|
1048
|
+
this.changeDetectorRef = changeDetectorRef;
|
|
1049
|
+
this.componentFactoryResolver = componentFactoryResolver;
|
|
1050
|
+
this.layoutService = layoutService;
|
|
1051
|
+
this.validationService = validationService;
|
|
1052
|
+
this.componentService = componentService;
|
|
1053
|
+
this.relationService = relationService;
|
|
1054
|
+
this.context = null;
|
|
1055
|
+
this.blur = new EventEmitter();
|
|
1056
|
+
this.change = new EventEmitter();
|
|
1057
|
+
this.focus = new EventEmitter();
|
|
1058
|
+
}
|
|
1059
|
+
get componentType() {
|
|
1060
|
+
var _a;
|
|
1061
|
+
return (_a = this.componentService.getCustomComponentType(this.model)) !== null && _a !== void 0 ? _a : this.getComponentType(this.model);
|
|
1062
|
+
}
|
|
1063
|
+
get startTemplate() {
|
|
1064
|
+
return (this.model.type == DYNAMIC_FORM_CONTROL_TYPE_ARRAY)
|
|
1065
|
+
? this.layoutService.getAlignedTemplate(this.model, this.templates, "ARRAY_START")
|
|
1066
|
+
: this.layoutService.getStartTemplate(this.model, this.templates);
|
|
1067
|
+
}
|
|
1068
|
+
get endTemplate() {
|
|
1069
|
+
return (this.model.type == DYNAMIC_FORM_CONTROL_TYPE_ARRAY)
|
|
1070
|
+
? this.layoutService.getAlignedTemplate(this.model, this.templates, "ARRAY_END")
|
|
1071
|
+
: this.layoutService.getEndTemplate(this.model, this.templates);
|
|
1072
|
+
}
|
|
1073
|
+
get formService() {
|
|
1074
|
+
return this.form.formService;
|
|
1075
|
+
}
|
|
1076
|
+
ngOnInit() {
|
|
1077
|
+
this.onDetectChanges = this.formService.onDetectChanges.subscribe(form => {
|
|
1078
|
+
if (form !== this.form)
|
|
1079
|
+
return;
|
|
1080
|
+
this.changeDetectorRef.detectChanges();
|
|
1081
|
+
this.formService.updateSelectOptions(this.model, this.control, this.form.model);
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
ngOnDestroy() {
|
|
1085
|
+
super.ngOnDestroy();
|
|
1086
|
+
this.onDetectChanges.unsubscribe();
|
|
1087
|
+
}
|
|
1088
|
+
getLabel() {
|
|
1089
|
+
var _a;
|
|
1090
|
+
const label = collectPathAble(this.model, p => p.label);
|
|
1091
|
+
if (label.length == 0)
|
|
1092
|
+
return "";
|
|
1093
|
+
if ((_a = this.form) === null || _a === void 0 ? void 0 : _a.labelPrefix) {
|
|
1094
|
+
label.unshift(this.form.labelPrefix);
|
|
1095
|
+
}
|
|
1096
|
+
return label.join(".");
|
|
1097
|
+
}
|
|
1098
|
+
createFormControlComponent() {
|
|
1099
|
+
var _a;
|
|
1100
|
+
super.createFormControlComponent();
|
|
1101
|
+
const component = (_a = this.componentRef) === null || _a === void 0 ? void 0 : _a.instance;
|
|
1102
|
+
if (!component || !ObjectUtils.isFunction(component.onCreated))
|
|
1103
|
+
return;
|
|
1104
|
+
component.onCreated();
|
|
1105
|
+
}
|
|
1106
|
+
getComponentType(model) {
|
|
1107
|
+
return null;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
DynamicBaseFormControlContainerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicBaseFormControlContainerComponent, deps: [{ token: DynamicBaseFormComponent }, { token: i0.ChangeDetectorRef }, { token: i0.ComponentFactoryResolver }, { token: i1.DynamicFormLayoutService }, { token: i1.DynamicFormValidationService }, { token: i1.DynamicFormComponentService }, { token: i1.DynamicFormRelationService }], target: i0.ɵɵFactoryTarget.Component });
|
|
1111
|
+
DynamicBaseFormControlContainerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.8", type: DynamicBaseFormControlContainerComponent, selector: "dynamic-base-form-control", inputs: { context: "context", group: "group", hostClass: "hostClass", inputTemplateList: ["templates", "inputTemplateList"], layout: "layout", model: "model" }, outputs: { blur: "blur", change: "change", focus: "focus" }, host: { properties: { "class": "this.klass" } }, queries: [{ propertyName: "contentTemplateList", predicate: DynamicTemplateDirective }], viewQueries: [{ propertyName: "componentViewContainerRef", first: true, predicate: ["componentViewContainer"], descendants: true, read: ViewContainerRef, static: true }], usesInheritance: true, ngImport: i0, template: "", isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1112
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicBaseFormControlContainerComponent, decorators: [{
|
|
1113
|
+
type: Component,
|
|
1114
|
+
args: [{
|
|
1115
|
+
selector: "dynamic-base-form-control",
|
|
1116
|
+
template: "",
|
|
1117
|
+
changeDetection: ChangeDetectionStrategy.OnPush
|
|
1118
|
+
}]
|
|
1119
|
+
}], ctorParameters: function () { return [{ type: DynamicBaseFormComponent }, { type: i0.ChangeDetectorRef }, { type: i0.ComponentFactoryResolver }, { type: i1.DynamicFormLayoutService }, { type: i1.DynamicFormValidationService }, { type: i1.DynamicFormComponentService }, { type: i1.DynamicFormRelationService }]; }, propDecorators: { contentTemplateList: [{
|
|
1120
|
+
type: ContentChildren,
|
|
1121
|
+
args: [DynamicTemplateDirective]
|
|
1122
|
+
}], klass: [{
|
|
1123
|
+
type: HostBinding,
|
|
1124
|
+
args: ["class"]
|
|
1125
|
+
}], context: [{
|
|
1126
|
+
type: Input
|
|
1127
|
+
}], group: [{
|
|
1128
|
+
type: Input
|
|
1129
|
+
}], hostClass: [{
|
|
1130
|
+
type: Input
|
|
1131
|
+
}], inputTemplateList: [{
|
|
1132
|
+
type: Input,
|
|
1133
|
+
args: ["templates"]
|
|
1134
|
+
}], layout: [{
|
|
1135
|
+
type: Input
|
|
1136
|
+
}], model: [{
|
|
1137
|
+
type: Input
|
|
1138
|
+
}], blur: [{
|
|
1139
|
+
type: Output
|
|
1140
|
+
}], change: [{
|
|
1141
|
+
type: Output
|
|
1142
|
+
}], focus: [{
|
|
1143
|
+
type: Output
|
|
1144
|
+
}], componentViewContainerRef: [{
|
|
1145
|
+
type: ViewChild,
|
|
1146
|
+
args: ["componentViewContainer", { read: ViewContainerRef, static: true }]
|
|
1147
|
+
}] } });
|
|
1148
|
+
|
|
1149
|
+
class DynamicBaseFormGroupComponent extends DynamicFormGroupComponent {
|
|
1150
|
+
constructor(layoutService, validationService) {
|
|
1151
|
+
super(layoutService, validationService);
|
|
1152
|
+
this.layoutService = layoutService;
|
|
1153
|
+
this.validationService = validationService;
|
|
1154
|
+
this.blur = new EventEmitter();
|
|
1155
|
+
this.change = new EventEmitter();
|
|
1156
|
+
this.customEvent = new EventEmitter();
|
|
1157
|
+
this.focus = new EventEmitter();
|
|
1158
|
+
}
|
|
1159
|
+
getClass(context, place, model) {
|
|
1160
|
+
return [
|
|
1161
|
+
context == "element" ? this.getModelClass(model) : null,
|
|
1162
|
+
context == "element" ? this.getAdditionalClass(model) : null,
|
|
1163
|
+
super.getClass(context, place, model)
|
|
1164
|
+
].filter(cls => !!cls).join(" ");
|
|
1165
|
+
}
|
|
1166
|
+
getModelClass(model) {
|
|
1167
|
+
const parts = collectPathAble(model, p => p.id);
|
|
1168
|
+
if (parts.length == 0)
|
|
1169
|
+
return "";
|
|
1170
|
+
if (model instanceof DynamicFormGroupModel) {
|
|
1171
|
+
return `form-group-${parts.join("-")}`;
|
|
1172
|
+
}
|
|
1173
|
+
return `form-control-${parts.join("-")}`;
|
|
1174
|
+
}
|
|
1175
|
+
getAdditionalClass(model) {
|
|
1176
|
+
var _a, _b;
|
|
1177
|
+
if (model instanceof DynamicFormArrayModel) {
|
|
1178
|
+
return (_a = model.additional) === null || _a === void 0 ? void 0 : _a.classes;
|
|
1179
|
+
}
|
|
1180
|
+
if (model instanceof DynamicFormValueControlModel) {
|
|
1181
|
+
return (_b = model.additional) === null || _b === void 0 ? void 0 : _b.classes;
|
|
1182
|
+
}
|
|
1183
|
+
return null;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
DynamicBaseFormGroupComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicBaseFormGroupComponent, deps: [{ token: i1.DynamicFormLayoutService }, { token: i1.DynamicFormValidationService }], target: i0.ɵɵFactoryTarget.Component });
|
|
1187
|
+
DynamicBaseFormGroupComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.8", type: DynamicBaseFormGroupComponent, selector: "dynamic-base-form-group", inputs: { formLayout: "formLayout", group: "group", layout: "layout", model: "model", templates: "templates" }, outputs: { blur: "blur", change: "change", customEvent: "customEvent", focus: "focus" }, viewQueries: [{ propertyName: "components", predicate: i0.forwardRef(function () { return DynamicFormControlContainerComponent; }), descendants: true }], usesInheritance: true, ngImport: i0, template: "", isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1188
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: DynamicBaseFormGroupComponent, decorators: [{
|
|
1189
|
+
type: Component,
|
|
1190
|
+
args: [{
|
|
1191
|
+
selector: "dynamic-base-form-group",
|
|
1192
|
+
template: "",
|
|
1193
|
+
changeDetection: ChangeDetectionStrategy.OnPush
|
|
1194
|
+
}]
|
|
1195
|
+
}], ctorParameters: function () { return [{ type: i1.DynamicFormLayoutService }, { type: i1.DynamicFormValidationService }]; }, propDecorators: { formLayout: [{
|
|
1196
|
+
type: Input
|
|
1197
|
+
}], group: [{
|
|
1198
|
+
type: Input
|
|
1199
|
+
}], layout: [{
|
|
1200
|
+
type: Input
|
|
1201
|
+
}], model: [{
|
|
1202
|
+
type: Input
|
|
1203
|
+
}], templates: [{
|
|
1204
|
+
type: Input
|
|
1205
|
+
}], blur: [{
|
|
1206
|
+
type: Output
|
|
1207
|
+
}], change: [{
|
|
1208
|
+
type: Output
|
|
1209
|
+
}], customEvent: [{
|
|
1210
|
+
type: Output
|
|
1211
|
+
}], focus: [{
|
|
1212
|
+
type: Output
|
|
1213
|
+
}], components: [{
|
|
1214
|
+
type: ViewChildren,
|
|
1215
|
+
args: [forwardRef(() => DynamicFormControlContainerComponent)]
|
|
1216
|
+
}] } });
|
|
1217
|
+
|
|
1218
|
+
// --- Components ---
|
|
1219
|
+
const components = [
|
|
1220
|
+
DynamicBaseFormComponent,
|
|
1221
|
+
DynamicBaseFormArrayComponent,
|
|
1222
|
+
DynamicBaseFormControlContainerComponent,
|
|
1223
|
+
DynamicBaseFormGroupComponent
|
|
1224
|
+
];
|
|
1225
|
+
// --- Directives ---
|
|
1226
|
+
const directives = [
|
|
1227
|
+
AsyncSubmitDirective,
|
|
1228
|
+
];
|
|
1229
|
+
// --- Pipes ---
|
|
1230
|
+
const pipes = [];
|
|
1231
|
+
function defaultFormControlProvider() {
|
|
1232
|
+
return () => null;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
class NgxDynamicFormModule {
|
|
1236
|
+
static forRoot(config) {
|
|
1237
|
+
return {
|
|
1238
|
+
ngModule: NgxDynamicFormModule,
|
|
1239
|
+
providers: [
|
|
1240
|
+
DynamicFormService,
|
|
1241
|
+
{
|
|
1242
|
+
provide: DynamicFormService$1,
|
|
1243
|
+
useExisting: DynamicFormService
|
|
1244
|
+
},
|
|
1245
|
+
{
|
|
1246
|
+
provide: DYNAMIC_FORM_CONTROL_MAP_FN,
|
|
1247
|
+
useFactory: ((config === null || config === void 0 ? void 0 : config.controlProvider) || defaultFormControlProvider),
|
|
1248
|
+
deps: [Injector]
|
|
1249
|
+
}
|
|
1250
|
+
]
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
NgxDynamicFormModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: NgxDynamicFormModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1255
|
+
NgxDynamicFormModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: NgxDynamicFormModule, declarations: [DynamicBaseFormComponent, DynamicBaseFormArrayComponent, DynamicBaseFormControlContainerComponent, DynamicBaseFormGroupComponent, AsyncSubmitDirective], imports: [CommonModule,
|
|
1256
|
+
FormsModule,
|
|
1257
|
+
ReactiveFormsModule,
|
|
1258
|
+
NgxUtilsModule], exports: [DynamicBaseFormComponent, DynamicBaseFormArrayComponent, DynamicBaseFormControlContainerComponent, DynamicBaseFormGroupComponent, AsyncSubmitDirective, FormsModule,
|
|
1259
|
+
ReactiveFormsModule,
|
|
1260
|
+
NgxUtilsModule] });
|
|
1261
|
+
NgxDynamicFormModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: NgxDynamicFormModule, providers: [
|
|
1262
|
+
...pipes,
|
|
1263
|
+
{ provide: NG_VALIDATORS, useValue: validateJSON, multi: true },
|
|
1264
|
+
{ provide: NG_VALIDATORS, useValue: validateRequiredTranslation, multi: true },
|
|
1265
|
+
{ provide: NG_VALIDATORS, useValue: validateItemsMinLength, multi: true },
|
|
1266
|
+
{ provide: NG_VALIDATORS, useValue: validateItemsMaxLength, multi: true },
|
|
1267
|
+
{ provide: NG_VALIDATORS, useValue: validateItemsMinValue, multi: true },
|
|
1268
|
+
{ provide: NG_VALIDATORS, useValue: validateItemsMaxValue, multi: true },
|
|
1269
|
+
{
|
|
1270
|
+
provide: DYNAMIC_VALIDATORS,
|
|
1271
|
+
useValue: new Map([
|
|
1272
|
+
["json", validateJSON],
|
|
1273
|
+
["requiredTranslation", validateRequiredTranslation],
|
|
1274
|
+
["phone", validatePhone],
|
|
1275
|
+
["itemsMinLength", validateItemsMinLength],
|
|
1276
|
+
["itemsMaxLength", validateItemsMaxLength],
|
|
1277
|
+
["itemsMinValue", validateItemsMinValue],
|
|
1278
|
+
["itemsMaxValue", validateItemsMaxValue],
|
|
1279
|
+
])
|
|
1280
|
+
}
|
|
1281
|
+
], imports: [[
|
|
1282
|
+
CommonModule,
|
|
1283
|
+
FormsModule,
|
|
1284
|
+
ReactiveFormsModule,
|
|
1285
|
+
NgxUtilsModule
|
|
1286
|
+
], FormsModule,
|
|
1287
|
+
ReactiveFormsModule,
|
|
1288
|
+
NgxUtilsModule] });
|
|
1289
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: NgxDynamicFormModule, decorators: [{
|
|
1290
|
+
type: NgModule,
|
|
1291
|
+
args: [{
|
|
1292
|
+
declarations: [
|
|
1293
|
+
...components,
|
|
1294
|
+
...directives,
|
|
1295
|
+
...pipes
|
|
1296
|
+
],
|
|
1297
|
+
imports: [
|
|
1298
|
+
CommonModule,
|
|
1299
|
+
FormsModule,
|
|
1300
|
+
ReactiveFormsModule,
|
|
1301
|
+
NgxUtilsModule
|
|
1302
|
+
],
|
|
1303
|
+
exports: [
|
|
1304
|
+
...components,
|
|
1305
|
+
...directives,
|
|
1306
|
+
...pipes,
|
|
1307
|
+
FormsModule,
|
|
1308
|
+
ReactiveFormsModule,
|
|
1309
|
+
NgxUtilsModule
|
|
1310
|
+
],
|
|
1311
|
+
entryComponents: components,
|
|
1312
|
+
providers: [
|
|
1313
|
+
...pipes,
|
|
1314
|
+
{ provide: NG_VALIDATORS, useValue: validateJSON, multi: true },
|
|
1315
|
+
{ provide: NG_VALIDATORS, useValue: validateRequiredTranslation, multi: true },
|
|
1316
|
+
{ provide: NG_VALIDATORS, useValue: validateItemsMinLength, multi: true },
|
|
1317
|
+
{ provide: NG_VALIDATORS, useValue: validateItemsMaxLength, multi: true },
|
|
1318
|
+
{ provide: NG_VALIDATORS, useValue: validateItemsMinValue, multi: true },
|
|
1319
|
+
{ provide: NG_VALIDATORS, useValue: validateItemsMaxValue, multi: true },
|
|
1320
|
+
{
|
|
1321
|
+
provide: DYNAMIC_VALIDATORS,
|
|
1322
|
+
useValue: new Map([
|
|
1323
|
+
["json", validateJSON],
|
|
1324
|
+
["requiredTranslation", validateRequiredTranslation],
|
|
1325
|
+
["phone", validatePhone],
|
|
1326
|
+
["itemsMinLength", validateItemsMinLength],
|
|
1327
|
+
["itemsMaxLength", validateItemsMaxLength],
|
|
1328
|
+
["itemsMinValue", validateItemsMinValue],
|
|
1329
|
+
["itemsMaxValue", validateItemsMaxValue],
|
|
1330
|
+
])
|
|
1331
|
+
}
|
|
1332
|
+
]
|
|
1333
|
+
}]
|
|
1334
|
+
}] });
|
|
1335
|
+
|
|
1336
|
+
/**
|
|
1337
|
+
* Generated bundle index. Do not edit.
|
|
1338
|
+
*/
|
|
1339
|
+
|
|
1340
|
+
export { AsyncSubmitDirective, DynamicBaseFormArrayComponent, DynamicBaseFormComponent, DynamicBaseFormControlContainerComponent, DynamicBaseFormGroupComponent, DynamicFormArrayModel, DynamicFormService, FormFile, FormInput, FormModel, FormSelect, FormSelectSubject, FormSerializable, FormStatic, FormSubject, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, createFormControl, createFormInput, createFormModel, createFormSelect, createFormStatic, defaultSerializer, defineFormControl, getFormControl, getFormSerializer, validateItemsMaxLength, validateItemsMaxValue, validateItemsMinLength, validateItemsMinValue, validateJSON, validatePhone, validateRequiredTranslation };
|
|
1341
|
+
//# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map
|