@sankhyalabs/sankhyablocks 8.6.0-dev.3 → 8.6.0-dev.5
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-56db34ee.js} +11 -0
- package/dist/cjs/{auth-fetcher-92f3040b.js → auth-fetcher-78231356.js} +1 -1
- package/dist/cjs/dataunit-fetcher-4f7d4ee7.js +878 -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 +3 -2
- 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-aab80f66.js} +5 -4
- package/dist/cjs/snk-guides-viewer.cjs.entry.js +8 -6
- package/dist/cjs/snk-personalized-filter.cjs.entry.js +3 -3
- 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 +1 -1
- 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/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 +59 -0
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.js +169 -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 +781 -100
- package/dist/components/snk-actions-button2.js +1 -1
- package/dist/components/snk-application2.js +11 -4
- 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-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-b9410c72.js} +11 -0
- package/dist/esm/{auth-fetcher-5c3ae75b.js → auth-fetcher-a8c8ee7e.js} +1 -1
- package/dist/esm/dataunit-fetcher-1c2ccae2.js +874 -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 +3 -2
- 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-62b0fa69.js} +5 -4
- package/dist/esm/snk-guides-viewer.entry.js +8 -6
- package/dist/esm/snk-personalized-filter.entry.js +3 -3
- package/dist/esm/snk-simple-crud.entry.js +7 -91
- package/dist/sankhyablocks/p-193971ad.js +1 -0
- package/dist/sankhyablocks/{p-54f01129.entry.js → p-19cbe6e2.entry.js} +3 -3
- package/dist/sankhyablocks/{p-ee57d9f5.js → p-240f5892.js} +1 -1
- package/dist/sankhyablocks/p-2c7c1323.entry.js +1 -0
- package/dist/sankhyablocks/p-3253e7f2.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-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-acb1374c.entry.js +1 -0
- package/dist/sankhyablocks/p-b36053da.entry.js +1 -0
- package/dist/sankhyablocks/p-b481e5ad.js +1 -0
- package/dist/sankhyablocks/p-d264da22.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-d56b65e3.entry.js +1 -0
- package/dist/sankhyablocks/p-e473ca13.entry.js +1 -0
- package/dist/sankhyablocks/{p-6cd36947.entry.js → p-e74e2153.entry.js} +1 -1
- package/dist/sankhyablocks/p-e86d4a53.js +59 -0
- package/dist/sankhyablocks/{p-b417c608.entry.js → p-e8b55571.entry.js} +1 -1
- 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-grid/filtercolumn/SnkMultiSelectionListDataSource.d.ts +1 -0
- package/dist/types/components/snk-grid/snk-grid.d.ts +3 -4
- 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-016a1733.entry.js +0 -1
- package/dist/sankhyablocks/p-0abc880c.entry.js +0 -1
- package/dist/sankhyablocks/p-1284f14a.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-fa9d3f73.js +0 -1
@@ -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
|
},
|
@@ -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 ? 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 = {};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
export class ArrayRepository {
|
2
|
+
constructor(equalsFunction) {
|
3
|
+
this._list = [];
|
4
|
+
this._equalsFunction = equalsFunction;
|
5
|
+
}
|
6
|
+
async load(filterFunction, sortingFunction, offset, limit) {
|
7
|
+
let result = [].concat(this._list);
|
8
|
+
if (filterFunction != undefined) {
|
9
|
+
result = this._list.filter(item => filterFunction(item));
|
10
|
+
}
|
11
|
+
if (sortingFunction != undefined) {
|
12
|
+
result = result.sort(sortingFunction);
|
13
|
+
}
|
14
|
+
const count = result.length;
|
15
|
+
if (limit != undefined) {
|
16
|
+
const start = offset || 0;
|
17
|
+
const end = limit ? start + limit : result.length;
|
18
|
+
result = result.slice(start, end);
|
19
|
+
}
|
20
|
+
return Promise.resolve({ result, count });
|
21
|
+
}
|
22
|
+
async distict(itemProcessor) {
|
23
|
+
const processedItems = this._list.map(item => itemProcessor(item));
|
24
|
+
return Promise.resolve(new Map(processedItems.filter(item => item != undefined)
|
25
|
+
.map(item => [item.key, item.value])));
|
26
|
+
}
|
27
|
+
async push(items) {
|
28
|
+
this._list.push(...items);
|
29
|
+
}
|
30
|
+
async clear() {
|
31
|
+
this._list = [];
|
32
|
+
}
|
33
|
+
async delete(items) {
|
34
|
+
this._list = this._list.filter(item => !items.includes(item));
|
35
|
+
}
|
36
|
+
async update(items) {
|
37
|
+
this._list = this._list.map(existingItem => {
|
38
|
+
const newItem = items.find(newItem => this._equalsFunction(existingItem, newItem));
|
39
|
+
return newItem == undefined ? existingItem : newItem;
|
40
|
+
});
|
41
|
+
}
|
42
|
+
async insert(itemReference, items) {
|
43
|
+
const itemPosition = this._list.indexOf(itemReference);
|
44
|
+
if (itemPosition == -1) {
|
45
|
+
this._list.push(...items);
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
this._list = this._list.slice(0, itemPosition).concat(items).concat(this._list.slice(itemPosition));
|
49
|
+
}
|
50
|
+
isOperating() {
|
51
|
+
return true;
|
52
|
+
}
|
53
|
+
async isEmpty() {
|
54
|
+
return Promise.resolve(this._list.length === 0);
|
55
|
+
}
|
56
|
+
async count() {
|
57
|
+
return Promise.resolve(this._list.length);
|
58
|
+
}
|
59
|
+
}
|
@@ -0,0 +1,169 @@
|
|
1
|
+
import { DataUnit, FieldComparator, SortMode } from "@sankhyalabs/core";
|
2
|
+
import DataUnitFetcher from "../dataunit-fetcher";
|
3
|
+
import { ArrayRepository } from "./ArrayRepository";
|
4
|
+
const COLUMN_FILTER_PATTERN = /FILTRO_COLUNA_(.+)/;
|
5
|
+
export default class PreloadManager {
|
6
|
+
static setLoadingStatus(dataUnit, loadingInProgress) {
|
7
|
+
this._loadingStatus.set(dataUnit.name, loadingInProgress);
|
8
|
+
}
|
9
|
+
static isCacheEnabled(dataUnit) {
|
10
|
+
const dataUnitResourceId = PreloadManager.getResourceId(dataUnit.name);
|
11
|
+
if (dataUnitResourceId !== this.applicationResourceID) {
|
12
|
+
return false;
|
13
|
+
}
|
14
|
+
return this.getRepository(dataUnit).isOperating();
|
15
|
+
}
|
16
|
+
static getResourceId(dataUnitName) {
|
17
|
+
const dataUnitNameInfo = DataUnitFetcher.parseDataUnitName(dataUnitName);
|
18
|
+
return dataUnitNameInfo == undefined ? undefined : dataUnitNameInfo.resourceID;
|
19
|
+
}
|
20
|
+
static cacheRecords(dataUnit, records, resetDatabase, loadingInProgress) {
|
21
|
+
PreloadManager.setLoadingStatus(dataUnit, loadingInProgress);
|
22
|
+
if (PreloadManager.isCacheEnabled(dataUnit)) {
|
23
|
+
this.getRepository(dataUnit).push(records);
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
if (resetDatabase) {
|
27
|
+
this._repositories.delete(dataUnit.name);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
static getSortingFunction(dataUnit, sorting) {
|
32
|
+
if (sorting == undefined || sorting.length == 0) {
|
33
|
+
return undefined;
|
34
|
+
}
|
35
|
+
return (recordA, recordB) => {
|
36
|
+
for (const sort of sorting) {
|
37
|
+
const result = FieldComparator.compare(dataUnit.getField(sort.field), recordA, recordB, sort.mode === SortMode.ASC);
|
38
|
+
if (result != 0) {
|
39
|
+
return result;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
};
|
43
|
+
}
|
44
|
+
static async getDistinct(dataUnit, fieldName) {
|
45
|
+
if (!PreloadManager.isCacheEnabled(dataUnit)) {
|
46
|
+
return Promise.resolve(undefined);
|
47
|
+
}
|
48
|
+
return new Promise((accept, reject) => {
|
49
|
+
PreloadManager.getRepository(dataUnit).distict(record => {
|
50
|
+
const fieldValue = record[fieldName];
|
51
|
+
if (fieldValue == undefined) {
|
52
|
+
return undefined;
|
53
|
+
}
|
54
|
+
const value = fieldValue.value != undefined ? fieldValue.value : fieldValue;
|
55
|
+
return { key: dataUnit.getFormattedValue(fieldName, fieldValue), value };
|
56
|
+
})
|
57
|
+
.then(values => accept(values))
|
58
|
+
.catch(reason => reject(reason));
|
59
|
+
});
|
60
|
+
}
|
61
|
+
static async loadData(dataUnit, request, loadFromServer) {
|
62
|
+
try {
|
63
|
+
if (PreloadManager.isCacheEnabled(dataUnit)) {
|
64
|
+
let useCache = request.source === "EZ_GRID_LOADING_SOURCE" || request.source === DataUnit.CHANGING_PAGE_LOADING_SOURCE;
|
65
|
+
if (useCache) {
|
66
|
+
const isCacheEmpty = await PreloadManager.getRepository(dataUnit).isEmpty();
|
67
|
+
if (!isCacheEmpty) {
|
68
|
+
return PreloadManager.loadFromCache(dataUnit, request);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
//Como não vamos aproveitar o cache, ele precisa ser limpado.
|
72
|
+
PreloadManager.getRepository(dataUnit).clear().catch(() => { });
|
73
|
+
}
|
74
|
+
return loadFromServer(dataUnit, request);
|
75
|
+
}
|
76
|
+
catch (error) {
|
77
|
+
console.error(error);
|
78
|
+
return Promise.reject(error);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
static insertRecords(dataUnit, reference, records) {
|
82
|
+
if (PreloadManager.isCacheEnabled(dataUnit)) {
|
83
|
+
PreloadManager.getRepository(dataUnit).insert(reference, records);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
static updateRecords(dataUnit, records) {
|
87
|
+
if (PreloadManager.isCacheEnabled(dataUnit)) {
|
88
|
+
PreloadManager.getRepository(dataUnit).update(records);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
static removeRecords(dataUnit, records) {
|
92
|
+
if (PreloadManager.isCacheEnabled(dataUnit)) {
|
93
|
+
PreloadManager.getRepository(dataUnit).delete(records);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
static async countRecords(dataUnit) {
|
97
|
+
if (PreloadManager.isCacheEnabled(dataUnit)) {
|
98
|
+
return PreloadManager.getRepository(dataUnit).count();
|
99
|
+
}
|
100
|
+
return Promise.resolve(0);
|
101
|
+
}
|
102
|
+
static getRepository(dataUnit) {
|
103
|
+
const name = dataUnit.name;
|
104
|
+
if (!PreloadManager._repositories.has(name)) {
|
105
|
+
PreloadManager._repositories.set(name, new ArrayRepository((recordA, recordB) => recordA.__record__id__ === recordB.__record__id__));
|
106
|
+
}
|
107
|
+
return PreloadManager._repositories.get(name);
|
108
|
+
}
|
109
|
+
static getFilterFunction(dataUnit, filters) {
|
110
|
+
if (filters != undefined && filters.length > 0) {
|
111
|
+
return record => {
|
112
|
+
for (const filter of filters) {
|
113
|
+
if (!PreloadManager.recordMatchesFilter(dataUnit, record, filter)) {
|
114
|
+
return false;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
return true;
|
118
|
+
};
|
119
|
+
}
|
120
|
+
return undefined;
|
121
|
+
}
|
122
|
+
static recordMatchesFilter(dataUnit, record, columnFilter) {
|
123
|
+
const fieldValue = record[columnFilter.columnName];
|
124
|
+
for (let param of columnFilter.params) {
|
125
|
+
const paramValue = dataUnit.valueFromString(columnFilter.columnName, param.value);
|
126
|
+
if (FieldComparator.compareValues(dataUnit.getField(columnFilter.columnName), fieldValue, paramValue) === 0) {
|
127
|
+
return true;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
return false;
|
131
|
+
}
|
132
|
+
static async loadFromCache(dataUnit, request) {
|
133
|
+
return new Promise((accept, reject) => {
|
134
|
+
const columnFilters = PreloadManager.getColumnFilters(request.filters);
|
135
|
+
const { limit, offset, sort } = request;
|
136
|
+
PreloadManager.getRepository(dataUnit)
|
137
|
+
.load(PreloadManager.getFilterFunction(dataUnit, Array.from(columnFilters.values())), PreloadManager.getSortingFunction(dataUnit, sort), offset, limit)
|
138
|
+
.then(loadResult => {
|
139
|
+
const stillLoading = PreloadManager._loadingStatus.get(dataUnit.name);
|
140
|
+
const { count, result: records } = loadResult;
|
141
|
+
const firstRecord = count == 0 ? 1 : offset + 1;
|
142
|
+
const lastRecord = offset + Math.min(records.length, limit);
|
143
|
+
const currentPage = offset / limit;
|
144
|
+
const paginationInfo = {
|
145
|
+
count, currentPage, firstRecord, lastRecord,
|
146
|
+
hasMore: stillLoading || (lastRecord < count),
|
147
|
+
total: stillLoading ? undefined : count
|
148
|
+
};
|
149
|
+
accept({ records, paginationInfo });
|
150
|
+
})
|
151
|
+
.catch(reason => reject(reason));
|
152
|
+
});
|
153
|
+
}
|
154
|
+
static getColumnFilters(filters) {
|
155
|
+
const columnFilters = new Map();
|
156
|
+
if (filters == undefined || filters.length == 0) {
|
157
|
+
return columnFilters;
|
158
|
+
}
|
159
|
+
filters.forEach(filter => {
|
160
|
+
const match = COLUMN_FILTER_PATTERN.exec(filter.name);
|
161
|
+
if (match) {
|
162
|
+
columnFilters.set(filter.name, Object.assign({ columnName: match[1] }, filter));
|
163
|
+
}
|
164
|
+
});
|
165
|
+
return columnFilters;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
PreloadManager._repositories = new Map();
|
169
|
+
PreloadManager._loadingStatus = new Map();
|