@zeedhi/common 1.37.0 → 1.39.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.
Files changed (57) hide show
  1. package/dist/zd-common.esm.js +390 -46
  2. package/dist/zd-common.umd.js +390 -46
  3. package/package.json +2 -2
  4. package/types/components/zd-grid/grid-editable.d.ts +1 -1
  5. package/types/components/zd-iterable/column.d.ts +4 -2
  6. package/types/components/zd-select/select.d.ts +2 -0
  7. package/types/components/zd-select-multiple/select-multiple.d.ts +4 -0
  8. package/types/components/zd-select-tree/select-tree.d.ts +7 -1
  9. package/types/components/zd-select-tree-multiple/select-tree-multiple.d.ts +4 -0
  10. package/types/components/zd-tree-grid/interfaces.d.ts +3 -1
  11. package/types/components/zd-tree-grid/tree-grid-editable.d.ts +4 -3
  12. package/types/utils/report/report-type/interfaces.d.ts +7 -2
  13. package/types/utils/report/report-type/xls-report.d.ts +17 -1
  14. package/types/components/zd-apex-chart/apex_chart.d.ts +0 -55
  15. package/types/components/zd-button-group/button_group.d.ts +0 -83
  16. package/types/components/zd-checkbox-multiple/checkbox_multiple.d.ts +0 -42
  17. package/types/components/zd-code-editor/code_editor.d.ts +0 -58
  18. package/types/components/zd-code-editor/prism.d.ts +0 -14
  19. package/types/components/zd-collapse-card/collapse_card.d.ts +0 -56
  20. package/types/components/zd-component/child_not_found.d.ts +0 -6
  21. package/types/components/zd-component/component_render.d.ts +0 -16
  22. package/types/components/zd-component/invalid_accessor.d.ts +0 -6
  23. package/types/components/zd-date/date_range.d.ts +0 -124
  24. package/types/components/zd-grid/errors/not_editing.d.ts +0 -6
  25. package/types/components/zd-grid/errors/row_not_found.d.ts +0 -6
  26. package/types/components/zd-grid/grid_column.d.ts +0 -52
  27. package/types/components/zd-grid/grid_column_editable.d.ts +0 -13
  28. package/types/components/zd-grid/grid_editable.d.ts +0 -162
  29. package/types/components/zd-iterable/column_not_found.d.ts +0 -6
  30. package/types/components/zd-iterable/iterable_columns_button.d.ts +0 -29
  31. package/types/components/zd-iterable/iterable_columns_button_controller.d.ts +0 -6
  32. package/types/components/zd-iterable/iterable_page_component.d.ts +0 -27
  33. package/types/components/zd-iterable/iterable_page_info.d.ts +0 -7
  34. package/types/components/zd-iterable/iterable_page_size.d.ts +0 -62
  35. package/types/components/zd-iterable/iterable_pagination.d.ts +0 -28
  36. package/types/components/zd-list/item_not_found.d.ts +0 -6
  37. package/types/components/zd-list/list_group.d.ts +0 -30
  38. package/types/components/zd-list/list_item.d.ts +0 -49
  39. package/types/components/zd-master-detail/detail_not_found.d.ts +0 -6
  40. package/types/components/zd-master-detail/master_detail.d.ts +0 -20
  41. package/types/components/zd-master-detail/master_not_found.d.ts +0 -6
  42. package/types/components/zd-menu/menu_button.d.ts +0 -28
  43. package/types/components/zd-menu/menu_group.d.ts +0 -53
  44. package/types/components/zd-menu/menu_link.d.ts +0 -46
  45. package/types/components/zd-menu/menu_separator.d.ts +0 -7
  46. package/types/components/zd-modal/modal_close_button.d.ts +0 -28
  47. package/types/components/zd-svg-map/svg_map.d.ts +0 -78
  48. package/types/components/zd-tabs/tab_not_found.d.ts +0 -11
  49. package/types/components/zd-text-input/text_input.d.ts +0 -90
  50. package/types/components/zd-tree-grid/errors/not_editing.d.ts +0 -6
  51. package/types/components/zd-tree-grid/errors/row_not_found.d.ts +0 -6
  52. package/types/components/zd-tree-grid/tree-data-structure.d.ts +0 -144
  53. package/types/components/zd-tree-grid/tree_data_structure.d.ts +0 -144
  54. package/types/components/zd-tree-grid/tree_grid.d.ts +0 -77
  55. package/types/components/zd-tree-grid/tree_grid_column.d.ts +0 -52
  56. package/types/components/zd-tree-grid/tree_grid_column_editable.d.ts +0 -13
  57. package/types/components/zd-tree-grid/tree_grid_editable.d.ts +0 -157
@@ -2495,7 +2495,7 @@ class Loading extends Component {
2495
2495
  */
2496
2496
  this.text = 'Loading';
2497
2497
  this.isVisible = false;
2498
- this.zIndex = '100';
2498
+ this.zIndex = 999;
2499
2499
  this.text = this.getInitValue('text', props.text, this.text);
2500
2500
  this.zIndex = this.getInitValue('zIndex', props.zIndex, this.zIndex);
2501
2501
  this.defaultText = this.text;
@@ -4313,11 +4313,11 @@ class Column extends Component {
4313
4313
  * Apply conditions
4314
4314
  * @param row Datasource row
4315
4315
  */
4316
- applyCondition(row) {
4316
+ applyCondition(row, factoredConditions = this.factoredConditions) {
4317
4317
  const appliedConditions = {};
4318
- Object.keys(this.factoredConditions).forEach((condition) => {
4319
- const conditionFunction = this.factoredConditions[condition];
4320
- set(appliedConditions, condition, conditionFunction({ row }));
4318
+ Object.keys(factoredConditions).forEach((condition) => {
4319
+ const conditionFunction = factoredConditions[condition];
4320
+ set(appliedConditions, condition, conditionFunction({ row, column: this }));
4321
4321
  });
4322
4322
  return appliedConditions;
4323
4323
  }
@@ -4331,11 +4331,7 @@ class Column extends Component {
4331
4331
  const appliedConditions = {};
4332
4332
  Object.keys(this.actionFactoredConditions).forEach((action) => {
4333
4333
  const factoredConditions = this.actionFactoredConditions[action];
4334
- appliedConditions[action] = {};
4335
- Object.keys(factoredConditions).forEach((condition) => {
4336
- const conditionFunction = factoredConditions[condition];
4337
- set(appliedConditions[action], condition, conditionFunction({ row }));
4338
- });
4334
+ appliedConditions[action] = Object.assign({}, this.applyCondition(row, factoredConditions));
4339
4335
  });
4340
4336
  return appliedConditions;
4341
4337
  }
@@ -5068,7 +5064,6 @@ class GridEditable extends Grid {
5068
5064
  if (this.editing)
5069
5065
  return;
5070
5066
  if (column.editable) {
5071
- this.selectedRows = [];
5072
5067
  this.editing = true;
5073
5068
  this.preventRowClick = true;
5074
5069
  this.datasource.currentRow = row;
@@ -5138,7 +5133,7 @@ class GridEditable extends Grid {
5138
5133
  else {
5139
5134
  colValue = row[column.name];
5140
5135
  }
5141
- const componentProps = merge({}, column.componentProps, cellProps.componentProps);
5136
+ const componentProps = merge({}, column.componentProps, cellProps === null || cellProps === void 0 ? void 0 : cellProps.componentProps);
5142
5137
  let compEvents = {};
5143
5138
  if (componentProps && componentProps.events) {
5144
5139
  compEvents = Event.factory(componentProps.events);
@@ -5848,7 +5843,7 @@ class Select extends TextInput {
5848
5843
  */
5849
5844
  constructor(props) {
5850
5845
  var _a, _b;
5851
- super(props);
5846
+ super(Object.assign(Object.assign({}, props), { value: undefined }));
5852
5847
  /**
5853
5848
  * Field used to display values
5854
5849
  */
@@ -5931,6 +5926,7 @@ class Select extends TextInput {
5931
5926
  this.cachedData = [];
5932
5927
  this.cachedTotal = 0;
5933
5928
  this.formatterFn = FormatterParserProvider.getFormatter('ZdSelect');
5929
+ this.pushedValue = null;
5934
5930
  this.loadMoreQtty = 0;
5935
5931
  this.debounceSearch = debounce(this.doSearch, 500);
5936
5932
  this.appendIcon = this.getInitValue('appendIcon', props.appendIcon, 'expand');
@@ -5952,7 +5948,13 @@ class Select extends TextInput {
5952
5948
  this.dataText = [this.dataText];
5953
5949
  const defaultDatasource = this.getDefaultDatasource(props);
5954
5950
  this.datasource = DatasourceFactory.factory(defaultDatasource);
5955
- this.setDefaultValue(props.value, (_b = props.datasource) === null || _b === void 0 ? void 0 : _b.lazyLoad);
5951
+ this.overrideGet();
5952
+ let defaultValue = props.value;
5953
+ if (Accessor.isAccessorDefinition(props.value)) {
5954
+ defaultValue = this.getAccessorValue(props.value);
5955
+ this.getInitValue('value', props.value, this.value);
5956
+ }
5957
+ this.setDefaultValue(defaultValue, (_b = props.datasource) === null || _b === void 0 ? void 0 : _b.lazyLoad);
5956
5958
  this.preventLoadOnFocus = !defaultDatasource.lazyLoad;
5957
5959
  this.preventLoadOnFocus = this.getInitValue('preventLoadOnFocus', props.preventLoadOnFocus, this.preventLoadOnFocus);
5958
5960
  this.loadMoreQtty = this.datasource.limit;
@@ -5961,6 +5963,11 @@ class Select extends TextInput {
5961
5963
  this.createAccessors();
5962
5964
  this.initialized = true;
5963
5965
  }
5966
+ getAccessorValue(accessorName) {
5967
+ const [controller, accessor] = Accessor.getAccessor(accessorName);
5968
+ const instance = Loader.getInstance(controller);
5969
+ return instance[accessor];
5970
+ }
5964
5971
  /**
5965
5972
  * Retrieves datasource structure applying infinity scroll
5966
5973
  * @param field Field structure
@@ -5972,6 +5979,16 @@ class Select extends TextInput {
5972
5979
  const searchIn = (((_a = field.datasource) === null || _a === void 0 ? void 0 : _a.searchIn) || []).concat(searchInDefault);
5973
5980
  return Object.assign(Object.assign({}, field.datasource), { searchIn, lazyLoad: (field.value !== '' && field.value !== undefined) || (field.datasource && field.datasource.lazyLoad) });
5974
5981
  }
5982
+ overrideGet() {
5983
+ const oldGet = this.datasource.get;
5984
+ this.datasource.get = () => __awaiter(this, void 0, void 0, function* () {
5985
+ yield oldGet.call(this.datasource);
5986
+ if (this.indexOf(this.value) !== -1 || this.datasource.search || this.isFocused)
5987
+ return;
5988
+ yield this.setValue(this.value, false);
5989
+ this.removePushedValue();
5990
+ });
5991
+ }
5975
5992
  get search() {
5976
5993
  return this.searchValue;
5977
5994
  }
@@ -5998,7 +6015,7 @@ class Select extends TextInput {
5998
6015
  }
5999
6016
  if (this.manualMode)
6000
6017
  return;
6001
- this.cachedData = this.datasource.data;
6018
+ this.cachedData = [...this.datasource.data];
6002
6019
  this.cachedTotal = this.datasource.total;
6003
6020
  if (pushed) {
6004
6021
  this.pushedValue = this.selectedData;
@@ -6057,10 +6074,14 @@ class Select extends TextInput {
6057
6074
  if (!this.pushedValue && this.isFilledObj(this.selectValue) && this.indexOf(this.selectValue) === -1) {
6058
6075
  this.pushedValue = this.selectValue;
6059
6076
  }
6060
- if (this.isFilledObj(this.pushedValue) && this.indexOf(this.pushedValue) === -1) {
6077
+ const index = this.indexOf(this.pushedValue);
6078
+ if (this.isFilledObj(this.pushedValue) && index === -1) {
6061
6079
  this.datasource.data.unshift(this.pushedValue);
6062
6080
  }
6063
- this.cachedData = this.datasource.data;
6081
+ else if (index !== 0) {
6082
+ this.pushedValue = null;
6083
+ }
6084
+ this.cachedData = [...this.datasource.data];
6064
6085
  this.cachedTotal = this.datasource.total;
6065
6086
  }
6066
6087
  /**
@@ -6119,6 +6140,7 @@ class Select extends TextInput {
6119
6140
  }
6120
6141
  if (!searchValue) {
6121
6142
  this.setFieldRowValue(null);
6143
+ this.selectValue = this.selectedData;
6122
6144
  return false;
6123
6145
  }
6124
6146
  this.setFieldRowValue(searchValue);
@@ -6229,7 +6251,7 @@ class Select extends TextInput {
6229
6251
  else {
6230
6252
  this.removePushedValue();
6231
6253
  this.datasource.search = this.searchValue;
6232
- this.datasource.data = this.cachedData;
6254
+ this.datasource.data = [...this.cachedData];
6233
6255
  this.datasource.total = this.cachedTotal;
6234
6256
  }
6235
6257
  });
@@ -6242,6 +6264,11 @@ class Select extends TextInput {
6242
6264
  yield this.datasource.setLimit(this.datasource.limit + this.loadMoreQtty);
6243
6265
  if (!this.datasource.search) {
6244
6266
  this.afterLoad();
6267
+ const { dataValue } = this;
6268
+ const isSelected = this.selectValue && this.pushedValue && this.selectValue[dataValue] === this.pushedValue[dataValue];
6269
+ if (isSelected)
6270
+ return;
6271
+ this.removePushedValue();
6245
6272
  }
6246
6273
  });
6247
6274
  }
@@ -6255,7 +6282,7 @@ class Select extends TextInput {
6255
6282
  this.datasource.search = '';
6256
6283
  this.dirtySearchValue = '';
6257
6284
  if (!this.manualMode) {
6258
- this.datasource.data = this.cachedData;
6285
+ this.datasource.data = [...this.cachedData];
6259
6286
  this.datasource.total = this.cachedTotal;
6260
6287
  }
6261
6288
  this.checkValueOnBlur();
@@ -6268,13 +6295,17 @@ class Select extends TextInput {
6268
6295
  }
6269
6296
  if (this.manualMode)
6270
6297
  return;
6271
- if (this.isFilledObj(this.selectValue)) {
6272
- if (this.indexOf(this.selectValue) === -1) {
6273
- this.datasource.data.unshift(this.selectValue);
6274
- this.pushedValue = this.selectValue;
6298
+ if (this.isFilledObj(this.selectValue) && this.indexOf(this.selectValue) === -1) {
6299
+ if (this.pushedValue) {
6300
+ this.removePushedValue();
6275
6301
  }
6302
+ this.datasource.data.unshift(this.selectValue);
6303
+ this.pushedValue = this.selectValue;
6276
6304
  return;
6277
6305
  }
6306
+ const { dataValue } = this;
6307
+ if (this.pushedValue && this.selectValue && this.selectValue[dataValue] === this.pushedValue[dataValue])
6308
+ return;
6278
6309
  this.removePushedValue();
6279
6310
  }
6280
6311
  showLoadMore() {
@@ -7864,7 +7895,6 @@ class SelectMultiple extends Select {
7864
7895
  */
7865
7896
  constructor(props) {
7866
7897
  super(props);
7867
- this.selectedValue = [];
7868
7898
  /**
7869
7899
  * Selected items that were added to datasource
7870
7900
  */
@@ -7878,6 +7908,9 @@ class SelectMultiple extends Select {
7878
7908
  */
7879
7909
  this.moreChip = 0;
7880
7910
  this.showSelectAll = false;
7911
+ if (!this.selectedValue) {
7912
+ this.selectedValue = [];
7913
+ }
7881
7914
  this.showSelectAll = this.getInitValue('showSelectAll', props.showSelectAll, this.showSelectAll);
7882
7915
  this.createAccessors();
7883
7916
  }
@@ -7917,20 +7950,23 @@ class SelectMultiple extends Select {
7917
7950
  set selectValue(rows) {
7918
7951
  if (!Array.isArray(rows))
7919
7952
  return;
7920
- if (!this.manualMode && this.insertedValues.length > 0) {
7921
- this.insertsRemoved = [];
7953
+ if (!this.manualMode) {
7922
7954
  const values = rows.map((row) => row[this.dataValue]);
7923
- this.insertedValues = this.insertedValues.filter((inserted) => {
7924
- const removed = !values.includes(inserted[this.dataValue]);
7925
- if (removed) {
7926
- this.insertsRemoved.push(inserted);
7927
- }
7928
- return !removed;
7929
- });
7955
+ this.cutFromAToB(this.insertedValues, this.insertsRemoved, (value) => !values.includes(value[this.dataValue]));
7956
+ this.cutFromAToB(this.insertsRemoved, this.insertedValues, (value) => values.includes(value[this.dataValue]));
7930
7957
  }
7931
7958
  this.selectedValue = rows;
7932
7959
  this.setFieldValue(this.getValues(rows));
7933
7960
  }
7961
+ /**
7962
+ * Removes item from array a and add it to array b if condition is satisfied
7963
+ */
7964
+ cutFromAToB(a, b, condition) {
7965
+ const indices = a.reduce((result, value, index) => (condition(value) ? [...result, index] : result), []);
7966
+ indices.forEach((index) => {
7967
+ b.push(a.splice(index)[0]);
7968
+ });
7969
+ }
7934
7970
  setFieldValue(value) {
7935
7971
  return __awaiter(this, void 0, void 0, function* () {
7936
7972
  const promises = [];
@@ -7960,7 +7996,9 @@ class SelectMultiple extends Select {
7960
7996
  }));
7961
7997
  }
7962
7998
  });
7963
- yield Promise.all(promises);
7999
+ if (promises.length) {
8000
+ yield Promise.all(promises);
8001
+ }
7964
8002
  if (searchValues.length > 0) {
7965
8003
  this.setFieldRowValue(searchValues);
7966
8004
  }
@@ -8105,7 +8143,7 @@ class SelectMultiple extends Select {
8105
8143
  showLoadMore() {
8106
8144
  return !!this.datasource.data.length
8107
8145
  && !this.datasource.loadAll
8108
- && (this.datasource.data.length - this.insertedValues.length) < this.datasource.total;
8146
+ && (this.datasource.data.length - this.insertedValues.length - this.insertsRemoved.length) < this.datasource.total;
8109
8147
  }
8110
8148
  /**
8111
8149
  * Load more data
@@ -8113,10 +8151,16 @@ class SelectMultiple extends Select {
8113
8151
  loadMore() {
8114
8152
  return __awaiter(this, void 0, void 0, function* () {
8115
8153
  yield this.datasource.setLimit(this.datasource.limit + this.loadMoreQtty);
8154
+ this.insertsRemoved = this.insertsRemoved.filter((insert) => {
8155
+ const value = insert[this.dataValue];
8156
+ const foundInData = this.datasource.data.find(this.getCondition(value));
8157
+ return !foundInData;
8158
+ });
8159
+ this.insertSelected();
8116
8160
  if (!this.datasource.search) {
8117
8161
  this.setCache();
8118
8162
  }
8119
- this.insertSelected();
8163
+ this.removePushedValue();
8120
8164
  });
8121
8165
  }
8122
8166
  /**
@@ -8310,6 +8354,9 @@ class TreeDataStructure {
8310
8354
  }
8311
8355
  return item;
8312
8356
  });
8357
+ if (parent) { // remove all existing children to add new ones
8358
+ this.treeData = this.treeData.filter((item) => item.tree__parent !== parent);
8359
+ }
8313
8360
  if (!parent) {
8314
8361
  this.treeData = childData;
8315
8362
  }
@@ -8493,7 +8540,7 @@ class TreeDataStructure {
8493
8540
  this.treeStructure = {};
8494
8541
  const childData = this.originalDatasource.data.map((row) => (Object.assign(Object.assign({}, row), { tree__children: [], tree__opened: false, tree__searched: true, tree__level: 1, tree__parent: undefined })));
8495
8542
  this.treeData = childData;
8496
- this.treeStructure['no-parent'] = this.originalDatasource.data;
8543
+ this.treeStructure['no-parent'] = childData;
8497
8544
  }
8498
8545
  /**
8499
8546
  * Search value against a memory datasource
@@ -8628,6 +8675,7 @@ class SelectTree extends TextInput {
8628
8675
  * Defines if should wait and not execute GET method when Datasource is created
8629
8676
  */
8630
8677
  this.lazyLoad = true;
8678
+ this.selectValue = null;
8631
8679
  this.nodes = this.getInitValue('nodes', props.nodes, this.nodes);
8632
8680
  this.alwaysOpen = this.getInitValue('alwaysOpen', props.alwaysOpen, this.alwaysOpen);
8633
8681
  this.flattenSearchResults = this.getInitValue('flattenSearchResults', props.flattenSearchResults, this.flattenSearchResults);
@@ -8795,8 +8843,41 @@ class SelectTree extends TextInput {
8795
8843
  get searchValue() {
8796
8844
  return this.lastInputValue;
8797
8845
  }
8846
+ clearRow(row) {
8847
+ const result = Object.assign({}, row);
8848
+ Object.keys(result).forEach((key) => {
8849
+ if (key.indexOf('tree__') === 0) {
8850
+ delete result[key];
8851
+ }
8852
+ });
8853
+ return result;
8854
+ }
8855
+ get value() {
8856
+ if (!this.selectValue)
8857
+ return this.selectValue;
8858
+ if (this.returnObject) {
8859
+ return this.clearRow(this.selectValue.row);
8860
+ }
8861
+ return this.selectValue;
8862
+ }
8863
+ set value(value) {
8864
+ this.selectValue = value;
8865
+ }
8798
8866
  setValue(value) {
8799
- this.value = value;
8867
+ if (this.returnObject) {
8868
+ if (typeof value !== 'object') {
8869
+ this.value = { id: value };
8870
+ }
8871
+ else {
8872
+ this.value = { id: value[this.dataValue] };
8873
+ }
8874
+ }
8875
+ else if (typeof value === 'object') {
8876
+ this.value = value[this.dataValue];
8877
+ }
8878
+ else {
8879
+ this.value = value;
8880
+ }
8800
8881
  }
8801
8882
  }
8802
8883
 
@@ -8822,6 +8903,7 @@ class SelectTreeMultiple extends SelectTree {
8822
8903
  * Selected Nodes
8823
8904
  */
8824
8905
  this.selectedNodes = [];
8906
+ this.selectValue = [];
8825
8907
  this.flat = this.getInitValue('flat', props.flat, this.flat);
8826
8908
  this.limit = this.getInitValue('limit', props.limit, this.limit);
8827
8909
  this.createAccessors();
@@ -8838,6 +8920,34 @@ class SelectTreeMultiple extends SelectTree {
8838
8920
  deselect(node, element) {
8839
8921
  this.callEvent('onDeselect', { element, component: this, node });
8840
8922
  }
8923
+ get value() {
8924
+ if (this.returnObject) {
8925
+ return this.selectValue.map((value) => this.clearRow(value.row));
8926
+ }
8927
+ return this.selectValue;
8928
+ }
8929
+ set value(value) {
8930
+ this.selectValue = value;
8931
+ }
8932
+ setValue(value) {
8933
+ const arrValue = Array.isArray(value) ? value : [value];
8934
+ if (this.returnObject) {
8935
+ this.value = arrValue.map((item) => {
8936
+ if (typeof item !== 'object') {
8937
+ return { id: item };
8938
+ }
8939
+ return { id: item[this.dataValue] };
8940
+ });
8941
+ }
8942
+ else {
8943
+ this.value = arrValue.map((item) => {
8944
+ if (typeof item === 'object') {
8945
+ return item[this.dataValue];
8946
+ }
8947
+ return item;
8948
+ });
8949
+ }
8950
+ }
8841
8951
  }
8842
8952
 
8843
8953
  /**
@@ -10107,7 +10217,6 @@ class TreeGridEditable extends TreeGrid {
10107
10217
  if (this.editing)
10108
10218
  return;
10109
10219
  if (column.editable) {
10110
- this.selectedRows = [];
10111
10220
  this.editing = true;
10112
10221
  this.preventRowClick = true;
10113
10222
  this.datasource.currentRow = row;
@@ -11056,17 +11165,37 @@ class PDFReport extends BaseReport {
11056
11165
  }
11057
11166
 
11058
11167
  class XLSReport extends BaseReport {
11059
- constructor() {
11060
- super(...arguments);
11168
+ constructor(type) {
11169
+ super();
11061
11170
  this.route = '/generateXLS';
11171
+ this.expressionZeedhiToXls = {
11172
+ AVG: 'AVERAGE',
11173
+ COUNT: 'COUNTA',
11174
+ MAX: 'MAX',
11175
+ MIN: 'MIN',
11176
+ SUM: 'SUM',
11177
+ };
11178
+ this.colunmXLS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
11179
+ this.type = type || 'xls';
11062
11180
  }
11063
- buildDataset(data, columns) {
11181
+ buildDataset(data, columns, metadata) {
11182
+ let result;
11183
+ if (this.type === 'xls') {
11184
+ result = this.formatRawDataSet(data, columns);
11185
+ }
11186
+ else if (metadata) {
11187
+ result = this.formatDataSet(metadata, data);
11188
+ }
11189
+ return JSON.stringify(result);
11190
+ }
11191
+ // formata o dataset para o formato "cru" xls
11192
+ formatRawDataSet(data, columns) {
11064
11193
  const columnNames = columns.map((col) => col.name);
11065
11194
  const result = data.reduce((reduced, row) => {
11066
11195
  const values = columnNames.map((col) => row[col] || '');
11067
11196
  return [...reduced, values];
11068
11197
  }, [columnNames]);
11069
- return JSON.stringify(result);
11198
+ return result;
11070
11199
  }
11071
11200
  buildMetadata(name, title, columns, filter) {
11072
11201
  const builtCols = this.buildColumns(columns);
@@ -11095,9 +11224,215 @@ class XLSReport extends BaseReport {
11095
11224
  orientation: 'PORTRAIT',
11096
11225
  columns: builtCols,
11097
11226
  filter: builtFilters,
11227
+ reportXLS: true,
11228
+ xlsMergedCell: [],
11098
11229
  };
11099
11230
  return Promise.resolve(JSON.stringify(metadataObj));
11100
11231
  }
11232
+ isFormat3(format) {
11233
+ return format === 'xls3';
11234
+ }
11235
+ // Ordenar o nome das colunas de acordo com seu index, excluindo o nome das colunas agrupadas
11236
+ getColumnsNameFormat3(columns, metaData) {
11237
+ const columnsNameGroup = metaData.groups.map((row) => row.field);
11238
+ let columnsName = [];
11239
+ Object.entries(columns).forEach((row) => {
11240
+ const columnName = row[0];
11241
+ if (columnsNameGroup.indexOf(columnName) === -1) {
11242
+ const index = row[1].sequence;
11243
+ columnsName[index] = columnName;
11244
+ }
11245
+ });
11246
+ columnsName = columnsName.filter((columnName) => typeof columnName === 'string');
11247
+ return columnsName;
11248
+ }
11249
+ // Ordenar o nome das colunas de acordo com seu index, e sempre deixando as colunas agrupadas nas primeiras posições
11250
+ getColumnsName(columns, metaData, lengthGroup) {
11251
+ const columnsNameGroup = metaData.groups.map((row) => row.field);
11252
+ let columnsName = [];
11253
+ Object.entries(columns).forEach((row) => {
11254
+ const columnName = row[0];
11255
+ const index = row[1].sequence;
11256
+ if (columnsNameGroup.indexOf(columnName) === -1) {
11257
+ columnsName[index + lengthGroup] = columnName;
11258
+ }
11259
+ else {
11260
+ columnsName[index] = columnName;
11261
+ }
11262
+ });
11263
+ columnsName = columnsName.filter((columnName) => typeof columnName === 'string');
11264
+ return columnsName;
11265
+ }
11266
+ // Inicializa alguns valores auxiliares
11267
+ initVars(metaData, type) {
11268
+ metaData.xlsMergedCell = [];
11269
+ const { columns } = metaData;
11270
+ const lengthGroup = metaData.groups.length;
11271
+ const indexLastGroup = lengthGroup - 1;
11272
+ let columnsName = [];
11273
+ if (this.isFormat3(type)) {
11274
+ columnsName = this.getColumnsNameFormat3(columns, metaData);
11275
+ }
11276
+ else {
11277
+ columnsName = this.getColumnsName(columns, metaData, lengthGroup);
11278
+ }
11279
+ const rowValues = [];
11280
+ const formatedDataSet = [];
11281
+ const groups = [];
11282
+ groups.groupEnd = {};
11283
+ groups.groupEnd.cellsfunc = {};
11284
+ return {
11285
+ columns, indexLastGroup, columnsName, rowValues, formatedDataSet, groups,
11286
+ };
11287
+ }
11288
+ // formata a linha do grupo de acordo com o formato xls3
11289
+ setRowGroupFormat3(row, rowValuesParam, groups, formatedDataSet, columnsName, columns, indexLastGroup) {
11290
+ let rowValues = rowValuesParam;
11291
+ const label = `${row.groupLabel}:${row.groupValue}`;
11292
+ const index = row.groupIndex;
11293
+ if (row.groupHeader) {
11294
+ rowValues[index] = label;
11295
+ groups[index] = { init: null, end: null };
11296
+ formatedDataSet.push(rowValues);
11297
+ rowValues = [];
11298
+ }
11299
+ else if (row.groupFooter) {
11300
+ if (!row.groupLabel) {
11301
+ rowValues.push('Total');
11302
+ }
11303
+ else {
11304
+ rowValues.push(`Total (${label})`);
11305
+ }
11306
+ formatedDataSet.push(rowValues);
11307
+ rowValues = [];
11308
+ const funcXls = null;
11309
+ columnsName.forEach((column) => {
11310
+ this.formatRowFunc(column, columns, row, index, rowValues, funcXls, groups, indexLastGroup);
11311
+ });
11312
+ }
11313
+ return rowValues;
11314
+ }
11315
+ // formata as expressões da linha
11316
+ formatRowFunc(column, columns, row, index, rowValues, funcXlsParam, groups, indexLastGroup) {
11317
+ let funcXls = funcXlsParam;
11318
+ if ((row[column] === 0 || row[column]) && index !== undefined) {
11319
+ const letter = this.colunmXLS[rowValues.length];
11320
+ funcXls = this.expressionZeedhiToXls[columns[column].expression];
11321
+ const cellsfunc = `${letter + groups[index].init}:${letter}${groups[index].end}`;
11322
+ let expression = '';
11323
+ if (indexLastGroup === index) {
11324
+ expression = `=${funcXls}(${cellsfunc})`;
11325
+ }
11326
+ else {
11327
+ expression = `=${funcXls}(${groups[index].cellsfunc[column]})`;
11328
+ if (index === 0) {
11329
+ if (groups.groupEnd.cellsfunc[column]) {
11330
+ groups.groupEnd.cellsfunc[column] += `,${groups[index].cellsfunc[column]}`;
11331
+ }
11332
+ else {
11333
+ groups.groupEnd.cellsfunc[column] = groups[index].cellsfunc[column];
11334
+ }
11335
+ }
11336
+ groups[index].cellsfunc[column] = null;
11337
+ }
11338
+ rowValues.push(expression);
11339
+ groups.forEach((group, indexGroup) => {
11340
+ if (indexGroup !== indexLastGroup) {
11341
+ if (!group.cellsfunc) {
11342
+ group.cellsfunc = {};
11343
+ }
11344
+ if (group.cellsfunc[column]) {
11345
+ group.cellsfunc[column] += `,${cellsfunc}`;
11346
+ }
11347
+ else {
11348
+ group.cellsfunc[column] = cellsfunc;
11349
+ }
11350
+ }
11351
+ });
11352
+ }
11353
+ else {
11354
+ let cell = row[column];
11355
+ if (row.groupSummary) {
11356
+ const groupEndFunc = groups.groupEnd.cellsfunc;
11357
+ if (groupEndFunc[column]) {
11358
+ funcXls = this.expressionZeedhiToXls[columns[column].expression];
11359
+ cell = `=${funcXls}(${groupEndFunc[column]})`;
11360
+ }
11361
+ }
11362
+ rowValues.push(cell);
11363
+ }
11364
+ }
11365
+ // formata a linha de grupo de acordo com o formato xls2
11366
+ setRowGroup(row, rowValues, groups, metaData, formatedDataSet, columnsName, columns, indexLastGroup) {
11367
+ const label = `${row.groupLabel}:${row.groupValue}`;
11368
+ const index = row.groupIndex;
11369
+ if (row.groupHeader) {
11370
+ rowValues[index] = label;
11371
+ groups[index] = { init: null, end: null };
11372
+ }
11373
+ else if (row.groupFooter) {
11374
+ if (!row.groupLabel) {
11375
+ rowValues.push('Total');
11376
+ }
11377
+ else {
11378
+ rowValues.push(`Total (${label})`);
11379
+ }
11380
+ const funcXls = null;
11381
+ if (groups[index]) {
11382
+ metaData.xlsMergedCell.push({
11383
+ start_row: groups[index].init,
11384
+ start_col: this.colunmXLS[index],
11385
+ end_row: formatedDataSet.length + 2,
11386
+ end_col: this.colunmXLS[index],
11387
+ });
11388
+ }
11389
+ columnsName.forEach((column, columnIndex) => {
11390
+ if (!(row.groupFooter && columnIndex === 0)) {
11391
+ this.formatRowFunc(column, columns, row, index, rowValues, funcXls, groups, indexLastGroup);
11392
+ }
11393
+ });
11394
+ }
11395
+ return rowValues;
11396
+ }
11397
+ // Defina o index dos grupos
11398
+ setIndexGroups(groups, formatedDataSet) {
11399
+ groups.forEach((group) => {
11400
+ if (!group.init) {
11401
+ group.init = formatedDataSet.length + 2;
11402
+ }
11403
+ group.end = formatedDataSet.length + 2;
11404
+ });
11405
+ }
11406
+ // Preenche uma linha "normal"
11407
+ setRowNormal(columnsName, rowValues, row) {
11408
+ columnsName.forEach((column) => {
11409
+ rowValues.push(row[column]);
11410
+ });
11411
+ }
11412
+ formatDataSet(metaData, dataSet) {
11413
+ const initVars = this.initVars(metaData, this.type);
11414
+ const { columns, indexLastGroup, columnsName, formatedDataSet, groups, } = initVars;
11415
+ let { rowValues } = initVars;
11416
+ dataSet.forEach((row) => {
11417
+ if (row.group || row.groupFooter) {
11418
+ if (this.isFormat3(this.type)) {
11419
+ rowValues = this.setRowGroupFormat3(row, rowValues, groups, formatedDataSet, columnsName, columns, indexLastGroup);
11420
+ }
11421
+ else {
11422
+ rowValues = this.setRowGroup(row, rowValues, groups, metaData, formatedDataSet, columnsName, columns, indexLastGroup);
11423
+ }
11424
+ }
11425
+ else {
11426
+ this.setIndexGroups(groups, formatedDataSet);
11427
+ this.setRowNormal(columnsName, rowValues, row);
11428
+ }
11429
+ if (!row.groupHeader) {
11430
+ formatedDataSet.push(rowValues);
11431
+ }
11432
+ rowValues = [];
11433
+ });
11434
+ return [columnsName].concat(formatedDataSet);
11435
+ }
11101
11436
  }
11102
11437
 
11103
11438
  class Report {
@@ -11133,8 +11468,8 @@ class Report {
11133
11468
  if (type === 'pdf') {
11134
11469
  return new PDFReport();
11135
11470
  }
11136
- if (type === 'xls') {
11137
- return new XLSReport();
11471
+ if (type === 'xls' || type === 'xls2' || type === 'xls3') {
11472
+ return new XLSReport(type);
11138
11473
  }
11139
11474
  throw new Error(`Invalid report type: ${type}`);
11140
11475
  }
@@ -11149,9 +11484,18 @@ class Report {
11149
11484
  const reportType = this.getReportType(type);
11150
11485
  const { route } = reportType;
11151
11486
  const { name, columns, datasource } = this.iterable;
11487
+ const { groupedData } = Object.assign({}, this.iterable);
11152
11488
  const formattedColumns = this.removeActionColumns(columns);
11153
- const dataset = reportType.buildDataset(data, formattedColumns);
11154
11489
  const metadataObj = yield reportType.buildMetadata(name, this.title, formattedColumns, datasource.filter, portrait);
11490
+ let dataset;
11491
+ if ((reportType.type === 'xls2' || reportType.type === 'xls3') && groupedData) {
11492
+ const rowMetadata = rowObj.metaData;
11493
+ const metadataObjClone = merge(rowMetadata, JSON.parse(metadataObj));
11494
+ dataset = reportType.buildDataset(groupedData, formattedColumns, metadataObjClone);
11495
+ }
11496
+ else {
11497
+ dataset = reportType.buildDataset(data, formattedColumns);
11498
+ }
11155
11499
  const filter = '[]';
11156
11500
  let row = {};
11157
11501
  if (rowObj) {