tuain-ng-forms-lib 12.0.33 → 12.0.40

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.
@@ -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';
@@ -59,7 +60,8 @@ ActionComponent.propDecorators = {
59
60
  showLabel: [{ type: Input }]
60
61
  };
61
62
 
62
- const VALUE = '';
63
+ const VALUE = 'value';
64
+ const FOCUS = 'focus';
63
65
  class FieldComponent {
64
66
  ngOnInit() {
65
67
  var _a, _b;
@@ -68,29 +70,35 @@ class FieldComponent {
68
70
  // Inicialización
69
71
  const mapping = Object.entries(this.formConfig.componentFieldAttrMap);
70
72
  for (let index = 0; index < mapping.length; index++) {
71
- const [fieldAttr, compAttr1] = mapping[index];
73
+ const [fieldAttr1, compAttr1] = mapping[index];
72
74
  const compAttr = compAttr1.toString();
73
- if (compAttr === VALUE) {
74
- this.updateValue();
75
- }
76
- else {
77
- this[compAttr] = (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr.toString()];
78
- }
75
+ const fieldAttr = fieldAttr1.toString();
76
+ const attributeValue = (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr];
77
+ this.dafaultProcessFieldChange(compAttr, attributeValue);
78
+ this.processFieldChange(compAttr, attributeValue);
79
79
  }
80
80
  // Subscripción a cambios en atributos
81
81
  this.field.attributeChange.subscribe(event => {
82
82
  const { name: fieldAttr, value } = event;
83
83
  const compAttr = this.formConfig.componentFieldAttrMap[fieldAttr];
84
- if (compAttr === VALUE) {
85
- this.updateValue();
86
- }
87
- else {
88
- this[compAttr] = value;
89
- }
84
+ this.dafaultProcessFieldChange(compAttr, value);
85
+ this.processFieldChange(compAttr, value);
90
86
  });
91
87
  }
92
88
  this.start();
93
89
  }
90
+ dafaultProcessFieldChange(attribute, value) {
91
+ if (attribute === VALUE) {
92
+ this.updateValue();
93
+ }
94
+ else if (attribute === FOCUS) {
95
+ this.focus();
96
+ }
97
+ else {
98
+ this[attribute] = value;
99
+ }
100
+ }
101
+ processFieldChange(attribute, value) { }
94
102
  start() { }
95
103
  focus() { }
96
104
  updateObject() {
@@ -293,7 +301,6 @@ class FormElement {
293
301
  this._visibleForced = false;
294
302
  this.disabled = (_a = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.disabled) !== null && _a !== void 0 ? _a : false;
295
303
  this.setVisibility((_b = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.visible) !== null && _b !== void 0 ? _b : true);
296
- this.widget = null;
297
304
  this.customAttributes = (_c = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.customAttributes) !== null && _c !== void 0 ? _c : {};
298
305
  }
299
306
  getCustomAttribute(name) { var _a, _b; return (_b = (_a = this.customAttributes) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : null; }
@@ -994,7 +1001,6 @@ class LibTableComponent {
994
1001
  this.tableFieldStyles = this.formConfig.tableFieldStyles;
995
1002
  this.selectable = this.table.selectable;
996
1003
  this.hasActions = this.table.hasActions;
997
- this.table.widget = this;
998
1004
  this.inlineActions = this.table.getActions(this.formConfig.tableActions.inline);
999
1005
  this.globalActions = this.table.getActions(this.formConfig.tableActions.global);
1000
1006
  this.selectionActions = this.table.getActions(this.formConfig.tableActions.selection);
@@ -1150,6 +1156,7 @@ const fldAttr = {
1150
1156
  maxValue: '_maxValue',
1151
1157
  maxLength: '_maxLength',
1152
1158
  onValidation: '_onValidation',
1159
+ focus: 'focus',
1153
1160
  intrinsicErrorMessage: '_intrinsicErrorMessage',
1154
1161
  code: 'fieldCode',
1155
1162
  info: 'fieldInfo',
@@ -1222,6 +1229,7 @@ class FieldDescriptor extends FormElement {
1222
1229
  get info() { return this.fieldInfo; }
1223
1230
  get validating() { return this._onValidation; }
1224
1231
  set validating(isValidating) { this.setAttr(fldAttr.onValidation, isValidating); }
1232
+ focus() { this.setAttr(fldAttr.focus, true); }
1225
1233
  setIntrinsicErrorMessage(message) { this.setAttr(fldAttr.intrinsicErrorMessage, message); }
1226
1234
  set intrinsicErrorMessage(message) { this.setIntrinsicErrorMessage(message); }
1227
1235
  get fieldValue() { return this.getValue(); }
@@ -1256,6 +1264,14 @@ class FieldDescriptor extends FormElement {
1256
1264
  this.setError('99', this._intrinsicErrorMessage);
1257
1265
  }
1258
1266
  }
1267
+ if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
1268
+ intrinsicValidation = false;
1269
+ this.setError('99', 'Campo con valor inferior al mínimo');
1270
+ }
1271
+ if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
1272
+ intrinsicValidation = false;
1273
+ this.setError('99', 'Campo con valor superior al máximo');
1274
+ }
1259
1275
  this._editionFinish.next({ code: this.fieldCode, intrinsicValidation });
1260
1276
  }
1261
1277
  setAttr(name, value) {
@@ -1306,7 +1322,7 @@ class FieldDescriptor extends FormElement {
1306
1322
  getValue() {
1307
1323
  if (this.fieldType === this._formConfig.fieldTypes.boolean
1308
1324
  || this.fieldType === this._formConfig.fieldTypes.check) {
1309
- return !!this._value;
1325
+ return yn(this._value);
1310
1326
  }
1311
1327
  return this._value;
1312
1328
  }
@@ -1335,39 +1351,25 @@ class FieldDescriptor extends FormElement {
1335
1351
  setFieldType(inputFieldType) {
1336
1352
  this.setAttr(fldAttr.type, inputFieldType);
1337
1353
  }
1338
- setMinValue(minValue) {
1339
- var _a, _b, _c;
1340
- if (this.fieldType === this._formConfig.fieldTypes.date
1341
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMinValue)) {
1342
- this.setAttr(fldAttr.minValue, minValue);
1343
- if (!minValue) {
1344
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMinValue(false);
1345
- }
1346
- else {
1347
- const minDate = new Date(minValue);
1348
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMinValue(minDate);
1349
- }
1354
+ setMinValue(inputMinValue) {
1355
+ let minValue = inputMinValue;
1356
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1357
+ minValue = new Date(minValue);
1350
1358
  }
1359
+ this.setAttr(fldAttr.minValue, minValue);
1351
1360
  }
1352
- setMaxValue(maxValue) {
1353
- var _a, _b, _c;
1354
- if (this.fieldType === this._formConfig.fieldTypes.date
1355
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMaxValue)) {
1356
- this.setAttr(fldAttr.maxValue, maxValue);
1357
- if (!maxValue) {
1358
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMaxValue(false);
1359
- }
1360
- else {
1361
- const maxDate = new Date(maxValue);
1362
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMaxValue(maxDate);
1363
- }
1361
+ setMaxValue(inputMaxValue) {
1362
+ let maxValue = inputMaxValue;
1363
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1364
+ maxValue = new Date(maxValue);
1364
1365
  }
1366
+ this.setAttr(fldAttr.maxValue, maxValue);
1365
1367
  }
1366
1368
  getFieldOptions() {
1367
1369
  return JSON.parse(JSON.stringify(this.fieldOptions));
1368
1370
  }
1369
1371
  setFieldOptions(newOptions) {
1370
- var _a, _b, _c, _d;
1372
+ var _a;
1371
1373
  if ((this.captureType !== 'LIST' && this.captureType !== 'RADIO')
1372
1374
  || typeof newOptions === UNDEFINED || !newOptions
1373
1375
  || !Array.isArray(newOptions)) {
@@ -1383,12 +1385,9 @@ class FieldDescriptor extends FormElement {
1383
1385
  fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
1384
1386
  && fieldOptions.length > 0) ? fieldOptions : [];
1385
1387
  this.setAttr(fldAttr.options, fieldOptions);
1386
- if (this.fieldType === this._formConfig.fieldTypes.array && this.widget) {
1387
- return (_a = this.widget) === null || _a === void 0 ? void 0 : _a.refereshContent();
1388
- }
1389
1388
  if (this._value) {
1390
1389
  if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
1391
- const fieldValue = (_b = this._value) === null || _b === void 0 ? void 0 : _b.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
1390
+ const fieldValue = (_a = this._value) === null || _a === void 0 ? void 0 : _a.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
1392
1391
  this.setAttr(fldAttr.value, fieldValue);
1393
1392
  }
1394
1393
  else {
@@ -1401,56 +1400,40 @@ class FieldDescriptor extends FormElement {
1401
1400
  }
1402
1401
  if (this.fieldRequired && this.fieldOptions.length === 1) {
1403
1402
  this.setValue(this.fieldOptions[0].fieldOptionId);
1404
- if ((_c = this.widget) === null || _c === void 0 ? void 0 : _c.onChangeContent) {
1405
- (_d = this.widget) === null || _d === void 0 ? void 0 : _d.onChangeContent();
1406
- }
1407
1403
  }
1408
1404
  }
1409
1405
  setValue(newValue, widgetUpdate = true) {
1410
- var _a;
1411
1406
  if (typeof newValue === UNDEFINED || newValue === null) {
1412
1407
  return true;
1413
1408
  }
1414
1409
  let newFinalValue;
1415
- switch (this.fieldType) {
1416
- case 'BOOLEAN':
1417
- newFinalValue = !!newValue;
1418
- break;
1419
- case this._formConfig.fieldTypes.boolean:
1420
- newFinalValue = !!newValue;
1421
- break;
1422
- case this._formConfig.fieldTypes.check:
1423
- newFinalValue = !!newValue;
1424
- break;
1425
- case this._formConfig.fieldTypes.array:
1426
- if (newValue === null || newValue === '') {
1427
- newFinalValue = [];
1428
- }
1429
- else if (!Array.isArray(newValue)) {
1430
- if (typeof (newValue) !== 'string') {
1431
- newValue = newValue.toString();
1432
- }
1433
- newFinalValue = newValue.split(',');
1434
- }
1435
- else {
1436
- newFinalValue = newValue;
1437
- }
1438
- break;
1439
- case this._formConfig.fieldTypes.map:
1440
- newFinalValue = newValue;
1441
- if (newFinalValue && this.widget && widgetUpdate) {
1442
- const latitude = parseFloat(newFinalValue[0]);
1443
- const longitude = parseFloat(newFinalValue[1]);
1444
- (_a = this.widget) === null || _a === void 0 ? void 0 : _a.setLocation(latitude, longitude);
1445
- }
1446
- break;
1447
- default:
1410
+ if (this.fieldType === this._formConfig.fieldTypes.boolean
1411
+ || this.fieldType === this._formConfig.fieldTypes.check) {
1412
+ newFinalValue = yn(newValue);
1413
+ }
1414
+ else if (this.fieldType === this._formConfig.fieldTypes.array
1415
+ || this.fieldType === this._formConfig.fieldTypes.map) {
1416
+ if (newValue === null || newValue === '') {
1417
+ newFinalValue = [];
1418
+ }
1419
+ else if (Array.isArray(newValue)) {
1448
1420
  newFinalValue = newValue;
1449
- break;
1421
+ }
1422
+ else {
1423
+ newFinalValue = newValue.toString().split(',');
1424
+ }
1425
+ }
1426
+ else {
1427
+ newFinalValue = newValue;
1450
1428
  }
1451
1429
  if (this._value !== newFinalValue) {
1452
1430
  this.setChanged(true);
1453
- this.setAttr(fldAttr.value, newFinalValue);
1431
+ if (widgetUpdate) {
1432
+ this.setAttr(fldAttr.value, newFinalValue);
1433
+ }
1434
+ else {
1435
+ this._value = newFinalValue;
1436
+ }
1454
1437
  }
1455
1438
  return true;
1456
1439
  }
@@ -3537,11 +3520,8 @@ class BasicFormComponent {
3537
3520
  this.tagFieldsWithError(requiredEmptyFields, null, this.formConfig.formStandardErrors.requiredField);
3538
3521
  for (const fieldCode of requiredEmptyFields) {
3539
3522
  const requiredEmptyField = this.getField(fieldCode);
3540
- if (requiredEmptyField && requiredEmptyField.widget
3541
- && requiredEmptyField.widget.focus) {
3542
- requiredEmptyField.widget.focus();
3543
- break;
3544
- }
3523
+ requiredEmptyField === null || requiredEmptyField === void 0 ? void 0 : requiredEmptyField.focus();
3524
+ break;
3545
3525
  }
3546
3526
  }
3547
3527
  const validationIssueFields = this.getFieldsWithValidationIssues(null, sectionCode);
@@ -3550,11 +3530,8 @@ class BasicFormComponent {
3550
3530
  this.setError(this.formConfig.formStandardErrors.typeWarning, this.formConfig.formStandardErrors.validationTitle, this.formConfig.formStandardErrors.validationFields);
3551
3531
  for (const fieldCode of validationIssueFields) {
3552
3532
  const validationIssueField = this.getField(fieldCode);
3553
- if (validationIssueField && validationIssueField.widget
3554
- && validationIssueField.widget.focus) {
3555
- validationIssueField.widget.focus();
3556
- break;
3557
- }
3533
+ validationIssueField.focus();
3534
+ break;
3558
3535
  }
3559
3536
  }
3560
3537
  return validationError;