@zeedhi/teknisa-components-common 3.0.4 → 3.2.0

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 (134) hide show
  1. package/dist/teknisa-components-common.es.js +3536 -0
  2. package/dist/types/components/index.d.ts +2 -0
  3. package/dist/types/components/tek-breadcrumb-header/breadcrumb-header.d.ts +2 -2
  4. package/dist/types/components/tek-breadcrumb-header/interfaces.d.ts +1 -1
  5. package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +1 -21
  6. package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +6 -30
  7. package/dist/types/components/tek-grid/filter-helper.d.ts +2 -2
  8. package/dist/types/components/tek-grid/grid-filter-button.d.ts +1 -0
  9. package/dist/types/components/tek-grid/grouped-data-manager.d.ts +8 -1
  10. package/dist/types/components/tek-grid/grouped-data-navigator.d.ts +12 -0
  11. package/dist/types/components/tek-grid/index.d.ts +1 -1
  12. package/dist/types/components/tek-grid/interfaces.d.ts +8 -1
  13. package/dist/types/components/tek-grid/tek-grid-controller.d.ts +19 -17
  14. package/dist/types/components/tek-grid/tek-grid-data-editor.d.ts +11 -0
  15. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.d.ts +1 -1
  16. package/dist/types/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.d.ts +8 -1
  17. package/dist/types/components/tek-grid/tek-grid.d.ts +24 -6
  18. package/dist/types/components/tek-loading/interfaces.d.ts +6 -0
  19. package/dist/types/components/tek-loading/loading.d.ts +16 -0
  20. package/dist/types/components/tek-user-info/TekUserInfoController.d.ts +4 -4
  21. package/dist/types/utils/extract-properties/extract-properties.d.ts +1 -0
  22. package/dist/types/utils/index.d.ts +2 -0
  23. package/dist/types/utils/report-filter/report-filter.d.ts +12 -0
  24. package/package.json +32 -12
  25. package/coverage/clover.xml +0 -6
  26. package/coverage/coverage-final.json +0 -1
  27. package/coverage/lcov-report/base.css +0 -224
  28. package/coverage/lcov-report/block-navigation.js +0 -87
  29. package/coverage/lcov-report/favicon.png +0 -0
  30. package/coverage/lcov-report/index.html +0 -101
  31. package/coverage/lcov-report/prettify.css +0 -1
  32. package/coverage/lcov-report/prettify.js +0 -2
  33. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  34. package/coverage/lcov-report/sorter.js +0 -210
  35. package/coverage/lcov.info +0 -0
  36. package/dist/teknisa-components-common.js +0 -3802
  37. package/dist/teknisa-components-common.min.js +0 -3802
  38. package/dist/types/components/tek-grid/grouped-view-navigator.d.ts +0 -14
  39. package/dist/types/error/delete-rows-error.d.ts +0 -6
  40. package/environments.json +0 -14
  41. package/jest.config.js +0 -1
  42. package/src/components/index.ts +0 -101
  43. package/src/components/tek-breadcrumb-header/breadcrumb-header.ts +0 -29
  44. package/src/components/tek-breadcrumb-header/interfaces.ts +0 -7
  45. package/src/components/tek-datasource/index.ts +0 -3
  46. package/src/components/tek-datasource/interfaces.ts +0 -36
  47. package/src/components/tek-datasource/tek-memory-datasource.ts +0 -314
  48. package/src/components/tek-datasource/tek-rest-datasource.ts +0 -224
  49. package/src/components/tek-grid/columns-searcher.ts +0 -22
  50. package/src/components/tek-grid/dynamic-filter-datasource-factory.ts +0 -20
  51. package/src/components/tek-grid/filter-helper.ts +0 -20
  52. package/src/components/tek-grid/grid-filter-button.ts +0 -419
  53. package/src/components/tek-grid/grouped-data-manager.ts +0 -448
  54. package/src/components/tek-grid/grouped-data-selector.ts +0 -40
  55. package/src/components/tek-grid/grouped-view-navigator.ts +0 -84
  56. package/src/components/tek-grid/index.ts +0 -18
  57. package/src/components/tek-grid/interfaces.ts +0 -329
  58. package/src/components/tek-grid/keymap-grouped.ts +0 -20
  59. package/src/components/tek-grid/layout-options.ts +0 -248
  60. package/src/components/tek-grid/tek-grid-column.ts +0 -193
  61. package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.ts +0 -28
  62. package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.ts +0 -38
  63. package/src/components/tek-grid/tek-grid-controller.ts +0 -140
  64. package/src/components/tek-grid/tek-grid-events.ts +0 -105
  65. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.ts +0 -26
  66. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/index.ts +0 -3
  67. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.ts +0 -6
  68. package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.ts +0 -85
  69. package/src/components/tek-grid/tek-grid-toolbar-provider/index.ts +0 -2
  70. package/src/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.ts +0 -365
  71. package/src/components/tek-grid/tek-grid.ts +0 -1118
  72. package/src/components/tek-user-info/TekUserInfoController.ts +0 -87
  73. package/src/components/tek-user-info/interfaces.ts +0 -21
  74. package/src/components/tek-user-info/tek-user-info-list.ts +0 -64
  75. package/src/components/tek-user-info/tek-user-info.ts +0 -337
  76. package/src/error/tek-grid-delete-rows-error.ts +0 -15
  77. package/src/error/teknisa-common-error.ts +0 -8
  78. package/src/utils/config/config.ts +0 -8
  79. package/src/utils/index.ts +0 -3
  80. package/src/utils/is-filled-object/is-filled-object.ts +0 -5
  81. package/src/utils/is-nil.ts +0 -3
  82. package/tests/__helpers__/component-event-helper.ts +0 -5
  83. package/tests/__helpers__/flush-promises-helper.ts +0 -3
  84. package/tests/__helpers__/get-child-helper.ts +0 -27
  85. package/tests/__helpers__/index.ts +0 -3
  86. package/tests/__helpers__/mock-created-helper.ts +0 -12
  87. package/tests/__mocks__/@zeedhi/core/i18n.js +0 -75
  88. package/tests/__mocks__/@zeedhi/core.js +0 -5
  89. package/tests/unit/components/crud/crud-add-button.spec.ts +0 -56
  90. package/tests/unit/components/crud/crud-button.spec.ts +0 -94
  91. package/tests/unit/components/crud/crud-cancel-button.spec.ts +0 -91
  92. package/tests/unit/components/crud/crud-delete-button.spec.ts +0 -122
  93. package/tests/unit/components/crud/crud-form.spec.ts +0 -165
  94. package/tests/unit/components/crud/crud-save-button.spec.ts +0 -118
  95. package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +0 -42
  96. package/tests/unit/components/tek-card-title/CardTitle.spec.ts +0 -34
  97. package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +0 -460
  98. package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +0 -362
  99. package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +0 -112
  100. package/tests/unit/components/tek-grid/button-option.spec.ts +0 -49
  101. package/tests/unit/components/tek-grid/columns-searcher.spec.ts +0 -112
  102. package/tests/unit/components/tek-grid/dynamic-filter-datasource-factory.spec.ts +0 -90
  103. package/tests/unit/components/tek-grid/filter-helper.spec.ts +0 -52
  104. package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +0 -842
  105. package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +0 -593
  106. package/tests/unit/components/tek-grid/grouped-data-selector.spec.ts +0 -136
  107. package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +0 -244
  108. package/tests/unit/components/tek-grid/keymap-grouped.spec.ts +0 -20
  109. package/tests/unit/components/tek-grid/layout-options.spec.ts +0 -1020
  110. package/tests/unit/components/tek-grid/multi-option.spec.ts +0 -139
  111. package/tests/unit/components/tek-grid/tek-grid-column.spec.ts +0 -312
  112. package/tests/unit/components/tek-grid/tek-grid-columns-button.spec.ts +0 -228
  113. package/tests/unit/components/tek-grid/tek-grid-controller.spec.ts +0 -253
  114. package/tests/unit/components/tek-grid/tek-grid-events.spec.ts +0 -186
  115. package/tests/unit/components/tek-grid/tek-grid-toolbar-provider.spec.ts +0 -34
  116. package/tests/unit/components/tek-grid/tek-grid.spec.ts +0 -895
  117. package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +0 -482
  118. package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +0 -422
  119. package/tests/unit/components/tek-image/Image.spec.ts +0 -67
  120. package/tests/unit/components/tek-iterable-carousel/iterable-carousel.spec.ts +0 -37
  121. package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +0 -200
  122. package/tests/unit/components/tek-loading/Loading.spec.ts +0 -30
  123. package/tests/unit/components/tek-notifications/notifications.spec.ts +0 -201
  124. package/tests/unit/components/tek-product-card/product-card.spec.ts +0 -61
  125. package/tests/unit/components/tek-user-info/TekUserInfoContoller.spec.ts +0 -220
  126. package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +0 -86
  127. package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +0 -430
  128. package/tests/unit/components/tree-grid/tree-grid.spec.ts +0 -776
  129. package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +0 -44
  130. package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +0 -135
  131. package/tests/unit/utils/grid-base/grid-controller.spec.ts +0 -174
  132. package/tests/unit/utils/report-filter/report-filter.spec.ts +0 -66
  133. package/tsconfig.build.json +0 -7
  134. package/tsconfig.eslint.json +0 -9
@@ -1,329 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
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
- }
@@ -1,248 +0,0 @@
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
- }