tuain-ng-forms-lib 12.0.31 → 12.0.37
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/bundles/tuain-ng-forms-lib.umd.js +84 -128
- package/bundles/tuain-ng-forms-lib.umd.js.map +1 -1
- package/esm2015/lib/classes/forms/field.js +46 -90
- package/esm2015/lib/components/elements/action.component.js +4 -4
- package/esm2015/lib/components/elements/field.component.js +24 -22
- package/esm2015/lib/components/elements/layout/element.component.js +4 -4
- package/esm2015/lib/components/elements/tables/table.component.js +2 -2
- package/esm2015/lib/components/forms/basic-form.js +3 -4
- package/fesm2015/tuain-ng-forms-lib.js +77 -120
- package/fesm2015/tuain-ng-forms-lib.js.map +1 -1
- package/lib/classes/forms/field.d.ts +4 -5
- package/lib/components/elements/action.component.d.ts +1 -1
- package/lib/components/elements/field.component.d.ts +3 -1
- package/lib/components/elements/layout/element.component.d.ts +1 -1
- package/lib/components/elements/tables/table.component.d.ts +1 -1
- package/lib/components/forms/basic-form.d.ts +0 -1
- package/package.json +1 -1
- package/tuain-ng-forms-lib.metadata.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component, Input, EventEmitter, Output, ChangeDetectionStrategy, NgModule } from '@angular/core';
|
|
2
2
|
import { Subject, ReplaySubject } from 'rxjs';
|
|
3
3
|
import { __awaiter } from 'tslib';
|
|
4
|
+
import yn from 'yn';
|
|
4
5
|
import { nanoid } from 'nanoid';
|
|
5
6
|
import { CommonModule } from '@angular/common';
|
|
6
7
|
import { RouterModule } from '@angular/router';
|
|
@@ -37,11 +38,11 @@ class ActionComponent {
|
|
|
37
38
|
}
|
|
38
39
|
get visible() {
|
|
39
40
|
var _a;
|
|
40
|
-
return ((_a = this.action) === null || _a === void 0 ? void 0 : _a.visibleOn(this.
|
|
41
|
+
return ((_a = this.action) === null || _a === void 0 ? void 0 : _a.visibleOn(this.state)) && this.visibleOnRestriction();
|
|
41
42
|
}
|
|
42
43
|
get disabled() {
|
|
43
44
|
var _a;
|
|
44
|
-
return !((_a = this.action) === null || _a === void 0 ? void 0 : _a.enabledOn(this.
|
|
45
|
+
return !((_a = this.action) === null || _a === void 0 ? void 0 : _a.enabledOn(this.state));
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
ActionComponent.decorators = [
|
|
@@ -54,7 +55,7 @@ ActionComponent.propDecorators = {
|
|
|
54
55
|
action: [{ type: Input }],
|
|
55
56
|
busy: [{ type: Input }],
|
|
56
57
|
relatedField: [{ type: Input }],
|
|
57
|
-
|
|
58
|
+
state: [{ type: Input }],
|
|
58
59
|
style: [{ type: Input }],
|
|
59
60
|
showLabel: [{ type: Input }]
|
|
60
61
|
};
|
|
@@ -62,50 +63,52 @@ ActionComponent.propDecorators = {
|
|
|
62
63
|
const VALUE = '';
|
|
63
64
|
class FieldComponent {
|
|
64
65
|
ngOnInit() {
|
|
65
|
-
var _a, _b;
|
|
66
|
+
var _a, _b, _c;
|
|
66
67
|
if (this.field) {
|
|
67
68
|
this.formConfig = (_a = this.field) === null || _a === void 0 ? void 0 : _a._formConfig;
|
|
68
69
|
// Inicialización
|
|
69
70
|
const mapping = Object.entries(this.formConfig.componentFieldAttrMap);
|
|
70
71
|
for (let index = 0; index < mapping.length; index++) {
|
|
71
|
-
const [
|
|
72
|
+
const [fieldAttr1, compAttr1] = mapping[index];
|
|
72
73
|
const compAttr = compAttr1.toString();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
else {
|
|
77
|
-
this[compAttr] = (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr.toString()];
|
|
78
|
-
}
|
|
74
|
+
const fieldAttr = fieldAttr1.toString();
|
|
75
|
+
this.dafaultProcessFieldChange(compAttr, (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr]);
|
|
76
|
+
this.processFieldChange(compAttr, (_c = this.field) === null || _c === void 0 ? void 0 : _c[fieldAttr]);
|
|
79
77
|
}
|
|
80
78
|
// Subscripción a cambios en atributos
|
|
81
79
|
this.field.attributeChange.subscribe(event => {
|
|
82
80
|
const { name: fieldAttr, value } = event;
|
|
83
81
|
const compAttr = this.formConfig.componentFieldAttrMap[fieldAttr];
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
this[compAttr] = value;
|
|
89
|
-
}
|
|
82
|
+
this.dafaultProcessFieldChange(compAttr, value);
|
|
83
|
+
this.processFieldChange(compAttr, value);
|
|
90
84
|
});
|
|
91
85
|
}
|
|
92
86
|
this.start();
|
|
93
87
|
}
|
|
88
|
+
dafaultProcessFieldChange(attribute, value) {
|
|
89
|
+
if (attribute === VALUE) {
|
|
90
|
+
this.updateValue();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this[attribute] = value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
processFieldChange(attribute, value) { }
|
|
94
97
|
start() { }
|
|
95
98
|
focus() { }
|
|
96
99
|
updateObject() {
|
|
97
|
-
this.field.
|
|
100
|
+
this.field.setValue(this.value);
|
|
98
101
|
}
|
|
99
102
|
inputChanged() {
|
|
100
|
-
this.field.
|
|
103
|
+
this.field.setValue(this.value);
|
|
101
104
|
this.onChangeContent();
|
|
102
105
|
}
|
|
103
106
|
inputTyped() {
|
|
104
|
-
this.field.
|
|
107
|
+
this.field.setValue(this.value);
|
|
105
108
|
this.onInputChange();
|
|
106
109
|
}
|
|
107
110
|
updateValue() {
|
|
108
|
-
this.value = this.field.
|
|
111
|
+
this.value = this.field.getValue();
|
|
109
112
|
}
|
|
110
113
|
onInputChange() {
|
|
111
114
|
setTimeout(() => this.field.notifyEditionPartial(), 50);
|
|
@@ -122,11 +125,11 @@ class FieldComponent {
|
|
|
122
125
|
}
|
|
123
126
|
get visible() {
|
|
124
127
|
var _a;
|
|
125
|
-
return (_a = this.field) === null || _a === void 0 ? void 0 : _a.visibleOn(this.
|
|
128
|
+
return (_a = this.field) === null || _a === void 0 ? void 0 : _a.visibleOn(this.state);
|
|
126
129
|
}
|
|
127
130
|
get disabled() {
|
|
128
131
|
var _a;
|
|
129
|
-
return !((_a = this.field) === null || _a === void 0 ? void 0 : _a.enabledOn(this.
|
|
132
|
+
return !((_a = this.field) === null || _a === void 0 ? void 0 : _a.enabledOn(this.state));
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
FieldComponent.decorators = [
|
|
@@ -137,7 +140,7 @@ FieldComponent.decorators = [
|
|
|
137
140
|
];
|
|
138
141
|
FieldComponent.propDecorators = {
|
|
139
142
|
field: [{ type: Input }],
|
|
140
|
-
|
|
143
|
+
state: [{ type: Input }]
|
|
141
144
|
};
|
|
142
145
|
|
|
143
146
|
class ElementComponent {
|
|
@@ -149,11 +152,11 @@ class ElementComponent {
|
|
|
149
152
|
start() { }
|
|
150
153
|
get visible() {
|
|
151
154
|
var _a;
|
|
152
|
-
return (_a = this.element) === null || _a === void 0 ? void 0 : _a.visibleOn(this.
|
|
155
|
+
return (_a = this.element) === null || _a === void 0 ? void 0 : _a.visibleOn(this.state);
|
|
153
156
|
}
|
|
154
157
|
get disabled() {
|
|
155
158
|
var _a;
|
|
156
|
-
return !((_a = this.element) === null || _a === void 0 ? void 0 : _a.enabledOn(this.
|
|
159
|
+
return !((_a = this.element) === null || _a === void 0 ? void 0 : _a.enabledOn(this.state));
|
|
157
160
|
}
|
|
158
161
|
}
|
|
159
162
|
ElementComponent.decorators = [
|
|
@@ -165,7 +168,7 @@ ElementComponent.decorators = [
|
|
|
165
168
|
ElementComponent.propDecorators = {
|
|
166
169
|
element: [{ type: Input }],
|
|
167
170
|
form: [{ type: Input }],
|
|
168
|
-
|
|
171
|
+
state: [{ type: Input }]
|
|
169
172
|
};
|
|
170
173
|
|
|
171
174
|
class FormErrorComponent {
|
|
@@ -1100,7 +1103,7 @@ LibTableComponent.propDecorators = {
|
|
|
1100
1103
|
table: [{ type: Input }],
|
|
1101
1104
|
tableRecords: [{ type: Input }],
|
|
1102
1105
|
disabled: [{ type: Input }],
|
|
1103
|
-
|
|
1106
|
+
state: [{ type: Input }],
|
|
1104
1107
|
waiting: [{ type: Input }]
|
|
1105
1108
|
};
|
|
1106
1109
|
|
|
@@ -1145,7 +1148,7 @@ const STD_MAX_LENGTH = 50;
|
|
|
1145
1148
|
const BIG_MAX_LENGTH = 500;
|
|
1146
1149
|
const fldAttr = {
|
|
1147
1150
|
validateOnServer: 'validateOnServer',
|
|
1148
|
-
value: '
|
|
1151
|
+
value: '_value',
|
|
1149
1152
|
minValue: '_minValue',
|
|
1150
1153
|
maxValue: '_maxValue',
|
|
1151
1154
|
maxLength: '_maxLength',
|
|
@@ -1272,7 +1275,6 @@ class FieldDescriptor extends FormElement {
|
|
|
1272
1275
|
hideLabel() { this.setVisibleLabel(false); }
|
|
1273
1276
|
setChanged(hasChanged) { this.setAttr(fldAttr.hasChanged, hasChanged); }
|
|
1274
1277
|
changed() { this.setChanged(true); }
|
|
1275
|
-
getRawValue() { return this._fieldValue; }
|
|
1276
1278
|
setLabel(label) { this.setAttr(fldAttr.title, label); }
|
|
1277
1279
|
clean() { this.setValue(this.defaultValue || ''); this.resetError(); }
|
|
1278
1280
|
get backend() { return this.validateOnServer; }
|
|
@@ -1305,22 +1307,11 @@ class FieldDescriptor extends FormElement {
|
|
|
1305
1307
|
return fieldCurrentValue === '';
|
|
1306
1308
|
}
|
|
1307
1309
|
getValue() {
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
return (_a = this._fieldValue) !== null && _a !== void 0 ? _a : false;
|
|
1312
|
-
break;
|
|
1313
|
-
case this._formConfig.fieldTypes.check:
|
|
1314
|
-
return (_b = this._fieldValue) !== null && _b !== void 0 ? _b : false;
|
|
1315
|
-
break;
|
|
1316
|
-
case this._formConfig.fieldTypes.currency:
|
|
1317
|
-
return (typeof this._fieldValue === 'string')
|
|
1318
|
-
? this._fieldValue.replace(',', '') : this._fieldValue;
|
|
1319
|
-
break;
|
|
1320
|
-
default:
|
|
1321
|
-
return this._fieldValue;
|
|
1322
|
-
break;
|
|
1310
|
+
if (this.fieldType === this._formConfig.fieldTypes.boolean
|
|
1311
|
+
|| this.fieldType === this._formConfig.fieldTypes.check) {
|
|
1312
|
+
return yn(this._value);
|
|
1323
1313
|
}
|
|
1314
|
+
return this._value;
|
|
1324
1315
|
}
|
|
1325
1316
|
updateFromServer(fld) {
|
|
1326
1317
|
var _a;
|
|
@@ -1347,39 +1338,25 @@ class FieldDescriptor extends FormElement {
|
|
|
1347
1338
|
setFieldType(inputFieldType) {
|
|
1348
1339
|
this.setAttr(fldAttr.type, inputFieldType);
|
|
1349
1340
|
}
|
|
1350
|
-
setMinValue(
|
|
1351
|
-
|
|
1352
|
-
if (this.fieldType === this._formConfig.fieldTypes.date
|
|
1353
|
-
|
|
1354
|
-
this.setAttr(fldAttr.minValue, minValue);
|
|
1355
|
-
if (!minValue) {
|
|
1356
|
-
(_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMinValue(false);
|
|
1357
|
-
}
|
|
1358
|
-
else {
|
|
1359
|
-
const minDate = new Date(minValue);
|
|
1360
|
-
(_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMinValue(minDate);
|
|
1361
|
-
}
|
|
1341
|
+
setMinValue(inputMinValue) {
|
|
1342
|
+
let minValue = inputMinValue;
|
|
1343
|
+
if (this.fieldType === this._formConfig.fieldTypes.date) {
|
|
1344
|
+
minValue = new Date(minValue);
|
|
1362
1345
|
}
|
|
1346
|
+
this.setAttr(fldAttr.minValue, minValue);
|
|
1363
1347
|
}
|
|
1364
|
-
setMaxValue(
|
|
1365
|
-
|
|
1366
|
-
if (this.fieldType === this._formConfig.fieldTypes.date
|
|
1367
|
-
|
|
1368
|
-
this.setAttr(fldAttr.maxValue, maxValue);
|
|
1369
|
-
if (!maxValue) {
|
|
1370
|
-
(_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMaxValue(false);
|
|
1371
|
-
}
|
|
1372
|
-
else {
|
|
1373
|
-
const maxDate = new Date(maxValue);
|
|
1374
|
-
(_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMaxValue(maxDate);
|
|
1375
|
-
}
|
|
1348
|
+
setMaxValue(inputMaxValue) {
|
|
1349
|
+
let maxValue = inputMaxValue;
|
|
1350
|
+
if (this.fieldType === this._formConfig.fieldTypes.date) {
|
|
1351
|
+
maxValue = new Date(maxValue);
|
|
1376
1352
|
}
|
|
1353
|
+
this.setAttr(fldAttr.maxValue, maxValue);
|
|
1377
1354
|
}
|
|
1378
1355
|
getFieldOptions() {
|
|
1379
1356
|
return JSON.parse(JSON.stringify(this.fieldOptions));
|
|
1380
1357
|
}
|
|
1381
1358
|
setFieldOptions(newOptions) {
|
|
1382
|
-
var _a
|
|
1359
|
+
var _a;
|
|
1383
1360
|
if ((this.captureType !== 'LIST' && this.captureType !== 'RADIO')
|
|
1384
1361
|
|| typeof newOptions === UNDEFINED || !newOptions
|
|
1385
1362
|
|| !Array.isArray(newOptions)) {
|
|
@@ -1395,17 +1372,14 @@ class FieldDescriptor extends FormElement {
|
|
|
1395
1372
|
fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
|
|
1396
1373
|
&& fieldOptions.length > 0) ? fieldOptions : [];
|
|
1397
1374
|
this.setAttr(fldAttr.options, fieldOptions);
|
|
1398
|
-
if (this.
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
if (this._fieldValue) {
|
|
1402
|
-
if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._fieldValue)) {
|
|
1403
|
-
const fieldValue = (_b = this._fieldValue) === null || _b === void 0 ? void 0 : _b.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
|
|
1375
|
+
if (this._value) {
|
|
1376
|
+
if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
|
|
1377
|
+
const fieldValue = (_a = this._value) === null || _a === void 0 ? void 0 : _a.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
|
|
1404
1378
|
this.setAttr(fldAttr.value, fieldValue);
|
|
1405
1379
|
}
|
|
1406
1380
|
else {
|
|
1407
1381
|
const valInOptions = this.fieldOptions
|
|
1408
|
-
.find(item => item.fieldOptionId === this.
|
|
1382
|
+
.find(item => item.fieldOptionId === this._value);
|
|
1409
1383
|
if (!valInOptions) {
|
|
1410
1384
|
this.setValue('');
|
|
1411
1385
|
}
|
|
@@ -1413,56 +1387,40 @@ class FieldDescriptor extends FormElement {
|
|
|
1413
1387
|
}
|
|
1414
1388
|
if (this.fieldRequired && this.fieldOptions.length === 1) {
|
|
1415
1389
|
this.setValue(this.fieldOptions[0].fieldOptionId);
|
|
1416
|
-
if ((_c = this.widget) === null || _c === void 0 ? void 0 : _c.onChangeContent) {
|
|
1417
|
-
(_d = this.widget) === null || _d === void 0 ? void 0 : _d.onChangeContent();
|
|
1418
|
-
}
|
|
1419
1390
|
}
|
|
1420
1391
|
}
|
|
1421
1392
|
setValue(newValue, widgetUpdate = true) {
|
|
1422
|
-
var _a;
|
|
1423
1393
|
if (typeof newValue === UNDEFINED || newValue === null) {
|
|
1424
1394
|
return true;
|
|
1425
1395
|
}
|
|
1426
1396
|
let newFinalValue;
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
case this._formConfig.fieldTypes.array:
|
|
1438
|
-
if (newValue === null || newValue === '') {
|
|
1439
|
-
newFinalValue = [];
|
|
1440
|
-
}
|
|
1441
|
-
else if (!Array.isArray(newValue)) {
|
|
1442
|
-
if (typeof (newValue) !== 'string') {
|
|
1443
|
-
newValue = newValue.toString();
|
|
1444
|
-
}
|
|
1445
|
-
newFinalValue = newValue.split(',');
|
|
1446
|
-
}
|
|
1447
|
-
else {
|
|
1448
|
-
newFinalValue = newValue;
|
|
1449
|
-
}
|
|
1450
|
-
break;
|
|
1451
|
-
case this._formConfig.fieldTypes.map:
|
|
1452
|
-
newFinalValue = newValue;
|
|
1453
|
-
if (newFinalValue && this.widget && widgetUpdate) {
|
|
1454
|
-
const latitude = parseFloat(newFinalValue[0]);
|
|
1455
|
-
const longitude = parseFloat(newFinalValue[1]);
|
|
1456
|
-
(_a = this.widget) === null || _a === void 0 ? void 0 : _a.setLocation(latitude, longitude);
|
|
1457
|
-
}
|
|
1458
|
-
break;
|
|
1459
|
-
default:
|
|
1397
|
+
if (this.fieldType === this._formConfig.fieldTypes.boolean
|
|
1398
|
+
|| this.fieldType === this._formConfig.fieldTypes.check) {
|
|
1399
|
+
newFinalValue = yn(newValue);
|
|
1400
|
+
}
|
|
1401
|
+
else if (this.fieldType === this._formConfig.fieldTypes.array
|
|
1402
|
+
|| this.fieldType === this._formConfig.fieldTypes.map) {
|
|
1403
|
+
if (newValue === null || newValue === '') {
|
|
1404
|
+
newFinalValue = [];
|
|
1405
|
+
}
|
|
1406
|
+
else if (Array.isArray(newValue)) {
|
|
1460
1407
|
newFinalValue = newValue;
|
|
1461
|
-
|
|
1408
|
+
}
|
|
1409
|
+
else {
|
|
1410
|
+
newFinalValue = newValue.toString().split(',');
|
|
1411
|
+
}
|
|
1462
1412
|
}
|
|
1463
|
-
|
|
1413
|
+
else {
|
|
1414
|
+
newFinalValue = newValue;
|
|
1415
|
+
}
|
|
1416
|
+
if (this._value !== newFinalValue) {
|
|
1464
1417
|
this.setChanged(true);
|
|
1465
|
-
|
|
1418
|
+
if (widgetUpdate) {
|
|
1419
|
+
this.setAttr(fldAttr.value, newFinalValue);
|
|
1420
|
+
}
|
|
1421
|
+
else {
|
|
1422
|
+
this._value = newFinalValue;
|
|
1423
|
+
}
|
|
1466
1424
|
}
|
|
1467
1425
|
return true;
|
|
1468
1426
|
}
|
|
@@ -2536,10 +2494,9 @@ class BasicFormComponent {
|
|
|
2536
2494
|
set formCode(name) { this.name = name; }
|
|
2537
2495
|
get inServerProcess() { return this.busy; }
|
|
2538
2496
|
get form() { return this._formStructure; }
|
|
2539
|
-
get state() { return this.
|
|
2497
|
+
get state() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.state; }
|
|
2540
2498
|
get currentState() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.state; }
|
|
2541
2499
|
set currentState(state) { this._formStructure.changeState(state); }
|
|
2542
|
-
get currentMode() { return this.currentState; }
|
|
2543
2500
|
get immutableData() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.immutableData; }
|
|
2544
2501
|
get extraInfo() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.extraInfo; }
|
|
2545
2502
|
get visibleSections() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.visibleSections; }
|
|
@@ -2601,7 +2558,7 @@ class BasicFormComponent {
|
|
|
2601
2558
|
if (!cleanStack) {
|
|
2602
2559
|
origin = Object.assign(Object.assign({}, backData), { name: this.name, url: this._formRoute, token: this._controlToken });
|
|
2603
2560
|
origin.subject = (_a = origin === null || origin === void 0 ? void 0 : origin.subject) !== null && _a !== void 0 ? _a : this.formSubject;
|
|
2604
|
-
origin.state = (_b = origin === null || origin === void 0 ? void 0 : origin.state) !== null && _b !== void 0 ? _b : this.
|
|
2561
|
+
origin.state = (_b = origin === null || origin === void 0 ? void 0 : origin.state) !== null && _b !== void 0 ? _b : this.state;
|
|
2605
2562
|
origin.fields = (_c = origin === null || origin === void 0 ? void 0 : origin.fields) !== null && _c !== void 0 ? _c : {};
|
|
2606
2563
|
origin.extra = (_d = origin === null || origin === void 0 ? void 0 : origin.extra) !== null && _d !== void 0 ? _d : {};
|
|
2607
2564
|
}
|