@sankhyalabs/core 5.20.0-dev.9 → 5.20.0-ms.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/classes/Base64Utils.md +39 -0
- package/.docs/classes/Change.md +11 -11
- package/.docs/classes/ColumnFilterManager.md +145 -0
- package/.docs/classes/DataUnit.md +429 -139
- package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
- package/.docs/classes/DataUnitLoaderUtils.md +151 -0
- package/.docs/classes/DateUtils.md +8 -8
- package/.docs/classes/FieldComparator.md +2 -2
- package/.docs/classes/IDBRepository.md +22 -0
- package/.docs/classes/LockManager.md +249 -0
- package/.docs/classes/MaskFormatter.md +66 -14
- package/.docs/classes/ObjectUtils.md +141 -0
- package/.docs/classes/OverflowWatcher.md +310 -46
- package/.docs/classes/SelectionInfo.md +25 -11
- package/.docs/classes/ServiceCanceledException.md +193 -0
- package/.docs/classes/ServiceUtils.md +67 -0
- package/.docs/classes/SilentException.md +193 -0
- package/.docs/classes/StringUtils.md +24 -0
- package/.docs/classes/UserAgentUtils.md +15 -1
- package/.docs/enumerations/Action.md +41 -21
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/LockManagerOperation.md +33 -0
- package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
- package/.docs/enumerations/SelectionMode.md +2 -2
- package/.docs/enumerations/StorageType.md +37 -0
- package/.docs/globals.md +19 -0
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
- package/.docs/interfaces/IRepository.md +18 -0
- package/.docs/interfaces/LoadDataRequest.md +1 -1
- package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/PaginationInfo.md +25 -0
- package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
- package/.docs/interfaces/QuickFilter.md +3 -3
- package/.docs/interfaces/Record.md +4 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +1 -1
- package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +1 -1
- package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
- package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
- package/.releaserc +1 -0
- package/bun.lockb +0 -0
- package/dist/dataunit/DataUnit.d.ts +92 -13
- package/dist/dataunit/DataUnit.js +219 -71
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/DataUnitHelper.js +6 -5
- package/dist/dataunit/DataUnitHelper.js.map +1 -1
- package/dist/dataunit/formatting/PrettyFormatter.js +14 -6
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
- package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
- package/dist/dataunit/loading/PaginationInfo.d.ts +8 -0
- package/dist/dataunit/metadata/DataType.js +3 -0
- package/dist/dataunit/metadata/DataType.js.map +1 -1
- package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
- package/dist/dataunit/sorting/FieldComparator.js +4 -9
- package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
- package/dist/dataunit/state/action/DataUnitAction.d.ts +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js +2 -0
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/dataunit/state/slice/LoadingControlSlice.js +16 -0
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.js +4 -4
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/exceptions/ServiceCanceledException.d.ts +14 -0
- package/dist/exceptions/ServiceCanceledException.js +13 -0
- package/dist/exceptions/ServiceCanceledException.js.map +1 -0
- package/dist/exceptions/SilentException.d.ts +14 -0
- package/dist/exceptions/SilentException.js +13 -0
- package/dist/exceptions/SilentException.js.map +1 -0
- package/dist/index.d.ts +13 -3
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/repository/IRepository.d.ts +6 -0
- package/dist/repository/indexeddb/IDBRepository.d.ts +1 -0
- package/dist/repository/indexeddb/IDBRepository.js +3 -0
- package/dist/repository/indexeddb/IDBRepository.js.map +1 -1
- package/dist/utils/Base64Utils.d.ts +7 -0
- package/dist/utils/Base64Utils.js +13 -0
- package/dist/utils/Base64Utils.js.map +1 -0
- package/dist/utils/CacheManager/index.d.ts +52 -0
- package/dist/utils/CacheManager/index.js +101 -0
- package/dist/utils/CacheManager/index.js.map +1 -0
- package/dist/utils/CacheManager/interfaces/index.d.ts +5 -0
- package/dist/utils/CacheManager/interfaces/index.js +7 -0
- package/dist/utils/CacheManager/interfaces/index.js.map +1 -0
- package/dist/utils/ColumnFilterManager.d.ts +19 -0
- package/dist/utils/ColumnFilterManager.js +73 -0
- package/dist/utils/ColumnFilterManager.js.map +1 -0
- package/dist/utils/DateUtils.js +3 -0
- package/dist/utils/DateUtils.js.map +1 -1
- package/dist/utils/ElementUtils.d.ts +2 -0
- package/dist/utils/ElementUtils.js +9 -0
- package/dist/utils/ElementUtils.js.map +1 -0
- package/dist/utils/LockManager.d.ts +58 -0
- package/dist/utils/LockManager.js +191 -0
- package/dist/utils/LockManager.js.map +1 -0
- package/dist/utils/MaskFormatter.d.ts +16 -1
- package/dist/utils/MaskFormatter.js +82 -2
- package/dist/utils/MaskFormatter.js.map +1 -1
- package/dist/utils/ObjectUtils.d.ts +38 -0
- package/dist/utils/ObjectUtils.js +51 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/OnboardingUtils.js +1 -1
- package/dist/utils/OnboardingUtils.js.map +1 -1
- package/dist/utils/OverflowWatcher/index.d.ts +35 -7
- package/dist/utils/OverflowWatcher/index.js +140 -59
- package/dist/utils/OverflowWatcher/index.js.map +1 -1
- package/dist/utils/ServiceUtils.d.ts +24 -0
- package/dist/utils/ServiceUtils.js +40 -0
- package/dist/utils/ServiceUtils.js.map +1 -0
- package/dist/utils/SortingUtils.d.ts +9 -0
- package/dist/utils/SortingUtils.js +24 -0
- package/dist/utils/SortingUtils.js.map +1 -0
- package/dist/utils/StringUtils.d.ts +6 -0
- package/dist/utils/StringUtils.js +11 -0
- package/dist/utils/StringUtils.js.map +1 -1
- package/dist/utils/UserAgentUtils/index.d.ts +1 -0
- package/dist/utils/UserAgentUtils/index.js +5 -0
- package/dist/utils/UserAgentUtils/index.js.map +1 -1
- package/jest.config.ts +2 -0
- package/package.json +2 -1
- package/reports/test-report.xml +215 -0
- package/setupTests.js +7 -0
- package/sonar-project.properties +6 -3
- package/src/dataunit/DataUnit.ts +268 -86
- package/src/dataunit/DataUnitHelper.ts +6 -5
- package/src/dataunit/formatting/PrettyFormatter.ts +15 -6
- package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
- package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
- package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
- package/src/dataunit/loading/LoadDataRequest.ts +1 -1
- package/src/dataunit/loading/PaginationInfo.ts +10 -0
- package/src/dataunit/metadata/DataType.ts +3 -0
- package/src/dataunit/sorting/FieldComparator.ts +18 -32
- package/src/dataunit/state/action/DataUnitAction.ts +2 -0
- package/src/dataunit/state/slice/LoadingControlSlice.ts +42 -0
- package/src/dataunit/state/slice/RecordsSlice.ts +1 -1
- package/src/dataunit/state/slice/SelectionSlice.ts +4 -4
- package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +45 -0
- package/src/dataunit/test/DataUnit.spec.ts +44 -0
- package/src/exceptions/ServiceCanceledException.ts +25 -0
- package/src/exceptions/SilentException.ts +25 -0
- package/src/index.ts +30 -3
- package/src/repository/IRepository.ts +7 -0
- package/src/repository/indexeddb/IDBRepository.ts +4 -0
- package/src/utils/Base64Utils.ts +13 -0
- package/src/utils/CacheManager/index.ts +103 -0
- package/src/utils/CacheManager/interfaces/index.ts +5 -0
- package/src/utils/ColumnFilterManager.ts +104 -0
- package/src/utils/DateUtils.ts +3 -0
- package/src/utils/ElementUtils.ts +10 -0
- package/src/utils/LockManager.ts +213 -0
- package/src/utils/MaskFormatter.ts +93 -2
- package/src/utils/ObjectUtils.ts +56 -0
- package/src/utils/OnboardingUtils.ts +1 -1
- package/src/utils/OverflowWatcher/index.ts +170 -78
- package/src/utils/ServiceUtils.ts +36 -0
- package/src/utils/SortingUtils.ts +30 -0
- package/src/utils/StringUtils.ts +13 -0
- package/src/utils/UserAgentUtils/index.ts +6 -1
- package/src/utils/test/objectUtils.spec.ts +109 -0
- package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
- package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
- package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
- package/test/util/ColumnFilterManager.spec.ts +133 -0
- package/test/util/ElementUtils.spec.ts +34 -0
- package/test/util/OverflowWatcher.spec.ts +152 -118
|
@@ -29,6 +29,9 @@ import { v4 as uuid } from "uuid";
|
|
|
29
29
|
import { DataUnitStorage } from "./DataUnitStorage.js";
|
|
30
30
|
import { getInvalidFieldMessage, InvalidFieldsReducer } from "./state/slice/InvalidFieldsSlice.js";
|
|
31
31
|
import { getLoadingProperties, LoadingPropertiesReducer } from "./state/slice/LoadingProperties.js";
|
|
32
|
+
import SortingUtils from "../utils/SortingUtils.js";
|
|
33
|
+
import ServiceCanceledException from "../exceptions/ServiceCanceledException.js";
|
|
34
|
+
import SilentException from "../exceptions/SilentException.js";
|
|
32
35
|
/***
|
|
33
36
|
* `DataUnit`: Atua como uma camada de abstração entre o back-end e a interface do usuário.
|
|
34
37
|
*/
|
|
@@ -37,6 +40,8 @@ export default class DataUnit {
|
|
|
37
40
|
var _a;
|
|
38
41
|
this._childByName = new Map();
|
|
39
42
|
this._savingLockers = [];
|
|
43
|
+
this._waitingToReload = false;
|
|
44
|
+
this._cancelPagination = false;
|
|
40
45
|
/**
|
|
41
46
|
*
|
|
42
47
|
* Trata as Actions do DataUnit Parent
|
|
@@ -50,6 +55,8 @@ export default class DataUnit {
|
|
|
50
55
|
case Action.NEXT_SELECTED:
|
|
51
56
|
case Action.PREVIOUS_SELECTED:
|
|
52
57
|
case Action.DATA_LOADED:
|
|
58
|
+
case Action.RECORDS_ADDED:
|
|
59
|
+
case Action.EDITION_CANCELED:
|
|
53
60
|
this.clearDataUnit();
|
|
54
61
|
const selectedRecord = (_a = this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.getSelectedRecord();
|
|
55
62
|
if (selectedRecord != undefined && !this.isNewRecord(selectedRecord.__record__id__)) {
|
|
@@ -75,11 +82,12 @@ export default class DataUnit {
|
|
|
75
82
|
InvalidFieldsReducer,
|
|
76
83
|
SnapshotReducer
|
|
77
84
|
]);
|
|
78
|
-
this._observers =
|
|
85
|
+
this._observers = new Map();
|
|
79
86
|
this._filterProviders = new Map();
|
|
80
87
|
this._sortingProvider = undefined;
|
|
81
88
|
this._defaultSorting = [];
|
|
82
|
-
this.
|
|
89
|
+
this._allowReleaseCallbacks = true;
|
|
90
|
+
this._interceptors = new Map();
|
|
83
91
|
this._parentDataUnit = parentDataUnit;
|
|
84
92
|
(_a = this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.subscribe(this.onDataUnitParentEvent);
|
|
85
93
|
this._loadingLockers = [];
|
|
@@ -107,10 +115,12 @@ export default class DataUnit {
|
|
|
107
115
|
* - Sorting Providers
|
|
108
116
|
*/
|
|
109
117
|
releaseCallbacks() {
|
|
110
|
-
this.
|
|
118
|
+
if (!this._allowReleaseCallbacks)
|
|
119
|
+
return;
|
|
120
|
+
this._observers = new Map();
|
|
111
121
|
this._filterProviders = new Map();
|
|
112
122
|
this._sortingProvider = undefined;
|
|
113
|
-
this._interceptors =
|
|
123
|
+
this._interceptors = new Map();
|
|
114
124
|
}
|
|
115
125
|
/**
|
|
116
126
|
* Adiciona uma propriedade transacional que será envida aos
|
|
@@ -135,6 +145,31 @@ export default class DataUnit {
|
|
|
135
145
|
get dataUnitId() {
|
|
136
146
|
return this._uuid;
|
|
137
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Retorna se o dataUnit está com recarregamento pendente.
|
|
150
|
+
*/
|
|
151
|
+
isWaitingToReload() {
|
|
152
|
+
return this._waitingToReload;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Define se o dataUnit tem um recarregamento pendente.
|
|
156
|
+
* @param isWaiting
|
|
157
|
+
*/
|
|
158
|
+
setWaitingToReload(isWaiting) {
|
|
159
|
+
this._waitingToReload = isWaiting;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Informa se a paginação deve ser cancelada.
|
|
163
|
+
*/
|
|
164
|
+
get cancelPagination() {
|
|
165
|
+
return this._cancelPagination;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Informa se a paginação deve ser cancelada.
|
|
169
|
+
*/
|
|
170
|
+
set cancelPagination(cancelPagination) {
|
|
171
|
+
this._cancelPagination = cancelPagination;
|
|
172
|
+
}
|
|
138
173
|
/**
|
|
139
174
|
*
|
|
140
175
|
* Obtém o nome de identificação do DataUnit (geralmente em formato de URI - Uniform Resource Identifier).
|
|
@@ -203,7 +238,7 @@ export default class DataUnit {
|
|
|
203
238
|
if (yield this.dispatchAction(Action.LOADING_DATA, request, executionCtx)) {
|
|
204
239
|
if (this.dataLoader) {
|
|
205
240
|
this.dataLoader(this, request).then((response) => __awaiter(this, void 0, void 0, function* () {
|
|
206
|
-
yield this.dispatchAction(Action.DATA_LOADED, Object.assign(Object.assign({}, response), { keepSelection: request.keepSelection, filters: request.filters }), executionCtx);
|
|
241
|
+
yield this.dispatchAction(Action.DATA_LOADED, Object.assign(Object.assign({}, response), { keepSelection: request.keepSelection, filters: request.filters, selectFirstRecord }), executionCtx);
|
|
207
242
|
yield this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
208
243
|
if (selectFirstRecord) {
|
|
209
244
|
this.requestSelectFirst(executionCtx);
|
|
@@ -255,6 +290,11 @@ export default class DataUnit {
|
|
|
255
290
|
}
|
|
256
291
|
});
|
|
257
292
|
}
|
|
293
|
+
loadDataWithParams({ source, keepSelection, selectFirstRecord, executionCtx, checkLastFilter, quickFilter }) {
|
|
294
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
return yield this.loadData(quickFilter, executionCtx, checkLastFilter, source, selectFirstRecord, keepSelection);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
258
298
|
/**
|
|
259
299
|
*
|
|
260
300
|
* Carrega os registros do DataUnit.
|
|
@@ -266,18 +306,21 @@ export default class DataUnit {
|
|
|
266
306
|
* @returns - Registros requisitados.
|
|
267
307
|
*
|
|
268
308
|
*/
|
|
269
|
-
loadData(quickFilter, executionCtx, checkLastFilter, source, selectFirstRecord) {
|
|
309
|
+
loadData(quickFilter, executionCtx, checkLastFilter, source, selectFirstRecord, keepSelection) {
|
|
270
310
|
return __awaiter(this, void 0, void 0, function* () {
|
|
271
311
|
yield this.processLoadingLockers();
|
|
272
|
-
if (this._parentDataUnit
|
|
273
|
-
|
|
274
|
-
|
|
312
|
+
if (this._parentDataUnit) {
|
|
313
|
+
const parentRecord = this._parentDataUnit.getSelectedRecord();
|
|
314
|
+
if (parentRecord == undefined || this._parentDataUnit.isNewRecord(parentRecord.__record__id__)) {
|
|
315
|
+
if (this.records) {
|
|
316
|
+
this.clearDataUnit();
|
|
317
|
+
}
|
|
318
|
+
return Promise.resolve({
|
|
319
|
+
records: []
|
|
320
|
+
});
|
|
275
321
|
}
|
|
276
|
-
return Promise.resolve({
|
|
277
|
-
records: []
|
|
278
|
-
});
|
|
279
322
|
}
|
|
280
|
-
const loadDataRequest = this.getLoadDataRequest(quickFilter, source);
|
|
323
|
+
const loadDataRequest = this.getLoadDataRequest(quickFilter, source, keepSelection);
|
|
281
324
|
return this.executeLoadData(loadDataRequest, executionCtx, checkLastFilter, selectFirstRecord);
|
|
282
325
|
});
|
|
283
326
|
}
|
|
@@ -293,6 +336,9 @@ export default class DataUnit {
|
|
|
293
336
|
*/
|
|
294
337
|
gotoPage(page, executionCtx) {
|
|
295
338
|
return __awaiter(this, void 0, void 0, function* () {
|
|
339
|
+
if (this._pageSize === 0) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
296
342
|
let request = getCurrentRequest(this._stateManager);
|
|
297
343
|
if (!request) {
|
|
298
344
|
request = {
|
|
@@ -333,12 +379,13 @@ export default class DataUnit {
|
|
|
333
379
|
return this.gotoPage(getCurrentPage(this._stateManager) - 1, executionCtx);
|
|
334
380
|
});
|
|
335
381
|
}
|
|
336
|
-
getLoadDataRequest(quickFilter, source) {
|
|
382
|
+
getLoadDataRequest(quickFilter, source, keepSelection) {
|
|
337
383
|
const request = {
|
|
338
384
|
filters: (quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.filter) ? [quickFilter.filter] : this.getFilters(),
|
|
339
385
|
sort: this.getSort(),
|
|
340
386
|
parentRecordId: this.getParentRecordId(),
|
|
341
|
-
source
|
|
387
|
+
source,
|
|
388
|
+
keepSelection
|
|
342
389
|
};
|
|
343
390
|
if (quickFilter) {
|
|
344
391
|
request.quickFilter = quickFilter;
|
|
@@ -405,7 +452,16 @@ export default class DataUnit {
|
|
|
405
452
|
Promise.all(dispatchPromisses).then(() => resolve());
|
|
406
453
|
}).catch(cause => {
|
|
407
454
|
const { errorCode } = cause;
|
|
455
|
+
this.dispatchAction(Action.SAVING_ERROR);
|
|
408
456
|
this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
457
|
+
if (cause instanceof ServiceCanceledException) {
|
|
458
|
+
console.debug("Service canceled: " + cause.message);
|
|
459
|
+
resolve();
|
|
460
|
+
}
|
|
461
|
+
if (cause instanceof SilentException) {
|
|
462
|
+
fail(cause);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
409
465
|
fail(new ErrorException("Erro ao salvar alterações", cause, errorCode));
|
|
410
466
|
});
|
|
411
467
|
}
|
|
@@ -509,9 +565,10 @@ export default class DataUnit {
|
|
|
509
565
|
const currentRecordsKeys = Array.from(getCurrentRecords(this._stateManager).keys());
|
|
510
566
|
const removedIndex = recordIds
|
|
511
567
|
.map(id => currentRecordsKeys.indexOf(id))
|
|
512
|
-
.filter(index => index > -1)
|
|
568
|
+
.filter(index => index > -1)
|
|
569
|
+
.sort((a, b) => a - b);
|
|
513
570
|
const nextIndex = Math.min(removedIndex.slice(-1)[0] + 1, currentRecordsKeys.length);
|
|
514
|
-
const selectionAfterRemove = [currentRecordsKeys[nextIndex]];
|
|
571
|
+
const selectionAfterRemove = currentRecordsKeys[nextIndex] ? [currentRecordsKeys[nextIndex]] : [];
|
|
515
572
|
this.dispatchAction(Action.RECORDS_REMOVED, { records: removedIds, cachedRecords, removedIndex, buffered: false, selectionAfterRemove }, executionCtx);
|
|
516
573
|
this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
517
574
|
resolve(removedIds);
|
|
@@ -591,7 +648,7 @@ export default class DataUnit {
|
|
|
591
648
|
*
|
|
592
649
|
*/
|
|
593
650
|
addInterceptor(interceptor) {
|
|
594
|
-
this._interceptors.
|
|
651
|
+
this._interceptors.set(interceptor.interceptAction.toString(), interceptor);
|
|
595
652
|
}
|
|
596
653
|
/**
|
|
597
654
|
*
|
|
@@ -601,7 +658,7 @@ export default class DataUnit {
|
|
|
601
658
|
*
|
|
602
659
|
*/
|
|
603
660
|
removeInterceptor(interceptor) {
|
|
604
|
-
this._interceptors
|
|
661
|
+
this._interceptors.delete(interceptor.interceptAction.toString());
|
|
605
662
|
}
|
|
606
663
|
/**
|
|
607
664
|
*
|
|
@@ -700,7 +757,8 @@ export default class DataUnit {
|
|
|
700
757
|
*
|
|
701
758
|
*/
|
|
702
759
|
set records(records) {
|
|
703
|
-
this.
|
|
760
|
+
const paginationInfo = this.getPaginationInfo();
|
|
761
|
+
this.dispatchAction(Action.DATA_LOADED, { records, paginationInfo }, undefined);
|
|
704
762
|
}
|
|
705
763
|
/**
|
|
706
764
|
*
|
|
@@ -787,6 +845,9 @@ export default class DataUnit {
|
|
|
787
845
|
copySelected(executionCtx) {
|
|
788
846
|
const selectionInfo = this.getSelectionInfo();
|
|
789
847
|
if (selectionInfo) {
|
|
848
|
+
if (selectionInfo.isAllRecords()) {
|
|
849
|
+
throw new Error("Erro interno: Impossível copiar os registros selecionados pois a seleção atual é virtual.");
|
|
850
|
+
}
|
|
790
851
|
const selectedRecords = selectionInfo.records;
|
|
791
852
|
if (selectedRecords) {
|
|
792
853
|
this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
|
|
@@ -845,27 +906,35 @@ export default class DataUnit {
|
|
|
845
906
|
* @param fieldName -Identificador do campo a ser modificado.
|
|
846
907
|
* @param newValue - Valor a ser inserido no campo.
|
|
847
908
|
* @param records - Indica quais registros foram afetados pela alteração no valor do campo.
|
|
909
|
+
* @param options - Configurações do evento
|
|
848
910
|
* @returns - Promise que será resolvida quando o novo valor for persistido no state.
|
|
849
911
|
*
|
|
850
|
-
|
|
851
|
-
setFieldValue(fieldName, newValue, records) {
|
|
912
|
+
*/
|
|
913
|
+
setFieldValue(fieldName, newValue, records, options) {
|
|
852
914
|
return __awaiter(this, void 0, void 0, function* () {
|
|
853
|
-
|
|
915
|
+
const noRecordSelected = !this.hasNewRecord() && !this.getSelectedRecord();
|
|
916
|
+
const suppressCreateNewRecord = options === null || options === void 0 ? void 0 : options.suppressCreateNewRecord;
|
|
917
|
+
if (noRecordSelected && suppressCreateNewRecord)
|
|
918
|
+
return Promise.resolve(false);
|
|
919
|
+
if (noRecordSelected)
|
|
854
920
|
yield this.addRecord();
|
|
855
921
|
const typedValue = this.validateAndTypeValue(fieldName, newValue);
|
|
856
922
|
const currentValue = this.getFieldValue(fieldName);
|
|
923
|
+
if (!(newValue instanceof Promise) && ObjectUtils.hasEquivalentProps(currentValue, typedValue)) {
|
|
924
|
+
return Promise.resolve(false);
|
|
925
|
+
}
|
|
857
926
|
if (newValue instanceof Promise) {
|
|
858
927
|
const promise = new Promise(accept => {
|
|
859
928
|
newValue.then(resolvedValue => {
|
|
860
929
|
this.dispatchAction(Action.DATA_RESOLVED, { [fieldName]: resolvedValue, records }, undefined);
|
|
861
|
-
accept(this.setFieldValue(fieldName, resolvedValue, records));
|
|
930
|
+
accept(this.setFieldValue(fieldName, resolvedValue, records, options));
|
|
862
931
|
});
|
|
863
932
|
});
|
|
864
933
|
this._savingLockers.push(promise);
|
|
865
934
|
return promise;
|
|
866
935
|
}
|
|
867
936
|
if (currentValue !== typedValue) {
|
|
868
|
-
const promise = this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records }, undefined);
|
|
937
|
+
const promise = this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records }, undefined, options);
|
|
869
938
|
this._savingLockers.push(promise);
|
|
870
939
|
return promise;
|
|
871
940
|
}
|
|
@@ -884,6 +953,17 @@ export default class DataUnit {
|
|
|
884
953
|
setInvalidField(fieldName, message, recordId) {
|
|
885
954
|
this.dispatchAction(Action.FIELD_INVALIDATED, { fieldName, message, recordId }, undefined);
|
|
886
955
|
}
|
|
956
|
+
/**
|
|
957
|
+
*
|
|
958
|
+
* Cancela o saving exibindo os campos invalidos.
|
|
959
|
+
*
|
|
960
|
+
* @param filds - Lista dos campos
|
|
961
|
+
* @param recordId - Indica qual registro está com os campos inválido.
|
|
962
|
+
*
|
|
963
|
+
*/
|
|
964
|
+
savingCanceled(fields, recordId) {
|
|
965
|
+
this.dispatchAction(Action.SAVING_CANCELED, { fields, recordId }, undefined);
|
|
966
|
+
}
|
|
887
967
|
/**
|
|
888
968
|
*
|
|
889
969
|
* Limpa campos inválidos.
|
|
@@ -982,7 +1062,7 @@ export default class DataUnit {
|
|
|
982
1062
|
setSelection(selection, executionCtx) {
|
|
983
1063
|
return new Promise(resolve => {
|
|
984
1064
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }, executionCtx)
|
|
985
|
-
.then(() => resolve(getSelectionInfo(
|
|
1065
|
+
.then(() => resolve(this.getSelectionInfo()));
|
|
986
1066
|
});
|
|
987
1067
|
}
|
|
988
1068
|
/**
|
|
@@ -1001,30 +1081,44 @@ export default class DataUnit {
|
|
|
1001
1081
|
*
|
|
1002
1082
|
* @param selection - IDs dos registros selecionados no snapshot atual
|
|
1003
1083
|
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
1004
|
-
*
|
|
1005
1084
|
* @returns - Informações sobre a seleção.
|
|
1006
1085
|
*/
|
|
1007
1086
|
updatePageSelection(selection, executionCtx) {
|
|
1008
|
-
if (!selection)
|
|
1087
|
+
if (!selection)
|
|
1009
1088
|
return Promise.resolve(this.getSelectionInfo());
|
|
1010
|
-
}
|
|
1011
1089
|
return new Promise(resolve => {
|
|
1012
|
-
const newSelection = new Set(
|
|
1013
|
-
const currentRecords = getCurrentRecords(this._stateManager) || new Map();
|
|
1014
|
-
Array.from(currentRecords.keys()).forEach(recordId => {
|
|
1015
|
-
if (selection.includes(recordId)) {
|
|
1016
|
-
newSelection.add(recordId);
|
|
1017
|
-
}
|
|
1018
|
-
else {
|
|
1019
|
-
newSelection.delete(recordId);
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1090
|
+
const newSelection = new Set(selection);
|
|
1022
1091
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) }, executionCtx)
|
|
1023
|
-
.then(() =>
|
|
1024
|
-
|
|
1025
|
-
|
|
1092
|
+
.then(() => resolve(this.getSelectionInfo()));
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
updatePageSelectionAll(addRecords) {
|
|
1096
|
+
return new Promise(resolve => {
|
|
1097
|
+
const newSelection = new Set();
|
|
1098
|
+
const cachedSelection = getSelection(this._stateManager);
|
|
1099
|
+
cachedSelection.forEach(item => newSelection.add(item));
|
|
1100
|
+
const recordsIds = this.records.map(r => r.__record__id__);
|
|
1101
|
+
recordsIds.forEach(id => addRecords ? newSelection.add(id) : newSelection.delete(id));
|
|
1102
|
+
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) })
|
|
1103
|
+
.then(() => resolve(this.getSelectionInfo()));
|
|
1026
1104
|
});
|
|
1027
1105
|
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Seleciona todos os registros da página.
|
|
1108
|
+
*
|
|
1109
|
+
* @returns - Informações sobre a seleção.
|
|
1110
|
+
*/
|
|
1111
|
+
selectAllRecords() {
|
|
1112
|
+
return this.updatePageSelectionAll(true);
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Desseleciona todos os registros da página.
|
|
1116
|
+
*
|
|
1117
|
+
* @returns - Informações sobre a seleção.
|
|
1118
|
+
*/
|
|
1119
|
+
unSelectAllRecords() {
|
|
1120
|
+
return this.updatePageSelectionAll(false);
|
|
1121
|
+
}
|
|
1028
1122
|
/**
|
|
1029
1123
|
*
|
|
1030
1124
|
* Obtém informações sobre a seleção atual.
|
|
@@ -1033,7 +1127,14 @@ export default class DataUnit {
|
|
|
1033
1127
|
*
|
|
1034
1128
|
**/
|
|
1035
1129
|
getSelectionInfo() {
|
|
1036
|
-
|
|
1130
|
+
var _a;
|
|
1131
|
+
const selectionInfo = getSelectionInfo(this._stateManager);
|
|
1132
|
+
selectionInfo.getAllRecords = () => { var _a; return (_a = this.allRecordsLoader) === null || _a === void 0 ? void 0 : _a.call(this, this); };
|
|
1133
|
+
if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
|
|
1134
|
+
const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort);
|
|
1135
|
+
(_a = selectionInfo.records) === null || _a === void 0 ? void 0 : _a.sort(sortingFunction);
|
|
1136
|
+
}
|
|
1137
|
+
return selectionInfo;
|
|
1037
1138
|
}
|
|
1038
1139
|
/**
|
|
1039
1140
|
*
|
|
@@ -1045,6 +1146,14 @@ export default class DataUnit {
|
|
|
1045
1146
|
getSelectedRecord() {
|
|
1046
1147
|
return getSelectedRecord(this._stateManager);
|
|
1047
1148
|
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Retorna o DataUnit pai
|
|
1151
|
+
*
|
|
1152
|
+
* @returns DataUnit pai ou undefined
|
|
1153
|
+
*/
|
|
1154
|
+
getParentDataUnit() {
|
|
1155
|
+
return this._parentDataUnit;
|
|
1156
|
+
}
|
|
1048
1157
|
/**
|
|
1049
1158
|
*
|
|
1050
1159
|
* Limpa todos os registros do DataUnit
|
|
@@ -1132,12 +1241,25 @@ export default class DataUnit {
|
|
|
1132
1241
|
*
|
|
1133
1242
|
* Retorna se existe algum tipo de alteração pendente.
|
|
1134
1243
|
*
|
|
1244
|
+
* @param ignoreChildren: Define se deverá ignorar alterações pendentes no DataUnit filho.
|
|
1135
1245
|
* @returns Verdadeiro se existir alterações pendentes.
|
|
1136
1246
|
*
|
|
1137
1247
|
*/
|
|
1138
|
-
isDirty() {
|
|
1248
|
+
isDirty(ignoreChildren) {
|
|
1249
|
+
if (ignoreChildren)
|
|
1250
|
+
return isDirty(this._stateManager);
|
|
1139
1251
|
return isDirty(this._stateManager) || this.childrenIsDirty();
|
|
1140
1252
|
}
|
|
1253
|
+
/**
|
|
1254
|
+
*
|
|
1255
|
+
* Retorna se existe alterações pendentes no DataUnit pai.
|
|
1256
|
+
*
|
|
1257
|
+
* @returns Verdadeiro se existir alterações pendentes e Falso caso não exista alterações ou não exista DataUnit pai.
|
|
1258
|
+
*
|
|
1259
|
+
*/
|
|
1260
|
+
isParentDirty() {
|
|
1261
|
+
return this._parentDataUnit ? this._parentDataUnit.isDirty(true) : false;
|
|
1262
|
+
}
|
|
1141
1263
|
/**
|
|
1142
1264
|
*
|
|
1143
1265
|
* Retorna se existe algum DataUnit detail com alterações pendentes.
|
|
@@ -1299,18 +1421,18 @@ export default class DataUnit {
|
|
|
1299
1421
|
* @returns - Verdadeiro se ação iniciada.
|
|
1300
1422
|
*
|
|
1301
1423
|
*/
|
|
1302
|
-
dispatchAction(actionType, payload, executionCtx) {
|
|
1424
|
+
dispatchAction(actionType, payload, executionCtx, options) {
|
|
1303
1425
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1304
1426
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
1305
1427
|
let action = new DataUnitAction(actionType, payload);
|
|
1306
1428
|
if (executionCtx && executionCtx.before) {
|
|
1307
1429
|
action = executionCtx.before(action);
|
|
1308
1430
|
}
|
|
1309
|
-
if (action && this._interceptors && this._interceptors.
|
|
1431
|
+
if (action && this._interceptors && this._interceptors.size > 0) {
|
|
1310
1432
|
action = yield this.intercept(action, this._interceptors.values());
|
|
1311
1433
|
}
|
|
1312
1434
|
if (action) {
|
|
1313
|
-
this.doDispatchAction(action);
|
|
1435
|
+
this.doDispatchAction(action, options);
|
|
1314
1436
|
if (executionCtx && executionCtx.after) {
|
|
1315
1437
|
executionCtx.after(action);
|
|
1316
1438
|
}
|
|
@@ -1350,17 +1472,14 @@ export default class DataUnit {
|
|
|
1350
1472
|
* @param action - Ações em execução no DataUnit.
|
|
1351
1473
|
*
|
|
1352
1474
|
*/
|
|
1353
|
-
doDispatchAction(action) {
|
|
1475
|
+
doDispatchAction(action, options = {}) {
|
|
1354
1476
|
var _a;
|
|
1355
1477
|
this._stateManager.process(action);
|
|
1356
1478
|
(_a = this === null || this === void 0 ? void 0 : this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.dispatchAction(Action.CHILD_CHANGED, { srcAction: action, srcDataUnit: this });
|
|
1357
1479
|
this._observers.forEach(f => {
|
|
1358
|
-
|
|
1359
|
-
if some observer throws exceptions,
|
|
1360
|
-
should be continued
|
|
1361
|
-
*/
|
|
1480
|
+
//if some observer throws exceptions, should be continued
|
|
1362
1481
|
try {
|
|
1363
|
-
f(action);
|
|
1482
|
+
f(action, options);
|
|
1364
1483
|
}
|
|
1365
1484
|
catch (e) {
|
|
1366
1485
|
console.warn("[DataUnit] error while call observer", e);
|
|
@@ -1395,20 +1514,36 @@ export default class DataUnit {
|
|
|
1395
1514
|
* Ela vai ser chamada sempre que uma ação for despachada (dispatchAction()).
|
|
1396
1515
|
*
|
|
1397
1516
|
* @param observer - Função que recebe como parâmetro as ações que serão monitoradas.
|
|
1398
|
-
*
|
|
1517
|
+
* @param uuid - Identificador do observer. Quando não informado, será gerado um identificador aleatório.
|
|
1399
1518
|
*/
|
|
1400
|
-
subscribe(observer) {
|
|
1401
|
-
|
|
1519
|
+
subscribe(observer, uuid) {
|
|
1520
|
+
if (uuid) {
|
|
1521
|
+
this._observers.set(uuid, observer);
|
|
1522
|
+
}
|
|
1523
|
+
else {
|
|
1524
|
+
uuid = StringUtils.generateUUID();
|
|
1525
|
+
this._observers.set(uuid, observer);
|
|
1526
|
+
}
|
|
1527
|
+
return uuid;
|
|
1402
1528
|
}
|
|
1403
1529
|
/**
|
|
1404
1530
|
*
|
|
1405
1531
|
* Remove um observer existente.
|
|
1406
1532
|
*
|
|
1407
1533
|
* @param observer - Observer que se deseja remover.
|
|
1408
|
-
*
|
|
1534
|
+
* @param uuid - Identificador do observer. Quando não informado o delete removera com base no equals do observer.
|
|
1409
1535
|
*/
|
|
1410
|
-
unsubscribe(observer) {
|
|
1411
|
-
|
|
1536
|
+
unsubscribe(observer, uuid) {
|
|
1537
|
+
if (uuid) {
|
|
1538
|
+
this._observers.delete(uuid);
|
|
1539
|
+
}
|
|
1540
|
+
else {
|
|
1541
|
+
this._observers.forEach((valor, chave) => {
|
|
1542
|
+
if (valor == observer) {
|
|
1543
|
+
this._observers.delete(chave);
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1412
1547
|
}
|
|
1413
1548
|
/**
|
|
1414
1549
|
*
|
|
@@ -1420,19 +1555,21 @@ export default class DataUnit {
|
|
|
1420
1555
|
reloadCurrentRecord() {
|
|
1421
1556
|
return new Promise((resolve, fail) => __awaiter(this, void 0, void 0, function* () {
|
|
1422
1557
|
const selection = getSelection(this._stateManager);
|
|
1423
|
-
this.dispatchAction(Action.LOADING_RECORD, selection);
|
|
1558
|
+
yield this.dispatchAction(Action.LOADING_RECORD, selection);
|
|
1424
1559
|
if (!this.recordLoader || !this.dataLoader) {
|
|
1425
|
-
this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
1560
|
+
yield this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
1561
|
+
resolve([]);
|
|
1426
1562
|
return;
|
|
1427
1563
|
}
|
|
1428
|
-
this.recordLoader(this, selection).then(response => {
|
|
1429
|
-
this.dispatchAction(Action.RECORD_LOADED, response);
|
|
1430
|
-
this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
1431
|
-
|
|
1432
|
-
|
|
1564
|
+
this.recordLoader(this, selection).then((response) => __awaiter(this, void 0, void 0, function* () {
|
|
1565
|
+
yield this.dispatchAction(Action.RECORD_LOADED, response);
|
|
1566
|
+
yield this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
1567
|
+
resolve(response);
|
|
1568
|
+
})).catch((cause) => __awaiter(this, void 0, void 0, function* () {
|
|
1569
|
+
yield this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
1433
1570
|
const { errorCode } = cause;
|
|
1434
1571
|
fail(new ErrorException("Erro ao recarregar registro", cause, errorCode));
|
|
1435
|
-
});
|
|
1572
|
+
}));
|
|
1436
1573
|
}));
|
|
1437
1574
|
}
|
|
1438
1575
|
/**
|
|
@@ -1515,10 +1652,11 @@ export default class DataUnit {
|
|
|
1515
1652
|
* @param fieldName - nome do campo para ficar invisível.
|
|
1516
1653
|
*
|
|
1517
1654
|
*/
|
|
1518
|
-
hideField(fieldName) {
|
|
1655
|
+
hideField(fieldName, options) {
|
|
1519
1656
|
const fieldDescriptor = this.getField(fieldName);
|
|
1520
1657
|
if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.visible) === true) {
|
|
1521
1658
|
fieldDescriptor.visible = false;
|
|
1659
|
+
fieldDescriptor.properties = Object.assign(Object.assign({}, fieldDescriptor.properties), { visibleOnConfig: options.visibleOnConfig });
|
|
1522
1660
|
this.metadata = Object.assign({}, this.metadata);
|
|
1523
1661
|
}
|
|
1524
1662
|
}
|
|
@@ -1570,10 +1708,13 @@ export default class DataUnit {
|
|
|
1570
1708
|
getSelection() {
|
|
1571
1709
|
console.warn("DataUnit: O método `getSelection` foi descontinuado. Use o método `getSelectionInfo`.");
|
|
1572
1710
|
const selection = this.getSelectionInfo();
|
|
1573
|
-
if (selection
|
|
1711
|
+
if (selection == undefined) {
|
|
1712
|
+
return [];
|
|
1713
|
+
}
|
|
1714
|
+
if (selection.isAllRecords()) {
|
|
1574
1715
|
throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
|
|
1575
1716
|
}
|
|
1576
|
-
return
|
|
1717
|
+
return selection === null || selection === void 0 ? void 0 : selection.recordIds;
|
|
1577
1718
|
}
|
|
1578
1719
|
/**
|
|
1579
1720
|
* Adiciona um campo stand-alone ao dataUnit.
|
|
@@ -1603,6 +1744,9 @@ export default class DataUnit {
|
|
|
1603
1744
|
}));
|
|
1604
1745
|
return loadingLockerResolver || Promise.resolve;
|
|
1605
1746
|
}
|
|
1747
|
+
set allowReleaseCallbacks(allow) {
|
|
1748
|
+
this._allowReleaseCallbacks = allow;
|
|
1749
|
+
}
|
|
1606
1750
|
processLoadingLockers() {
|
|
1607
1751
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1608
1752
|
if (this._loadingLockers.length) {
|
|
@@ -1613,6 +1757,7 @@ export default class DataUnit {
|
|
|
1613
1757
|
}
|
|
1614
1758
|
}
|
|
1615
1759
|
DataUnit.CHANGING_PAGE_LOADING_SOURCE = "CHANGING_PAGE_LOADING_SOURCE";
|
|
1760
|
+
DataUnit.ALL_RECORDS_SELECTION_SOURCE = "ALL_RECORDS_SELECTION_SOURCE";
|
|
1616
1761
|
DataUnit.DEFAULT_DATAUNIT_NAME = "dataunit";
|
|
1617
1762
|
export var ChangeOperation;
|
|
1618
1763
|
(function (ChangeOperation) {
|
|
@@ -1698,7 +1843,10 @@ export class SelectionInfo {
|
|
|
1698
1843
|
}
|
|
1699
1844
|
get records() {
|
|
1700
1845
|
if (this.isAllRecords()) {
|
|
1701
|
-
|
|
1846
|
+
if (this.getAllRecords != undefined) {
|
|
1847
|
+
return this.getAllRecords();
|
|
1848
|
+
}
|
|
1849
|
+
throw new Error("Erro interno: Impossível retornar os registros selecionados numa seleção virtual.");
|
|
1702
1850
|
}
|
|
1703
1851
|
return this._records;
|
|
1704
1852
|
}
|