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.
Files changed (108) hide show
  1. package/esm2020/lib/classes/forms/action.mjs +36 -0
  2. package/esm2020/lib/classes/forms/element.mjs +26 -0
  3. package/esm2020/lib/classes/forms/field.mjs +445 -0
  4. package/esm2020/lib/classes/forms/form.constants.mjs +26 -0
  5. package/esm2020/lib/classes/forms/form.mjs +431 -0
  6. package/esm2020/lib/classes/forms/piece-propagate.mjs +37 -0
  7. package/esm2020/lib/classes/forms/piece.mjs +95 -0
  8. package/esm2020/lib/classes/forms/section.mjs +138 -0
  9. package/esm2020/lib/classes/forms/subsection.mjs +81 -0
  10. package/esm2020/lib/classes/forms/table/action.mjs +18 -0
  11. package/esm2020/lib/classes/forms/table/column.mjs +74 -0
  12. package/esm2020/lib/classes/forms/table/row-data.mjs +116 -0
  13. package/esm2020/lib/classes/forms/table/table.mjs +416 -0
  14. package/esm2020/lib/components/elements/action.component.mjs +71 -0
  15. package/esm2020/lib/components/elements/field.component.mjs +81 -0
  16. package/esm2020/lib/components/elements/layout/element.component.mjs +20 -0
  17. package/esm2020/lib/components/elements/layout/form-error.component.mjs +20 -0
  18. package/esm2020/lib/components/elements/layout/form-header.component.mjs +31 -0
  19. package/esm2020/lib/components/elements/layout/piece.component.mjs +39 -0
  20. package/esm2020/lib/components/elements/layout/section.component.mjs +37 -0
  21. package/esm2020/lib/components/elements/layout/sub-section.component.mjs +37 -0
  22. package/esm2020/lib/components/elements/tables/table-record-action.component.mjs +56 -0
  23. package/esm2020/lib/components/elements/tables/table-record-field.component.mjs +30 -0
  24. package/esm2020/lib/components/elements/tables/table.component.mjs +89 -0
  25. package/esm2020/lib/components/forms/basic-form.mjs +1514 -0
  26. package/esm2020/lib/services/event-manager.service.mjs +18 -0
  27. package/esm2020/lib/services/file-manager.service.mjs +6 -0
  28. package/esm2020/lib/services/form-manager.service.mjs +80 -0
  29. package/esm2020/lib/tuain-ng-forms-lib.module.mjs +71 -0
  30. package/esm2020/public-api.mjs +19 -0
  31. package/esm2020/tuain-ng-forms-lib.mjs +5 -0
  32. package/fesm2015/tuain-ng-forms-lib.mjs +4259 -0
  33. package/fesm2015/tuain-ng-forms-lib.mjs.map +1 -0
  34. package/fesm2020/tuain-ng-forms-lib.mjs +4074 -0
  35. package/fesm2020/tuain-ng-forms-lib.mjs.map +1 -0
  36. package/lib/classes/forms/action.d.ts +22 -0
  37. package/lib/classes/forms/element.d.ts +17 -0
  38. package/lib/classes/forms/field.d.ts +205 -0
  39. package/lib/classes/forms/form.constants.d.ts +25 -0
  40. package/lib/classes/forms/form.d.ts +137 -0
  41. package/lib/classes/forms/piece-propagate.d.ts +13 -0
  42. package/lib/classes/forms/piece.d.ts +41 -0
  43. package/lib/classes/forms/section.d.ts +32 -0
  44. package/lib/classes/forms/subsection.d.ts +24 -0
  45. package/lib/classes/forms/table/action.d.ts +15 -0
  46. package/lib/classes/forms/table/column.d.ts +33 -0
  47. package/lib/classes/forms/table/row-data.d.ts +14 -0
  48. package/lib/classes/forms/table/table.d.ts +100 -0
  49. package/lib/components/elements/action.component.d.ts +17 -0
  50. package/lib/components/elements/field.component.d.ts +38 -0
  51. package/lib/components/elements/layout/element.component.d.ts +9 -0
  52. package/lib/components/elements/layout/form-error.component.d.ts +8 -0
  53. package/lib/components/elements/layout/form-header.component.d.ts +12 -0
  54. package/lib/components/elements/layout/piece.component.d.ts +12 -0
  55. package/lib/components/elements/layout/section.component.d.ts +11 -0
  56. package/lib/components/elements/layout/sub-section.component.d.ts +11 -0
  57. package/lib/components/elements/tables/table-record-action.component.d.ts +16 -0
  58. package/lib/components/elements/tables/table-record-field.component.d.ts +12 -0
  59. package/lib/components/elements/tables/table.component.d.ts +35 -0
  60. package/lib/components/forms/basic-form.d.ts +353 -0
  61. package/lib/services/event-manager.service.d.ts +9 -0
  62. package/lib/services/file-manager.service.d.ts +5 -0
  63. package/lib/services/form-manager.service.d.ts +28 -0
  64. package/lib/tuain-ng-forms-lib.module.d.ts +20 -0
  65. package/package.json +24 -6
  66. package/{src/public-api.ts → public-api.d.ts} +0 -5
  67. package/tuain-ng-forms-lib.d.ts +5 -0
  68. package/.browserslistrc +0 -16
  69. package/.yarn/cache/nanoid-npm-4.0.0-924f5c6312-7d5946df5c.zip +0 -0
  70. package/.yarn/cache/tslib-npm-2.4.1-36f0ed04db-19480d6e03.zip +0 -0
  71. package/.yarn/cache/yn-npm-5.0.0-b001dab23c-f0ec7710d3.zip +0 -0
  72. package/.yarn/install-state.gz +0 -0
  73. package/karma.conf.js +0 -44
  74. package/ng-package.json +0 -11
  75. package/src/lib/classes/forms/action.ts +0 -56
  76. package/src/lib/classes/forms/element.ts +0 -29
  77. package/src/lib/classes/forms/field.ts +0 -500
  78. package/src/lib/classes/forms/form.constants.ts +0 -28
  79. package/src/lib/classes/forms/form.ts +0 -508
  80. package/src/lib/classes/forms/piece-propagate.ts +0 -46
  81. package/src/lib/classes/forms/piece.ts +0 -122
  82. package/src/lib/classes/forms/section.ts +0 -152
  83. package/src/lib/classes/forms/subsection.ts +0 -90
  84. package/src/lib/classes/forms/table/action.ts +0 -32
  85. package/src/lib/classes/forms/table/column.ts +0 -94
  86. package/src/lib/classes/forms/table/row-data.ts +0 -121
  87. package/src/lib/classes/forms/table/table.ts +0 -478
  88. package/src/lib/components/elements/action.component.ts +0 -59
  89. package/src/lib/components/elements/field.component.ts +0 -92
  90. package/src/lib/components/elements/layout/element.component.ts +0 -13
  91. package/src/lib/components/elements/layout/form-error.component.ts +0 -11
  92. package/src/lib/components/elements/layout/form-header.component.ts +0 -17
  93. package/src/lib/components/elements/layout/piece.component.ts +0 -34
  94. package/src/lib/components/elements/layout/section.component.ts +0 -31
  95. package/src/lib/components/elements/layout/sub-section.component.ts +0 -31
  96. package/src/lib/components/elements/tables/table-record-action.component.ts +0 -50
  97. package/src/lib/components/elements/tables/table-record-field.component.ts +0 -20
  98. package/src/lib/components/elements/tables/table.component.ts +0 -86
  99. package/src/lib/components/forms/basic-form.ts +0 -1588
  100. package/src/lib/services/event-manager.service.ts +0 -21
  101. package/src/lib/services/file-manager.service.ts +0 -6
  102. package/src/lib/services/form-manager.service.ts +0 -89
  103. package/src/lib/services/icon-dictionary.service.ts +0 -159
  104. package/src/lib/tuain-ng-forms-lib.module.ts +0 -40
  105. package/src/test.ts +0 -27
  106. package/tsconfig.lib.json +0 -15
  107. package/tsconfig.lib.prod.json +0 -10
  108. package/tsconfig.spec.json +0 -17
@@ -1,122 +0,0 @@
1
- import { BehaviorSubject } from 'rxjs';
2
-
3
- export class FormPiece {
4
- protected _formState: string = '';
5
- protected _visibleForced: boolean;
6
- protected _isForced: boolean;
7
- protected _absoluteVisible: boolean = true;
8
- protected _absoluteDisabled: boolean = false;
9
-
10
- protected visibleStates: string[] | null = null;
11
- protected enabledStates: string[] | null = null;
12
-
13
- public _formConfig: any;
14
- public _visible: boolean = true;
15
- public _disabled: boolean = false;
16
- public customAttributes: any = {};
17
-
18
- constructor(pieceDefinition: any, formConfig: any) {
19
- this._formConfig = formConfig;
20
- this._isForced = false;
21
- this._visibleForced = false;
22
- this.setVisibleStates(pieceDefinition.visibleStates);
23
- this.setEnabledStates(pieceDefinition.enabledStates);
24
-
25
- this.enabled = !pieceDefinition?.disabled ?? false;
26
- this.setVisibility(pieceDefinition?.visible ?? true);
27
- this.customAttributes = pieceDefinition?.customAttributes ?? {};
28
- if (pieceDefinition?.customAttributes) {
29
- Object.keys(pieceDefinition?.customAttributes)
30
- ?.forEach(attr => this.customAttributes[attr] = pieceDefinition?.customAttributes[attr])
31
- }
32
- }
33
-
34
- getCustomAttribute(name: string): any { return this.customAttributes?.[name] ?? null; }
35
- setCustomAttribute(name: string, value: any): void { if (name) { this.customAttributes[name] = value; } }
36
-
37
- setCustomAttributes(attributes: any): void {
38
- Object.entries(attributes).forEach(([name, value]) => {
39
- this.setCustomAttribute(name, value);
40
- });
41
- }
42
-
43
- matchAttribute(name: string, value: string): boolean { return this.customAttributes?.[name] === value; }
44
-
45
- setVisibleStates(newStates: any): void {
46
- const visibleStates = (!Array.isArray(newStates) && typeof newStates === 'string')
47
- ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
48
- : newStates;
49
- this.visibleStates = (Array.isArray(visibleStates)) ? visibleStates : [];
50
- }
51
-
52
- setEnabledStates(newStates: any): void {
53
- const enabledStates = (!Array.isArray(newStates) && typeof newStates === 'string')
54
- ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
55
- : newStates;
56
- this.enabledStates = (Array.isArray(enabledStates)) ? enabledStates : [];
57
- }
58
-
59
- viewOnState(state: string): boolean { return (this.visibleStates && state) ? this.visibleStates.includes(state) : false; }
60
- enabledOnState(state: string): boolean { return (this.enabledStates && state) ? this.enabledStates.includes(state) : false; }
61
-
62
- get absoluteVisible(): boolean { return this._absoluteVisible; }
63
- get absoluteDisabled(): boolean { return this._absoluteDisabled; }
64
-
65
- get visible(): boolean { return this._visible; }
66
- set visible(visible: boolean) { this.setVisibility(visible); }
67
-
68
- visibleOn(state: string): boolean {
69
- return this._absoluteVisible && this.viewOnState(state);
70
- }
71
-
72
- enabledOn(state: string): boolean {
73
- return !this._absoluteDisabled && this.enabledOnState(state);
74
- }
75
-
76
- setVisibility(visible: boolean, forced: boolean | null = null): void {
77
- this._absoluteVisible = !!visible;
78
- if (forced !== null) {
79
- this._isForced = forced;
80
- this._visibleForced = visible;
81
- }
82
- this._visible = this._absoluteVisible && this.viewOnState(this._formState);
83
- }
84
-
85
- show(forced: boolean | null = null): void {
86
- this.setVisibility(true, forced);
87
- }
88
-
89
- hide(forced: boolean | null = null): void {
90
- this.setVisibility(false, forced);
91
- }
92
-
93
- get enabled(): boolean { return !this._disabled; }
94
- set enabled(enabled) {
95
- this._absoluteDisabled = !enabled;
96
- this._disabled = this._absoluteDisabled || !this.enabledOnState(this._formState);
97
- }
98
-
99
- get editable(): boolean { return !this._disabled; }
100
-
101
- get disabled(): boolean { return this._disabled; }
102
-
103
- set disabled(disabled) { this.enabled = !disabled; }
104
-
105
- enable(): void { this.enabled = true; }
106
- disable(): void { this.enabled = false; }
107
-
108
- formStateChangeCustomSubscribe(formChangeSubject) { }
109
-
110
- formStateChange(state) {
111
- if (state) {
112
- this._formState = state;
113
- this._visible = this._absoluteVisible && this.viewOnState(state);
114
- this._disabled = this._absoluteDisabled || !this.enabledOnState(state);
115
- }
116
- }
117
-
118
- subscribeFormStateChange(formChangeSubject) {
119
- this.formStateChangeCustomSubscribe(formChangeSubject);
120
- formChangeSubject.subscribe(event => this.formStateChange(event?.state));
121
- }
122
- }
@@ -1,152 +0,0 @@
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
-
12
- active = false;
13
- sectionId: string | null = null;
14
- sectionCode: string | null = null;
15
- sectionTitle: string | null = null;
16
- subSections: RecordFormSubSection[] = [];
17
- subSectionsObj: any;
18
- private _exclusiveSubSectionsByAttr = {};
19
-
20
- constructor(sectionReceived, formObject, formConfig) {
21
- super(sectionReceived, formConfig);
22
- this.propagationCustomAttributes = this._formConfig?.propagationCustomAttributes?.sections ?? [];
23
- if (!sectionReceived) { return; }
24
- this.sectionId = (sectionReceived.sectionId) ? sectionReceived.sectionId.toString() : '';
25
- this.sectionCode = (sectionReceived.sectionCode) ? sectionReceived.sectionCode : '';
26
- this.sectionTitle = (sectionReceived.sectionTitle) ? sectionReceived.sectionTitle : '';
27
- this.subSections = [];
28
- this.subSectionsObj = {};
29
- if (sectionReceived.subsections) {
30
- const subsections = sectionReceived.subsections.map(subSecDef => {
31
- const visibleStates = subSecDef.visibleStates ?? [];
32
- if (subSecDef.elements && Array.isArray(subSecDef.elements)) {
33
- subSecDef.elements = subSecDef.elements.map(elm => ({ code: elm.elementCode, type: elm.elementTypeName }));
34
- }
35
- return { ...subSecDef, visibleStates };
36
- });
37
- for (const subsectionReceived of subsections) {
38
- const subSectionToAdd = new RecordFormSubSection(subsectionReceived, formObject, formConfig);
39
- const subsectionCode = subSectionToAdd.subsectionCode;
40
- if (subsectionCode) {
41
- this.subSections.push(subSectionToAdd);
42
- this.subSectionsObj[subsectionCode] = subSectionToAdd;
43
- }
44
- }
45
- }
46
- }
47
-
48
- get code() { return this.sectionCode; }
49
- get activation() { return this._activation; }
50
- get inactivation() { return this._inactivation; }
51
-
52
- activate() {
53
- if (!this.active) {
54
- this.active = true;
55
- this.sectionCode && this._activation.next(this.sectionCode);
56
- }
57
- }
58
-
59
- inactivate() {
60
- if (this.active) {
61
- this.active = false;
62
- this.sectionCode && this._inactivation.next(this.sectionCode);
63
- }
64
- }
65
-
66
- get title() { return this.sectionTitle; }
67
- set title(title) { this.sectionTitle = title; }
68
-
69
- getVisibleSubsections(state) {
70
- return this.subSections.filter(subSection => subSection.visible);
71
- }
72
-
73
- getSubsection(subSectionCode) {
74
- return (this.subSectionsObj && this.subSectionsObj[subSectionCode])
75
- ? this.subSectionsObj[subSectionCode] : null;
76
- }
77
-
78
- activateSubSection(subSectionCode) {
79
- if (subSectionCode === this._exclusiveSubSectionsByAttr[ACTIVE]) { return; }
80
- const subSection = (this.subSectionsObj && this.subSectionsObj[subSectionCode])
81
- ? this.subSectionsObj[subSectionCode] : null;
82
- if (subSection) {
83
- subSection?.activate();
84
- this._exclusiveSubSectionsByAttr[ACTIVE] = subSectionCode;
85
- }
86
- }
87
-
88
- getFields() {
89
- let fieldsArray: any[] = [];
90
- if (this.subSections && this.subSections.length > 0) {
91
- for (const subSection of this.subSections) {
92
- const subsectionFields: any[] = subSection.getFields() ?? [];
93
- if (subsectionFields?.length > 0) {
94
- fieldsArray = fieldsArray.concat(subsectionFields);
95
- }
96
- }
97
- }
98
- return fieldsArray;
99
- }
100
-
101
- getActions(): FormAction[] {
102
- let actionArray: any[] = [];
103
- if (this.subSections && this.subSections.length > 0) {
104
- for (const subSection of this.subSections) {
105
- const subSectionActions = subSection.getActions() ?? [];
106
- if (subSectionActions?.length > 0) {
107
- actionArray = actionArray.concat(subSectionActions);
108
- }
109
- }
110
- }
111
- return actionArray;
112
- }
113
-
114
- getActionNames(): string[] {
115
- let actionArray: string[] = [];
116
- if (this.subSections && this.subSections.length > 0) {
117
- for (const subSection of this.subSections) {
118
- actionArray = actionArray.concat(subSection.getActionNames());
119
- }
120
- }
121
- return actionArray;
122
- }
123
-
124
- getFieldNames() {
125
- let fieldsArray: string[] = [];
126
- if (this.subSections && this.subSections.length > 0) {
127
- for (const subSection of this.subSections) {
128
- fieldsArray = fieldsArray.concat(subSection.getFieldNames());
129
- }
130
- }
131
- return fieldsArray;
132
- }
133
-
134
- getField(name) {
135
- let field = null;
136
- if (this.subSections && this.subSections.length > 0) {
137
- for (const subSection of this.subSections) {
138
- field = subSection.getField(name);
139
- if (field) {
140
- return field;
141
- }
142
- }
143
- }
144
- return null;
145
- }
146
-
147
- override formStateChangeCustomSubscribe(formChangeSubject) {
148
- this.subSections?.forEach(subsection => {
149
- subsection?.subscribeFormStateChange(formChangeSubject);
150
- });
151
- }
152
- }
@@ -1,90 +0,0 @@
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
- _customRender: string | null = null;
7
- subsectionId: string | null = null;
8
- subsectionCode: string | null = null;
9
- subsectionTitle: string | null = null;
10
-
11
- subSectionElements: any[] = [];
12
- subSectionFields: any[] = [];
13
- subSectionTables: any[] = [];
14
- subSectionActions: any[] = [];
15
- elementsArray: any = {};
16
- active = false;
17
-
18
- constructor(subsectionReceived, formObject, formConfig) {
19
- super(subsectionReceived, formConfig);
20
- this.propagationCustomAttributes = this._formConfig?.propagationCustomAttributes?.subsections ?? [];
21
- if (!subsectionReceived) { return; }
22
- this.subsectionId = (subsectionReceived.subsectionId) ? subsectionReceived.subsectionId.toString() : '';
23
- this.subsectionCode = (subsectionReceived.subsectionCode) ? subsectionReceived.subsectionCode : '';
24
- this.subsectionTitle = (subsectionReceived.subsectionTitle) ? subsectionReceived.subsectionTitle : '';
25
- if (subsectionReceived.elements) {
26
- for (const receivedElement of subsectionReceived.elements) {
27
- let elementObject: any = null;
28
- let arrayToAdd: any[] = [];
29
- const { type, code } = receivedElement;
30
- switch (type) {
31
- case elementTypes.field:
32
- elementObject = formObject.getField(code);
33
- arrayToAdd = this.subSectionFields;
34
- break;
35
- case elementTypes.table:
36
- elementObject = formObject.getTable(code);
37
- arrayToAdd = this.subSectionTables;
38
- break;
39
- case elementTypes.action:
40
- elementObject = formObject.getAction(code);
41
- arrayToAdd = this.subSectionActions;
42
- break;
43
- }
44
- if (elementObject) {
45
- elementObject.elementType = type;
46
- arrayToAdd.push(elementObject);
47
- this.subSectionElements.push(elementObject);
48
- this.elementsArray[code] = elementObject;
49
- }
50
- }
51
- }
52
- }
53
-
54
- get customRender() { return this._customRender; }
55
- set customRender(customRenderName) { this._customRender = customRenderName; }
56
-
57
- getField(name) {
58
- return this.subSectionFields.find(fld => fld.name === name);
59
- }
60
-
61
- getFields() {
62
- return this.subSectionFields;
63
- }
64
-
65
- getFieldNames() {
66
- return this.subSectionFields.map(field => field.code);
67
- }
68
-
69
- getActions(): FormAction[] {
70
- return this.subSectionActions;
71
- }
72
-
73
- getActionNames(): string[] {
74
- return this.subSectionActions.map(action => action.actionCode);
75
- }
76
-
77
- activate() {
78
- if (!this.active) {
79
- this.active = true;
80
- // this.subsectionCode && this._activation.next(this.subsectionCode);
81
- }
82
- }
83
-
84
- inactivate() {
85
- if (this.active) {
86
- this.active = false;
87
- // this.subsectionCode && this._inactivation.next(this.subsectionCode);
88
- }
89
- }
90
- }
@@ -1,32 +0,0 @@
1
- import { FormPiece } from '../piece';
2
- export class TableAction extends FormPiece {
3
- newState: string;
4
-
5
- actionCode: string;
6
- actionTitle: string;
7
- iconName: string;
8
- actionType: string;
9
- actionClass: string;
10
- stateField: string;
11
-
12
- backend: boolean;
13
- restrictedOnField: string;
14
- restrictedOnValue: string;
15
- restrictedOnOperator: string;
16
-
17
- constructor(actionDefinition, formConfig) {
18
- super(actionDefinition, formConfig);
19
-
20
- this.actionCode = actionDefinition.actionCode;
21
- this.actionTitle = actionDefinition.actionTitle;
22
- this.iconName = actionDefinition.iconName || this.actionCode;
23
- this.actionType = actionDefinition.actionType || 'STANDARD';
24
- this.actionClass = actionDefinition.actionClass || 'INLINE';
25
- this.newState = actionDefinition.newState;
26
- this.stateField = actionDefinition.stateField || '';
27
- this.backend = actionDefinition?.serverAction ?? false;
28
- this.restrictedOnField = actionDefinition.fieldRestrictedCode || '';
29
- this.restrictedOnValue = actionDefinition.valueRestricted ?? '';
30
- this.restrictedOnOperator = actionDefinition.operatorRestricted || '';
31
- }
32
- }
@@ -1,94 +0,0 @@
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],
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
- }
@@ -1,121 +0,0 @@
1
- import { RecordTableColumn } from './column';
2
- import { operators } from '../form.constants';
3
-
4
- export class TableRecordData {
5
- recordId: string | null = null;
6
- selected: boolean = false;
7
- recordData: any = {};
8
-
9
- constructor(recordReceived, recordDefinition: RecordTableColumn[], selectionFieldName = null) {
10
- const { tableRecordId, recordData } = recordReceived;
11
- this.recordId = tableRecordId;
12
- if (!recordDefinition || recordDefinition.length === 0 || !recordData || recordData.length === 0) {
13
- return;
14
- }
15
- const fieldNames = recordDefinition.map(column => column.fieldCode);
16
- if (Array.isArray(recordData)) {
17
- const rawRecordData = recordData.filter(fieldData => fieldData.fieldCode && fieldNames.includes(fieldData.fieldCode));
18
- rawRecordData.forEach(fieldData => {
19
- const { fieldCode, fieldValue } = fieldData;
20
- const fieldDef = recordDefinition.find(column => column.fieldCode === fieldCode);
21
- this.recordData[fieldCode] = fieldValue ?? '';
22
- if (fieldCode === selectionFieldName) {
23
- this.selected = fieldValue;
24
- }
25
- });
26
- } else {
27
- const fields = Object.keys(recordData);
28
- fields.forEach(fieldCode => {
29
- const fieldValue = recordData[fieldCode];
30
- const fieldDef = recordDefinition.find(column => column.fieldCode === fieldCode);
31
- this.recordData[fieldCode] = fieldValue ?? '';
32
- });
33
- }
34
- }
35
-
36
- toggleSelect() { this.selected = !this.selected; }
37
- select() { this.selected = true; }
38
- unselect() { this.selected = false; }
39
-
40
- get recordIdKey() {
41
- return (typeof this.recordId === 'object')
42
- ? JSON.stringify(this.recordId) : this.recordId;
43
- }
44
-
45
- getFieldValue(fieldCode): any {
46
- return (fieldCode && this.recordData) ? this.recordData[fieldCode] : null;
47
- }
48
-
49
- hasPattern(words, columnObj) {
50
- if (!words || words.length === 0) {
51
- return true;
52
- }
53
- for (const word of words) {
54
- let wordIsPresent = false;
55
- for (const fieldCode in this.recordData) {
56
- const columnDef = columnObj?.[fieldCode];
57
- if (columnDef?.searchable && this.recordData.hasOwnProperty(fieldCode)) {
58
- const term = word.toUpperCase();
59
- let fieldValue;
60
- if (columnDef.fieldType.toUpperCase().includes('DATE')) {
61
- fieldValue = this.recordData[fieldCode].substring(0, 16);
62
- } else {
63
- fieldValue = this.recordData[fieldCode];
64
- }
65
- if (fieldValue.toString().toUpperCase().includes(term)) {
66
- wordIsPresent = true;
67
- break;
68
- }
69
- }
70
- }
71
- if (!wordIsPresent) {
72
- return false;
73
- }
74
- }
75
- return true;
76
- }
77
-
78
- hasCondition(columnFilters) {
79
- if (!columnFilters || columnFilters.length === 0) {
80
- return true;
81
- }
82
- for (const condition of columnFilters) {
83
- const { fieldCode, operator, values } = condition;
84
- if (this.recordData.hasOwnProperty(fieldCode)) {
85
- const fieldValue = this.recordData[fieldCode];
86
- const stringValue = fieldValue.toString().toUpperCase();
87
- if (operator === operators.G && fieldValue <= values[0]) {
88
- return false;
89
- }
90
- if (operator === operators.L && fieldValue >= values[0]) {
91
- return false;
92
- }
93
- if (operator === operators.GE && fieldValue < values[0]) {
94
- return false;
95
- }
96
- if (operator === operators.LE && fieldValue > values[0]) {
97
- return false;
98
- }
99
- if (operator === operators.IN && !values.includes(fieldValue)) {
100
- return false;
101
- }
102
- if (operator === operators.EQ) {
103
- return fieldValue === values[0];
104
- }
105
- if (operator === operators.NEQ && fieldValue === values[0]) {
106
- return false;
107
- }
108
- if (operator === operators.HAS && !stringValue.includes(values[0].toString().toUpperCase())) {
109
- return false;
110
- }
111
- if (operator === operators.NOTHAS && stringValue.includes(values[0].toString().toUpperCase())) {
112
- return false;
113
- }
114
- if (operator === operators.BETWEEN && (fieldValue < values[0] || fieldValue > values[1])) {
115
- return false;
116
- }
117
- }
118
- }
119
- return true;
120
- }
121
- }