tuain-ng-forms-lib 14.4.93 → 14.4.95
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.
- package/esm2020/lib/classes/forms/action.mjs +36 -0
- package/esm2020/lib/classes/forms/element.mjs +26 -0
- package/esm2020/lib/classes/forms/field.mjs +445 -0
- package/esm2020/lib/classes/forms/form.constants.mjs +26 -0
- package/esm2020/lib/classes/forms/form.mjs +431 -0
- package/esm2020/lib/classes/forms/piece-propagate.mjs +37 -0
- package/esm2020/lib/classes/forms/piece.mjs +95 -0
- package/esm2020/lib/classes/forms/section.mjs +138 -0
- package/esm2020/lib/classes/forms/subsection.mjs +81 -0
- package/esm2020/lib/classes/forms/table/action.mjs +18 -0
- package/esm2020/lib/classes/forms/table/column.mjs +74 -0
- package/esm2020/lib/classes/forms/table/row-data.mjs +116 -0
- package/esm2020/lib/classes/forms/table/table.mjs +416 -0
- package/esm2020/lib/components/elements/action.component.mjs +71 -0
- package/esm2020/lib/components/elements/field.component.mjs +81 -0
- package/esm2020/lib/components/elements/layout/element.component.mjs +20 -0
- package/esm2020/lib/components/elements/layout/form-error.component.mjs +20 -0
- package/esm2020/lib/components/elements/layout/form-header.component.mjs +31 -0
- package/esm2020/lib/components/elements/layout/piece.component.mjs +39 -0
- package/esm2020/lib/components/elements/layout/section.component.mjs +37 -0
- package/esm2020/lib/components/elements/layout/sub-section.component.mjs +37 -0
- package/esm2020/lib/components/elements/tables/table-record-action.component.mjs +56 -0
- package/esm2020/lib/components/elements/tables/table-record-field.component.mjs +30 -0
- package/esm2020/lib/components/elements/tables/table.component.mjs +89 -0
- package/esm2020/lib/components/forms/basic-form.mjs +1514 -0
- package/esm2020/lib/services/event-manager.service.mjs +18 -0
- package/esm2020/lib/services/file-manager.service.mjs +6 -0
- package/esm2020/lib/services/form-manager.service.mjs +80 -0
- package/esm2020/lib/tuain-ng-forms-lib.module.mjs +71 -0
- package/esm2020/public-api.mjs +19 -0
- package/esm2020/tuain-ng-forms-lib.mjs +5 -0
- package/fesm2015/tuain-ng-forms-lib.mjs +4259 -0
- package/fesm2015/tuain-ng-forms-lib.mjs.map +1 -0
- package/fesm2020/tuain-ng-forms-lib.mjs +4074 -0
- package/fesm2020/tuain-ng-forms-lib.mjs.map +1 -0
- package/lib/classes/forms/action.d.ts +22 -0
- package/lib/classes/forms/element.d.ts +17 -0
- package/lib/classes/forms/field.d.ts +205 -0
- package/lib/classes/forms/form.constants.d.ts +25 -0
- package/lib/classes/forms/form.d.ts +137 -0
- package/lib/classes/forms/piece-propagate.d.ts +13 -0
- package/lib/classes/forms/piece.d.ts +41 -0
- package/lib/classes/forms/section.d.ts +32 -0
- package/lib/classes/forms/subsection.d.ts +24 -0
- package/lib/classes/forms/table/action.d.ts +15 -0
- package/lib/classes/forms/table/column.d.ts +33 -0
- package/lib/classes/forms/table/row-data.d.ts +14 -0
- package/lib/classes/forms/table/table.d.ts +100 -0
- package/lib/components/elements/action.component.d.ts +17 -0
- package/lib/components/elements/field.component.d.ts +38 -0
- package/lib/components/elements/layout/element.component.d.ts +9 -0
- package/lib/components/elements/layout/form-error.component.d.ts +8 -0
- package/lib/components/elements/layout/form-header.component.d.ts +12 -0
- package/lib/components/elements/layout/piece.component.d.ts +12 -0
- package/lib/components/elements/layout/section.component.d.ts +11 -0
- package/lib/components/elements/layout/sub-section.component.d.ts +11 -0
- package/lib/components/elements/tables/table-record-action.component.d.ts +16 -0
- package/lib/components/elements/tables/table-record-field.component.d.ts +12 -0
- package/lib/components/elements/tables/table.component.d.ts +35 -0
- package/lib/components/forms/basic-form.d.ts +353 -0
- package/lib/services/event-manager.service.d.ts +9 -0
- package/lib/services/file-manager.service.d.ts +5 -0
- package/lib/services/form-manager.service.d.ts +28 -0
- package/lib/tuain-ng-forms-lib.module.d.ts +20 -0
- package/package.json +24 -6
- package/{src/public-api.ts → public-api.d.ts} +0 -5
- package/tuain-ng-forms-lib.d.ts +5 -0
- package/.browserslistrc +0 -16
- package/.yarn/cache/nanoid-npm-4.0.0-924f5c6312-7d5946df5c.zip +0 -0
- package/.yarn/cache/tslib-npm-2.4.1-36f0ed04db-19480d6e03.zip +0 -0
- package/.yarn/cache/yn-npm-5.0.0-b001dab23c-f0ec7710d3.zip +0 -0
- package/.yarn/install-state.gz +0 -0
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -11
- package/src/lib/classes/forms/action.ts +0 -56
- package/src/lib/classes/forms/element.ts +0 -29
- package/src/lib/classes/forms/field.ts +0 -500
- package/src/lib/classes/forms/form.constants.ts +0 -28
- package/src/lib/classes/forms/form.ts +0 -508
- package/src/lib/classes/forms/piece-propagate.ts +0 -46
- package/src/lib/classes/forms/piece.ts +0 -122
- package/src/lib/classes/forms/section.ts +0 -152
- package/src/lib/classes/forms/subsection.ts +0 -90
- package/src/lib/classes/forms/table/action.ts +0 -32
- package/src/lib/classes/forms/table/column.ts +0 -94
- package/src/lib/classes/forms/table/row-data.ts +0 -121
- package/src/lib/classes/forms/table/table.ts +0 -478
- package/src/lib/components/elements/action.component.ts +0 -59
- package/src/lib/components/elements/field.component.ts +0 -92
- package/src/lib/components/elements/layout/element.component.ts +0 -13
- package/src/lib/components/elements/layout/form-error.component.ts +0 -11
- package/src/lib/components/elements/layout/form-header.component.ts +0 -17
- package/src/lib/components/elements/layout/piece.component.ts +0 -34
- package/src/lib/components/elements/layout/section.component.ts +0 -31
- package/src/lib/components/elements/layout/sub-section.component.ts +0 -31
- package/src/lib/components/elements/tables/table-record-action.component.ts +0 -50
- package/src/lib/components/elements/tables/table-record-field.component.ts +0 -20
- package/src/lib/components/elements/tables/table.component.ts +0 -86
- package/src/lib/components/forms/basic-form.ts +0 -1588
- package/src/lib/services/event-manager.service.ts +0 -21
- package/src/lib/services/file-manager.service.ts +0 -6
- package/src/lib/services/form-manager.service.ts +0 -89
- package/src/lib/services/icon-dictionary.service.ts +0 -159
- package/src/lib/tuain-ng-forms-lib.module.ts +0 -40
- package/src/test.ts +0 -27
- package/tsconfig.lib.json +0 -15
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const NO_ERROR = '00';
|
|
2
|
-
export const HEADER = 'HEADER';
|
|
3
|
-
|
|
4
|
-
export const elementTypes = {
|
|
5
|
-
action: 'ACTION',
|
|
6
|
-
field: 'FIELD',
|
|
7
|
-
table: 'TABLE',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const formActions = {
|
|
11
|
-
tableAction: 'TABLEACTION',
|
|
12
|
-
getData: 'GETDATA',
|
|
13
|
-
getTableData: 'GETTABLEDATA',
|
|
14
|
-
validate: 'VALIDATE',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const operators = {
|
|
18
|
-
G: 'G',
|
|
19
|
-
L: 'L',
|
|
20
|
-
GE: 'GE',
|
|
21
|
-
LE: 'LE',
|
|
22
|
-
EQ: 'EQ',
|
|
23
|
-
NEQ: 'NEQ',
|
|
24
|
-
HAS: 'HAS',
|
|
25
|
-
NOTHAS: 'NOTHAS',
|
|
26
|
-
BETWEEN: 'BETWEEN',
|
|
27
|
-
IN: 'IN',
|
|
28
|
-
};
|
|
@@ -1,508 +0,0 @@
|
|
|
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
|
-
interface Transition {
|
|
17
|
-
name: string;
|
|
18
|
-
source: string;
|
|
19
|
-
destination: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface StateFlow {
|
|
23
|
-
defaultState: string;
|
|
24
|
-
states: string[];
|
|
25
|
-
transitions: Transition[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface FieldPayload {
|
|
29
|
-
fieldCode: string;
|
|
30
|
-
fieldValue: any;
|
|
31
|
-
editable: boolean;
|
|
32
|
-
visible: boolean;
|
|
33
|
-
required: boolean;
|
|
34
|
-
fieldOptions: string,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface TablePayload {
|
|
38
|
-
tableCode: string;
|
|
39
|
-
visible: boolean;
|
|
40
|
-
currentPage: number;
|
|
41
|
-
requestedPage: number;
|
|
42
|
-
recordsPerPage: number;
|
|
43
|
-
currentFilter: any,
|
|
44
|
-
sortingColumn: string;
|
|
45
|
-
sortingDirection: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface FormPayload {
|
|
49
|
-
fields: FieldPayload[],
|
|
50
|
-
tables: TablePayload[],
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class FormStructureAndData {
|
|
54
|
-
private readonly _stateChange = new Subject<any>();
|
|
55
|
-
|
|
56
|
-
state: string;
|
|
57
|
-
_name: string = '';
|
|
58
|
-
_formConfig: any;
|
|
59
|
-
private _title: string = '';
|
|
60
|
-
private _stateFlow: StateFlow;
|
|
61
|
-
private _fieldArray: FieldDescriptor[];
|
|
62
|
-
private _fields = {};
|
|
63
|
-
private _actionArray: FormAction[];
|
|
64
|
-
private _actions = {};
|
|
65
|
-
private _tableArray: RecordTable[];
|
|
66
|
-
private _tables = {};
|
|
67
|
-
private _sectionArray: RecordFormSection[];
|
|
68
|
-
private _sections = {};
|
|
69
|
-
private _immutableData = {};
|
|
70
|
-
private _extraInfo = {};
|
|
71
|
-
private _exclusiveSectionsByAttr = {};
|
|
72
|
-
|
|
73
|
-
constructor(definitionReceived, formConfig) {
|
|
74
|
-
this._formConfig = formConfig;
|
|
75
|
-
this.state = '';
|
|
76
|
-
this._actionArray = [];
|
|
77
|
-
this._fieldArray = [];
|
|
78
|
-
this._tableArray = [];
|
|
79
|
-
this._sectionArray = [];
|
|
80
|
-
this._stateFlow = {
|
|
81
|
-
defaultState: '',
|
|
82
|
-
states: [],
|
|
83
|
-
transitions: [],
|
|
84
|
-
};
|
|
85
|
-
if (!definitionReceived) { return; }
|
|
86
|
-
this._name = (definitionReceived.form && definitionReceived.form.formCode)
|
|
87
|
-
? definitionReceived.form.formCode : this._name;
|
|
88
|
-
this._title = (definitionReceived.form && definitionReceived.form.formTitle)
|
|
89
|
-
? definitionReceived.form.formTitle : '';
|
|
90
|
-
this.setStateFlow(definitionReceived?.states, definitionReceived?.transitions,
|
|
91
|
-
definitionReceived?.defaultState);
|
|
92
|
-
this.immutableData = definitionReceived.immutableData;
|
|
93
|
-
this.extraInfo = definitionReceived.extraInfo;
|
|
94
|
-
|
|
95
|
-
if (definitionReceived.actions) {
|
|
96
|
-
const formActions = definitionReceived.actions.map(objDef => {
|
|
97
|
-
let visibleStates = objDef.visibleStates;
|
|
98
|
-
let enabledStates = objDef.enabledStates ?? objDef.editableStates;
|
|
99
|
-
if (!visibleStates) {
|
|
100
|
-
visibleStates = (objDef.actionModes || '').split(',')
|
|
101
|
-
.map(state => state.trim())
|
|
102
|
-
.filter(state => state.length > 0) || [];
|
|
103
|
-
enabledStates = [...visibleStates];
|
|
104
|
-
}
|
|
105
|
-
return { ...objDef, visibleStates, enabledStates };
|
|
106
|
-
});
|
|
107
|
-
for (const actionReceived of formActions) {
|
|
108
|
-
const globalAction = new FormAction(actionReceived, this._formConfig);
|
|
109
|
-
const globalActionCode = globalAction.actionCode;
|
|
110
|
-
if (globalActionCode) {
|
|
111
|
-
this._actionArray.push(globalAction);
|
|
112
|
-
this._actions[globalActionCode] = globalAction;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (definitionReceived.fields) {
|
|
118
|
-
const formFields = definitionReceived.fields.map(objDef => {
|
|
119
|
-
let visibleStates = objDef.visibleStates;
|
|
120
|
-
let enabledStates = objDef.enabledStates ?? objDef.editableStates;
|
|
121
|
-
if (!visibleStates) {
|
|
122
|
-
visibleStates = (objDef.fieldModes || '').split(',')
|
|
123
|
-
.map(state => state.trim())
|
|
124
|
-
.filter(state => state.length > 0) || [];
|
|
125
|
-
enabledStates = [...visibleStates];
|
|
126
|
-
}
|
|
127
|
-
return { ...objDef, visibleStates, enabledStates };
|
|
128
|
-
});
|
|
129
|
-
for (const fieldReceived of formFields) {
|
|
130
|
-
const fieldToAdd = new FieldDescriptor(fieldReceived, this._formConfig);
|
|
131
|
-
const fieldCode = fieldToAdd.code;
|
|
132
|
-
if (fieldCode) {
|
|
133
|
-
this._fieldArray.push(fieldToAdd);
|
|
134
|
-
this._fields[fieldCode] = fieldToAdd;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (definitionReceived.tables) {
|
|
140
|
-
const tables = definitionReceived.tables.map(objDef => {
|
|
141
|
-
let visibleStates = objDef.visibleStates;
|
|
142
|
-
let enabledStates = objDef.enabledStates || objDef.editableStates;
|
|
143
|
-
if (!visibleStates) {
|
|
144
|
-
visibleStates = (objDef.tableModes || '').split(',')
|
|
145
|
-
.map(state => state.trim())
|
|
146
|
-
.filter(state => state.length > 0) || [];
|
|
147
|
-
enabledStates = [...visibleStates];
|
|
148
|
-
}
|
|
149
|
-
return { ...objDef, visibleStates, enabledStates };
|
|
150
|
-
});
|
|
151
|
-
for (const tableReceived of tables) {
|
|
152
|
-
const tableToAdd = new RecordTable(tableReceived, this._formConfig);
|
|
153
|
-
const tableCode = tableToAdd.tableCode;
|
|
154
|
-
if (tableCode) {
|
|
155
|
-
this._tableArray.push(tableToAdd);
|
|
156
|
-
this._tables[tableCode] = tableToAdd;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (definitionReceived.sections) {
|
|
162
|
-
const formSections = definitionReceived.sections.map(objDef => {
|
|
163
|
-
let visibleStates = objDef.visibleStates;
|
|
164
|
-
if (!visibleStates) {
|
|
165
|
-
visibleStates = (objDef.sectionModes || '').split(',')
|
|
166
|
-
.map(state => state.trim())
|
|
167
|
-
.filter(state => state.length > 0) || [];
|
|
168
|
-
}
|
|
169
|
-
return { ...objDef, visibleStates };
|
|
170
|
-
});
|
|
171
|
-
for (const sectionReceived of formSections) {
|
|
172
|
-
const sectionToAdd = new RecordFormSection(sectionReceived, this, this._formConfig);
|
|
173
|
-
const sectionCode = sectionToAdd.sectionCode;
|
|
174
|
-
if (sectionCode) {
|
|
175
|
-
this._sectionArray.push(sectionToAdd);
|
|
176
|
-
this._sections[sectionCode] = sectionToAdd;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
getTitle(): string { return this._title; }
|
|
183
|
-
setTitle(title: string): void { this._title = title; }
|
|
184
|
-
get name(): string { return this._name; }
|
|
185
|
-
set name(name) { this._name = name; }
|
|
186
|
-
|
|
187
|
-
// Estados
|
|
188
|
-
get defaultState(): string { return this._stateFlow.defaultState; }
|
|
189
|
-
supportState(state: string): boolean { return this._stateFlow.states?.includes(state); }
|
|
190
|
-
supportMode(state: string): boolean { return this.supportState(state); }
|
|
191
|
-
get states(): any[] { return this._stateFlow.states; }
|
|
192
|
-
|
|
193
|
-
getCurrentState(): string { return this.state; }
|
|
194
|
-
|
|
195
|
-
changeState(newState: string): boolean {
|
|
196
|
-
if (!newState || !this.supportState(newState)) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
if (!this.state) {
|
|
200
|
-
this.state = newState;
|
|
201
|
-
} else {
|
|
202
|
-
const transitionToChange = this._stateFlow.transitions.find(trns =>
|
|
203
|
-
trns.source === this.state && trns.destination === newState);
|
|
204
|
-
if (transitionToChange) {
|
|
205
|
-
this.state = newState;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
this._stateChange.next({ state: this.state });
|
|
209
|
-
return (this.state === newState);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
get stateChange() { return this._stateChange; }
|
|
213
|
-
|
|
214
|
-
setStateFlow(states?, transitions?, defaultState?: string): void {
|
|
215
|
-
this._stateFlow.states = states;
|
|
216
|
-
this._stateFlow.defaultState = defaultState || this._stateFlow.states[0];
|
|
217
|
-
this._stateFlow.transitions = transitions.map(transition => {
|
|
218
|
-
const name = transition.name;
|
|
219
|
-
const source = (this._stateFlow.states.includes(transition.source)) ? transition.source : '';
|
|
220
|
-
const destination = (this._stateFlow.states.includes(transition.destination)) ? transition.destination : '';
|
|
221
|
-
return { name, source, destination };
|
|
222
|
-
}).filter(item => item.name && item.source && item.destination);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// immutable Data
|
|
226
|
-
getImmutableElement(name: string): any { return this._immutableData?.[name]?.value ?? null; }
|
|
227
|
-
set immutableData(immutableData) { Object.assign(this._immutableData, immutableData); }
|
|
228
|
-
get immutableData(): any { return JSON.parse(JSON.stringify(this._immutableData)); }
|
|
229
|
-
|
|
230
|
-
// extra Info
|
|
231
|
-
getExtraInfo(name: string): any { return this._extraInfo?.[name]?.value ?? null; }
|
|
232
|
-
set extraInfo(extraInfo) { Object.assign(this._extraInfo, extraInfo); }
|
|
233
|
-
get extraInfo(): any { return JSON.parse(JSON.stringify(this._extraInfo)); }
|
|
234
|
-
|
|
235
|
-
// Fields
|
|
236
|
-
get fields(): any { return this._fields; }
|
|
237
|
-
get fieldNames(): string[] { return this.getFieldNames(); }
|
|
238
|
-
getFields(): FieldDescriptor[] { return this._fieldArray; }
|
|
239
|
-
getFieldNames(): string[] { return this._fieldArray.map(field => field.code); }
|
|
240
|
-
getField(code: string): FieldDescriptor { return (code && this._fields?.[code]) ? this._fields[code] : null; }
|
|
241
|
-
enableField(code: string): void { this.getField(code)?.enable(); }
|
|
242
|
-
disableField(code: string): void { this.getField(code)?.disable(); }
|
|
243
|
-
getFieldValue(code: string): any { return this.getField(code)?.value; }
|
|
244
|
-
getFieldOptionText(code: string): any { return this.getField(code)?.optionText; }
|
|
245
|
-
getFieldOptions(code: string): FieldOption[] | null { return this.getField(code)?.options ?? null; }
|
|
246
|
-
setFieldValue(code: string, value: any): any { this.getField(code)?.setValue(value); }
|
|
247
|
-
setFieldError(code: string, errorCode: string, message: string, type: string = 'error'): any { this.getField(code)?.setError(errorCode, message, type); }
|
|
248
|
-
setFieldIntrinsicErrorMessage(code: string, message: string): any { this.getField(code)?.setIntrinsicErrorMessage(message); }
|
|
249
|
-
|
|
250
|
-
setFieldRequired(inputCodes: string[] | string | null, required: boolean): any {
|
|
251
|
-
const codes = this.getFieldSet(null, inputCodes ?? null);
|
|
252
|
-
for (const code of codes) {
|
|
253
|
-
try {
|
|
254
|
-
const field = this.getField(code) ?? null;
|
|
255
|
-
field && (field.required = required);
|
|
256
|
-
} catch (e) {
|
|
257
|
-
console.log(`Error modificando campo ${code}: ${e}`);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
setFieldErrorMessage(code: string, message: string): any { this.getField(code)?.setErrorMessage(message); }
|
|
263
|
-
|
|
264
|
-
setFieldOptions(code: string, optionsArray: any[], idAttribute: string, nameAttribute: string): any {
|
|
265
|
-
const field = this.getField(code);
|
|
266
|
-
if (field && optionsArray?.length > 0) {
|
|
267
|
-
const fieldOptions = optionsArray.map(item => ({
|
|
268
|
-
fieldOptionId: item[idAttribute],
|
|
269
|
-
fieldOptionValue: item[nameAttribute]
|
|
270
|
-
}));
|
|
271
|
-
field.setFieldOptions(fieldOptions);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
getFieldSet(filter, inputCodes: string[] | string | null, secCode?: string | null, subCode?: string | null): string[] {
|
|
276
|
-
let codes: any[] = [];
|
|
277
|
-
if (inputCodes) {
|
|
278
|
-
if (typeof inputCodes === 'string') {
|
|
279
|
-
codes = [inputCodes];
|
|
280
|
-
} else if (Array.isArray(inputCodes) && inputCodes.length > 0) {
|
|
281
|
-
codes = inputCodes ?? [];
|
|
282
|
-
}
|
|
283
|
-
} else if (secCode && !subCode) {
|
|
284
|
-
codes = this.getSection(secCode)?.getFieldNames() ?? [];
|
|
285
|
-
} else if (secCode && subCode) {
|
|
286
|
-
codes = this.getSubSection(secCode, subCode)?.getFieldNames() ?? [];
|
|
287
|
-
} else {
|
|
288
|
-
codes = this.getFieldNames() ?? [];
|
|
289
|
-
}
|
|
290
|
-
return (filter) ? codes.filter(fld => filter(this.getField(fld))) : codes;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
applyOnFields(processFunc, inputCodes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
294
|
-
if (!processFunc) { return 0; }
|
|
295
|
-
const codes = this.getFieldSet(null, inputCodes ?? null, secCode, subCode);
|
|
296
|
-
let processedFields = 0;
|
|
297
|
-
for (const code of codes) {
|
|
298
|
-
const field = this.getField(code);
|
|
299
|
-
if (field) {
|
|
300
|
-
try {
|
|
301
|
-
processFunc(field);
|
|
302
|
-
processedFields += 1;
|
|
303
|
-
} catch (e) {
|
|
304
|
-
console.log(`Error procesando funcion en campo ${field}: ${e}`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return processedFields;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
enableFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
312
|
-
return this.applyOnFields(fld => fld?.enable(), codes, secCode, subCode);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
showFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
316
|
-
return this.applyOnFields(fld => fld?.show(), codes, secCode, subCode);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
hideFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
320
|
-
return this.applyOnFields(fld => fld?.hide(), codes, secCode, subCode);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
showLabelFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
324
|
-
return this.applyOnFields(fld => fld?.showLablel(), codes, secCode, subCode);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
hideLabelFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
328
|
-
return this.applyOnFields(fld => fld?.hideLabel(), codes, secCode, subCode);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
disableFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
332
|
-
return this.applyOnFields(fld => fld?.disable(), codes, secCode, subCode);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
cleanFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
336
|
-
return this.applyOnFields(fld => fld?.clean(), codes, secCode, subCode);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
tagFieldsWithError(message: string, codes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
340
|
-
return this.applyOnFields(fld => fld?.setErrorMessage(message), codes, secCode, subCode);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
cleanErrorFields(codes?: string[] | string | null, secCode?: string, subCode?: string): number {
|
|
344
|
-
return this.tagFieldsWithError('', codes, secCode, subCode);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
tagEmptyRequiredFields(message: string, codes = null, secCode?: string, subCode?: string): boolean {
|
|
348
|
-
return this.tagFieldsWithError(message, this.getRequiredEmptyFields(codes, secCode, subCode)) > 0;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
getRequiredFields(codes?: string[] | string | null, secCode?: string, subCode?: string): string[] {
|
|
352
|
-
return this.getFieldSet(fld => fld?.required, codes ?? null, secCode, subCode);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
getRequiredEmptyFields(codes?: string[] | string | null, secCode?: string, subCode?: string): string[] {
|
|
356
|
-
return this.getFieldSet(fld => fld?.required && fld?.empty, codes ?? null, secCode, subCode);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
getChangedFields(codes?: string[] | string | null, secCode?: string, subCode?: string): string[] {
|
|
360
|
-
return this.getFieldSet(fld => !fld?.outputOnly && fld?.hasChanged(), codes ?? null, secCode, subCode);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
getFieldsWithValidationIssues(codes?: string[] | string | null, secCode?: string, subCode?: string): string[] {
|
|
364
|
-
return this.getFieldSet(fld => fld?.hasError(), codes ?? null, secCode, subCode);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
getFieldsValues(inputCodes?: string[] | string | null, secCode?: string, subCode?: string): any {
|
|
368
|
-
const codes = this.getFieldSet(null, inputCodes ?? null, secCode, subCode);
|
|
369
|
-
const resultObject = {};
|
|
370
|
-
for (let index = 0; index < codes.length; index++) {
|
|
371
|
-
const code = codes[index];
|
|
372
|
-
if (code) {
|
|
373
|
-
resultObject[code] = this._fields?.[code]?.getValue() ?? null;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return resultObject;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// Acciones
|
|
380
|
-
get actions() { return this._actions; }
|
|
381
|
-
|
|
382
|
-
getActionsByAttribute(name: string, value): FormAction[] { return this._actionArray.filter(actionItem => actionItem.matchAttribute(name, value)); }
|
|
383
|
-
getActions(): FormAction[] { return this._actionArray; }
|
|
384
|
-
getAction(code: string): FormAction { return (code && this._actions?.[code]) ? this._actions[code] : null; }
|
|
385
|
-
showActions(codes: string[] | string): void { return this.execOnActions(codes, SHOW); }
|
|
386
|
-
hideActions(codes: string[] | string): void { return this.execOnActions(codes, HIDE); }
|
|
387
|
-
enableActions(codes: string[] | string): void { return this.execOnActions(codes, ENABLE); }
|
|
388
|
-
disableActions(codes: string[] | string): void { return this.execOnActions(codes, DISABLE); }
|
|
389
|
-
|
|
390
|
-
execOnActions(codes: string[] | string | null, functionName: string): void {
|
|
391
|
-
const actionCodes = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
|
|
392
|
-
if (!functionName || actionCodes.length === 0) { return; }
|
|
393
|
-
actionCodes.forEach(code => {
|
|
394
|
-
const action = this.getAction(code);
|
|
395
|
-
action?.[functionName]?.();
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// Tablas
|
|
400
|
-
get tables(): any { return this.tables; }
|
|
401
|
-
getTables(): RecordTable[] { return this._tableArray; }
|
|
402
|
-
getTable(code: string): RecordTable { return (code && this._tables?.[code]) ? this._tables[code] : null; }
|
|
403
|
-
getTableRecord(code: string, id: string): TableRecordData { return this.getTable(code)?.getTableRecord(id) }
|
|
404
|
-
|
|
405
|
-
enableTables(codes: string[] | string): void { return this.execOnTables(codes, ENABLE); }
|
|
406
|
-
disableTables(codes: string[] | string): void { return this.execOnTables(codes, DISABLE); }
|
|
407
|
-
showTables(codes: string[] | string): void { return this.execOnTables(codes, SHOW); }
|
|
408
|
-
hideTables(codes: string[] | string): void { return this.execOnTables(codes, HIDE); }
|
|
409
|
-
cleanTables(codes: string[] | string): void { return this.execOnTables(codes, CLEAN); }
|
|
410
|
-
|
|
411
|
-
execOnTables(codes: string[] | string | null, functionName: string) {
|
|
412
|
-
const tableCodes = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
|
|
413
|
-
if (!functionName || tableCodes.length === 0) { return; }
|
|
414
|
-
tableCodes.forEach(code => {
|
|
415
|
-
const table = this.getTable(code);
|
|
416
|
-
table?.[functionName]?.();
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// Secciones
|
|
421
|
-
get sections(): any { return this._sections; }
|
|
422
|
-
getSections(): RecordFormSection[] { return this._sectionArray; }
|
|
423
|
-
getSectionsByAttribute(name, value): RecordFormSection[] { return this._sectionArray.filter(item => item.matchAttribute(name, value)); }
|
|
424
|
-
get sectionTitles(): string[] { return this._sectionArray.map(formSection => formSection.sectionTitle); }
|
|
425
|
-
get visibleSections(): RecordFormSection[] { return this._sectionArray.filter(sec => sec.absoluteVisible); }
|
|
426
|
-
getSection(code: string): RecordFormSection { return (code && this._sections?.[code]) ? this._sections[code] : null; }
|
|
427
|
-
showSections(codes: string[] | string): void { this.execOnSections(codes, SHOW); }
|
|
428
|
-
hideSections(codes: string[] | string): void { this.execOnSections(codes, HIDE); }
|
|
429
|
-
activeSection(): string { return this._exclusiveSectionsByAttr[ACTIVE]; }
|
|
430
|
-
getSubSection(code: string, subCode): RecordFormSubSection { return this.getSection(code)?.getSubsection(subCode) ?? null; }
|
|
431
|
-
showSubSections(code: string, subCodes: string[] | string): void { return this.execOnSubSections(code, subCodes, SHOW); }
|
|
432
|
-
hideSubSections(code: string, subCodes: string[] | string): void { return this.execOnSubSections(code, subCodes, HIDE); }
|
|
433
|
-
getSectionActions(code): FormAction[] { return this.getSection(code)?.getActions() ?? null; }
|
|
434
|
-
getSectionActionNames(code): string[] { return this.getSection(code)?.getActionNames() ?? null; }
|
|
435
|
-
|
|
436
|
-
activateSection(code: string): void {
|
|
437
|
-
if (code === this._exclusiveSectionsByAttr[ACTIVE]) { return; }
|
|
438
|
-
this.getSection(this.activeSection())?.inactivate();
|
|
439
|
-
this.getSection(code)?.activate();
|
|
440
|
-
this._exclusiveSectionsByAttr[ACTIVE] = code;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
execOnSections(codes: string[] | string | null, functionName: string): void {
|
|
444
|
-
const sectionCodes = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
|
|
445
|
-
if (!functionName || sectionCodes.length === 0) { return; }
|
|
446
|
-
sectionCodes.forEach(code => {
|
|
447
|
-
const section = this.getSection(code);
|
|
448
|
-
section?.[functionName]?.();
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
execOnSubSections(code: string, subNames: string[] | string | null, functionName: string): void {
|
|
453
|
-
const subCodes = (Array.isArray(subNames)) ? subNames : (subNames ? [subNames] : []);
|
|
454
|
-
const section = this.getSection(code);
|
|
455
|
-
if (!functionName || !section || subCodes.length === 0) { return; }
|
|
456
|
-
for (const subCode of subCodes) {
|
|
457
|
-
const subSection = this.getSubSection(code, subCode);
|
|
458
|
-
subSection?.[functionName]?.();
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* Métodos propios de gestión del formulario
|
|
464
|
-
*/
|
|
465
|
-
|
|
466
|
-
cleanData(): void {
|
|
467
|
-
for (const field of this._fieldArray) {
|
|
468
|
-
field.setValue(field.defaultValue);
|
|
469
|
-
}
|
|
470
|
-
for (const table of this._tableArray) {
|
|
471
|
-
table.clean();
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
getPayload(): any {
|
|
476
|
-
const formData: FormPayload = {
|
|
477
|
-
fields: [],
|
|
478
|
-
tables: [],
|
|
479
|
-
};
|
|
480
|
-
formData.fields = this.getFields().filter(fld => !fld?.outputOnly)
|
|
481
|
-
.map(fld => {
|
|
482
|
-
const fieldPayload: FieldPayload = {
|
|
483
|
-
fieldCode: fld?.code,
|
|
484
|
-
fieldValue: fld?.value,
|
|
485
|
-
editable: !fld?.absoluteDisabled,
|
|
486
|
-
visible: fld?.absoluteVisible,
|
|
487
|
-
required: fld?.required,
|
|
488
|
-
fieldOptions: '',
|
|
489
|
-
}
|
|
490
|
-
return fieldPayload;
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
formData.tables = this.getTables().map(tbl => {
|
|
494
|
-
const tablePayload: TablePayload = {
|
|
495
|
-
tableCode: tbl.tableCode,
|
|
496
|
-
visible: tbl.absoluteVisible,
|
|
497
|
-
currentPage: tbl.currentPage,
|
|
498
|
-
requestedPage: tbl.requestedPage,
|
|
499
|
-
recordsPerPage: tbl.recordsPerPage,
|
|
500
|
-
currentFilter: tbl.currentFilter,
|
|
501
|
-
sortingColumn: tbl.sorting.columnName,
|
|
502
|
-
sortingDirection: tbl.sorting.direction,
|
|
503
|
-
};
|
|
504
|
-
return tablePayload
|
|
505
|
-
})
|
|
506
|
-
return formData;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { BehaviorSubject } from 'rxjs';
|
|
2
|
-
import { FormPiece } from './piece';
|
|
3
|
-
|
|
4
|
-
const VISIBLE = 'visible';
|
|
5
|
-
const DISABLED = 'disabled';
|
|
6
|
-
|
|
7
|
-
export class FormPiecePropagate extends FormPiece {
|
|
8
|
-
protected propagationCustomAttributes: string[] = [];
|
|
9
|
-
protected _attributeChange: BehaviorSubject<any>;
|
|
10
|
-
|
|
11
|
-
constructor(pieceDefinition: any, formConfig: any) {
|
|
12
|
-
super(pieceDefinition, formConfig);
|
|
13
|
-
this._attributeChange = new BehaviorSubject<any>(null);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get attributeChange() { return this._attributeChange; }
|
|
17
|
-
|
|
18
|
-
propagateAttribute(name, value) {
|
|
19
|
-
this._attributeChange?.next({ name, value });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
override setCustomAttribute(name: string, value: any): void {
|
|
23
|
-
super.setCustomAttribute(name, value);
|
|
24
|
-
if (this.propagationCustomAttributes?.includes(name)) {
|
|
25
|
-
this.propagateAttribute(name, value);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
override setVisibility(visible: boolean, forced: boolean | null = null): void {
|
|
30
|
-
super.setVisibility(visible, forced);
|
|
31
|
-
this.propagateAttribute(VISIBLE, this._visible);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
override set enabled(enabled) {
|
|
35
|
-
super.enabled = enabled;
|
|
36
|
-
this.propagateAttribute(DISABLED, this._disabled);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
override formStateChange(state) {
|
|
40
|
-
super.formStateChange(state);
|
|
41
|
-
if (state) {
|
|
42
|
-
this.propagateAttribute(VISIBLE, this._visible);
|
|
43
|
-
this.propagateAttribute(DISABLED, this._disabled);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|