@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,193 @@
|
|
|
1
|
+
import { Datasource, DatasourceFactory, IDictionary } from '@zeedhi/core';
|
|
2
|
+
import { GridColumnEditable } from '@zeedhi/common';
|
|
3
|
+
import { IFilterPropsComponent, ITekGridColumn, ITekGridColumnAggregation } from './interfaces';
|
|
4
|
+
import { TekGrid } from './tek-grid';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Base class for TekGrid column
|
|
8
|
+
*/
|
|
9
|
+
export class TekGridColumn extends GridColumnEditable implements ITekGridColumn {
|
|
10
|
+
/* filter component props */
|
|
11
|
+
public filterProps: IFilterPropsComponent | IFilterPropsComponent[] = [];
|
|
12
|
+
|
|
13
|
+
/* column can be use to filter */
|
|
14
|
+
public filterable = true;
|
|
15
|
+
|
|
16
|
+
/* Index of the column inside filter modal */
|
|
17
|
+
public filterIndex?: number;
|
|
18
|
+
|
|
19
|
+
/* should not consider lookup column on search */
|
|
20
|
+
public skipLookupSearch = false;
|
|
21
|
+
|
|
22
|
+
/* column is grouped */
|
|
23
|
+
private groupedValue = false;
|
|
24
|
+
|
|
25
|
+
/* column group is opened */
|
|
26
|
+
private groupOpenedValue?: boolean = false;
|
|
27
|
+
|
|
28
|
+
/* Value to show when grouped value is empty */
|
|
29
|
+
public groupLabelForEmptyValue = '';
|
|
30
|
+
|
|
31
|
+
/* column has aggregation */
|
|
32
|
+
private aggregationValue?: ITekGridColumnAggregation;
|
|
33
|
+
|
|
34
|
+
/* column is visible */
|
|
35
|
+
private isVisibleValue = true;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Defines if the column should store the componentProps datasource.data in memory
|
|
39
|
+
*/
|
|
40
|
+
public storeData = true;
|
|
41
|
+
|
|
42
|
+
private grid: TekGrid;
|
|
43
|
+
|
|
44
|
+
/* istanbul ignore next */
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new TekGrid Column.
|
|
47
|
+
* @param props TekGrid column properties
|
|
48
|
+
*/
|
|
49
|
+
constructor(props: ITekGridColumn, grid: TekGrid) {
|
|
50
|
+
super(props);
|
|
51
|
+
this.grid = grid;
|
|
52
|
+
this.isVisible = this.getInitValue('isVisible', props.isVisible, this.isVisible);
|
|
53
|
+
this.filterProps = this.getInitValue('filterProps', props.filterProps, this.filterProps);
|
|
54
|
+
this.filterable = this.getInitValue('filterable', props.filterable, this.filterable);
|
|
55
|
+
this.filterIndex = this.getInitValue('filterIndex', props.filterIndex, this.filterIndex);
|
|
56
|
+
this.skipLookupSearch = this.getInitValue('skipLookupSearch', props.skipLookupSearch, this.skipLookupSearch);
|
|
57
|
+
this.grouped = this.getInitValue('grouped', props.grouped, this.grouped);
|
|
58
|
+
this.groupOpened = this.getInitValue('groupOpened', props.groupOpened, this.groupOpened);
|
|
59
|
+
this.aggregation = this.getInitValue('aggregation', props.aggregation, this.aggregation);
|
|
60
|
+
this.groupLabelForEmptyValue = this.getInitValue(
|
|
61
|
+
'groupLabelForEmptyValue',
|
|
62
|
+
props.groupLabelForEmptyValue,
|
|
63
|
+
this.groupLabelForEmptyValue,
|
|
64
|
+
);
|
|
65
|
+
this.storeData = this.getInitValue('storeData', props.storeData, this.storeData);
|
|
66
|
+
this.createAccessors();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public async getBatchLookupData(lookupColumn: string, values: any[]): Promise<IDictionary[]> {
|
|
70
|
+
const batch: IDictionary[] = [];
|
|
71
|
+
const dataToLookup: any[] = [];
|
|
72
|
+
values.forEach((value) => {
|
|
73
|
+
if (this.lookupData[value]) {
|
|
74
|
+
batch.push(this.lookupData[value]);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const dataIndex = this.lookupDatasource!.data.findIndex((row) => row[lookupColumn] === value);
|
|
79
|
+
if (dataIndex !== -1) {
|
|
80
|
+
this.lookupData[value] = this.lookupDatasource!.data[dataIndex];
|
|
81
|
+
batch.push(this.lookupData[value]);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
dataToLookup.push(value);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (dataToLookup.length > 0) {
|
|
89
|
+
await this.lookupFn(lookupColumn, dataToLookup);
|
|
90
|
+
|
|
91
|
+
dataToLookup.forEach((value) => {
|
|
92
|
+
const row = this.lookupData[value];
|
|
93
|
+
if (row) batch.push(row);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return batch;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Memory search, without changing lookupDatasource
|
|
102
|
+
*/
|
|
103
|
+
public async memorySearch(search: string): Promise<any> {
|
|
104
|
+
if (!this.lookupDatasource) {
|
|
105
|
+
throw new Error("Can't search in a column that doesn't have a datasource");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let { data } = this.lookupDatasource;
|
|
109
|
+
if (this.storeData) {
|
|
110
|
+
if (!data.length) {
|
|
111
|
+
data = await this.lookupDatasource.get();
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
// datasource without the lookup filters
|
|
115
|
+
const defaultDs = DatasourceFactory.factory({
|
|
116
|
+
...this.componentProps.datasource,
|
|
117
|
+
lazyLoad: true,
|
|
118
|
+
loadAll: true,
|
|
119
|
+
});
|
|
120
|
+
defaultDs.initialize();
|
|
121
|
+
|
|
122
|
+
data = await defaultDs.get();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const { dataText } = this.componentProps;
|
|
126
|
+
const searchIn = Array.isArray(dataText) ? dataText : [dataText];
|
|
127
|
+
|
|
128
|
+
// get datasource as memory
|
|
129
|
+
const datasource: Datasource = DatasourceFactory.factory({
|
|
130
|
+
searchIn,
|
|
131
|
+
data,
|
|
132
|
+
type: 'memory',
|
|
133
|
+
loadAll: true,
|
|
134
|
+
});
|
|
135
|
+
datasource.initialize();
|
|
136
|
+
|
|
137
|
+
return datasource.setSearch(search);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get grouped() {
|
|
141
|
+
return this.groupedValue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
set grouped(value: boolean) {
|
|
145
|
+
const changed = value !== this.groupedValue;
|
|
146
|
+
this.groupedValue = value;
|
|
147
|
+
if (changed) {
|
|
148
|
+
this.changeGrouping();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get aggregation() {
|
|
153
|
+
return this.aggregationValue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
set aggregation(value: ITekGridColumnAggregation) {
|
|
157
|
+
const changed = value !== this.aggregationValue;
|
|
158
|
+
this.aggregationValue = value;
|
|
159
|
+
if (changed) {
|
|
160
|
+
this.changeGrouping();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
get groupOpened() {
|
|
165
|
+
return this.groupOpenedValue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
set groupOpened(value: boolean | undefined) {
|
|
169
|
+
const changed = value !== this.groupOpenedValue;
|
|
170
|
+
this.groupOpenedValue = value;
|
|
171
|
+
if (changed) {
|
|
172
|
+
this.changeGrouping();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* istanbul ignore next */
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
get isVisible() {
|
|
179
|
+
return this.isVisibleValue && !this.grouped;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* istanbul ignore next */
|
|
183
|
+
set isVisible(value: boolean) {
|
|
184
|
+
this.isVisibleValue = value;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private changeGrouping() {
|
|
188
|
+
// wait for grid.constructor to be fully executed
|
|
189
|
+
setTimeout(() => {
|
|
190
|
+
this.grid.updateGrouping();
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IEventParam } from '@zeedhi/core';
|
|
2
|
+
import { Checkbox, IterableColumnsButtonController } from '@zeedhi/common';
|
|
3
|
+
import { TekGridColumn } from '../tek-grid-column';
|
|
4
|
+
|
|
5
|
+
export class TekGridColumnsButtonController extends IterableColumnsButtonController {
|
|
6
|
+
public changeGroupedColumn(column: TekGridColumn, { component, event, element }: IEventParam<Checkbox>) {
|
|
7
|
+
column.grouped = component.value;
|
|
8
|
+
if (!column.grouped) {
|
|
9
|
+
const index = this.iterableComponent.datasource.order.indexOf(`${column.name}.asc`);
|
|
10
|
+
this.iterableComponent.datasource.order.splice(index, 1);
|
|
11
|
+
}
|
|
12
|
+
this.iterableComponent.changeLayout(event, element);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public changeAggregationColumn(column: TekGridColumn, { component, event, element }: IEventParam<Checkbox>) {
|
|
16
|
+
const newValue = component.value || undefined;
|
|
17
|
+
if (column.aggregation !== newValue) {
|
|
18
|
+
this.iterableComponent.changeLayout(event, element);
|
|
19
|
+
}
|
|
20
|
+
column.aggregation = newValue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public showHideTekColumn(column: TekGridColumn, { component, event, element }: IEventParam<Checkbox>) {
|
|
24
|
+
if (!component.value && column.grouped) column.grouped = false;
|
|
25
|
+
column.isVisible = component.value;
|
|
26
|
+
this.iterableComponent.changeLayout(event, element);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { I18n, Loader } from '@zeedhi/core';
|
|
2
|
+
import { IterableColumnsButton } from '@zeedhi/common';
|
|
3
|
+
import { TekGridColumn } from '../tek-grid-column';
|
|
4
|
+
import { ITekGridColumnsButton, columnAggregationValues } from '../interfaces';
|
|
5
|
+
import { TekGridColumnsButtonController } from './tek-grid-columns-button-controller';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base class for TekGrid Columns Button component
|
|
9
|
+
*/
|
|
10
|
+
export class TekGridColumnsButton extends IterableColumnsButton<TekGridColumn> implements ITekGridColumnsButton {
|
|
11
|
+
public hideGroups = false;
|
|
12
|
+
|
|
13
|
+
constructor(props: ITekGridColumnsButton) {
|
|
14
|
+
super(props);
|
|
15
|
+
this.hideGroups = this.getInitValue('hideGroups', props.hideGroups, this.hideGroups);
|
|
16
|
+
this.createAccessors();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public onCreated() {
|
|
20
|
+
super.onCreated();
|
|
21
|
+
Loader.addController(`IterableColumnsButtonController_${this.name}`, TekGridColumnsButtonController, [
|
|
22
|
+
this.iterableComponent,
|
|
23
|
+
]);
|
|
24
|
+
this.controller = Loader.getInstance(`IterableColumnsButtonController_${this.name}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private aggregationDataSet: any[] = [];
|
|
28
|
+
|
|
29
|
+
public getAggregationSelectData() {
|
|
30
|
+
if (!this.aggregationDataSet.length) {
|
|
31
|
+
this.aggregationDataSet = columnAggregationValues.filter(Boolean).map((value) => ({
|
|
32
|
+
text: I18n.translate(`TEKGRID_AGGREGATION_${value}`),
|
|
33
|
+
value,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
return this.aggregationDataSet;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { IGridEditable } from '@zeedhi/common';
|
|
2
|
+
import { ISupportsToolbar } from './interfaces';
|
|
3
|
+
|
|
4
|
+
export class TekGridController {
|
|
5
|
+
private grid!: IGridEditable & ISupportsToolbar;
|
|
6
|
+
|
|
7
|
+
public openToolbar = true;
|
|
8
|
+
|
|
9
|
+
public constructor(grid: IGridEditable & ISupportsToolbar) {
|
|
10
|
+
this.grid = grid;
|
|
11
|
+
this.openToolbar = this.grid.toolbarOpened;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public get gridTitle() {
|
|
15
|
+
return this.grid.title;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public get showAddButton() {
|
|
19
|
+
return this.grid.addButton;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public get showDeleteButton() {
|
|
23
|
+
return this.grid.deleteButton !== 'none';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public get showFilterButton() {
|
|
27
|
+
return this.grid.filterButton;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public get showModalFilterProps() {
|
|
31
|
+
return this.grid.modalFilterProps;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public get showSearchInput() {
|
|
35
|
+
return this.grid.showSearch;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public get showToolbar() {
|
|
39
|
+
return this.openToolbar;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public set showToolbar(value: boolean) {
|
|
43
|
+
this.openToolbar = value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public get toolbarClass(): string {
|
|
47
|
+
return !this.openToolbar ? 'is-rotated' : '';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public get tooltipName() {
|
|
51
|
+
return !this.openToolbar ? 'TEKGRID_SHOW' : 'TEKGRID_HIDE';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public get showReloadButton() {
|
|
55
|
+
return this.grid.showReload;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public get showDivider2() {
|
|
59
|
+
return (
|
|
60
|
+
this.showReloadButton &&
|
|
61
|
+
(this.showLayoutOptionsButton ||
|
|
62
|
+
this.showColumnsButton ||
|
|
63
|
+
this.showActionsButton ||
|
|
64
|
+
this.showExportButton ||
|
|
65
|
+
this.showSearchInput)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public get showColumnsButton() {
|
|
70
|
+
return this.grid.columnsButton;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public get columnsButtonIgnore() {
|
|
74
|
+
return this.grid.columnsButtonIgnore;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public get showLayoutOptionsButton() {
|
|
78
|
+
return this.grid.showLayoutOptions;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public get showDivider1() {
|
|
82
|
+
return (
|
|
83
|
+
(this.showAddButton || this.showDeleteButton) &&
|
|
84
|
+
(this.showReloadButton ||
|
|
85
|
+
this.showLayoutOptionsButton ||
|
|
86
|
+
this.showColumnsButton ||
|
|
87
|
+
this.showActionsButton ||
|
|
88
|
+
this.showExportButton ||
|
|
89
|
+
this.showSearchInput)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public get showActionsButton() {
|
|
94
|
+
return this.grid.actions.length > 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public get showExportButton() {
|
|
98
|
+
return this.grid.showExport;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public get showActionAndExportButton() {
|
|
102
|
+
return (
|
|
103
|
+
(this.showLayoutOptionsButton || this.showColumnsButton) &&
|
|
104
|
+
(this.showActionsButton || this.showExportButton || this.showSearchInput)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public get showDivider3() {
|
|
109
|
+
return (this.showActionsButton || this.showExportButton) && this.showSearchInput;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public get isEditing() {
|
|
113
|
+
return this.grid.editing;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public get showEditButtons() {
|
|
117
|
+
return this.isEditing && this.grid.showEditButtons;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public get isNotEditing() {
|
|
121
|
+
return !this.isEditing;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public get disableDeleteButton() {
|
|
125
|
+
if (this.grid.deleteButton === 'selection') {
|
|
126
|
+
if (this.grid.selectAllPages) {
|
|
127
|
+
const { allSelected, except } = this.grid.selectionState;
|
|
128
|
+
return (allSelected && except.length === this.grid.datasource.total) || (!allSelected && except.length === 0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return this.grid.selectedRows.length === 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (this.grid.deleteButton === 'currentRow') {
|
|
135
|
+
return !this.grid.datasource.currentRow[this.grid.datasource.uniqueKey];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { IDictionary } from '@zeedhi/core';
|
|
2
|
+
import { GridEditableEvents } from '@zeedhi/common';
|
|
3
|
+
import { ITekGrid, ITekGridEvents, ITekGridSummary } from './interfaces';
|
|
4
|
+
import { TekGridColumn } from './tek-grid-column';
|
|
5
|
+
|
|
6
|
+
export class TekGridEvents extends GridEditableEvents implements ITekGridEvents {
|
|
7
|
+
protected tekGrid: ITekGrid;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Flag to prevent row click
|
|
11
|
+
*/
|
|
12
|
+
protected preventRowClick = false;
|
|
13
|
+
|
|
14
|
+
protected preventRowDoubleClick = false;
|
|
15
|
+
|
|
16
|
+
constructor(tekGrid: ITekGrid) {
|
|
17
|
+
super(tekGrid);
|
|
18
|
+
this.tekGrid = tekGrid;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
calcSummary(column: TekGridColumn, summary: ITekGridSummary, row: IDictionary): void {
|
|
22
|
+
this.tekGrid.callEvent('calcSummary', {
|
|
23
|
+
component: this.tekGrid,
|
|
24
|
+
column,
|
|
25
|
+
columnName: column.name,
|
|
26
|
+
summary,
|
|
27
|
+
row,
|
|
28
|
+
rowValue: row[column.name],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public rowDoubleClick(row: IDictionary<any>, event: Event, element: HTMLElement) {
|
|
33
|
+
if (!this.preventRowDoubleClick) {
|
|
34
|
+
this.tekGrid.datasource.currentRow = row;
|
|
35
|
+
|
|
36
|
+
this.tekGrid.callEvent('rowDoubleClick', {
|
|
37
|
+
event,
|
|
38
|
+
element,
|
|
39
|
+
row,
|
|
40
|
+
component: this.tekGrid,
|
|
41
|
+
column: undefined,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
this.preventRowDoubleClick = false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Dispatches group row click event
|
|
49
|
+
* @param row Grid row
|
|
50
|
+
* @param event DOM event
|
|
51
|
+
* @param element DOM Element
|
|
52
|
+
*/
|
|
53
|
+
public groupRowClick(row: IDictionary<any>, event: Event, element: HTMLElement) {
|
|
54
|
+
if (!this.preventRowClick) {
|
|
55
|
+
this.tekGrid.callEvent('groupRowClick', {
|
|
56
|
+
event,
|
|
57
|
+
element,
|
|
58
|
+
row,
|
|
59
|
+
component: this.tekGrid,
|
|
60
|
+
column: undefined,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
this.preventRowClick = false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public groupRowDoubleClick(row: IDictionary<any>, event: Event, element: HTMLElement) {
|
|
67
|
+
if (!this.preventRowDoubleClick) {
|
|
68
|
+
this.tekGrid.callEvent('groupRowDoubleClick', {
|
|
69
|
+
event,
|
|
70
|
+
element,
|
|
71
|
+
row,
|
|
72
|
+
component: this.tekGrid,
|
|
73
|
+
column: undefined,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
this.preventRowDoubleClick = false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Dispatches group select/unselect event
|
|
81
|
+
* @param row Group row
|
|
82
|
+
* @param isSelected Row is selected
|
|
83
|
+
* @param event DOM event
|
|
84
|
+
* @param element DOM Element
|
|
85
|
+
*/
|
|
86
|
+
public selectGroupClick(row: IDictionary<any>, isSelected: boolean, event: Event, element: HTMLElement) {
|
|
87
|
+
if (isSelected) {
|
|
88
|
+
this.tekGrid.callEvent('groupSelected', {
|
|
89
|
+
event,
|
|
90
|
+
element,
|
|
91
|
+
row,
|
|
92
|
+
component: this.tekGrid,
|
|
93
|
+
column: undefined,
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
this.tekGrid.callEvent('groupUnselected', {
|
|
97
|
+
event,
|
|
98
|
+
element,
|
|
99
|
+
row,
|
|
100
|
+
component: this.tekGrid,
|
|
101
|
+
column: undefined,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IComponent } from '@zeedhi/common';
|
|
2
|
+
import { IExportable, ITekGridExportConfig } from '../../interfaces';
|
|
3
|
+
import { IExportOption } from './interfaces';
|
|
4
|
+
|
|
5
|
+
export class ButtonOption implements IExportOption {
|
|
6
|
+
private config: ITekGridExportConfig;
|
|
7
|
+
|
|
8
|
+
constructor(config: ITekGridExportConfig) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
buildComponent(grid: IComponent & IExportable) {
|
|
13
|
+
const { type, label, portrait = true, iconName } = this.config;
|
|
14
|
+
const orientation = portrait ? 'portrait' : 'landscape';
|
|
15
|
+
return {
|
|
16
|
+
label,
|
|
17
|
+
iconName,
|
|
18
|
+
name: `${grid.name}_export_${type}_${orientation}`,
|
|
19
|
+
component: 'ZdButton',
|
|
20
|
+
flat: true,
|
|
21
|
+
events: {
|
|
22
|
+
click: () => grid.getReport(type, portrait) as any,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { IButton, IComponent, IDivider, IRow, IText, ITooltip } from '@zeedhi/common';
|
|
2
|
+
import { IExportable, ITekGridExportConfig, MultiOptionParams } from '../../interfaces';
|
|
3
|
+
import { IExportOption } from './interfaces';
|
|
4
|
+
|
|
5
|
+
export class MultiOption implements IExportOption {
|
|
6
|
+
private config: ITekGridExportConfig;
|
|
7
|
+
|
|
8
|
+
constructor(config: ITekGridExportConfig) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private formatName(id: string, type: string, grid: IComponent & IExportable) {
|
|
13
|
+
return `${grid.name}_export_${type}_${id}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private buildTooltip(option: MultiOptionParams, type: string, grid: IComponent & IExportable): ITooltip {
|
|
17
|
+
const { label } = option;
|
|
18
|
+
return {
|
|
19
|
+
name: this.formatName(`tooltip_${label}`, type, grid),
|
|
20
|
+
component: 'ZdTooltip',
|
|
21
|
+
bottom: true,
|
|
22
|
+
label,
|
|
23
|
+
children: [],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private buildButton(option: MultiOptionParams, type: string, grid: IComponent & IExportable): IButton {
|
|
28
|
+
const { cssClass, label, iconName, reportParams } = option;
|
|
29
|
+
const { portrait: optionPortrait, rowObj } = reportParams || {};
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
name: this.formatName(`button_${label}`, type, grid),
|
|
33
|
+
component: 'ZdButton',
|
|
34
|
+
cssClass,
|
|
35
|
+
icon: true,
|
|
36
|
+
iconName,
|
|
37
|
+
events: {
|
|
38
|
+
click: () => grid.getReport(type, optionPortrait, rowObj) as any,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private buildDivider(option: MultiOptionParams, type: string, grid: IComponent & IExportable): IDivider {
|
|
44
|
+
const { label } = option;
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
name: this.formatName(`divider_${label}`, type, grid),
|
|
48
|
+
component: 'ZdDivider',
|
|
49
|
+
cssClass: 'zd-my-1',
|
|
50
|
+
vertical: true,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
buildComponent(grid: IComponent & IExportable) {
|
|
55
|
+
const { type, label, multiOption } = this.config;
|
|
56
|
+
|
|
57
|
+
const optionComponents = multiOption!.flatMap((option) => [
|
|
58
|
+
{
|
|
59
|
+
...this.buildTooltip(option, type, grid),
|
|
60
|
+
children: [this.buildButton(option, type, grid)],
|
|
61
|
+
},
|
|
62
|
+
this.buildDivider(option, type, grid),
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
optionComponents.pop();
|
|
66
|
+
|
|
67
|
+
const text: IText = {
|
|
68
|
+
name: this.formatName('text', type, grid),
|
|
69
|
+
component: 'ZdText',
|
|
70
|
+
cssClass: 'zd-display-flex zd-align-center zd-flex-grow-1 tek-grid-export-multioption-text',
|
|
71
|
+
events: {
|
|
72
|
+
click: ({ event }) => event?.stopPropagation(),
|
|
73
|
+
},
|
|
74
|
+
text: label || '',
|
|
75
|
+
};
|
|
76
|
+
const result: IRow = {
|
|
77
|
+
name: this.formatName('row', type, grid),
|
|
78
|
+
component: 'ZdRow',
|
|
79
|
+
cssClass: 'zd-display-flex zd-ma-0 zd-py-0 zd-gap-x-1 tek-grid-export-multioption-row',
|
|
80
|
+
children: [text, ...optionComponents],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
}
|