@sankhyalabs/sankhyablocks 8.6.0-dev.2 → 8.6.0-dev.4
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-bbffce76.js → ConfigStorage-a97ca159.js} +2 -2
- package/dist/cjs/{DataFetcher-0cc561bc.js → DataFetcher-2a99283c.js} +25 -10
- package/dist/cjs/{SnkFormConfigManager-c49af777.js → SnkFormConfigManager-f641f502.js} +2 -2
- package/dist/cjs/{SnkMultiSelectionListDataSource-804ff4c7.js → SnkMultiSelectionListDataSource-faf3a0f2.js} +11 -0
- package/dist/cjs/{auth-fetcher-fff2319e.js → auth-fetcher-78231356.js} +1 -1
- package/dist/cjs/dataunit-fetcher-9e875872.js +877 -0
- package/dist/cjs/{form-config-fetcher-35752aad.js → form-config-fetcher-a322a522.js} +1 -1
- package/dist/cjs/{pesquisa-fetcher-415eab63.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-36b39c9c.js → snk-guides-viewer-015b8632.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 +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/lib/dataUnit/InMemoryLoader.js +23 -2
- package/dist/collection/lib/http/data-fetcher/DataFetcher.js +25 -10
- package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.js +112 -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 +26 -11
- package/dist/components/SnkMultiSelectionListDataSource.js +11 -0
- package/dist/components/dataunit-fetcher.js +780 -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-simple-crud2.js +2 -88
- package/dist/esm/{ConfigStorage-80ca14d5.js → ConfigStorage-26f89143.js} +2 -2
- package/dist/esm/{DataFetcher-044e3988.js → DataFetcher-90e91631.js} +26 -11
- package/dist/esm/{SnkFormConfigManager-1a8b3a44.js → SnkFormConfigManager-18948123.js} +2 -2
- package/dist/esm/{SnkMultiSelectionListDataSource-892f37f9.js → SnkMultiSelectionListDataSource-9e916004.js} +11 -0
- package/dist/esm/{auth-fetcher-1b378f8e.js → auth-fetcher-a8c8ee7e.js} +1 -1
- package/dist/esm/dataunit-fetcher-cc16ac1a.js +873 -0
- package/dist/esm/{form-config-fetcher-c702e9e3.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-767ad354.js → snk-guides-viewer-1838230d.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-218d30c7.js +1 -0
- package/dist/sankhyablocks/{p-76926391.js → p-240f5892.js} +2 -2
- package/dist/sankhyablocks/p-3258df1d.js +59 -0
- package/dist/sankhyablocks/{p-dacb4c4c.entry.js → p-3ec7e5f9.entry.js} +3 -3
- package/dist/sankhyablocks/{p-d1cc9007.entry.js → p-57550ddc.entry.js} +1 -1
- package/dist/sankhyablocks/p-5d51bff4.js +1 -0
- package/dist/sankhyablocks/{p-727b8cbe.entry.js → p-5dd52ec5.entry.js} +1 -1
- package/dist/sankhyablocks/p-6541f0df.js +1 -0
- package/dist/sankhyablocks/{p-845c7480.entry.js → p-8652f90b.entry.js} +1 -1
- package/dist/sankhyablocks/{p-a2c7c45f.js → p-910af03c.js} +1 -1
- package/dist/sankhyablocks/p-992a9d0f.js +1 -0
- package/dist/sankhyablocks/p-c3642830.entry.js +1 -0
- package/dist/sankhyablocks/p-cf954be2.entry.js +1 -0
- package/dist/sankhyablocks/{p-af86752b.js → p-d47bbee3.js} +1 -1
- package/dist/sankhyablocks/p-d50b5736.entry.js +1 -0
- package/dist/sankhyablocks/{p-e46dd27b.entry.js → p-d563e451.entry.js} +1 -1
- package/dist/sankhyablocks/p-d5bc8eb1.js +1 -0
- package/dist/sankhyablocks/p-d8d4ff87.entry.js +1 -0
- package/dist/sankhyablocks/p-dfca1930.entry.js +1 -0
- package/dist/sankhyablocks/{p-3ef37b31.entry.js → p-e74e2153.entry.js} +1 -1
- package/dist/sankhyablocks/{p-3c1759ba.entry.js → p-e8b55571.entry.js} +1 -1
- package/dist/sankhyablocks/{p-90c07587.entry.js → p-ebfa6460.entry.js} +1 -1
- package/dist/sankhyablocks/p-f3fdb409.entry.js +1 -0
- package/dist/sankhyablocks/p-f9dd2359.entry.js +1 -0
- 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.d.ts +3 -2
- package/dist/types/lib/dataUnit/InMemoryLoader.d.ts +2 -1
- package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +2 -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-16b32d96.js +0 -356
- package/dist/esm/dataunit-fetcher-e0361781.js +0 -354
- package/dist/esm/pesquisa-fetcher-d1b4e5a2.js +0 -165
- package/dist/sankhyablocks/p-15578509.entry.js +0 -1
- package/dist/sankhyablocks/p-1f32ad9c.entry.js +0 -1
- package/dist/sankhyablocks/p-2043a64f.js +0 -1
- package/dist/sankhyablocks/p-251985c1.entry.js +0 -1
- package/dist/sankhyablocks/p-473c7df4.js +0 -1
- package/dist/sankhyablocks/p-77aebc26.js +0 -1
- package/dist/sankhyablocks/p-867e9b79.js +0 -1
- package/dist/sankhyablocks/p-8d1602f2.entry.js +0 -1
- package/dist/sankhyablocks/p-98ae8ddc.entry.js +0 -1
- package/dist/sankhyablocks/p-9de24cf3.entry.js +0 -1
- package/dist/sankhyablocks/p-b6d54b6c.entry.js +0 -1
- package/dist/sankhyablocks/p-d5b11196.js +0 -76
- package/dist/sankhyablocks/p-fa9d3f73.js +0 -1
@@ -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
|
},
|
@@ -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() +
|
386
|
+
let url = `${this.resolveURL() + DataFetcher.getGraphQLPath()}`;
|
380
387
|
const responseExtensions = [];
|
381
|
-
|
382
|
-
|
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,112 @@
|
|
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 lastRecord = offset + Math.min(pageSize, limit);
|
101
|
+
return {
|
102
|
+
total,
|
103
|
+
count,
|
104
|
+
lastRecord,
|
105
|
+
firstRecord: offset + 1,
|
106
|
+
currentPage: offset / limit,
|
107
|
+
hasMore: lastRecord < count || loadingInProgress
|
108
|
+
};
|
109
|
+
}
|
110
|
+
}
|
111
|
+
DataUnitDataLoader._requestTimeByDataUnit = new Map();
|
112
|
+
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();
|