@sankhyalabs/sankhyablocks 8.6.0 → 8.8.0-dev.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 (142) hide show
  1. package/dist/cjs/{ConfigStorage-bbffce76.js → ConfigStorage-a97ca159.js} +2 -2
  2. package/dist/cjs/{DataFetcher-0cc561bc.js → DataFetcher-2a99283c.js} +25 -10
  3. package/dist/cjs/{SnkFormConfigManager-c49af777.js → SnkFormConfigManager-f641f502.js} +2 -2
  4. package/dist/cjs/{SnkMultiSelectionListDataSource-804ff4c7.js → SnkMultiSelectionListDataSource-56db34ee.js} +11 -0
  5. package/dist/cjs/{auth-fetcher-fff2319e.js → auth-fetcher-78231356.js} +1 -1
  6. package/dist/cjs/dataunit-fetcher-4f7d4ee7.js +878 -0
  7. package/dist/cjs/{form-config-fetcher-35752aad.js → form-config-fetcher-a322a522.js} +1 -1
  8. package/dist/cjs/{pesquisa-fetcher-415eab63.js → pesquisa-fetcher-7ef61508.js} +1 -1
  9. package/dist/cjs/snk-actions-button.cjs.entry.js +4 -3
  10. package/dist/cjs/snk-application.cjs.entry.js +17 -8
  11. package/dist/cjs/snk-attach.cjs.entry.js +16 -3
  12. package/dist/cjs/snk-crud.cjs.entry.js +6 -4
  13. package/dist/cjs/snk-data-exporter.cjs.entry.js +1 -1
  14. package/dist/cjs/snk-detail-view.cjs.entry.js +8 -6
  15. package/dist/cjs/snk-filter-bar.cjs.entry.js +3 -3
  16. package/dist/cjs/snk-filter-modal-item.cjs.entry.js +3 -3
  17. package/dist/cjs/snk-form-config.cjs.entry.js +2 -2
  18. package/dist/cjs/snk-form.cjs.entry.js +4 -4
  19. package/dist/cjs/snk-grid-config.cjs.entry.js +3 -3
  20. package/dist/cjs/snk-grid.cjs.entry.js +25 -14
  21. package/dist/cjs/{snk-guides-viewer-36b39c9c.js → snk-guides-viewer-aab80f66.js} +5 -4
  22. package/dist/cjs/snk-guides-viewer.cjs.entry.js +8 -6
  23. package/dist/cjs/snk-personalized-filter.cjs.entry.js +19 -9
  24. package/dist/cjs/snk-simple-crud.cjs.entry.js +8 -92
  25. package/dist/collection/components/snk-application/snk-application.js +11 -3
  26. package/dist/collection/components/snk-attach/snk-attach.js +14 -2
  27. package/dist/collection/components/snk-grid/filtercolumn/SnkMultiSelectionListDataSource.js +11 -0
  28. package/dist/collection/components/snk-grid/snk-grid.js +24 -14
  29. package/dist/collection/components/snk-personalized-filter/snk-personalized-filter.js +16 -6
  30. package/dist/collection/lib/dataUnit/InMemoryLoader.js +23 -2
  31. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +25 -10
  32. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.js +113 -0
  33. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/ArrayRepository.js +59 -0
  34. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.js +169 -0
  35. package/dist/collection/lib/http/data-fetcher/fetchers/{dataunit-fetcher.js → data-unit/dataunit-fetcher.js} +48 -100
  36. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataResult.js +1 -0
  37. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataStrategy.js +1 -0
  38. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadingInfo.js +1 -0
  39. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRecordField.js +1 -0
  40. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IResponseRecord.js +1 -0
  41. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DataUnitStrategy.js +68 -0
  42. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.js +131 -0
  43. package/dist/collection/lib/index.js +1 -1
  44. package/dist/components/DataFetcher.js +26 -11
  45. package/dist/components/SnkMultiSelectionListDataSource.js +11 -0
  46. package/dist/components/dataunit-fetcher.js +781 -100
  47. package/dist/components/snk-actions-button2.js +1 -1
  48. package/dist/components/snk-application2.js +11 -4
  49. package/dist/components/snk-attach2.js +13 -1
  50. package/dist/components/snk-crud.js +1 -1
  51. package/dist/components/snk-detail-view2.js +1 -1
  52. package/dist/components/snk-grid2.js +19 -11
  53. package/dist/components/snk-personalized-filter2.js +16 -6
  54. package/dist/components/snk-simple-crud2.js +2 -88
  55. package/dist/esm/{ConfigStorage-80ca14d5.js → ConfigStorage-26f89143.js} +2 -2
  56. package/dist/esm/{DataFetcher-044e3988.js → DataFetcher-90e91631.js} +26 -11
  57. package/dist/esm/{SnkFormConfigManager-1a8b3a44.js → SnkFormConfigManager-18948123.js} +2 -2
  58. package/dist/esm/{SnkMultiSelectionListDataSource-892f37f9.js → SnkMultiSelectionListDataSource-b9410c72.js} +11 -0
  59. package/dist/esm/{auth-fetcher-1b378f8e.js → auth-fetcher-a8c8ee7e.js} +1 -1
  60. package/dist/esm/dataunit-fetcher-1c2ccae2.js +874 -0
  61. package/dist/esm/{form-config-fetcher-c702e9e3.js → form-config-fetcher-7c3b6273.js} +1 -1
  62. package/dist/{components/pesquisa-fetcher.js → esm/pesquisa-fetcher-90d6853b.js} +1 -1
  63. package/dist/esm/snk-actions-button.entry.js +4 -3
  64. package/dist/esm/snk-application.entry.js +17 -8
  65. package/dist/esm/snk-attach.entry.js +16 -3
  66. package/dist/esm/snk-crud.entry.js +6 -4
  67. package/dist/esm/snk-data-exporter.entry.js +1 -1
  68. package/dist/esm/snk-detail-view.entry.js +8 -6
  69. package/dist/esm/snk-filter-bar.entry.js +3 -3
  70. package/dist/esm/snk-filter-modal-item.entry.js +3 -3
  71. package/dist/esm/snk-form-config.entry.js +2 -2
  72. package/dist/esm/snk-form.entry.js +4 -4
  73. package/dist/esm/snk-grid-config.entry.js +3 -3
  74. package/dist/esm/snk-grid.entry.js +26 -15
  75. package/dist/esm/{snk-guides-viewer-767ad354.js → snk-guides-viewer-62b0fa69.js} +5 -4
  76. package/dist/esm/snk-guides-viewer.entry.js +8 -6
  77. package/dist/esm/snk-personalized-filter.entry.js +19 -9
  78. package/dist/esm/snk-simple-crud.entry.js +7 -91
  79. package/dist/sankhyablocks/p-193971ad.js +1 -0
  80. package/dist/sankhyablocks/{p-dacb4c4c.entry.js → p-19cbe6e2.entry.js} +3 -3
  81. package/dist/sankhyablocks/{p-76926391.js → p-240f5892.js} +2 -2
  82. package/dist/sankhyablocks/p-2c7c1323.entry.js +1 -0
  83. package/dist/sankhyablocks/p-3253e7f2.entry.js +1 -0
  84. package/dist/sankhyablocks/{p-d1cc9007.entry.js → p-57550ddc.entry.js} +1 -1
  85. package/dist/sankhyablocks/p-5d51bff4.js +1 -0
  86. package/dist/sankhyablocks/{p-727b8cbe.entry.js → p-5dd52ec5.entry.js} +1 -1
  87. package/dist/sankhyablocks/p-6541f0df.js +1 -0
  88. package/dist/sankhyablocks/p-68fbd480.entry.js +1 -0
  89. package/dist/sankhyablocks/{p-845c7480.entry.js → p-8652f90b.entry.js} +1 -1
  90. package/dist/sankhyablocks/{p-a2c7c45f.js → p-910af03c.js} +1 -1
  91. package/dist/sankhyablocks/p-992a9d0f.js +1 -0
  92. package/dist/sankhyablocks/p-acb1374c.entry.js +1 -0
  93. package/dist/sankhyablocks/p-b36053da.entry.js +1 -0
  94. package/dist/sankhyablocks/p-b481e5ad.js +1 -0
  95. package/dist/sankhyablocks/p-d264da22.entry.js +1 -0
  96. package/dist/sankhyablocks/{p-af86752b.js → p-d47bbee3.js} +1 -1
  97. package/dist/sankhyablocks/{p-e46dd27b.entry.js → p-d563e451.entry.js} +1 -1
  98. package/dist/sankhyablocks/p-d56b65e3.entry.js +1 -0
  99. package/dist/sankhyablocks/p-e473ca13.entry.js +1 -0
  100. package/dist/sankhyablocks/{p-3ef37b31.entry.js → p-e74e2153.entry.js} +1 -1
  101. package/dist/sankhyablocks/p-e86d4a53.js +59 -0
  102. package/dist/sankhyablocks/{p-90c07587.entry.js → p-ebfa6460.entry.js} +1 -1
  103. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  104. package/dist/types/components/snk-application/snk-application.d.ts +1 -1
  105. package/dist/types/components/snk-attach/snk-attach.d.ts +1 -0
  106. package/dist/types/components/snk-grid/filtercolumn/SnkMultiSelectionListDataSource.d.ts +1 -0
  107. package/dist/types/components/snk-grid/snk-grid.d.ts +3 -4
  108. package/dist/types/components/snk-personalized-filter/snk-personalized-filter.d.ts +3 -1
  109. package/dist/types/components.d.ts +3 -2
  110. package/dist/types/lib/dataUnit/InMemoryLoader.d.ts +2 -1
  111. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +2 -1
  112. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.d.ts +13 -0
  113. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/cache/ArrayRepository.d.ts +19 -0
  114. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.d.ts +25 -0
  115. package/dist/types/lib/http/data-fetcher/fetchers/{dataunit-fetcher.d.ts → data-unit/dataunit-fetcher.d.ts} +5 -3
  116. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataResult.d.ts +6 -0
  117. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataStrategy.d.ts +7 -0
  118. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadingInfo.d.ts +8 -0
  119. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRecordField.d.ts +4 -0
  120. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IResponseRecord.d.ts +6 -0
  121. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DataUnitStrategy.d.ts +9 -0
  122. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.d.ts +15 -0
  123. package/dist/types/lib/http/data-fetcher/fetchers/personalized-filter-fetcher.d.ts +1 -1
  124. package/dist/types/lib/index.d.ts +1 -1
  125. package/package.json +3 -3
  126. package/dist/cjs/dataunit-fetcher-16b32d96.js +0 -356
  127. package/dist/esm/dataunit-fetcher-e0361781.js +0 -354
  128. package/dist/esm/pesquisa-fetcher-d1b4e5a2.js +0 -165
  129. package/dist/sankhyablocks/p-15578509.entry.js +0 -1
  130. package/dist/sankhyablocks/p-1f32ad9c.entry.js +0 -1
  131. package/dist/sankhyablocks/p-2043a64f.js +0 -1
  132. package/dist/sankhyablocks/p-251985c1.entry.js +0 -1
  133. package/dist/sankhyablocks/p-3c1759ba.entry.js +0 -1
  134. package/dist/sankhyablocks/p-473c7df4.js +0 -1
  135. package/dist/sankhyablocks/p-77aebc26.js +0 -1
  136. package/dist/sankhyablocks/p-867e9b79.js +0 -1
  137. package/dist/sankhyablocks/p-8d1602f2.entry.js +0 -1
  138. package/dist/sankhyablocks/p-98ae8ddc.entry.js +0 -1
  139. package/dist/sankhyablocks/p-9de24cf3.entry.js +0 -1
  140. package/dist/sankhyablocks/p-b6d54b6c.entry.js +0 -1
  141. package/dist/sankhyablocks/p-d5b11196.js +0 -76
  142. package/dist/sankhyablocks/p-fa9d3f73.js +0 -1
@@ -6,105 +6,21 @@ const index = require('./index-f9e81701.js');
6
6
  const core = require('@sankhyalabs/core');
7
7
  const constants = require('./constants-d187e03e.js');
8
8
  const taskbarElements = require('./taskbar-elements-39949c7a.js');
9
- require('./DataFetcher-0cc561bc.js');
10
- require('./pesquisa-fetcher-415eab63.js');
9
+ require('./DataFetcher-2a99283c.js');
10
+ require('./pesquisa-fetcher-7ef61508.js');
11
11
  const index$1 = require('./index-0e663819.js');
12
12
  require('./ISave-d68ce3cd.js');
13
13
  require('@sankhyalabs/ezui/dist/collection/utils/constants');
14
14
  require('@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata');
15
+ const dataunitFetcher = require('./dataunit-fetcher-4f7d4ee7.js');
15
16
  require('./filter-item-type.enum-aa823a00.js');
16
- require('./form-config-fetcher-35752aad.js');
17
+ require('./form-config-fetcher-a322a522.js');
17
18
  const taskbarProcessor = require('./taskbar-processor-bce3f499.js');
18
- const SnkMultiSelectionListDataSource = require('./SnkMultiSelectionListDataSource-804ff4c7.js');
19
+ const SnkMultiSelectionListDataSource = require('./SnkMultiSelectionListDataSource-56db34ee.js');
19
20
  require('./index-102ba62d.js');
20
21
  require('./_commonjsHelpers-537d719a.js');
21
22
  require('./PrintUtils-bcaeb82f.js');
22
-
23
- class InMemoryLoader {
24
- constructor(metadata, records) {
25
- this.records = records;
26
- this.metadata = metadata;
27
- this._dataUnit = new core.DataUnit(InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME);
28
- this._dataUnit.metadataLoader = () => this.metadaLoader();
29
- this._dataUnit.dataLoader = (dataUnit, request) => core.defaultDataLoader(dataUnit, request, this.getRecordsToLoad());
30
- this._dataUnit.saveLoader = (_dataUnit, changes) => this.saveLoader(_dataUnit, changes);
31
- this._dataUnit.removeLoader = (_dataUnit, recordIds) => this.removeLoader(_dataUnit, recordIds);
32
- this.dataUnit.loadMetadata().then(() => this.dataUnit.loadData());
33
- }
34
- getRecordsToLoad() {
35
- if (this._initialRecords) {
36
- try {
37
- return this._initialRecords;
38
- }
39
- finally {
40
- this._initialRecords = undefined;
41
- }
42
- }
43
- return this.dataUnit.records;
44
- }
45
- get dataUnit() {
46
- return this._dataUnit;
47
- }
48
- get records() {
49
- return this.dataUnit.records;
50
- }
51
- set records(records) {
52
- const newRecords = records === null || records === void 0 ? void 0 : records.map(record => {
53
- if (!record["__record__id__"]) {
54
- record["__record__id__"] = this.generateUniqueId();
55
- }
56
- return record;
57
- });
58
- if (this._dataUnit) {
59
- this._dataUnit.records = newRecords;
60
- }
61
- else {
62
- this._initialRecords = newRecords;
63
- }
64
- }
65
- get metadata() {
66
- return this._metadata;
67
- }
68
- set metadata(metadata) {
69
- this._metadata = metadata;
70
- if (this._dataUnit) {
71
- this._dataUnit.metadata = this._metadata;
72
- }
73
- }
74
- generateUniqueId() {
75
- return core.StringUtils.generateUUID();
76
- }
77
- metadaLoader() {
78
- return Promise.resolve(this._metadata);
79
- }
80
- saveLoader(_dataUnit, changes) {
81
- return new Promise((resolve) => {
82
- let dataUnitRecords = [];
83
- changes.forEach(change => {
84
- let { record, updatingFields, operation } = change;
85
- const changedRecord = Object.assign(Object.assign({}, record), updatingFields);
86
- if (operation === core.ChangeOperation.INSERT ||
87
- operation === core.ChangeOperation.COPY) {
88
- changedRecord["__old__id__"] = record["__record__id__"];
89
- changedRecord["__record__id__"] = this.generateUniqueId();
90
- this.records.push(changedRecord);
91
- }
92
- else {
93
- const recordIndex = this.records.findIndex(r => r["__record__id__"] == changedRecord["__record__id__"]);
94
- this.records[recordIndex] = changedRecord;
95
- }
96
- dataUnitRecords.push(changedRecord);
97
- });
98
- resolve(dataUnitRecords);
99
- });
100
- }
101
- removeLoader(_dataUnit, recordIds) {
102
- return new Promise((resolve) => {
103
- resolve(recordIds);
104
- });
105
- }
106
- }
107
- InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME = "InMemoryDataUnit";
23
+ require('./ResourceIDUtils-5ff86aa7.js');
108
24
 
109
25
  const snkSimpleCrudCss = ".sc-snk-simple-crud-h{display:flex;height:100%;width:100%}.simple-crud__container.sc-snk-simple-crud{display:grid;grid-template-rows:max-content;row-gap:12px;height:100%;width:100%}.simple-crud__container-section.sc-snk-simple-crud{flex-wrap:unset;flex-direction:column}ez-grid.sc-snk-simple-crud{--ez-grid__container--shadow:none;min-height:300px}ez-form.sc-snk-simple-crud{min-height:300px}";
110
26
 
@@ -200,7 +116,7 @@ const SnkSimpleCrud = class {
200
116
  return this._currentViewMode === constants.VIEW_MODE.GRID ? "snkSimpleCrudTaskbar.grid_regular" : "snkSimpleCrudTaskbar.form_regular";
201
117
  }
202
118
  initInMemoryDataUnit() {
203
- this._inMemoryLoader = new InMemoryLoader(this._metadata);
119
+ this._inMemoryLoader = new dataunitFetcher.InMemoryLoader(this._metadata);
204
120
  this.dataUnit = this._inMemoryLoader.dataUnit;
205
121
  this.dataUnitReady.emit(this.dataUnit);
206
122
  }
@@ -281,7 +197,7 @@ const SnkSimpleCrud = class {
281
197
  }
282
198
  render() {
283
199
  var _a;
284
- return (index.h("snk-data-unit", { class: "simple-crud__container", dataUnit: this.dataUnit, useCancelConfirm: this.useCancelConfirm, onDataStateChange: evt => this.onDataStateChange(evt), onCancelEdition: this.handleCancelEdit.bind(this), onInsertionMode: () => this.goToView(constants.VIEW_MODE.FORM), onDataUnitReady: (evt) => this.dataUnitReady.emit(evt.detail), ignoreSaveMessage: this._currentViewMode === constants.VIEW_MODE.GRID, onMessagesBuilderUpdated: evt => this.messagesBuilder = evt.detail }, index.h("header", null, index.h("slot", { name: "snkSimpleCrudHeader" })), index.h("section", { class: "ez-box ez-box--shadow simple-crud__container-section" }, index.h("snk-taskbar", { class: "ez-box ez-box--shadow ez-padding--medium ez-margin-bottom--large", dataUnit: this.dataUnit, primaryButton: ((_a = this.dataState) === null || _a === void 0 ? void 0 : _a.isDirty) ? "SAVE" : "INSERT", "data-element-id": "grid_left", messagesBuilder: this.messagesBuilder, buttons: this._taskbarProcessor.buttons, disabledButtons: this._taskbarProcessor.disabledButtons, customButtons: this._taskbarProcessor.customButtons, slot: "leftButtons", presentationMode: index$1.PresentationMode.SECONDARY }, index.h("slot", { name: "TASKBAR_CUSTOM_ELEMENTS" })), index.h("ez-view-stack", { ref: (ref) => this._viewStack = ref, "data-element-id": "simple-crud" }, index.h("stack-item", null, index.h("ez-grid", { dataUnit: this.dataUnit, config: this.gridConfig, "no-header": true, multipleSelection: this.multipleSelection, onEzDoubleClick: () => this.goToView(constants.VIEW_MODE.FORM), columnfilterDataSource: this.dataUnit.name.includes(InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME)
200
+ return (index.h("snk-data-unit", { class: "simple-crud__container", dataUnit: this.dataUnit, useCancelConfirm: this.useCancelConfirm, onDataStateChange: evt => this.onDataStateChange(evt), onCancelEdition: this.handleCancelEdit.bind(this), onInsertionMode: () => this.goToView(constants.VIEW_MODE.FORM), onDataUnitReady: (evt) => this.dataUnitReady.emit(evt.detail), ignoreSaveMessage: this._currentViewMode === constants.VIEW_MODE.GRID, onMessagesBuilderUpdated: evt => this.messagesBuilder = evt.detail }, index.h("header", null, index.h("slot", { name: "snkSimpleCrudHeader" })), index.h("section", { class: "ez-box ez-box--shadow simple-crud__container-section" }, index.h("snk-taskbar", { class: "ez-box ez-box--shadow ez-padding--medium ez-margin-bottom--large", dataUnit: this.dataUnit, primaryButton: ((_a = this.dataState) === null || _a === void 0 ? void 0 : _a.isDirty) ? "SAVE" : "INSERT", "data-element-id": "grid_left", messagesBuilder: this.messagesBuilder, buttons: this._taskbarProcessor.buttons, disabledButtons: this._taskbarProcessor.disabledButtons, customButtons: this._taskbarProcessor.customButtons, slot: "leftButtons", presentationMode: index$1.PresentationMode.SECONDARY }, index.h("slot", { name: "TASKBAR_CUSTOM_ELEMENTS" })), index.h("ez-view-stack", { ref: (ref) => this._viewStack = ref, "data-element-id": "simple-crud" }, index.h("stack-item", null, index.h("ez-grid", { dataUnit: this.dataUnit, config: this.gridConfig, "no-header": true, multipleSelection: this.multipleSelection, onEzDoubleClick: () => this.goToView(constants.VIEW_MODE.FORM), columnfilterDataSource: this.dataUnit.name.includes(dataunitFetcher.InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME)
285
201
  ? undefined
286
202
  : this._multiSelectionListDataSource, useEnterLikeTab: this.useEnterLikeTab }, index.h("div", { slot: "footer" }, index.h("slot", { name: "snkSimpleCrudFooter" })))), index.h("stack-item", null, index.h("ez-form", { dataUnit: this.dataUnit, config: this.formConfig }))))));
287
203
  }
@@ -6,7 +6,7 @@ import MGEAuthorization from '../../lib/auth/mgeauthorization.module';
6
6
  import { ConfigStorage } from "../../lib/configs/ConfigStorage";
7
7
  import { DataFetcher } from "../../lib/http/data-fetcher/DataFetcher";
8
8
  import AuthFetcher, { AutorizationType } from "../../lib/http/data-fetcher/fetchers/auth-fetcher";
9
- import DataUnitFetcher from "../../lib/http/data-fetcher/fetchers/dataunit-fetcher";
9
+ import DataUnitFetcher from "../../lib/http/data-fetcher/fetchers/data-unit/dataunit-fetcher";
10
10
  import ParametersFetcher from "../../lib/http/data-fetcher/fetchers/parameters-fecher";
11
11
  import { PesquisaFetcher } from "../../lib/http/data-fetcher/fetchers/pesquisa-fetcher";
12
12
  import { TotalsFetcher } from "../../lib/http/data-fetcher/fetchers/totals-fetcher";
@@ -2237,8 +2237,16 @@ class RequestListenerLoadingBar {
2237
2237
  }
2238
2238
  ;
2239
2239
  isIgnoreLoadingOnRequest(param) {
2240
- var _a;
2241
- if (((_a = param === null || param === void 0 ? void 0 : param.requestBody) === null || _a === void 0 ? void 0 : _a.length) == 1) {
2240
+ if (param == undefined) {
2241
+ return false;
2242
+ }
2243
+ if (param.url.includes("quietMode=true")) {
2244
+ return true;
2245
+ }
2246
+ if (param.requestBody == undefined) {
2247
+ return false;
2248
+ }
2249
+ if (param.requestBody.length == 1) {
2242
2250
  const { name } = param.requestBody[0].variables;
2243
2251
  if (name) {
2244
2252
  const nameParts = name.split(":");
@@ -2,7 +2,7 @@ import { h } from "@stencil/core";
2
2
  import { ApplicationContext } from "@sankhyalabs/core";
3
3
  import { AttachFetcher } from "../../lib/http/data-fetcher/fetchers/attach-fetcher";
4
4
  import { VIEW_MODE } from "../../lib/utils/constants";
5
- import DataUnitFetcher from "../../lib/http/data-fetcher/fetchers/dataunit-fetcher";
5
+ import DataUnitFetcher from "../../lib/http/data-fetcher/fetchers/data-unit/dataunit-fetcher";
6
6
  import { AttachmentDataUnitBuilder, buildTaskBarManager, crudConfig } from "./structure";
7
7
  const RESOURCE_ID = 'AnexoSistema';
8
8
  const DATA_UNIT_NAME = 'br.com.sankhya.core.v3.anexoSistema';
@@ -83,13 +83,25 @@ export class SnkAttach {
83
83
  dataUnit.addFilterProvider({ getFilter: () => this._dataUnitBuilder.getFilters(this.registerKey) });
84
84
  dataUnit.addInterceptor({ interceptAction: (action) => this._dataUnitBuilder.getInterceptions(dataUnit, action, this._crudElement) });
85
85
  this.dataUnit = dataUnit;
86
- this.dataUnit.loadData();
86
+ this.dataUnit.loadData().then(() => {
87
+ this.disableEditFieldsNotInForm();
88
+ });
87
89
  return this.dataUnit;
88
90
  }
89
91
  catch (error) {
90
92
  throw new Error('There was an error while creating the data unit');
91
93
  }
92
94
  }
95
+ disableEditFieldsNotInForm() {
96
+ var _a;
97
+ (_a = this.crudConfig) === null || _a === void 0 ? void 0 : _a.grid.columns.forEach(column => {
98
+ var _a;
99
+ const fieldName = column.name;
100
+ if (!((_a = this.crudConfig) === null || _a === void 0 ? void 0 : _a.form.fields.some(field => field.name === fieldName))) {
101
+ this.dataUnit.disableField(fieldName);
102
+ }
103
+ });
104
+ }
93
105
  componentWillLoad() {
94
106
  this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
95
107
  this.loadAttachmentDataUnit();
@@ -1,4 +1,5 @@
1
1
  import { DateUtils, UserInterface } from '@sankhyalabs/core';
2
+ import PreloadManager from '../../../lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager';
2
3
  export default class SnkMultiSelectionListDataSource {
3
4
  setDataUnit(dataUnit) {
4
5
  this._dataUnit = dataUnit;
@@ -13,6 +14,16 @@ export default class SnkMultiSelectionListDataSource {
13
14
  }
14
15
  return String(this._dataUnit.getFormattedValue(fieldName, value));
15
16
  }
17
+ async getStaticOptions(fieldName) {
18
+ if (fieldName == undefined) {
19
+ return Promise.resolve(undefined);
20
+ }
21
+ const result = await PreloadManager.getDistinct(this._dataUnit, fieldName);
22
+ if (result == undefined) {
23
+ return Promise.resolve(undefined);
24
+ }
25
+ return Promise.resolve(Array.from(result.entries()).map(([label, value]) => ({ label: String(label), value, check: true })));
26
+ }
16
27
  fetchData(filterTerm, fieldName) {
17
28
  return new Promise(resolve => {
18
29
  this._application.executeSelectDistinct(this._dataUnit, fieldName, filterTerm).then(result => {
@@ -8,6 +8,7 @@ import TaskbarProcessor from '../snk-taskbar/processor/taskbar-processor';
8
8
  import store from "../../lib/store";
9
9
  import SnkMultiSelectionListDataSource from './filtercolumn/SnkMultiSelectionListDataSource';
10
10
  import { SelectionMode } from '@sankhyalabs/core/dist/dataunit/DataUnit';
11
+ import { SortMode } from '@sankhyalabs/core';
11
12
  export class SnkGrid {
12
13
  constructor() {
13
14
  this._topTaskbarProcessor = new TaskbarProcessor({
@@ -88,6 +89,18 @@ export class SnkGrid {
88
89
  }
89
90
  setGridConfig(config) {
90
91
  this._gridConfig = config;
92
+ this.assertDefaultSorting();
93
+ }
94
+ assertDefaultSorting() {
95
+ if (this._gridConfig && this._dataUnit) {
96
+ this._dataUnit.defaultSorting = this._gridConfig
97
+ .columns
98
+ .sort((colA, colB) => colA.orderIndex - colB.orderIndex)
99
+ .map(({ name: field, ascending }) => {
100
+ const { dataType } = this._dataUnit.getField(field);
101
+ return { field, dataType, mode: ascending ? SortMode.ASC : SortMode.DESC };
102
+ });
103
+ }
91
104
  }
92
105
  loadConfig() {
93
106
  ConfigStorage.loadGridConfig(this.configName, this.resourceID)
@@ -213,11 +226,12 @@ export class SnkGrid {
213
226
  ElementIDUtils.addIDInfo(this._element, null, dataInfo);
214
227
  }
215
228
  finshLoading() {
216
- var _a, _b;
217
- this._dataUnitLoadLockerResolver = this._dataUnit.addLoadingLocker();
229
+ this.assertDefaultSorting();
218
230
  this.addElementID();
219
- (_a = this.columnFilterDataSource) === null || _a === void 0 ? void 0 : _a.setApplication(this._application);
220
- (_b = this.columnFilterDataSource) === null || _b === void 0 ? void 0 : _b.setDataUnit(this._dataUnit);
231
+ if (this.columnFilterDataSource != undefined) {
232
+ this.columnFilterDataSource.setApplication(this._application);
233
+ this.columnFilterDataSource.setDataUnit(this._dataUnit);
234
+ }
221
235
  }
222
236
  componentWillLoad() {
223
237
  this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
@@ -298,18 +312,13 @@ export class SnkGrid {
298
312
  getPrimaryButton() {
299
313
  return this.presentationMode === PresentationMode.PRIMARY ? "INSERT" : "";
300
314
  }
301
- onEzGridReady() {
302
- var _a;
303
- (_a = this._dataUnitLoadLockerResolver) === null || _a === void 0 ? void 0 : _a.call(this);
304
- this._dataUnitLoadLockerResolver = undefined;
305
- }
306
315
  render() {
307
316
  var _a, _b;
308
317
  if (!this._dataUnit) {
309
318
  return undefined;
310
319
  }
311
320
  return (h("div", { class: "snk-grid__container ez-flex ez-flex--column ez-flex-item--auto ez-padding--large" }, h("div", { class: "snk-grid__header ez-margin-bottom--medium" }, h("snk-filter-bar", { ref: (ref) => this._snkFilterBar = ref, dataUnit: this._dataUnit, "data-element-id": "gridFilter", class: "snk-grid__filter-bar ez-align--top", configName: this.configName, messagesBuilder: this.messagesBuilder, resourceID: this.resourceID }), ((_b = (_a = this._snkFilterBar) === null || _a === void 0 ? void 0 : _a.filterConfig) === null || _b === void 0 ? void 0 : _b.length) > 0 &&
312
- h("hr", { class: "ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-grid__header-divider" }), h("snk-taskbar", { class: "ez-padding-left--medium", "data-element-id": "grid_top", key: "topTaskbar", configName: this.configName, dataUnit: this._dataUnit, messagesBuilder: this.messagesBuilder, buttons: this._topTaskbarProcessor.buttons, disabledButtons: this._topTaskbarProcessor.disabledButtons, customButtons: this._topTaskbarProcessor.customButtons, primaryButton: this.getPrimaryButton(), resourceID: this.resourceID, customContainerId: this.taskbarCustomContainerId, customSlotId: this.topTaskbarCustomSlotId }, h("slot", { name: this.topTaskbarCustomSlotId }))), h("ez-grid", { ref: ref => this._grid = ref, class: (this.presentationMode === PresentationMode.SECONDARY ? "snk-grid-container__without-shadow " : "") + "snk-grid__table", "data-element-id": "embedded", dataUnit: this._dataUnit, key: "grid-" + this._snkDataUnit.entityName, config: this._gridConfig, onConfigChange: (evt) => { this.gridConfigChangeHandler(evt); }, onEzDoubleClick: () => this.gridDoubleClick.emit(), statusResolver: this.statusResolver, multipleSelection: this.multipleSelection, onComponentReady: () => this.onEzGridReady(), columnfilterDataSource: this.columnFilterDataSource, selectionToastConfig: this.selectionToastConfig, useEnterLikeTab: this.useEnterLikeTab, recordsValidator: this.recordsValidator, canEdit: this.canEdit }, h("snk-taskbar", { dataUnit: this._dataUnit, configName: this.configName, messagesBuilder: this.messagesBuilder, "data-element-id": "grid_left", buttons: this._headerTaskbarProcessor.buttons, disabledButtons: this._headerTaskbarProcessor.disabledButtons, customButtons: this._headerTaskbarProcessor.customButtons, slot: "leftButtons", actionsList: this.actionsList, resourceID: this.resourceID, customContainerId: this.taskbarCustomContainerId, customSlotId: this.gridHeaderCustomSlotId }, h("slot", { name: this.gridHeaderCustomSlotId }))), h("div", { class: "ez-col ez-col--sd-12" }, h("slot", { name: "SnkGridFooter" })), h("ez-modal", { modalSize: "small", closeEsc: false, closeOutsideClick: false, opened: this._popUpGridConfig, onEzCloseModal: () => this.closeGridConfig() }, h("snk-grid-config", { ref: ref => this._snkGridConfig = ref, config: this._gridConfig, "data-element-id": this._element.getAttribute(ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME), application: this._application, selectedIndex: 0, configName: this.configName, onConfigChange: (evt) => this.modalConfigChangeHandler(evt), onConfigCancel: () => this.closeGridConfig(), resourceID: this.resourceID }))));
321
+ h("hr", { class: "ez-divider-vertical ez-divider--dark ez-margin-left--medium snk-grid__header-divider" }), h("snk-taskbar", { class: "ez-padding-left--medium", "data-element-id": "grid_top", key: "topTaskbar", configName: this.configName, dataUnit: this._dataUnit, messagesBuilder: this.messagesBuilder, buttons: this._topTaskbarProcessor.buttons, disabledButtons: this._topTaskbarProcessor.disabledButtons, customButtons: this._topTaskbarProcessor.customButtons, primaryButton: this.getPrimaryButton(), resourceID: this.resourceID, customContainerId: this.taskbarCustomContainerId, customSlotId: this.topTaskbarCustomSlotId }, h("slot", { name: this.topTaskbarCustomSlotId }))), h("ez-grid", { ref: ref => this._grid = ref, class: (this.presentationMode === PresentationMode.SECONDARY ? "snk-grid-container__without-shadow " : "") + "snk-grid__table", "data-element-id": "embedded", dataUnit: this._dataUnit, key: "grid-" + this._snkDataUnit.entityName, config: this._gridConfig, onConfigChange: (evt) => { this.gridConfigChangeHandler(evt); }, onEzDoubleClick: () => this.gridDoubleClick.emit(), statusResolver: this.statusResolver, multipleSelection: this.multipleSelection, columnfilterDataSource: this.columnFilterDataSource, selectionToastConfig: this.selectionToastConfig, useEnterLikeTab: this.useEnterLikeTab, recordsValidator: this.recordsValidator, canEdit: this.canEdit }, h("snk-taskbar", { dataUnit: this._dataUnit, configName: this.configName, messagesBuilder: this.messagesBuilder, "data-element-id": "grid_left", buttons: this._headerTaskbarProcessor.buttons, disabledButtons: this._headerTaskbarProcessor.disabledButtons, customButtons: this._headerTaskbarProcessor.customButtons, slot: "leftButtons", actionsList: this.actionsList, resourceID: this.resourceID, customContainerId: this.taskbarCustomContainerId, customSlotId: this.gridHeaderCustomSlotId }, h("slot", { name: this.gridHeaderCustomSlotId }))), h("div", { class: "ez-col ez-col--sd-12" }, h("slot", { name: "SnkGridFooter" })), h("ez-modal", { modalSize: "small", closeEsc: false, closeOutsideClick: false, opened: this._popUpGridConfig, onEzCloseModal: () => this.closeGridConfig() }, h("snk-grid-config", { ref: ref => this._snkGridConfig = ref, config: this._gridConfig, "data-element-id": this._element.getAttribute(ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME), application: this._application, selectedIndex: 0, configName: this.configName, onConfigChange: (evt) => this.modalConfigChangeHandler(evt), onConfigCancel: () => this.closeGridConfig(), resourceID: this.resourceID }))));
313
322
  }
314
323
  static get is() { return "snk-grid"; }
315
324
  static get encapsulation() { return "scoped"; }
@@ -329,11 +338,12 @@ export class SnkGrid {
329
338
  "type": "unknown",
330
339
  "mutable": true,
331
340
  "complexType": {
332
- "original": "SnkMultiSelectionListDataSource",
333
- "resolved": "SnkMultiSelectionListDataSource",
341
+ "original": "IMultiSelectionListDataSource",
342
+ "resolved": "IMultiSelectionListDataSource",
334
343
  "references": {
335
- "SnkMultiSelectionListDataSource": {
336
- "location": "global"
344
+ "IMultiSelectionListDataSource": {
345
+ "location": "import",
346
+ "path": "@sankhyalabs/ezui/dist/types/components/ez-multi-selection-list/interfaces/IMultiSelectionListDataSource"
337
347
  }
338
348
  }
339
349
  },
@@ -72,7 +72,7 @@ export class SnkPersonalizedFilter {
72
72
  }
73
73
  ConfigStorage.loadPersonalizedFilter(newValue, this.resourceID, this.configName)
74
74
  .then((resp) => {
75
- const personalizedFilter = this.addLabelToItems(resp);
75
+ const personalizedFilter = this.applyDefaultValues(resp);
76
76
  this._filterAssistent = personalizedFilter;
77
77
  this._originalFilterAssistent = ObjectUtils.copy(personalizedFilter);
78
78
  this._filterAssistentMode = this._filterAssistent.hasOwnProperty("assistent") && this._filterAssistent.assistent != undefined;
@@ -183,20 +183,30 @@ export class SnkPersonalizedFilter {
183
183
  this._filterAssistent = Object.assign(Object.assign({}, this._filterAssistent), { name });
184
184
  this._elButtonSave.enabled = !this.hasChangesToSave();
185
185
  }
186
- addLabelToItems(resp) {
186
+ applyDefaultValues(personalizedFilter) {
187
+ this.addLabelToItems(personalizedFilter);
188
+ this.addFilterGroupCondition(personalizedFilter);
189
+ return personalizedFilter;
190
+ }
191
+ addFilterGroupCondition(personalizedFilter) {
192
+ if (!personalizedFilter.assistent.operand) {
193
+ personalizedFilter.assistent.operand = FilterGroupCondition.AND;
194
+ }
195
+ }
196
+ ;
197
+ addLabelToItems(personalizedFilter) {
187
198
  //Workaround: Alguns filtros foram salvos sem o fieldLabel. Para evitar transtornos
188
199
  //tentamos usar o fieldLabel que pode estar informado no parametro.
189
- if (resp.assistent && resp.assistent.items && resp.assistent.items.length > 0) {
190
- resp.assistent.items.forEach(item => {
200
+ if (personalizedFilter.assistent && personalizedFilter.assistent.items && personalizedFilter.assistent.items.length > 0) {
201
+ personalizedFilter.assistent.items.forEach(item => {
191
202
  if (item.fieldLabel == undefined) {
192
- const param = (resp.parameters || []).find(param => param.fieldName === item.fieldName);
203
+ const param = (personalizedFilter.parameters || []).find(param => param.fieldName === item.fieldName);
193
204
  if (param) {
194
205
  item.fieldLabel = param.label;
195
206
  }
196
207
  }
197
208
  });
198
209
  }
199
- return resp;
200
210
  }
201
211
  handleExpressionChangeAdvancedMode(expression) {
202
212
  this._filterAssistent = Object.assign(Object.assign({}, this._filterAssistent), { expression });
@@ -1,8 +1,8 @@
1
- import { ChangeOperation, DataUnit, defaultDataLoader, StringUtils, } from '@sankhyalabs/core';
1
+ import { ChangeOperation, DataType, DataUnit, DateUtils, defaultDataLoader, StringUtils, } from '@sankhyalabs/core';
2
2
  export default class InMemoryLoader {
3
3
  constructor(metadata, records) {
4
- this.records = records;
5
4
  this.metadata = metadata;
5
+ this.records = records;
6
6
  this._dataUnit = new DataUnit(InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME);
7
7
  this._dataUnit.metadataLoader = () => this.metadaLoader();
8
8
  this._dataUnit.dataLoader = (dataUnit, request) => defaultDataLoader(dataUnit, request, this.getRecordsToLoad());
@@ -27,11 +27,32 @@ export default class InMemoryLoader {
27
27
  get records() {
28
28
  return this.dataUnit.records;
29
29
  }
30
+ static getConvertedValue(descriptor, strValue) {
31
+ if (descriptor.dataType === DataType.BOOLEAN) {
32
+ return strValue === "S";
33
+ }
34
+ if (descriptor.dataType === DataType.NUMBER) {
35
+ return Number(strValue);
36
+ }
37
+ if (descriptor.dataType === DataType.DATE) {
38
+ return DateUtils.strToDate(strValue, true);
39
+ }
40
+ return strValue;
41
+ }
30
42
  set records(records) {
43
+ const columns = this._metadata ? new Map(this._metadata.fields.map(descriptor => [descriptor.name, descriptor])) : undefined;
31
44
  const newRecords = records === null || records === void 0 ? void 0 : records.map(record => {
32
45
  if (!record["__record__id__"]) {
33
46
  record["__record__id__"] = this.generateUniqueId();
34
47
  }
48
+ if (columns != undefined) {
49
+ for (const name in record) {
50
+ const value = record[name];
51
+ if (typeof value === "string" && columns.has(name)) {
52
+ record[name] = InMemoryLoader.getConvertedValue(columns.get(name), value);
53
+ }
54
+ }
55
+ }
35
56
  return record;
36
57
  });
37
58
  if (this._dataUnit) {
@@ -34,9 +34,14 @@ export class DataFetcher {
34
34
  }
35
35
  }
36
36
  this.instance.application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
37
- this.instance.graphqlPath = `/${this.instance.application.getModuleName()}/graphql`;
38
37
  return this.instance;
39
38
  }
39
+ static getGraphQLPath() {
40
+ if (StringUtils.isEmpty(this.instance.graphqlPath) && this.instance.application != undefined) {
41
+ this.instance.graphqlPath = `/${this.instance.application.getModuleName()}/graphql`;
42
+ }
43
+ return this.instance.graphqlPath;
44
+ }
40
45
  static addRequestListener(listener) {
41
46
  const index = DataFetcher.requestListener.indexOf(listener);
42
47
  if (index < 0) {
@@ -86,7 +91,7 @@ export class DataFetcher {
86
91
  }
87
92
  return new ErrorException(title, statusMessage, tsErrorCode);
88
93
  }
89
- async callGraphQL(req) {
94
+ async callGraphQL(req, quietMode = false) {
90
95
  var _a;
91
96
  if (this.ready) {
92
97
  this.pause();
@@ -104,7 +109,7 @@ export class DataFetcher {
104
109
  if (this.ready) {
105
110
  return new Promise(async (resolve, reject) => {
106
111
  let query = this.getQueryTemplate(req);
107
- const res = await this.fecthGrapql([{ document: query, variables: req.values }]);
112
+ const res = await this.fecthGrapql([{ document: query, variables: req.values }], quietMode);
108
113
  if (res.errors.length > 0) {
109
114
  if (!this.proccesGraphQLClientEvents(res === null || res === void 0 ? void 0 : res.extensions, req, resolve, reject)) {
110
115
  const error = this.processGraphQlErrorInfo(res.errors);
@@ -119,7 +124,7 @@ export class DataFetcher {
119
124
  }
120
125
  else {
121
126
  if (!this.watingRequestsById.has(reqKey)) {
122
- this.watingRequestsById.set(reqKey, new WaitingRequest(req));
127
+ this.watingRequestsById.set(reqKey, new WaitingRequest(req, quietMode));
123
128
  }
124
129
  return (_a = this.watingRequestsById.get(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
125
130
  }
@@ -347,14 +352,16 @@ export class DataFetcher {
347
352
  }
348
353
  async executePendingRequest(watingRequestsById) {
349
354
  const requestsBatch = [];
355
+ let quietMode = true;
350
356
  watingRequestsById.forEach(async (waitingReq) => {
351
357
  let query = this.getQueryTemplate(waitingReq.request);
352
358
  requestsBatch.push({ document: query, variables: Object.assign({}, waitingReq.request.values) });
359
+ quietMode = quietMode && waitingReq.quietMode;
353
360
  });
354
361
  let res = undefined;
355
362
  let dataResponse = [];
356
363
  let errorsResponse = [];
357
- res = await this.fecthGrapql(requestsBatch);
364
+ res = await this.fecthGrapql(requestsBatch, quietMode);
358
365
  dataResponse = res.data;
359
366
  errorsResponse = res.errors;
360
367
  //Reject promises with errors from query
@@ -372,14 +379,18 @@ export class DataFetcher {
372
379
  });
373
380
  });
374
381
  }
375
- async fecthGrapql(request) {
382
+ async fecthGrapql(request, quietMode) {
376
383
  let res = undefined;
377
384
  let dataResponse = [];
378
385
  let errorsResponse = [];
379
- let url = `${this.resolveURL() + this.graphqlPath}`;
386
+ let url = `${this.resolveURL() + DataFetcher.getGraphQLPath()}`;
380
387
  const responseExtensions = [];
381
- if (window['mgeSession']) {
382
- url += `?mgeSession=${window['mgeSession']}`;
388
+ const mgeSession = window["mgeSession"];
389
+ if (mgeSession != undefined) {
390
+ url += `?mgeSession=${mgeSession}`;
391
+ }
392
+ if (quietMode) {
393
+ url += `${url.indexOf("?") > -1 ? "&" : "?"}quietMode=true`;
383
394
  }
384
395
  DataFetcher.requestListener.forEach(listener => listener.onRequestStart({ url: url, requestBody: request }));
385
396
  try {
@@ -465,7 +476,7 @@ DataFetcher.SERVICE_BROKER_STATUS = {
465
476
  };
466
477
  DataFetcher.clientEventsByID = new Map();
467
478
  class WaitingRequest {
468
- constructor(req) {
479
+ constructor(req, quietMode) {
469
480
  this._resolve = () => { };
470
481
  this._reject = () => { };
471
482
  this._request = undefined;
@@ -474,6 +485,7 @@ class WaitingRequest {
474
485
  this._resolve = resolve;
475
486
  this._reject = reject;
476
487
  });
488
+ this._quietMode = quietMode;
477
489
  }
478
490
  get resolve() {
479
491
  return this._resolve;
@@ -487,4 +499,7 @@ class WaitingRequest {
487
499
  get request() {
488
500
  return this._request;
489
501
  }
502
+ get quietMode() {
503
+ return this._quietMode;
504
+ }
490
505
  }
@@ -0,0 +1,113 @@
1
+ import PreloadManager from "./cache/PreloadManager";
2
+ import { DatasetStrategy } from "./loadstrategy/DatasetStrategy";
3
+ export default class DataUnitDataLoader {
4
+ static async debounce(dataUnit, callBack) {
5
+ const duName = dataUnit.name;
6
+ if (DataUnitDataLoader._debouncingTimeouts[duName]) {
7
+ clearTimeout(DataUnitDataLoader._debouncingTimeouts[duName]);
8
+ delete DataUnitDataLoader._debouncingTimeouts[duName];
9
+ }
10
+ DataUnitDataLoader._debouncingTimeouts[duName] = setTimeout(() => {
11
+ delete DataUnitDataLoader._debouncingTimeouts[duName];
12
+ callBack();
13
+ }, 100);
14
+ }
15
+ static async loadData(dataUnit, request) {
16
+ return new Promise((resolve, reject) => {
17
+ DataUnitDataLoader.debounce(dataUnit, () => {
18
+ PreloadManager.loadData(dataUnit, request, this.loadFromServer)
19
+ .then(resp => resolve(resp))
20
+ .catch(reason => reject(reason));
21
+ });
22
+ });
23
+ }
24
+ static async loadFromServer(dataUnit, request, loadingInfo) {
25
+ try {
26
+ //Registramos a request com as informações de carga para determinarmos a última.
27
+ //Caso o usuário inicie outro refresh antes de terminar, devemos ignorar o resultado.
28
+ loadingInfo = DataUnitDataLoader.registryLoading(dataUnit, loadingInfo);
29
+ const loadResult = await DataUnitDataLoader.callLoader(dataUnit, request, loadingInfo);
30
+ if (loadResult == undefined) {
31
+ //Essa request foi originada de refresh antigo. Será ignorada;
32
+ return;
33
+ }
34
+ const loadedRecords = loadResult.records;
35
+ const paginationInfo = DataUnitDataLoader.buildPaginationInfo(loadedRecords.length, request, loadResult.loadingInfo);
36
+ const records = paginationInfo == undefined ? loadedRecords : loadedRecords.slice(0, paginationInfo.lastRecord);
37
+ return Promise.resolve({ records, paginationInfo });
38
+ }
39
+ catch (error) {
40
+ console.error(error);
41
+ return Promise.reject(error);
42
+ }
43
+ }
44
+ static async callLoader(dataUnit, request, requestLoadingInfo, dataLoader) {
45
+ if (dataLoader == undefined) {
46
+ //dataLoader = new DataUnitStrategy();
47
+ dataLoader = new DatasetStrategy();
48
+ }
49
+ const result = await dataLoader.load(dataUnit, request, requestLoadingInfo);
50
+ const { records, loadingInfo: responseLoadingInfo } = result;
51
+ if (DataUnitDataLoader.isOldRequest(dataUnit, responseLoadingInfo)) {
52
+ return Promise.resolve(undefined);
53
+ }
54
+ const recreateCache = !dataLoader.canSlice() || responseLoadingInfo.count === 0;
55
+ PreloadManager.cacheRecords(dataUnit, records, recreateCache, responseLoadingInfo.loadingInProgress);
56
+ if (PreloadManager.isCacheEnabled(dataUnit) && responseLoadingInfo.loadingInProgress) {
57
+ const newRequest = Object.assign(Object.assign({}, request), { offset: responseLoadingInfo.count });
58
+ const newLoadingInfo = Object.assign(Object.assign({}, responseLoadingInfo), { pageNumber: (responseLoadingInfo.pageNumber || 0) + 1 });
59
+ this.callLoader(dataUnit, newRequest, newLoadingInfo, dataLoader)
60
+ .then(result => DataUnitDataLoader.afterLoadingPage(dataUnit, result.loadingInfo))
61
+ .catch(reason => console.error(reason));
62
+ }
63
+ return Promise.resolve(result);
64
+ }
65
+ static afterLoadingPage(dataUnit, loadingInfo) {
66
+ PreloadManager.setLoadingStatus(dataUnit, loadingInfo.loadingInProgress);
67
+ const dataUnitPagination = dataUnit.getPaginationInfo();
68
+ if (dataUnitPagination == undefined) {
69
+ return;
70
+ }
71
+ const count = loadingInfo.count;
72
+ if (loadingInfo.loadingInProgress) {
73
+ dataUnit.updatePagination(Object.assign(Object.assign({}, dataUnitPagination), { count }));
74
+ return;
75
+ }
76
+ dataUnit.updatePagination(Object.assign(Object.assign({}, dataUnitPagination), { total: count, count }));
77
+ }
78
+ static registryLoading(dataUnit, loadingInfo) {
79
+ if (loadingInfo == undefined) {
80
+ loadingInfo = { requestTime: new Date().getTime(), count: 0 };
81
+ }
82
+ DataUnitDataLoader._requestTimeByDataUnit.set(dataUnit.name, loadingInfo.requestTime);
83
+ return loadingInfo;
84
+ }
85
+ static isOldRequest(dataUnit, loadingInfo) {
86
+ return DataUnitDataLoader._requestTimeByDataUnit.get(dataUnit.name) > loadingInfo.requestTime;
87
+ }
88
+ static buildPaginationInfo(pageSize, request, loadingInfo) {
89
+ let { limit, offset } = request;
90
+ if (!limit) {
91
+ return undefined;
92
+ }
93
+ if (loadingInfo.pageNumber === 1) {
94
+ // Quando o loader não é capaz de fatiar os registros
95
+ // ele pode decidir por uma carga completa, o que faz o
96
+ // controle de paginação voltar pra primeira página.
97
+ offset = 0;
98
+ }
99
+ const { total, count, loadingInProgress } = loadingInfo;
100
+ const firstRecord = count === 0 ? 0 : offset + 1;
101
+ const lastRecord = offset + Math.min(pageSize, limit);
102
+ return {
103
+ total,
104
+ count,
105
+ lastRecord,
106
+ firstRecord,
107
+ currentPage: offset / limit,
108
+ hasMore: lastRecord < count || loadingInProgress
109
+ };
110
+ }
111
+ }
112
+ DataUnitDataLoader._requestTimeByDataUnit = new Map();
113
+ DataUnitDataLoader._debouncingTimeouts = {};