@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.
Files changed (103) hide show
  1. package/.package.json +4 -1
  2. package/dist/teknisa-components-common.js +3722 -32
  3. package/dist/teknisa-components-common.min.js +3722 -32
  4. package/dist/types/components/index.d.ts +5 -0
  5. package/dist/types/components/tek-datasource/index.d.ts +3 -0
  6. package/dist/types/components/tek-datasource/interfaces.d.ts +16 -0
  7. package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +93 -0
  8. package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +95 -0
  9. package/dist/types/components/tek-grid/columns-searcher.d.ts +5 -0
  10. package/dist/types/components/tek-grid/dynamic-filter-datasource-factory.d.ts +6 -0
  11. package/dist/types/components/tek-grid/filter-helper.d.ts +7 -0
  12. package/dist/types/components/tek-grid/grid-filter-button.d.ts +29 -0
  13. package/dist/types/components/tek-grid/grouped-data-manager.d.ts +82 -0
  14. package/dist/types/components/tek-grid/grouped-data-selector.d.ts +7 -0
  15. package/dist/types/components/tek-grid/grouped-view-navigator.d.ts +14 -0
  16. package/dist/types/components/tek-grid/index.d.ts +18 -0
  17. package/dist/types/components/tek-grid/interfaces.d.ts +259 -0
  18. package/dist/types/components/tek-grid/keymap-grouped.d.ts +6 -0
  19. package/dist/types/components/tek-grid/layout-options.d.ts +39 -0
  20. package/dist/types/components/tek-grid/tek-grid-column.d.ts +42 -0
  21. package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.d.ts +8 -0
  22. package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.d.ts +13 -0
  23. package/dist/types/components/tek-grid/tek-grid-controller.d.ts +31 -0
  24. package/dist/types/components/tek-grid/tek-grid-events.d.ts +31 -0
  25. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.d.ts +17 -0
  26. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/index.d.ts +3 -0
  27. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.d.ts +5 -0
  28. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.d.ts +12 -0
  29. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/index.d.ts +2 -0
  30. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.d.ts +22 -0
  31. package/dist/types/components/tek-grid/tek-grid.d.ts +216 -0
  32. package/dist/types/components/tek-user-info/TekUserInfoController.d.ts +22 -0
  33. package/dist/types/components/tek-user-info/interfaces.d.ts +27 -0
  34. package/dist/types/components/tek-user-info/tek-user-info-list.d.ts +32 -0
  35. package/dist/types/components/tek-user-info/tek-user-info.d.ts +37 -0
  36. package/dist/types/error/tek-grid-delete-rows-error.d.ts +7 -0
  37. package/dist/types/error/teknisa-common-error.d.ts +6 -0
  38. package/dist/types/index.d.ts +1 -0
  39. package/dist/types/utils/config/config.d.ts +7 -0
  40. package/dist/types/utils/index.d.ts +3 -0
  41. package/dist/types/utils/is-filled-object/is-filled-object.d.ts +2 -0
  42. package/dist/types/utils/is-nil.d.ts +1 -0
  43. package/package.json +2 -2
  44. package/src/components/index.ts +5 -12
  45. package/src/components/tek-datasource/index.ts +3 -0
  46. package/src/components/tek-datasource/interfaces.ts +36 -0
  47. package/src/components/tek-datasource/tek-memory-datasource.ts +314 -0
  48. package/src/components/tek-datasource/tek-rest-datasource.ts +224 -0
  49. package/src/components/tek-grid/columns-searcher.ts +22 -0
  50. package/src/components/tek-grid/dynamic-filter-datasource-factory.ts +20 -0
  51. package/src/components/tek-grid/filter-helper.ts +20 -0
  52. package/src/components/tek-grid/grid-filter-button.ts +419 -0
  53. package/src/components/tek-grid/grouped-data-manager.ts +448 -0
  54. package/src/components/tek-grid/grouped-data-selector.ts +40 -0
  55. package/src/components/tek-grid/grouped-view-navigator.ts +84 -0
  56. package/src/components/tek-grid/index.ts +18 -0
  57. package/src/components/tek-grid/interfaces.ts +329 -0
  58. package/src/components/tek-grid/keymap-grouped.ts +20 -0
  59. package/src/components/tek-grid/layout-options.ts +248 -0
  60. package/src/components/tek-grid/tek-grid-column.ts +193 -0
  61. package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.ts +28 -0
  62. package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.ts +38 -0
  63. package/src/components/tek-grid/tek-grid-controller.ts +140 -0
  64. package/src/components/tek-grid/tek-grid-events.ts +105 -0
  65. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.ts +26 -0
  66. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/index.ts +3 -0
  67. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.ts +6 -0
  68. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.ts +85 -0
  69. package/src/components/tek-grid/tek-grid-toolbar-provider/index.ts +2 -0
  70. package/src/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.ts +365 -0
  71. package/src/components/tek-grid/tek-grid.ts +1118 -0
  72. package/src/components/tek-user-info/TekUserInfoController.ts +87 -0
  73. package/src/components/tek-user-info/interfaces.ts +21 -0
  74. package/src/components/tek-user-info/tek-user-info-list.ts +64 -0
  75. package/src/components/tek-user-info/tek-user-info.ts +337 -0
  76. package/src/error/tek-grid-delete-rows-error.ts +15 -0
  77. package/src/error/teknisa-common-error.ts +8 -0
  78. package/src/index.ts +1 -0
  79. package/src/utils/config/config.ts +8 -0
  80. package/src/utils/index.ts +3 -0
  81. package/src/utils/is-filled-object/is-filled-object.ts +5 -0
  82. package/src/utils/is-nil.ts +3 -0
  83. package/tests/unit/components/tek-grid/button-option.spec.ts +49 -0
  84. package/tests/unit/components/tek-grid/columns-searcher.spec.ts +112 -0
  85. package/tests/unit/components/tek-grid/dynamic-filter-datasource-factory.spec.ts +90 -0
  86. package/tests/unit/components/tek-grid/filter-helper.spec.ts +34 -130
  87. package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +110 -241
  88. package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +593 -0
  89. package/tests/unit/components/tek-grid/grouped-data-selector.spec.ts +136 -0
  90. package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +244 -0
  91. package/tests/unit/components/tek-grid/keymap-grouped.spec.ts +20 -0
  92. package/tests/unit/components/tek-grid/{layout_options.spec.ts → layout-options.spec.ts} +77 -35
  93. package/tests/unit/components/tek-grid/multi-option.spec.ts +139 -0
  94. package/tests/unit/components/tek-grid/{grid-column.spec.ts → tek-grid-column.spec.ts} +48 -6
  95. package/tests/unit/components/tek-grid/{grid-columns-button.spec.ts → tek-grid-columns-button.spec.ts} +42 -9
  96. package/tests/unit/components/tek-grid/tek-grid-controller.spec.ts +253 -0
  97. package/tests/unit/components/tek-grid/tek-grid-events.spec.ts +186 -0
  98. package/tests/unit/components/tek-grid/tek-grid-toolbar-provider.spec.ts +34 -0
  99. package/tests/unit/components/tek-grid/tek-grid.spec.ts +895 -0
  100. package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +482 -0
  101. package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +422 -0
  102. package/src/error/delete-rows-error.ts +0 -11
  103. package/tests/unit/components/tek-grid/grid.spec.ts +0 -2701
@@ -0,0 +1,448 @@
1
+ import { I18n, IDictionary } from '@zeedhi/core';
2
+ import debounce from 'lodash.debounce';
3
+ import { NonInitializedError } from '@zeedhi/common';
4
+ import { isFilledObject, isNil } from '../../utils';
5
+ import {
6
+ IGroupedDataManager,
7
+ ITekGrid,
8
+ ITekGridGroup,
9
+ ITekGridGroupFooter,
10
+ ITekGridGroupHeader,
11
+ ITekGridSummary,
12
+ } from './interfaces';
13
+ import { TekGridColumn } from './tek-grid-column';
14
+
15
+ export class GroupedDataManager implements IGroupedDataManager {
16
+ protected grid: ITekGrid;
17
+
18
+ public summaryColumns: TekGridColumn[] = [];
19
+
20
+ private groups: ITekGridGroup[] = [];
21
+
22
+ private summary: IDictionary<ITekGridSummary> = {};
23
+
24
+ private groupedData: IDictionary<any>[] = [];
25
+
26
+ private groupColumnNames: string[] = [];
27
+
28
+ private groupColumns: TekGridColumn[] = [];
29
+
30
+ private originalDatasourceLoadAll?: boolean;
31
+
32
+ private originalDatasourceLimit?: number;
33
+
34
+ private viewUpdateScrollData?: () => void;
35
+
36
+ private viewUpdateFixedColumns?: () => void;
37
+
38
+ constructor(grid: ITekGrid) {
39
+ this.grid = grid;
40
+ }
41
+
42
+ setViewUpdateFixedColumns(fn: () => void) {
43
+ this.viewUpdateFixedColumns = fn;
44
+ }
45
+
46
+ setViewUpdateScrollData(fn: () => void) {
47
+ this.viewUpdateScrollData = fn;
48
+ }
49
+
50
+ /**
51
+ * Tasks that should be finished before loading the grid data
52
+ */
53
+ private tasksBeforeLoad: Promise<any>[] = [];
54
+
55
+ public registerTask(task: Promise<any>) {
56
+ this.tasksBeforeLoad.push(task);
57
+ }
58
+
59
+ private request: () => void = () => {
60
+ throw new NonInitializedError(this.constructor.name);
61
+ };
62
+
63
+ private debounceUpdateGrouping: (lazyLoad?: boolean) => void = () => {
64
+ throw new NonInitializedError(this.constructor.name);
65
+ };
66
+
67
+ /**
68
+ * Loads grid data after resolving all tasks
69
+ */
70
+ public async loadAfterTasks() {
71
+ Promise.all(this.tasksBeforeLoad.map((promise) => promise.catch(() => undefined)));
72
+ this.tasksBeforeLoad = [];
73
+
74
+ return this.request();
75
+ }
76
+
77
+ private initializeDebounceFunctions() {
78
+ this.request = debounce(() => {
79
+ this.grid.reload();
80
+ }, 500);
81
+ this.debounceUpdateGrouping = debounce((lazyLoad = false) => {
82
+ this.updateGroupedData(lazyLoad);
83
+ }, 100);
84
+ }
85
+
86
+ /**
87
+ * Initializes grid groups, summary columns and registers the grid datasource callback
88
+ * @param lazyLoad defines if the grid should automatically load data after updating the datasource
89
+ */
90
+ initializeGrouping(lazyLoad: boolean): void {
91
+ this.initializeDebounceFunctions();
92
+
93
+ this.initGroups();
94
+ this.initSummaryColumns();
95
+
96
+ this.originalDatasourceLoadAll = this.grid.datasource.loadAll;
97
+ this.originalDatasourceLimit = this.grid.datasource.limit;
98
+ this.grid.datasource.registerGetCallback((data) => this.onGet(data));
99
+ this.updateGrouping(lazyLoad);
100
+ }
101
+
102
+ private onGet(data: IDictionary) {
103
+ if (this.isGrouped()) {
104
+ this.buildGroupedData();
105
+ }
106
+
107
+ return data;
108
+ }
109
+
110
+ private resetFooterVariables(group: ITekGridGroup) {
111
+ this.summaryColumns.forEach((column) => {
112
+ group.footer[column.name] = {
113
+ count: 0,
114
+ sum: undefined,
115
+ avg: undefined,
116
+ min: undefined,
117
+ max: undefined,
118
+ };
119
+ });
120
+ }
121
+
122
+ private initGroups() {
123
+ this.groups = [];
124
+ this.groupColumns.forEach((column) => {
125
+ const newGroup = {
126
+ column,
127
+ name: column.name,
128
+ label: column.label,
129
+ lastValue: undefined,
130
+ initialized: false,
131
+ footer: {},
132
+ };
133
+ this.resetFooterVariables(newGroup);
134
+
135
+ this.groups.push(newGroup);
136
+ });
137
+ }
138
+
139
+ getGroupedData(): IDictionary<any>[] {
140
+ return this.groupedData;
141
+ }
142
+
143
+ private initSummaryColumns() {
144
+ this.summaryColumns = this.grid.columns.filter((column) => !!column.aggregation && !column.grouped);
145
+ this.summary = {};
146
+ }
147
+
148
+ /**
149
+ * Calls updateGroupedData with debounce
150
+ */
151
+ public updateGrouping(lazyLoad?: boolean) {
152
+ this.debounceUpdateGrouping(lazyLoad);
153
+ }
154
+
155
+ /**
156
+ * Inits summary columns, updates the grid datasource and, if needed, reloads the grid data
157
+ */
158
+ async updateGroupedData(lazyLoad: boolean): Promise<void> {
159
+ this.initSummaryColumns();
160
+ this.updateGridDatasource();
161
+
162
+ if (!lazyLoad) {
163
+ await this.loadAfterTasks();
164
+ }
165
+
166
+ if (this.grid.virtualScroll && this.viewUpdateScrollData) {
167
+ this.viewUpdateScrollData();
168
+ }
169
+ if (this.viewUpdateFixedColumns) {
170
+ this.viewUpdateFixedColumns();
171
+ }
172
+ }
173
+
174
+ /**
175
+ * When using groups, should update the grid datasource order to reflect the group order
176
+ * If the grid is not grouped, should not update the datasource order
177
+ */
178
+ private updateGridDatasource() {
179
+ this.groupedData = [];
180
+
181
+ this.groupColumns = this.grid.columns.filter((column) => column.grouped);
182
+ this.groupColumnNames = this.groupColumns.map((column) => column.name);
183
+ if (this.isGrouped()) {
184
+ if (this.groupColumns.length) {
185
+ const order = this.getOrder(this.groupColumnNames, this.grid.datasource.order);
186
+ this.grid.datasource.order = order;
187
+ }
188
+
189
+ this.grid.datasource.loadAll = true;
190
+ return;
191
+ }
192
+
193
+ this.grid.datasource.loadAll = this.originalDatasourceLoadAll!;
194
+ this.grid.datasource.limit = this.originalDatasourceLimit!;
195
+ }
196
+
197
+ /**
198
+ * Returns the order to be used in the grid datasource based on the group column names and the grid order
199
+ */
200
+ private getOrder(groupColumnNames: string[], gridOrder: string[]): string[] {
201
+ const groupOrderColumns = groupColumnNames.map((column) => `${column}.asc`);
202
+ const otherOrderColumns = gridOrder.filter((column) => groupColumnNames.indexOf(column.split('.')[0]) === -1);
203
+
204
+ return [...groupOrderColumns, ...otherOrderColumns];
205
+ }
206
+
207
+ /**
208
+ * Returns the summary data for the group
209
+ */
210
+ public getSummaryData(group: IDictionary<ITekGridSummary>) {
211
+ const summaryData: IDictionary = {};
212
+ this.summaryColumns.forEach((column) => {
213
+ const { aggregation } = column;
214
+ const currentGroup = group[column.name];
215
+
216
+ if (!currentGroup) {
217
+ summaryData[column.name] = 0;
218
+ return;
219
+ }
220
+
221
+ if (aggregation === 'COUNT') {
222
+ summaryData[column.name] = currentGroup.count;
223
+ } else if (aggregation === 'SUM') {
224
+ summaryData[column.name] = currentGroup.sum;
225
+ } else if (aggregation === 'AVG') {
226
+ if (currentGroup.avg) {
227
+ summaryData[column.name] = currentGroup.avg;
228
+ } else if (typeof currentGroup.sum === 'number') {
229
+ summaryData[column.name] = currentGroup.sum / currentGroup.count;
230
+ }
231
+ } else if (aggregation === 'MIN') {
232
+ summaryData[column.name] = currentGroup.min;
233
+ } else {
234
+ // if (aggregation === 'MAX') {
235
+ summaryData[column.name] = currentGroup.max;
236
+ }
237
+ });
238
+
239
+ return summaryData;
240
+ }
241
+
242
+ /**
243
+ * Adds group footers to the grouped data
244
+ */
245
+ private addGroupFooters(groupIndex: number) {
246
+ if (this.summaryColumns.length === 0) {
247
+ return;
248
+ }
249
+
250
+ for (let i = this.groups.length - 1; i >= groupIndex; i -= 1) {
251
+ if (this.groups[i].initialized) {
252
+ const groupFooterRow: ITekGridGroupFooter = {
253
+ groupFooter: true,
254
+ groupIndex: i,
255
+ groupHeaders: [],
256
+ groupLabel: this.groups[i].lastGroupHeaderRow!.groupLabel,
257
+ groupValue: this.groups[i].lastGroupHeaderRow!.groupValue,
258
+ ...this.getSummaryData(this.groups[i].footer),
259
+ };
260
+
261
+ // add header for outer groups
262
+ for (let g = 0; g < i; g += 1) {
263
+ const { lastGroupHeaderRow } = this.groups[g];
264
+ if (lastGroupHeaderRow) {
265
+ groupFooterRow.groupHeaders.push(lastGroupHeaderRow);
266
+ }
267
+ }
268
+
269
+ this.groupedData.push(groupFooterRow);
270
+ }
271
+ }
272
+ }
273
+
274
+ private getGroupValue(group: IDictionary<any>, row: IDictionary<any>) {
275
+ const groupColumn = this.grid.getColumn(group.column.name);
276
+ const cellsApplied = this.grid.getAppliedConditions({ row, column: groupColumn });
277
+ if (!isFilledObject(cellsApplied)) {
278
+ this.grid.reapplyConditions(row);
279
+ }
280
+ const groupValue = groupColumn.formatterByRow(row, cellsApplied);
281
+ return groupValue;
282
+ }
283
+
284
+ private addGroupHeader(row: IDictionary, group: ITekGridGroup, index: number) {
285
+ const groupValue = this.getGroupValue(group, row) || group.column.groupLabelForEmptyValue;
286
+ const groupHeaderRow: ITekGridGroupHeader = {
287
+ group: true,
288
+ groupRow: row,
289
+ groupColumnName: group.column.name,
290
+ groupHeader: true,
291
+ groupIndex: index,
292
+ groupLabel: I18n.translate(group.label),
293
+ groupValue,
294
+ groupOpened: group.column.groupOpened || this.grid.groupsOpened,
295
+ groupHeaders: [],
296
+ children: [],
297
+ };
298
+ // add header for outer groups to the added row
299
+ for (let i = 0; i < index; i += 1) {
300
+ groupHeaderRow.groupHeaders.push(this.groups[i].lastGroupHeaderRow!);
301
+ }
302
+ group.lastGroupHeaderRow = groupHeaderRow;
303
+ group.initialized = true;
304
+ this.groupedData.push(groupHeaderRow);
305
+ }
306
+
307
+ private calcSummaryValues(column: TekGridColumn, summary: ITekGridSummary, row: IDictionary) {
308
+ const rowValue = row[column.name];
309
+
310
+ if (isNil(rowValue)) return;
311
+
312
+ summary.count += 1;
313
+
314
+ if (this.grid.events.calcSummary) {
315
+ this.grid.calcSummary(column, summary, row);
316
+ return;
317
+ }
318
+
319
+ if (summary.min === undefined) summary.min = rowValue;
320
+ if (summary.max === undefined) summary.max = rowValue;
321
+ summary.min = rowValue < summary.min ? rowValue : summary.min;
322
+ summary.max = rowValue > summary.max ? rowValue : summary.max;
323
+
324
+ if (typeof rowValue === 'number') {
325
+ summary.sum = (summary.sum || 0) + rowValue;
326
+ }
327
+ }
328
+
329
+ private calcSummary(row: IDictionary<any>) {
330
+ if (this.summaryColumns.length === 0) return;
331
+
332
+ this.summaryColumns.forEach((column) => {
333
+ const columnName = column.name;
334
+ if (isNil(this.summary[columnName])) {
335
+ this.summary[columnName] = {
336
+ count: 0,
337
+ sum: undefined,
338
+ avg: undefined,
339
+ min: undefined,
340
+ max: undefined,
341
+ };
342
+ }
343
+
344
+ this.calcSummaryValues(column, this.summary[columnName], row);
345
+
346
+ this.groups.forEach((group) => {
347
+ this.calcSummaryValues(column, group.footer[columnName], row);
348
+ });
349
+ });
350
+ }
351
+
352
+ private addSummary() {
353
+ if (this.summaryColumns.length === 0) return;
354
+
355
+ const summaryRow = {
356
+ groupFooter: true,
357
+ groupSummary: true,
358
+ ...this.getSummaryData(this.summary),
359
+ };
360
+
361
+ this.groupedData.push(summaryRow);
362
+ }
363
+
364
+ /**
365
+ * It takes a flat array of data and groups it by the group columns specified in
366
+ * the grid.
367
+ */
368
+ buildGroupedData(): void {
369
+ this.initGroups();
370
+ this.initSummaryColumns();
371
+ this.groupedData = [];
372
+ const data = this.grid.getData();
373
+
374
+ data.forEach((row) => {
375
+ let groupBreak = false;
376
+ this.groups.forEach((group, index) => {
377
+ const groupValue = row[group.name];
378
+ if (group.lastValue !== groupValue || groupBreak) {
379
+ if (!groupBreak) {
380
+ this.addGroupFooters(index);
381
+ }
382
+ group.lastValue = groupValue;
383
+
384
+ this.resetFooterVariables(group);
385
+ this.addGroupHeader(row, group, index);
386
+ groupBreak = true;
387
+ }
388
+ });
389
+
390
+ this.groups.forEach((group) => {
391
+ group.lastGroupHeaderRow!.children.push(row);
392
+ });
393
+
394
+ this.groupedData.push({
395
+ ...row,
396
+ groupHeaders: this.groups.map((group) => group.lastGroupHeaderRow).filter(Boolean),
397
+ });
398
+
399
+ this.calcSummary(row);
400
+ });
401
+
402
+ if (this.groupedData.length > 0) {
403
+ this.addGroupFooters(0);
404
+
405
+ if (this.grid.showSummaryTotal) {
406
+ this.addSummary();
407
+ }
408
+ }
409
+ }
410
+
411
+ openGroup(group: IDictionary<any>): void {
412
+ group.groupOpened = !group.groupOpened;
413
+ if (this.grid.virtualScroll && this.viewUpdateScrollData) this.viewUpdateScrollData();
414
+ }
415
+
416
+ isItemVisible(row: IDictionary<any>) {
417
+ return !row.groupHeaders || !row.groupHeaders.length || row.groupHeaders.every((group: any) => group.groupOpened);
418
+ }
419
+
420
+ isGrouped(): boolean {
421
+ return !!this.groupColumnNames.length || (this.grid.showSummaryTotal && !!this.summaryColumns.length);
422
+ }
423
+
424
+ isColumnSearchable(column: TekGridColumn): boolean {
425
+ return !this.grid.searchVisibleOnly || column.isVisible || column.grouped;
426
+ }
427
+
428
+ directionalLeft(): void {
429
+ const { currentRow } = this.grid.datasource;
430
+ if (currentRow.group && currentRow.groupOpened) {
431
+ currentRow.groupOpened = false;
432
+ return;
433
+ }
434
+
435
+ if (this.grid.cellSelection || !currentRow.groupHeaders?.length) return;
436
+
437
+ const newCurrentRow = currentRow.groupHeaders[currentRow.groupHeaders.length - 1];
438
+ this.grid.setCurrentRow(newCurrentRow);
439
+ }
440
+
441
+ directionalRight(): void {
442
+ const { currentRow } = this.grid.datasource;
443
+
444
+ if (!currentRow.group || currentRow.groupOpened) return;
445
+
446
+ currentRow.groupOpened = true;
447
+ }
448
+ }
@@ -0,0 +1,40 @@
1
+ import { IDictionary } from '@zeedhi/core';
2
+ import { DataSelector, IDataSelector, IGrid } from '@zeedhi/common';
3
+ import { IGroupedDataManager } from './interfaces';
4
+
5
+ export class GroupedDataSelector extends DataSelector implements IDataSelector {
6
+ protected declare iterable: IGrid & IGroupedDataManager;
7
+
8
+ public selectAll(isSelected: boolean) {
9
+ if (!this.iterable.selectable) return;
10
+
11
+ this.iterable.selectionState = { allSelected: isSelected, except: [] };
12
+ const data = this.getData();
13
+
14
+ if (!isSelected) {
15
+ data.forEach((row: IDictionary) => {
16
+ const index = this.iterable.selectedRows.indexOf(row);
17
+ if (index > -1) {
18
+ this.iterable.selectedRows.splice(index, 1);
19
+ }
20
+ });
21
+ return;
22
+ }
23
+
24
+ data.forEach((row: IDictionary) => {
25
+ if (this.callDisableSelection(row)) return;
26
+
27
+ const key = this.iterable.getRowKey(row);
28
+ if (key && this.iterable.selectedRows.indexOf(row) === -1) {
29
+ this.iterable.selectedRows.push(row);
30
+ }
31
+ });
32
+ }
33
+
34
+ private getData() {
35
+ if (this.iterable.isGrouped()) {
36
+ return this.iterable.getGroupedData();
37
+ }
38
+ return this.iterable.getData();
39
+ }
40
+ }
@@ -0,0 +1,84 @@
1
+ import { IEventParam, IDictionary } from '@zeedhi/core';
2
+ import { Direction, IViewNavigator, ViewNavigator } from '@zeedhi/common';
3
+ import { ITekGrid } from './interfaces';
4
+
5
+ export class GroupedViewNavigator implements IViewNavigator {
6
+ private viewNavigator: ViewNavigator;
7
+
8
+ protected grid: ITekGrid;
9
+
10
+ constructor(iterable: ITekGrid) {
11
+ this.viewNavigator = new ViewNavigator();
12
+ this.grid = iterable;
13
+ }
14
+
15
+ navigateLeft(param: IEventParam<any>): void {
16
+ this.viewNavigator.navigateLeft(param);
17
+ }
18
+
19
+ navigateRight(param: IEventParam<any>): void {
20
+ this.viewNavigator.navigateRight(param);
21
+ }
22
+
23
+ setViewNavigate(viewNavigate: (direction: Direction, event?: Event) => void): void {
24
+ this.viewNavigator.setViewNavigate(viewNavigate);
25
+ }
26
+
27
+ private getRowIndex(groupedData: IDictionary[], index?: number) {
28
+ if (index) return index;
29
+
30
+ const { currentRow } = this.grid.datasource;
31
+ return groupedData.findIndex((row) => {
32
+ if (currentRow.group) {
33
+ return row.group && row.groupValue === currentRow.groupValue;
34
+ }
35
+ const rowKey = this.grid.getRowKey(row);
36
+ const currentRowKey = this.grid.getRowKey(currentRow);
37
+ return rowKey && rowKey === currentRowKey;
38
+ });
39
+ }
40
+
41
+ public navigateUp(index?: number) {
42
+ if (!this.grid.isGrouped() || this.grid.cellSelection) {
43
+ this.viewNavigator.navigateUp();
44
+ return;
45
+ }
46
+ const groupedData = this.grid.getGroupedData();
47
+
48
+ if (!groupedData.length || index === -1) return;
49
+
50
+ let rowIndex: number = this.getRowIndex(groupedData, index);
51
+
52
+ if (rowIndex === -1) rowIndex = groupedData.length;
53
+
54
+ const newRow = groupedData[rowIndex - 1];
55
+
56
+ if (!newRow || !this.grid.isItemVisible(newRow) || newRow.groupFooter) {
57
+ this.navigateUp(rowIndex - 1);
58
+ return;
59
+ }
60
+
61
+ this.grid.setCurrentRow(newRow);
62
+ }
63
+
64
+ public navigateDown(index?: number) {
65
+ if (!this.grid.isGrouped() || this.grid.cellSelection) {
66
+ this.viewNavigator.navigateDown();
67
+ return;
68
+ }
69
+ const groupedData = this.grid.getGroupedData();
70
+
71
+ if (!groupedData.length || index === groupedData.length) return;
72
+
73
+ const rowIndex = this.getRowIndex(groupedData, index);
74
+
75
+ const newRow = groupedData[rowIndex + 1];
76
+
77
+ if (!newRow || !this.grid.isItemVisible(newRow) || newRow.groupFooter) {
78
+ this.navigateDown(rowIndex + 1);
79
+ return;
80
+ }
81
+
82
+ this.grid.setCurrentRow(newRow);
83
+ }
84
+ }
@@ -0,0 +1,18 @@
1
+ export * from '../tek-datasource';
2
+ export * from './tek-grid-toolbar-provider';
3
+ export * from './columns-searcher';
4
+ export * from './dynamic-filter-datasource-factory';
5
+ export * from './filter-helper';
6
+ export * from './grid-filter-button';
7
+ export * from './grouped-data-manager';
8
+ export * from './grouped-view-navigator';
9
+ export * from './interfaces';
10
+ export * from './keymap-grouped';
11
+ export * from './layout-options';
12
+ export * from './tek-grid-column';
13
+ export * from './tek-grid-controller';
14
+ export * from './tek-grid-events';
15
+ export * from './tek-grid';
16
+ export * from './tek-grid-columns-button/tek-grid-columns-button';
17
+ export * from './tek-grid-columns-button/tek-grid-columns-button-controller';
18
+ export * from './grouped-data-selector';