tuain-ng-forms-lib 14.5.10 → 14.5.26

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.
@@ -126,6 +126,7 @@ class FieldComponent extends ElementComponent {
126
126
  }
127
127
  this.formConfig = this.field?._formConfig;
128
128
  const mapping = Object.entries(this.formConfig?.fieldPropagateAttributes);
129
+ const customAttributesMapping = this.formConfig?.propagationCustomAttributes.fields ?? [];
129
130
  for (let index = 0; index < mapping.length; index++) {
130
131
  const fieldAttr = mapping[index]?.[0];
131
132
  const componentAttr = mapping[index]?.[1]?.toString() ?? '';
@@ -135,6 +136,18 @@ class FieldComponent extends ElementComponent {
135
136
  this.customProcessAttributeChange(componentAttr, value);
136
137
  }
137
138
  }
139
+ // Atributos personalizados
140
+ for (let index = 0; index < customAttributesMapping.length; index++) {
141
+ const customAttribute = customAttributesMapping[index];
142
+ if (customAttribute) {
143
+ const value = this.field?.getCustomAttribute(customAttribute);
144
+ const fullName = `customAttributes.${customAttribute}`;
145
+ if (value) {
146
+ this.defaultProcessAttributeChange(fullName, value);
147
+ this.customProcessAttributeChange(fullName, value);
148
+ }
149
+ }
150
+ }
138
151
  // Subscripción a cambios en atributos
139
152
  this.field?.attributeChange.subscribe(event => {
140
153
  const { name: componentAttr, value } = event;
@@ -298,6 +311,7 @@ const INLINE_ACTION$1 = 'INLINE';
298
311
  class LibTableRecordActionComponent extends PieceComponent {
299
312
  constructor() {
300
313
  super(...arguments);
314
+ this.isVisible = true;
301
315
  this.actionSelected = new EventEmitter();
302
316
  }
303
317
  ngOnInit() {
@@ -309,20 +323,25 @@ class LibTableRecordActionComponent extends PieceComponent {
309
323
  this.defaultProcessAttributeChange(attrName, attributeValue);
310
324
  this.customProcessAttributeChange(attrName, attributeValue);
311
325
  }
312
- // Subscripción a cambios en atributos
313
- this.action?.attributeChange.subscribe(event => {
314
- const { name: attrName, value } = event;
315
- this.defaultProcessAttributeChange(attrName, value);
316
- this.customProcessAttributeChange(attrName, value);
317
- });
318
326
  this.start();
319
327
  }
320
328
  start() {
321
- this.action?.setRecodData(this.recordData);
329
+ if (this.action && this.action.restrictedOnField && this.recordData) {
330
+ const relatedField = this.recordData[this.action.restrictedOnField];
331
+ if (relatedField) {
332
+ const fieldValue = relatedField;
333
+ const restrictionOper = this.action.restrictedOnOperator;
334
+ const restrictionValue = this.action.restrictedOnValue;
335
+ if ((restrictionOper === '==' && fieldValue !== restrictionValue)
336
+ || (restrictionOper === '!=' && fieldValue === restrictionValue)) {
337
+ this.isVisible = false;
338
+ }
339
+ }
340
+ }
322
341
  }
323
342
  onActivate() {
324
343
  const tableEvent = {
325
- actionCode: this.action.actionCode,
344
+ actionCode: this.action?.actionCode ?? '',
326
345
  recordId: this.recordId,
327
346
  recordData: this.recordData,
328
347
  };
@@ -494,8 +513,8 @@ class FormPiece {
494
513
  this._formState = '';
495
514
  this._absoluteVisible = true;
496
515
  this._absoluteDisabled = false;
497
- this.visibleStates = null;
498
- this.enabledStates = null;
516
+ this.visibleStates = [];
517
+ this.enabledStates = [];
499
518
  this._form = null;
500
519
  this._visible = true;
501
520
  this._disabled = false;
@@ -527,13 +546,35 @@ class FormPiece {
527
546
  const visibleStates = (!Array.isArray(newStates) && typeof newStates === 'string')
528
547
  ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
529
548
  : newStates;
530
- this.visibleStates = (Array.isArray(visibleStates)) ? visibleStates : [];
549
+ this.visibleStates = (Array.isArray(visibleStates)) ? [...(new Set(visibleStates))] : [];
550
+ }
551
+ addVisibleState(state) {
552
+ if (!this.visibleStates.includes(state)) {
553
+ this.visibleStates.push(state);
554
+ }
555
+ }
556
+ removeVisibleState(state) {
557
+ const existStateIdx = this.visibleStates.findIndex(st => st === state);
558
+ if (existStateIdx >= 0) {
559
+ this.visibleStates.splice(existStateIdx, 1);
560
+ }
531
561
  }
532
562
  setEnabledStates(newStates) {
533
563
  const enabledStates = (!Array.isArray(newStates) && typeof newStates === 'string')
534
564
  ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
535
565
  : newStates;
536
- this.enabledStates = (Array.isArray(enabledStates)) ? enabledStates : [];
566
+ this.enabledStates = (Array.isArray(enabledStates)) ? [...(new Set(enabledStates))] : [];
567
+ }
568
+ addEnabledState(state) {
569
+ if (!this.enabledStates.includes(state)) {
570
+ this.enabledStates.push(state);
571
+ }
572
+ }
573
+ removeEnabledState(state) {
574
+ const existStateIdx = this.enabledStates.findIndex(st => st === state);
575
+ if (existStateIdx >= 0) {
576
+ this.enabledStates.splice(existStateIdx, 1);
577
+ }
537
578
  }
538
579
  viewOnState(state) { return (this.visibleStates && state) ? this.visibleStates.includes(state) : false; }
539
580
  enabledOnState(state) { return (this.enabledStates && state) ? this.enabledStates.includes(state) : false; }
@@ -601,7 +642,8 @@ class FormPiecePropagate extends FormPiece {
601
642
  setCustomAttribute(name, value) {
602
643
  super.setCustomAttribute(name, value);
603
644
  if (this.propagationCustomAttributes?.includes(name)) {
604
- this.propagateAttribute(name, value);
645
+ const fullName = `customAttributes.${name}`;
646
+ this.propagateAttribute(fullName, value);
605
647
  }
606
648
  }
607
649
  setVisibility(visible, forced = null) {
@@ -661,6 +703,23 @@ class FormAction extends FormElement {
661
703
  }
662
704
  this.customValidation = () => true;
663
705
  }
706
+ connectWithParentForm(form, formChangeSubject) {
707
+ super.connectWithParentForm(form, formChangeSubject);
708
+ if (this.restrictedOnField) {
709
+ const relatedField = this._form.fields?.[this.restrictedOnField];
710
+ if (relatedField) {
711
+ relatedField.editionFinish.subscribe(event => this.updateRestrictedVisibility());
712
+ relatedField.editionPartial.subscribe(event => this.updateRestrictedVisibility());
713
+ }
714
+ }
715
+ }
716
+ updateRestrictedVisibility() {
717
+ const lastVisible = this._visible;
718
+ const newVisible = this._absoluteVisible && this.viewOnState(this._formState);
719
+ if (lastVisible !== newVisible) {
720
+ this.setVisibility(newVisible);
721
+ }
722
+ }
664
723
  viewOnState(state) {
665
724
  const actionVisible = (this.visibleStates && state) ? this.visibleStates.includes(state) : false;
666
725
  if (actionVisible && this._form && this.restrictedOnField) {
@@ -1214,25 +1273,6 @@ class TableAction extends FormPiece {
1214
1273
  this.restrictedOnOperator = actionDefinition.operatorRestricted || null;
1215
1274
  }
1216
1275
  }
1217
- viewOnState(state) {
1218
- const actionVisible = (this.visibleStates && state) ? this.visibleStates.includes(state) : false;
1219
- if (actionVisible && this._form && this.restrictedOnField) {
1220
- // Aqui se debe cambiar el campo por la columna del registro!!!!!
1221
- // const relatedField = this._form.fields?.[this.restrictedOnField];
1222
- const relatedField = this.recordData?.[this.restrictedOnField];
1223
- if (relatedField) {
1224
- const fieldValue = relatedField.value;
1225
- if ((this.restrictedOnOperator === '==' && fieldValue !== this.restrictedOnValue)
1226
- || (this.restrictedOnOperator === '!=' && fieldValue === this.restrictedOnValue)) {
1227
- return false;
1228
- }
1229
- }
1230
- }
1231
- return actionVisible;
1232
- }
1233
- setRecodData(recordData) {
1234
- this.recordData = recordData;
1235
- }
1236
1276
  }
1237
1277
 
1238
1278
  class TableRecordData {
@@ -1601,23 +1641,70 @@ class RecordTable extends FormElement {
1601
1641
  }
1602
1642
  updateFromServer(tableReceived) {
1603
1643
  this.requestedPage = 1;
1604
- this.visible = tableReceived?.visible || true;
1605
- this.totalPages = tableReceived.totalPages || 1;
1606
- this.recordsNumber = tableReceived.recordsNumber;
1607
- this.setAttr(attrs.currentPage, +tableReceived?.currentPage || 1);
1608
- this.setAttr(attrs.recordsPerPage, +tableReceived.recordsPerPage);
1609
- this.setAttr(attrs.totalRecordsNumber, (this.clientPaging) ? tableReceived.tableRecords.length : +tableReceived.totalRecordsNumber);
1610
- this.setAttr(attrs.sorting, {
1611
- columnName: tableReceived.sortingColumn || '',
1612
- direction: tableReceived.sortingDirection || ''
1613
- });
1614
- this.waiting = false;
1615
- if (!this._appendPages) {
1616
- this.replaceRecords(tableReceived.tableRecords);
1644
+ const { visible = true, totalPages = 1, recordsNumber, currentPage = 1, recordsPerPage, totalRecordsNumber, sortingColumn, sortingDirection, tableRecords, actions, fields, } = tableReceived;
1645
+ this.visible = visible;
1646
+ if (actions) {
1647
+ Object.keys(actions).forEach(actionCode => {
1648
+ const tblAction = this.getAction(actionCode);
1649
+ const actionReceived = actions[actionCode];
1650
+ if (actionReceived.visible === true || actionReceived.visible === false) {
1651
+ (actionReceived.visible === true) && tblAction.show();
1652
+ (actionReceived.visible === false) && tblAction.hide();
1653
+ }
1654
+ if (actionReceived.enabled === true || actionReceived.enabled === false) {
1655
+ (actionReceived.enabled === true) && tblAction.enable();
1656
+ (actionReceived.enabled === false) && tblAction.disable();
1657
+ }
1658
+ if (actionReceived.showOnStates) {
1659
+ actionReceived.showOnStates?.forEach(newState => {
1660
+ tblAction.addVisibleState(newState);
1661
+ });
1662
+ }
1663
+ if (actionReceived.hideOnStates) {
1664
+ actionReceived.hideOnStates?.forEach(newState => {
1665
+ tblAction.removeVisibleState(newState);
1666
+ });
1667
+ }
1668
+ if (actionReceived.enableOnStates) {
1669
+ actionReceived.enableOnStates?.forEach(newState => {
1670
+ tblAction.addEnabledState(newState);
1671
+ });
1672
+ }
1673
+ if (actionReceived.disableOnStates) {
1674
+ actionReceived.disableOnStates?.forEach(newState => {
1675
+ tblAction.removeEnabledState(newState);
1676
+ });
1677
+ }
1678
+ });
1617
1679
  }
1618
- else {
1619
- this.appendRecords(tableReceived.tableRecords);
1680
+ if (fields) {
1681
+ Object.keys(fields).forEach(fieldCode => {
1682
+ const tblField = this.columnDefinition(fieldCode);
1683
+ const fieldReceived = fields[fieldCode];
1684
+ if (fieldReceived.visible === true || fieldReceived.visible === false) {
1685
+ (fieldReceived.visible === true) && tblField.show();
1686
+ (fieldReceived.visible === false) && tblField.hide();
1687
+ }
1688
+ });
1620
1689
  }
1690
+ if (tableRecords) {
1691
+ this.totalPages = totalPages;
1692
+ this.recordsNumber = recordsNumber;
1693
+ this.setAttr(attrs.currentPage, +currentPage);
1694
+ this.setAttr(attrs.recordsPerPage, +recordsPerPage);
1695
+ this.setAttr(attrs.totalRecordsNumber, (this.clientPaging) ? tableRecords.length : +totalRecordsNumber);
1696
+ this.setAttr(attrs.sorting, {
1697
+ columnName: sortingColumn || '',
1698
+ direction: sortingDirection || ''
1699
+ });
1700
+ if (!this._appendPages) {
1701
+ this.replaceRecords(tableRecords);
1702
+ }
1703
+ else {
1704
+ this.appendRecords(tableRecords);
1705
+ }
1706
+ }
1707
+ this.waiting = false;
1621
1708
  this.updateVisibleRecords();
1622
1709
  }
1623
1710
  getTableRecord(recordId) {
@@ -2500,6 +2587,7 @@ class LibFileManagementService {
2500
2587
  openFile(fileBase64Data, fileName, fileType) { }
2501
2588
  saveFileFromURL(fileUrl, fullFileName = null) { }
2502
2589
  saveFile(fileBase64Data, fileName, fileType) { }
2590
+ printPdfFile(pdfBufferData) { }
2503
2591
  }
2504
2592
 
2505
2593
  const PAYLOAD_VERSION = 'TUAINEXCHANGE_1.0';