@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,14 +0,0 @@
1
- import { IEventParam } from '@zeedhi/core';
2
- import { Direction, IViewNavigator } from '@zeedhi/common';
3
- import { ITekGrid } from './interfaces';
4
- export declare class GroupedViewNavigator implements IViewNavigator {
5
- private viewNavigator;
6
- protected grid: ITekGrid;
7
- constructor(iterable: ITekGrid);
8
- navigateLeft(param: IEventParam<any>): void;
9
- navigateRight(param: IEventParam<any>): void;
10
- setViewNavigate(viewNavigate: (direction: Direction, event?: Event) => void): void;
11
- private getRowIndex;
12
- navigateUp(index?: number): void;
13
- navigateDown(index?: number): void;
14
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Delete rows error
3
- */
4
- export declare class TekGridDeleteRowsError extends Error {
5
- constructor();
6
- }
package/environments.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "development": {
3
- "devDependencies": {
4
- "@zeedhi/common": "file:../../../zeedhi-client-core/packages/common",
5
- "@zeedhi/core": "file:../../../zeedhi-client-core/packages/core"
6
- }
7
- },
8
- "production": {
9
- "devDependencies": {
10
- "@zeedhi/common": "^3.0.0",
11
- "@zeedhi/core": "^3.0.0"
12
- }
13
- }
14
- }
package/jest.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('../../jest.config.js');
@@ -1,101 +0,0 @@
1
- import { Messages } from '@zeedhi/core';
2
-
3
- Messages.add({
4
- 'pt-BR': {
5
- translation: {
6
- NO_NOTIFICATIONS: 'Nenhuma Notificação',
7
- MARK_ALL_AS_READ: 'Marcar todas como lidas',
8
- NOTIFICATIONS: 'Notificações',
9
- SEE_ALL_NOTIFICATIONS: 'Ver todas notificações',
10
- UNAVAILABLE_IMAGE: 'Imagem indisponível',
11
- REFRESH: 'Atualizar',
12
- ACTIONS: 'Ações',
13
- FILTER: 'Filtro',
14
- LAYOUT: 'Layout: ',
15
- NEW_LAYOUT: 'Novo layout',
16
- DEFAULT_LAYOUT: 'Padrão',
17
- LAYOUT_MODIFIED: 'O layout atual foi modificado. Crie um novo layout, sobrescreva um existente ou descarte as alterações', // eslint-disable-line
18
- LAYOUT_NOT_MODIFIED: 'Crie um novo layout ou aplique um dos layouts já existentes',
19
- LAYOUT_DISCART_CHANGES: 'Descartar alterações',
20
- },
21
- },
22
- 'en-US': {
23
- translation: {
24
- NO_NOTIFICATIONS: 'No Notifications',
25
- MARK_ALL_AS_READ: 'Mark all as read',
26
- NOTIFICATIONS: 'Notifications',
27
- SEE_ALL_NOTIFICATIONS: 'See all notifications',
28
- UNAVAILABLE_IMAGE: 'Unavailable image',
29
- REFRESH: 'Refresh',
30
- ACTIONS: 'Actions',
31
- FILTER: 'Filter',
32
- LAYOUT: 'Layout: ',
33
- NEW_LAYOUT: 'New layout',
34
- DEFAULT_LAYOUT: 'Default',
35
- LAYOUT_MODIFIED: 'The current layout has been modified. Create a new layout, overwrite an existing one or discard changes', // eslint-disable-line
36
- LAYOUT_NOT_MODIFIED: 'Create a new layout or apply one of the existing layouts',
37
- LAYOUT_DISCART_CHANGES: 'Discard changes',
38
- },
39
- },
40
- 'es-CL': {
41
- translation: {
42
- NO_NOTIFICATIONS: 'Sin Notificación',
43
- MARK_ALL_AS_READ: 'Marcar todo como leído',
44
- NOTIFICATIONS: 'Notificaciones',
45
- SEE_ALL_NOTIFICATIONS: 'Ver todas las notificaciones',
46
- UNAVAILABLE_IMAGE: 'Imagen no disponible',
47
- REFRESH: 'Actualizar',
48
- ACTIONS: 'Acciones',
49
- FILTER: 'Filtro',
50
- LAYOUT: 'Disposición: ',
51
- NEW_LAYOUT: 'Nueva disposición',
52
- DEFAULT_LAYOUT: 'Default',
53
- LAYOUT_MODIFIED: 'La disposición actual ha sido modificada. Cree una nueva disposición, sobrescriba una existente o descarte los cambios', // eslint-disable-line
54
- LAYOUT_NOT_MODIFIED: 'Cree una nueva disposición o aplique una de las disposiciones existentes',
55
- LAYOUT_DISCART_CHANGES: 'Descartar los cambios',
56
- },
57
- },
58
- });
59
-
60
- // export * from './crud/crud-form';
61
- // export * from './crud/crud-button';
62
- // export * from './crud/crud-add-button';
63
- // export * from './crud/crud-cancel-button';
64
- // export * from './crud/crud-delete-button';
65
- // export * from './crud/crud-save-button';
66
- // export * from './crud/interfaces';
67
-
68
- export * from './tek-breadcrumb-header/breadcrumb-header';
69
- export * from './tek-breadcrumb-header/interfaces';
70
-
71
- // export * from './tek-card-title/card-title';
72
- // export * from './tek-card-title/interfaces';
73
-
74
- // export * from './tek-image/image';
75
- // export * from './tek-image/interfaces';
76
-
77
- // export * from './tek-product-card/product-card';
78
- // export * from './tek-product-card/interfaces';
79
-
80
- // export * from './tek-iterable-component-render/iterable-component-render';
81
- // export * from './tek-iterable-component-render/interfaces';
82
-
83
- // export * from './tek-iterable-carousel/iterable-carousel';
84
- // export * from './tek-iterable-carousel/interfaces';
85
-
86
- // export * from './tek-loading/loading';
87
- // export * from './tek-loading/interfaces';
88
-
89
- // export * from './tek-notifications/notifications';
90
- // export * from './tek-notifications/interfaces';
91
-
92
- export * from './tek-grid';
93
-
94
- export * from './tek-datasource';
95
-
96
- // export * from './tek-tree-grid/interfaces';
97
- // export * from './tek-tree-grid/tree-grid';
98
-
99
- export * from './tek-user-info/interfaces';
100
- export * from './tek-user-info/tek-user-info';
101
- export * from './tek-user-info/tek-user-info-list';
@@ -1,29 +0,0 @@
1
- import { type IBreadcrumbs, ComponentRender, type IComponentRender } from '@zeedhi/common';
2
- import type { IBreadcrumbHeader } from './interfaces';
3
-
4
- /**
5
- * BreadcrumbHeader join breadcrumb and title
6
- */
7
- export class BreadcrumbHeader extends ComponentRender implements IBreadcrumbHeader {
8
- public breadcrumb: IBreadcrumbs;
9
-
10
- public title = '';
11
-
12
- public rightSlot: IComponentRender[] = [];
13
-
14
- public constructor(props: IBreadcrumbHeader) {
15
- super(props);
16
- this.breadcrumb = this.getBreadcrumbProperties(props.breadcrumb);
17
- this.title = this.getInitValue('title', props.title, this.title);
18
- this.rightSlot = props.rightSlot || this.rightSlot;
19
- }
20
-
21
- private getBreadcrumbProperties(breadcrumb: any): IBreadcrumbs {
22
- return {
23
- ...breadcrumb,
24
- name: breadcrumb.name,
25
- component: 'ZdBreadcrumb',
26
- divider: '>',
27
- };
28
- }
29
- }
@@ -1,7 +0,0 @@
1
- import type { IBreadcrumbs, IComponentRender } from '@zeedhi/common';
2
-
3
- export interface IBreadcrumbHeader extends IComponentRender {
4
- breadcrumb: IBreadcrumbs;
5
- title: string;
6
- rightSlot?: IComponentRender[];
7
- }
@@ -1,3 +0,0 @@
1
- export * from './interfaces';
2
- export * from './tek-memory-datasource';
3
- export * from './tek-rest-datasource';
@@ -1,36 +0,0 @@
1
- import { IDictionary, IMemoryDatasource, IRestDatasource } from '@zeedhi/core';
2
-
3
- export interface ITekMemoryDatasource extends IMemoryDatasource {
4
- dynamicFilter?: IDictionary<any>;
5
- searchJoin?: IDictionary<Array<string | number>>;
6
- }
7
-
8
- export interface ITekRestDatasource extends IRestDatasource {
9
- dynamicFilter?: IDictionary<any>;
10
- searchJoin?: IDictionary<Array<string | number>>;
11
- }
12
-
13
- export interface IDynamicFilterItem {
14
- relation: string;
15
- operation: string;
16
- value: any;
17
- }
18
-
19
- export const DynamicFilterOperations: IDictionary<boolean> = {
20
- CONTAINS: true,
21
- NOT_CONTAINS: true,
22
- EQUALS: true,
23
- NOT_EQUALS: true,
24
- GREATER_THAN: true,
25
- LESS_THAN: true,
26
- GREATER_THAN_EQUALS: true,
27
- LESS_THAN_EQUALS: true,
28
- IN: true,
29
- NOT_IN: true,
30
- BETWEEN: true,
31
- };
32
-
33
- export const DynamicFilterRelations: IDictionary<boolean> = {
34
- AND: true,
35
- OR: true,
36
- };
@@ -1,314 +0,0 @@
1
- import { DatasourceFactory, IDatasource, IDictionary, MemoryDatasource, URL, Utils } from '@zeedhi/core';
2
- import {
3
- DynamicFilterOperations,
4
- DynamicFilterRelations,
5
- IDynamicFilterItem,
6
- ITekMemoryDatasource,
7
- } from './interfaces';
8
-
9
- export class TekMemoryDatasource extends MemoryDatasource implements ITekMemoryDatasource {
10
- /** Dynamic filter data */
11
- public dynamicFilter!: IDictionary<IDynamicFilterItem[]>;
12
-
13
- /** Search Join data */
14
- public searchJoin!: IDictionary<Array<string | number>>;
15
-
16
- /**
17
- * Dynamic Filter Operations
18
- */
19
- public dynamicFilterOperations = DynamicFilterOperations;
20
-
21
- /**
22
- * Dynamic Filter Relations
23
- */
24
- public dynamicFilterRelations = DynamicFilterRelations;
25
-
26
- /**
27
- * Dynamic Filter applied flag
28
- */
29
- protected dynamicFilterApplied = '';
30
-
31
- /**
32
- * Create new datasource
33
- * @param props Datasource properties
34
- */
35
- constructor(props: ITekMemoryDatasource) {
36
- super(props);
37
-
38
- if (!this.watchUrl) {
39
- this.dynamicFilter = this.getInitValue('dynamicFilter', props.dynamicFilter, {});
40
- this.searchJoin = this.getInitValue('searchJoin', props.searchJoin, {});
41
- }
42
-
43
- this.createAccessors();
44
- this.createObjAccessors(this.dynamicFilter, 'dynamicFilter');
45
- this.createObjAccessors(this.searchJoin, 'searchJoin');
46
- }
47
-
48
- protected updateReservedKeys() {
49
- this.reservedKeys.dynamic_filter = true;
50
- this.reservedKeys.search_join = true;
51
- }
52
-
53
- protected updateInternalProperties(datasource: IDatasource = {}) {
54
- if (!this.watchUrl) return;
55
- this.updateReservedKeys();
56
- super.updateInternalProperties(datasource);
57
- const queryString = URL.getParsedQueryStringFromUrl();
58
- this.dynamicFilter = this.getEncodedParam(queryString.dynamic_filter, datasource.dynamicFilter);
59
- this.searchJoin = this.getEncodedParam(queryString.search_join, datasource.searchJoin);
60
- }
61
-
62
- protected getEncodedParam(urlParam: string, datasourceParam: IDictionary<any> = {}): IDictionary<any> {
63
- return urlParam ? JSON.parse(atob(urlParam)) : datasourceParam;
64
- }
65
-
66
- protected getQueryStringValues(): IDictionary<any> {
67
- const values = super.getQueryStringValues();
68
- if (this.dynamicFilter && Object.keys(this.dynamicFilter).length) {
69
- values.dynamic_filter = btoa(JSON.stringify(this.dynamicFilter));
70
- }
71
- if (this.searchJoin && Object.keys(this.searchJoin).length) {
72
- values.search_join = btoa(JSON.stringify(this.searchJoin));
73
- }
74
- return values;
75
- }
76
-
77
- protected getUrlQueryString() {
78
- const superQueryString = super.getUrlQueryString();
79
- const query = URL.getParsedQueryStringFromUrl();
80
-
81
- let dynamicFilterQuerystring = '';
82
- if (query.dynamic_filter) {
83
- dynamicFilterQuerystring = `&${URL.getFormattedQueryString({
84
- dynamic_filter: query.dynamic_filter,
85
- })}`;
86
- }
87
-
88
- let searchJoinQuerystring = '';
89
- if (query.search_join) {
90
- searchJoinQuerystring = `&${URL.getFormattedQueryString({
91
- search_join: query.search_join,
92
- })}`;
93
- }
94
- return superQueryString + dynamicFilterQuerystring + searchJoinQuerystring;
95
- }
96
-
97
- /**
98
- * Adds a new dynamic filter position or replace if exists
99
- * @param column Dynamic Filter column name
100
- * @param value Dynamic Filter value
101
- * @returns Promise with data collection
102
- */
103
- public addDynamicFilter(column: string, value: any) {
104
- if (this.isValidDynamicFilterValue(column, value)) {
105
- this.dynamicFilter[column] = value;
106
- return this.updateDynamicFilter();
107
- }
108
- return this.removeDynamicFilter(column);
109
- }
110
-
111
- /**
112
- * Removes a dynamic filter position
113
- * @param column Dynamic Filter column name
114
- * @returns Promise with data collection
115
- */
116
- public removeDynamicFilter(column: string) {
117
- delete this.dynamicFilter[column];
118
- return this.updateDynamicFilter();
119
- }
120
-
121
- /**
122
- * Sets new dynamic filter value
123
- * @param filter Dynamic Filter value
124
- * @returns Promise with data collection
125
- */
126
- public setDynamicFilter(filter: IDictionary<any>) {
127
- this.dynamicFilter = {};
128
- Object.keys(filter).forEach((column: string) => {
129
- if (this.isValidDynamicFilterValue(column, filter[column])) {
130
- this.dynamicFilter[column] = filter[column];
131
- } else {
132
- delete this.dynamicFilter[column];
133
- }
134
- });
135
- return this.updateDynamicFilter();
136
- }
137
-
138
- /**
139
- * Clears Dynamic filter value
140
- * @returns Promise with data collection
141
- */
142
- public clearDynamicFilter() {
143
- this.dynamicFilter = {};
144
- return this.updateDynamicFilter();
145
- }
146
-
147
- /**
148
- * Resets page and selected rows and tries to update the url
149
- * @returns Promise with data collection
150
- */
151
- public async updateDynamicFilter() {
152
- this.page = this.firstPage;
153
- this.selectedRows = [];
154
- this.visibleSelectedRows = [];
155
- if (this.watchUrl) {
156
- if (this.dynamicFilter && Object.keys(this.dynamicFilter).length) {
157
- URL.updateQueryString({
158
- dynamic_filter: btoa(JSON.stringify(this.dynamicFilter)),
159
- });
160
- } else {
161
- URL.updateQueryString({
162
- dynamic_filter: undefined,
163
- });
164
- }
165
- }
166
- return this.get();
167
- }
168
-
169
- /**
170
- * Checks if a filter value is valid
171
- * @param value Filter value
172
- * @returns Is valid filter value
173
- */
174
- protected isValidDynamicFilterValue(column: string, value?: IDictionary<any>[]) {
175
- return (
176
- !this.reservedKeys[column] &&
177
- value &&
178
- value.length > 0 &&
179
- value.every(
180
- (filterValue) =>
181
- this.dynamicFilterOperations[filterValue.operation] &&
182
- this.dynamicFilterRelations[filterValue.relation] &&
183
- filterValue.value !== '' &&
184
- filterValue.value !== null,
185
- )
186
- );
187
- }
188
-
189
- public clone() {
190
- return {
191
- ...super.clone(),
192
- dynamicFilter: this.dynamicFilter,
193
- searchJoin: this.searchJoin,
194
- type: 'tek-memory',
195
- };
196
- }
197
-
198
- /**
199
- * Updates filtered data
200
- */
201
- protected updateFilteredData() {
202
- // first apply filters (simple and dynamic)
203
- this.filteredData = Object.keys(this.filter).length
204
- ? this.allData.filter((row) => this.getRowByFilter(row))
205
- : Array.from(this.allData);
206
-
207
- if (this.dynamicFilter && Object.keys(this.dynamicFilter).length) {
208
- this.filteredData = this.filteredData.filter((row) => this.getRowByDynamicFilter(row));
209
- }
210
-
211
- const searchWithoutSearchJoin = (row: IDictionary<any>) => {
212
- const searchRow = { ...row };
213
- if (this.searchJoin) {
214
- // do not search on columns with searchJoin
215
- Object.keys(this.searchJoin).forEach((key) => delete searchRow[key]);
216
- }
217
- return this.getRowBySearch(searchRow);
218
- };
219
-
220
- // only after do the search
221
- const searchData = this.search ? this.filteredData.filter(searchWithoutSearchJoin) : this.filteredData;
222
-
223
- let searchIds = searchData.map((row) => row[this.uniqueKey]);
224
-
225
- if (this.searchJoin && Object.keys(this.searchJoin).length) {
226
- const searchJoinData = this.filteredData.filter((row) => this.getRowBySearchJoin(row));
227
-
228
- // get the ids from search and searchJoin
229
- searchIds = searchIds.concat(searchJoinData.map((row) => row[this.uniqueKey])).sort();
230
- }
231
-
232
- // filter filteredData using searchIds
233
- this.filteredData = this.allData.filter((row) => searchIds.indexOf(row[this.uniqueKey]) !== -1);
234
- }
235
-
236
- protected getRowByDynamicFilter(row: IDictionary<any>) {
237
- let filtered: any;
238
- try {
239
- Object.keys(this.dynamicFilter).forEach((key) => {
240
- const filterItems = this.dynamicFilter[key];
241
- filterItems.forEach((item) => {
242
- if (filtered === false && item.relation === 'AND') return;
243
- if (filtered === true && item.relation === 'OR') return;
244
-
245
- const columnValue = Utils.normalize(row[key].toString());
246
- let value: string | string[] = '';
247
- if (Array.isArray(item.value)) {
248
- value = item.value.map((val: string) => Utils.normalize(val.toString()));
249
-
250
- switch (item.operation) {
251
- case 'IN':
252
- filtered = value.includes(columnValue);
253
- break;
254
- case 'NOT_IN':
255
- filtered = !value.includes(columnValue);
256
- break;
257
- case 'BETWEEN':
258
- filtered =
259
- (Number(columnValue) || columnValue) >= (Number(value[0]) || value[0]) &&
260
- (Number(columnValue) || columnValue) <= (Number(value[1]) || value[1]);
261
- break;
262
- default:
263
- break;
264
- }
265
- } else {
266
- value = Utils.normalize(item.value.toString());
267
-
268
- switch (item.operation) {
269
- case 'CONTAINS':
270
- filtered = columnValue.indexOf(value) !== -1;
271
- break;
272
- case 'NOT_CONTAINS':
273
- filtered = columnValue.indexOf(value) === -1;
274
- break;
275
- case 'EQUALS':
276
- filtered = columnValue === value;
277
- break;
278
- case 'NOT_EQUALS':
279
- filtered = columnValue !== value;
280
- break;
281
- case 'GREATER_THAN':
282
- filtered = (Number(columnValue) || columnValue) > (Number(value) || value);
283
- break;
284
- case 'LESS_THAN':
285
- filtered = (Number(columnValue) || columnValue) < (Number(value) || value);
286
- break;
287
- case 'GREATER_THAN_EQUALS':
288
- filtered = (Number(columnValue) || columnValue) >= (Number(value) || value);
289
- break;
290
- case 'LESS_THAN_EQUALS':
291
- filtered = (Number(columnValue) || columnValue) <= (Number(value) || value);
292
- break;
293
- default:
294
- break;
295
- }
296
- }
297
- });
298
- });
299
- } catch {
300
- // do nothing
301
- }
302
- return filtered;
303
- }
304
-
305
- protected getRowBySearchJoin(row: IDictionary<any>) {
306
- return Object.keys(this.searchJoin).some((key) => this.searchJoin[key].includes(row[key]));
307
- }
308
-
309
- public hasFilter(columnName: string): boolean {
310
- return this.dynamicFilter[columnName] && this.dynamicFilter[columnName].length > 0;
311
- }
312
- }
313
-
314
- DatasourceFactory.register('tek-memory', TekMemoryDatasource);