@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
@@ -10,15 +10,18 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
10
10
|
}
|
11
11
|
return t;
|
12
12
|
};
|
13
|
-
import { ChangeOperation, DataType, DataUnit,
|
13
|
+
import { ChangeOperation, DataType, DataUnit, DataUnitStorage } from "@sankhyalabs/core";
|
14
14
|
import { gql } from "graphql-request";
|
15
|
-
import { DataFetcher } from "
|
15
|
+
import { DataFetcher } from "../../DataFetcher";
|
16
16
|
import { DISTINCT_FILTER_NAME_PREFIX } from "@sankhyalabs/ezui/dist/collection/utils/constants";
|
17
17
|
import { DataUnitTransient } from "@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";
|
18
|
+
import DataUnitDataLoader from "./DataUnitDataLoader";
|
19
|
+
import PreloadManager from "./cache/PreloadManager";
|
20
|
+
import ResourceIDUtils from "../../../../resourceid/ResourceIDUtils";
|
21
|
+
const DATA_UNIT_NAME_PARSER = /dd:\/\/([^/]+)\/([^/?]+)/;
|
18
22
|
export default class DataUnitFetcher {
|
19
23
|
constructor() {
|
20
24
|
this.templateByQuery = new Map();
|
21
|
-
this._loadDataTimeout = {};
|
22
25
|
this.buldTemplates();
|
23
26
|
}
|
24
27
|
buldTemplates() {
|
@@ -57,24 +60,6 @@ export default class DataUnitFetcher {
|
|
57
60
|
}
|
58
61
|
}
|
59
62
|
}`);
|
60
|
-
this.templateByQuery.set("fetchData", gql `query($dataunit: String! $limit: Int $offset:Int $filters: [InputFilter!] $sort: [InputSort!] $parentRecordId: String) {
|
61
|
-
$queryAlias$: fetchDataUnit(name: $dataunit){
|
62
|
-
data(limit: $limit offset: $offset filters: $filters sort: $sort parentRecordId: $parentRecordId){
|
63
|
-
limit
|
64
|
-
offset
|
65
|
-
total
|
66
|
-
hasMore
|
67
|
-
records{
|
68
|
-
id
|
69
|
-
label
|
70
|
-
fields {
|
71
|
-
name
|
72
|
-
value
|
73
|
-
}
|
74
|
-
}
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}`);
|
78
63
|
this.templateByQuery.set("saveData", gql `mutation($changes: [InputBatchChange!]!) {
|
79
64
|
$queryAlias$: batchOperationDataUnit(changes: $changes){
|
80
65
|
oldId
|
@@ -103,11 +88,25 @@ export default class DataUnitFetcher {
|
|
103
88
|
$queryAlias$: selectDistinct(dataUnit: $dataUnit, fieldName: $fieldName, argument: $argument, filters: $filters, parentRecordId: $parentRecordId)
|
104
89
|
}`);
|
105
90
|
}
|
91
|
+
static parseDataUnitName(name) {
|
92
|
+
if (name == undefined) {
|
93
|
+
return undefined;
|
94
|
+
}
|
95
|
+
const parts = DATA_UNIT_NAME_PARSER.exec(name);
|
96
|
+
if (!parts) {
|
97
|
+
return undefined;
|
98
|
+
}
|
99
|
+
return { entityName: parts[1], resourceID: parts[2] };
|
100
|
+
}
|
106
101
|
getDataUnit(entityName, resourceID, parentDataUnit, configName) {
|
102
|
+
if (PreloadManager.applicationResourceID == undefined) {
|
103
|
+
//Por falta de um lugar melhor pra iniciar essa variável, fazemos isso aqui.
|
104
|
+
ResourceIDUtils.getResourceID().then(resourceID => PreloadManager.applicationResourceID = resourceID);
|
105
|
+
}
|
107
106
|
const duName = `dd://${entityName}/${resourceID}${configName ? "/" + configName : ""}`;
|
108
107
|
const dataUnit = parentDataUnit != undefined ? parentDataUnit.getChildDataunit(duName) : new DataUnit(duName);
|
109
108
|
dataUnit.metadataLoader = (dataUnit) => this.loadMetadata(dataUnit);
|
110
|
-
dataUnit.dataLoader = (dataUnit, request) =>
|
109
|
+
dataUnit.dataLoader = (dataUnit, request) => DataUnitDataLoader.loadData(dataUnit, request);
|
111
110
|
dataUnit.saveLoader = (_dataUnit, changes) => this.saveData(dataUnit, changes);
|
112
111
|
dataUnit.removeLoader = (dataUnit, recordIds) => this.removeRecords(dataUnit, recordIds);
|
113
112
|
dataUnit.recordLoader = (dataUnit, recordIds) => this.loadRecord(dataUnit, recordIds);
|
@@ -147,24 +146,6 @@ export default class DataUnitFetcher {
|
|
147
146
|
});
|
148
147
|
});
|
149
148
|
}
|
150
|
-
async loadData(dataUnit, request) {
|
151
|
-
try {
|
152
|
-
const duName = dataUnit.name;
|
153
|
-
if (this._loadDataTimeout[duName]) {
|
154
|
-
clearTimeout(this._loadDataTimeout[duName]);
|
155
|
-
delete this._loadDataTimeout[duName];
|
156
|
-
}
|
157
|
-
const result = await this.doLoadData(dataUnit, request);
|
158
|
-
delete this._loadDataTimeout[duName];
|
159
|
-
await new Promise(resolve => {
|
160
|
-
this._loadDataTimeout[duName] = setTimeout(resolve, 200);
|
161
|
-
});
|
162
|
-
return Promise.resolve(result);
|
163
|
-
}
|
164
|
-
catch (error) {
|
165
|
-
return Promise.reject(error);
|
166
|
-
}
|
167
|
-
}
|
168
149
|
loadSelectDistinct(dataUnit, fieldName, argument) {
|
169
150
|
const { parentRecordId, filters } = dataUnit.getLastLoadRequest() || {};
|
170
151
|
const filteredFilters = filters.filter(f => f.name !== `${DISTINCT_FILTER_NAME_PREFIX}${fieldName}`);
|
@@ -189,67 +170,9 @@ export default class DataUnitFetcher {
|
|
189
170
|
});
|
190
171
|
});
|
191
172
|
}
|
192
|
-
doLoadData(dataUnit, request) {
|
193
|
-
return new Promise((resolve, reject) => {
|
194
|
-
var _a;
|
195
|
-
const { sort, filters, limit, offset, quickFilter } = request;
|
196
|
-
const variables = { dataunit: dataUnit.name, sort, filters };
|
197
|
-
variables.limit = limit;
|
198
|
-
variables.offset = offset;
|
199
|
-
variables.parentRecordId = request.parentRecordId;
|
200
|
-
if (!StringUtils.isEmpty(quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.term)) {
|
201
|
-
if (variables.filter === undefined) {
|
202
|
-
variables.filter = [];
|
203
|
-
}
|
204
|
-
const quickFilterCriteria = {
|
205
|
-
name: "__QUICK_FILTER__",
|
206
|
-
expression: "__QUICK_FILTER__",
|
207
|
-
params: [{ name: "term", dataType: DataType.TEXT, value: quickFilter.term }]
|
208
|
-
};
|
209
|
-
if (((_a = quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.fields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
210
|
-
quickFilterCriteria.params.push({ name: "fields", dataType: DataType.OBJECT, value: quickFilter.fields });
|
211
|
-
}
|
212
|
-
variables.filter.push(quickFilterCriteria);
|
213
|
-
}
|
214
|
-
DataFetcher.get()
|
215
|
-
.callGraphQL({
|
216
|
-
values: variables,
|
217
|
-
query: this.templateByQuery.get("fetchData"),
|
218
|
-
})
|
219
|
-
.then((resp) => {
|
220
|
-
const { limit, offset, total, hasMore, records } = resp.data;
|
221
|
-
let paginationInfo;
|
222
|
-
if (limit) {
|
223
|
-
const firstRecord = total == 0 ? 0 : offset + 1;
|
224
|
-
const lastRecord = offset + Math.min(records.length, limit);
|
225
|
-
const currentPage = offset / limit;
|
226
|
-
paginationInfo = {
|
227
|
-
firstRecord,
|
228
|
-
lastRecord,
|
229
|
-
total,
|
230
|
-
currentPage,
|
231
|
-
hasMore
|
232
|
-
};
|
233
|
-
}
|
234
|
-
const processedRecords = [];
|
235
|
-
records.forEach((responseRecord) => {
|
236
|
-
const duRecord = { __record__id__: responseRecord.id, __record__label__: responseRecord.label };
|
237
|
-
responseRecord.fields.forEach(({ name, value }) => {
|
238
|
-
duRecord[name] = dataUnit.valueFromString(name, value);
|
239
|
-
});
|
240
|
-
processedRecords.push(duRecord);
|
241
|
-
});
|
242
|
-
resolve({
|
243
|
-
paginationInfo,
|
244
|
-
records: processedRecords
|
245
|
-
});
|
246
|
-
})
|
247
|
-
.catch((error) => {
|
248
|
-
reject(error);
|
249
|
-
});
|
250
|
-
});
|
251
|
-
}
|
252
173
|
saveData(dataUnit, duChanges) {
|
174
|
+
const updatedRecordsIds = [];
|
175
|
+
const addedRecordsIds = [];
|
253
176
|
const changes = duChanges.map((change) => {
|
254
177
|
const { dataUnit: changeDU, record, updatingFields, operation } = change;
|
255
178
|
const dataUnitInstance = DataUnitStorage.get(changeDU);
|
@@ -261,6 +184,14 @@ export default class DataUnitFetcher {
|
|
261
184
|
return { fieldName, dataType, value: dataUnitInstance.valueToString(fieldName, value) };
|
262
185
|
});
|
263
186
|
}
|
187
|
+
if (changeDU === dataUnit.name) {
|
188
|
+
if (operation === ChangeOperation.INSERT || operation === ChangeOperation.COPY) {
|
189
|
+
addedRecordsIds.push(record.__record__id__);
|
190
|
+
}
|
191
|
+
else {
|
192
|
+
updatedRecordsIds.push(record.__record__id__);
|
193
|
+
}
|
194
|
+
}
|
264
195
|
const reqChange = { dataUnit: changeDU, fields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
|
265
196
|
if (change.sourceId) {
|
266
197
|
reqChange.sourceId = change.sourceId;
|
@@ -298,6 +229,7 @@ export default class DataUnitFetcher {
|
|
298
229
|
});
|
299
230
|
dataUnitRecords.push(duRecord);
|
300
231
|
});
|
232
|
+
this.updateCache(dataUnit, dataUnitRecords, updatedRecordsIds, addedRecordsIds);
|
301
233
|
resolve(dataUnitRecords);
|
302
234
|
})
|
303
235
|
.catch((error) => {
|
@@ -305,6 +237,20 @@ export default class DataUnitFetcher {
|
|
305
237
|
});
|
306
238
|
});
|
307
239
|
}
|
240
|
+
updateCache(dataUnit, savedRecords, toUpdate, toInsert) {
|
241
|
+
const recordsById = new Map(savedRecords.map(record => [record.__old__id__ || record.__record__id__, record]));
|
242
|
+
const addedRecords = toInsert.map(recordId => {
|
243
|
+
const copy = Object.assign({}, recordsById.get(recordId));
|
244
|
+
delete copy.__old__id__;
|
245
|
+
return copy;
|
246
|
+
});
|
247
|
+
if (addedRecords.length > 0) {
|
248
|
+
const firstRecord = dataUnit.records[0];
|
249
|
+
PreloadManager.insertRecords(dataUnit, firstRecord, addedRecords);
|
250
|
+
}
|
251
|
+
const updatedRecords = toUpdate.map(recordId => (Object.assign({}, recordsById.get(recordId))));
|
252
|
+
PreloadManager.updateRecords(dataUnit, updatedRecords);
|
253
|
+
}
|
308
254
|
getTransientInfo(dataUnit, recordID) {
|
309
255
|
const { records } = dataUnit.getSelectionInfo();
|
310
256
|
return Object.entries(records.filter(record => record.__record__id__ == recordID)[0]).filter(([key]) => key.startsWith(DataUnitTransient.DATA_UNIT_TRANSIENT_PREFIX_NAME)).map(([name, value]) => ({ fieldName: name, value, dataType: DataType.TEXT }));
|
@@ -320,6 +266,7 @@ export default class DataUnitFetcher {
|
|
320
266
|
query: this.templateByQuery.get("saveData"),
|
321
267
|
})
|
322
268
|
.then((_resp) => {
|
269
|
+
PreloadManager.removeRecords(dataUnit, dataUnit.records.filter(record => recordIds.includes(record.__record__id__)));
|
323
270
|
resolve(recordIds);
|
324
271
|
})
|
325
272
|
.catch((error) => {
|
@@ -343,6 +290,7 @@ export default class DataUnitFetcher {
|
|
343
290
|
});
|
344
291
|
dataUnitRecords.push(duRecord);
|
345
292
|
});
|
293
|
+
//TODO: Chamar o worker para persistir a nova versão do registro
|
346
294
|
resolve(dataUnitRecords);
|
347
295
|
})
|
348
296
|
.catch((error) => {
|
package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataResult.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/ILoadDataStrategy.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IResponseRecord.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DataUnitStrategy.js
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
import { DataType, StringUtils } from "@sankhyalabs/core";
|
2
|
+
import { DataFetcher } from "../../../DataFetcher";
|
3
|
+
import { gql } from "graphql-request";
|
4
|
+
const GQL_QUERY = gql `query($dataunit: String! $limit: Int $offset:Int $filters: [InputFilter!] $sort: [InputSort!] $parentRecordId: String) {
|
5
|
+
$queryAlias$: fetchDataUnit(name: $dataunit) {
|
6
|
+
data(limit: $limit offset: $offset filters: $filters sort: $sort parentRecordId: $parentRecordId) {
|
7
|
+
limit
|
8
|
+
offset
|
9
|
+
total
|
10
|
+
hasMore
|
11
|
+
records {
|
12
|
+
id
|
13
|
+
label
|
14
|
+
fields {
|
15
|
+
name
|
16
|
+
value
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}`;
|
22
|
+
export class DataUnitStrategy {
|
23
|
+
canSlice() {
|
24
|
+
return true;
|
25
|
+
}
|
26
|
+
getVariables(dataunit, request) {
|
27
|
+
var _a;
|
28
|
+
let { sort, filters, limit, offset, quickFilter, parentRecordId } = request;
|
29
|
+
if (!StringUtils.isEmpty(quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.term)) {
|
30
|
+
const quickFilterCriteria = {
|
31
|
+
name: "__QUICK_FILTER__",
|
32
|
+
expression: "__QUICK_FILTER__",
|
33
|
+
params: [{ name: "term", dataType: DataType.TEXT, value: quickFilter.term }]
|
34
|
+
};
|
35
|
+
if (((_a = quickFilter.fields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
36
|
+
quickFilterCriteria.params.push({ name: "fields", dataType: DataType.OBJECT, value: quickFilter.fields });
|
37
|
+
}
|
38
|
+
if (filters === undefined) {
|
39
|
+
filters = [];
|
40
|
+
}
|
41
|
+
filters.push(quickFilterCriteria);
|
42
|
+
}
|
43
|
+
return { dataunit, sort, filters, limit, offset, parentRecordId };
|
44
|
+
}
|
45
|
+
async load(dataUnit, request, loadingInfo) {
|
46
|
+
return new Promise((accept, reject) => {
|
47
|
+
DataFetcher.get().callGraphQL({
|
48
|
+
values: this.getVariables(dataUnit.name, request),
|
49
|
+
query: GQL_QUERY
|
50
|
+
}, false)
|
51
|
+
.then(resp => {
|
52
|
+
const { hasMore, records: responseRecords, total } = resp.data;
|
53
|
+
const records = responseRecords.map((record) => {
|
54
|
+
const duRecord = { __record__id__: record.id, __record__label__: record.label };
|
55
|
+
record.fields.forEach(({ name, value }) => {
|
56
|
+
duRecord[name] = dataUnit.valueFromString(name, value);
|
57
|
+
});
|
58
|
+
return duRecord;
|
59
|
+
});
|
60
|
+
accept({
|
61
|
+
records,
|
62
|
+
loadingInfo: Object.assign(Object.assign({}, loadingInfo), { loadingInProgress: hasMore, total, count: loadingInfo.count + records.length })
|
63
|
+
});
|
64
|
+
})
|
65
|
+
.catch(reason => reject(reason));
|
66
|
+
});
|
67
|
+
}
|
68
|
+
}
|
package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.js
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
import { StringUtils, UserInterface } from "@sankhyalabs/core";
|
2
|
+
import { DataFetcher } from "../../../DataFetcher";
|
3
|
+
import DataUnitFetcher from "../dataunit-fetcher";
|
4
|
+
import InMemoryLoader from "../../../../../dataUnit/InMemoryLoader";
|
5
|
+
export class DatasetStrategy {
|
6
|
+
canSlice() {
|
7
|
+
return false;
|
8
|
+
}
|
9
|
+
async load(dataUnit, request, loadingInfo) {
|
10
|
+
if (dataUnit.metadata == undefined) {
|
11
|
+
return Promise.resolve({ records: [], loadingInfo });
|
12
|
+
}
|
13
|
+
try {
|
14
|
+
const fields = this.getFieldsList(dataUnit);
|
15
|
+
const serviceName = "DatasetSP.loadRecords";
|
16
|
+
const requestBody = this.buildRequestBody(serviceName, fields, dataUnit, request, loadingInfo);
|
17
|
+
const { result: responseRecords, pagerID: pagerId } = await DataFetcher.get().callServiceBroker(serviceName, requestBody);
|
18
|
+
const records = this.processRecords(dataUnit, fields, responseRecords);
|
19
|
+
const loadingInProgress = pagerId != undefined;
|
20
|
+
const count = loadingInfo.count + records.length;
|
21
|
+
return Promise.resolve({
|
22
|
+
records,
|
23
|
+
loadingInfo: Object.assign(Object.assign({}, loadingInfo), { pagerId,
|
24
|
+
loadingInProgress, total: loadingInProgress ? undefined : count, count })
|
25
|
+
});
|
26
|
+
}
|
27
|
+
catch (error) {
|
28
|
+
console.error(error);
|
29
|
+
return Promise.reject(error);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
getFieldsList(dataUnit) {
|
33
|
+
let fields = ["__record__id__", "__record__label__"];
|
34
|
+
dataUnit.metadata.fields.forEach(descriptor => {
|
35
|
+
fields = fields.concat(this.getFieldNames(descriptor));
|
36
|
+
});
|
37
|
+
return fields;
|
38
|
+
}
|
39
|
+
getFieldNames(descriptor) {
|
40
|
+
const descriptionField = this.getSearchDescriptionField(descriptor);
|
41
|
+
if (descriptionField == undefined) {
|
42
|
+
return descriptor.name;
|
43
|
+
}
|
44
|
+
return [descriptor.name, descriptionField];
|
45
|
+
}
|
46
|
+
buildRequestBody(serviceName, fields, dataUnit, request, loadingInfo) {
|
47
|
+
const dataSetID = dataUnit.dataUnitId;
|
48
|
+
const dataUnitName = dataUnit.name;
|
49
|
+
const entityName = DataUnitFetcher.parseDataUnitName(dataUnitName).entityName;
|
50
|
+
const requestBody = {
|
51
|
+
serviceName,
|
52
|
+
requestBody: {
|
53
|
+
dataSetID,
|
54
|
+
fields,
|
55
|
+
entityName,
|
56
|
+
pageNumber: loadingInfo.pageNumber,
|
57
|
+
totalRecordsCount: loadingInfo.count,
|
58
|
+
pagerID: loadingInfo.pagerId,
|
59
|
+
standAlone: false,
|
60
|
+
standAloneFieldsMD: {
|
61
|
+
__record__id__: { "fieldType": "S", "userType": "P" },
|
62
|
+
__record__label__: { "fieldType": "S", "userType": "P" }
|
63
|
+
},
|
64
|
+
tryJoinedFields: true,
|
65
|
+
parallelLoader: true,
|
66
|
+
crudListener: "br.com.sankhya.modelcore.dataset.DataUnitDatasetAdapter",
|
67
|
+
txProperties: this.getTxProperties(dataUnitName, request),
|
68
|
+
useDefaultRowsLimit: false
|
69
|
+
}
|
70
|
+
};
|
71
|
+
return JSON.stringify(requestBody);
|
72
|
+
}
|
73
|
+
getTxProperties(dataUnitName, request) {
|
74
|
+
const txProperties = {
|
75
|
+
"__DATA_UNIT_ADAPTER__[dataUnitName]": dataUnitName
|
76
|
+
};
|
77
|
+
const serverSideFilters = request.filters.filter(filter => !filter.name.startsWith("FILTRO_COLUNA_"));
|
78
|
+
if (serverSideFilters.length !== 0) {
|
79
|
+
txProperties["__DATA_UNIT_ADAPTER__[criteria]"] = JSON.stringify(serverSideFilters);
|
80
|
+
}
|
81
|
+
const sorting = request.sort;
|
82
|
+
if (sorting != undefined && sorting.length !== 0) {
|
83
|
+
txProperties["__DATA_UNIT_ADAPTER__[sorting]"] = JSON.stringify(sorting);
|
84
|
+
}
|
85
|
+
return txProperties;
|
86
|
+
}
|
87
|
+
processRecords(dataUnit, fields, responseRecords) {
|
88
|
+
return responseRecords.map((dataFrame) => {
|
89
|
+
const duRecord = {
|
90
|
+
__record__id__: dataFrame[0],
|
91
|
+
__record__label__: dataFrame[1]
|
92
|
+
};
|
93
|
+
dataUnit.metadata.fields.forEach(fieldDescriptor => {
|
94
|
+
duRecord[fieldDescriptor.name] = this.buildFieldValue(fieldDescriptor, fields, dataFrame);
|
95
|
+
});
|
96
|
+
return duRecord;
|
97
|
+
});
|
98
|
+
}
|
99
|
+
buildFieldValue(descriptor, allFields, dataFrame) {
|
100
|
+
const fieldIndex = allFields.indexOf(descriptor.name);
|
101
|
+
if (fieldIndex < 0) {
|
102
|
+
return null;
|
103
|
+
}
|
104
|
+
const strValue = dataFrame[fieldIndex];
|
105
|
+
if (StringUtils.isEmpty(strValue)) {
|
106
|
+
return null;
|
107
|
+
}
|
108
|
+
const descriptionField = this.getSearchDescriptionField(descriptor);
|
109
|
+
if (descriptionField != undefined) {
|
110
|
+
const descriptionFieldIndex = allFields.indexOf(descriptionField);
|
111
|
+
if (descriptionFieldIndex >= 0) {
|
112
|
+
return { value: strValue, label: dataFrame[descriptionFieldIndex] };
|
113
|
+
}
|
114
|
+
}
|
115
|
+
if (descriptor.userInterface === UserInterface.SEARCH) {
|
116
|
+
//Se não tem um campo de descrição (código acima)
|
117
|
+
//Mas é um search, tentamos parsear um numero...
|
118
|
+
return isNaN(Number(strValue)) ? strValue : Number(strValue);
|
119
|
+
}
|
120
|
+
return InMemoryLoader.getConvertedValue(descriptor, strValue);
|
121
|
+
}
|
122
|
+
getSearchDescriptionField(descriptor) {
|
123
|
+
if (descriptor.userInterface === UserInterface.SEARCH) {
|
124
|
+
const { ENTITYNAME, mergedFrom, DESCRIPTIONFIELD } = descriptor.properties;
|
125
|
+
if (!StringUtils.isEmpty(DESCRIPTIONFIELD)) {
|
126
|
+
return mergedFrom != undefined ? `${mergedFrom}.${ENTITYNAME}.${DESCRIPTIONFIELD}` : `${ENTITYNAME}.${DESCRIPTIONFIELD}`;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
return undefined;
|
130
|
+
}
|
131
|
+
}
|
@@ -5,7 +5,7 @@ export { PresentationMode } from "./@types";
|
|
5
5
|
export { TotalsFetcher } from './http/data-fetcher/fetchers/totals-fetcher';
|
6
6
|
export { default as ApplicationConfigFetcher } from './http/data-fetcher/fetchers/application-config-fetcher';
|
7
7
|
export { AttachFetcher } from './http/data-fetcher/fetchers/attach-fetcher';
|
8
|
-
export { default as DataUnitFetcher } from './http/data-fetcher/fetchers/dataunit-fetcher';
|
8
|
+
export { default as DataUnitFetcher } from './http/data-fetcher/fetchers/data-unit/dataunit-fetcher';
|
9
9
|
export { default as FilterBarConfigFetcher } from './http/data-fetcher/fetchers/filter-bar-config-fetcher';
|
10
10
|
export { FormConfigFetcher } from './http/data-fetcher/fetchers/form-config-fetcher';
|
11
11
|
export { default as GridConfigFetcher } from './http/data-fetcher/fetchers/grid-config-fetcher';
|
@@ -6541,11 +6541,10 @@ class DataFetcher {
|
|
6541
6541
|
}
|
6542
6542
|
}
|
6543
6543
|
this.instance.application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
|
6544
|
-
this.instance.graphqlPath = `/${this.instance.application.getModuleName()}/graphql`;
|
6545
6544
|
return this.instance;
|
6546
6545
|
}
|
6547
6546
|
static getGraphQLPath() {
|
6548
|
-
if (StringUtils.isEmpty(this.instance.graphqlPath)) {
|
6547
|
+
if (StringUtils.isEmpty(this.instance.graphqlPath) && this.instance.application != undefined) {
|
6549
6548
|
this.instance.graphqlPath = `/${this.instance.application.getModuleName()}/graphql`;
|
6550
6549
|
}
|
6551
6550
|
return this.instance.graphqlPath;
|
@@ -6599,7 +6598,7 @@ class DataFetcher {
|
|
6599
6598
|
}
|
6600
6599
|
return new ErrorException(title, statusMessage, tsErrorCode);
|
6601
6600
|
}
|
6602
|
-
async callGraphQL(req) {
|
6601
|
+
async callGraphQL(req, quietMode = false) {
|
6603
6602
|
var _a;
|
6604
6603
|
if (this.ready) {
|
6605
6604
|
this.pause();
|
@@ -6617,7 +6616,7 @@ class DataFetcher {
|
|
6617
6616
|
if (this.ready) {
|
6618
6617
|
return new Promise(async (resolve, reject) => {
|
6619
6618
|
let query = this.getQueryTemplate(req);
|
6620
|
-
const res = await this.fecthGrapql([{ document: query, variables: req.values }]);
|
6619
|
+
const res = await this.fecthGrapql([{ document: query, variables: req.values }], quietMode);
|
6621
6620
|
if (res.errors.length > 0) {
|
6622
6621
|
if (!this.proccesGraphQLClientEvents(res === null || res === void 0 ? void 0 : res.extensions, req, resolve, reject)) {
|
6623
6622
|
const error = this.processGraphQlErrorInfo(res.errors);
|
@@ -6632,7 +6631,7 @@ class DataFetcher {
|
|
6632
6631
|
}
|
6633
6632
|
else {
|
6634
6633
|
if (!this.watingRequestsById.has(reqKey)) {
|
6635
|
-
this.watingRequestsById.set(reqKey, new WaitingRequest(req));
|
6634
|
+
this.watingRequestsById.set(reqKey, new WaitingRequest(req, quietMode));
|
6636
6635
|
}
|
6637
6636
|
return (_a = this.watingRequestsById.get(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
|
6638
6637
|
}
|
@@ -6848,14 +6847,16 @@ class DataFetcher {
|
|
6848
6847
|
}
|
6849
6848
|
async executePendingRequest(watingRequestsById) {
|
6850
6849
|
const requestsBatch = [];
|
6850
|
+
let quietMode = true;
|
6851
6851
|
watingRequestsById.forEach(async (waitingReq) => {
|
6852
6852
|
let query = this.getQueryTemplate(waitingReq.request);
|
6853
6853
|
requestsBatch.push({ document: query, variables: Object.assign({}, waitingReq.request.values) });
|
6854
|
+
quietMode = quietMode && waitingReq.quietMode;
|
6854
6855
|
});
|
6855
6856
|
let res = undefined;
|
6856
6857
|
let dataResponse = [];
|
6857
6858
|
let errorsResponse = [];
|
6858
|
-
res = await this.fecthGrapql(requestsBatch);
|
6859
|
+
res = await this.fecthGrapql(requestsBatch, quietMode);
|
6859
6860
|
dataResponse = res.data;
|
6860
6861
|
errorsResponse = res.errors;
|
6861
6862
|
//Reject promises with errors from query
|
@@ -6873,14 +6874,18 @@ class DataFetcher {
|
|
6873
6874
|
});
|
6874
6875
|
});
|
6875
6876
|
}
|
6876
|
-
async fecthGrapql(request) {
|
6877
|
+
async fecthGrapql(request, quietMode) {
|
6877
6878
|
let res = undefined;
|
6878
6879
|
let dataResponse = [];
|
6879
6880
|
let errorsResponse = [];
|
6880
6881
|
let url = `${this.resolveURL() + DataFetcher.getGraphQLPath()}`;
|
6881
6882
|
const responseExtensions = [];
|
6882
|
-
|
6883
|
-
|
6883
|
+
const mgeSession = window["mgeSession"];
|
6884
|
+
if (mgeSession != undefined) {
|
6885
|
+
url += `?mgeSession=${mgeSession}`;
|
6886
|
+
}
|
6887
|
+
if (quietMode) {
|
6888
|
+
url += `${url.indexOf("?") > -1 ? "&" : "?"}quietMode=true`;
|
6884
6889
|
}
|
6885
6890
|
DataFetcher.requestListener.forEach(listener => listener.onRequestStart({ url: url, requestBody: request }));
|
6886
6891
|
try {
|
@@ -6966,7 +6971,7 @@ DataFetcher.SERVICE_BROKER_STATUS = {
|
|
6966
6971
|
};
|
6967
6972
|
DataFetcher.clientEventsByID = new Map();
|
6968
6973
|
class WaitingRequest {
|
6969
|
-
constructor(req) {
|
6974
|
+
constructor(req, quietMode) {
|
6970
6975
|
this._resolve = () => { };
|
6971
6976
|
this._reject = () => { };
|
6972
6977
|
this._request = undefined;
|
@@ -6975,6 +6980,7 @@ class WaitingRequest {
|
|
6975
6980
|
this._resolve = resolve;
|
6976
6981
|
this._reject = reject;
|
6977
6982
|
});
|
6983
|
+
this._quietMode = quietMode;
|
6978
6984
|
}
|
6979
6985
|
get resolve() {
|
6980
6986
|
return this._resolve;
|
@@ -6988,6 +6994,9 @@ class WaitingRequest {
|
|
6988
6994
|
get request() {
|
6989
6995
|
return this._request;
|
6990
6996
|
}
|
6997
|
+
get quietMode() {
|
6998
|
+
return this._quietMode;
|
6999
|
+
}
|
6991
7000
|
}
|
6992
7001
|
|
6993
7002
|
export { DataFetcher as D, UrlUtils as U, dist as d };
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { UserInterface, DateUtils } from '@sankhyalabs/core';
|
2
|
+
import { a as PreloadManager } from './dataunit-fetcher.js';
|
2
3
|
|
3
4
|
class TaskbarProcessor {
|
4
5
|
constructor(defaultButtons) {
|
@@ -60,6 +61,16 @@ class SnkMultiSelectionListDataSource {
|
|
60
61
|
}
|
61
62
|
return String(this._dataUnit.getFormattedValue(fieldName, value));
|
62
63
|
}
|
64
|
+
async getStaticOptions(fieldName) {
|
65
|
+
if (fieldName == undefined) {
|
66
|
+
return Promise.resolve(undefined);
|
67
|
+
}
|
68
|
+
const result = await PreloadManager.getDistinct(this._dataUnit, fieldName);
|
69
|
+
if (result == undefined) {
|
70
|
+
return Promise.resolve(undefined);
|
71
|
+
}
|
72
|
+
return Promise.resolve(Array.from(result.entries()).map(([label, value]) => ({ label: String(label), value, check: true })));
|
73
|
+
}
|
63
74
|
fetchData(filterTerm, fieldName) {
|
64
75
|
return new Promise(resolve => {
|
65
76
|
this._application.executeSelectDistinct(this._dataUnit, fieldName, filterTerm).then(result => {
|