tuain-ng-forms-lib 12.0.5 → 12.0.6

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.
@@ -536,13 +536,13 @@ class RecordTable extends FormElement {
536
536
  this._recordSelectionTrigger = new Subject();
537
537
  this._selectionActionTrigger = new Subject();
538
538
  this._getDataTrigger = new Subject();
539
+ this._attributeChange = new Subject();
539
540
  this.tableRecordObj = {};
540
541
  this._tableColumnObj = {};
541
542
  this._actionsObj = {};
542
543
  this.allSelected = false;
543
544
  this.elementType = elementTypes.table;
544
545
  this.waiting = false;
545
- this.complexFilter = false;
546
546
  this.currentPage = 1;
547
547
  this.totalPages = 1;
548
548
  this.requestedPage = 1;
@@ -550,26 +550,30 @@ class RecordTable extends FormElement {
550
550
  this._tableColumnObj = {};
551
551
  this._actions = [];
552
552
  this._actionsObj = {};
553
- this.filterConfig = [];
554
- this.filterObject = new Filter();
555
553
  this.tableRecords = [];
556
- this.tableCode = tableReceived.tableCode;
554
+ this.setAttr('allSelected', false);
555
+ this.setAttr('filterObject', new Filter());
556
+ this.setAttr('filterConfig', []);
557
+ this.setAttr('tableCode', tableReceived.tableCode);
557
558
  this.tableTitle = tableReceived.tableTitle;
558
- this.clientPaging = (_a = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.clientPaging) !== null && _a !== void 0 ? _a : true;
559
- this.simpleFilter = (_b = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.simpleFilter) !== null && _b !== void 0 ? _b : false;
559
+ this.setAttr('clientPaging', (_a = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.clientPaging) !== null && _a !== void 0 ? _a : true);
560
+ this.setAttr('simpleFilter', (_b = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.simpleFilter) !== null && _b !== void 0 ? _b : false);
561
+ this.setAttr('complexFilter', false);
560
562
  this._appendPages = (_c = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.append) !== null && _c !== void 0 ? _c : false;
561
563
  this.selectable = (_d = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectable) !== null && _d !== void 0 ? _d : false;
562
- this.selectionBackend = (_e = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectionBackend) !== null && _e !== void 0 ? _e : false;
564
+ this.setAttr('selectionBackend', (_e = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectionBackend) !== null && _e !== void 0 ? _e : false);
563
565
  this.customAttributes = (_f = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.customAttributes) !== null && _f !== void 0 ? _f : {};
564
- this.sortable = (_g = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.sortable) !== null && _g !== void 0 ? _g : false;
565
- this.sorting = { columnName: '', direction: '' };
566
- this.recordsPerPage = formConfig.defaultRecordsPerPage;
566
+ this.setAttr('sortable', (_g = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.sortable) !== null && _g !== void 0 ? _g : false);
567
+ this.setAttr('sorting', { columnName: '', direction: '' });
568
+ this.setAttr('recordsPerPage', formConfig.defaultRecordsPerPage);
567
569
  if (tableReceived.fields) {
570
+ const columns = [];
568
571
  for (const columnReceived of tableReceived.fields) {
569
572
  const columnDefinition = new RecordTableColumn(columnReceived, this._formConfig);
570
- this.columns.push(columnDefinition);
573
+ columns.push(columnDefinition);
571
574
  this._tableColumnObj[columnDefinition.fieldCode] = columnDefinition;
572
575
  }
576
+ this.setAttr('columns', columns);
573
577
  }
574
578
  if (tableReceived.actions) {
575
579
  const tableActions = tableReceived.actions.map(objDef => {
@@ -592,11 +596,13 @@ class RecordTable extends FormElement {
592
596
  }
593
597
  }
594
598
  if (tableReceived.filters && tableReceived.filters.length > 0) {
595
- this.complexFilter = true;
599
+ this.setAttr('complexFilter', true);
600
+ const filterConfig = this.filterConfig;
596
601
  for (const filterReceived of tableReceived.filters) {
597
602
  const filterItem = new FieldSearch(filterReceived);
598
- this.filterConfig.push(filterItem);
603
+ filterConfig.push(filterItem);
599
604
  }
605
+ this.setAttr('filterConfig', filterConfig);
600
606
  }
601
607
  if (this.selectable) {
602
608
  this.selectionField = this.columns
@@ -608,6 +614,7 @@ class RecordTable extends FormElement {
608
614
  get selectionActionTrigger() { return this._selectionActionTrigger; }
609
615
  get recordSelectionTrigger() { return this._recordSelectionTrigger; }
610
616
  get getDataTrigger() { return this._getDataTrigger; }
617
+ get attributeChange() { return this._attributeChange; }
611
618
  get hasActions() { return (this._actions.length > 0); }
612
619
  get selectionFieldName() { var _a, _b; return (_b = (_a = this.selectionField) === null || _a === void 0 ? void 0 : _a.fieldCode) !== null && _b !== void 0 ? _b : null; }
613
620
  get columnNames() { return Object.keys(this._tableColumnObj); }
@@ -617,6 +624,12 @@ class RecordTable extends FormElement {
617
624
  return this.tableRecords.filter(rec => rec.selected)
618
625
  .map(rec => rec.recordId);
619
626
  }
627
+ setAttr(name, value) {
628
+ this[name] = value;
629
+ if (this._formConfig.monitoredTableAttributes.includes(name)) {
630
+ this._attributeChange.next({ name, value });
631
+ }
632
+ }
620
633
  appendRecords(records) { this.setTableRecords(records, true); }
621
634
  replaceRecords(records) { this.setTableRecords(records, false); }
622
635
  columnDefinition(fieldCode) { return this._tableColumnObj[fieldCode]; }
@@ -683,11 +696,11 @@ class RecordTable extends FormElement {
683
696
  this.tableRecordObj = {};
684
697
  }
685
698
  selectAll() {
686
- this.allSelected = true;
699
+ this.setAttr('allSelected', true);
687
700
  this.tableRecords.forEach(record => record.select());
688
701
  }
689
702
  unSelectAll() {
690
- this.allSelected = false;
703
+ this.setAttr('allSelected', false);
691
704
  this.tableRecords.forEach(record => record.unselect());
692
705
  }
693
706
  setTableRecords(tableRecords, append) {
@@ -709,21 +722,24 @@ class RecordTable extends FormElement {
709
722
  }
710
723
  updateVisibleRecords() {
711
724
  if (!this.clientPaging || !this.tableRecords || this.tableRecords.length === 0) {
712
- this.visibleRecords = this.tableRecords;
725
+ this.setAttr('visibleRecords', this.tableRecords);
713
726
  }
714
- this.visibleRecords = (this.filterObject.filterModeSimple)
727
+ const recordsVisible = (this.filterObject.filterModeSimple)
715
728
  ? this.tableRecords.filter(record => record.hasPattern(this.filterObject.simpleFilterWords))
716
729
  : this.tableRecords.filter(record => record.hasCondition(this.filterObject.advancedFilter));
730
+ this.setAttr('visibleRecords', recordsVisible);
717
731
  }
718
732
  updateFromServer(tableReceived) {
719
733
  this.visible = (tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.visible) || true;
720
- this.currentPage = parseInt(tableReceived.currentPage, 10) || 1;
734
+ this.setAttr('currentPage', parseInt(tableReceived.currentPage, 10) || 1);
721
735
  this.totalPages = tableReceived.totalPages || 1;
722
- this.recordsPerPage = tableReceived.recordsPerPage;
736
+ this.setAttr('recordsPerPage', tableReceived.recordsPerPage);
723
737
  this.recordsNumber = tableReceived.recordsNumber;
724
- this.totalRecordsNumber = tableReceived.totalRecordsNumber;
725
- this.sorting.columnName = tableReceived.sortingColumn || '';
726
- this.sorting.direction = tableReceived.sortingDirection || '';
738
+ this.setAttr('totalRecordsNumber', tableReceived.totalRecordsNumber);
739
+ this.setAttr('sorting', {
740
+ columnName: tableReceived.sortingColumn || '',
741
+ direction: tableReceived.sortingDirection || ''
742
+ });
727
743
  this.requestedPage = 1;
728
744
  this.waiting = false;
729
745
  this.clean();
@@ -803,16 +819,15 @@ class RecordTable extends FormElement {
803
819
  // Ordenamiento
804
820
  setRequiredOrder(columnField) {
805
821
  if (columnField !== this.sorting.columnName) {
806
- this.sorting.columnName = columnField;
807
- this.sorting.direction = TABLE_SORT_ASCENDING;
822
+ this.setAttr('sorting', {
823
+ columnName: columnField,
824
+ direction: TABLE_SORT_ASCENDING
825
+ });
808
826
  }
809
827
  else {
810
- if (this.sorting.direction === TABLE_SORT_ASCENDING) {
811
- this.sorting.direction = TABLE_SORT_DESCENDING;
812
- }
813
- else {
814
- this.sorting.direction = TABLE_SORT_ASCENDING;
815
- }
828
+ const tableSort = this.sorting;
829
+ tableSort.direction = (tableSort.direction === TABLE_SORT_ASCENDING) ? TABLE_SORT_DESCENDING : TABLE_SORT_ASCENDING;
830
+ this.setAttr('sorting', tableSort);
816
831
  }
817
832
  }
818
833
  localSortData() {
@@ -988,15 +1003,29 @@ class LibTableComponent {
988
1003
  this.hasActions = false;
989
1004
  }
990
1005
  ngOnInit() {
991
- var _a;
992
- this.formConfig = (_a = this.tableObject) === null || _a === void 0 ? void 0 : _a._formConfig;
993
- this.tableFieldStyles = this.formConfig.tableFieldStyles;
994
- this.selectable = this.tableObject.selectable;
995
- this.hasActions = this.tableObject.hasActions;
996
- this.tableObject.widget = this;
997
- this.inlineActions = this.tableObject.getActions(this.formConfig.tableActions.inline);
998
- this.globalActions = this.tableObject.getActions(this.formConfig.tableActions.global);
999
- this.selectionActions = this.tableObject.getActions(this.formConfig.tableActions.selection);
1006
+ var _a, _b;
1007
+ if (this.tableObject) {
1008
+ this.formConfig = (_a = this.tableObject) === null || _a === void 0 ? void 0 : _a._formConfig;
1009
+ this.tableFieldStyles = this.formConfig.tableFieldStyles;
1010
+ this.selectable = this.tableObject.selectable;
1011
+ this.hasActions = this.tableObject.hasActions;
1012
+ this.tableObject.widget = this;
1013
+ this.inlineActions = this.tableObject.getActions(this.formConfig.tableActions.inline);
1014
+ this.globalActions = this.tableObject.getActions(this.formConfig.tableActions.global);
1015
+ this.selectionActions = this.tableObject.getActions(this.formConfig.tableActions.selection);
1016
+ // Inicialización de campos mapeados del objeto
1017
+ const mapping = Object.entries(this.formConfig.componentTableAttrMap);
1018
+ for (let index = 0; index < mapping.length; index++) {
1019
+ const [tableAttr, compAttr] = mapping[index];
1020
+ this[compAttr.toString()] = (_b = this.tableObject) === null || _b === void 0 ? void 0 : _b[tableAttr.toString()];
1021
+ }
1022
+ // Subscripción a cambios en atributos
1023
+ this.tableObject.attributeChange.subscribe(event => {
1024
+ const { name: tableAttr, value } = event;
1025
+ const compAttr = this.formConfig.componentTableAttrMap[tableAttr];
1026
+ this.hasOwnProperty(compAttr) && (this[compAttr] = value);
1027
+ });
1028
+ }
1000
1029
  this.start();
1001
1030
  }
1002
1031
  start() { }
@@ -1011,22 +1040,22 @@ class LibTableComponent {
1011
1040
  }
1012
1041
  tableColumnSort(columnFieldCode) {
1013
1042
  this.tableObject.setRequiredOrder(columnFieldCode);
1014
- if (this.tableObject.clientPaging) {
1043
+ if (this.clientPaging) {
1015
1044
  return this.tableObject.localSortData();
1016
1045
  }
1017
1046
  this.tableObject.notifyGetDataAction();
1018
1047
  }
1019
1048
  changePage(requestedPage) {
1020
- if (!this.tableObject.clientPaging) {
1049
+ if (!this.clientPaging) {
1021
1050
  this.tableObject.notifyGetDataAction(requestedPage);
1022
1051
  }
1023
1052
  }
1024
1053
  get records() {
1025
- const currentPageRecords = this.tableObject.records;
1026
- if (this.tableObject.clientPaging && currentPageRecords && currentPageRecords.length > 0) {
1027
- this.tableObject.totalRecordsNumber = currentPageRecords.length;
1054
+ const currentPageRecords = this.visibleRecords;
1055
+ if (this.clientPaging && currentPageRecords && currentPageRecords.length > 0) {
1056
+ this.totalRecordsNumber = currentPageRecords.length;
1028
1057
  return currentPageRecords.map((record, i) => (Object.assign({ id: i + 1 }, record)))
1029
- .slice((this.tableObject.currentPage - 1) * this.tableObject.recordsPerPage, (this.tableObject.currentPage - 1) * this.tableObject.recordsPerPage + this.tableObject.recordsPerPage);
1058
+ .slice((this.currentPage - 1) * this.recordsPerPage, (this.currentPage - 1) * this.recordsPerPage + this.recordsPerPage);
1030
1059
  }
1031
1060
  return currentPageRecords;
1032
1061
  }
@@ -1035,8 +1064,8 @@ class LibTableComponent {
1035
1064
  let triggerDataUpdate = false;
1036
1065
  if (eventType === TABLE_FILTER_TYPES.simpleFilterChange || eventType === TABLE_FILTER_TYPES.simpleFilterFinish) {
1037
1066
  this.tableObject.simpleFilterText = tableFilterEvent.simpleFilterString.trim();
1038
- if (this.tableObject.clientPaging) {
1039
- this.tableObject.currentPage = 1;
1067
+ if (this.clientPaging) {
1068
+ this.tableObject.setAttr('currentPage', 1);
1040
1069
  this.tableObject.updateVisibleRecords();
1041
1070
  }
1042
1071
  else if (eventType === TABLE_FILTER_TYPES.simpleFilterFinish) {
@@ -1061,13 +1090,19 @@ class LibTableComponent {
1061
1090
  this.tableObject.notifyRecordSelection(recordId);
1062
1091
  }
1063
1092
  toggleSelectAll() {
1064
- if (this.tableObject.allSelected) {
1093
+ if (this.allSelected) {
1065
1094
  this.tableObject.unSelectAll();
1066
1095
  }
1067
1096
  else {
1068
1097
  this.tableObject.selectAll();
1069
1098
  }
1070
1099
  }
1100
+ get availableFilters() {
1101
+ return this.tableObject.availableFilters;
1102
+ }
1103
+ get selectedRecords() {
1104
+ return this.tableObject.selectedRecords;
1105
+ }
1071
1106
  }
1072
1107
  LibTableComponent.decorators = [
1073
1108
  { type: Component, args: [{
@@ -1473,20 +1508,20 @@ class FieldDescriptor extends FormElement {
1473
1508
  for (let index = 0; index < fieldKeys.length; index++) {
1474
1509
  const attrName = fieldKeys[index];
1475
1510
  const attrValue = fld[attrName];
1476
- (attrName === this._formConfig.apifieldattrs.visible) && this.setVisibility(attrValue);
1477
- (attrName === this._formConfig.apifieldattrs.labelVisible) && this.setVisibleLabel(fld.visibleLabel);
1478
- (attrName === this._formConfig.apifieldattrs.required) && this.setAttr(fldAttr.required, (_a = fld.required) !== null && _a !== void 0 ? _a : false);
1479
- (attrName === this._formConfig.apifieldattrs.errorCode) && this.setAttr(fldAttr.errorCode, fld.errorCode);
1480
- (attrName === this._formConfig.apifieldattrs.errorMessage) && this.setAttr(fldAttr.errorMessage, fld.errorMessage);
1481
- (attrName === this._formConfig.apifieldattrs.tooltip) && this.setAttr(fldAttr.tooltipText, fld.tooltip);
1482
- (attrName === this._formConfig.apifieldattrs.info) && this.setAttr(fldAttr.info, fld.info);
1483
- (attrName === this._formConfig.apifieldattrs.editable) && this.setEditable(fld.editable);
1484
- (attrName === this._formConfig.apifieldattrs.title) && this.setLabel(fld.fieldTitle.toString());
1485
- (attrName === this._formConfig.apifieldattrs.value) && (this.setValue(fld.fieldValue) && this.setChanged(false));
1486
- (attrName === this._formConfig.apifieldattrs.options) && this.setFieldOptions(fld.fieldOptions);
1487
- (attrName === this._formConfig.apifieldattrs.captureType) && this.setAttr(fldAttr.captureType, fld.captureType || 'INPUT');
1488
- (attrName === this._formConfig.apifieldattrs.type) && this.setFieldType(fld.fieldTypeCode);
1489
- (attrName === this._formConfig.apifieldattrs.maxLength) && this.setAttr(fldAttr.maxLength, fld.maxLength);
1511
+ (attrName === this._formConfig.apiFieldAttrs.visible) && this.setVisibility(attrValue);
1512
+ (attrName === this._formConfig.apiFieldAttrs.labelVisible) && this.setVisibleLabel(fld.visibleLabel);
1513
+ (attrName === this._formConfig.apiFieldAttrs.required) && this.setAttr(fldAttr.required, (_a = fld.required) !== null && _a !== void 0 ? _a : false);
1514
+ (attrName === this._formConfig.apiFieldAttrs.errorCode) && this.setAttr(fldAttr.errorCode, fld.errorCode);
1515
+ (attrName === this._formConfig.apiFieldAttrs.errorMessage) && this.setAttr(fldAttr.errorMessage, fld.errorMessage);
1516
+ (attrName === this._formConfig.apiFieldAttrs.tooltip) && this.setAttr(fldAttr.tooltipText, fld.tooltip);
1517
+ (attrName === this._formConfig.apiFieldAttrs.info) && this.setAttr(fldAttr.info, fld.info);
1518
+ (attrName === this._formConfig.apiFieldAttrs.editable) && this.setEditable(fld.editable);
1519
+ (attrName === this._formConfig.apiFieldAttrs.title) && this.setLabel(fld.fieldTitle.toString());
1520
+ (attrName === this._formConfig.apiFieldAttrs.value) && (this.setValue(fld.fieldValue) && this.setChanged(false));
1521
+ (attrName === this._formConfig.apiFieldAttrs.options) && this.setFieldOptions(fld.fieldOptions);
1522
+ (attrName === this._formConfig.apiFieldAttrs.captureType) && this.setAttr(fldAttr.captureType, fld.captureType || 'INPUT');
1523
+ (attrName === this._formConfig.apiFieldAttrs.type) && this.setFieldType(fld.fieldTypeCode);
1524
+ (attrName === this._formConfig.apiFieldAttrs.maxLength) && this.setAttr(fldAttr.maxLength, fld.maxLength);
1490
1525
  }
1491
1526
  }
1492
1527
  setFieldType(inputFieldType) {
@@ -2532,7 +2567,8 @@ class BasicFormComponent {
2532
2567
  this.controlToken = (_a = params === null || params === void 0 ? void 0 : params[TOKEN]) !== null && _a !== void 0 ? _a : null;
2533
2568
  const { token, subject, state, fields, extra, originToken } = this.formManagerService.getFormInfo(this.controlToken);
2534
2569
  if (!this.controlToken || this.controlToken !== token) {
2535
- console.log(`No se obtuvo un token válido para abrir el formulario ${this.controlToken}->${token}`);
2570
+ console.log(`No se obtuvo un token válido para abrir el formulario ${this.name}:${this.controlToken}->${token}`);
2571
+ return;
2536
2572
  }
2537
2573
  this.formSubject = (_c = (_b = params === null || params === void 0 ? void 0 : params[SUBJECT]) !== null && _b !== void 0 ? _b : subject) !== null && _c !== void 0 ? _c : null;
2538
2574
  this.inputDataFields = fields;