@zeedhi/teknisa-components-common 1.88.0 → 1.90.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.
- package/coverage/clover.xml +679 -622
- package/coverage/coverage-final.json +41 -39
- package/coverage/lcov-report/index.html +31 -16
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +4 -4
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +12 -12
- package/coverage/lcov-report/tests/__helpers__/index.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +5 -5
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +4 -4
- package/coverage/lcov.info +1135 -1038
- package/dist/tek-components-common.esm.js +613 -496
- package/dist/tek-components-common.umd.js +615 -497
- package/package.json +3 -2
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +112 -0
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +846 -0
- package/tests/unit/components/tek-grid/grid.spec.ts +20 -769
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +15 -9
- package/types/components/index.d.ts +3 -0
- package/types/components/tek-drag-grid/interfaces.d.ts +7 -0
- package/types/components/tek-drag-grid/tek-drag-grid.d.ts +36 -0
- package/types/components/tek-grid/grid-filter-button.d.ts +29 -0
- package/types/components/tek-grid/interfaces.d.ts +6 -2
- package/types/utils/grid-base/grid-base.d.ts +9 -19
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { KeyMap, I18n, FormatterParserProvider, Messages,
|
|
2
|
-
import { Form, Button, Tooltip, GridEditable, Grid, ComponentRender, Iterable, Carousel, IterableComponentRender as IterableComponentRender$1, Loading as Loading$1,
|
|
1
|
+
import { KeyMap, I18n, FormatterParserProvider, Messages, DatasourceFactory, Metadata, MemoryDatasource, URL, Utils, RestDatasource, Loader, DateHelper, Config, Http, Singleton, VersionService } from '@zeedhi/core';
|
|
2
|
+
import { Form, Button, Tooltip, GridEditable, Grid, ComponentRender, Iterable, Carousel, IterableComponentRender as IterableComponentRender$1, Loading as Loading$1, GridColumnEditable, Report, ColumnNotFoundError, IterableColumnsButtonController, IterableColumnsButton, ModalService, TreeGridEditable, List } from '@zeedhi/common';
|
|
3
3
|
import debounce from 'lodash.debounce';
|
|
4
4
|
import merge from 'lodash.merge';
|
|
5
5
|
import { UserInfo } from '@zeedhi/zd-user-info-common';
|
|
6
|
+
import { Draggable } from '@zeedhi/zd-drag-grid-common';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Form to be used on Crud operations
|
|
@@ -713,7 +714,6 @@ class TekGridDeleteRowsError extends Error {
|
|
|
713
714
|
class GridBase {
|
|
714
715
|
constructor(grid) {
|
|
715
716
|
this.exportConfigButtons = [];
|
|
716
|
-
this.filterFormInputs = {};
|
|
717
717
|
this.atoms = {
|
|
718
718
|
TITLE: '_gridTitle',
|
|
719
719
|
ADD_BUTTON: '_addButton',
|
|
@@ -942,18 +942,21 @@ class GridBase {
|
|
|
942
942
|
children: [
|
|
943
943
|
{
|
|
944
944
|
name: `${this.grid.name}_filterButton`,
|
|
945
|
-
component: '
|
|
946
|
-
|
|
947
|
-
|
|
945
|
+
component: 'TekGridFilterButton',
|
|
946
|
+
grid: this.grid,
|
|
947
|
+
gridName: this.grid.name,
|
|
948
948
|
isVisible: `{{GridController_${this.grid.componentId}.showFilterButton}}`,
|
|
949
949
|
events: {
|
|
950
|
-
|
|
950
|
+
onCreated: this.loadFilterButton.bind(this),
|
|
951
951
|
},
|
|
952
952
|
},
|
|
953
953
|
],
|
|
954
954
|
},
|
|
955
955
|
];
|
|
956
956
|
}
|
|
957
|
+
loadFilterButton({ component }) {
|
|
958
|
+
this.filterButton = component;
|
|
959
|
+
}
|
|
957
960
|
addButtonClick({ event }) {
|
|
958
961
|
if (this.grid.editNewRowsOnly) {
|
|
959
962
|
this.grid.editingNewRows = true;
|
|
@@ -998,344 +1001,37 @@ class GridBase {
|
|
|
998
1001
|
this.grid.callEvent('afterCancel', { component: this.grid });
|
|
999
1002
|
}
|
|
1000
1003
|
}
|
|
1001
|
-
filterClick({ event }) {
|
|
1002
|
-
this.grid.callEvent('filterClick', { component: this.grid, event });
|
|
1003
|
-
if (!event.defaultPrevented) {
|
|
1004
|
-
this.createFilterFromColumns();
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
destroyFilterModal() {
|
|
1008
|
-
var _a;
|
|
1009
|
-
(_a = this.filterModal) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
1010
|
-
}
|
|
1011
|
-
createFilterFromColumns() {
|
|
1012
|
-
if (!this.filterModal) {
|
|
1013
|
-
const originalProps = {
|
|
1014
|
-
height: 'auto',
|
|
1015
|
-
persistent: true,
|
|
1016
|
-
title: 'FILTER',
|
|
1017
|
-
};
|
|
1018
|
-
const mergeModalFilterProps = Object.assign(originalProps, this.grid.modalFilterProps);
|
|
1019
|
-
const filterModalDef = {
|
|
1020
|
-
name: `${this.grid.name}-filter-modal`,
|
|
1021
|
-
persistent: mergeModalFilterProps.persistent,
|
|
1022
|
-
grid: mergeModalFilterProps.grid,
|
|
1023
|
-
cssClass: mergeModalFilterProps.cssClass,
|
|
1024
|
-
cssStyle: mergeModalFilterProps.cssStyle,
|
|
1025
|
-
draggable: mergeModalFilterProps.draggable,
|
|
1026
|
-
dragHandle: mergeModalFilterProps.dragHandle,
|
|
1027
|
-
fullscreen: mergeModalFilterProps.fullscreen,
|
|
1028
|
-
light: mergeModalFilterProps.light,
|
|
1029
|
-
dark: mergeModalFilterProps.dark,
|
|
1030
|
-
escKeydownStop: false,
|
|
1031
|
-
children: [
|
|
1032
|
-
{
|
|
1033
|
-
name: `${this.grid.name}-filter-header-container`,
|
|
1034
|
-
component: 'ZdContainer',
|
|
1035
|
-
cssClass: 'zd-pa-0',
|
|
1036
|
-
children: [
|
|
1037
|
-
{
|
|
1038
|
-
name: `${this.grid.name}-filter-modal-header`,
|
|
1039
|
-
component: 'ZdHeader',
|
|
1040
|
-
color: 'transparent',
|
|
1041
|
-
padless: true,
|
|
1042
|
-
elevation: 0,
|
|
1043
|
-
leftSlot: [
|
|
1044
|
-
{
|
|
1045
|
-
name: `${this.grid.name}-filter-title`,
|
|
1046
|
-
component: 'ZdText',
|
|
1047
|
-
cssStyle: `color: ${'var(--v-primary-base);'}`,
|
|
1048
|
-
text: `${mergeModalFilterProps.title}`,
|
|
1049
|
-
tag: 'h3',
|
|
1050
|
-
},
|
|
1051
|
-
],
|
|
1052
|
-
rightSlot: [
|
|
1053
|
-
{
|
|
1054
|
-
name: `${this.grid.name}-filter-close-button`,
|
|
1055
|
-
component: 'ZdModalCloseButton',
|
|
1056
|
-
small: true,
|
|
1057
|
-
modalName: `${this.grid.name}-filter-modal`,
|
|
1058
|
-
},
|
|
1059
|
-
],
|
|
1060
|
-
},
|
|
1061
|
-
],
|
|
1062
|
-
},
|
|
1063
|
-
{
|
|
1064
|
-
name: `${this.grid.name}-filter-content-container`,
|
|
1065
|
-
component: 'ZdContainer',
|
|
1066
|
-
scrollView: true,
|
|
1067
|
-
cssClass: 'zd-my-2 zd-pa-0',
|
|
1068
|
-
maxHeight: '18.75rem',
|
|
1069
|
-
height: this.grid.modalFilterProps.height,
|
|
1070
|
-
children: [
|
|
1071
|
-
{
|
|
1072
|
-
name: `${this.grid.name}-filter-form`,
|
|
1073
|
-
component: 'ZdForm',
|
|
1074
|
-
cssClass: 'zd-my-2',
|
|
1075
|
-
children: this.getFilterModalComponents(),
|
|
1076
|
-
events: {
|
|
1077
|
-
onMounted: this.loadFilterValues.bind(this),
|
|
1078
|
-
},
|
|
1079
|
-
},
|
|
1080
|
-
],
|
|
1081
|
-
},
|
|
1082
|
-
{
|
|
1083
|
-
name: `${this.grid.name}-filter-footer-container`,
|
|
1084
|
-
component: 'ZdContainer',
|
|
1085
|
-
cssClass: 'zd-pa-0',
|
|
1086
|
-
children: [
|
|
1087
|
-
{
|
|
1088
|
-
name: `${this.grid.name}-filter-footer`,
|
|
1089
|
-
component: 'ZdFooter',
|
|
1090
|
-
color: 'transparent',
|
|
1091
|
-
padless: true,
|
|
1092
|
-
leftSlot: [
|
|
1093
|
-
{
|
|
1094
|
-
name: `${this.grid.name}-filter-clearButton`,
|
|
1095
|
-
component: 'ZdButton',
|
|
1096
|
-
label: 'CLEAR',
|
|
1097
|
-
outline: true,
|
|
1098
|
-
events: {
|
|
1099
|
-
click: this.clearFilter.bind(this),
|
|
1100
|
-
},
|
|
1101
|
-
},
|
|
1102
|
-
],
|
|
1103
|
-
rightSlot: [
|
|
1104
|
-
{
|
|
1105
|
-
name: `${this.grid.name}-filter-cancelButton`,
|
|
1106
|
-
component: 'ZdButton',
|
|
1107
|
-
label: 'CANCEL',
|
|
1108
|
-
keyMap: {
|
|
1109
|
-
esc: {
|
|
1110
|
-
event: this.hideFilterModal.bind(this),
|
|
1111
|
-
focus: true,
|
|
1112
|
-
visible: true,
|
|
1113
|
-
input: true,
|
|
1114
|
-
stop: true,
|
|
1115
|
-
},
|
|
1116
|
-
},
|
|
1117
|
-
outline: true,
|
|
1118
|
-
events: {
|
|
1119
|
-
click: this.hideFilterModal.bind(this),
|
|
1120
|
-
},
|
|
1121
|
-
},
|
|
1122
|
-
{
|
|
1123
|
-
name: `${this.grid.name}-filter-okButton`,
|
|
1124
|
-
component: 'ZdButton',
|
|
1125
|
-
label: 'OK',
|
|
1126
|
-
events: {
|
|
1127
|
-
click: this.applyFilter.bind(this),
|
|
1128
|
-
},
|
|
1129
|
-
keyMap: {
|
|
1130
|
-
'mod+enter': {
|
|
1131
|
-
event: this.applyFilter.bind(this),
|
|
1132
|
-
focus: true,
|
|
1133
|
-
input: true,
|
|
1134
|
-
stop: true,
|
|
1135
|
-
visible: true,
|
|
1136
|
-
},
|
|
1137
|
-
},
|
|
1138
|
-
},
|
|
1139
|
-
],
|
|
1140
|
-
},
|
|
1141
|
-
],
|
|
1142
|
-
},
|
|
1143
|
-
],
|
|
1144
|
-
};
|
|
1145
|
-
this.filterModal = ModalService.create(filterModalDef);
|
|
1146
|
-
}
|
|
1147
|
-
else {
|
|
1148
|
-
this.loadFilterValues({ component: Metadata.getInstance(`${this.grid.name}-filter-form`) });
|
|
1149
|
-
}
|
|
1150
|
-
this.filterModal.show();
|
|
1151
|
-
}
|
|
1152
1004
|
hideFilterModal() {
|
|
1153
|
-
this.
|
|
1154
|
-
}
|
|
1155
|
-
sortFilterIndex(col1, col2) {
|
|
1156
|
-
const index1 = col1.filterIndex !== undefined ? col1.filterIndex : Number.MAX_SAFE_INTEGER;
|
|
1157
|
-
const index2 = col2.filterIndex !== undefined ? col2.filterIndex : Number.MAX_SAFE_INTEGER;
|
|
1158
|
-
return index1 - index2;
|
|
1005
|
+
this.filterButton.hideFilterModal();
|
|
1159
1006
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
if (column.filterable && filterProps && filterProps.length > 0) {
|
|
1166
|
-
this.filterFormInputs[column.name] = [];
|
|
1167
|
-
filterProps.forEach((filterItem, index) => {
|
|
1168
|
-
const { datasource } = this.grid;
|
|
1169
|
-
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
1170
|
-
const relation = filterItem.relation || 'AND';
|
|
1171
|
-
const operation = filterItem.operation || 'CONTAINS';
|
|
1172
|
-
columnComponentName = `${this.grid.name}-filter-${relation}-${operation}-${column.name}-${index}`;
|
|
1173
|
-
}
|
|
1174
|
-
else {
|
|
1175
|
-
columnComponentName = `${this.grid.name}-filter-AND-CONTAINS-${column.name}-${index}`;
|
|
1176
|
-
}
|
|
1177
|
-
this.filterFormInputs[column.name].push(columnComponentName);
|
|
1178
|
-
const newColumnComponent = Object.assign(Object.assign(Object.assign({ label: column.label }, column.componentProps), filterItem), { name: columnComponentName });
|
|
1179
|
-
if (filterItem.helperOptions) {
|
|
1180
|
-
if (!newColumnComponent.events)
|
|
1181
|
-
newColumnComponent.events = {};
|
|
1182
|
-
newColumnComponent.events.change = this.changeHelperEvent.bind(this, column);
|
|
1183
|
-
}
|
|
1184
|
-
filterColumns.push(newColumnComponent);
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1007
|
+
getFilterRelationsDatasource() {
|
|
1008
|
+
return DatasourceFactory.factory({
|
|
1009
|
+
data: this.getFilterOptionsData('relations'),
|
|
1010
|
+
loadAll: true,
|
|
1011
|
+
translate: ['text'],
|
|
1187
1012
|
});
|
|
1188
|
-
return filterColumns;
|
|
1189
1013
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1196
|
-
else {
|
|
1197
|
-
column.filterProps.forEach((prop) => {
|
|
1198
|
-
const relationAndOperationAndName = componentName.split(`${this.grid.name}-filter-`)[1];
|
|
1199
|
-
const [relation, operation] = relationAndOperationAndName.split('-');
|
|
1200
|
-
if ((prop.relation || 'AND') === relation && (prop.operation || 'CONTAINS') === operation) {
|
|
1201
|
-
prop.helperValue = helperValue;
|
|
1202
|
-
}
|
|
1203
|
-
});
|
|
1204
|
-
}
|
|
1014
|
+
getFilterOperationsDatasource() {
|
|
1015
|
+
return DatasourceFactory.factory({
|
|
1016
|
+
data: this.getFilterOptionsData('operations'),
|
|
1017
|
+
loadAll: true,
|
|
1018
|
+
translate: ['text'],
|
|
1019
|
+
});
|
|
1205
1020
|
}
|
|
1206
|
-
|
|
1207
|
-
const changedCompNames = [];
|
|
1021
|
+
getFilterOptionsData(prop) {
|
|
1208
1022
|
const { datasource } = this.grid;
|
|
1209
1023
|
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
if (columnObj instanceof TekGridColumn) {
|
|
1222
|
-
const { filterProps } = columnObj;
|
|
1223
|
-
if (!Array.isArray(filterProps)) {
|
|
1224
|
-
helperValue = filterProps.helperValue || '';
|
|
1225
|
-
}
|
|
1226
|
-
else {
|
|
1227
|
-
filterProps.forEach((prop) => {
|
|
1228
|
-
if ((prop.relation || 'AND') === relation && (prop.operation || 'CONTAINS') === operation) {
|
|
1229
|
-
helperValue = prop.helperValue || '';
|
|
1230
|
-
}
|
|
1231
|
-
});
|
|
1232
|
-
}
|
|
1233
|
-
const inputObj = Metadata.getInstances(compName);
|
|
1234
|
-
if (helperValue && inputObj.length && inputObj[0]) {
|
|
1235
|
-
inputObj[0].hint = TekFilterHelper.getLabel(helperValue);
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
});
|
|
1239
|
-
}
|
|
1240
|
-
});
|
|
1241
|
-
}
|
|
1242
|
-
else {
|
|
1243
|
-
const { filter } = datasource;
|
|
1244
|
-
Object.keys(filter).forEach((item) => {
|
|
1245
|
-
if (filter[item]) {
|
|
1246
|
-
const compName = `${this.grid.name}-filter-AND-CONTAINS-${item}-0`;
|
|
1247
|
-
changedCompNames.push(compName);
|
|
1248
|
-
component.value[compName] = filter[item];
|
|
1249
|
-
}
|
|
1250
|
-
});
|
|
1251
|
-
}
|
|
1252
|
-
Object.keys(component.value).forEach((compName) => {
|
|
1253
|
-
if (changedCompNames.indexOf(compName) === -1) {
|
|
1254
|
-
component.value[compName] = null;
|
|
1255
|
-
}
|
|
1256
|
-
});
|
|
1257
|
-
}
|
|
1258
|
-
applyFilter({ event }) {
|
|
1259
|
-
const filterForm = Metadata.getInstance(`${this.grid.name}-filter-form`);
|
|
1260
|
-
if (filterForm.validate()) {
|
|
1261
|
-
const { datasource } = this.grid;
|
|
1262
|
-
const filter = {};
|
|
1263
|
-
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
1264
|
-
Object.keys(filterForm.value).forEach((item) => {
|
|
1265
|
-
if (filterForm.value[item] && !(Array.isArray(filterForm.value[item]) && !filterForm.value[item].length)) {
|
|
1266
|
-
const relationAndOperationAndName = item.split(`${this.grid.name}-filter-`)[1];
|
|
1267
|
-
const [relation, operation] = relationAndOperationAndName.split('-');
|
|
1268
|
-
let columnName = relationAndOperationAndName.split(`${relation}-${operation}-`)[1];
|
|
1269
|
-
columnName = columnName.split('-').slice(0, -1).join('-'); // remove index
|
|
1270
|
-
if (!filter[columnName]) {
|
|
1271
|
-
filter[columnName] = [];
|
|
1272
|
-
}
|
|
1273
|
-
const value = filterForm.value[item];
|
|
1274
|
-
filter[columnName].push({
|
|
1275
|
-
relation,
|
|
1276
|
-
operation,
|
|
1277
|
-
value,
|
|
1278
|
-
});
|
|
1279
|
-
}
|
|
1280
|
-
});
|
|
1281
|
-
datasource.dynamicFilter = filter;
|
|
1282
|
-
this.setFilter(filter, event, datasource.setDynamicFilter.bind(datasource));
|
|
1283
|
-
}
|
|
1284
|
-
else {
|
|
1285
|
-
Object.keys(filterForm.value).forEach((item) => {
|
|
1286
|
-
let columnName = item.split(`${this.grid.name}-filter-AND-CONTAINS-`)[1];
|
|
1287
|
-
columnName = columnName.split('-').slice(0, -1).join('-'); // remove index
|
|
1288
|
-
if (filterForm.value[item]) {
|
|
1289
|
-
filter[columnName] = filterForm.value[item];
|
|
1290
|
-
}
|
|
1291
|
-
});
|
|
1292
|
-
datasource.filter = filter;
|
|
1293
|
-
this.setFilter(filter, event, datasource.setFilter.bind(datasource));
|
|
1294
|
-
}
|
|
1295
|
-
this.grid.changeLayout(event);
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
setFilter(filter, event, filterFn) {
|
|
1299
|
-
this.grid.callEvent('beforeApplyFilter', { component: this.grid, event });
|
|
1300
|
-
if (event.defaultPrevented)
|
|
1301
|
-
return;
|
|
1302
|
-
filterFn(filter);
|
|
1303
|
-
this.hideFilterModal();
|
|
1304
|
-
}
|
|
1305
|
-
clearFilter() {
|
|
1306
|
-
const filterForm = Metadata.getInstance(`${this.grid.name}-filter-form`);
|
|
1307
|
-
Object.keys(filterForm.value).forEach((item) => {
|
|
1308
|
-
filterForm.value[item] = null;
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
getFilterRelationsDatasource() {
|
|
1312
|
-
return DatasourceFactory.factory({
|
|
1313
|
-
data: this.getFilterOptionsData('relations'),
|
|
1314
|
-
loadAll: true,
|
|
1315
|
-
translate: ['text'],
|
|
1316
|
-
});
|
|
1317
|
-
}
|
|
1318
|
-
getFilterOperationsDatasource() {
|
|
1319
|
-
return DatasourceFactory.factory({
|
|
1320
|
-
data: this.getFilterOptionsData('operations'),
|
|
1321
|
-
loadAll: true,
|
|
1322
|
-
translate: ['text'],
|
|
1323
|
-
});
|
|
1324
|
-
}
|
|
1325
|
-
getFilterOptionsData(prop) {
|
|
1326
|
-
const { datasource } = this.grid;
|
|
1327
|
-
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
1328
|
-
let options;
|
|
1329
|
-
if (prop === 'relations') {
|
|
1330
|
-
options = Object.keys(datasource.dynamicFilterRelations);
|
|
1331
|
-
}
|
|
1332
|
-
else {
|
|
1333
|
-
options = Object.keys(datasource.dynamicFilterOperations);
|
|
1334
|
-
}
|
|
1335
|
-
return options.map((item) => ({
|
|
1336
|
-
text: `TEKGRID_${item}`,
|
|
1337
|
-
value: item,
|
|
1338
|
-
}));
|
|
1024
|
+
let options;
|
|
1025
|
+
if (prop === 'relations') {
|
|
1026
|
+
options = Object.keys(datasource.dynamicFilterRelations);
|
|
1027
|
+
}
|
|
1028
|
+
else {
|
|
1029
|
+
options = Object.keys(datasource.dynamicFilterOperations);
|
|
1030
|
+
}
|
|
1031
|
+
return options.map((item) => ({
|
|
1032
|
+
text: `TEKGRID_${item}`,
|
|
1033
|
+
value: item,
|
|
1034
|
+
}));
|
|
1339
1035
|
}
|
|
1340
1036
|
return [];
|
|
1341
1037
|
}
|
|
@@ -1363,12 +1059,7 @@ class GridBase {
|
|
|
1363
1059
|
return Metadata.getInstance(`${this.grid.name}${this.atoms[key]}`);
|
|
1364
1060
|
}
|
|
1365
1061
|
getFilterInputs(columnName) {
|
|
1366
|
-
|
|
1367
|
-
if (columnName) {
|
|
1368
|
-
return this.filterFormInputs[columnName].map(mapper);
|
|
1369
|
-
}
|
|
1370
|
-
const values = Object.values(this.filterFormInputs);
|
|
1371
|
-
return values.reduce((result, current) => ([...result, ...current.map(mapper)]), []);
|
|
1062
|
+
return this.filterButton.getFilterInputs(columnName);
|
|
1372
1063
|
}
|
|
1373
1064
|
}
|
|
1374
1065
|
Messages.add({
|
|
@@ -2493,10 +2184,10 @@ class TekGrid extends GridEditable {
|
|
|
2493
2184
|
input: true,
|
|
2494
2185
|
},
|
|
2495
2186
|
};
|
|
2187
|
+
this.createAccessors();
|
|
2496
2188
|
this.gridBase = new GridBase(this);
|
|
2497
2189
|
this.filterOperationsDatasource = this.gridBase.getFilterOperationsDatasource();
|
|
2498
2190
|
this.filterRelationsDatasource = this.gridBase.getFilterRelationsDatasource();
|
|
2499
|
-
this.createAccessors();
|
|
2500
2191
|
this.defaultLazy = (_a = props.datasource) === null || _a === void 0 ? void 0 : _a.lazyLoad;
|
|
2501
2192
|
}
|
|
2502
2193
|
onCreated() {
|
|
@@ -2522,7 +2213,6 @@ class TekGrid extends GridEditable {
|
|
|
2522
2213
|
}
|
|
2523
2214
|
onBeforeDestroy() {
|
|
2524
2215
|
super.onBeforeDestroy();
|
|
2525
|
-
this.gridBase.destroyFilterModal();
|
|
2526
2216
|
KeyMap.unbind(this.keyShortcutKeyMapping, this);
|
|
2527
2217
|
}
|
|
2528
2218
|
focusSearchInput() {
|
|
@@ -2936,156 +2626,515 @@ class TekGrid extends GridEditable {
|
|
|
2936
2626
|
if (currentRow.group) {
|
|
2937
2627
|
return row.group && row.groupValue === currentRow.groupValue;
|
|
2938
2628
|
}
|
|
2939
|
-
return row[uniqueKey] && row[uniqueKey] === currentRow[uniqueKey];
|
|
2629
|
+
return row[uniqueKey] && row[uniqueKey] === currentRow[uniqueKey];
|
|
2630
|
+
});
|
|
2631
|
+
if (rowIndex === -1)
|
|
2632
|
+
rowIndex = this.groupedData.length;
|
|
2633
|
+
const newRow = this.groupedData[rowIndex - 1];
|
|
2634
|
+
if (newRow && this.isItemVisible(newRow) && !newRow.groupFooter) {
|
|
2635
|
+
this.datasource.currentRow = newRow;
|
|
2636
|
+
}
|
|
2637
|
+
else {
|
|
2638
|
+
this.navigateUp({ index: rowIndex - 1 });
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
navigateLeft() {
|
|
2643
|
+
var _a;
|
|
2644
|
+
const { currentRow } = this.datasource;
|
|
2645
|
+
if (currentRow.group && currentRow.groupOpened) {
|
|
2646
|
+
currentRow.groupOpened = false;
|
|
2647
|
+
}
|
|
2648
|
+
else if ((_a = currentRow.groupHeaders) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2649
|
+
this.datasource.currentRow = currentRow.groupHeaders[currentRow.groupHeaders.length - 1];
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
navigateRight() {
|
|
2653
|
+
const { currentRow } = this.datasource;
|
|
2654
|
+
if (currentRow.group && !currentRow.groupOpened) {
|
|
2655
|
+
currentRow.groupOpened = true;
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
/**
|
|
2659
|
+
* Dispatches row click event
|
|
2660
|
+
* @param row Grid row
|
|
2661
|
+
* @param event DOM event
|
|
2662
|
+
* @param element DOM Element
|
|
2663
|
+
*/
|
|
2664
|
+
rowClick(row, event, element) {
|
|
2665
|
+
if (!this.preventRowClick) {
|
|
2666
|
+
this.datasource.currentRow = row;
|
|
2667
|
+
this.callEvent('rowClick', {
|
|
2668
|
+
event,
|
|
2669
|
+
element,
|
|
2670
|
+
row,
|
|
2671
|
+
component: this,
|
|
2672
|
+
column: undefined,
|
|
2673
|
+
});
|
|
2674
|
+
}
|
|
2675
|
+
this.preventRowClick = false;
|
|
2676
|
+
}
|
|
2677
|
+
/**
|
|
2678
|
+
* Dispatches group row click event
|
|
2679
|
+
* @param row Grid row
|
|
2680
|
+
* @param event DOM event
|
|
2681
|
+
* @param element DOM Element
|
|
2682
|
+
*/
|
|
2683
|
+
groupRowClick(row, event, element) {
|
|
2684
|
+
if (!this.preventRowClick) {
|
|
2685
|
+
this.callEvent('groupRowClick', {
|
|
2686
|
+
event,
|
|
2687
|
+
element,
|
|
2688
|
+
row,
|
|
2689
|
+
component: this,
|
|
2690
|
+
column: undefined,
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
this.preventRowClick = false;
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Dispatches group select/unselect event
|
|
2697
|
+
* @param row Group row
|
|
2698
|
+
* @param isSelected Row is selected
|
|
2699
|
+
* @param event DOM event
|
|
2700
|
+
* @param element DOM Element
|
|
2701
|
+
*/
|
|
2702
|
+
selectGroupClick(row, isSelected, event, element) {
|
|
2703
|
+
if (isSelected) {
|
|
2704
|
+
this.callEvent('groupSelected', {
|
|
2705
|
+
event,
|
|
2706
|
+
element,
|
|
2707
|
+
row,
|
|
2708
|
+
component: this,
|
|
2709
|
+
column: undefined,
|
|
2710
|
+
});
|
|
2711
|
+
}
|
|
2712
|
+
else {
|
|
2713
|
+
this.callEvent('groupUnselected', {
|
|
2714
|
+
event,
|
|
2715
|
+
element,
|
|
2716
|
+
row,
|
|
2717
|
+
component: this,
|
|
2718
|
+
column: undefined,
|
|
2719
|
+
});
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
getAtomInstance(key) {
|
|
2723
|
+
return this.gridBase.getAtomInstance(key);
|
|
2724
|
+
}
|
|
2725
|
+
getFilterInputs(columnName) {
|
|
2726
|
+
return this.gridBase.getFilterInputs(columnName);
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
class TekGridColumnsButtonController extends IterableColumnsButtonController {
|
|
2731
|
+
changeGroupedColumn(column, { component, event, element }) {
|
|
2732
|
+
column.grouped = component.value;
|
|
2733
|
+
if (!column.grouped) {
|
|
2734
|
+
const index = this.iterableComponent.datasource.order.indexOf(`${column.name}.asc`);
|
|
2735
|
+
this.iterableComponent.datasource.order.splice(index, 1);
|
|
2736
|
+
}
|
|
2737
|
+
this.iterableComponent.changeLayout(event, element);
|
|
2738
|
+
}
|
|
2739
|
+
changeAggregationColumn(column, { component, event, element }) {
|
|
2740
|
+
const newValue = component.value || undefined;
|
|
2741
|
+
if (column.aggregation !== newValue) {
|
|
2742
|
+
this.iterableComponent.changeLayout(event, element);
|
|
2743
|
+
}
|
|
2744
|
+
column.aggregation = newValue;
|
|
2745
|
+
}
|
|
2746
|
+
showHideTekColumn(column, { component, event, element }) {
|
|
2747
|
+
if (!component.value && column.grouped)
|
|
2748
|
+
column.grouped = false;
|
|
2749
|
+
column.isVisible = component.value;
|
|
2750
|
+
this.iterableComponent.changeLayout(event, element);
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
/**
|
|
2755
|
+
* Base class for TekGrid Columns Button component
|
|
2756
|
+
*/
|
|
2757
|
+
class TekGridColumnsButton extends IterableColumnsButton {
|
|
2758
|
+
constructor(props) {
|
|
2759
|
+
super(props);
|
|
2760
|
+
this.hideGroups = false;
|
|
2761
|
+
this.aggregationDataSet = [];
|
|
2762
|
+
this.hideGroups = this.getInitValue('hideGroups', props.hideGroups, this.hideGroups);
|
|
2763
|
+
this.createAccessors();
|
|
2764
|
+
}
|
|
2765
|
+
onCreated() {
|
|
2766
|
+
super.onCreated();
|
|
2767
|
+
this.controller = new TekGridColumnsButtonController(this.iterableComponent);
|
|
2768
|
+
Loader.addController(`IterableColumnsButtonController_${this.componentId}`, this.controller);
|
|
2769
|
+
}
|
|
2770
|
+
getAggregationSelectData() {
|
|
2771
|
+
if (!this.aggregationDataSet.length) {
|
|
2772
|
+
this.aggregationDataSet = columnAggregationValues.filter(Boolean).map((value) => ({
|
|
2773
|
+
text: I18n.translate(`TEKGRID_AGGREGATION_${value}`),
|
|
2774
|
+
value,
|
|
2775
|
+
}));
|
|
2776
|
+
}
|
|
2777
|
+
return this.aggregationDataSet;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
class TekFilterHelper {
|
|
2782
|
+
static getLabel(name) {
|
|
2783
|
+
return DateHelper.getLabel(name);
|
|
2784
|
+
}
|
|
2785
|
+
static getValue(name, column) {
|
|
2786
|
+
return DateHelper.getValue(name, column.componentProps.dateFormat);
|
|
2787
|
+
}
|
|
2788
|
+
static register(name, label, fn) {
|
|
2789
|
+
DateHelper.register(name, label, fn);
|
|
2790
|
+
}
|
|
2791
|
+
static unregister(name) {
|
|
2792
|
+
DateHelper.unregister(name);
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
/**
|
|
2797
|
+
* Base class for TekGrid Filter Button component
|
|
2798
|
+
*/
|
|
2799
|
+
class TekGridFilterButton extends Button {
|
|
2800
|
+
constructor(props) {
|
|
2801
|
+
super(props);
|
|
2802
|
+
this.filterFormInputs = {};
|
|
2803
|
+
this.gridName = this.getInitValue('gridName', props.gridName, this.gridName);
|
|
2804
|
+
this.grid = this.getInitValue('grid', props.grid, undefined);
|
|
2805
|
+
this.createAccessors();
|
|
2806
|
+
if (!this.grid)
|
|
2807
|
+
this.loadGrid();
|
|
2808
|
+
}
|
|
2809
|
+
loadGrid(gridName) {
|
|
2810
|
+
if (gridName)
|
|
2811
|
+
this.gridName = gridName;
|
|
2812
|
+
if (!this.gridName)
|
|
2813
|
+
return;
|
|
2814
|
+
this.grid = Metadata.getInstances(this.gridName)[0];
|
|
2815
|
+
}
|
|
2816
|
+
click(event) {
|
|
2817
|
+
this.callEvent('click', { component: this, event });
|
|
2818
|
+
this.grid.callEvent('filterClick', { component: this.grid, event });
|
|
2819
|
+
if (!event.defaultPrevented) {
|
|
2820
|
+
this.createFilterFromColumns.call(this);
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
loadFilterValues({ component }) {
|
|
2824
|
+
const changedCompNames = [];
|
|
2825
|
+
const { datasource } = this.grid;
|
|
2826
|
+
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
2827
|
+
const { dynamicFilter } = datasource;
|
|
2828
|
+
Object.keys(dynamicFilter).forEach((column) => {
|
|
2829
|
+
if (dynamicFilter[column] && dynamicFilter[column].length > 0) {
|
|
2830
|
+
dynamicFilter[column].forEach((filterItem, index) => {
|
|
2831
|
+
const relation = filterItem.relation || 'AND';
|
|
2832
|
+
const operation = filterItem.operation || 'CONTAINS';
|
|
2833
|
+
const compName = `${this.grid.name}-filter-${relation}-${operation}-${column}-${index}`;
|
|
2834
|
+
changedCompNames.push(compName);
|
|
2835
|
+
component.value[compName] = filterItem.value;
|
|
2836
|
+
let helperValue = '';
|
|
2837
|
+
const columnObj = this.grid.getColumn(column);
|
|
2838
|
+
if (columnObj instanceof TekGridColumn) {
|
|
2839
|
+
const { filterProps } = columnObj;
|
|
2840
|
+
if (!Array.isArray(filterProps)) {
|
|
2841
|
+
helperValue = filterProps.helperValue || '';
|
|
2842
|
+
}
|
|
2843
|
+
else {
|
|
2844
|
+
filterProps.forEach((prop) => {
|
|
2845
|
+
if ((prop.relation || 'AND') === relation && (prop.operation || 'CONTAINS') === operation) {
|
|
2846
|
+
helperValue = prop.helperValue || '';
|
|
2847
|
+
}
|
|
2848
|
+
});
|
|
2849
|
+
}
|
|
2850
|
+
const inputObj = Metadata.getInstances(compName);
|
|
2851
|
+
if (helperValue && inputObj.length && inputObj[0]) {
|
|
2852
|
+
inputObj[0].hint = TekFilterHelper.getLabel(helperValue);
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
});
|
|
2856
|
+
}
|
|
2857
|
+
});
|
|
2858
|
+
}
|
|
2859
|
+
else {
|
|
2860
|
+
const { filter } = datasource;
|
|
2861
|
+
Object.keys(filter).forEach((item) => {
|
|
2862
|
+
if (filter[item]) {
|
|
2863
|
+
const compName = `${this.grid.name}-filter-AND-CONTAINS-${item}-0`;
|
|
2864
|
+
changedCompNames.push(compName);
|
|
2865
|
+
component.value[compName] = filter[item];
|
|
2866
|
+
}
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2869
|
+
Object.keys(component.value).forEach((compName) => {
|
|
2870
|
+
if (changedCompNames.indexOf(compName) === -1) {
|
|
2871
|
+
component.value[compName] = null;
|
|
2872
|
+
}
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2875
|
+
hideFilterModal() {
|
|
2876
|
+
this.filterModal.hide();
|
|
2877
|
+
}
|
|
2878
|
+
destroyFilterModal() {
|
|
2879
|
+
this.filterModal.destroy();
|
|
2880
|
+
}
|
|
2881
|
+
createFilterFromColumns() {
|
|
2882
|
+
if (!this.filterModal) {
|
|
2883
|
+
const originalProps = {
|
|
2884
|
+
height: 'auto',
|
|
2885
|
+
persistent: true,
|
|
2886
|
+
title: 'FILTER',
|
|
2887
|
+
};
|
|
2888
|
+
const mergeModalFilterProps = Object.assign(originalProps, this.grid.modalFilterProps);
|
|
2889
|
+
const filterModalDef = {
|
|
2890
|
+
name: `${this.grid.name}-filter-modal`,
|
|
2891
|
+
persistent: mergeModalFilterProps.persistent,
|
|
2892
|
+
grid: mergeModalFilterProps.grid,
|
|
2893
|
+
cssClass: mergeModalFilterProps.cssClass,
|
|
2894
|
+
cssStyle: mergeModalFilterProps.cssStyle,
|
|
2895
|
+
draggable: mergeModalFilterProps.draggable,
|
|
2896
|
+
dragHandle: mergeModalFilterProps.dragHandle,
|
|
2897
|
+
fullscreen: mergeModalFilterProps.fullscreen,
|
|
2898
|
+
light: mergeModalFilterProps.light,
|
|
2899
|
+
dark: mergeModalFilterProps.dark,
|
|
2900
|
+
escKeydownStop: false,
|
|
2901
|
+
children: [
|
|
2902
|
+
{
|
|
2903
|
+
name: `${this.grid.name}-filter-header-container`,
|
|
2904
|
+
component: 'ZdContainer',
|
|
2905
|
+
cssClass: 'zd-pa-0',
|
|
2906
|
+
children: [
|
|
2907
|
+
{
|
|
2908
|
+
name: `${this.grid.name}-filter-modal-header`,
|
|
2909
|
+
component: 'ZdHeader',
|
|
2910
|
+
color: 'transparent',
|
|
2911
|
+
padless: true,
|
|
2912
|
+
elevation: 0,
|
|
2913
|
+
leftSlot: [
|
|
2914
|
+
{
|
|
2915
|
+
name: `${this.grid.name}-filter-title`,
|
|
2916
|
+
component: 'ZdText',
|
|
2917
|
+
cssStyle: `color: ${'var(--v-primary-base);'}`,
|
|
2918
|
+
text: `${mergeModalFilterProps.title}`,
|
|
2919
|
+
tag: 'h3',
|
|
2920
|
+
},
|
|
2921
|
+
],
|
|
2922
|
+
rightSlot: [
|
|
2923
|
+
{
|
|
2924
|
+
name: `${this.grid.name}-filter-close-button`,
|
|
2925
|
+
component: 'ZdModalCloseButton',
|
|
2926
|
+
small: true,
|
|
2927
|
+
modalName: `${this.grid.name}-filter-modal`,
|
|
2928
|
+
},
|
|
2929
|
+
],
|
|
2930
|
+
},
|
|
2931
|
+
],
|
|
2932
|
+
},
|
|
2933
|
+
{
|
|
2934
|
+
name: `${this.grid.name}-filter-content-container`,
|
|
2935
|
+
component: 'ZdContainer',
|
|
2936
|
+
scrollView: true,
|
|
2937
|
+
cssClass: 'zd-my-2 zd-pa-0',
|
|
2938
|
+
maxHeight: '18.75rem',
|
|
2939
|
+
height: this.grid.modalFilterProps.height,
|
|
2940
|
+
children: [
|
|
2941
|
+
{
|
|
2942
|
+
name: `${this.grid.name}-filter-form`,
|
|
2943
|
+
component: 'ZdForm',
|
|
2944
|
+
cssClass: 'zd-my-2',
|
|
2945
|
+
children: this.getFilterModalComponents(),
|
|
2946
|
+
events: {
|
|
2947
|
+
onMounted: this.loadFilterValues.bind(this),
|
|
2948
|
+
},
|
|
2949
|
+
},
|
|
2950
|
+
],
|
|
2951
|
+
},
|
|
2952
|
+
{
|
|
2953
|
+
name: `${this.grid.name}-filter-footer-container`,
|
|
2954
|
+
component: 'ZdContainer',
|
|
2955
|
+
cssClass: 'zd-pa-0',
|
|
2956
|
+
children: [
|
|
2957
|
+
{
|
|
2958
|
+
name: `${this.grid.name}-filter-footer`,
|
|
2959
|
+
component: 'ZdFooter',
|
|
2960
|
+
color: 'transparent',
|
|
2961
|
+
padless: true,
|
|
2962
|
+
leftSlot: [
|
|
2963
|
+
{
|
|
2964
|
+
name: `${this.grid.name}-filter-clearButton`,
|
|
2965
|
+
component: 'ZdButton',
|
|
2966
|
+
label: 'CLEAR',
|
|
2967
|
+
outline: true,
|
|
2968
|
+
events: {
|
|
2969
|
+
click: this.clearFilter.bind(this),
|
|
2970
|
+
},
|
|
2971
|
+
},
|
|
2972
|
+
],
|
|
2973
|
+
rightSlot: [
|
|
2974
|
+
{
|
|
2975
|
+
name: `${this.grid.name}-filter-cancelButton`,
|
|
2976
|
+
component: 'ZdButton',
|
|
2977
|
+
label: 'CANCEL',
|
|
2978
|
+
keyMap: {
|
|
2979
|
+
esc: {
|
|
2980
|
+
event: this.hideFilterModal.bind(this),
|
|
2981
|
+
focus: true,
|
|
2982
|
+
visible: true,
|
|
2983
|
+
input: true,
|
|
2984
|
+
stop: true,
|
|
2985
|
+
},
|
|
2986
|
+
},
|
|
2987
|
+
outline: true,
|
|
2988
|
+
events: {
|
|
2989
|
+
click: this.hideFilterModal.bind(this),
|
|
2990
|
+
},
|
|
2991
|
+
},
|
|
2992
|
+
{
|
|
2993
|
+
name: `${this.grid.name}-filter-okButton`,
|
|
2994
|
+
component: 'ZdButton',
|
|
2995
|
+
label: 'OK',
|
|
2996
|
+
events: {
|
|
2997
|
+
click: this.applyFilter.bind(this),
|
|
2998
|
+
},
|
|
2999
|
+
keyMap: {
|
|
3000
|
+
'mod+enter': {
|
|
3001
|
+
event: this.applyFilter.bind(this),
|
|
3002
|
+
focus: true,
|
|
3003
|
+
input: true,
|
|
3004
|
+
stop: true,
|
|
3005
|
+
visible: true,
|
|
3006
|
+
},
|
|
3007
|
+
},
|
|
3008
|
+
},
|
|
3009
|
+
],
|
|
3010
|
+
},
|
|
3011
|
+
],
|
|
3012
|
+
},
|
|
3013
|
+
],
|
|
3014
|
+
};
|
|
3015
|
+
this.filterModal = ModalService.create(filterModalDef);
|
|
3016
|
+
}
|
|
3017
|
+
else {
|
|
3018
|
+
this.loadFilterValues({ component: Metadata.getInstance(`${this.grid.name}-filter-form`) });
|
|
3019
|
+
}
|
|
3020
|
+
this.filterModal.show();
|
|
3021
|
+
}
|
|
3022
|
+
onBeforeDestroy() {
|
|
3023
|
+
super.onBeforeDestroy();
|
|
3024
|
+
this.destroyFilterModal();
|
|
3025
|
+
}
|
|
3026
|
+
applyFilter({ event }) {
|
|
3027
|
+
const filterForm = Metadata.getInstance(`${this.grid.name}-filter-form`);
|
|
3028
|
+
if (filterForm.validate()) {
|
|
3029
|
+
const { datasource } = this.grid;
|
|
3030
|
+
const filter = {};
|
|
3031
|
+
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
3032
|
+
Object.keys(filterForm.value).forEach((item) => {
|
|
3033
|
+
if (filterForm.value[item] && !(Array.isArray(filterForm.value[item]) && !filterForm.value[item].length)) {
|
|
3034
|
+
const relationAndOperationAndName = item.split(`${this.grid.name}-filter-`)[1];
|
|
3035
|
+
const [relation, operation] = relationAndOperationAndName.split('-');
|
|
3036
|
+
let columnName = relationAndOperationAndName.split(`${relation}-${operation}-`)[1];
|
|
3037
|
+
columnName = columnName.split('-').slice(0, -1).join('-'); // remove index
|
|
3038
|
+
if (!filter[columnName]) {
|
|
3039
|
+
filter[columnName] = [];
|
|
3040
|
+
}
|
|
3041
|
+
const value = filterForm.value[item];
|
|
3042
|
+
filter[columnName].push({
|
|
3043
|
+
relation,
|
|
3044
|
+
operation,
|
|
3045
|
+
value,
|
|
3046
|
+
});
|
|
3047
|
+
}
|
|
2940
3048
|
});
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
const newRow = this.groupedData[rowIndex - 1];
|
|
2944
|
-
if (newRow && this.isItemVisible(newRow) && !newRow.groupFooter) {
|
|
2945
|
-
this.datasource.currentRow = newRow;
|
|
3049
|
+
datasource.dynamicFilter = filter;
|
|
3050
|
+
this.setFilter(filter, event, datasource.setDynamicFilter.bind(datasource));
|
|
2946
3051
|
}
|
|
2947
3052
|
else {
|
|
2948
|
-
|
|
3053
|
+
Object.keys(filterForm.value).forEach((item) => {
|
|
3054
|
+
let columnName = item.split(`${this.grid.name}-filter-AND-CONTAINS-`)[1];
|
|
3055
|
+
columnName = columnName.split('-').slice(0, -1).join('-'); // remove index
|
|
3056
|
+
if (filterForm.value[item]) {
|
|
3057
|
+
filter[columnName] = filterForm.value[item];
|
|
3058
|
+
}
|
|
3059
|
+
});
|
|
3060
|
+
datasource.filter = filter;
|
|
3061
|
+
this.setFilter(filter, event, datasource.setFilter.bind(datasource));
|
|
2949
3062
|
}
|
|
3063
|
+
this.grid.changeLayout(event);
|
|
2950
3064
|
}
|
|
2951
3065
|
}
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
else if ((_a = currentRow.groupHeaders) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2959
|
-
this.datasource.currentRow = currentRow.groupHeaders[currentRow.groupHeaders.length - 1];
|
|
2960
|
-
}
|
|
3066
|
+
setFilter(filter, event, filterFn) {
|
|
3067
|
+
this.grid.callEvent('beforeApplyFilter', { component: this.grid, event });
|
|
3068
|
+
if (event.defaultPrevented)
|
|
3069
|
+
return;
|
|
3070
|
+
filterFn(filter);
|
|
3071
|
+
this.hideFilterModal();
|
|
2961
3072
|
}
|
|
2962
|
-
|
|
2963
|
-
const
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
}
|
|
3073
|
+
clearFilter() {
|
|
3074
|
+
const filterForm = Metadata.getInstance(`${this.grid.name}-filter-form`);
|
|
3075
|
+
Object.keys(filterForm.value).forEach((item) => {
|
|
3076
|
+
filterForm.value[item] = null;
|
|
3077
|
+
});
|
|
2967
3078
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
* @param element DOM Element
|
|
2973
|
-
*/
|
|
2974
|
-
rowClick(row, event, element) {
|
|
2975
|
-
if (!this.preventRowClick) {
|
|
2976
|
-
this.datasource.currentRow = row;
|
|
2977
|
-
this.callEvent('rowClick', {
|
|
2978
|
-
event,
|
|
2979
|
-
element,
|
|
2980
|
-
row,
|
|
2981
|
-
component: this,
|
|
2982
|
-
column: undefined,
|
|
2983
|
-
});
|
|
2984
|
-
}
|
|
2985
|
-
this.preventRowClick = false;
|
|
3079
|
+
sortFilterIndex(col1, col2) {
|
|
3080
|
+
const index1 = col1.filterIndex !== undefined ? col1.filterIndex : Number.MAX_SAFE_INTEGER;
|
|
3081
|
+
const index2 = col2.filterIndex !== undefined ? col2.filterIndex : Number.MAX_SAFE_INTEGER;
|
|
3082
|
+
return index1 - index2;
|
|
2986
3083
|
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
* @param element DOM Element
|
|
2992
|
-
*/
|
|
2993
|
-
groupRowClick(row, event, element) {
|
|
2994
|
-
if (!this.preventRowClick) {
|
|
2995
|
-
this.callEvent('groupRowClick', {
|
|
2996
|
-
event,
|
|
2997
|
-
element,
|
|
2998
|
-
row,
|
|
2999
|
-
component: this,
|
|
3000
|
-
column: undefined,
|
|
3001
|
-
});
|
|
3084
|
+
getFilterInputs(columnName) {
|
|
3085
|
+
const mapper = (name) => Metadata.getInstance(name);
|
|
3086
|
+
if (columnName) {
|
|
3087
|
+
return this.filterFormInputs[columnName].map(mapper);
|
|
3002
3088
|
}
|
|
3003
|
-
|
|
3089
|
+
const values = Object.values(this.filterFormInputs);
|
|
3090
|
+
return values.reduce((result, current) => ([...result, ...current.map(mapper)]), []);
|
|
3004
3091
|
}
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3092
|
+
getFilterModalComponents() {
|
|
3093
|
+
const filterColumns = [];
|
|
3094
|
+
let columnComponentName;
|
|
3095
|
+
[...this.grid.columns].sort(this.sortFilterIndex).forEach((column) => {
|
|
3096
|
+
const filterProps = Array.isArray(column.filterProps) ? column.filterProps : [column.filterProps];
|
|
3097
|
+
if (column.filterable && filterProps && filterProps.length > 0) {
|
|
3098
|
+
this.filterFormInputs[column.name] = [];
|
|
3099
|
+
filterProps.forEach((filterItem, index) => {
|
|
3100
|
+
const { datasource } = this.grid;
|
|
3101
|
+
if (datasource instanceof TekRestDatasource || datasource instanceof TekMemoryDatasource) {
|
|
3102
|
+
const relation = filterItem.relation || 'AND';
|
|
3103
|
+
const operation = filterItem.operation || 'CONTAINS';
|
|
3104
|
+
columnComponentName = `${this.grid.name}-filter-${relation}-${operation}-${column.name}-${index}`;
|
|
3105
|
+
}
|
|
3106
|
+
else {
|
|
3107
|
+
columnComponentName = `${this.grid.name}-filter-AND-CONTAINS-${column.name}-${index}`;
|
|
3108
|
+
}
|
|
3109
|
+
this.filterFormInputs[column.name].push(columnComponentName);
|
|
3110
|
+
const newColumnComponent = Object.assign(Object.assign(Object.assign({ label: column.label }, column.componentProps), filterItem), { name: columnComponentName });
|
|
3111
|
+
if (filterItem.helperOptions) {
|
|
3112
|
+
if (!newColumnComponent.events)
|
|
3113
|
+
newColumnComponent.events = {};
|
|
3114
|
+
newColumnComponent.events.change = this.changeHelperEvent.bind(this, column);
|
|
3115
|
+
}
|
|
3116
|
+
filterColumns.push(newColumnComponent);
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
});
|
|
3120
|
+
return filterColumns;
|
|
3121
|
+
}
|
|
3122
|
+
changeHelperEvent(column, { component }) {
|
|
3123
|
+
const { helperValue } = component;
|
|
3124
|
+
const componentName = component.name;
|
|
3125
|
+
if (!Array.isArray(column.filterProps)) {
|
|
3126
|
+
column.filterProps.helperValue = helperValue;
|
|
3021
3127
|
}
|
|
3022
3128
|
else {
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3129
|
+
column.filterProps.forEach((prop) => {
|
|
3130
|
+
const relationAndOperationAndName = componentName.split(`${this.grid.name}-filter-`)[1];
|
|
3131
|
+
const [relation, operation] = relationAndOperationAndName.split('-');
|
|
3132
|
+
if ((prop.relation || 'AND') === relation && (prop.operation || 'CONTAINS') === operation) {
|
|
3133
|
+
prop.helperValue = helperValue;
|
|
3134
|
+
}
|
|
3029
3135
|
});
|
|
3030
3136
|
}
|
|
3031
3137
|
}
|
|
3032
|
-
getAtomInstance(key) {
|
|
3033
|
-
return this.gridBase.getAtomInstance(key);
|
|
3034
|
-
}
|
|
3035
|
-
getFilterInputs(columnName) {
|
|
3036
|
-
return this.gridBase.getFilterInputs(columnName);
|
|
3037
|
-
}
|
|
3038
|
-
}
|
|
3039
|
-
|
|
3040
|
-
class TekGridColumnsButtonController extends IterableColumnsButtonController {
|
|
3041
|
-
changeGroupedColumn(column, { component, event, element }) {
|
|
3042
|
-
column.grouped = component.value;
|
|
3043
|
-
if (!column.grouped) {
|
|
3044
|
-
const index = this.iterableComponent.datasource.order.indexOf(`${column.name}.asc`);
|
|
3045
|
-
this.iterableComponent.datasource.order.splice(index, 1);
|
|
3046
|
-
}
|
|
3047
|
-
this.iterableComponent.changeLayout(event, element);
|
|
3048
|
-
}
|
|
3049
|
-
changeAggregationColumn(column, { component, event, element }) {
|
|
3050
|
-
const newValue = component.value || undefined;
|
|
3051
|
-
if (column.aggregation !== newValue) {
|
|
3052
|
-
this.iterableComponent.changeLayout(event, element);
|
|
3053
|
-
}
|
|
3054
|
-
column.aggregation = newValue;
|
|
3055
|
-
}
|
|
3056
|
-
showHideTekColumn(column, { component, event, element }) {
|
|
3057
|
-
if (!component.value && column.grouped)
|
|
3058
|
-
column.grouped = false;
|
|
3059
|
-
column.isVisible = component.value;
|
|
3060
|
-
this.iterableComponent.changeLayout(event, element);
|
|
3061
|
-
}
|
|
3062
|
-
}
|
|
3063
|
-
|
|
3064
|
-
/**
|
|
3065
|
-
* Base class for TekGrid Columns Button component
|
|
3066
|
-
*/
|
|
3067
|
-
class TekGridColumnsButton extends IterableColumnsButton {
|
|
3068
|
-
constructor(props) {
|
|
3069
|
-
super(props);
|
|
3070
|
-
this.hideGroups = false;
|
|
3071
|
-
this.aggregationDataSet = [];
|
|
3072
|
-
this.hideGroups = this.getInitValue('hideGroups', props.hideGroups, this.hideGroups);
|
|
3073
|
-
this.createAccessors();
|
|
3074
|
-
}
|
|
3075
|
-
onCreated() {
|
|
3076
|
-
super.onCreated();
|
|
3077
|
-
this.controller = new TekGridColumnsButtonController(this.iterableComponent);
|
|
3078
|
-
Loader.addController(`IterableColumnsButtonController_${this.componentId}`, this.controller);
|
|
3079
|
-
}
|
|
3080
|
-
getAggregationSelectData() {
|
|
3081
|
-
if (!this.aggregationDataSet.length) {
|
|
3082
|
-
this.aggregationDataSet = columnAggregationValues.filter(Boolean).map((value) => ({
|
|
3083
|
-
text: I18n.translate(`TEKGRID_AGGREGATION_${value}`),
|
|
3084
|
-
value,
|
|
3085
|
-
}));
|
|
3086
|
-
}
|
|
3087
|
-
return this.aggregationDataSet;
|
|
3088
|
-
}
|
|
3089
3138
|
}
|
|
3090
3139
|
|
|
3091
3140
|
class TekGridLayoutOptions extends ComponentRender {
|
|
@@ -3274,21 +3323,6 @@ class TekGridLayoutOptions extends ComponentRender {
|
|
|
3274
3323
|
}
|
|
3275
3324
|
}
|
|
3276
3325
|
|
|
3277
|
-
class TekFilterHelper {
|
|
3278
|
-
static getLabel(name) {
|
|
3279
|
-
return DateHelper.getLabel(name);
|
|
3280
|
-
}
|
|
3281
|
-
static getValue(name, column) {
|
|
3282
|
-
return DateHelper.getValue(name, column.componentProps.dateFormat);
|
|
3283
|
-
}
|
|
3284
|
-
static register(name, label, fn) {
|
|
3285
|
-
DateHelper.register(name, label, fn);
|
|
3286
|
-
}
|
|
3287
|
-
static unregister(name) {
|
|
3288
|
-
DateHelper.unregister(name);
|
|
3289
|
-
}
|
|
3290
|
-
}
|
|
3291
|
-
|
|
3292
3326
|
/* TekTreeGrid Class */
|
|
3293
3327
|
class TekTreeGrid extends TreeGridEditable {
|
|
3294
3328
|
/**
|
|
@@ -3961,6 +3995,89 @@ class TekUserInfoList extends List {
|
|
|
3961
3995
|
}
|
|
3962
3996
|
}
|
|
3963
3997
|
|
|
3998
|
+
class TekDragGrid extends TekGrid {
|
|
3999
|
+
constructor(props) {
|
|
4000
|
+
super(Object.assign(Object.assign({}, props), { datasource: Object.assign(Object.assign({}, props.datasource), { order: [`${props.orderColumnName}.${props.orderMode || 'asc'}`] }) }));
|
|
4001
|
+
this.internalOrderColumnName = '';
|
|
4002
|
+
this.internalOrderMode = 'asc';
|
|
4003
|
+
this.internalOrderColumnName = this.getInitValue('orderColumnName', props.orderColumnName, this.orderColumnName);
|
|
4004
|
+
this.internalOrderMode = this.getInitValue('orderMode', props.orderMode, this.orderMode);
|
|
4005
|
+
this.createAccessors();
|
|
4006
|
+
this.draggable = new Draggable(this.orderColumnName, this.orderMode);
|
|
4007
|
+
}
|
|
4008
|
+
set orderColumnName(value) {
|
|
4009
|
+
this.internalOrderColumnName = value;
|
|
4010
|
+
this.draggable.orderColumnName = value;
|
|
4011
|
+
}
|
|
4012
|
+
get orderColumnName() {
|
|
4013
|
+
return this.internalOrderColumnName;
|
|
4014
|
+
}
|
|
4015
|
+
set orderMode(value) {
|
|
4016
|
+
this.internalOrderMode = value;
|
|
4017
|
+
this.draggable.orderColumnName = value;
|
|
4018
|
+
}
|
|
4019
|
+
get orderMode() {
|
|
4020
|
+
return this.internalOrderMode;
|
|
4021
|
+
}
|
|
4022
|
+
/**
|
|
4023
|
+
* Event triggered when dragged element is moving
|
|
4024
|
+
* @param event DOM event
|
|
4025
|
+
* @param row row being dragged
|
|
4026
|
+
* @param element HTML element
|
|
4027
|
+
* @returns return false to cancel dragging
|
|
4028
|
+
*/
|
|
4029
|
+
onDragMove(event, row, element) {
|
|
4030
|
+
this.callEvent('onDragMove', {
|
|
4031
|
+
component: this,
|
|
4032
|
+
event,
|
|
4033
|
+
row,
|
|
4034
|
+
element,
|
|
4035
|
+
});
|
|
4036
|
+
return true;
|
|
4037
|
+
}
|
|
4038
|
+
/**
|
|
4039
|
+
* Event triggered when drag starts
|
|
4040
|
+
* @param event DOM event
|
|
4041
|
+
* @param row row being dragged
|
|
4042
|
+
* @param element HTML element
|
|
4043
|
+
*/
|
|
4044
|
+
onDragStart(event, row, element) {
|
|
4045
|
+
return this.callEvent('onDragStart', {
|
|
4046
|
+
component: this,
|
|
4047
|
+
event,
|
|
4048
|
+
row,
|
|
4049
|
+
element,
|
|
4050
|
+
});
|
|
4051
|
+
}
|
|
4052
|
+
/**
|
|
4053
|
+
* Event triggered when drag ends
|
|
4054
|
+
* @param event DOM event
|
|
4055
|
+
* @param row row being dragged
|
|
4056
|
+
* @param element HTML element
|
|
4057
|
+
*/
|
|
4058
|
+
onDragEnd(event, row, element) {
|
|
4059
|
+
const { oldIndex, newIndex } = event;
|
|
4060
|
+
const changes = this.draggable.getDragChanges(oldIndex, newIndex, this.datasource, this.getEditedRows());
|
|
4061
|
+
this.editing = true;
|
|
4062
|
+
changes.forEach((change) => {
|
|
4063
|
+
this.changeEditableComponent({ name: this.orderColumnName }, change.row, change.value);
|
|
4064
|
+
});
|
|
4065
|
+
this.callEvent('inlineEdit', {
|
|
4066
|
+
event,
|
|
4067
|
+
element,
|
|
4068
|
+
row,
|
|
4069
|
+
column: { name: this.orderColumnName },
|
|
4070
|
+
component: this,
|
|
4071
|
+
});
|
|
4072
|
+
this.callEvent('onDragEnd', {
|
|
4073
|
+
component: this,
|
|
4074
|
+
event,
|
|
4075
|
+
row,
|
|
4076
|
+
element,
|
|
4077
|
+
});
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
|
|
3964
4081
|
Messages.add({
|
|
3965
4082
|
'pt-BR': {
|
|
3966
4083
|
translation: {
|
|
@@ -4012,4 +4129,4 @@ Messages.add({
|
|
|
4012
4129
|
const packageContent = require('../package.json');
|
|
4013
4130
|
VersionService.addPackageVersion(packageContent.name, packageContent.version);
|
|
4014
4131
|
|
|
4015
|
-
export { BreadcrumbHeader, CardTitle, CrudAddButton, CrudButton, CrudCancelButton, CrudDeleteButton, CrudForm, CrudSaveButton, DynamicFilterOperations, DynamicFilterRelations, Image, IterableCarousel, IterableComponentRender, Loading, Notifications, ProductCard, TekFilterHelper, TekGrid, TekGridColumn, TekGridColumnsButton, TekGridLayoutOptions, TekMemoryDatasource, TekRestDatasource, TekTreeGrid, TekUserInfo, TekUserInfoList, columnAggregationValues };
|
|
4132
|
+
export { BreadcrumbHeader, CardTitle, CrudAddButton, CrudButton, CrudCancelButton, CrudDeleteButton, CrudForm, CrudSaveButton, DynamicFilterOperations, DynamicFilterRelations, Image, IterableCarousel, IterableComponentRender, Loading, Notifications, ProductCard, TekDragGrid, TekFilterHelper, TekGrid, TekGridColumn, TekGridColumnsButton, TekGridFilterButton, TekGridLayoutOptions, TekMemoryDatasource, TekRestDatasource, TekTreeGrid, TekUserInfo, TekUserInfoList, columnAggregationValues };
|