@sankhyalabs/sankhyablocks 8.7.0 → 8.8.0-dev.2
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/cjs/{ConfigStorage-1097ff27.js → ConfigStorage-a97ca159.js} +2 -2
- package/dist/cjs/{DataFetcher-a00bc007.js → DataFetcher-2a99283c.js} +19 -10
- package/dist/cjs/{SnkFormConfigManager-a4b4d852.js → SnkFormConfigManager-f641f502.js} +2 -2
- package/dist/cjs/{SnkMultiSelectionListDataSource-804ff4c7.js → SnkMultiSelectionListDataSource-4e3de426.js} +11 -0
- package/dist/cjs/{auth-fetcher-92f3040b.js → auth-fetcher-78231356.js} +1 -1
- package/dist/cjs/dataunit-fetcher-a4e8352b.js +906 -0
- package/dist/cjs/{form-config-fetcher-60fbeb94.js → form-config-fetcher-a322a522.js} +1 -1
- package/dist/cjs/{pesquisa-fetcher-b2ed9767.js → pesquisa-fetcher-7ef61508.js} +1 -1
- package/dist/cjs/snk-actions-button.cjs.entry.js +4 -3
- package/dist/cjs/snk-application.cjs.entry.js +17 -8
- package/dist/cjs/snk-attach.cjs.entry.js +16 -3
- package/dist/cjs/snk-crud.cjs.entry.js +6 -4
- package/dist/cjs/snk-data-exporter.cjs.entry.js +1 -1
- package/dist/cjs/snk-detail-view.cjs.entry.js +8 -6
- package/dist/cjs/snk-filter-bar.cjs.entry.js +3 -3
- package/dist/cjs/snk-filter-modal-item.cjs.entry.js +3 -3
- package/dist/cjs/snk-form-config.cjs.entry.js +2 -2
- package/dist/cjs/snk-form.cjs.entry.js +4 -4
- package/dist/cjs/snk-grid-config.cjs.entry.js +3 -3
- package/dist/cjs/snk-grid.cjs.entry.js +25 -14
- package/dist/cjs/{snk-guides-viewer-eab0ec84.js → snk-guides-viewer-c540f4c5.js} +5 -4
- package/dist/cjs/snk-guides-viewer.cjs.entry.js +8 -6
- package/dist/cjs/snk-personalized-filter.cjs.entry.js +19 -9
- package/dist/cjs/snk-simple-crud.cjs.entry.js +8 -92
- package/dist/collection/components/snk-application/snk-application.js +11 -3
- package/dist/collection/components/snk-attach/snk-attach.js +14 -2
- package/dist/collection/components/snk-grid/filtercolumn/SnkMultiSelectionListDataSource.js +11 -0
- package/dist/collection/components/snk-grid/snk-grid.js +24 -14
- package/dist/collection/components/snk-personalized-filter/snk-personalized-filter.js +16 -6
- package/dist/collection/lib/dataUnit/InMemoryLoader.js +23 -2
- package/dist/collection/lib/http/data-fetcher/DataFetcher.js +19 -10
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.js +113 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/ArrayRepository.js +77 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.js +179 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/{dataunit-fetcher.js → data-unit/dataunit-fetcher.js} +48 -100
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataResult.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataStrategy.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadingInfo.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRecordField.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IResponseRecord.js +1 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DataUnitStrategy.js +68 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.js +131 -0
- package/dist/collection/lib/index.js +1 -1
- package/dist/components/DataFetcher.js +19 -10
- package/dist/components/SnkMultiSelectionListDataSource.js +11 -0
- package/dist/components/dataunit-fetcher.js +809 -100
- package/dist/components/snk-actions-button2.js +1 -1
- package/dist/components/snk-application2.js +11 -4
- package/dist/components/snk-attach2.js +13 -1
- package/dist/components/snk-crud.js +1 -1
- package/dist/components/snk-detail-view2.js +1 -1
- package/dist/components/snk-grid2.js +19 -11
- package/dist/components/snk-personalized-filter2.js +16 -6
- package/dist/components/snk-simple-crud2.js +2 -88
- package/dist/esm/{ConfigStorage-4d30a649.js → ConfigStorage-26f89143.js} +2 -2
- package/dist/esm/{DataFetcher-487d6aad.js → DataFetcher-90e91631.js} +19 -10
- package/dist/esm/{SnkFormConfigManager-da594f63.js → SnkFormConfigManager-18948123.js} +2 -2
- package/dist/esm/{SnkMultiSelectionListDataSource-892f37f9.js → SnkMultiSelectionListDataSource-36887f31.js} +11 -0
- package/dist/esm/{auth-fetcher-5c3ae75b.js → auth-fetcher-a8c8ee7e.js} +1 -1
- package/dist/esm/dataunit-fetcher-c22b889c.js +902 -0
- package/dist/esm/{form-config-fetcher-cd3fa459.js → form-config-fetcher-7c3b6273.js} +1 -1
- package/dist/{components/pesquisa-fetcher.js → esm/pesquisa-fetcher-90d6853b.js} +1 -1
- package/dist/esm/snk-actions-button.entry.js +4 -3
- package/dist/esm/snk-application.entry.js +17 -8
- package/dist/esm/snk-attach.entry.js +16 -3
- package/dist/esm/snk-crud.entry.js +6 -4
- package/dist/esm/snk-data-exporter.entry.js +1 -1
- package/dist/esm/snk-detail-view.entry.js +8 -6
- package/dist/esm/snk-filter-bar.entry.js +3 -3
- package/dist/esm/snk-filter-modal-item.entry.js +3 -3
- package/dist/esm/snk-form-config.entry.js +2 -2
- package/dist/esm/snk-form.entry.js +4 -4
- package/dist/esm/snk-grid-config.entry.js +3 -3
- package/dist/esm/snk-grid.entry.js +26 -15
- package/dist/esm/{snk-guides-viewer-cff5e95d.js → snk-guides-viewer-e87b77d5.js} +5 -4
- package/dist/esm/snk-guides-viewer.entry.js +8 -6
- package/dist/esm/snk-personalized-filter.entry.js +19 -9
- package/dist/esm/snk-simple-crud.entry.js +7 -91
- package/dist/sankhyablocks/p-182246c9.entry.js +1 -0
- package/dist/sankhyablocks/{p-ee57d9f5.js → p-240f5892.js} +1 -1
- package/dist/sankhyablocks/p-42de2707.entry.js +1 -0
- package/dist/sankhyablocks/p-5356efdd.entry.js +1 -0
- package/dist/sankhyablocks/{p-c9fa27ce.entry.js → p-57550ddc.entry.js} +1 -1
- package/dist/sankhyablocks/{p-e2160bdd.js → p-5d51bff4.js} +1 -1
- package/dist/sankhyablocks/{p-ebd9f2b1.entry.js → p-5dd52ec5.entry.js} +1 -1
- package/dist/sankhyablocks/p-6541f0df.js +1 -0
- package/dist/sankhyablocks/p-68fbd480.entry.js +1 -0
- package/dist/sankhyablocks/{p-5e5816ed.entry.js → p-8652f90b.entry.js} +1 -1
- package/dist/sankhyablocks/{p-358e8f7b.js → p-910af03c.js} +1 -1
- package/dist/sankhyablocks/p-992a9d0f.js +1 -0
- package/dist/sankhyablocks/p-9e705c91.entry.js +1 -0
- package/dist/sankhyablocks/p-a046a2e1.js +1 -0
- package/dist/sankhyablocks/p-a221bc67.js +1 -0
- package/dist/sankhyablocks/{p-54f01129.entry.js → p-b3cd0dd1.entry.js} +3 -3
- package/dist/sankhyablocks/p-b7798801.entry.js +1 -0
- package/dist/sankhyablocks/p-bcc2b79d.js +59 -0
- package/dist/sankhyablocks/p-d07651cc.entry.js +1 -0
- package/dist/sankhyablocks/{p-33745612.js → p-d47bbee3.js} +1 -1
- package/dist/sankhyablocks/{p-86d00468.entry.js → p-d563e451.entry.js} +1 -1
- package/dist/sankhyablocks/{p-6cd36947.entry.js → p-e74e2153.entry.js} +1 -1
- package/dist/sankhyablocks/p-eab2c97d.entry.js +1 -0
- package/dist/sankhyablocks/{p-d109914d.entry.js → p-ebfa6460.entry.js} +1 -1
- package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
- package/dist/types/components/snk-application/snk-application.d.ts +1 -1
- package/dist/types/components/snk-attach/snk-attach.d.ts +1 -0
- package/dist/types/components/snk-grid/filtercolumn/SnkMultiSelectionListDataSource.d.ts +1 -0
- package/dist/types/components/snk-grid/snk-grid.d.ts +3 -4
- package/dist/types/components/snk-personalized-filter/snk-personalized-filter.d.ts +3 -1
- package/dist/types/components.d.ts +3 -2
- package/dist/types/lib/dataUnit/InMemoryLoader.d.ts +2 -1
- package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +1 -1
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.d.ts +13 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/cache/ArrayRepository.d.ts +19 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.d.ts +25 -0
- package/dist/types/lib/http/data-fetcher/fetchers/{dataunit-fetcher.d.ts → data-unit/dataunit-fetcher.d.ts} +5 -3
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataResult.d.ts +6 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataStrategy.d.ts +7 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadingInfo.d.ts +8 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRecordField.d.ts +4 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IResponseRecord.d.ts +6 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DataUnitStrategy.d.ts +9 -0
- package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.d.ts +15 -0
- package/dist/types/lib/http/data-fetcher/fetchers/personalized-filter-fetcher.d.ts +1 -1
- package/dist/types/lib/index.d.ts +1 -1
- package/package.json +3 -3
- package/dist/cjs/dataunit-fetcher-32bb845f.js +0 -356
- package/dist/esm/dataunit-fetcher-d3033a06.js +0 -354
- package/dist/esm/pesquisa-fetcher-615da3ca.js +0 -165
- package/dist/sankhyablocks/p-0abc880c.entry.js +0 -1
- package/dist/sankhyablocks/p-1284f14a.entry.js +0 -1
- package/dist/sankhyablocks/p-162161ae.entry.js +0 -1
- package/dist/sankhyablocks/p-329f7520.entry.js +0 -1
- package/dist/sankhyablocks/p-401da0a5.entry.js +0 -1
- package/dist/sankhyablocks/p-5d62a74e.js +0 -1
- package/dist/sankhyablocks/p-5e63571e.entry.js +0 -1
- package/dist/sankhyablocks/p-6b2ee5b5.entry.js +0 -1
- package/dist/sankhyablocks/p-719c246f.js +0 -1
- package/dist/sankhyablocks/p-89b3df4c.js +0 -1
- package/dist/sankhyablocks/p-90946802.js +0 -76
- package/dist/sankhyablocks/p-b417c608.entry.js +0 -1
- 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-
|
10
|
-
require('./pesquisa-fetcher-
|
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-a4e8352b.js');
|
15
16
|
require('./filter-item-type.enum-aa823a00.js');
|
16
|
-
require('./form-config-fetcher-
|
17
|
+
require('./form-config-fetcher-a322a522.js');
|
17
18
|
const taskbarProcessor = require('./taskbar-processor-bce3f499.js');
|
18
|
-
const SnkMultiSelectionListDataSource = require('./SnkMultiSelectionListDataSource-
|
19
|
+
const SnkMultiSelectionListDataSource = require('./SnkMultiSelectionListDataSource-4e3de426.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
|
-
|
2241
|
-
|
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
|
-
|
217
|
-
this._dataUnitLoadLockerResolver = this._dataUnit.addLoadingLocker();
|
229
|
+
this.assertDefaultSorting();
|
218
230
|
this.addElementID();
|
219
|
-
(
|
220
|
-
|
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,
|
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": "
|
333
|
-
"resolved": "
|
341
|
+
"original": "IMultiSelectionListDataSource",
|
342
|
+
"resolved": "IMultiSelectionListDataSource",
|
334
343
|
"references": {
|
335
|
-
"
|
336
|
-
"location": "
|
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.
|
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
|
-
|
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 (
|
190
|
-
|
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 = (
|
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,11 +34,10 @@ 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
|
}
|
40
39
|
static getGraphQLPath() {
|
41
|
-
if (StringUtils.isEmpty(this.instance.graphqlPath)) {
|
40
|
+
if (StringUtils.isEmpty(this.instance.graphqlPath) && this.instance.application != undefined) {
|
42
41
|
this.instance.graphqlPath = `/${this.instance.application.getModuleName()}/graphql`;
|
43
42
|
}
|
44
43
|
return this.instance.graphqlPath;
|
@@ -92,7 +91,7 @@ export class DataFetcher {
|
|
92
91
|
}
|
93
92
|
return new ErrorException(title, statusMessage, tsErrorCode);
|
94
93
|
}
|
95
|
-
async callGraphQL(req) {
|
94
|
+
async callGraphQL(req, quietMode = false) {
|
96
95
|
var _a;
|
97
96
|
if (this.ready) {
|
98
97
|
this.pause();
|
@@ -110,7 +109,7 @@ export class DataFetcher {
|
|
110
109
|
if (this.ready) {
|
111
110
|
return new Promise(async (resolve, reject) => {
|
112
111
|
let query = this.getQueryTemplate(req);
|
113
|
-
const res = await this.fecthGrapql([{ document: query, variables: req.values }]);
|
112
|
+
const res = await this.fecthGrapql([{ document: query, variables: req.values }], quietMode);
|
114
113
|
if (res.errors.length > 0) {
|
115
114
|
if (!this.proccesGraphQLClientEvents(res === null || res === void 0 ? void 0 : res.extensions, req, resolve, reject)) {
|
116
115
|
const error = this.processGraphQlErrorInfo(res.errors);
|
@@ -125,7 +124,7 @@ export class DataFetcher {
|
|
125
124
|
}
|
126
125
|
else {
|
127
126
|
if (!this.watingRequestsById.has(reqKey)) {
|
128
|
-
this.watingRequestsById.set(reqKey, new WaitingRequest(req));
|
127
|
+
this.watingRequestsById.set(reqKey, new WaitingRequest(req, quietMode));
|
129
128
|
}
|
130
129
|
return (_a = this.watingRequestsById.get(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
|
131
130
|
}
|
@@ -353,14 +352,16 @@ export class DataFetcher {
|
|
353
352
|
}
|
354
353
|
async executePendingRequest(watingRequestsById) {
|
355
354
|
const requestsBatch = [];
|
355
|
+
let quietMode = true;
|
356
356
|
watingRequestsById.forEach(async (waitingReq) => {
|
357
357
|
let query = this.getQueryTemplate(waitingReq.request);
|
358
358
|
requestsBatch.push({ document: query, variables: Object.assign({}, waitingReq.request.values) });
|
359
|
+
quietMode = quietMode && waitingReq.quietMode;
|
359
360
|
});
|
360
361
|
let res = undefined;
|
361
362
|
let dataResponse = [];
|
362
363
|
let errorsResponse = [];
|
363
|
-
res = await this.fecthGrapql(requestsBatch);
|
364
|
+
res = await this.fecthGrapql(requestsBatch, quietMode);
|
364
365
|
dataResponse = res.data;
|
365
366
|
errorsResponse = res.errors;
|
366
367
|
//Reject promises with errors from query
|
@@ -378,14 +379,18 @@ export class DataFetcher {
|
|
378
379
|
});
|
379
380
|
});
|
380
381
|
}
|
381
|
-
async fecthGrapql(request) {
|
382
|
+
async fecthGrapql(request, quietMode) {
|
382
383
|
let res = undefined;
|
383
384
|
let dataResponse = [];
|
384
385
|
let errorsResponse = [];
|
385
386
|
let url = `${this.resolveURL() + DataFetcher.getGraphQLPath()}`;
|
386
387
|
const responseExtensions = [];
|
387
|
-
|
388
|
-
|
388
|
+
const mgeSession = window["mgeSession"];
|
389
|
+
if (mgeSession != undefined) {
|
390
|
+
url += `?mgeSession=${mgeSession}`;
|
391
|
+
}
|
392
|
+
if (quietMode) {
|
393
|
+
url += `${url.indexOf("?") > -1 ? "&" : "?"}quietMode=true`;
|
389
394
|
}
|
390
395
|
DataFetcher.requestListener.forEach(listener => listener.onRequestStart({ url: url, requestBody: request }));
|
391
396
|
try {
|
@@ -471,7 +476,7 @@ DataFetcher.SERVICE_BROKER_STATUS = {
|
|
471
476
|
};
|
472
477
|
DataFetcher.clientEventsByID = new Map();
|
473
478
|
class WaitingRequest {
|
474
|
-
constructor(req) {
|
479
|
+
constructor(req, quietMode) {
|
475
480
|
this._resolve = () => { };
|
476
481
|
this._reject = () => { };
|
477
482
|
this._request = undefined;
|
@@ -480,6 +485,7 @@ class WaitingRequest {
|
|
480
485
|
this._resolve = resolve;
|
481
486
|
this._reject = reject;
|
482
487
|
});
|
488
|
+
this._quietMode = quietMode;
|
483
489
|
}
|
484
490
|
get resolve() {
|
485
491
|
return this._resolve;
|
@@ -493,4 +499,7 @@ class WaitingRequest {
|
|
493
499
|
get request() {
|
494
500
|
return this._request;
|
495
501
|
}
|
502
|
+
get quietMode() {
|
503
|
+
return this._quietMode;
|
504
|
+
}
|
496
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 || pageSize === 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 = {};
|