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,47 @@
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.asObservable(); }
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
+ const fullName = `customAttributes.${name}`;
26
+ this.propagateAttribute(fullName, value);
27
+ }
28
+ }
29
+
30
+ override setVisibility(visible: boolean, forced: boolean | null = null): void {
31
+ super.setVisibility(visible, forced);
32
+ this.propagateAttribute(VISIBLE, this._visible);
33
+ }
34
+
35
+ override set enabled(enabled) {
36
+ super.enabled = enabled;
37
+ this.propagateAttribute(DISABLED, this._disabled);
38
+ }
39
+
40
+ override formStateChange(state) {
41
+ super.formStateChange(state);
42
+ if (state) {
43
+ this.propagateAttribute(VISIBLE, this._visible);
44
+ this.propagateAttribute(DISABLED, this._disabled);
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,164 @@
1
+ import { Subject, takeUntil } from 'rxjs';
2
+
3
+ export class FormPiece {
4
+ private destroy$ = new Subject<void>();
5
+
6
+ protected _formState: string = '';
7
+ protected _visibleForced: boolean;
8
+ protected _isForced: boolean;
9
+ protected _absoluteVisible: boolean = true;
10
+ protected _absoluteDisabled: boolean = false;
11
+ protected _widget: any = null;
12
+
13
+ protected visibleStates: string[] = [];
14
+ protected enabledStates: string[] = [];
15
+
16
+ public _form: any = null;
17
+ public _formConfig: any;
18
+ public _visible: boolean = true;
19
+ public _disabled: boolean = false;
20
+ public customAttributes: any = {};
21
+
22
+ constructor(pieceDefinition: any, formConfig: any) {
23
+ this._formConfig = formConfig;
24
+ this._isForced = false;
25
+ this._visibleForced = false;
26
+ this.setVisibleStates(pieceDefinition.visibleStates);
27
+ this.setEnabledStates(pieceDefinition.enabledStates);
28
+
29
+ this.enabled = !pieceDefinition?.disabled ?? false;
30
+ this.setVisibility(pieceDefinition?.visible ?? true);
31
+ this.customAttributes = pieceDefinition?.customAttributes ?? {};
32
+ if (pieceDefinition?.customAttributes) {
33
+ Object.keys(pieceDefinition?.customAttributes)
34
+ ?.forEach(attr => this.customAttributes[attr] = pieceDefinition?.customAttributes[attr])
35
+ }
36
+ }
37
+
38
+ getCustomAttribute(name: string): any { return this.customAttributes?.[name] ?? null; }
39
+ setCustomAttribute(name: string, value: any): void { if (name) { this.customAttributes[name] = value; } }
40
+
41
+ setCustomAttributes(attributes: any): FormPiece {
42
+ Object.entries(attributes).forEach(([name, value]) => {
43
+ this.setCustomAttribute(name, value);
44
+ });
45
+ return this;
46
+ }
47
+
48
+ matchAttribute(name: string, value: string): boolean { return this.customAttributes?.[name] === value; }
49
+
50
+ setVisibleStates(newStates: any): void {
51
+ const visibleStates = (!Array.isArray(newStates) && typeof newStates === 'string')
52
+ ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
53
+ : newStates;
54
+ this.visibleStates = (Array.isArray(visibleStates)) ? [...(new Set(visibleStates))] : [];
55
+ }
56
+
57
+ addVisibleState(state: string) {
58
+ if (!this.visibleStates.includes(state)) {
59
+ this.visibleStates.push(state);
60
+ }
61
+ }
62
+
63
+ removeVisibleState(state: string) {
64
+ const existStateIdx = this.visibleStates.findIndex(st => st === state);
65
+ if (existStateIdx >= 0) {
66
+ this.visibleStates.splice(existStateIdx, 1);
67
+ }
68
+ }
69
+
70
+ setEnabledStates(newStates: any): void {
71
+ const enabledStates = (!Array.isArray(newStates) && typeof newStates === 'string')
72
+ ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
73
+ : newStates;
74
+ this.enabledStates = (Array.isArray(enabledStates)) ? [...(new Set(enabledStates))] : [];
75
+ }
76
+
77
+ addEnabledState(state: string) {
78
+ if (!this.enabledStates.includes(state)) {
79
+ this.enabledStates.push(state);
80
+ }
81
+ }
82
+
83
+ removeEnabledState(state: string) {
84
+ const existStateIdx = this.enabledStates.findIndex(st => st === state);
85
+ if (existStateIdx >= 0) {
86
+ this.enabledStates.splice(existStateIdx, 1);
87
+ }
88
+ }
89
+
90
+ viewOnState(state: string): boolean { return (this.visibleStates && state) ? this.visibleStates.includes(state) : false; }
91
+ enabledOnState(state: string): boolean { return (this.enabledStates && state) ? this.enabledStates.includes(state) : false; }
92
+
93
+ get absoluteVisible(): boolean { return this._absoluteVisible; }
94
+ get absoluteDisabled(): boolean { return this._absoluteDisabled; }
95
+
96
+ get visible(): boolean { return this._visible; }
97
+ set visible(visible: boolean) { this.setVisibility(visible); }
98
+
99
+ visibleOn(state: string): boolean {
100
+ return this._absoluteVisible && this.viewOnState(state);
101
+ }
102
+
103
+ enabledOn(state: string): boolean {
104
+ return !this._absoluteDisabled && this.enabledOnState(state);
105
+ }
106
+
107
+ setVisibility(visible: boolean, forced: boolean | null = null): void {
108
+ this._absoluteVisible = !!visible;
109
+ if (forced !== null) {
110
+ this._isForced = forced;
111
+ this._visibleForced = visible;
112
+ }
113
+ this._visible = this._absoluteVisible && this.viewOnState(this._formState);
114
+ }
115
+
116
+ show(forced: boolean | null = null): void {
117
+ this.setVisibility(true, forced);
118
+ }
119
+
120
+ hide(forced: boolean | null = null): void {
121
+ this.setVisibility(false, forced);
122
+ }
123
+
124
+ get enabled(): boolean { return !this._disabled; }
125
+ set enabled(enabled) {
126
+ this._absoluteDisabled = !enabled;
127
+ this._disabled = this._absoluteDisabled || !this.enabledOnState(this._formState);
128
+ }
129
+
130
+ get editable(): boolean { return !this._disabled; }
131
+
132
+ get disabled(): boolean { return this._disabled; }
133
+
134
+ set disabled(disabled) { this.enabled = !disabled; }
135
+
136
+ enable(): void { this.enabled = true; }
137
+ disable(): void { this.enabled = false; }
138
+
139
+ formStateChangeCustomSubscribe(form, formChangeSubject) { }
140
+
141
+ formStateChange(state) {
142
+ if (state) {
143
+ this._formState = state;
144
+ this._visible = this._absoluteVisible && this.viewOnState(state);
145
+ this._disabled = this._absoluteDisabled || !this.enabledOnState(state);
146
+ }
147
+ }
148
+
149
+ connectWithParentForm(form, formChangeSubject) {
150
+ this._form = form;
151
+ this.formStateChangeCustomSubscribe(form, formChangeSubject);
152
+ formChangeSubject
153
+ .pipe(takeUntil(this.destroy$))
154
+ .subscribe(event => this.formStateChange(event?.state));
155
+ }
156
+
157
+ set widget(widget) { this._widget = widget; }
158
+ get widget() { return this._widget; }
159
+
160
+ destroy() {
161
+ this.destroy$.next();
162
+ this.destroy$.complete();
163
+ }
164
+ }
@@ -0,0 +1,165 @@
1
+ import { Subject } from 'rxjs';
2
+ import { FormPiecePropagate } from './piece-propagate';
3
+ import { FormAction } from './action';
4
+ import { RecordFormSubSection } from './subsection';
5
+
6
+ const ACTIVE = 'active';
7
+
8
+ export class RecordFormSection extends FormPiecePropagate {
9
+ private readonly _activation = new Subject<string>();
10
+ private readonly _inactivation = new Subject<string>();
11
+ private _active = false;
12
+ private _sectionId: string | null = null;
13
+ private _sectionCode: string | null = null;
14
+ private _sectionTitle: string | null = null;
15
+ private _subSections: RecordFormSubSection[] = [];
16
+ private _subSectionsObj: any;
17
+ private _exclusiveSubSectionsByAttr = {};
18
+
19
+ constructor(sectionReceived, formObject, formConfig) {
20
+ super(sectionReceived, formConfig);
21
+ this.propagationCustomAttributes = this._formConfig?.propagationCustomAttributes?.sections ?? [];
22
+ if (!sectionReceived) { return; }
23
+ this._sectionId = (sectionReceived.sectionId) ? sectionReceived.sectionId.toString() : '';
24
+ this._sectionCode = (sectionReceived.sectionCode) ? sectionReceived.sectionCode : '';
25
+ this._sectionTitle = (sectionReceived.sectionTitle) ? sectionReceived.sectionTitle : '';
26
+ this._subSections = [];
27
+ this._subSectionsObj = {};
28
+ if (sectionReceived.subsections) {
29
+ const subsections = sectionReceived.subsections.map(subSecDef => {
30
+ const visibleStates = subSecDef.visibleStates ?? [];
31
+ if (subSecDef.elements && Array.isArray(subSecDef.elements)) {
32
+ subSecDef.elements = subSecDef.elements.map(elm => ({ code: elm.elementCode, type: elm.elementTypeName }));
33
+ }
34
+ return { ...subSecDef, visibleStates };
35
+ });
36
+ for (const subsectionReceived of subsections) {
37
+ const subSectionToAdd = new RecordFormSubSection(subsectionReceived, formObject, formConfig);
38
+ const subsectionCode = subSectionToAdd.subsectionCode;
39
+ if (subsectionCode) {
40
+ this._subSections.push(subSectionToAdd);
41
+ this._subSectionsObj[subsectionCode] = subSectionToAdd;
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ get code() { return this._sectionCode; }
48
+ get activation() { return this._activation.asObservable(); }
49
+ get inactivation() { return this._inactivation.asObservable(); }
50
+
51
+ get active() { return this._active; }
52
+ get sectionId() { return this._sectionId; }
53
+ get sectionCode() { return this._sectionCode; }
54
+ get sectionTitle() { return this._sectionTitle; }
55
+ get subSections() { return this._subSections; }
56
+ get subSectionsObj() { return this._subSectionsObj; }
57
+
58
+ set active(active) { this._active = active; }
59
+ set sectionId(sectionId) { this._sectionId = sectionId; }
60
+ set sectionCode(sectionCode) { this._sectionCode = sectionCode; }
61
+ set sectionTitle(sectionTitle) { this._sectionTitle = sectionTitle; }
62
+ set subSections(subSections) { this._subSections = subSections; }
63
+ set subSectionsObj(subSectionsObj) { this._subSectionsObj = subSectionsObj; }
64
+
65
+ activate() {
66
+ if (!this._active) {
67
+ this._active = true;
68
+ this._sectionCode && this._activation.next(this._sectionCode);
69
+ }
70
+ }
71
+
72
+ inactivate() {
73
+ if (this._active) {
74
+ this._active = false;
75
+ this._sectionCode && this._inactivation.next(this._sectionCode);
76
+ }
77
+ }
78
+
79
+ get title() { return this._sectionTitle; }
80
+ set title(title) { this._sectionTitle = title; }
81
+
82
+ getVisibleSubsections(state) {
83
+ return this._subSections.filter(subSection => subSection.visible);
84
+ }
85
+
86
+ getSubsection(subSectionCode) {
87
+ return (this._subSectionsObj && this._subSectionsObj[subSectionCode])
88
+ ? this._subSectionsObj[subSectionCode] : null;
89
+ }
90
+
91
+ activateSubSection(subSectionCode) {
92
+ if (subSectionCode === this._exclusiveSubSectionsByAttr[ACTIVE]) { return; }
93
+ const subSection = (this._subSectionsObj && this._subSectionsObj[subSectionCode])
94
+ ? this._subSectionsObj[subSectionCode] : null;
95
+ if (subSection) {
96
+ subSection?.activate();
97
+ this._exclusiveSubSectionsByAttr[ACTIVE] = subSectionCode;
98
+ }
99
+ }
100
+
101
+ getFields() {
102
+ let fieldsArray: any[] = [];
103
+ if (this._subSections && this._subSections.length > 0) {
104
+ for (const subSection of this._subSections) {
105
+ const subsectionFields: any[] = subSection.getFields() ?? [];
106
+ if (subsectionFields?.length > 0) {
107
+ fieldsArray = fieldsArray.concat(subsectionFields);
108
+ }
109
+ }
110
+ }
111
+ return fieldsArray;
112
+ }
113
+
114
+ getActions(): FormAction[] {
115
+ let actionArray: any[] = [];
116
+ if (this._subSections && this._subSections.length > 0) {
117
+ for (const subSection of this._subSections) {
118
+ const subSectionActions = subSection.getActions() ?? [];
119
+ if (subSectionActions?.length > 0) {
120
+ actionArray = actionArray.concat(subSectionActions);
121
+ }
122
+ }
123
+ }
124
+ return actionArray;
125
+ }
126
+
127
+ getActionNames(): string[] {
128
+ let actionArray: string[] = [];
129
+ if (this._subSections && this._subSections.length > 0) {
130
+ for (const subSection of this._subSections) {
131
+ actionArray = actionArray.concat(subSection.getActionNames());
132
+ }
133
+ }
134
+ return actionArray;
135
+ }
136
+
137
+ getFieldNames() {
138
+ let fieldsArray: string[] = [];
139
+ if (this._subSections && this._subSections.length > 0) {
140
+ for (const subSection of this._subSections) {
141
+ fieldsArray = fieldsArray.concat(subSection.getFieldNames());
142
+ }
143
+ }
144
+ return fieldsArray;
145
+ }
146
+
147
+ getField(name) {
148
+ let field = null;
149
+ if (this._subSections && this._subSections.length > 0) {
150
+ for (const subSection of this._subSections) {
151
+ field = subSection.getField(name);
152
+ if (field) {
153
+ return field;
154
+ }
155
+ }
156
+ }
157
+ return null;
158
+ }
159
+
160
+ override formStateChangeCustomSubscribe(form, formChangeSubject) {
161
+ this._subSections?.forEach(subsection => {
162
+ subsection?.connectWithParentForm(form, formChangeSubject);
163
+ });
164
+ }
165
+ }
@@ -0,0 +1,109 @@
1
+ import { FormPiecePropagate } from './piece-propagate';
2
+ import { FormAction } from './action';
3
+ import { elementTypes } from './form.constants';
4
+
5
+ export class RecordFormSubSection extends FormPiecePropagate {
6
+ private _customRender: string | null = null;
7
+ private _subsectionId: string | null = null;
8
+ private _subsectionCode: string | null = null;
9
+ private _subsectionTitle: string | null = null;
10
+ private _subSectionElements: any[] = [];
11
+ private _subSectionFields: any[] = [];
12
+ private _subSectionTables: any[] = [];
13
+ private _subSectionActions: any[] = [];
14
+ private _elementsArray: any = {};
15
+ private _active = false;
16
+
17
+ constructor(subsectionReceived, formObject, formConfig) {
18
+ super(subsectionReceived, formConfig);
19
+ this.propagationCustomAttributes = this._formConfig?.propagationCustomAttributes?.subsections ?? [];
20
+ if (!subsectionReceived) { return; }
21
+ this._subsectionId = (subsectionReceived.subsectionId) ? subsectionReceived.subsectionId.toString() : '';
22
+ this._subsectionCode = (subsectionReceived.subsectionCode) ? subsectionReceived.subsectionCode : '';
23
+ this._subsectionTitle = (subsectionReceived.subsectionTitle) ? subsectionReceived.subsectionTitle : '';
24
+ if (subsectionReceived.elements) {
25
+ for (const receivedElement of subsectionReceived.elements) {
26
+ let elementObject: any = null;
27
+ let arrayToAdd: any[] = [];
28
+ const { type, code } = receivedElement;
29
+ switch (type) {
30
+ case elementTypes.field:
31
+ elementObject = formObject.getField(code);
32
+ arrayToAdd = this._subSectionFields;
33
+ break;
34
+ case elementTypes.table:
35
+ elementObject = formObject.getTable(code);
36
+ arrayToAdd = this._subSectionTables;
37
+ break;
38
+ case elementTypes.action:
39
+ elementObject = formObject.getAction(code);
40
+ arrayToAdd = this._subSectionActions;
41
+ break;
42
+ }
43
+ if (elementObject) {
44
+ elementObject.elementType = type;
45
+ arrayToAdd.push(elementObject);
46
+ this._subSectionElements.push(elementObject);
47
+ this._elementsArray[code] = elementObject;
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ get customRender() { return this._customRender; }
54
+ set customRender(customRenderName) { this._customRender = customRenderName; }
55
+
56
+ get subsectionId() { return this._subsectionId; }
57
+ get subsectionCode() { return this._subsectionCode; }
58
+ get subsectionTitle() { return this._subsectionTitle; }
59
+ get subSectionElements() { return this._subSectionElements; }
60
+ get subSectionFields() { return this._subSectionFields; }
61
+ get subSectionTables() { return this._subSectionTables; }
62
+ get subSectionActions() { return this._subSectionActions; }
63
+ get elementsArray() { return this._elementsArray; }
64
+ get active() { return this._active; }
65
+
66
+ set subsectionId(subsectionId) { this._subsectionId = subsectionId; }
67
+ set subsectionCode(subsectionCode) { this._subsectionCode = subsectionCode; }
68
+ set subsectionTitle(subsectionTitle) { this._subsectionTitle = subsectionTitle; }
69
+ set subSectionElements(subSectionElements) { this._subSectionElements = subSectionElements; }
70
+ set subSectionFields(subSectionFields) { this._subSectionFields = subSectionFields; }
71
+ set subSectionTables(subSectionTables) { this._subSectionTables = subSectionTables; }
72
+ set subSectionActions(subSectionActions) { this._subSectionActions = subSectionActions; }
73
+ set elementsArray(elementsArray) { this._elementsArray = elementsArray; }
74
+ set active(active) { this._active = active; }
75
+
76
+ getField(name) {
77
+ return this._subSectionFields.find(fld => fld.name === name);
78
+ }
79
+
80
+ getFields() {
81
+ return this._subSectionFields;
82
+ }
83
+
84
+ getFieldNames() {
85
+ return this._subSectionFields.map(field => field.code);
86
+ }
87
+
88
+ getActions(): FormAction[] {
89
+ return this._subSectionActions;
90
+ }
91
+
92
+ getActionNames(): string[] {
93
+ return this._subSectionActions.map(action => action.actionCode);
94
+ }
95
+
96
+ activate() {
97
+ if (!this._active) {
98
+ this._active = true;
99
+ // this.subsectionCode && this._activation.next(this.subsectionCode);
100
+ }
101
+ }
102
+
103
+ inactivate() {
104
+ if (this._active) {
105
+ this._active = false;
106
+ // this.subsectionCode && this._inactivation.next(this.subsectionCode);
107
+ }
108
+ }
109
+ }
@@ -0,0 +1,41 @@
1
+ import { FormPiece } from '../piece';
2
+ export class TableAction extends FormPiece {
3
+ actionCode: string;
4
+ actionTitle: string;
5
+ iconName: string;
6
+ actionType: string;
7
+ actionClass: string;
8
+ stateField: string;
9
+ newState: string;
10
+ backend: boolean;
11
+
12
+ restrictedOnField: string | null = null;
13
+ restrictedOnValue: string | null = null;
14
+ restrictedOnOperator: string | null = null;
15
+
16
+ constructor(actionDefinition, formConfig) {
17
+ super(actionDefinition, formConfig);
18
+
19
+ this.actionCode = actionDefinition.actionCode;
20
+ this.actionTitle = actionDefinition.actionTitle;
21
+ this.iconName = actionDefinition.iconName || this.actionCode;
22
+ this.actionType = actionDefinition.actionType || 'STANDARD';
23
+ this.actionClass = actionDefinition.actionClass || 'INLINE';
24
+ this.newState = actionDefinition.newState;
25
+ this.stateField = actionDefinition.stateField || '';
26
+ this.backend = actionDefinition?.serverAction ?? false;
27
+ this.restrictedOnField = actionDefinition.fieldRestrictedCode ?? null;
28
+ if (this.restrictedOnField) {
29
+ this.restrictedOnValue = actionDefinition.valueRestricted ?? null;
30
+ this.restrictedOnOperator = actionDefinition.operatorRestricted || null;
31
+ }
32
+ }
33
+
34
+ override formStateChange(state) {
35
+ if (state) {
36
+ this._formState = state;
37
+ this._visible = this._absoluteVisible && this.viewOnState(state);
38
+ this._disabled = this._absoluteDisabled || !this.enabledOnState(state);
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,94 @@
1
+ import { FormPiece } from '../piece';
2
+
3
+ export interface FilterDef {
4
+ operators: string[];
5
+ options: any[];
6
+ }
7
+
8
+ export interface FilterSetup {
9
+ fieldCode: string;
10
+ operator: string;
11
+ values: any[];
12
+ }
13
+ export class RecordTableColumn extends FormPiece {
14
+ fieldCode: string = '';
15
+ fieldTitle: string = '';
16
+ fieldType: string = '';
17
+ fieldAlignment: string = '';
18
+ fieldFormat: string = '';
19
+ sortable: boolean = true;
20
+ searchable: boolean = true;
21
+ sortDirections: string[] = [];
22
+ // Filtros
23
+ filterVisible: boolean = false;
24
+ filterDef: FilterDef | null = null;
25
+ filterSetup: FilterSetup | null = null;
26
+
27
+ constructor(recTableColReceived, formConfig) {
28
+ super(recTableColReceived, formConfig);
29
+ this.filterDef = null;
30
+ if (recTableColReceived) {
31
+ this.fieldCode = recTableColReceived.fieldCode;
32
+ this.fieldTitle = recTableColReceived.fieldTitle;
33
+ this.fieldType = recTableColReceived.fieldTypeCode || this._formConfig.fieldTypes.text;
34
+ const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this.fieldType] != null) ? this._formConfig.tableFieldStyles[this.fieldType]['text-align'] : 'left';
35
+ this.fieldAlignment = (recTableColReceived.alignment != null) ? recTableColReceived.alignment.toLowerCase() : defaultTypeAlignment;
36
+ this._absoluteVisible = recTableColReceived?.visible ?? true;
37
+ this.sortable = recTableColReceived?.sortable ?? false;
38
+ this.searchable = recTableColReceived?.searchable ?? true;
39
+ this.sortDirections = (this.sortable) ? ['ascend', 'descend'] : [];
40
+ this.fieldFormat = recTableColReceived.format || '';
41
+ this.customAttributes = recTableColReceived?.customAttributes ?? {};
42
+ }
43
+ }
44
+
45
+ setSearchable(searchable = true) { this.searchable = searchable; }
46
+
47
+ hideFilter() {
48
+ this.filterVisible = false;
49
+ }
50
+
51
+ addFilterDefinition(filterDefinition) {
52
+ this.filterDef = {
53
+ operators: filterDefinition.operators,
54
+ options: filterDefinition.options ?? null,
55
+ };
56
+ }
57
+
58
+ get filterDefinition() {
59
+ return this.filterDef;
60
+ }
61
+
62
+ addFilter(columnValues, operator) {
63
+ this.filterSetup = {
64
+ fieldCode: this.fieldCode,
65
+ operator: operator ?? this.filterDef?.operators[0] ?? 'IN',
66
+ values: columnValues,
67
+ }
68
+ }
69
+
70
+ get filter() {
71
+ return this.filterSetup;
72
+ }
73
+
74
+ removeFilter() {
75
+ this.filterSetup = null;
76
+ }
77
+
78
+ get options() {
79
+ if (this.filterDef?.operators?.length === 1 && this.filterDef?.operators[0] === 'IN') {
80
+ return this.filterDef?.options;
81
+ }
82
+ return null;
83
+ }
84
+
85
+ serSortDirections(ascend: boolean, descend: boolean) {
86
+ this.sortDirections = [];
87
+ if (ascend) {
88
+ this.sortDirections.unshift('ascend');
89
+ }
90
+ if (descend) {
91
+ this.sortDirections.unshift('descend');
92
+ }
93
+ }
94
+ }