tuain-ng-forms-lib 12.0.5 → 12.0.9

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.
@@ -51,6 +51,7 @@ ActionComponent.propDecorators = {
51
51
  showLabel: [{ type: Input }]
52
52
  };
53
53
 
54
+ const VALUE = '';
54
55
  class FieldComponent {
55
56
  ngOnInit() {
56
57
  var _a, _b;
@@ -66,13 +67,20 @@ class FieldComponent {
66
67
  this.fieldObject.attributeChange.subscribe(event => {
67
68
  const { name: fieldAttr, value } = event;
68
69
  const compAttr = this.formConfig.componentFieldAttrMap[fieldAttr];
69
- this.hasOwnProperty(compAttr) && (this[compAttr] = value);
70
+ if (compAttr === VALUE) {
71
+ this.updateValue();
72
+ }
73
+ else if (this.hasOwnProperty(compAttr)) {
74
+ this[compAttr] = value;
75
+ }
70
76
  });
71
77
  }
72
78
  this.start();
73
79
  }
74
80
  start() { }
75
81
  focus() { }
82
+ updateValue() { }
83
+ updateObject() { }
76
84
  onInputChange() {
77
85
  setTimeout(() => this.fieldObject.notifyEditionPartial(), 50);
78
86
  }
@@ -536,13 +544,13 @@ class RecordTable extends FormElement {
536
544
  this._recordSelectionTrigger = new Subject();
537
545
  this._selectionActionTrigger = new Subject();
538
546
  this._getDataTrigger = new Subject();
547
+ this._attributeChange = new Subject();
539
548
  this.tableRecordObj = {};
540
549
  this._tableColumnObj = {};
541
550
  this._actionsObj = {};
542
551
  this.allSelected = false;
543
552
  this.elementType = elementTypes.table;
544
553
  this.waiting = false;
545
- this.complexFilter = false;
546
554
  this.currentPage = 1;
547
555
  this.totalPages = 1;
548
556
  this.requestedPage = 1;
@@ -550,26 +558,30 @@ class RecordTable extends FormElement {
550
558
  this._tableColumnObj = {};
551
559
  this._actions = [];
552
560
  this._actionsObj = {};
553
- this.filterConfig = [];
554
- this.filterObject = new Filter();
555
561
  this.tableRecords = [];
556
- this.tableCode = tableReceived.tableCode;
562
+ this.setAttr('allSelected', false);
563
+ this.setAttr('filterObject', new Filter());
564
+ this.setAttr('filterConfig', []);
565
+ this.setAttr('tableCode', tableReceived.tableCode);
557
566
  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;
567
+ this.setAttr('clientPaging', (_a = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.clientPaging) !== null && _a !== void 0 ? _a : true);
568
+ this.setAttr('simpleFilter', (_b = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.simpleFilter) !== null && _b !== void 0 ? _b : false);
569
+ this.setAttr('complexFilter', false);
560
570
  this._appendPages = (_c = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.append) !== null && _c !== void 0 ? _c : false;
561
571
  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;
572
+ this.setAttr('selectionBackend', (_e = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectionBackend) !== null && _e !== void 0 ? _e : false);
563
573
  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;
574
+ this.setAttr('sortable', (_g = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.sortable) !== null && _g !== void 0 ? _g : false);
575
+ this.setAttr('sorting', { columnName: '', direction: '' });
576
+ this.setAttr('recordsPerPage', formConfig.defaultRecordsPerPage);
567
577
  if (tableReceived.fields) {
578
+ const columns = [];
568
579
  for (const columnReceived of tableReceived.fields) {
569
580
  const columnDefinition = new RecordTableColumn(columnReceived, this._formConfig);
570
- this.columns.push(columnDefinition);
581
+ columns.push(columnDefinition);
571
582
  this._tableColumnObj[columnDefinition.fieldCode] = columnDefinition;
572
583
  }
584
+ this.setAttr('columns', columns);
573
585
  }
574
586
  if (tableReceived.actions) {
575
587
  const tableActions = tableReceived.actions.map(objDef => {
@@ -592,11 +604,13 @@ class RecordTable extends FormElement {
592
604
  }
593
605
  }
594
606
  if (tableReceived.filters && tableReceived.filters.length > 0) {
595
- this.complexFilter = true;
607
+ this.setAttr('complexFilter', true);
608
+ const filterConfig = this.filterConfig;
596
609
  for (const filterReceived of tableReceived.filters) {
597
610
  const filterItem = new FieldSearch(filterReceived);
598
- this.filterConfig.push(filterItem);
611
+ filterConfig.push(filterItem);
599
612
  }
613
+ this.setAttr('filterConfig', filterConfig);
600
614
  }
601
615
  if (this.selectable) {
602
616
  this.selectionField = this.columns
@@ -608,6 +622,7 @@ class RecordTable extends FormElement {
608
622
  get selectionActionTrigger() { return this._selectionActionTrigger; }
609
623
  get recordSelectionTrigger() { return this._recordSelectionTrigger; }
610
624
  get getDataTrigger() { return this._getDataTrigger; }
625
+ get attributeChange() { return this._attributeChange; }
611
626
  get hasActions() { return (this._actions.length > 0); }
612
627
  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
628
  get columnNames() { return Object.keys(this._tableColumnObj); }
@@ -617,6 +632,12 @@ class RecordTable extends FormElement {
617
632
  return this.tableRecords.filter(rec => rec.selected)
618
633
  .map(rec => rec.recordId);
619
634
  }
635
+ setAttr(name, value) {
636
+ this[name] = value;
637
+ if (this._formConfig.monitoredTableAttributes.includes(name)) {
638
+ this._attributeChange.next({ name, value });
639
+ }
640
+ }
620
641
  appendRecords(records) { this.setTableRecords(records, true); }
621
642
  replaceRecords(records) { this.setTableRecords(records, false); }
622
643
  columnDefinition(fieldCode) { return this._tableColumnObj[fieldCode]; }
@@ -683,11 +704,11 @@ class RecordTable extends FormElement {
683
704
  this.tableRecordObj = {};
684
705
  }
685
706
  selectAll() {
686
- this.allSelected = true;
707
+ this.setAttr('allSelected', true);
687
708
  this.tableRecords.forEach(record => record.select());
688
709
  }
689
710
  unSelectAll() {
690
- this.allSelected = false;
711
+ this.setAttr('allSelected', false);
691
712
  this.tableRecords.forEach(record => record.unselect());
692
713
  }
693
714
  setTableRecords(tableRecords, append) {
@@ -709,21 +730,24 @@ class RecordTable extends FormElement {
709
730
  }
710
731
  updateVisibleRecords() {
711
732
  if (!this.clientPaging || !this.tableRecords || this.tableRecords.length === 0) {
712
- this.visibleRecords = this.tableRecords;
733
+ this.setAttr('visibleRecords', this.tableRecords);
713
734
  }
714
- this.visibleRecords = (this.filterObject.filterModeSimple)
735
+ const recordsVisible = (this.filterObject.filterModeSimple)
715
736
  ? this.tableRecords.filter(record => record.hasPattern(this.filterObject.simpleFilterWords))
716
737
  : this.tableRecords.filter(record => record.hasCondition(this.filterObject.advancedFilter));
738
+ this.setAttr('visibleRecords', recordsVisible);
717
739
  }
718
740
  updateFromServer(tableReceived) {
719
741
  this.visible = (tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.visible) || true;
720
- this.currentPage = parseInt(tableReceived.currentPage, 10) || 1;
742
+ this.setAttr('currentPage', parseInt(tableReceived.currentPage, 10) || 1);
721
743
  this.totalPages = tableReceived.totalPages || 1;
722
- this.recordsPerPage = tableReceived.recordsPerPage;
744
+ this.setAttr('recordsPerPage', tableReceived.recordsPerPage);
723
745
  this.recordsNumber = tableReceived.recordsNumber;
724
- this.totalRecordsNumber = tableReceived.totalRecordsNumber;
725
- this.sorting.columnName = tableReceived.sortingColumn || '';
726
- this.sorting.direction = tableReceived.sortingDirection || '';
746
+ this.setAttr('totalRecordsNumber', tableReceived.totalRecordsNumber);
747
+ this.setAttr('sorting', {
748
+ columnName: tableReceived.sortingColumn || '',
749
+ direction: tableReceived.sortingDirection || ''
750
+ });
727
751
  this.requestedPage = 1;
728
752
  this.waiting = false;
729
753
  this.clean();
@@ -803,16 +827,15 @@ class RecordTable extends FormElement {
803
827
  // Ordenamiento
804
828
  setRequiredOrder(columnField) {
805
829
  if (columnField !== this.sorting.columnName) {
806
- this.sorting.columnName = columnField;
807
- this.sorting.direction = TABLE_SORT_ASCENDING;
830
+ this.setAttr('sorting', {
831
+ columnName: columnField,
832
+ direction: TABLE_SORT_ASCENDING
833
+ });
808
834
  }
809
835
  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
- }
836
+ const tableSort = this.sorting;
837
+ tableSort.direction = (tableSort.direction === TABLE_SORT_ASCENDING) ? TABLE_SORT_DESCENDING : TABLE_SORT_ASCENDING;
838
+ this.setAttr('sorting', tableSort);
816
839
  }
817
840
  }
818
841
  localSortData() {
@@ -988,15 +1011,29 @@ class LibTableComponent {
988
1011
  this.hasActions = false;
989
1012
  }
990
1013
  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);
1014
+ var _a, _b;
1015
+ if (this.tableObject) {
1016
+ this.formConfig = (_a = this.tableObject) === null || _a === void 0 ? void 0 : _a._formConfig;
1017
+ this.tableFieldStyles = this.formConfig.tableFieldStyles;
1018
+ this.selectable = this.tableObject.selectable;
1019
+ this.hasActions = this.tableObject.hasActions;
1020
+ this.tableObject.widget = this;
1021
+ this.inlineActions = this.tableObject.getActions(this.formConfig.tableActions.inline);
1022
+ this.globalActions = this.tableObject.getActions(this.formConfig.tableActions.global);
1023
+ this.selectionActions = this.tableObject.getActions(this.formConfig.tableActions.selection);
1024
+ // Inicialización de campos mapeados del objeto
1025
+ const mapping = Object.entries(this.formConfig.componentTableAttrMap);
1026
+ for (let index = 0; index < mapping.length; index++) {
1027
+ const [tableAttr, compAttr] = mapping[index];
1028
+ this[compAttr.toString()] = (_b = this.tableObject) === null || _b === void 0 ? void 0 : _b[tableAttr.toString()];
1029
+ }
1030
+ // Subscripción a cambios en atributos
1031
+ this.tableObject.attributeChange.subscribe(event => {
1032
+ const { name: tableAttr, value } = event;
1033
+ const compAttr = this.formConfig.componentTableAttrMap[tableAttr];
1034
+ this.hasOwnProperty(compAttr) && (this[compAttr] = value);
1035
+ });
1036
+ }
1000
1037
  this.start();
1001
1038
  }
1002
1039
  start() { }
@@ -1011,22 +1048,22 @@ class LibTableComponent {
1011
1048
  }
1012
1049
  tableColumnSort(columnFieldCode) {
1013
1050
  this.tableObject.setRequiredOrder(columnFieldCode);
1014
- if (this.tableObject.clientPaging) {
1051
+ if (this.clientPaging) {
1015
1052
  return this.tableObject.localSortData();
1016
1053
  }
1017
1054
  this.tableObject.notifyGetDataAction();
1018
1055
  }
1019
1056
  changePage(requestedPage) {
1020
- if (!this.tableObject.clientPaging) {
1057
+ if (!this.clientPaging) {
1021
1058
  this.tableObject.notifyGetDataAction(requestedPage);
1022
1059
  }
1023
1060
  }
1024
1061
  get records() {
1025
- const currentPageRecords = this.tableObject.records;
1026
- if (this.tableObject.clientPaging && currentPageRecords && currentPageRecords.length > 0) {
1027
- this.tableObject.totalRecordsNumber = currentPageRecords.length;
1062
+ const currentPageRecords = this.visibleRecords;
1063
+ if (this.clientPaging && currentPageRecords && currentPageRecords.length > 0) {
1064
+ this.totalRecordsNumber = currentPageRecords.length;
1028
1065
  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);
1066
+ .slice((this.currentPage - 1) * this.recordsPerPage, (this.currentPage - 1) * this.recordsPerPage + this.recordsPerPage);
1030
1067
  }
1031
1068
  return currentPageRecords;
1032
1069
  }
@@ -1035,8 +1072,8 @@ class LibTableComponent {
1035
1072
  let triggerDataUpdate = false;
1036
1073
  if (eventType === TABLE_FILTER_TYPES.simpleFilterChange || eventType === TABLE_FILTER_TYPES.simpleFilterFinish) {
1037
1074
  this.tableObject.simpleFilterText = tableFilterEvent.simpleFilterString.trim();
1038
- if (this.tableObject.clientPaging) {
1039
- this.tableObject.currentPage = 1;
1075
+ if (this.clientPaging) {
1076
+ this.tableObject.setAttr('currentPage', 1);
1040
1077
  this.tableObject.updateVisibleRecords();
1041
1078
  }
1042
1079
  else if (eventType === TABLE_FILTER_TYPES.simpleFilterFinish) {
@@ -1061,13 +1098,19 @@ class LibTableComponent {
1061
1098
  this.tableObject.notifyRecordSelection(recordId);
1062
1099
  }
1063
1100
  toggleSelectAll() {
1064
- if (this.tableObject.allSelected) {
1101
+ if (this.allSelected) {
1065
1102
  this.tableObject.unSelectAll();
1066
1103
  }
1067
1104
  else {
1068
1105
  this.tableObject.selectAll();
1069
1106
  }
1070
1107
  }
1108
+ get availableFilters() {
1109
+ return this.tableObject.availableFilters;
1110
+ }
1111
+ get selectedRecords() {
1112
+ return this.tableObject.selectedRecords;
1113
+ }
1071
1114
  }
1072
1115
  LibTableComponent.decorators = [
1073
1116
  { type: Component, args: [{
@@ -1460,7 +1503,8 @@ class FieldDescriptor extends FormElement {
1460
1503
  return (_b = this._fieldValue) !== null && _b !== void 0 ? _b : false;
1461
1504
  break;
1462
1505
  case this._formConfig.fieldTypes.currency:
1463
- return this._fieldValue.replace(',', '');
1506
+ return (typeof this._fieldValue === 'string')
1507
+ ? this._fieldValue.replace(',', '') : this._fieldValue;
1464
1508
  break;
1465
1509
  default:
1466
1510
  return this._fieldValue;
@@ -1473,20 +1517,20 @@ class FieldDescriptor extends FormElement {
1473
1517
  for (let index = 0; index < fieldKeys.length; index++) {
1474
1518
  const attrName = fieldKeys[index];
1475
1519
  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);
1520
+ (attrName === this._formConfig.apiFieldAttrs.visible) && this.setVisibility(attrValue);
1521
+ (attrName === this._formConfig.apiFieldAttrs.labelVisible) && this.setVisibleLabel(fld.visibleLabel);
1522
+ (attrName === this._formConfig.apiFieldAttrs.required) && this.setAttr(fldAttr.required, (_a = fld.required) !== null && _a !== void 0 ? _a : false);
1523
+ (attrName === this._formConfig.apiFieldAttrs.errorCode) && this.setAttr(fldAttr.errorCode, fld.errorCode);
1524
+ (attrName === this._formConfig.apiFieldAttrs.errorMessage) && this.setAttr(fldAttr.errorMessage, fld.errorMessage);
1525
+ (attrName === this._formConfig.apiFieldAttrs.tooltip) && this.setAttr(fldAttr.tooltipText, fld.tooltip);
1526
+ (attrName === this._formConfig.apiFieldAttrs.info) && this.setAttr(fldAttr.info, fld.info);
1527
+ (attrName === this._formConfig.apiFieldAttrs.editable) && this.setEditable(fld.editable);
1528
+ (attrName === this._formConfig.apiFieldAttrs.title) && this.setLabel(fld.fieldTitle.toString());
1529
+ (attrName === this._formConfig.apiFieldAttrs.value) && (this.setValue(fld.fieldValue) && this.setChanged(false));
1530
+ (attrName === this._formConfig.apiFieldAttrs.options) && this.setFieldOptions(fld.fieldOptions);
1531
+ (attrName === this._formConfig.apiFieldAttrs.captureType) && this.setAttr(fldAttr.captureType, fld.captureType || 'INPUT');
1532
+ (attrName === this._formConfig.apiFieldAttrs.type) && this.setFieldType(fld.fieldTypeCode);
1533
+ (attrName === this._formConfig.apiFieldAttrs.maxLength) && this.setAttr(fldAttr.maxLength, fld.maxLength);
1490
1534
  }
1491
1535
  }
1492
1536
  setFieldType(inputFieldType) {
@@ -1833,6 +1877,9 @@ class FormStructureAndData {
1833
1877
  getSections() {
1834
1878
  return this._sections;
1835
1879
  }
1880
+ get visibleSections() {
1881
+ return this._sections.filter(sec => sec.visible);
1882
+ }
1836
1883
  numSections() {
1837
1884
  return this._sections.length;
1838
1885
  }
@@ -2448,6 +2495,7 @@ class BasicFormComponent {
2448
2495
  disableActions(actionArray) { return this.formStructure.disableActions(actionArray); }
2449
2496
  getStates() { return this.formStructure.getStates(); }
2450
2497
  getSections() { return this.formStructure.getSections(); }
2498
+ get visibleSections() { return this.formStructure.visibleSections; }
2451
2499
  getSection(sectionCode) { return this.formStructure.getSection(sectionCode); }
2452
2500
  activateSection(sectionCode) { return this.formStructure.activateSection(sectionCode); }
2453
2501
  getSubSection(sectionCode, subsectionCode) { return this.formStructure.getSubSection(sectionCode, subsectionCode); }
@@ -2532,7 +2580,7 @@ class BasicFormComponent {
2532
2580
  this.controlToken = (_a = params === null || params === void 0 ? void 0 : params[TOKEN]) !== null && _a !== void 0 ? _a : null;
2533
2581
  const { token, subject, state, fields, extra, originToken } = this.formManagerService.getFormInfo(this.controlToken);
2534
2582
  if (!this.controlToken || this.controlToken !== token) {
2535
- console.log(`No se obtuvo un token válido para abrir el formulario ${this.controlToken}->${token}`);
2583
+ return;
2536
2584
  }
2537
2585
  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
2586
  this.inputDataFields = fields;