tuain-ng-forms-lib 13.0.15 → 14.0.1

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.
Files changed (99) hide show
  1. package/.browserslistrc +16 -0
  2. package/.yarn/cache/nanoid-npm-4.0.0-924f5c6312-7d5946df5c.zip +0 -0
  3. package/.yarn/cache/tslib-npm-2.4.0-9cb6dc5030-8c4aa6a3c5.zip +0 -0
  4. package/.yarn/cache/yn-npm-5.0.0-b001dab23c-f0ec7710d3.zip +0 -0
  5. package/.yarn/install-state.gz +0 -0
  6. package/karma.conf.js +44 -0
  7. package/ng-package.json +11 -0
  8. package/package.json +6 -26
  9. package/src/lib/classes/forms/action.ts +55 -0
  10. package/src/lib/classes/forms/element.ts +98 -0
  11. package/src/lib/classes/forms/field.ts +408 -0
  12. package/src/lib/classes/forms/form.constants.ts +28 -0
  13. package/src/lib/classes/forms/form.ts +495 -0
  14. package/src/lib/classes/forms/section.ts +154 -0
  15. package/src/lib/classes/forms/subsection.ts +91 -0
  16. package/src/lib/classes/forms/table/action.ts +41 -0
  17. package/src/lib/classes/forms/table/column.ts +91 -0
  18. package/src/lib/classes/forms/table/row-data.ts +118 -0
  19. package/src/lib/classes/forms/table/table.ts +438 -0
  20. package/src/lib/components/elements/action.component.ts +53 -0
  21. package/src/lib/components/elements/field.component.ts +118 -0
  22. package/src/lib/components/elements/layout/element.component.ts +28 -0
  23. package/src/lib/components/elements/layout/form-error.component.ts +11 -0
  24. package/src/lib/components/elements/layout/form-header.component.ts +17 -0
  25. package/src/lib/components/elements/layout/section.component.ts +16 -0
  26. package/src/lib/components/elements/layout/sub-section.component.ts +17 -0
  27. package/src/lib/components/elements/tables/table-record-action.component.ts +37 -0
  28. package/src/lib/components/elements/tables/table-record-field.component.ts +19 -0
  29. package/src/lib/components/elements/tables/table.component.ts +102 -0
  30. package/src/lib/components/forms/basic-form.ts +1496 -0
  31. package/src/lib/services/event-manager.service.ts +21 -0
  32. package/src/lib/services/file-manager.service.ts +6 -0
  33. package/src/lib/services/form-manager.service.ts +89 -0
  34. package/src/lib/services/icon-dictionary.service.ts +159 -0
  35. package/src/lib/tuain-ng-forms-lib.module.ts +40 -0
  36. package/{public-api.d.ts → src/public-api.ts} +5 -0
  37. package/src/test.ts +27 -0
  38. package/tsconfig.lib.json +15 -0
  39. package/tsconfig.lib.prod.json +10 -0
  40. package/tsconfig.spec.json +17 -0
  41. package/esm2020/lib/classes/forms/action.mjs +0 -35
  42. package/esm2020/lib/classes/forms/element.mjs +0 -76
  43. package/esm2020/lib/classes/forms/field.mjs +0 -321
  44. package/esm2020/lib/classes/forms/form.constants.mjs +0 -26
  45. package/esm2020/lib/classes/forms/form.mjs +0 -422
  46. package/esm2020/lib/classes/forms/section.mjs +0 -132
  47. package/esm2020/lib/classes/forms/subsection.mjs +0 -70
  48. package/esm2020/lib/classes/forms/table/action.mjs +0 -22
  49. package/esm2020/lib/classes/forms/table/column.mjs +0 -61
  50. package/esm2020/lib/classes/forms/table/row-data.mjs +0 -111
  51. package/esm2020/lib/classes/forms/table/table.mjs +0 -372
  52. package/esm2020/lib/components/elements/action.component.mjs +0 -58
  53. package/esm2020/lib/components/elements/field.component.mjs +0 -90
  54. package/esm2020/lib/components/elements/layout/element.component.mjs +0 -31
  55. package/esm2020/lib/components/elements/layout/form-error.component.mjs +0 -20
  56. package/esm2020/lib/components/elements/layout/form-header.component.mjs +0 -30
  57. package/esm2020/lib/components/elements/layout/section.component.mjs +0 -22
  58. package/esm2020/lib/components/elements/layout/sub-section.component.mjs +0 -24
  59. package/esm2020/lib/components/elements/tables/table-record-action.component.mjs +0 -40
  60. package/esm2020/lib/components/elements/tables/table-record-field.component.mjs +0 -25
  61. package/esm2020/lib/components/elements/tables/table.component.mjs +0 -95
  62. package/esm2020/lib/components/forms/basic-form.mjs +0 -1425
  63. package/esm2020/lib/services/event-manager.service.mjs +0 -18
  64. package/esm2020/lib/services/file-manager.service.mjs +0 -6
  65. package/esm2020/lib/services/form-manager.service.mjs +0 -80
  66. package/esm2020/lib/tuain-ng-forms-lib.module.mjs +0 -73
  67. package/esm2020/public-api.mjs +0 -19
  68. package/esm2020/tuain-ng-forms-lib.mjs +0 -5
  69. package/fesm2015/tuain-ng-forms-lib.mjs +0 -3805
  70. package/fesm2015/tuain-ng-forms-lib.mjs.map +0 -1
  71. package/fesm2020/tuain-ng-forms-lib.mjs +0 -3636
  72. package/fesm2020/tuain-ng-forms-lib.mjs.map +0 -1
  73. package/lib/classes/forms/action.d.ts +0 -22
  74. package/lib/classes/forms/element.d.ts +0 -41
  75. package/lib/classes/forms/field.d.ts +0 -109
  76. package/lib/classes/forms/form.constants.d.ts +0 -25
  77. package/lib/classes/forms/form.d.ts +0 -134
  78. package/lib/classes/forms/section.d.ts +0 -39
  79. package/lib/classes/forms/subsection.d.ts +0 -26
  80. package/lib/classes/forms/table/action.d.ts +0 -20
  81. package/lib/classes/forms/table/column.d.ts +0 -33
  82. package/lib/classes/forms/table/row-data.d.ts +0 -14
  83. package/lib/classes/forms/table/table.d.ts +0 -100
  84. package/lib/components/elements/action.component.d.ts +0 -21
  85. package/lib/components/elements/field.component.d.ts +0 -43
  86. package/lib/components/elements/layout/element.component.d.ts +0 -14
  87. package/lib/components/elements/layout/form-error.component.d.ts +0 -8
  88. package/lib/components/elements/layout/form-header.component.d.ts +0 -12
  89. package/lib/components/elements/layout/section.component.d.ts +0 -10
  90. package/lib/components/elements/layout/sub-section.component.d.ts +0 -11
  91. package/lib/components/elements/tables/table-record-action.component.d.ts +0 -15
  92. package/lib/components/elements/tables/table-record-field.component.d.ts +0 -11
  93. package/lib/components/elements/tables/table.component.d.ts +0 -47
  94. package/lib/components/forms/basic-form.d.ts +0 -307
  95. package/lib/services/event-manager.service.d.ts +0 -9
  96. package/lib/services/file-manager.service.d.ts +0 -5
  97. package/lib/services/form-manager.service.d.ts +0 -28
  98. package/lib/tuain-ng-forms-lib.module.d.ts +0 -20
  99. package/tuain-ng-forms-lib.d.ts +0 -5
@@ -0,0 +1,438 @@
1
+ import { Subject } from 'rxjs';
2
+ import { elementTypes } from '../form.constants';
3
+ import { FormElement } from '../element';
4
+ import { RecordTableColumn } from './column';
5
+ import { TableAction } from './action';
6
+ import { TableRecordData } from './row-data';
7
+
8
+ const TABLE_SORT_ASCENDING = 'asc';
9
+ const TABLE_SORT_DESCENDING = 'desc';
10
+
11
+ export interface TableActionEvent {
12
+ actionCode: string;
13
+ recordId: any;
14
+ recordData: any;
15
+ }
16
+
17
+ export interface TableEvent {
18
+ tableCode: string;
19
+ actionCode: string;
20
+ actionDetail: any;
21
+ }
22
+
23
+ export class RecordTable extends FormElement {
24
+ private readonly _inlineActionTrigger = new Subject<TableEvent>();
25
+ private readonly _globalActionTrigger = new Subject<TableEvent>();
26
+ private readonly _recordSelectionTrigger = new Subject<TableEvent>();
27
+ private readonly _selectionActionTrigger = new Subject<TableEvent>();
28
+ private readonly _getDataTrigger = new Subject<TableEvent>();
29
+ private readonly _attributeChange = new Subject<any>();
30
+ private _tableColumnObj = {};
31
+ private _appendPages: boolean;
32
+ private _actions: TableAction[];
33
+ private _actionsObj = {};
34
+
35
+ // Mecanismos de filtrado nueva versión
36
+ private globalFilterStrings: string[] = [];
37
+ private selectedRecords: any;
38
+ private globalSearch: boolean;
39
+ private restrictedId: any;
40
+ private layout: string;
41
+
42
+ tableRecords: TableRecordData[];
43
+ tableRecordObj = {};
44
+ visibleRecords: TableRecordData[];
45
+ columns: RecordTableColumn[];
46
+ selectable: boolean;
47
+ selectionBackend: boolean;
48
+ selectionField: string;
49
+ allSelected = false;
50
+
51
+ tableCode: string;
52
+ tableTitle: string;
53
+ currentPage: number;
54
+ totalPages: number;
55
+ requestedPage: number;
56
+ recordsPerPage: number;
57
+ totalRecordsNumber: number;
58
+ recordsNumber: number;
59
+ sorting: any;
60
+
61
+ waiting: boolean;
62
+ clientPaging: boolean;
63
+ sortable: boolean;
64
+
65
+ constructor(tableReceived, formConfig) {
66
+ super(tableReceived, formConfig);
67
+ this.elementType = elementTypes.table;
68
+ this.waiting = false;
69
+ this.currentPage = 1;
70
+ this.totalPages = 1;
71
+ this.requestedPage = 1;
72
+ this.columns = [];
73
+ this._tableColumnObj = {};
74
+ this._actions = [];
75
+ this._actionsObj = {};
76
+ this.tableRecords = [];
77
+ this.globalSearch = false;
78
+ this.restrictedId = null;
79
+
80
+ this.tableTitle = tableReceived.tableTitle;
81
+ this._appendPages = tableReceived?.append ?? false;
82
+ this.selectable = tableReceived?.selectable ?? false;
83
+ this.selectionBackend = tableReceived?.selectionBackend ?? false;
84
+ this.sortable = tableReceived?.sortable ?? false;
85
+
86
+ this.setAttr('allSelected', false);
87
+ this.setAttr('tableCode', tableReceived.tableCode);
88
+ this.setAttr('clientPaging', tableReceived?.clientPaging ?? true);
89
+ this.setAttr('globalSearch', tableReceived?.simpleFilter ?? false);
90
+ this.setAttr('sorting', { columnName: '', direction: '' });
91
+ this.setAttr('recordsPerPage', formConfig.defaultRecordsPerPage);
92
+ this.setAttr('layout', '');
93
+
94
+ if (tableReceived.fields) {
95
+ const columns = [];
96
+ for (const columnReceived of tableReceived.fields) {
97
+ const columnDefinition = new RecordTableColumn(columnReceived, this._formConfig);
98
+ columns.push(columnDefinition);
99
+ this._tableColumnObj[columnDefinition.fieldCode] = columnDefinition;
100
+ }
101
+ this.setAttr('columns', columns);
102
+ }
103
+ if (tableReceived.actions) {
104
+ const tableActions = tableReceived.actions.map(objDef => {
105
+ let visibleStates = objDef.visibleStates;
106
+ let enabledStates = objDef.enabledStates;
107
+ if (!visibleStates) {
108
+ visibleStates = (objDef.actionModes || '').split(',')
109
+ .map(state => state.trim())
110
+ .filter(state => state.length > 0);
111
+ enabledStates = (objDef.actionModes || '').split(',')
112
+ .map(state => state.trim())
113
+ .filter(state => state.length > 0);
114
+ }
115
+ return { ...objDef, visibleStates, enabledStates };
116
+ });
117
+ for (const actionReceived of tableActions) {
118
+ const inlineAction = new TableAction(actionReceived);
119
+ this._actions.push(inlineAction);
120
+ this._actionsObj[inlineAction.actionCode] = inlineAction;
121
+ }
122
+ }
123
+ this.selectionField = (this.selectable) ? tableReceived?.selectionField : null;
124
+ // Filtros predefinidos en el formulario
125
+ if (tableReceived.filters) {
126
+ for (let index = 0; index < tableReceived.filters.length; index++) {
127
+ this.addFilterDefinition(tableReceived.filters[index].fieldCode, tableReceived.filters[index]);
128
+ }
129
+ }
130
+ }
131
+
132
+ get columnNames() { return Object.keys(this._tableColumnObj); }
133
+ get inlineActionTrigger() { return this._inlineActionTrigger; }
134
+ get globalActionTrigger() { return this._globalActionTrigger; }
135
+ get selectionActionTrigger() { return this._selectionActionTrigger; }
136
+ get recordSelectionTrigger() { return this._recordSelectionTrigger; }
137
+ get getDataTrigger() { return this._getDataTrigger; }
138
+ get attributeChange() { return this._attributeChange; }
139
+
140
+ getLayout() { return this.layout; }
141
+ setLayout(layout) { this.setAttr('layout', layout); }
142
+ hasActions() { return (this._actions.length > 0); }
143
+ getSelectedRecords() { return this.tableRecords.filter(rec => rec.selected).map(rec => rec.recordId); }
144
+ activateGlobalSearch() { this.globalSearch = true; }
145
+ inactivateGlobalSearch() { this.globalSearch = false; }
146
+ columnDefinition(fieldCode) { return this._tableColumnObj[fieldCode]; }
147
+ putOnWait() { this.waiting = true; }
148
+ freeWaiting() { this.waiting = false; }
149
+
150
+ setAttr(name: string, value: any) {
151
+ this[name] = value;
152
+ if (this._formConfig.monitoredTableAttributes.includes(name)) {
153
+ this._attributeChange.next({ name, value });
154
+ }
155
+ }
156
+
157
+ notifyGlobalAction(actionCode) {
158
+ const tableEvent: TableEvent = {
159
+ tableCode: this.tableCode,
160
+ actionCode,
161
+ actionDetail: null
162
+ };
163
+ this._globalActionTrigger.next(tableEvent);
164
+ }
165
+
166
+ notifyInlineAction(tableActionEvent: TableActionEvent) {
167
+ const tableEvent: TableEvent = {
168
+ tableCode: this.tableCode,
169
+ actionCode: tableActionEvent.actionCode,
170
+ actionDetail: {
171
+ recordId: tableActionEvent.recordId,
172
+ recordData: tableActionEvent.recordData
173
+ }
174
+ };
175
+ this._inlineActionTrigger.next(tableEvent);
176
+ }
177
+
178
+ notifyRecordSelection(recordId) {
179
+ const record = this.getTableRecord(recordId);
180
+ if (!record) { return; }
181
+ record.toggleSelect();
182
+ const tableEvent: TableEvent = {
183
+ tableCode: this.tableCode,
184
+ actionCode: null,
185
+ actionDetail: {
186
+ recordId: record.recordId,
187
+ recordData: record.recordData
188
+ }
189
+ };
190
+ this.recordSelectionTrigger.next(tableEvent);
191
+ }
192
+
193
+ notifySelectionAction(actionCode) {
194
+ const tableEvent: TableEvent = {
195
+ tableCode: this.tableCode,
196
+ actionCode,
197
+ actionDetail: {
198
+ selectedRecords: this.selectedRecords
199
+ }
200
+ };
201
+ this._selectionActionTrigger.next(tableEvent);
202
+ }
203
+
204
+ notifyGetDataAction(requestedPage = null) {
205
+ this.updateVisibleRecords();
206
+ this.requestedPage = requestedPage || this.currentPage;
207
+ const tableEvent: TableEvent = {
208
+ tableCode: this.tableCode,
209
+ actionCode: null,
210
+ actionDetail: null,
211
+ };
212
+ this._getDataTrigger.next(tableEvent);
213
+ return null;
214
+ }
215
+
216
+ clean() {
217
+ this.tableRecords = [];
218
+ this.unSelectAll();
219
+ this.tableRecordObj = {};
220
+ this.updateVisibleRecords();
221
+ }
222
+
223
+ selectAll() {
224
+ this.setAttr('allSelected', true);
225
+ this.tableRecords.forEach(record => record.select());
226
+ this.setAttr('selectedRecords', this.getSelectedRecords());
227
+ return true;
228
+
229
+ }
230
+
231
+ unSelectAll() {
232
+ this.setAttr('allSelected', false);
233
+ this.tableRecords.forEach(record => record.unselect());
234
+ this.setAttr('selectedRecords', this.getSelectedRecords());
235
+ return true;
236
+ }
237
+
238
+ setTableRecords(tableRecords, append) {
239
+ if (!append) { this.clean(); }
240
+ const newRecordsObj = { ...this.tableRecordObj };
241
+ const newRecords = [...this.tableRecords];
242
+ for (const tableRecord of tableRecords) {
243
+ const recordReceived: TableRecordData = new TableRecordData(tableRecord, this.columns, this.selectionField);
244
+ const recordIdKey = recordReceived.recordIdKey;
245
+ newRecords.push(recordReceived);
246
+ newRecordsObj[recordIdKey] = recordReceived;
247
+ }
248
+ this.tableRecords = newRecords;
249
+ this.setAttr('selectedRecords', this.getSelectedRecords());
250
+ this.tableRecordObj = newRecordsObj;
251
+ this.updateVisibleRecords();
252
+ }
253
+
254
+ appendRecords(records) { this.setTableRecords(records, true); }
255
+ replaceRecords(records) { this.setTableRecords(records, false); }
256
+
257
+ changePage(requestedPage) {
258
+ if (this.clientPaging) {
259
+ this.setAttr('currentPage', requestedPage);
260
+ this.updateVisibleRecords();
261
+ } else {
262
+ this.notifyGetDataAction(requestedPage);
263
+ }
264
+ }
265
+
266
+ updateVisibleRecords() {
267
+ // updateView const changeViewAttributes = ['currentPage', 'recordsPerPage', 'sorting'];
268
+ let visibleRecords: any[];
269
+ if (this.clientPaging) {
270
+ let filteredRecords = this.getFilteredRecords();
271
+ this.setAttr('totalRecordsNumber', filteredRecords.length);
272
+ visibleRecords = filteredRecords.slice((this.currentPage - 1) * this.recordsPerPage,
273
+ (this.currentPage - 1) * this.recordsPerPage + this.recordsPerPage);
274
+ } else {
275
+ visibleRecords = this.tableRecords;
276
+ }
277
+ this.setAttr('visibleRecords', visibleRecords);
278
+ }
279
+
280
+ updateFromServer(tableReceived) {
281
+ this.requestedPage = 1;
282
+ this.clean();
283
+ this.visible = tableReceived?.visible || true;
284
+ this.totalPages = tableReceived.totalPages || 1;
285
+ this.recordsNumber = tableReceived.recordsNumber;
286
+ this.setAttr('currentPage', +tableReceived?.currentPage ?? 1);
287
+ this.setAttr('recordsPerPage', +tableReceived.recordsPerPage);
288
+ this.setAttr('totalRecordsNumber', (this.clientPaging) ? tableReceived.tableRecords.length : +tableReceived.totalRecordsNumber);
289
+ this.setAttr('sorting', {
290
+ columnName: tableReceived.sortingColumn || '',
291
+ direction: tableReceived.sortingDirection || ''
292
+ });
293
+ this.waiting = false;
294
+ if (this._appendPages) {
295
+ this.replaceRecords(tableReceived.tableRecords);
296
+ } else {
297
+ this.appendRecords(tableReceived.tableRecords);
298
+ }
299
+ this.updateVisibleRecords();
300
+ }
301
+
302
+ getTableRecord(recordId) {
303
+ const recordIdKey = (typeof recordId === 'object') ? JSON.stringify(recordId) : recordId;
304
+ return (this.tableRecordObj && recordId && this.tableRecordObj[recordId])
305
+ ? this.tableRecordObj[recordId] : null;
306
+ }
307
+
308
+ getAction(actionCode) {
309
+ return (this._actionsObj && actionCode && this._actionsObj[actionCode])
310
+ ? this._actionsObj[actionCode] : null;
311
+ }
312
+
313
+ getActions(actionClass: string = this._formConfig.tableActions.inline, actionTypes: string[] = null) {
314
+ return this._actions.filter(actionDef => {
315
+ const typeIncluded = (actionTypes) ? actionTypes.includes(actionDef.actionType) : true;
316
+ return actionDef.actionClass === actionClass && typeIncluded;
317
+ });
318
+ }
319
+
320
+ // Filtros
321
+
322
+ setFilterById(id) {
323
+ if (this.restrictedId === id) { return; }
324
+ this.restrictedId = id;
325
+ this.updateVisibleRecords();
326
+ }
327
+
328
+ cleanIdFilter() {
329
+ if (this.restrictedId === null) { return; }
330
+ this.restrictedId = null;
331
+ this.updateVisibleRecords();
332
+ }
333
+
334
+ setGlobalFilterString(text) {
335
+ this.globalFilterStrings = text.split(' ').filter(t => t && t.trim().length > 0).map(t => t.trim()) ?? [];
336
+ if (this.clientPaging) {
337
+ this.changePage(1);
338
+ }
339
+ }
340
+
341
+ addFilterDefinition(columnName, filterDefinition) {
342
+ const tableColumn = this.columnDefinition(columnName);
343
+ tableColumn && tableColumn.addFilterDefinition(filterDefinition);
344
+ }
345
+
346
+ getFilteredRecords() {
347
+ let filteredRecords = this.tableRecords;
348
+ if (this.restrictedId) {
349
+ filteredRecords = filteredRecords.filter(record => record.recordId === this.restrictedId);
350
+ }
351
+ if (this.globalFilterStrings.length > 0) {
352
+ filteredRecords = filteredRecords.filter(record => record.hasPattern(this.globalFilterStrings, this._tableColumnObj));
353
+ }
354
+ const columnFilters = this.columns.filter(column => column.filter).map(column => column.filter);
355
+ if (columnFilters.length > 0) {
356
+ filteredRecords = filteredRecords.filter(record => record.hasCondition(columnFilters));
357
+ }
358
+ return filteredRecords;
359
+ }
360
+
361
+ getColumnFilter(columnName: string) {
362
+ const tableColumn = this.columnDefinition(columnName);
363
+ return tableColumn?.filter ?? null;
364
+ }
365
+
366
+ addColumnFilter(columnName: string, columnValues: any | any[], operator: string = null) {
367
+ const tableColumn = this.columnDefinition(columnName);
368
+ const columnFilterDefinition = tableColumn?.filterDefinition ?? null;
369
+ if (!columnFilterDefinition) {
370
+ return null;
371
+ }
372
+ tableColumn && tableColumn.addFilter(columnValues, operator);
373
+ this.updateVisibleRecords();
374
+ }
375
+
376
+ removeColumnFilter(columnName: string) {
377
+ const tableColumn = this.columnDefinition(columnName);
378
+ tableColumn && tableColumn.removeFilter();
379
+ this.updateVisibleRecords();
380
+ }
381
+
382
+ get currentFilter() {
383
+ const compactFilter: any = {
384
+ simpleFilterWords: this.globalFilterStrings,
385
+ advancedFilter: [],
386
+ };
387
+ const columnFilters = this.columns.filter(column => column.filter).map(column => column.filter);
388
+ for (let index = 0; index < columnFilters.length; index++) {
389
+ const columnFilter = columnFilters[index];
390
+ compactFilter.advancedFilter.push({
391
+ fieldCode: columnFilter.fieldCode,
392
+ operator: columnFilter.operator,
393
+ fieldValue1: columnFilter.values[0],
394
+ fieldValue2: columnFilter.values[1],
395
+ });
396
+ }
397
+ return compactFilter;
398
+ }
399
+
400
+ // Ordenamiento de registros local
401
+
402
+ sort(columnName, direction) {
403
+ this.setRequiredOrder(columnName, direction);
404
+ if (this.clientPaging) {
405
+ this.localSortData()
406
+ } else {
407
+ this.notifyGetDataAction();
408
+ }
409
+ }
410
+
411
+ setRequiredOrder(columnField, direction = null) {
412
+ this.setAttr('sorting', {
413
+ columnName: columnField,
414
+ direction: (direction === 'ascend') ? TABLE_SORT_ASCENDING : TABLE_SORT_DESCENDING,
415
+ });
416
+ }
417
+
418
+ localSortData() {
419
+ if (!this.sorting.columnName || !this.sorting.direction) { return; }
420
+ this.tableRecords.sort((a, b) => this.recordCompare(a, b, this.sorting.columnName, this.sorting.direction));
421
+ //this.unSelectAll();
422
+ this.updateVisibleRecords();
423
+ }
424
+
425
+ recordCompare(recordA: TableRecordData, recordB: TableRecordData, columnCompare, direction) {
426
+ const recordAValue = recordA.getFieldValue(columnCompare);
427
+ const recordBValue = recordB.getFieldValue(columnCompare);
428
+ const recordAColumn = isNaN(recordAValue) ? recordAValue.toLocaleLowerCase() : recordAValue;
429
+ const recordBColumn = isNaN(recordBValue) ? recordBValue.toLocaleLowerCase() : recordBValue;
430
+ let result = 0;
431
+ if (recordAColumn < recordBColumn) {
432
+ result = -1;
433
+ } else if (recordAColumn > recordBColumn) {
434
+ result = 1;
435
+ }
436
+ return direction === TABLE_SORT_ASCENDING ? result : -result;
437
+ }
438
+ }
@@ -0,0 +1,53 @@
1
+ import { Component, Input, OnInit } from '@angular/core';
2
+ import { FormAction } from '../../classes/forms/action';
3
+
4
+ @Component({
5
+ selector: 'lib-action',
6
+ template: `<ng-content></ng-content>`
7
+ })
8
+
9
+ export class ActionComponent implements OnInit {
10
+ formConfig: any;
11
+ inProgress: boolean;
12
+ @Input() action: FormAction;
13
+ @Input() busy: any;
14
+ @Input() relatedField: any;
15
+ @Input() state: any;
16
+
17
+ @Input() style = 'primary';
18
+ @Input() showLabel = true;
19
+
20
+ ngOnInit() {
21
+ this.formConfig = this.action?._formConfig;
22
+ this.start();
23
+ }
24
+
25
+ start() { }
26
+
27
+ activate() {
28
+ if (this.action?.notifyActivation) {
29
+ this.action.notifyActivation();
30
+ }
31
+ }
32
+
33
+ visibleOnRestriction() {
34
+ if (!this.action?.restrictedOnField) {
35
+ return true;
36
+ }
37
+ if ((this.action?.restrictedOnOperator === '=='
38
+ && this.relatedField === this.action?.restrictedOnValue)
39
+ || (this.action?.restrictedOnOperator === '!='
40
+ && this.relatedField !== this.action?.restrictedOnValue)) {
41
+ return true;
42
+ }
43
+ return false;
44
+ }
45
+
46
+ get visible() {
47
+ return this.action?.visibleOn(this.state) && this.visibleOnRestriction();
48
+ }
49
+
50
+ get disabled() {
51
+ return !(this.action?.enabledOn(this.state));
52
+ }
53
+ }
@@ -0,0 +1,118 @@
1
+ import { Component, OnInit, Input } from '@angular/core';
2
+ import { FieldDescriptor } from '../../classes/forms/field';
3
+
4
+ const VALUE = 'value';
5
+ const FOCUS = 'focus';
6
+ @Component({
7
+ selector: 'lib-field',
8
+ template: `<ng-content></ng-content>`
9
+ })
10
+ export class FieldComponent implements OnInit {
11
+ formConfig: any;
12
+ // Atributos obtenidos estáticamente
13
+ code: string;
14
+ value: any;
15
+ fieldInfo: string;
16
+ fieldAlignment: string;
17
+ tooltipText: string;
18
+
19
+ // Atributos actualizados por subscripción
20
+ maxLength: any;
21
+ minValue: any;
22
+ maxValue: any;
23
+ onValidation: any;
24
+ captureType: any;
25
+ title: any;
26
+ type: any;
27
+ visibleLabel: any;
28
+ required: any;
29
+ options: any;
30
+
31
+ errorType: any;
32
+ errorCode: any;
33
+ errorMessage: any;
34
+
35
+ @Input() field: FieldDescriptor;
36
+ @Input() state: any;
37
+
38
+ ngOnInit() {
39
+ if (this.field) {
40
+ this.formConfig = this.field?._formConfig;
41
+ // Inicialización
42
+ const mapping = Object.entries(this.formConfig.componentFieldAttrMap);
43
+ for (let index = 0; index < mapping.length; index++) {
44
+ const [fieldAttr1, compAttr1] = mapping[index];
45
+ const compAttr = compAttr1.toString();
46
+ const fieldAttr = fieldAttr1.toString();
47
+ const attributeValue = this.field?.[fieldAttr]
48
+ this.dafaultProcessFieldChange(compAttr, attributeValue);
49
+ this.processFieldChange(compAttr, attributeValue);
50
+ }
51
+ // Subscripción a cambios en atributos
52
+ this.field.attributeChange.subscribe(event => {
53
+ const { name: fieldAttr, value } = event;
54
+ const compAttr = this.formConfig.componentFieldAttrMap[fieldAttr];
55
+ this.dafaultProcessFieldChange(compAttr, value);
56
+ this.processFieldChange(compAttr, value);
57
+ });
58
+ }
59
+ this.start();
60
+ }
61
+
62
+ dafaultProcessFieldChange(attribute: string, value?: any) {
63
+ if (attribute === VALUE) {
64
+ this.updateValue();
65
+ } else if (attribute === FOCUS) {
66
+ this.focus();
67
+ } else {
68
+ this[attribute] = value;
69
+ }
70
+ }
71
+
72
+ processFieldChange(attribute: string, value?: any) { }
73
+ start() { }
74
+ focus() { }
75
+
76
+ updateObject() {
77
+ this.field.setValue(this.value);
78
+ }
79
+
80
+ inputChanged() {
81
+ this.field.setValue(this.value);
82
+ this.onChangeContent();
83
+ }
84
+
85
+ inputTyped() {
86
+ this.field.setValue(this.value);
87
+ this.onInputChange();
88
+ }
89
+
90
+ updateValue() {
91
+ this.value = this.field.getValue();
92
+ }
93
+
94
+ onInputChange() {
95
+ setTimeout(() => this.field.notifyEditionPartial(), 50);
96
+ }
97
+
98
+ onChangeContent() {
99
+ setTimeout(() => this.field.notifyEditionFinish(), 50);
100
+ }
101
+
102
+ onShowInfo(detail = null) {
103
+ setTimeout(() => this.field.notifyEditionDetailRequest(detail), 50);
104
+ }
105
+
106
+ numberInputValidation(event) {
107
+ const k = event.charCode;
108
+ return (k > 47 && k < 58);
109
+ }
110
+
111
+ get visible() {
112
+ return this.field?.visibleOn(this.state);
113
+ }
114
+
115
+ get disabled() {
116
+ return !this.field?.enabledOn(this.state);
117
+ }
118
+ }
@@ -0,0 +1,28 @@
1
+ import { Component, Input, OnInit } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'lib-element',
5
+ template: `<ng-content></ng-content>`
6
+ })
7
+ export class ElementComponent implements OnInit {
8
+ formConfig: any;
9
+
10
+ @Input() element: any;
11
+ @Input() form: any;
12
+ @Input() state: any;
13
+
14
+ ngOnInit() {
15
+ this.formConfig = this.element?._formConfig;
16
+ this.start();
17
+ }
18
+
19
+ start() { }
20
+
21
+ get visible() {
22
+ return this.element?.visibleOn(this.state);
23
+ }
24
+
25
+ get disabled() {
26
+ return !this.element?.enabledOn(this.state);
27
+ }
28
+ }
@@ -0,0 +1,11 @@
1
+ import { Component, Input } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'lib-form-error',
5
+ template: `<ng-content></ng-content>`
6
+ })
7
+ export class FormErrorComponent {
8
+ @Input() errorTitle: any;
9
+ @Input() errorMessage: any;
10
+ @Input() errorType: any;
11
+ }
@@ -0,0 +1,17 @@
1
+ import { Component, Input, Output, EventEmitter } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'lib-form-header',
5
+ template: `<ng-content></ng-content>`
6
+ })
7
+ export class FormHeaderComponent {
8
+ @Input() formManager: any;
9
+ @Input() goBackAction: boolean;
10
+ @Input() showTitle: any;
11
+ @Input() headerActions: any;
12
+ @Output() goBackEvent: EventEmitter<object> = new EventEmitter<object>();
13
+
14
+ goBackForm() {
15
+ this.goBackEvent.emit();
16
+ }
17
+ }
@@ -0,0 +1,16 @@
1
+ import { Component, Input, OnInit } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'lib-section',
5
+ template: `<ng-content></ng-content>`
6
+ })
7
+ export class SectionComponent implements OnInit {
8
+ @Input() section: any;
9
+ @Input() formManager: any;
10
+
11
+ ngOnInit() {
12
+ this.start();
13
+ }
14
+
15
+ start() { }
16
+ }
@@ -0,0 +1,17 @@
1
+ import { Component, Input, OnInit } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'lib-subsection',
5
+ template: `<ng-content></ng-content>`
6
+ })
7
+ export class SubSectionComponent implements OnInit {
8
+ @Input() subSection: any;
9
+ @Input() showHeader: any;
10
+ @Input() formManager: any;
11
+
12
+ ngOnInit() {
13
+ this.start();
14
+ }
15
+
16
+ start() { }
17
+ }