@zeedhi/teknisa-components-common 3.0.0 → 3.0.1
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 +4 -1
- 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/src/error/delete-rows-error.ts +0 -11
- package/tests/unit/components/tek-grid/grid.spec.ts +0 -2701
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { Datasource, IDictionary, IEvent, IEventParam } from '@zeedhi/core';
|
|
2
|
+
import {
|
|
3
|
+
EventDef,
|
|
4
|
+
GridEventsProp,
|
|
5
|
+
IButton,
|
|
6
|
+
IComponent,
|
|
7
|
+
IComponentEvents,
|
|
8
|
+
IComponentRender,
|
|
9
|
+
IGridColumnEditable,
|
|
10
|
+
IGridEditable,
|
|
11
|
+
IGridEditableEvents,
|
|
12
|
+
IGridEditableProps,
|
|
13
|
+
IGridEvent,
|
|
14
|
+
IIterableColumnsButton,
|
|
15
|
+
IModal,
|
|
16
|
+
Iterable,
|
|
17
|
+
} from '@zeedhi/common';
|
|
18
|
+
import { IDynamicFilterItem } from '../tek-datasource/interfaces';
|
|
19
|
+
import { TekGridColumn } from './tek-grid-column';
|
|
20
|
+
|
|
21
|
+
export interface IModalFilterProps extends IModal {
|
|
22
|
+
height?: string;
|
|
23
|
+
maxHeight?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ITekGridLayoutColumn {
|
|
27
|
+
name: string;
|
|
28
|
+
width?: string;
|
|
29
|
+
minWidth?: string;
|
|
30
|
+
maxWidth?: string;
|
|
31
|
+
isVisible?: boolean;
|
|
32
|
+
fixed?: boolean;
|
|
33
|
+
grouped?: boolean;
|
|
34
|
+
aggregation?: ITekGridColumnAggregation;
|
|
35
|
+
label?: string;
|
|
36
|
+
align?: 'left' | 'right' | 'center';
|
|
37
|
+
groupOpened?: boolean;
|
|
38
|
+
filterHelperValue?: string | IDictionary<any>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ITekGridLayout {
|
|
42
|
+
name: string;
|
|
43
|
+
gridWidth?: string;
|
|
44
|
+
columns?: ITekGridLayoutColumn[];
|
|
45
|
+
order?: string[];
|
|
46
|
+
dynamicFilter?: IDictionary<IDynamicFilterItem[]>;
|
|
47
|
+
filter?: IDictionary<any>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ITekGridLayoutInfo {
|
|
51
|
+
currentLayoutName?: string;
|
|
52
|
+
layouts?: IDictionary<ITekGridLayout>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ITekGridLayoutEventParams extends IEventParam<ITekGrid> {
|
|
56
|
+
layouts: ITekGridLayoutInfo;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ITekGridSummary {
|
|
60
|
+
sum: any;
|
|
61
|
+
avg: any;
|
|
62
|
+
count: number;
|
|
63
|
+
min: any;
|
|
64
|
+
max: any;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ITekGridCalcSummaryEventParams extends IEventParam<ITekGrid> {
|
|
68
|
+
summary: ITekGridSummary;
|
|
69
|
+
columnName: string;
|
|
70
|
+
rowValue: IDictionary<any>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ITekGridProps extends IGridEditableProps, Partial<ISupportsToolbar>, Partial<IExportable> {
|
|
74
|
+
events?: TekGridEventsProp;
|
|
75
|
+
groupsOpened?: boolean;
|
|
76
|
+
showSummaryTotal?: boolean;
|
|
77
|
+
mainGrid?: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ITekGrid
|
|
81
|
+
extends IGridEditable<TekGridColumn>,
|
|
82
|
+
ITekGridEvents,
|
|
83
|
+
ISupportsToolbar,
|
|
84
|
+
IExportable,
|
|
85
|
+
IGroupedDataManager {
|
|
86
|
+
events: TekGridEventsProp;
|
|
87
|
+
groupsOpened: boolean;
|
|
88
|
+
showSummaryTotal: boolean;
|
|
89
|
+
mainGrid: boolean;
|
|
90
|
+
columnHasFilter: (columnName: string) => boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface ISupportsToolbar {
|
|
94
|
+
actions: IComponentRender[];
|
|
95
|
+
addButton: boolean;
|
|
96
|
+
columnsButton: boolean;
|
|
97
|
+
columnsButtonIgnore: string[];
|
|
98
|
+
deleteButton: 'none' | 'currentRow' | 'selection';
|
|
99
|
+
showEditButtons: boolean;
|
|
100
|
+
filterButton: boolean;
|
|
101
|
+
showSearch: boolean;
|
|
102
|
+
showLayoutOptions: boolean;
|
|
103
|
+
title: string;
|
|
104
|
+
showExport: boolean;
|
|
105
|
+
showReload: boolean;
|
|
106
|
+
exportConfig: ITekGridExportConfig[];
|
|
107
|
+
exportActions?: IComponentRender[];
|
|
108
|
+
toolbarOpened: boolean;
|
|
109
|
+
columnFilterButton: boolean;
|
|
110
|
+
modalFilterProps: IModalFilterProps;
|
|
111
|
+
showCheckboxAllFilter: boolean;
|
|
112
|
+
defaultFilter: IDictionary;
|
|
113
|
+
editNewRowsOnly: boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface IExportable {
|
|
117
|
+
reportTitle: string;
|
|
118
|
+
xlsDefaultType?: string;
|
|
119
|
+
getReport(type: string, portrait?: boolean, rowObj?: any): Promise<Window | null>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type IAsyncEvent<T> = (event: T) => Promise<any>;
|
|
123
|
+
|
|
124
|
+
export interface TekGridEventsProp<
|
|
125
|
+
T = IGridEvent | IEventParam<any> | ITekGridLayoutEventParams | ITekGridCalcSummaryEventParams,
|
|
126
|
+
> extends GridEventsProp<T> {
|
|
127
|
+
addClick?: EventDef<T>;
|
|
128
|
+
afterCancel?: EventDef<T>;
|
|
129
|
+
afterDelete?: EventDef<T>;
|
|
130
|
+
afterSave?: EventDef<T>;
|
|
131
|
+
beforeApplyFilter?: EventDef<T>;
|
|
132
|
+
beforeCancel?: EventDef<T>;
|
|
133
|
+
beforeDelete?: EventDef<T>;
|
|
134
|
+
beforeSave?: EventDef<T>;
|
|
135
|
+
calcSummary?: EventDef<T>;
|
|
136
|
+
filterClick?: EventDef<T>;
|
|
137
|
+
loadLayouts?: EventDef<T, IAsyncEvent<T>>;
|
|
138
|
+
saveLayouts?: EventDef<T>;
|
|
139
|
+
groupRowClick?: EventDef<T>;
|
|
140
|
+
groupSelect?: EventDef<T>;
|
|
141
|
+
groupUnselect?: EventDef<T>;
|
|
142
|
+
beforeReload?: EventDef<T>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type MultiOptionParams = {
|
|
146
|
+
iconName: string;
|
|
147
|
+
label: string;
|
|
148
|
+
cssClass?: string;
|
|
149
|
+
reportParams?: { portrait?: boolean; rowObj?: any };
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export interface ITekGridExportConfig {
|
|
153
|
+
type: string;
|
|
154
|
+
portrait?: boolean;
|
|
155
|
+
label?: string;
|
|
156
|
+
iconName?: string;
|
|
157
|
+
multiOption?: MultiOptionParams[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface ITekGridEvents extends IGridEditableEvents {
|
|
161
|
+
rowDoubleClick(row: IDictionary<any>, event: Event, element?: HTMLElement): void;
|
|
162
|
+
groupRowClick(row: IDictionary<any>, event: Event, element?: HTMLElement): void;
|
|
163
|
+
groupRowDoubleClick(row: IDictionary<any>, event: Event, element?: HTMLElement): void;
|
|
164
|
+
selectGroupClick(row: IDictionary<any>, isSelected: boolean, event: Event, element?: HTMLElement): void;
|
|
165
|
+
calcSummary(column: TekGridColumn, summary: ITekGridSummary, row: IDictionary): void;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export type IFilterRelation = 'AND' | 'OR';
|
|
169
|
+
|
|
170
|
+
export type IFilterOperation =
|
|
171
|
+
| 'CONTAINS'
|
|
172
|
+
| 'NOT_CONTAINS'
|
|
173
|
+
| 'EQUALS'
|
|
174
|
+
| 'NOT_EQUALS'
|
|
175
|
+
| 'GREATER_THAN'
|
|
176
|
+
| 'LESS_THAN'
|
|
177
|
+
| 'GREATER_THAN_EQUALS'
|
|
178
|
+
| 'LESS_THAN_EQUALS'
|
|
179
|
+
| 'IN'
|
|
180
|
+
| 'NOT_IN'
|
|
181
|
+
| 'BETWEEN';
|
|
182
|
+
|
|
183
|
+
export interface IFilterPropsComponent extends IComponent {
|
|
184
|
+
relation?: IFilterRelation;
|
|
185
|
+
operation?: IFilterOperation;
|
|
186
|
+
helperOptions?: string[];
|
|
187
|
+
helperValue?: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
type Narrowable = string | number | boolean | symbol | object | void | null | undefined;
|
|
191
|
+
const tuple = <T extends Narrowable[]>(...args: T) => args;
|
|
192
|
+
export const columnAggregationValues = tuple('SUM', 'MIN', 'MAX', 'AVG', 'COUNT', undefined);
|
|
193
|
+
|
|
194
|
+
export type ITekGridColumnAggregation = (typeof columnAggregationValues)[number];
|
|
195
|
+
|
|
196
|
+
export interface ITekGridColumn extends IGridColumnEditable {
|
|
197
|
+
filterProps?: IFilterPropsComponent | IFilterPropsComponent[];
|
|
198
|
+
filterable?: boolean;
|
|
199
|
+
filterIndex?: number;
|
|
200
|
+
skipLookupSearch?: boolean;
|
|
201
|
+
grouped?: boolean;
|
|
202
|
+
aggregation?: ITekGridColumnAggregation;
|
|
203
|
+
groupOpened?: boolean;
|
|
204
|
+
groupLabelForEmptyValue?: string;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface IColumnsSearcher {
|
|
208
|
+
searchColumn(columns: ITekGridColumn[], search: string): Promise<IDictionary<(string | number)[]>>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface IGroupedDataManager {
|
|
212
|
+
initializeGrouping(lazyLoad: boolean): void;
|
|
213
|
+
updateGrouping: (lazyLoad?: boolean) => void;
|
|
214
|
+
updateGroupedData(lazyLoad: boolean): Promise<void>;
|
|
215
|
+
buildGroupedData(): void;
|
|
216
|
+
openGroup(group: IDictionary<any>): void;
|
|
217
|
+
isItemVisible(row: IDictionary<any>): any;
|
|
218
|
+
isGrouped(): boolean;
|
|
219
|
+
isColumnSearchable(column: TekGridColumn): boolean;
|
|
220
|
+
getGroupedData(): IDictionary<any>[];
|
|
221
|
+
directionalLeft(param: IEventParam<any>): void;
|
|
222
|
+
directionalRight(param: IEventParam<any>): void;
|
|
223
|
+
loadAfterTasks(): Promise<void>;
|
|
224
|
+
registerTask(task: Promise<any>): void;
|
|
225
|
+
setViewUpdateFixedColumns(fn: () => void): void;
|
|
226
|
+
setViewUpdateScrollData(fn: () => void): void;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface ITekGridGroupHeader {
|
|
230
|
+
group: boolean;
|
|
231
|
+
groupRow: IDictionary;
|
|
232
|
+
groupColumnName: string;
|
|
233
|
+
groupHeader: boolean;
|
|
234
|
+
groupIndex: number;
|
|
235
|
+
groupLabel: string;
|
|
236
|
+
groupValue: any;
|
|
237
|
+
groupOpened: boolean;
|
|
238
|
+
groupHeaders: ITekGridGroupHeader[]; // parent group headers
|
|
239
|
+
children: IDictionary<any>[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface ITekGridGroupFooter {
|
|
243
|
+
groupFooter: boolean;
|
|
244
|
+
groupIndex: number;
|
|
245
|
+
groupHeaders: ITekGridGroupHeader[];
|
|
246
|
+
groupLabel: string;
|
|
247
|
+
groupValue: any;
|
|
248
|
+
[key: string]: any;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface ITekGridFooter {
|
|
252
|
+
[key: string]: ITekGridSummary;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface ITekGridGroup {
|
|
256
|
+
column: ITekGridColumn;
|
|
257
|
+
name: string;
|
|
258
|
+
label: string;
|
|
259
|
+
lastValue: any;
|
|
260
|
+
footer: ITekGridFooter;
|
|
261
|
+
initialized: boolean;
|
|
262
|
+
lastGroupHeaderRow?: ITekGridGroupHeader;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface ITekGridAtoms {
|
|
266
|
+
TITLE: string;
|
|
267
|
+
HIDE_BUTTON: string;
|
|
268
|
+
ADD_BUTTON: string;
|
|
269
|
+
DELETE_BUTTON: string;
|
|
270
|
+
REFRESH_BUTTON: string;
|
|
271
|
+
COLUMNS_BUTTON: string;
|
|
272
|
+
LAYOUT_BUTTON: string;
|
|
273
|
+
EXPORT_BUTTON: string;
|
|
274
|
+
ACTIONS_BUTTON: string;
|
|
275
|
+
SAVE_BUTTON: string;
|
|
276
|
+
CANCEL_BUTTON: string;
|
|
277
|
+
SEARCH: string;
|
|
278
|
+
FILTER_BUTTON: string;
|
|
279
|
+
FILTER_MODAL: string;
|
|
280
|
+
FILTER_FORM: string;
|
|
281
|
+
EXPORT_DROPDOWN: string;
|
|
282
|
+
ACTIONS_DROPDOWN: string;
|
|
283
|
+
HIDE_TOOLTIP: string;
|
|
284
|
+
TOOLBAR_DIV: string;
|
|
285
|
+
NOT_EDITING_SPAN: string;
|
|
286
|
+
ADD_TOOLTIP: string;
|
|
287
|
+
DELETE_TOOLTIP: string;
|
|
288
|
+
DIVIDER1: string;
|
|
289
|
+
REFRESH_TOOLTIP: string;
|
|
290
|
+
DIVIDER2: string;
|
|
291
|
+
COLUMNS_TOOLTIP: string;
|
|
292
|
+
DIVIDER_ACTIONS: string;
|
|
293
|
+
DIVIDER3: string;
|
|
294
|
+
FILTER_TOOLTIP: string;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface ITekGridToolbarProvider {
|
|
298
|
+
getProperties(): IComponentRender[];
|
|
299
|
+
getAtomInstance<T>(key: keyof ITekGridAtoms): T;
|
|
300
|
+
getAtomName(key: keyof ITekGridAtoms): string;
|
|
301
|
+
// getFilterInputs(columnName?: string): Input[];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface IDynamicFilterDatasourceFactory {
|
|
305
|
+
factory(options: IDictionary<boolean>): Datasource;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export type ITekGridLayoutOptionsEvent<T> = (event: T) => Promise<any>;
|
|
309
|
+
|
|
310
|
+
export interface ITekGridLayoutOptionsEvents<T = IEventParam<any> | ITekGridLayoutEventParams>
|
|
311
|
+
extends IComponentEvents<T> {
|
|
312
|
+
loadLayouts?: IAsyncEvent<T>;
|
|
313
|
+
saveLayouts?: IEvent<T>;
|
|
314
|
+
[key: string]: any;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export interface ITekGridLayoutOptions extends IComponentRender {
|
|
318
|
+
events?: ITekGridLayoutOptionsEvents;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface ITekGridFilterButton extends IButton {
|
|
322
|
+
gridName?: string;
|
|
323
|
+
grid?: Iterable & ISupportsToolbar;
|
|
324
|
+
showCheckboxAll?: boolean;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export interface ITekGridColumnsButton extends IIterableColumnsButton {
|
|
328
|
+
hideGroups?: boolean;
|
|
329
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IKeyMap } from '@zeedhi/core';
|
|
2
|
+
import { Component, IKeyMapConfig } from '@zeedhi/common';
|
|
3
|
+
import { IGroupedDataManager } from './interfaces';
|
|
4
|
+
|
|
5
|
+
export class KeyMapGrouped implements IKeyMapConfig<IGroupedDataManager> {
|
|
6
|
+
getMap(instance: Component & IGroupedDataManager): IKeyMap {
|
|
7
|
+
return {
|
|
8
|
+
left: {
|
|
9
|
+
event: instance.directionalLeft.bind(instance),
|
|
10
|
+
stop: true,
|
|
11
|
+
active: true,
|
|
12
|
+
},
|
|
13
|
+
right: {
|
|
14
|
+
event: instance.directionalRight.bind(instance),
|
|
15
|
+
stop: true,
|
|
16
|
+
active: true,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { Config, Http, IDictionary } from '@zeedhi/core';
|
|
2
|
+
import { Column, ComponentRender, Iterable } from '@zeedhi/common';
|
|
3
|
+
import { ITekConfig } from '../../utils/config/config';
|
|
4
|
+
import {
|
|
5
|
+
ITekGridLayout,
|
|
6
|
+
ITekGridLayoutColumn,
|
|
7
|
+
ITekGridLayoutInfo,
|
|
8
|
+
ITekGridLayoutOptions,
|
|
9
|
+
ITekGridLayoutOptionsEvents,
|
|
10
|
+
} from './interfaces';
|
|
11
|
+
import { IDynamicFilterItem } from '../tek-datasource/interfaces';
|
|
12
|
+
import { TekGrid } from './tek-grid';
|
|
13
|
+
import { TekGridColumn } from './tek-grid-column';
|
|
14
|
+
|
|
15
|
+
export class TekGridLayoutOptions extends ComponentRender implements ITekGridLayoutOptions {
|
|
16
|
+
public currentLayoutName = '';
|
|
17
|
+
|
|
18
|
+
public layoutEdited = false;
|
|
19
|
+
|
|
20
|
+
public layouts: IDictionary<ITekGridLayout> = {};
|
|
21
|
+
|
|
22
|
+
public layoutNames: string[] = [];
|
|
23
|
+
|
|
24
|
+
public viewApplyLayout?: (layout?: ITekGridLayout) => void;
|
|
25
|
+
|
|
26
|
+
public viewGetCurrentLayout?: (layoutName: string) => {
|
|
27
|
+
name: string;
|
|
28
|
+
gridWidth: any;
|
|
29
|
+
order: any;
|
|
30
|
+
filter: any;
|
|
31
|
+
dynamicFilter: any;
|
|
32
|
+
columns: any;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
public originalColumnProps: ITekGridLayoutColumn[] = [];
|
|
36
|
+
|
|
37
|
+
public originalDatasourceOrder: string[] = [];
|
|
38
|
+
|
|
39
|
+
public originalDatasourceDynamicFilter: IDictionary<IDynamicFilterItem[]> = {};
|
|
40
|
+
|
|
41
|
+
public originalDatasourceFilter: IDictionary<any> = {};
|
|
42
|
+
|
|
43
|
+
/* Grid events */
|
|
44
|
+
public declare events: ITekGridLayoutOptionsEvents;
|
|
45
|
+
|
|
46
|
+
public grid!: Iterable<TekGridColumn>;
|
|
47
|
+
|
|
48
|
+
private getParentGrid() {
|
|
49
|
+
let { parent } = this;
|
|
50
|
+
while (parent && !(parent.constructor === Iterable || parent.constructor.prototype instanceof Iterable)) {
|
|
51
|
+
parent = parent.parent;
|
|
52
|
+
}
|
|
53
|
+
return parent as Iterable<TekGridColumn>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public async onMounted(element: HTMLElement) {
|
|
57
|
+
super.onMounted(element);
|
|
58
|
+
this.grid = this.getParentGrid();
|
|
59
|
+
|
|
60
|
+
this.originalDatasourceOrder = [...this.grid.datasource.order];
|
|
61
|
+
this.originalDatasourceDynamicFilter = {
|
|
62
|
+
...(this.grid.datasource as any).dynamicFilter,
|
|
63
|
+
};
|
|
64
|
+
this.originalDatasourceFilter = { ...this.grid.datasource.filter };
|
|
65
|
+
this.originalColumnProps = this.grid.columns.map((column: any) => ({
|
|
66
|
+
name: column.name,
|
|
67
|
+
label: column.label,
|
|
68
|
+
align: column.align,
|
|
69
|
+
isVisible: column.isVisible,
|
|
70
|
+
minWidth: column.minWidth,
|
|
71
|
+
maxWidth: column.maxWidth,
|
|
72
|
+
width: column.width,
|
|
73
|
+
fixed: column.fixed,
|
|
74
|
+
grouped: column.grouped,
|
|
75
|
+
groupOpened: column.groupOpened,
|
|
76
|
+
aggregation: column.aggregation,
|
|
77
|
+
filterHelperValue: this.getHelperValue(column),
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
let layoutsInfo: ITekGridLayoutInfo = {};
|
|
81
|
+
|
|
82
|
+
const promise = this.loadLayoutsInfo();
|
|
83
|
+
|
|
84
|
+
if (this.grid instanceof TekGrid) {
|
|
85
|
+
this.grid.registerTask(promise);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
layoutsInfo = await promise;
|
|
89
|
+
if (layoutsInfo.layouts) {
|
|
90
|
+
this.layouts = layoutsInfo.layouts;
|
|
91
|
+
this.layoutNames = Object.keys(this.layouts);
|
|
92
|
+
if (layoutsInfo.currentLayoutName) {
|
|
93
|
+
this.currentLayoutName = layoutsInfo.currentLayoutName;
|
|
94
|
+
this.applyLayout(this.currentLayoutName, false);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected async loadLayoutsInfo() {
|
|
100
|
+
const eventFunction = this.events.loadLayouts || this.grid.events.loadLayouts;
|
|
101
|
+
|
|
102
|
+
if (eventFunction && typeof eventFunction === 'function') {
|
|
103
|
+
return eventFunction({ component: this.grid });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if ((Config as ITekConfig).loadGridLayoutsEndPoint) {
|
|
107
|
+
const route = (Config as ITekConfig).loadGridLayoutsEndPoint!;
|
|
108
|
+
const response = await Http.get(`${route}?id=${this.grid.name}`);
|
|
109
|
+
const responseData = response.data.data;
|
|
110
|
+
return responseData.length && responseData[0] ? responseData[0].layouts : responseData.layouts || {};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return JSON.parse(localStorage.getItem(this.grid.name) || '{}');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public getHelperValue(column: Column) {
|
|
117
|
+
if (column instanceof TekGridColumn) {
|
|
118
|
+
if (!Array.isArray(column.filterProps)) return column.filterProps.helperValue;
|
|
119
|
+
return column.filterProps.map((prop) => prop.helperValue);
|
|
120
|
+
}
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public newLayout(layout: ITekGridLayout) {
|
|
125
|
+
this.fixColumns(layout);
|
|
126
|
+
this.currentLayoutName = layout.name;
|
|
127
|
+
this.addLayout(layout);
|
|
128
|
+
this.layoutEdited = false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public addLayout(layout: ITekGridLayout) {
|
|
132
|
+
this.fixColumns(layout);
|
|
133
|
+
this.layouts[layout.name] = layout;
|
|
134
|
+
|
|
135
|
+
this.saveLayouts();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public discardChanges() {
|
|
139
|
+
const layoutSelected = this.layouts[this.currentLayoutName];
|
|
140
|
+
|
|
141
|
+
if (this.viewApplyLayout) {
|
|
142
|
+
this.viewApplyLayout(layoutSelected);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this.layoutEdited = false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public applyLayout(name: string, save = true) {
|
|
149
|
+
this.currentLayoutName = name;
|
|
150
|
+
const layoutSelected = this.layouts[name];
|
|
151
|
+
|
|
152
|
+
if (this.viewApplyLayout) {
|
|
153
|
+
this.viewApplyLayout(layoutSelected);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (save) {
|
|
157
|
+
this.saveLayouts();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this.layoutEdited = false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private saveLayouts() {
|
|
164
|
+
this.layoutNames = Object.keys(this.layouts);
|
|
165
|
+
|
|
166
|
+
const layoutInfo: ITekGridLayoutInfo = {
|
|
167
|
+
currentLayoutName: this.currentLayoutName,
|
|
168
|
+
layouts: this.layouts,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const eventFunction = this.events.saveLayouts || this.grid.events.saveLayouts;
|
|
172
|
+
if (eventFunction && typeof eventFunction === 'function') {
|
|
173
|
+
eventFunction({ component: this.grid, layouts: layoutInfo });
|
|
174
|
+
} else if ((Config as ITekConfig).saveGridLayoutsEndPoint) {
|
|
175
|
+
const route = (Config as ITekConfig).saveGridLayoutsEndPoint!;
|
|
176
|
+
Http.post(route, { id: this.grid.name, layouts: layoutInfo });
|
|
177
|
+
} else {
|
|
178
|
+
localStorage.setItem(this.grid.name, JSON.stringify(layoutInfo));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public deleteLayout(name: string) {
|
|
183
|
+
if (this.currentLayoutName === name) {
|
|
184
|
+
this.currentLayoutName = '';
|
|
185
|
+
this.applyLayout(this.currentLayoutName, false);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
delete this.layouts[name];
|
|
189
|
+
|
|
190
|
+
this.saveLayouts();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public updateLayout(name: string, layout: ITekGridLayout) {
|
|
194
|
+
this.fixColumns(layout);
|
|
195
|
+
this.currentLayoutName = name;
|
|
196
|
+
layout.name = name;
|
|
197
|
+
this.layouts[layout.name] = layout;
|
|
198
|
+
|
|
199
|
+
this.saveLayouts();
|
|
200
|
+
|
|
201
|
+
this.layoutEdited = false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public updateDefaultLayout(layout: ITekGridLayout) {
|
|
205
|
+
this.fixColumns(layout);
|
|
206
|
+
this.originalDatasourceOrder = layout.order || this.originalDatasourceOrder;
|
|
207
|
+
this.originalDatasourceDynamicFilter = layout.dynamicFilter || this.originalDatasourceDynamicFilter;
|
|
208
|
+
this.originalDatasourceFilter = layout.filter || this.originalDatasourceFilter;
|
|
209
|
+
if (layout.columns) {
|
|
210
|
+
this.originalColumnProps = layout.columns.map((column: any) => {
|
|
211
|
+
const originalColumnIdx = this.originalColumnProps.findIndex((item) => item.name === column.name);
|
|
212
|
+
const originalColumn = originalColumnIdx !== -1 ? this.originalColumnProps[originalColumnIdx] : {};
|
|
213
|
+
return {
|
|
214
|
+
...originalColumn,
|
|
215
|
+
...column,
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (this.currentLayoutName === '') {
|
|
221
|
+
this.applyLayout(this.currentLayoutName, false);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private fixColumns(layout: ITekGridLayout) {
|
|
226
|
+
const hasLayoutColumns = !!layout.columns;
|
|
227
|
+
layout.columns = layout.columns || [];
|
|
228
|
+
const layoutColumnNames = layout.columns.map((layoutColumn) => layoutColumn.name);
|
|
229
|
+
this.grid.columns.forEach((gridColumn: any) => {
|
|
230
|
+
if (!hasLayoutColumns || layoutColumnNames.indexOf(gridColumn.name) === -1) {
|
|
231
|
+
layout.columns!.push({
|
|
232
|
+
name: gridColumn.name,
|
|
233
|
+
label: gridColumn.label,
|
|
234
|
+
align: gridColumn.align,
|
|
235
|
+
isVisible: !hasLayoutColumns && gridColumn.isVisible,
|
|
236
|
+
width: gridColumn.width,
|
|
237
|
+
minWidth: gridColumn.minWidth,
|
|
238
|
+
maxWidth: gridColumn.maxWidth,
|
|
239
|
+
fixed: gridColumn.fixed,
|
|
240
|
+
grouped: gridColumn.grouped,
|
|
241
|
+
groupOpened: gridColumn.groupOpened,
|
|
242
|
+
aggregation: gridColumn.aggregation,
|
|
243
|
+
filterHelperValue: this.getHelperValue(gridColumn),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|