@zeedhi/teknisa-components-common 3.0.0 → 3.0.2
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/.package.json +5 -2
- package/dist/teknisa-components-common.js +3722 -32
- package/dist/teknisa-components-common.min.js +3722 -32
- package/dist/types/components/index.d.ts +5 -0
- package/dist/types/components/tek-datasource/index.d.ts +3 -0
- package/dist/types/components/tek-datasource/interfaces.d.ts +16 -0
- package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +93 -0
- package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +95 -0
- package/dist/types/components/tek-grid/columns-searcher.d.ts +5 -0
- package/dist/types/components/tek-grid/dynamic-filter-datasource-factory.d.ts +6 -0
- package/dist/types/components/tek-grid/filter-helper.d.ts +7 -0
- package/dist/types/components/tek-grid/grid-filter-button.d.ts +29 -0
- package/dist/types/components/tek-grid/grouped-data-manager.d.ts +82 -0
- package/dist/types/components/tek-grid/grouped-data-selector.d.ts +7 -0
- package/dist/types/components/tek-grid/grouped-view-navigator.d.ts +14 -0
- package/dist/types/components/tek-grid/index.d.ts +18 -0
- package/dist/types/components/tek-grid/interfaces.d.ts +259 -0
- package/dist/types/components/tek-grid/keymap-grouped.d.ts +6 -0
- package/dist/types/components/tek-grid/layout-options.d.ts +39 -0
- package/dist/types/components/tek-grid/tek-grid-column.d.ts +42 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.d.ts +8 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.d.ts +13 -0
- package/dist/types/components/tek-grid/tek-grid-controller.d.ts +31 -0
- package/dist/types/components/tek-grid/tek-grid-events.d.ts +31 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.d.ts +17 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/index.d.ts +3 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.d.ts +5 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.d.ts +12 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/index.d.ts +2 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.d.ts +22 -0
- package/dist/types/components/tek-grid/tek-grid.d.ts +216 -0
- package/dist/types/components/tek-user-info/TekUserInfoController.d.ts +22 -0
- package/dist/types/components/tek-user-info/interfaces.d.ts +27 -0
- package/dist/types/components/tek-user-info/tek-user-info-list.d.ts +32 -0
- package/dist/types/components/tek-user-info/tek-user-info.d.ts +37 -0
- package/dist/types/error/tek-grid-delete-rows-error.d.ts +7 -0
- package/dist/types/error/teknisa-common-error.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/config/config.d.ts +7 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/is-filled-object/is-filled-object.d.ts +2 -0
- package/dist/types/utils/is-nil.d.ts +1 -0
- package/package.json +2 -2
- package/src/components/index.ts +5 -12
- package/src/components/tek-datasource/index.ts +3 -0
- package/src/components/tek-datasource/interfaces.ts +36 -0
- package/src/components/tek-datasource/tek-memory-datasource.ts +314 -0
- package/src/components/tek-datasource/tek-rest-datasource.ts +224 -0
- package/src/components/tek-grid/columns-searcher.ts +22 -0
- package/src/components/tek-grid/dynamic-filter-datasource-factory.ts +20 -0
- package/src/components/tek-grid/filter-helper.ts +20 -0
- package/src/components/tek-grid/grid-filter-button.ts +419 -0
- package/src/components/tek-grid/grouped-data-manager.ts +448 -0
- package/src/components/tek-grid/grouped-data-selector.ts +40 -0
- package/src/components/tek-grid/grouped-view-navigator.ts +84 -0
- package/src/components/tek-grid/index.ts +18 -0
- package/src/components/tek-grid/interfaces.ts +329 -0
- package/src/components/tek-grid/keymap-grouped.ts +20 -0
- package/src/components/tek-grid/layout-options.ts +248 -0
- package/src/components/tek-grid/tek-grid-column.ts +193 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.ts +28 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.ts +38 -0
- package/src/components/tek-grid/tek-grid-controller.ts +140 -0
- package/src/components/tek-grid/tek-grid-events.ts +105 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.ts +26 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/index.ts +3 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.ts +6 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.ts +85 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/index.ts +2 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.ts +365 -0
- package/src/components/tek-grid/tek-grid.ts +1118 -0
- package/src/components/tek-user-info/TekUserInfoController.ts +87 -0
- package/src/components/tek-user-info/interfaces.ts +21 -0
- package/src/components/tek-user-info/tek-user-info-list.ts +64 -0
- package/src/components/tek-user-info/tek-user-info.ts +337 -0
- package/src/error/tek-grid-delete-rows-error.ts +15 -0
- package/src/error/teknisa-common-error.ts +8 -0
- package/src/index.ts +1 -0
- package/src/utils/config/config.ts +8 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/is-filled-object/is-filled-object.ts +5 -0
- package/src/utils/is-nil.ts +3 -0
- package/tests/unit/components/tek-grid/button-option.spec.ts +49 -0
- package/tests/unit/components/tek-grid/columns-searcher.spec.ts +112 -0
- package/tests/unit/components/tek-grid/dynamic-filter-datasource-factory.spec.ts +90 -0
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +34 -130
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +110 -241
- package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +593 -0
- package/tests/unit/components/tek-grid/grouped-data-selector.spec.ts +136 -0
- package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +244 -0
- package/tests/unit/components/tek-grid/keymap-grouped.spec.ts +20 -0
- package/tests/unit/components/tek-grid/{layout_options.spec.ts → layout-options.spec.ts} +77 -35
- package/tests/unit/components/tek-grid/multi-option.spec.ts +139 -0
- package/tests/unit/components/tek-grid/{grid-column.spec.ts → tek-grid-column.spec.ts} +48 -6
- package/tests/unit/components/tek-grid/{grid-columns-button.spec.ts → tek-grid-columns-button.spec.ts} +42 -9
- package/tests/unit/components/tek-grid/tek-grid-controller.spec.ts +253 -0
- package/tests/unit/components/tek-grid/tek-grid-events.spec.ts +186 -0
- package/tests/unit/components/tek-grid/tek-grid-toolbar-provider.spec.ts +34 -0
- package/tests/unit/components/tek-grid/tek-grid.spec.ts +895 -0
- package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +482 -0
- package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +422 -0
- package/dist/types/error/delete-rows-error.d.ts +0 -6
- package/src/error/delete-rows-error.ts +0 -11
- package/tests/unit/components/tek-grid/grid.spec.ts +0 -2701
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { IDictionary, IEventParam, Metadata } from '@zeedhi/core';
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
Form,
|
|
5
|
+
IModal,
|
|
6
|
+
Input,
|
|
7
|
+
Iterable,
|
|
8
|
+
Modal,
|
|
9
|
+
ModalService,
|
|
10
|
+
} from '@zeedhi/common';
|
|
11
|
+
import { ISupportsToolbar, ITekGridColumn, ITekGridFilterButton } from './interfaces';
|
|
12
|
+
import { TekGridColumn } from './tek-grid-column';
|
|
13
|
+
import { TekMemoryDatasource, TekRestDatasource } from '../tek-datasource';
|
|
14
|
+
import { TekFilterHelper } from './filter-helper';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Base class for TekGrid Filter Button component
|
|
18
|
+
*/
|
|
19
|
+
export class TekGridFilterButton extends Button implements ITekGridFilterButton {
|
|
20
|
+
public gridName?: string;
|
|
21
|
+
|
|
22
|
+
public grid: Iterable<TekGridColumn> & ISupportsToolbar;
|
|
23
|
+
|
|
24
|
+
public showCheckboxAll = false;
|
|
25
|
+
|
|
26
|
+
private filterModal?: Modal;
|
|
27
|
+
|
|
28
|
+
protected filterFormInputs: IDictionary<string[]> = {};
|
|
29
|
+
|
|
30
|
+
constructor(props: ITekGridFilterButton) {
|
|
31
|
+
super(props);
|
|
32
|
+
this.gridName = this.getInitValue('gridName', props.gridName, this.gridName);
|
|
33
|
+
this.grid = this.getInitValue('grid', props.grid, undefined);
|
|
34
|
+
this.showCheckboxAll = this.getInitValue('showCheckboxAll', props.showCheckboxAll, this.showCheckboxAll);
|
|
35
|
+
this.createAccessors();
|
|
36
|
+
|
|
37
|
+
if (!this.grid) this.loadGrid();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public loadGrid(gridName?: string) {
|
|
41
|
+
if (gridName) this.gridName = gridName;
|
|
42
|
+
if (!this.gridName) return;
|
|
43
|
+
|
|
44
|
+
this.grid = Metadata.getInstances(this.gridName)[0];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public click(event?: Event) {
|
|
48
|
+
this.callEvent('click', { component: this, event });
|
|
49
|
+
this.grid.callEvent('filterClick', { component: this.grid, event });
|
|
50
|
+
if (!event?.defaultPrevented) {
|
|
51
|
+
this.createFilterFromColumns.call(this);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private loadFilterValues({ component }: IEventParam<Form>) {
|
|
56
|
+
const changedCompNames: string[] = [];
|
|
57
|
+
|
|
58
|
+
const { datasource } = this.grid;
|
|
59
|
+
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
60
|
+
const { dynamicFilter } = datasource;
|
|
61
|
+
|
|
62
|
+
const newDynamicFilter = { ...this.grid.defaultFilter, ...dynamicFilter };
|
|
63
|
+
|
|
64
|
+
Object.keys(newDynamicFilter).forEach((column) => {
|
|
65
|
+
if (newDynamicFilter[column] && newDynamicFilter[column].length > 0) {
|
|
66
|
+
newDynamicFilter[column].forEach((filterItem: any, index: number) => {
|
|
67
|
+
const relation = filterItem.relation || 'AND';
|
|
68
|
+
const operation = filterItem.operation || 'CONTAINS';
|
|
69
|
+
const compName = `${this.grid!.name}-filter-${relation}-${operation}-${column}-${index}`;
|
|
70
|
+
changedCompNames.push(compName);
|
|
71
|
+
component.value[compName] = filterItem.value;
|
|
72
|
+
|
|
73
|
+
let helperValue = '';
|
|
74
|
+
const columnObj = this.grid!.getColumn(column);
|
|
75
|
+
if (columnObj instanceof TekGridColumn) {
|
|
76
|
+
const { filterProps } = columnObj;
|
|
77
|
+
if (!Array.isArray(filterProps)) {
|
|
78
|
+
helperValue = filterProps.helperValue || '';
|
|
79
|
+
} else {
|
|
80
|
+
filterProps.forEach((prop) => {
|
|
81
|
+
if ((prop.relation || 'AND') === relation && (prop.operation || 'CONTAINS') === operation) {
|
|
82
|
+
helperValue = prop.helperValue || '';
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const inputObj = Metadata.getInstances(compName);
|
|
87
|
+
if (helperValue && inputObj.length && inputObj[0]) {
|
|
88
|
+
(inputObj[0] as Input).hint = TekFilterHelper.getLabel(helperValue);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
const { filter } = datasource;
|
|
96
|
+
|
|
97
|
+
const newFilter = { ...this.grid.defaultFilter, ...filter };
|
|
98
|
+
|
|
99
|
+
Object.keys(newFilter).forEach((item) => {
|
|
100
|
+
if (newFilter[item]) {
|
|
101
|
+
const compName = `${this.grid!.name}-filter-AND-CONTAINS-${item}-0`;
|
|
102
|
+
changedCompNames.push(compName);
|
|
103
|
+
component.value[compName] = newFilter[item];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
Object.keys(component.value).forEach((compName: string) => {
|
|
109
|
+
if (changedCompNames.indexOf(compName) === -1) {
|
|
110
|
+
component.value[compName] = null;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public hideFilterModal() {
|
|
116
|
+
this.filterModal!.hide();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public destroyFilterModal() {
|
|
120
|
+
if (this.filterModal) this.filterModal!.destroy();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private createFilterFromColumns() {
|
|
124
|
+
if (!this.filterModal) {
|
|
125
|
+
const originalProps = {
|
|
126
|
+
height: 'auto',
|
|
127
|
+
maxHeight: '18.75rem',
|
|
128
|
+
persistent: true,
|
|
129
|
+
title: 'FILTER',
|
|
130
|
+
};
|
|
131
|
+
const mergeModalFilterProps = Object.assign(originalProps, this.grid.modalFilterProps);
|
|
132
|
+
const filterModalDef: IModal = {
|
|
133
|
+
name: `${this.grid.name}-filter-modal`,
|
|
134
|
+
persistent: mergeModalFilterProps.persistent,
|
|
135
|
+
grid: mergeModalFilterProps.grid,
|
|
136
|
+
cssClass: mergeModalFilterProps.cssClass,
|
|
137
|
+
cssStyle: mergeModalFilterProps.cssStyle,
|
|
138
|
+
draggable: mergeModalFilterProps.draggable,
|
|
139
|
+
dragHandle: mergeModalFilterProps.dragHandle,
|
|
140
|
+
fullscreen: mergeModalFilterProps.fullscreen,
|
|
141
|
+
light: mergeModalFilterProps.light,
|
|
142
|
+
dark: mergeModalFilterProps.dark,
|
|
143
|
+
escKeydownStop: false,
|
|
144
|
+
children: [
|
|
145
|
+
{
|
|
146
|
+
name: `${this.grid.name}-filter-header-container`,
|
|
147
|
+
component: 'ZdContainer',
|
|
148
|
+
cssClass: 'zd-pa-0 zd-display-flex',
|
|
149
|
+
children: [
|
|
150
|
+
{
|
|
151
|
+
name: `${this.grid.name}-filter-title`,
|
|
152
|
+
component: 'ZdText',
|
|
153
|
+
cssStyle: `color: ${'var(--v-primary-base);'}`,
|
|
154
|
+
text: mergeModalFilterProps.title,
|
|
155
|
+
tag: 'h3',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: `${this.grid.name}-filter-spacer`,
|
|
159
|
+
component: 'VSpacer',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: `${this.grid.name}-filter-close-button`,
|
|
163
|
+
component: 'ZdModalCloseButton',
|
|
164
|
+
small: true,
|
|
165
|
+
modalName: `${this.grid.name}-filter-modal`,
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: `${this.grid.name}-filter-content-container`,
|
|
171
|
+
component: 'ZdContainer',
|
|
172
|
+
scrollView: true,
|
|
173
|
+
cssClass: 'zd-my-2 zd-pa-0 tek-grid-filter-content-container',
|
|
174
|
+
maxHeight: mergeModalFilterProps!.maxHeight,
|
|
175
|
+
height: mergeModalFilterProps!.height,
|
|
176
|
+
children: [
|
|
177
|
+
{
|
|
178
|
+
name: `${this.grid.name}-filter-form`,
|
|
179
|
+
component: 'ZdForm',
|
|
180
|
+
cssClass: 'zd-my-2 zd-pa-0',
|
|
181
|
+
children: this.getFilterModalComponents(),
|
|
182
|
+
events: {
|
|
183
|
+
onMounted: this.loadFilterValues.bind(this),
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: `${this.grid.name}-filter-footer-container`,
|
|
190
|
+
component: 'ZdContainer',
|
|
191
|
+
cssClass: 'zd-pa-0',
|
|
192
|
+
children: [
|
|
193
|
+
{
|
|
194
|
+
name: `${this.grid.name}-filter-footer`,
|
|
195
|
+
component: 'ZdFooter',
|
|
196
|
+
color: 'transparent',
|
|
197
|
+
padless: true,
|
|
198
|
+
leftSlot: [
|
|
199
|
+
{
|
|
200
|
+
name: `${this.grid.name}-filter-clearButton`,
|
|
201
|
+
component: 'ZdButton',
|
|
202
|
+
label: 'CLEAR',
|
|
203
|
+
outline: true,
|
|
204
|
+
events: {
|
|
205
|
+
click: this.clearFilter.bind(this),
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
rightSlot: [
|
|
210
|
+
{
|
|
211
|
+
name: `${this.grid.name}-filter-cancelButton`,
|
|
212
|
+
component: 'ZdButton',
|
|
213
|
+
label: 'CANCEL',
|
|
214
|
+
keyMap: {
|
|
215
|
+
esc: {
|
|
216
|
+
event: this.hideFilterModal.bind(this),
|
|
217
|
+
focus: true,
|
|
218
|
+
visible: true,
|
|
219
|
+
input: true,
|
|
220
|
+
stop: true,
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
outline: true,
|
|
224
|
+
events: {
|
|
225
|
+
click: this.hideFilterModal.bind(this),
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: `${this.grid.name}-filter-okButton`,
|
|
230
|
+
component: 'ZdButton',
|
|
231
|
+
label: 'OK',
|
|
232
|
+
events: {
|
|
233
|
+
click: this.applyFilter.bind(this),
|
|
234
|
+
},
|
|
235
|
+
keyMap: {
|
|
236
|
+
'mod+enter': {
|
|
237
|
+
event: this.applyFilter.bind(this),
|
|
238
|
+
focus: true,
|
|
239
|
+
input: true,
|
|
240
|
+
stop: true,
|
|
241
|
+
visible: true,
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
this.filterModal = ModalService.create(filterModalDef);
|
|
253
|
+
} else {
|
|
254
|
+
this.loadFilterValues({ component: Metadata.getInstance(`${this.grid.name}-filter-form`) });
|
|
255
|
+
}
|
|
256
|
+
this.filterModal.show();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
public onBeforeDestroy() {
|
|
260
|
+
super.onBeforeDestroy();
|
|
261
|
+
this.destroyFilterModal();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private formatFormValue(filterForm: Form) {
|
|
265
|
+
// TODO: add this logic when SelectMultiple is implemented
|
|
266
|
+
// return Object.keys(filterForm.value).reduce((result, item) => {
|
|
267
|
+
// try {
|
|
268
|
+
// const itemInstance = filterForm.getChildInstance<Input>(item);
|
|
269
|
+
// if (!(itemInstance instanceof SelectMultiple) || !itemInstance.checkboxAll) return result;
|
|
270
|
+
// // when selectmultiple with checkboxAll, should either remove it from the filter or
|
|
271
|
+
// // change the value to T, depending on selectAllCompatibilityMode
|
|
272
|
+
// if ((Config as ITekConfig).selectAllCompatibilityMode) {
|
|
273
|
+
// result[item] = 'T';
|
|
274
|
+
// return result;
|
|
275
|
+
// }
|
|
276
|
+
|
|
277
|
+
// delete result[item];
|
|
278
|
+
// return result;
|
|
279
|
+
// } catch (e) {
|
|
280
|
+
// return result;
|
|
281
|
+
// }
|
|
282
|
+
// }, { ...filterForm.value });
|
|
283
|
+
|
|
284
|
+
return filterForm.value;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private async applyFilter({ event }: any) {
|
|
288
|
+
const filterForm = Metadata.getInstance<Form>(`${this.grid.name}-filter-form`);
|
|
289
|
+
const isFormValid = await filterForm.validate();
|
|
290
|
+
if (isFormValid.valid) {
|
|
291
|
+
const { datasource } = this.grid;
|
|
292
|
+
const filter: IDictionary = {};
|
|
293
|
+
const formValue = this.formatFormValue(filterForm);
|
|
294
|
+
|
|
295
|
+
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
296
|
+
Object.keys(formValue).forEach((item) => {
|
|
297
|
+
const itemValue = formValue[item];
|
|
298
|
+
|
|
299
|
+
if (itemValue && !(Array.isArray(itemValue) && !itemValue.length)) {
|
|
300
|
+
const relationAndOperationAndName = item.split(`${this.grid!.name}-filter-`)[1];
|
|
301
|
+
const [relation, operation] = relationAndOperationAndName.split('-');
|
|
302
|
+
let columnName = relationAndOperationAndName.split(`${relation}-${operation}-`)[1];
|
|
303
|
+
columnName = columnName.split('-').slice(0, -1).join('-'); // remove index
|
|
304
|
+
|
|
305
|
+
if (!filter[columnName]) {
|
|
306
|
+
filter[columnName] = [];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const value = itemValue;
|
|
310
|
+
filter[columnName].push({
|
|
311
|
+
relation,
|
|
312
|
+
operation,
|
|
313
|
+
value,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
datasource.dynamicFilter = filter;
|
|
319
|
+
this.setFilter(filter, event, datasource.setDynamicFilter.bind(datasource));
|
|
320
|
+
} else {
|
|
321
|
+
Object.keys(formValue).forEach((item) => {
|
|
322
|
+
let columnName = item.split(`${this.grid!.name}-filter-AND-CONTAINS-`)[1];
|
|
323
|
+
columnName = columnName.split('-').slice(0, -1).join('-'); // remove index
|
|
324
|
+
|
|
325
|
+
if (formValue[item]) {
|
|
326
|
+
filter[columnName] = formValue[item];
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
datasource.filter = filter;
|
|
331
|
+
this.setFilter(filter, event, datasource.setFilter.bind(datasource));
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
this.grid.changeLayout(event);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
private setFilter(filter: IDictionary, event: Event, filterFn: (filter: IDictionary) => Promise<any>) {
|
|
339
|
+
this.grid.callEvent('beforeApplyFilter', { component: this.grid, event });
|
|
340
|
+
if (event.defaultPrevented) return;
|
|
341
|
+
|
|
342
|
+
filterFn(filter);
|
|
343
|
+
this.hideFilterModal();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private clearFilter() {
|
|
347
|
+
const filterForm = Metadata.getInstance<Form>(`${this.grid!.name}-filter-form`);
|
|
348
|
+
Object.keys(filterForm.value).forEach((item) => {
|
|
349
|
+
filterForm.value[item] = null;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
private sortFilterIndex(col1: ITekGridColumn, col2: ITekGridColumn) {
|
|
354
|
+
const index1 = col1.filterIndex !== undefined ? col1.filterIndex : Number.MAX_SAFE_INTEGER;
|
|
355
|
+
const index2 = col2.filterIndex !== undefined ? col2.filterIndex : Number.MAX_SAFE_INTEGER;
|
|
356
|
+
return index1 - index2;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
private getFilterModalComponents() {
|
|
360
|
+
const filterColumns: ITekGridColumn[] = [];
|
|
361
|
+
let columnComponentName: any;
|
|
362
|
+
[...this.grid.columns].sort(this.sortFilterIndex).forEach((column) => {
|
|
363
|
+
const filterProps = Array.isArray(column.filterProps) ? column.filterProps : [column.filterProps];
|
|
364
|
+
if (column.filterable && filterProps && filterProps.length > 0) {
|
|
365
|
+
this.filterFormInputs[column.name] = [];
|
|
366
|
+
|
|
367
|
+
filterProps.forEach((filterItem, index: number) => {
|
|
368
|
+
const { datasource } = this.grid;
|
|
369
|
+
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
370
|
+
const relation = filterItem.relation || 'AND';
|
|
371
|
+
const operation = filterItem.operation || 'CONTAINS';
|
|
372
|
+
|
|
373
|
+
columnComponentName = `${this.grid!.name}-filter-${relation}-${operation}-${column.name}-${index}`;
|
|
374
|
+
} else {
|
|
375
|
+
columnComponentName = `${this.grid!.name}-filter-AND-CONTAINS-${column.name}-${index}`;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
this.filterFormInputs[column.name].push(columnComponentName);
|
|
379
|
+
|
|
380
|
+
const newColumnComponent = {
|
|
381
|
+
label: column.label,
|
|
382
|
+
...column.componentProps,
|
|
383
|
+
...filterItem,
|
|
384
|
+
name: columnComponentName,
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
if (filterItem.helperOptions) {
|
|
388
|
+
if (!newColumnComponent.events) newColumnComponent.events = {};
|
|
389
|
+
newColumnComponent.events.change = this.changeHelperEvent.bind(this, column);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (newColumnComponent.component === 'ZdSelectMultiple') {
|
|
393
|
+
newColumnComponent.showCheckboxAll = newColumnComponent.showCheckboxAll ?? this.showCheckboxAll;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
filterColumns.push(newColumnComponent);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
return filterColumns;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
private changeHelperEvent(column: TekGridColumn, { component }: any) {
|
|
404
|
+
const { helperValue } = component;
|
|
405
|
+
const componentName = component.name;
|
|
406
|
+
|
|
407
|
+
if (!Array.isArray(column.filterProps)) {
|
|
408
|
+
column.filterProps.helperValue = helperValue;
|
|
409
|
+
} else {
|
|
410
|
+
column.filterProps.forEach((prop) => {
|
|
411
|
+
const relationAndOperationAndName = componentName.split(`${this.grid!.name}-filter-`)[1];
|
|
412
|
+
const [relation, operation] = relationAndOperationAndName.split('-');
|
|
413
|
+
if ((prop.relation || 'AND') === relation && (prop.operation || 'CONTAINS') === operation) {
|
|
414
|
+
prop.helperValue = helperValue;
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|