@zeedhi/common 1.113.0 → 1.115.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/dist/zd-common.esm.js +313 -127
- package/dist/zd-common.umd.js +314 -126
- package/package.json +2 -2
- package/types/components/zd-grid/grid-editable.d.ts +12 -0
- package/types/components/zd-input/input.d.ts +2 -0
- package/types/components/zd-input/interfaces.d.ts +2 -0
- package/types/components/zd-select/interfaces.d.ts +0 -1
- package/types/components/zd-select/select.d.ts +3 -3
- package/types/components/zd-select-tree/interfaces.d.ts +2 -1
- package/types/components/zd-select-tree/select-tree.d.ts +26 -3
- package/types/components/zd-select-tree-multiple/interfaces.d.ts +2 -0
- package/types/components/zd-select-tree-multiple/select-tree-multiple.d.ts +8 -6
- package/types/components/zd-tree-grid/tree-grid.d.ts +1 -0
- package/types/utils/datasource-searcher/datasource-searcher.d.ts +7 -0
- package/types/utils/datasource-searcher/index.d.ts +2 -0
- package/types/utils/datasource-searcher/interfaces.d.ts +5 -0
- package/types/utils/index.d.ts +2 -0
- package/types/utils/tree-data-structure/tree-data-structure.d.ts +1 -0
- package/types/utils/unique-by/index.d.ts +1 -0
- package/types/utils/unique-by/unique-by.d.ts +3 -0
package/dist/zd-common.umd.js
CHANGED
|
@@ -1923,6 +1923,7 @@
|
|
|
1923
1923
|
this.internalDisplayValue = '';
|
|
1924
1924
|
this.internalValue = null;
|
|
1925
1925
|
this.formParent = this.getFormParent();
|
|
1926
|
+
this.grid = {};
|
|
1926
1927
|
this.lastInputValue = '';
|
|
1927
1928
|
this.callInputEvent = debounce__default["default"](({ event, element, component }) => {
|
|
1928
1929
|
this.callEvent('input', { event, element, component });
|
|
@@ -1950,6 +1951,7 @@
|
|
|
1950
1951
|
this.value = this.getInitValue('value', props.value, this.value);
|
|
1951
1952
|
this.validations = this.getInitValue('validations', props.validations, this.validations);
|
|
1952
1953
|
this.autoRegister = this.getInitValue('autoRegister', props.autoRegister, this.autoRegister);
|
|
1954
|
+
this.grid = this.getInitValue('grid', props.grid, this.grid);
|
|
1953
1955
|
this.parseValidations(props.validations || {});
|
|
1954
1956
|
if (this.autoRegister && this.formParent) {
|
|
1955
1957
|
this.formParent.registerInput(this);
|
|
@@ -4439,6 +4441,9 @@
|
|
|
4439
4441
|
userAppendIconClick({ event, element, component });
|
|
4440
4442
|
}
|
|
4441
4443
|
};
|
|
4444
|
+
if (this.value && Array.isArray(this.value)) {
|
|
4445
|
+
this.internalDisplayValue = this.formatter(this.value);
|
|
4446
|
+
}
|
|
4442
4447
|
}
|
|
4443
4448
|
/**
|
|
4444
4449
|
* Character that will separate the two dates
|
|
@@ -5865,7 +5870,24 @@
|
|
|
5865
5870
|
&& (!this.searchVisibleOnly || column.isVisible)
|
|
5866
5871
|
&& (this.searchIn === undefined || this.searchIn === column.name);
|
|
5867
5872
|
}
|
|
5868
|
-
}
|
|
5873
|
+
}
|
|
5874
|
+
core.Messages.add({
|
|
5875
|
+
'pt-BR': {
|
|
5876
|
+
translation: {
|
|
5877
|
+
gridPageText: '{{firstRow}} - {{lastRow}} de {{total}}',
|
|
5878
|
+
},
|
|
5879
|
+
},
|
|
5880
|
+
'en-US': {
|
|
5881
|
+
translation: {
|
|
5882
|
+
gridPageText: '{{firstRow}} - {{lastRow}} of {{total}}',
|
|
5883
|
+
},
|
|
5884
|
+
},
|
|
5885
|
+
'es-CL': {
|
|
5886
|
+
translation: {
|
|
5887
|
+
gridPageText: '{{firstRow}} - {{lastRow}} de {{total}}',
|
|
5888
|
+
},
|
|
5889
|
+
},
|
|
5890
|
+
});
|
|
5869
5891
|
|
|
5870
5892
|
/**
|
|
5871
5893
|
* Delete rows error
|
|
@@ -7064,6 +7086,9 @@
|
|
|
7064
7086
|
});
|
|
7065
7087
|
}
|
|
7066
7088
|
}
|
|
7089
|
+
/**
|
|
7090
|
+
* Retrieves the visible value of a cell, which is the corresponding cell in edited row or in the default row
|
|
7091
|
+
*/
|
|
7067
7092
|
getVisibleValue(row, column) {
|
|
7068
7093
|
const key = row[this.datasource.uniqueKey];
|
|
7069
7094
|
if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.valueIn)) {
|
|
@@ -7071,6 +7096,18 @@
|
|
|
7071
7096
|
}
|
|
7072
7097
|
return row[column.valueIn];
|
|
7073
7098
|
}
|
|
7099
|
+
/**
|
|
7100
|
+
* Retrieves the visible values of a row
|
|
7101
|
+
* @param row
|
|
7102
|
+
* @returns
|
|
7103
|
+
*/
|
|
7104
|
+
getVisibleRow(row) {
|
|
7105
|
+
const visibleRow = Object.assign({}, row);
|
|
7106
|
+
this.columns.forEach((column) => {
|
|
7107
|
+
visibleRow[column.valueIn] = this.getVisibleValue(row, column);
|
|
7108
|
+
});
|
|
7109
|
+
return visibleRow;
|
|
7110
|
+
}
|
|
7074
7111
|
/**
|
|
7075
7112
|
* Returns editable component properties based on the column definition
|
|
7076
7113
|
* @param column Column definition
|
|
@@ -7166,6 +7203,15 @@
|
|
|
7166
7203
|
delete this.invalidComponents[component.name];
|
|
7167
7204
|
}
|
|
7168
7205
|
}
|
|
7206
|
+
clearInvalidComponentsForRow(rowKey) {
|
|
7207
|
+
const cloneInvalidComponents = Object.assign({}, this.invalidComponents);
|
|
7208
|
+
Object.keys(cloneInvalidComponents).forEach((compName) => {
|
|
7209
|
+
if (compName.includes(`_editable_${rowKey}`)) {
|
|
7210
|
+
delete cloneInvalidComponents[compName];
|
|
7211
|
+
}
|
|
7212
|
+
});
|
|
7213
|
+
this.invalidComponents = cloneInvalidComponents;
|
|
7214
|
+
}
|
|
7169
7215
|
/**
|
|
7170
7216
|
* change event of editable components
|
|
7171
7217
|
*/
|
|
@@ -7277,6 +7323,7 @@
|
|
|
7277
7323
|
delete cloneAddedRows[key];
|
|
7278
7324
|
this.editedRows = cloneEditedRows;
|
|
7279
7325
|
this.addedRows = cloneAddedRows;
|
|
7326
|
+
this.clearInvalidComponentsForRow(key);
|
|
7280
7327
|
const { data, uniqueKey } = this.datasource;
|
|
7281
7328
|
const index = data.findIndex((row) => row[uniqueKey] === key);
|
|
7282
7329
|
data.splice(index, 1);
|
|
@@ -7290,6 +7337,8 @@
|
|
|
7290
7337
|
for (let index = allData.length - 1; index >= 0; index -= 1) {
|
|
7291
7338
|
const row = allData[index];
|
|
7292
7339
|
if (this.addedRows[row[this.datasource.uniqueKey]]) {
|
|
7340
|
+
const key = row[this.datasource.uniqueKey];
|
|
7341
|
+
this.clearInvalidComponentsForRow(key);
|
|
7293
7342
|
allData.splice(index, 1);
|
|
7294
7343
|
}
|
|
7295
7344
|
}
|
|
@@ -7310,13 +7359,17 @@
|
|
|
7310
7359
|
saveEditedRows(revalidate = false) {
|
|
7311
7360
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7312
7361
|
const { page } = this.datasource;
|
|
7362
|
+
// Verificar se o grid é válido antes de tentar salvar
|
|
7363
|
+
if (!this.isGridValid(revalidate)) {
|
|
7364
|
+
throw new Error('Invalid rows');
|
|
7365
|
+
}
|
|
7366
|
+
// Só cancelar as linhas adicionadas se todas forem válidas
|
|
7313
7367
|
yield this.cancelAddedRows();
|
|
7314
|
-
const response = yield Promise.all(this.getEditedRows(revalidate).map((row) => this.addDataRow(row)));
|
|
7368
|
+
const response = yield Promise.all(this.getEditedRows(revalidate, true).map((row) => this.addDataRow(row)));
|
|
7315
7369
|
this.editing = false;
|
|
7316
7370
|
this.editedRows = {};
|
|
7317
7371
|
this.addedRows = {};
|
|
7318
7372
|
this.invalidComponents = {};
|
|
7319
|
-
this.addedRows = {};
|
|
7320
7373
|
yield this.datasource.setPage(page);
|
|
7321
7374
|
return response;
|
|
7322
7375
|
});
|
|
@@ -7567,6 +7620,8 @@
|
|
|
7567
7620
|
const rows = Object.assign({}, this.editedRows);
|
|
7568
7621
|
delete rows[foundRow[uniqueKey]];
|
|
7569
7622
|
this.editedRows = rows;
|
|
7623
|
+
const key = foundRow[uniqueKey];
|
|
7624
|
+
this.clearInvalidComponentsForRow(key);
|
|
7570
7625
|
}
|
|
7571
7626
|
/**
|
|
7572
7627
|
* Makes the cell enter edit mode
|
|
@@ -9668,6 +9723,22 @@
|
|
|
9668
9723
|
}
|
|
9669
9724
|
return result;
|
|
9670
9725
|
}
|
|
9726
|
+
loadChildren(row, rowIndex = -1) {
|
|
9727
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9728
|
+
const { uniqueKey } = this.originalDatasource;
|
|
9729
|
+
let index = rowIndex;
|
|
9730
|
+
if (index === -1) {
|
|
9731
|
+
index = this.findDataIndex(this.treeData, row[uniqueKey]);
|
|
9732
|
+
}
|
|
9733
|
+
const originalData = [...this.originalDatasource.data];
|
|
9734
|
+
const data = yield this.originalDatasource.addFilter(this.parentField, row[uniqueKey]);
|
|
9735
|
+
originalData.splice(index + 1, 0, ...data);
|
|
9736
|
+
this.originalDatasource.data = originalData;
|
|
9737
|
+
this.originalDatasource.currentRow = this.clearRow(row);
|
|
9738
|
+
delete this.originalDatasource.filter[this.parentField];
|
|
9739
|
+
return data;
|
|
9740
|
+
});
|
|
9741
|
+
}
|
|
9671
9742
|
/**
|
|
9672
9743
|
* Expands or collapses a row
|
|
9673
9744
|
* @param row Row object
|
|
@@ -9682,17 +9753,7 @@
|
|
|
9682
9753
|
&& this.fetchOnDemand
|
|
9683
9754
|
&& rowData.tree__children.length === 1
|
|
9684
9755
|
&& !rowData.tree__children[0][uniqueKey]) {
|
|
9685
|
-
|
|
9686
|
-
if (index === -1) {
|
|
9687
|
-
index = this.findDataIndex(this.treeData, row[uniqueKey]);
|
|
9688
|
-
}
|
|
9689
|
-
const originalData = [...this.originalDatasource.data];
|
|
9690
|
-
const data = yield this.originalDatasource.addFilter(this.parentField, row[uniqueKey]);
|
|
9691
|
-
originalData.splice(index + 1, 0, ...data);
|
|
9692
|
-
this.originalDatasource.data = originalData;
|
|
9693
|
-
this.originalDatasource.currentRow = this.clearRow(row);
|
|
9694
|
-
delete this.originalDatasource.filter[this.parentField];
|
|
9695
|
-
return data;
|
|
9756
|
+
return this.loadChildren(row, rowIndex);
|
|
9696
9757
|
}
|
|
9697
9758
|
return undefined;
|
|
9698
9759
|
});
|
|
@@ -9854,6 +9915,77 @@
|
|
|
9854
9915
|
}
|
|
9855
9916
|
}
|
|
9856
9917
|
|
|
9918
|
+
class DatasourceSearcher {
|
|
9919
|
+
constructor() {
|
|
9920
|
+
this.dsSearch = {
|
|
9921
|
+
SEARCH: (value, searchIn) => ({
|
|
9922
|
+
searchIn: [searchIn],
|
|
9923
|
+
search: String(value || ''),
|
|
9924
|
+
}),
|
|
9925
|
+
FILTER: (value, searchIn) => ({
|
|
9926
|
+
filter: {
|
|
9927
|
+
[searchIn]: value,
|
|
9928
|
+
},
|
|
9929
|
+
}),
|
|
9930
|
+
FIND: (value, searchIn) => ({
|
|
9931
|
+
find: {
|
|
9932
|
+
[searchIn]: value,
|
|
9933
|
+
},
|
|
9934
|
+
}),
|
|
9935
|
+
DYNAMIC_FILTER: (value, search_in) => {
|
|
9936
|
+
const arrayValue = Array.isArray(value) ? value : Array.of(value);
|
|
9937
|
+
const filter = arrayValue.map((item) => ({ operation: 'EQUALS', relation: 'OR', value: item }));
|
|
9938
|
+
const dynamicFilter = { [search_in]: filter };
|
|
9939
|
+
return { dynamicFilter };
|
|
9940
|
+
},
|
|
9941
|
+
};
|
|
9942
|
+
}
|
|
9943
|
+
search(datasource, searchValue, searchIn, searchParam) {
|
|
9944
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9945
|
+
// using filter/find/dynamicFilter should make only 1 request
|
|
9946
|
+
// using normal search should make one request per search value
|
|
9947
|
+
if (!Array.isArray(searchValue)) {
|
|
9948
|
+
return this.searchRequest(datasource, searchValue, searchIn, searchParam);
|
|
9949
|
+
}
|
|
9950
|
+
if (searchParam !== 'SEARCH') {
|
|
9951
|
+
const items = yield this.searchRequest(datasource, searchValue, searchIn, searchParam);
|
|
9952
|
+
return items;
|
|
9953
|
+
}
|
|
9954
|
+
const searchedItems = [];
|
|
9955
|
+
const promises = searchValue.map((value) => __awaiter(this, void 0, void 0, function* () {
|
|
9956
|
+
const [item] = yield this.searchRequest(datasource, value, searchIn, searchParam);
|
|
9957
|
+
searchedItems.push(item);
|
|
9958
|
+
}));
|
|
9959
|
+
yield Promise.all(promises);
|
|
9960
|
+
return searchedItems;
|
|
9961
|
+
});
|
|
9962
|
+
}
|
|
9963
|
+
searchRequest(datasource, searchValue, searchIn, searchParam) {
|
|
9964
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9965
|
+
const config = Object.assign(Object.assign(Object.assign({}, datasource.clone()), this.dsSearch[searchParam](searchValue, searchIn)), { lazyLoad: true, loadAll: Array.isArray(searchValue) });
|
|
9966
|
+
const cloneDatasource = core.DatasourceFactory.factory(config);
|
|
9967
|
+
const items = yield cloneDatasource.get();
|
|
9968
|
+
cloneDatasource.destroy();
|
|
9969
|
+
if (Array.isArray(searchValue)) {
|
|
9970
|
+
return items.filter((item) => searchValue.includes(item[searchIn]));
|
|
9971
|
+
}
|
|
9972
|
+
return items.filter((row) => row[searchIn] === searchValue);
|
|
9973
|
+
});
|
|
9974
|
+
}
|
|
9975
|
+
}
|
|
9976
|
+
|
|
9977
|
+
const uniqueBy = (a, key) => {
|
|
9978
|
+
const seen = {};
|
|
9979
|
+
return a.filter((item) => {
|
|
9980
|
+
const k = item[key] || JSON.stringify(item);
|
|
9981
|
+
if (!seen[k]) {
|
|
9982
|
+
seen[k] = true;
|
|
9983
|
+
return true;
|
|
9984
|
+
}
|
|
9985
|
+
return false;
|
|
9986
|
+
});
|
|
9987
|
+
};
|
|
9988
|
+
|
|
9857
9989
|
/**
|
|
9858
9990
|
* Base class for Select component.
|
|
9859
9991
|
*/
|
|
@@ -10144,18 +10276,13 @@
|
|
|
10144
10276
|
* Finds and retrieves items searching by value
|
|
10145
10277
|
* @param value Default value
|
|
10146
10278
|
*/
|
|
10147
|
-
getItemsBySearchValue(value
|
|
10279
|
+
getItemsBySearchValue(value) {
|
|
10148
10280
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10149
|
-
const config = Object.assign(Object.assign(Object.assign({}, this.datasource.clone()), this.dsSearch[this.searchParam](value, searchIn)), { lazyLoad: true, loadAll: Array.isArray(value) });
|
|
10150
10281
|
this.datasource.loading = true;
|
|
10151
|
-
const
|
|
10152
|
-
const
|
|
10282
|
+
const datasourceSearcher = new DatasourceSearcher();
|
|
10283
|
+
const result = yield datasourceSearcher.search(this.datasource, value, this.dataValue, this.searchParam);
|
|
10153
10284
|
this.datasource.loading = false;
|
|
10154
|
-
|
|
10155
|
-
if (Array.isArray(value)) {
|
|
10156
|
-
return items.filter((item) => value.includes(item[this.dataValue]));
|
|
10157
|
-
}
|
|
10158
|
-
return items.filter(this.getCondition(value));
|
|
10285
|
+
return result;
|
|
10159
10286
|
});
|
|
10160
10287
|
}
|
|
10161
10288
|
getCondition(filterValue) {
|
|
@@ -10180,17 +10307,6 @@
|
|
|
10180
10307
|
this.updateSearch(this.dirtySearchValue);
|
|
10181
10308
|
});
|
|
10182
10309
|
}
|
|
10183
|
-
uniqueBy(a, key) {
|
|
10184
|
-
const seen = {};
|
|
10185
|
-
return a.filter((item) => {
|
|
10186
|
-
const k = item[key] || JSON.stringify(item);
|
|
10187
|
-
if (!seen[k]) {
|
|
10188
|
-
seen[k] = true;
|
|
10189
|
-
return true;
|
|
10190
|
-
}
|
|
10191
|
-
return false;
|
|
10192
|
-
});
|
|
10193
|
-
}
|
|
10194
10310
|
afterLoad() {
|
|
10195
10311
|
if (this.manualMode)
|
|
10196
10312
|
return;
|
|
@@ -10256,11 +10372,10 @@
|
|
|
10256
10372
|
else {
|
|
10257
10373
|
filterValue = value;
|
|
10258
10374
|
}
|
|
10259
|
-
const searchIn = this.dataValue;
|
|
10260
10375
|
const foundInData = this.datasource.data.find(this.getCondition(filterValue));
|
|
10261
10376
|
let searchValue = foundInData;
|
|
10262
10377
|
if (!foundInData && !this.manualMode) {
|
|
10263
|
-
[searchValue] = yield this.getItemsBySearchValue(filterValue
|
|
10378
|
+
[searchValue] = yield this.getItemsBySearchValue(filterValue);
|
|
10264
10379
|
}
|
|
10265
10380
|
if (!searchValue) {
|
|
10266
10381
|
this.setFieldRowValue(null);
|
|
@@ -10893,15 +11008,12 @@
|
|
|
10893
11008
|
this.createAccessors();
|
|
10894
11009
|
}
|
|
10895
11010
|
addSlashes(value) {
|
|
10896
|
-
|
|
10897
|
-
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
.replace(/"/g, '\\"');
|
|
10903
|
-
}
|
|
10904
|
-
return value;
|
|
11011
|
+
return value.replace(/\\/g, '\\\\')
|
|
11012
|
+
.replace(/\t/g, '\\t')
|
|
11013
|
+
.replace(/\n/g, '\\n')
|
|
11014
|
+
.replace(/\f/g, '\\f')
|
|
11015
|
+
.replace(/\r/g, '\\r')
|
|
11016
|
+
.replace(/"/g, '\\"');
|
|
10905
11017
|
}
|
|
10906
11018
|
/**
|
|
10907
11019
|
* Returns the iterable component metadata based on row data
|
|
@@ -10914,14 +11026,13 @@
|
|
|
10914
11026
|
.replace(rowExp, JSON.stringify(row))
|
|
10915
11027
|
.replace(exp, (match) => {
|
|
10916
11028
|
const propPath = match.replace(/<<|>>|"/g, '').split('.').splice(1).join('.');
|
|
10917
|
-
|
|
11029
|
+
let value = get__default["default"](row, propPath);
|
|
11030
|
+
if (value === undefined || value === null)
|
|
11031
|
+
value = '';
|
|
10918
11032
|
if (typeof value === 'string') {
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
return value;
|
|
11033
|
+
const escaped = this.addSlashes(value);
|
|
11034
|
+
return match.startsWith('"') && match.endsWith('"') ? `"${escaped}"` : escaped;
|
|
10922
11035
|
}
|
|
10923
|
-
if (value === undefined)
|
|
10924
|
-
return '""';
|
|
10925
11036
|
return value;
|
|
10926
11037
|
});
|
|
10927
11038
|
return JSON.parse(metadata);
|
|
@@ -12599,19 +12710,10 @@
|
|
|
12599
12710
|
this.insertedValues.push(item);
|
|
12600
12711
|
pushed = true;
|
|
12601
12712
|
});
|
|
12602
|
-
|
|
12603
|
-
|
|
12604
|
-
if (this.searchParam !== 'SEARCH') {
|
|
12605
|
-
const items = yield this.getItemsBySearchValue(searchedValues, this.dataValue);
|
|
12713
|
+
if (searchedValues.length) {
|
|
12714
|
+
const items = yield this.getItemsBySearchValue(searchedValues);
|
|
12606
12715
|
items.forEach(insertItem);
|
|
12607
12716
|
}
|
|
12608
|
-
else {
|
|
12609
|
-
const promises = searchedValues.map((searchedValue) => __awaiter(this, void 0, void 0, function* () {
|
|
12610
|
-
const [item] = yield this.getItemsBySearchValue(searchedValue, this.dataValue);
|
|
12611
|
-
insertItem(item);
|
|
12612
|
-
}));
|
|
12613
|
-
yield Promise.all(promises);
|
|
12614
|
-
}
|
|
12615
12717
|
if (foundValues.length > 0) {
|
|
12616
12718
|
this.setFieldRowValue(foundValues);
|
|
12617
12719
|
}
|
|
@@ -12849,7 +12951,7 @@
|
|
|
12849
12951
|
if (this.manualMode)
|
|
12850
12952
|
return;
|
|
12851
12953
|
if (this.insertedValues.length) {
|
|
12852
|
-
this.datasource.data =
|
|
12954
|
+
this.datasource.data = uniqueBy(this.insertedValues.concat(this.datasource.data), this.datasource.uniqueKey);
|
|
12853
12955
|
const values = this.insertedValues.map((inserted) => inserted[this.dataValue]);
|
|
12854
12956
|
// prevent caching insertedValues
|
|
12855
12957
|
this.cachedData = this.datasource.data.filter((row) => !values.includes(row[this.dataValue]));
|
|
@@ -13084,6 +13186,7 @@
|
|
|
13084
13186
|
* Defines if should wait and not execute GET method when Datasource is created
|
|
13085
13187
|
*/
|
|
13086
13188
|
this.lazyLoad = true;
|
|
13189
|
+
this.selectValue = null;
|
|
13087
13190
|
/**
|
|
13088
13191
|
* Uses delayed loading to load tree branches
|
|
13089
13192
|
*/
|
|
@@ -13105,6 +13208,10 @@
|
|
|
13105
13208
|
*/
|
|
13106
13209
|
this.dataValueOutFormName = '';
|
|
13107
13210
|
this.formatterFn = core.FormatterParserProvider.getFormatter('ZdSelectTree');
|
|
13211
|
+
/**
|
|
13212
|
+
* Defines if data handling should be manual or automatic
|
|
13213
|
+
*/
|
|
13214
|
+
this.searchParam = 'SEARCH';
|
|
13108
13215
|
this.savedNodes = undefined;
|
|
13109
13216
|
this.search = '';
|
|
13110
13217
|
this.debounceSearch = debounce__default["default"](this.searchChange, 500);
|
|
@@ -13132,6 +13239,7 @@
|
|
|
13132
13239
|
this.autoSelection = this.getInitValue('autoSelection', props.autoSelection, this.autoSelection);
|
|
13133
13240
|
this.dataValueOut = this.getInitValue('dataValueOut', props.dataValueOut, this.dataValueOut);
|
|
13134
13241
|
this.dataValueOutFormName = this.getInitValue('dataValueOutFormName', props.dataValueOutFormName, this.dataValueOutFormName);
|
|
13242
|
+
this.searchParam = this.getInitValue('searchParam', props.searchParam, this.searchParam);
|
|
13135
13243
|
if (props.datasource && Object.keys(props.datasource).length) {
|
|
13136
13244
|
this.lazyLoad = props.datasource.lazyLoad !== false;
|
|
13137
13245
|
const searchFields = Array.isArray(this.dataText) ? this.dataText : [this.dataText];
|
|
@@ -13201,6 +13309,9 @@
|
|
|
13201
13309
|
this.nodes = this.createChildrenNodes(firstLevelNodes);
|
|
13202
13310
|
}
|
|
13203
13311
|
}
|
|
13312
|
+
/**
|
|
13313
|
+
* Creates a Tree Node from a datasource row
|
|
13314
|
+
*/
|
|
13204
13315
|
createNodeFromRow(row) {
|
|
13205
13316
|
let children;
|
|
13206
13317
|
if (this.fetchOnDemand && !this.datasource.search) {
|
|
@@ -13340,31 +13451,71 @@
|
|
|
13340
13451
|
});
|
|
13341
13452
|
return result;
|
|
13342
13453
|
}
|
|
13454
|
+
clearNodeRow(row) {
|
|
13455
|
+
return this.clearRow(row.row || row);
|
|
13456
|
+
}
|
|
13457
|
+
/**
|
|
13458
|
+
* Finds and retrieves items searching by value
|
|
13459
|
+
* @param value Default value
|
|
13460
|
+
*/
|
|
13461
|
+
getItemsBySearchValue(value) {
|
|
13462
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13463
|
+
this.datasource.loading = true;
|
|
13464
|
+
const datasourceSearcher = new DatasourceSearcher();
|
|
13465
|
+
const result = yield datasourceSearcher.search(this.datasource, value, this.dataValue, this.searchParam);
|
|
13466
|
+
this.datasource.loading = false;
|
|
13467
|
+
return result;
|
|
13468
|
+
});
|
|
13469
|
+
}
|
|
13343
13470
|
get value() {
|
|
13344
13471
|
if (!this.selectValue)
|
|
13345
13472
|
return this.selectValue;
|
|
13346
13473
|
if (this.returnObject) {
|
|
13347
|
-
return this.
|
|
13474
|
+
return this.clearNodeRow(this.selectValue);
|
|
13348
13475
|
}
|
|
13349
|
-
|
|
13476
|
+
const key = this.datasource ? this.dataValue : 'id';
|
|
13477
|
+
return this.selectValue[key];
|
|
13350
13478
|
}
|
|
13351
13479
|
set value(value) {
|
|
13352
13480
|
this.setValue(value);
|
|
13353
13481
|
}
|
|
13354
13482
|
setValue(value) {
|
|
13355
|
-
|
|
13356
|
-
|
|
13357
|
-
|
|
13358
|
-
|
|
13359
|
-
|
|
13360
|
-
|
|
13361
|
-
|
|
13362
|
-
|
|
13363
|
-
|
|
13364
|
-
|
|
13365
|
-
|
|
13366
|
-
|
|
13367
|
-
|
|
13483
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13484
|
+
let val = null;
|
|
13485
|
+
const key = this.datasource ? this.dataValue : 'id';
|
|
13486
|
+
if (!value && value !== 0) {
|
|
13487
|
+
val = null;
|
|
13488
|
+
}
|
|
13489
|
+
else if (typeof value === 'object') {
|
|
13490
|
+
val = value[key];
|
|
13491
|
+
}
|
|
13492
|
+
else {
|
|
13493
|
+
val = value;
|
|
13494
|
+
}
|
|
13495
|
+
if (!val) {
|
|
13496
|
+
this.selectValue = null;
|
|
13497
|
+
return;
|
|
13498
|
+
}
|
|
13499
|
+
if (!this.datasource) {
|
|
13500
|
+
this.selectValue = { id: val };
|
|
13501
|
+
return;
|
|
13502
|
+
}
|
|
13503
|
+
const searchIn = this.dataValue;
|
|
13504
|
+
const foundInData = this.datasource.data.find((row) => row[searchIn] === val);
|
|
13505
|
+
let foundValue = foundInData;
|
|
13506
|
+
if (!foundInData) {
|
|
13507
|
+
[foundValue] = yield this.getItemsBySearchValue(val);
|
|
13508
|
+
}
|
|
13509
|
+
if (!foundValue) {
|
|
13510
|
+
if (typeof value === 'object') {
|
|
13511
|
+
this.selectValue = Object.assign({ id: val }, value);
|
|
13512
|
+
return;
|
|
13513
|
+
}
|
|
13514
|
+
this.selectValue = { id: val };
|
|
13515
|
+
return;
|
|
13516
|
+
}
|
|
13517
|
+
this.selectValue = foundValue;
|
|
13518
|
+
});
|
|
13368
13519
|
}
|
|
13369
13520
|
loadChildren(parentNode) {
|
|
13370
13521
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -13417,6 +13568,7 @@
|
|
|
13417
13568
|
* Selected Nodes
|
|
13418
13569
|
*/
|
|
13419
13570
|
this.selectedNodes = [];
|
|
13571
|
+
this.selectValue = [];
|
|
13420
13572
|
/**
|
|
13421
13573
|
* Changes the behavior of checked nodes that will be displayed in the array of values
|
|
13422
13574
|
*/
|
|
@@ -13435,7 +13587,9 @@
|
|
|
13435
13587
|
* Triggered after selected nodes change
|
|
13436
13588
|
*/
|
|
13437
13589
|
changeSelectedNodes(selectedNodes, element) {
|
|
13438
|
-
|
|
13590
|
+
const selection = this.returnObject
|
|
13591
|
+
? selectedNodes.map((value) => this.clearNodeRow(value)) : selectedNodes.map((node) => node.id);
|
|
13592
|
+
this.callEvent('onChangeSelectedNodes', { element, component: this, selectedNodes: selection });
|
|
13439
13593
|
}
|
|
13440
13594
|
/**
|
|
13441
13595
|
* Triggered deselecting an node
|
|
@@ -13447,34 +13601,58 @@
|
|
|
13447
13601
|
if (!this.selectValue)
|
|
13448
13602
|
return [];
|
|
13449
13603
|
if (this.returnObject) {
|
|
13450
|
-
return this.selectValue.map((value) => this.
|
|
13604
|
+
return this.selectValue.map((value) => this.clearNodeRow(value));
|
|
13451
13605
|
}
|
|
13452
|
-
|
|
13606
|
+
const key = this.datasource ? this.dataValue : 'id';
|
|
13607
|
+
return this.selectValue.map((item) => item[key]);
|
|
13453
13608
|
}
|
|
13454
13609
|
set value(value) {
|
|
13455
13610
|
this.setValue(value);
|
|
13456
13611
|
}
|
|
13457
13612
|
setValue(value) {
|
|
13458
|
-
|
|
13459
|
-
|
|
13460
|
-
|
|
13461
|
-
|
|
13462
|
-
|
|
13463
|
-
|
|
13464
|
-
|
|
13465
|
-
this.
|
|
13613
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13614
|
+
if (!value) {
|
|
13615
|
+
this.selectValue = [];
|
|
13616
|
+
return;
|
|
13617
|
+
}
|
|
13618
|
+
const arrValue = Array.isArray(value) ? value : [value];
|
|
13619
|
+
const key = this.datasource ? this.dataValue : 'id';
|
|
13620
|
+
if (!this.datasource) {
|
|
13621
|
+
this.selectValue = arrValue.map((item) => {
|
|
13622
|
+
if (item && typeof item === 'object') {
|
|
13623
|
+
return item;
|
|
13624
|
+
}
|
|
13625
|
+
return { [key]: item };
|
|
13626
|
+
});
|
|
13627
|
+
return;
|
|
13628
|
+
}
|
|
13629
|
+
const valuesToSearch = [];
|
|
13630
|
+
const foundValues = [];
|
|
13631
|
+
const insertItem = (item) => __awaiter(this, void 0, void 0, function* () {
|
|
13632
|
+
if (!item)
|
|
13633
|
+
return;
|
|
13634
|
+
foundValues.push(item);
|
|
13635
|
+
});
|
|
13636
|
+
arrValue.forEach((item) => __awaiter(this, void 0, void 0, function* () {
|
|
13637
|
+
const searchIn = this.dataValue;
|
|
13638
|
+
if (!item)
|
|
13639
|
+
return;
|
|
13466
13640
|
if (typeof item === 'object') {
|
|
13467
|
-
|
|
13641
|
+
insertItem(item);
|
|
13642
|
+
return;
|
|
13468
13643
|
}
|
|
13469
|
-
|
|
13470
|
-
|
|
13471
|
-
|
|
13472
|
-
|
|
13473
|
-
|
|
13474
|
-
|
|
13475
|
-
|
|
13644
|
+
const foundInData = this.datasource.data.find((row) => row[searchIn] === item);
|
|
13645
|
+
if (!foundInData) {
|
|
13646
|
+
valuesToSearch.push(item);
|
|
13647
|
+
return;
|
|
13648
|
+
}
|
|
13649
|
+
insertItem(foundInData);
|
|
13650
|
+
}));
|
|
13651
|
+
if (valuesToSearch.length) {
|
|
13652
|
+
const items = yield this.getItemsBySearchValue(valuesToSearch);
|
|
13653
|
+
items.forEach(insertItem);
|
|
13476
13654
|
}
|
|
13477
|
-
|
|
13655
|
+
this.selectValue = foundValues;
|
|
13478
13656
|
});
|
|
13479
13657
|
}
|
|
13480
13658
|
/**
|
|
@@ -13522,16 +13700,18 @@
|
|
|
13522
13700
|
*/
|
|
13523
13701
|
selectAllItems(nodes = this.nodes) {
|
|
13524
13702
|
var _a;
|
|
13525
|
-
|
|
13526
|
-
|
|
13527
|
-
|
|
13528
|
-
|
|
13529
|
-
|
|
13530
|
-
|
|
13531
|
-
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
|
|
13703
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13704
|
+
if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
|
|
13705
|
+
yield this.setValue(this.datasource.data);
|
|
13706
|
+
return;
|
|
13707
|
+
}
|
|
13708
|
+
const allNodes = this.getAllNodes(nodes, !this.search);
|
|
13709
|
+
// merge all nodes with the current value before setting it
|
|
13710
|
+
const currentValue = this.getValueAsObject();
|
|
13711
|
+
const nodeMap = this.createMergeMap(currentValue, allNodes);
|
|
13712
|
+
const uniqueArray = Array.from(nodeMap.values());
|
|
13713
|
+
yield this.setValue(uniqueArray);
|
|
13714
|
+
});
|
|
13535
13715
|
}
|
|
13536
13716
|
/**
|
|
13537
13717
|
* Unelects all items in the tree \
|
|
@@ -13543,21 +13723,23 @@
|
|
|
13543
13723
|
*/
|
|
13544
13724
|
unSelectAllItems(nodes = this.nodes) {
|
|
13545
13725
|
var _a;
|
|
13546
|
-
|
|
13547
|
-
this.
|
|
13548
|
-
|
|
13549
|
-
|
|
13550
|
-
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
13726
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13727
|
+
if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
|
|
13728
|
+
yield this.setValue([]);
|
|
13729
|
+
return;
|
|
13730
|
+
}
|
|
13731
|
+
const allNodes = this.getAllNodes(nodes, !this.search);
|
|
13732
|
+
// merge all nodes with the current value before setting it
|
|
13733
|
+
const currentValue = this.getValueAsObject();
|
|
13734
|
+
const nodeMap = this.createMergeMap(currentValue);
|
|
13735
|
+
// remove the current visible nodes from the array
|
|
13736
|
+
const valuesToRemove = allNodes.map((node) => node.id);
|
|
13737
|
+
valuesToRemove.forEach((value) => {
|
|
13738
|
+
nodeMap.delete(value);
|
|
13739
|
+
});
|
|
13740
|
+
const uniqueArray = Array.from(nodeMap.values());
|
|
13741
|
+
yield this.setValue(uniqueArray);
|
|
13558
13742
|
});
|
|
13559
|
-
const uniqueArray = Array.from(nodeMap.values());
|
|
13560
|
-
this.setValue(uniqueArray);
|
|
13561
13743
|
}
|
|
13562
13744
|
/**
|
|
13563
13745
|
* Takes two arrays and creates a map of the unique values
|
|
@@ -13579,10 +13761,9 @@
|
|
|
13579
13761
|
return this.value;
|
|
13580
13762
|
}
|
|
13581
13763
|
getValueAsObject() {
|
|
13582
|
-
return this.
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
return { id: row };
|
|
13764
|
+
return this.selectValue.map((row) => {
|
|
13765
|
+
const key = this.datasource ? this.dataValue : 'id';
|
|
13766
|
+
return Object.assign({ id: row[key] }, row);
|
|
13586
13767
|
});
|
|
13587
13768
|
}
|
|
13588
13769
|
}
|
|
@@ -15296,6 +15477,11 @@
|
|
|
15296
15477
|
return response;
|
|
15297
15478
|
});
|
|
15298
15479
|
}
|
|
15480
|
+
loadChildren(row, rowIndex = -1) {
|
|
15481
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15482
|
+
yield this.treeDataStructure.loadChildren(row, rowIndex);
|
|
15483
|
+
});
|
|
15484
|
+
}
|
|
15299
15485
|
/**
|
|
15300
15486
|
* Expands or collapses a row
|
|
15301
15487
|
* @param row Row object
|
|
@@ -16124,6 +16310,7 @@
|
|
|
16124
16310
|
exports.Currency = Currency;
|
|
16125
16311
|
exports.Dashboard = Dashboard;
|
|
16126
16312
|
exports.DataValueOutHelper = DataValueOutHelper;
|
|
16313
|
+
exports.DatasourceSearcher = DatasourceSearcher;
|
|
16127
16314
|
exports.Date = Date$1;
|
|
16128
16315
|
exports.DateRange = DateRange;
|
|
16129
16316
|
exports.Dialog = Dialog;
|
|
@@ -16210,6 +16397,7 @@
|
|
|
16210
16397
|
exports.XLS3Report = XLS3Report;
|
|
16211
16398
|
exports.XLSReport = XLSReport;
|
|
16212
16399
|
exports.initTheme = initTheme;
|
|
16400
|
+
exports.uniqueBy = uniqueBy;
|
|
16213
16401
|
|
|
16214
16402
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
16215
16403
|
|