tuain-ng-forms-lib 17.2.21 → 17.2.22

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 (106) 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.1-36f0ed04db-19480d6e03.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 +2 -16
  9. package/src/lib/classes/forms/action.ts +117 -0
  10. package/src/lib/classes/forms/element.ts +26 -0
  11. package/src/lib/classes/forms/field.ts +522 -0
  12. package/src/lib/classes/forms/form.constants.ts +28 -0
  13. package/src/lib/classes/forms/form.ts +692 -0
  14. package/src/lib/classes/forms/piece-propagate.ts +47 -0
  15. package/src/lib/classes/forms/piece.ts +164 -0
  16. package/src/lib/classes/forms/section.ts +165 -0
  17. package/src/lib/classes/forms/subsection.ts +109 -0
  18. package/src/lib/classes/forms/table/action.ts +41 -0
  19. package/src/lib/classes/forms/table/column.ts +94 -0
  20. package/src/lib/classes/forms/table/row-data.ts +121 -0
  21. package/src/lib/classes/forms/table/table.ts +582 -0
  22. package/src/lib/components/elements/action.component.ts +70 -0
  23. package/src/lib/components/elements/field.component.ts +115 -0
  24. package/src/lib/components/elements/layout/element.component.ts +14 -0
  25. package/src/lib/components/elements/layout/form-error.component.ts +11 -0
  26. package/src/lib/components/elements/layout/form-header.component.ts +14 -0
  27. package/src/lib/components/elements/layout/piece.component.ts +60 -0
  28. package/src/lib/components/elements/layout/section.component.ts +52 -0
  29. package/src/lib/components/elements/layout/sub-section.component.ts +52 -0
  30. package/src/lib/components/elements/tables/table-record-action.component.ts +66 -0
  31. package/src/lib/components/elements/tables/table-record-field.component.ts +20 -0
  32. package/src/lib/components/elements/tables/table.component.ts +112 -0
  33. package/src/lib/components/forms/basic-form.ts +1464 -0
  34. package/src/lib/services/event-manager.service.ts +45 -0
  35. package/src/lib/services/file-manager.service.ts +7 -0
  36. package/src/lib/services/form-manager.service.ts +89 -0
  37. package/src/lib/services/icon-dictionary.service.ts +159 -0
  38. package/src/lib/tuain-ng-forms-lib.module.ts +40 -0
  39. package/{public-api.d.ts → src/public-api.ts} +5 -0
  40. package/src/test.ts +27 -0
  41. package/tsconfig.lib.json +15 -0
  42. package/tsconfig.lib.prod.json +10 -0
  43. package/tsconfig.spec.json +17 -0
  44. package/esm2022/lib/classes/forms/action.mjs +0 -106
  45. package/esm2022/lib/classes/forms/element.mjs +0 -25
  46. package/esm2022/lib/classes/forms/field.mjs +0 -474
  47. package/esm2022/lib/classes/forms/form.constants.mjs +0 -26
  48. package/esm2022/lib/classes/forms/form.mjs +0 -608
  49. package/esm2022/lib/classes/forms/piece-propagate.mjs +0 -39
  50. package/esm2022/lib/classes/forms/piece.mjs +0 -134
  51. package/esm2022/lib/classes/forms/section.mjs +0 -151
  52. package/esm2022/lib/classes/forms/subsection.mjs +0 -99
  53. package/esm2022/lib/classes/forms/table/action.mjs +0 -38
  54. package/esm2022/lib/classes/forms/table/column.mjs +0 -74
  55. package/esm2022/lib/classes/forms/table/row-data.mjs +0 -116
  56. package/esm2022/lib/classes/forms/table/table.mjs +0 -535
  57. package/esm2022/lib/components/elements/action.component.mjs +0 -70
  58. package/esm2022/lib/components/elements/field.component.mjs +0 -115
  59. package/esm2022/lib/components/elements/layout/element.component.mjs +0 -21
  60. package/esm2022/lib/components/elements/layout/form-error.component.mjs +0 -23
  61. package/esm2022/lib/components/elements/layout/form-header.component.mjs +0 -23
  62. package/esm2022/lib/components/elements/layout/piece.component.mjs +0 -64
  63. package/esm2022/lib/components/elements/layout/section.component.mjs +0 -56
  64. package/esm2022/lib/components/elements/layout/sub-section.component.mjs +0 -56
  65. package/esm2022/lib/components/elements/tables/table-record-action.component.mjs +0 -72
  66. package/esm2022/lib/components/elements/tables/table-record-field.component.mjs +0 -31
  67. package/esm2022/lib/components/elements/tables/table.component.mjs +0 -109
  68. package/esm2022/lib/components/forms/basic-form.mjs +0 -1399
  69. package/esm2022/lib/services/event-manager.service.mjs +0 -43
  70. package/esm2022/lib/services/file-manager.service.mjs +0 -7
  71. package/esm2022/lib/services/form-manager.service.mjs +0 -81
  72. package/esm2022/lib/tuain-ng-forms-lib.module.mjs +0 -71
  73. package/esm2022/public-api.mjs +0 -19
  74. package/esm2022/tuain-ng-forms-lib.mjs +0 -5
  75. package/fesm2022/tuain-ng-forms-lib.mjs +0 -4593
  76. package/fesm2022/tuain-ng-forms-lib.mjs.map +0 -1
  77. package/index.d.ts +0 -5
  78. package/lib/classes/forms/action.d.ts +0 -40
  79. package/lib/classes/forms/element.d.ts +0 -9
  80. package/lib/classes/forms/field.d.ts +0 -206
  81. package/lib/classes/forms/form.constants.d.ts +0 -25
  82. package/lib/classes/forms/form.d.ts +0 -232
  83. package/lib/classes/forms/piece-propagate.d.ts +0 -13
  84. package/lib/classes/forms/piece.d.ts +0 -51
  85. package/lib/classes/forms/section.d.ts +0 -43
  86. package/lib/classes/forms/subsection.d.ts +0 -42
  87. package/lib/classes/forms/table/action.d.ts +0 -16
  88. package/lib/classes/forms/table/column.d.ts +0 -33
  89. package/lib/classes/forms/table/row-data.d.ts +0 -14
  90. package/lib/classes/forms/table/table.d.ts +0 -145
  91. package/lib/components/elements/action.component.d.ts +0 -22
  92. package/lib/components/elements/field.component.d.ts +0 -47
  93. package/lib/components/elements/layout/element.component.d.ts +0 -8
  94. package/lib/components/elements/layout/form-error.component.d.ts +0 -8
  95. package/lib/components/elements/layout/form-header.component.d.ts +0 -9
  96. package/lib/components/elements/layout/piece.component.d.ts +0 -18
  97. package/lib/components/elements/layout/section.component.d.ts +0 -13
  98. package/lib/components/elements/layout/sub-section.component.d.ts +0 -13
  99. package/lib/components/elements/tables/table-record-action.component.d.ts +0 -18
  100. package/lib/components/elements/tables/table-record-field.component.d.ts +0 -12
  101. package/lib/components/elements/tables/table.component.d.ts +0 -44
  102. package/lib/components/forms/basic-form.d.ts +0 -256
  103. package/lib/services/event-manager.service.d.ts +0 -11
  104. package/lib/services/file-manager.service.d.ts +0 -6
  105. package/lib/services/form-manager.service.d.ts +0 -28
  106. package/lib/tuain-ng-forms-lib.module.d.ts +0 -20
@@ -0,0 +1,692 @@
1
+ import { Subject } from 'rxjs';
2
+ import { FormAction } from './action';
3
+ import { FieldDescriptor, FieldOption } from './field';
4
+ import { RecordTable } from './table/table';
5
+ import { RecordFormSection } from './section';
6
+ import { RecordFormSubSection } from './subsection';
7
+ import { NO_ERROR, HEADER } from './form.constants';
8
+ import { TableRecordData } from './table/row-data';
9
+
10
+ const ACTIVE = 'active';
11
+ const SHOW = 'show';
12
+ const HIDE = 'hide';
13
+ const ENABLE = 'enable';
14
+ const DISABLE = 'disable';
15
+ const CLEAN = 'clean';
16
+
17
+ const alwaysVisible = 'ALWAYS';
18
+ const neverVisible = 'NONE';
19
+ const onStatesVisible = 'ONSTATES';
20
+ interface Transition {
21
+ name: string;
22
+ source: string;
23
+ destination: string;
24
+ }
25
+
26
+ interface StateFlow {
27
+ defaultState: string;
28
+ states: string[];
29
+ stateDescriptions: string[];
30
+ transitions: Transition[];
31
+ }
32
+
33
+ export interface FieldPayload {
34
+ fieldCode: string;
35
+ fieldValue: any;
36
+ editable: boolean;
37
+ visible: boolean;
38
+ required: boolean;
39
+ fieldOptions: string,
40
+ }
41
+
42
+ export interface TablePayload {
43
+ tableCode: string;
44
+ visible: boolean;
45
+ currentPage: number;
46
+ requestedPage: number;
47
+ recordsPerPage: number;
48
+ currentFilter: any,
49
+ sortingColumn: string;
50
+ sortingDirection: string;
51
+ }
52
+
53
+ interface FormPayload {
54
+ fields: FieldPayload[],
55
+ tables: TablePayload[],
56
+ }
57
+
58
+ export class FormStructureAndData {
59
+ private readonly _stateChange = new Subject<any>();
60
+ private _immutableData = {};
61
+ private _extraInfo = {};
62
+ private _exclusiveSectionsByAttr = {};
63
+
64
+ protected loadInitialData: boolean = true;
65
+ protected subject: string | null = null;
66
+ protected stateFlow: StateFlow;
67
+ protected fields = {};
68
+ protected actions = {};
69
+ protected tables = {};
70
+ protected sections = {};
71
+ protected fieldArray: FieldDescriptor[];
72
+ protected actionArray: FormAction[];
73
+ protected tableArray: RecordTable[];
74
+ protected sectionArray: RecordFormSection[];
75
+
76
+ public customAttributes: any = {};
77
+ formConfig: any;
78
+ state: string;
79
+ name: string = '';
80
+ title: string = '';
81
+
82
+ constructor() {
83
+ this.state = '';
84
+ this.actionArray = [];
85
+ this.fieldArray = [];
86
+ this.tableArray = [];
87
+ this.sectionArray = [];
88
+ this.stateFlow = {
89
+ defaultState: '',
90
+ states: [],
91
+ stateDescriptions: [],
92
+ transitions: [],
93
+ };
94
+ }
95
+
96
+ setConfig(formConfig) {
97
+ this.formConfig = formConfig;
98
+ }
99
+
100
+ cleanForm() {
101
+ this.actionArray = [];
102
+ this.fieldArray = [];
103
+ this.tableArray = [];
104
+ this.sectionArray = [];
105
+ this.stateFlow = {
106
+ defaultState: '',
107
+ states: [],
108
+ stateDescriptions: [],
109
+ transitions: [],
110
+ };
111
+ }
112
+
113
+ loadDefinition(definitionReceived) {
114
+ this.state = '';
115
+ let allStates = [];
116
+ this.cleanForm();
117
+ if (!definitionReceived) { return; }
118
+ const { form = {} } = definitionReceived;
119
+ this.name = this.name ?? form.formCode;
120
+ this.title = form.formTitle ?? this.name;
121
+ this.loadInitialData = form.loadInitialData ?? true;
122
+ allStates = definitionReceived?.states;
123
+ this.setStateFlow(definitionReceived?.states, definitionReceived?.transitions,
124
+ definitionReceived?.defaultState, definitionReceived?.stateDescriptions);
125
+ this.immutableData = definitionReceived.immutableData;
126
+ this.extraInfo = definitionReceived.extraInfo;
127
+ this.customAttributes = {};
128
+ if (definitionReceived?.customAttributes) {
129
+ this.setCustomAttributes(definitionReceived?.customAttributes);
130
+ }
131
+ if (definitionReceived.actions) {
132
+ const formActions = definitionReceived.actions.map(objDef => {
133
+ let visibleStates = objDef.visibleStates
134
+ ?? (objDef.actionModes?.split(',')?.map(state => state.trim())?.filter(state => state))
135
+ ?? [];
136
+ let enabledStates = objDef.enabledStates ?? objDef.editableStates ?? [];
137
+ if (!Array.isArray(visibleStates) && typeof visibleStates === 'string') {
138
+ visibleStates = (visibleStates === neverVisible) ? [] : allStates;
139
+ }
140
+ if (!Array.isArray(enabledStates) && typeof enabledStates === 'string') {
141
+ enabledStates = (enabledStates === neverVisible) ? [] : visibleStates;
142
+ }
143
+ enabledStates = enabledStates.filter(state => visibleStates.includes(state));
144
+ return { ...objDef, visibleStates, enabledStates };
145
+ });
146
+ for (const actionReceived of formActions) {
147
+ const globalAction = new FormAction(actionReceived, this.formConfig);
148
+ const globalActionCode = globalAction.actionCode;
149
+ if (globalActionCode) {
150
+ this.actionArray.push(globalAction);
151
+ this.actions[globalActionCode] = globalAction;
152
+ }
153
+ }
154
+ }
155
+
156
+ if (definitionReceived.fields) {
157
+ const formFields = definitionReceived.fields.map(objDef => {
158
+ let visibleStates = objDef.visibleStates
159
+ ?? (objDef.fieldModes?.split(',')?.map(state => state.trim())?.filter(state => state))
160
+ ?? [];
161
+ let enabledStates = objDef.enabledStates ?? objDef.editableStates ?? [];
162
+ if (!Array.isArray(visibleStates) && typeof visibleStates === 'string') {
163
+ visibleStates = (visibleStates === neverVisible) ? [] : allStates;
164
+ }
165
+ if (!Array.isArray(enabledStates) && typeof enabledStates === 'string') {
166
+ enabledStates = (enabledStates === neverVisible) ? [] : visibleStates;
167
+ }
168
+ enabledStates = enabledStates.filter(state => visibleStates.includes(state));
169
+ return { ...objDef, visibleStates, enabledStates };
170
+ });
171
+ for (const fieldReceived of formFields) {
172
+ const fieldToAdd = new FieldDescriptor(fieldReceived, this.formConfig);
173
+ const fieldCode = fieldToAdd.code;
174
+ if (fieldCode) {
175
+ this.fieldArray.push(fieldToAdd);
176
+ this.fields[fieldCode] = fieldToAdd;
177
+ }
178
+ }
179
+ }
180
+
181
+ if (definitionReceived.tables) {
182
+ const tables = definitionReceived.tables.map(objDef => {
183
+ let visibleStates = objDef.visibleStates
184
+ ?? (objDef.tableModes?.split(',')?.map(state => state.trim())?.filter(state => state))
185
+ ?? [];
186
+ let enabledStates = objDef.enabledStates ?? objDef.editableStates ?? [];
187
+ if (!Array.isArray(visibleStates) && typeof visibleStates === 'string') {
188
+ visibleStates = (visibleStates === neverVisible) ? [] : allStates;
189
+ }
190
+ if (!Array.isArray(enabledStates) && typeof enabledStates === 'string') {
191
+ enabledStates = (enabledStates === neverVisible) ? [] : visibleStates;
192
+ }
193
+ enabledStates = enabledStates.filter(state => visibleStates.includes(state));
194
+ return { ...objDef, visibleStates, enabledStates };
195
+ });
196
+ for (const tableReceived of tables) {
197
+ const tableToAdd = new RecordTable(tableReceived, this.formConfig);
198
+ const tableCode = tableToAdd.tableCode;
199
+ if (tableCode) {
200
+ this.tableArray.push(tableToAdd);
201
+ this.tables[tableCode] = tableToAdd;
202
+ }
203
+ }
204
+ }
205
+
206
+ if (definitionReceived.sections) {
207
+ const formSections = definitionReceived.sections.map(objDef => {
208
+ let visibleStates = objDef.visibleStates
209
+ ?? (objDef.sectionModes?.split(',')?.map(state => state.trim())?.filter(state => state))
210
+ ?? [];
211
+ if (!Array.isArray(visibleStates) && typeof visibleStates === 'string') {
212
+ visibleStates = (visibleStates === neverVisible) ? [] : allStates;
213
+ }
214
+ const subsections = objDef.subsections.map(subSecDef => {
215
+ let subSecVisibleStates = subSecDef.visibleStates ?? [];
216
+ if (!Array.isArray(subSecVisibleStates) && typeof subSecVisibleStates === 'string') {
217
+ subSecVisibleStates = (subSecVisibleStates === neverVisible) ? [] : allStates;
218
+ }
219
+ return { ...subSecDef, visibleStates: subSecVisibleStates };
220
+ });
221
+ return { ...objDef, subsections, visibleStates };
222
+ });
223
+ for (const sectionReceived of formSections) {
224
+ const sectionToAdd = new RecordFormSection(sectionReceived, this, this.formConfig);
225
+ const sectionCode = sectionToAdd.sectionCode;
226
+ if (sectionCode) {
227
+ this.sectionArray.push(sectionToAdd);
228
+ this.sections[sectionCode] = sectionToAdd;
229
+ }
230
+ }
231
+ }
232
+ }
233
+
234
+ // Estados
235
+ get defaultState(): string { return this.stateFlow.defaultState; }
236
+ get states(): any[] { return this.stateFlow.states; }
237
+ get stateDescriptions(): any[] { return this.stateFlow.stateDescriptions; }
238
+ supportState(state: string = ''): boolean { return (!!state && this.stateFlow.states?.includes(state)); }
239
+
240
+ getNextStates(): string[] {
241
+ return this.stateFlow.transitions.filter(trns => trns.source === this.state)
242
+ .map(trns => trns.destination);
243
+ }
244
+
245
+ changeState(newState: string): boolean {
246
+ const currentState = this.state;
247
+ if (!newState || !this.supportState(newState) || currentState === newState) {
248
+ return false;
249
+ }
250
+ if (!this.state) {
251
+ this.state = newState;
252
+ } else {
253
+ const transitionToChange = this.stateFlow.transitions.find(trns =>
254
+ trns.source === this.state && trns.destination === newState);
255
+ if (transitionToChange) {
256
+ this.state = newState;
257
+ }
258
+ }
259
+ this._stateChange.next({ state: this.state });
260
+ return (this.state === newState);
261
+ }
262
+
263
+ get stateChange() { return this._stateChange.asObservable(); }
264
+
265
+ setStateFlow(states?, transitions?, defaultState?: string, stateDescriptions = []): void {
266
+ this.stateFlow.states = states;
267
+ this.stateFlow.stateDescriptions = stateDescriptions;
268
+ this.stateFlow.defaultState = defaultState || this.stateFlow.states[0];
269
+ this.stateFlow.transitions = transitions.map(transition => {
270
+ const name = transition.name;
271
+ const source = (this.stateFlow.states.includes(transition.source)) ? transition.source : '';
272
+ const destination = (this.stateFlow.states.includes(transition.destination)) ? transition.destination : '';
273
+ return { name, source, destination };
274
+ }).filter(item => item.name && item.source && item.destination);
275
+ }
276
+
277
+ // immutable Data
278
+ getImmutableElement(name: string): any { return this._immutableData?.[name]?.value ?? null; }
279
+ set immutableData(immutableData) { Object.assign(this._immutableData, immutableData); }
280
+ get immutableData(): any { return JSON.parse(JSON.stringify(this._immutableData)); }
281
+
282
+ // extra Info
283
+ getExtraInfo(name: string): any { return this._extraInfo?.[name]?.value ?? null; }
284
+ set extraInfo(extraInfo) { Object.assign(this._extraInfo, extraInfo); }
285
+ get extraInfo(): any { return JSON.parse(JSON.stringify(this._extraInfo)); }
286
+
287
+ // Custom Attributes
288
+ getCustomAttribute(name: string): any { return this.customAttributes?.[name] ?? null; }
289
+ setCustomAttribute(name: string, value: any): void { if (name) { this.customAttributes[name] = value; } }
290
+ setCustomAttributes(attributes: any): FormStructureAndData {
291
+ if (attributes && typeof attributes === 'object') {
292
+ Object.entries(attributes).forEach(([name, value]) => {
293
+ this.setCustomAttribute(name, value);
294
+ });
295
+ }
296
+ return this;
297
+ }
298
+
299
+ // Fields
300
+ get fieldNames(): string[] { return this.getFieldNames(); }
301
+ getFields(): FieldDescriptor[] { return this.fieldArray; }
302
+ getFieldNames(): string[] { return this.fieldArray.map(field => field.code); }
303
+ getField(code: string): FieldDescriptor { return (code && this.fields?.[code]) ? this.fields[code] : null; }
304
+ enableField(code: string): void { this.getField(code)?.enable(); }
305
+ disableField(code: string): void { this.getField(code)?.disable(); }
306
+ getFieldValue(code: string): any { return this.getField(code)?.value; }
307
+ getFieldOptionText(code: string): any { return this.getField(code)?.optionText; }
308
+ getFieldOptions(code: string): FieldOption[] | null { return this.getField(code)?.options ?? null; }
309
+ setFieldValue(code: string, value: any): any { this.getField(code)?.setValue(value); }
310
+ setFieldError(code: string, errorCode: string, message: string, type: string = 'error'): any { this.getField(code)?.setError(errorCode, message, type); }
311
+ setFieldIntrinsicErrorMessage(code: string, message: string): any { this.getField(code)?.setIntrinsicErrorMessage(message); }
312
+
313
+ setFieldRequired(inputCodes: string[] | string | null, required: boolean): any {
314
+ const codes = this.getFieldSet(null, inputCodes ?? null);
315
+ for (const code of codes) {
316
+ try {
317
+ const field = this.getField(code) ?? null;
318
+ field && (field.required = required);
319
+ } catch (e) {
320
+ console.log(`Error modificando campo ${code}: ${e}`);
321
+ }
322
+ }
323
+ }
324
+
325
+ setFieldErrorMessage(code: string, message: string): any { this.getField(code)?.setErrorMessage(message); }
326
+
327
+ setFieldOptions(code: string, optionsArray: any[], idAttribute: string, valueAttribute: string | string[], saparator = '-'): any {
328
+ const field = this.getField(code);
329
+ if (!field) { return; }
330
+ const newOptions: any[] = [];
331
+ const numSeparators = (Array.isArray(valueAttribute)) ? (valueAttribute.length - 1) : 0;
332
+ for (let i = 0; i < optionsArray?.length; i++) {
333
+ const optionItem = optionsArray[i];
334
+ const fieldOptionId = optionItem?.[idAttribute];
335
+ let fieldOptionText = '';
336
+ if (Array.isArray(valueAttribute)) {
337
+ for (let index = 0; index < valueAttribute.length; index++) {
338
+ const textPart = valueAttribute[index];
339
+ fieldOptionText += (index < numSeparators)
340
+ ? `${optionItem?.[textPart]} ${saparator} ` : optionItem?.[textPart];
341
+ }
342
+ } else {
343
+ fieldOptionText = optionItem?.[valueAttribute];
344
+ }
345
+ if (fieldOptionId !== undefined && fieldOptionId !== null
346
+ && fieldOptionText !== undefined && fieldOptionText !== null) {
347
+ newOptions.push({ fieldOptionId, fieldOptionValue: fieldOptionText });
348
+ }
349
+ }
350
+ field.options = newOptions;
351
+ }
352
+
353
+ getFieldSet(filter, inputCodes: string[] | string | null, secCode?: string | null, subCode?: string | null): string[] {
354
+ let codes: any[] = [];
355
+ if (inputCodes) {
356
+ if (typeof inputCodes === 'string') {
357
+ codes = [inputCodes];
358
+ } else if (Array.isArray(inputCodes) && inputCodes.length > 0) {
359
+ codes = inputCodes ?? [];
360
+ }
361
+ } else if (secCode && !subCode) {
362
+ codes = this.getSection(secCode)?.getFieldNames() ?? [];
363
+ } else if (secCode && subCode) {
364
+ codes = this.getSubSection(secCode, subCode)?.getFieldNames() ?? [];
365
+ } else {
366
+ codes = this.getFieldNames() ?? [];
367
+ }
368
+ return (filter) ? codes.filter(fld => filter(this.getField(fld))) : codes;
369
+ }
370
+
371
+ applyOnFields(processFunc, inputCodes?: string[] | string | null, secCode?: string, subCode?: string): number {
372
+ if (!processFunc) { return 0; }
373
+ const codes = this.getFieldSet(null, inputCodes ?? null, secCode, subCode);
374
+ let processedFields = 0;
375
+ for (const code of codes) {
376
+ const field = this.getField(code);
377
+ if (field) {
378
+ try {
379
+ processFunc(field);
380
+ processedFields += 1;
381
+ } catch (e) {
382
+ console.log(`Error procesando funcion en campo ${field}: ${e}`);
383
+ }
384
+ }
385
+ }
386
+ return processedFields;
387
+ }
388
+
389
+ applyProcessToAllFields(processFunc) {
390
+ return this.applyOnFields(processFunc);
391
+ }
392
+
393
+ enableFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
394
+ return this.applyOnFields(fld => fld?.enable(), codes, secCode, subCode);
395
+ }
396
+
397
+ showFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
398
+ return this.applyOnFields(fld => fld?.show(), codes, secCode, subCode);
399
+ }
400
+
401
+ hideFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
402
+ return this.applyOnFields(fld => fld?.hide(), codes, secCode, subCode);
403
+ }
404
+
405
+ showLabelFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
406
+ return this.applyOnFields(fld => fld?.showLablel(), codes, secCode, subCode);
407
+ }
408
+
409
+ hideLabelFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
410
+ return this.applyOnFields(fld => fld?.hideLabel(), codes, secCode, subCode);
411
+ }
412
+
413
+ disableFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
414
+ return this.applyOnFields(fld => fld?.disable(), codes, secCode, subCode);
415
+ }
416
+
417
+ cleanFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
418
+ return this.applyOnFields(fld => fld?.clean(), codes, secCode, subCode);
419
+ }
420
+
421
+ tagFieldsWithError(message: string, codes?: string[] | string | null, secCode?: string, subCode?: string): number {
422
+ return this.applyOnFields(fld => fld?.setErrorMessage(message), codes, secCode, subCode);
423
+ }
424
+
425
+ cleanErrorFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
426
+ return this.tagFieldsWithError('', codes, secCode, subCode);
427
+ }
428
+
429
+ tagEmptyRequiredFields(message: string, codes = null, secCode?: string, subCode?: string): boolean {
430
+ return this.tagFieldsWithError(message, this.getRequiredEmptyFields(codes, secCode, subCode)) > 0;
431
+ }
432
+
433
+ getRequiredFields(codes?: string[] | string | null, secCode?: string, subCode?: string): string[] {
434
+ return this.getFieldSet(fld => fld?.required, codes ?? null, secCode, subCode);
435
+ }
436
+
437
+ getRequiredEmptyFields(codes?: string[] | string | null, secCode?: string, subCode?: string, onlyVisible?: boolean): string[] {
438
+ if (onlyVisible) {
439
+ return this.getFieldSet(fld => fld?.required && fld?.visible && fld?.empty, codes ?? null, secCode, subCode);
440
+ }
441
+ return this.getFieldSet(fld => fld?.required && fld?.empty, codes ?? null, secCode, subCode);
442
+ }
443
+
444
+ getChangedFields(codes?: string[] | string | null, secCode?: string, subCode?: string): string[] {
445
+ return this.getFieldSet(fld => !fld?.outputOnly && fld?.hasChanged, codes ?? null, secCode, subCode);
446
+ }
447
+
448
+ getFieldsWithValidationIssues(codes?: string[] | string | null, secCode?: string, subCode?: string, onlyVisible?: boolean): string[] {
449
+ if (onlyVisible) {
450
+ return this.getFieldSet(fld => (fld?.hasError() && fld?.visible), codes ?? null, secCode, subCode);
451
+ }
452
+ return this.getFieldSet(fld => fld?.hasError(), codes ?? null, secCode, subCode);
453
+ }
454
+
455
+ getFieldsValues(inputCodes?: string[] | string | null, secCode?: string, subCode?: string): any {
456
+ const codes = this.getFieldSet(null, inputCodes ?? null, secCode, subCode);
457
+ const resultObject = {};
458
+ for (let index = 0; index < codes.length; index++) {
459
+ const code = codes[index];
460
+ if (code) {
461
+ resultObject[code] = this.fields?.[code]?.getValue() ?? null;
462
+ }
463
+ }
464
+ return resultObject;
465
+ }
466
+
467
+ // Acciones
468
+ getActions(): FormAction[] { return this.actionArray; }
469
+ getAction(code: string): FormAction { return (code && this.actions?.[code]) ? this.actions[code] : null; }
470
+ showActions(codes: string[] | string): void { return this.execOnActions(codes, SHOW); }
471
+ hideActions(codes: string[] | string): void { return this.execOnActions(codes, HIDE); }
472
+ enableActions(codes: string[] | string): void { return this.execOnActions(codes, ENABLE); }
473
+ disableActions(codes: string[] | string): void { return this.execOnActions(codes, DISABLE); }
474
+ enableAction(code: string): void { return this.enableActions(code); }
475
+ disableAction(code: string): void { return this.disableActions(code); }
476
+ showAction(code: string): void { return this.showActions(code); }
477
+ hideAction(code: string): void { return this.hideActions(code); }
478
+ getHeaderActions() { return this.getActionsByAttribute('location', HEADER); }
479
+
480
+ getActionsByAttribute(name: string, value): FormAction[] {
481
+ return this.actionArray.filter(actionItem => actionItem.matchAttribute(name, value));
482
+ }
483
+
484
+ execOnActions(codes: string[] | string | null, functionName: string): void {
485
+ const actionCodes = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
486
+ if (!functionName || actionCodes.length === 0) { return; }
487
+ actionCodes.forEach(code => {
488
+ const action = this.getAction(code);
489
+ action?.[functionName]?.();
490
+ });
491
+ }
492
+
493
+ // Tablas
494
+ getTables(): RecordTable[] { return this.tableArray; }
495
+ getTable(code: string): RecordTable { return (code && this.tables?.[code]) ? this.tables[code] : null; }
496
+ getTableRecord(code: string, id: string): TableRecordData { return this.getTable(code)?.getTableRecord(id) }
497
+ enableTables(codes: string[] | string): void { return this.execOnTables(codes, ENABLE); }
498
+ disableTables(codes: string[] | string): void { return this.execOnTables(codes, DISABLE); }
499
+ showTables(codes: string[] | string): void { return this.execOnTables(codes, SHOW); }
500
+ hideTables(codes: string[] | string): void { return this.execOnTables(codes, HIDE); }
501
+ cleanTables(codes: string[] | string): void { return this.execOnTables(codes, CLEAN); }
502
+ showTable(code: string) { return this.showTables(code); }
503
+ hideTable(code: string) { return this.hideTables(code); }
504
+ cleanTable(code: string) { return this.getTable(code)?.clean(); }
505
+
506
+ execOnTables(codes: string[] | string | null, functionName: string) {
507
+ const tableCodes = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
508
+ if (!functionName || tableCodes.length === 0) { return; }
509
+ tableCodes.forEach(code => {
510
+ const table = this.getTable(code);
511
+ table?.[functionName]?.();
512
+ });
513
+ }
514
+
515
+ // Secciones
516
+ getSections(): RecordFormSection[] { return this.sectionArray; }
517
+ getSectionsTitles(): string[] { return this.getSections()?.filter(sec => sec?.title).map(sec => sec?.title ?? ''); }
518
+ numSections(): number { return this.sectionArray.length; }
519
+ getSectionsByAttribute(name, value): RecordFormSection[] { return this.sectionArray.filter(item => item.matchAttribute(name, value)); }
520
+ get sectionTitles(): string[] { return this.getSectionsTitles(); }
521
+ get visibleSections(): RecordFormSection[] { return this.sectionArray.filter(sec => sec.absoluteVisible); }
522
+ getSection(code: string): RecordFormSection { return (code && this.sections?.[code]) ? this.sections[code] : null; }
523
+ showSections(codes: string[] | string): void { this.execOnSections(codes, SHOW); }
524
+ hideSections(codes: string[] | string): void { this.execOnSections(codes, HIDE); }
525
+ showSection(code: string): void { return this.showSections(code); }
526
+ hideSection(code: string): void { return this.hideSections(code); }
527
+ activeSection(): string { return this._exclusiveSectionsByAttr[ACTIVE]; }
528
+ getSubSection(code: string, subCode): RecordFormSubSection { return this.getSection(code)?.getSubsection(subCode) ?? null; }
529
+ showSubSections(code: string, subCodes: string[] | string): void { return this.execOnSubSections(code, subCodes, SHOW); }
530
+ showSubSection(code: string, subCode: string): void { return this.showSubSections(code, subCode); }
531
+ hideSubSection(code: string, subCode: string): void { return this.hideSubSections(code, subCode); }
532
+ hideSubSections(code: string, subCodes: string[] | string): void { return this.execOnSubSections(code, subCodes, HIDE); }
533
+ getSectionActions(code): FormAction[] { return this.getSection(code)?.getActions() ?? null; }
534
+ getSectionActionNames(code): string[] { return this.getSection(code)?.getActionNames() ?? null; }
535
+
536
+ activateSection(code: string): void {
537
+ if (code === this._exclusiveSectionsByAttr[ACTIVE]) { return; }
538
+ this.getSection(this.activeSection())?.inactivate();
539
+ this.getSection(code)?.activate();
540
+ this._exclusiveSectionsByAttr[ACTIVE] = code;
541
+ }
542
+
543
+ execOnSections(codes: string[] | string | null, functionName: string): void {
544
+ const sectionCodes = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
545
+ if (!functionName || sectionCodes.length === 0) { return; }
546
+ sectionCodes.forEach(code => {
547
+ const section = this.getSection(code);
548
+ section?.[functionName]?.();
549
+ });
550
+ }
551
+
552
+ execOnSubSections(code: string, subNames: string[] | string | null, functionName: string): void {
553
+ const subCodes = (Array.isArray(subNames)) ? subNames : (subNames ? [subNames] : []);
554
+ const section = this.getSection(code);
555
+ if (!functionName || !section || subCodes.length === 0) { return; }
556
+ for (const subCode of subCodes) {
557
+ const subSection = this.getSubSection(code, subCode);
558
+ subSection?.[functionName]?.();
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Métodos propios de gestión del formulario
564
+ */
565
+
566
+ cleanData(): void {
567
+ for (const field of this.fieldArray) {
568
+ field.setValue(field.defaultValue);
569
+ }
570
+ for (const table of this.tableArray) {
571
+ table.clean();
572
+ }
573
+ }
574
+
575
+ getPayload(): any {
576
+ const formData: FormPayload = { fields: [], tables: [] };
577
+ formData.fields = this.getFields().filter(fld => !fld?.outputOnly)
578
+ .map(fld => {
579
+ const fieldPayload: FieldPayload = {
580
+ fieldCode: fld?.code,
581
+ fieldValue: fld?.value,
582
+ editable: !fld?.absoluteDisabled,
583
+ visible: fld?.absoluteVisible,
584
+ required: fld?.required,
585
+ fieldOptions: '',
586
+ }
587
+ return fieldPayload;
588
+ });
589
+
590
+ formData.tables = this.getTables().map(tbl => {
591
+ const tablePayload: TablePayload = {
592
+ tableCode: tbl.tableCode,
593
+ visible: tbl.absoluteVisible,
594
+ currentPage: tbl.currentPage,
595
+ requestedPage: tbl.requestedPage,
596
+ recordsPerPage: tbl.recordsPerPage,
597
+ currentFilter: tbl.currentFilter,
598
+ sortingColumn: tbl.sorting.columnName,
599
+ sortingDirection: tbl.sorting.direction,
600
+ };
601
+ return tablePayload
602
+ })
603
+ return formData;
604
+ }
605
+
606
+ /**
607
+ * @deprecated Use subject
608
+ */
609
+ get formSubject() { return this.subject; }
610
+
611
+ /**
612
+ * @deprecated Use subject
613
+ */
614
+ set formSubject(subject) { this.subject = subject; }
615
+
616
+ /**
617
+ * @deprecated Use states
618
+ */
619
+ getStates() { return this.states; }
620
+
621
+ /**
622
+ * @deprecated Use state
623
+ */
624
+ getCurrentState(): string { return this.state; }
625
+
626
+ /**
627
+ * @deprecated Use title
628
+ */
629
+ getTitle(): string { return this.title; }
630
+
631
+ /**
632
+ * @deprecated Use title
633
+ */
634
+ setTitle(title: string): void { this.title = title; }
635
+
636
+ /**
637
+ * @deprecated Use supportState
638
+ */
639
+ supportMode(state: string): boolean { return this.supportState(state); }
640
+
641
+ /**
642
+ * @deprecated Use enableFields
643
+ */
644
+ enableEditFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
645
+ return this.enableFields(codes, secCode, subCode);
646
+ }
647
+ /**
648
+ * @deprecated Use disableFields
649
+ */
650
+ disableEditFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
651
+ return this.disableFields(codes, secCode, subCode);
652
+ }
653
+
654
+ /**
655
+ * @deprecated Use getField
656
+ */
657
+ getFieldObject(code: string): FieldDescriptor | null { return this.getField(code); }
658
+
659
+ /**
660
+ * @deprecated Use getAction
661
+ */
662
+ getActionObject(code: string): FormAction | null { return this.getAction(code); }
663
+
664
+ /**
665
+ * @deprecated Use getTable
666
+ */
667
+ getTableObject(code: string): RecordTable | null { return this.getTable(code); }
668
+
669
+ /**
670
+ * @deprecated Use getSection
671
+ */
672
+ getSectionObject(code: string): RecordFormSection | null { return this.getSection(code); }
673
+
674
+ /**
675
+ * @deprecated Use changeState
676
+ */
677
+ changeFormMode(state: string): boolean { return this.changeState(state); }
678
+
679
+ /**
680
+ * @deprecated Use subject
681
+ */
682
+ getFormSubject(): string { return this.subject; }
683
+ /**
684
+ * @deprecated Use subject
685
+ */
686
+ getSubject(): string { return this.subject ?? ''; }
687
+ /**
688
+ * @deprecated Use subject
689
+ */
690
+ getformSubject(): string { return this.subject ?? ''; }
691
+
692
+ }