@sankhyalabs/core 6.1.0-dev.2 → 6.1.0-dev.3
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/Change.md +11 -11
- package/.docs/classes/ColumnFilterManager.md +6 -6
- package/.docs/classes/DataUnit.md +157 -157
- package/.docs/classes/DataUnitLoaderUtils.md +6 -6
- package/.docs/classes/SelectionInfo.md +16 -16
- package/.docs/enumerations/ChangeOperation.md +4 -4
- package/.docs/enumerations/SelectionMode.md +2 -2
- package/.docs/functions/defaultDataLoader.md +1 -1
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/PaginationInfoBuilderParams.md +3 -3
- 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/type-aliases/DataUnitEventOptions.md +1 -1
- package/dist/dataunit/Changes.d.ts +52 -0
- package/dist/dataunit/Changes.js +64 -0
- package/dist/dataunit/Changes.js.map +1 -0
- package/dist/dataunit/DataUnit.d.ts +9 -129
- package/dist/dataunit/DataUnit.js +87 -177
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/DataUnitHelper.d.ts +2 -1
- package/dist/dataunit/DataUnitHelper.js.map +1 -1
- package/dist/dataunit/SelectionInfo.d.ts +16 -0
- package/dist/dataunit/SelectionInfo.js +39 -0
- package/dist/dataunit/SelectionInfo.js.map +1 -0
- package/dist/dataunit/interfaces/dataUnit.d.ts +61 -0
- package/dist/dataunit/interfaces/dataUnit.js +13 -0
- package/dist/dataunit/interfaces/dataUnit.js.map +1 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +2 -1
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -1
- package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
- package/dist/dataunit/loading/LoadDataResponse.d.ts +1 -1
- package/dist/dataunit/sorting/FieldComparator.d.ts +1 -1
- package/dist/dataunit/state/slice/AddedRecordsSlice.d.ts +1 -1
- package/dist/dataunit/state/slice/ChangesSlice.d.ts +2 -1
- package/dist/dataunit/state/slice/ChangesSlice.js +2 -1
- package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.d.ts +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.d.ts +2 -1
- package/dist/dataunit/state/slice/SelectionSlice.js +2 -1
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SnapshotSlice.d.ts +1 -1
- package/dist/dataunit/state/slice/WaitingChangesSlice.d.ts +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/ColumnFilterManager.d.ts +2 -1
- package/dist/utils/ColumnFilterManager.js.map +1 -1
- package/dist/utils/SortingUtils.d.ts +1 -1
- package/package.json +2 -1
- package/reports/test-report.xml +648 -447
- package/src/dataunit/Changes.ts +77 -0
- package/src/dataunit/DataUnit.ts +242 -397
- package/src/dataunit/DataUnitHelper.ts +2 -1
- package/src/dataunit/SelectionInfo.ts +55 -0
- package/src/dataunit/interfaces/dataUnit.ts +71 -0
- package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +2 -1
- package/src/dataunit/loading/LoadDataRequest.ts +1 -1
- package/src/dataunit/loading/LoadDataResponse.ts +1 -1
- package/src/dataunit/sorting/FieldComparator.ts +1 -1
- package/src/dataunit/state/slice/AddedRecordsSlice.ts +1 -1
- package/src/dataunit/state/slice/ChangesSlice.ts +2 -1
- package/src/dataunit/state/slice/LoadingControlSlice.ts +1 -2
- package/src/dataunit/state/slice/RecordsSlice.ts +3 -2
- package/src/dataunit/state/slice/SelectionSlice.ts +2 -1
- package/src/dataunit/state/slice/SnapshotSlice.ts +1 -1
- package/src/dataunit/state/slice/WaitingChangesSlice.ts +1 -1
- package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +1 -1
- package/src/index.ts +4 -1
- package/src/utils/ColumnFilterManager.ts +2 -1
- package/src/utils/SortingUtils.ts +1 -1
- package/test/dataunit/AccessParentsDataUnit.spec.ts +69 -0
- package/test/dataunit/Actions.spec.ts +74 -0
- package/test/dataunit/Change.spec.ts +66 -0
- package/test/dataunit/FieldManager.spec.ts +286 -0
- package/test/dataunit/FilterSortsLockersAndObservers.spec.ts +339 -0
- package/test/dataunit/InfoManager.spec.ts +254 -0
- package/test/dataunit/LoadDataAndMetadata.spec.ts +269 -0
- package/test/dataunit/RecodsSelection.spec.ts +229 -0
- package/test/dataunit/RecordsManager.spec.ts +323 -0
- package/test/dataunit/SavingData.spec.ts +206 -0
- package/test/dataunit/SelectionInfo.spec.ts +143 -0
- package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +2 -1
- package/test/dataunit/loader/utils/createDataUnitMock.ts +34 -0
- package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +1 -1
- package/test/dataunit/resources/metadata.ts +39 -0
- package/test/dataunit/resources/records.ts +29 -0
- package/test/util/ColumnFilterManager.spec.ts +2 -1
- package/tsconfig.json +1 -0
- package/src/dataunit/test/DataUnit.spec.ts +0 -44
package/src/dataunit/DataUnit.ts
CHANGED
|
@@ -29,12 +29,15 @@ import { getLoadingProperties, LoadingPropertiesReducer } from "./state/slice/Lo
|
|
|
29
29
|
import SortingUtils from "../utils/SortingUtils.js";
|
|
30
30
|
import ServiceCanceledException from "../exceptions/ServiceCanceledException.js";
|
|
31
31
|
import SilentException from "../exceptions/SilentException.js";
|
|
32
|
+
import { DataUnitEventOptions, DUActionInterceptor, HideFieldOptions, LoadDataParams, QuickFilter, Record, SavedRecord, SelectionMode, WaitingChange } from "./interfaces/dataUnit.js";
|
|
33
|
+
import { Change } from "./Changes.js";
|
|
34
|
+
import { SelectionInfo } from "./SelectionInfo.js";
|
|
32
35
|
|
|
33
36
|
/***
|
|
34
37
|
* `DataUnit`: Atua como uma camada de abstração entre o back-end e a interface do usuário.
|
|
35
38
|
*/
|
|
36
39
|
export default class DataUnit {
|
|
37
|
-
|
|
40
|
+
|
|
38
41
|
public static CHANGING_PAGE_LOADING_SOURCE = "CHANGING_PAGE_LOADING_SOURCE";
|
|
39
42
|
public static ALL_RECORDS_SELECTION_SOURCE = "ALL_RECORDS_SELECTION_SOURCE";
|
|
40
43
|
public static DEFAULT_DATAUNIT_NAME = "dataunit";
|
|
@@ -57,7 +60,7 @@ export default class DataUnit {
|
|
|
57
60
|
private _cancelPagination: boolean = false;
|
|
58
61
|
private _isMultipleEdition: boolean = false;
|
|
59
62
|
private _fieldSourceValue: Map<string, string> = new Map<string, string>();
|
|
60
|
-
|
|
63
|
+
|
|
61
64
|
public metadataLoader?: (dataUnit: DataUnit) => Promise<UnitMetadata>;
|
|
62
65
|
public dataLoader?: (dataUnit: DataUnit, request: LoadDataRequest) => Promise<LoadDataResponse>;
|
|
63
66
|
public saveLoader?: (dataUnit: DataUnit, changes: Array<Change>) => Promise<Array<SavedRecord>>;
|
|
@@ -100,9 +103,9 @@ export default class DataUnit {
|
|
|
100
103
|
/**
|
|
101
104
|
* Desfaz vinculos do DataUnit. Chamado quando o DU não é mais necessário.
|
|
102
105
|
*/
|
|
103
|
-
public release(){
|
|
106
|
+
public release() {
|
|
104
107
|
DataUnitStorage.remove(this._name);
|
|
105
|
-
if(this._parentDataUnit){
|
|
108
|
+
if (this._parentDataUnit) {
|
|
106
109
|
this._parentDataUnit.unsubscribe(this.onDataUnitParentEvent);
|
|
107
110
|
this._parentDataUnit.removeChildDataunit(this._name);
|
|
108
111
|
}
|
|
@@ -120,8 +123,8 @@ export default class DataUnit {
|
|
|
120
123
|
* - Observers
|
|
121
124
|
* - Sorting Providers
|
|
122
125
|
*/
|
|
123
|
-
public releaseCallbacks(){
|
|
124
|
-
if(!this._allowReleaseCallbacks) return;
|
|
126
|
+
public releaseCallbacks() {
|
|
127
|
+
if (!this._allowReleaseCallbacks) return;
|
|
125
128
|
|
|
126
129
|
this._observers = new Map();
|
|
127
130
|
this._filterProviders = new Map<string, FilterProvider>();
|
|
@@ -138,8 +141,8 @@ export default class DataUnit {
|
|
|
138
141
|
* @param value - Valor da propriedade
|
|
139
142
|
*
|
|
140
143
|
*/
|
|
141
|
-
public addGlobalLoaderProp(name: string, value: string):void{
|
|
142
|
-
this.dispatchAction(Action.LOADING_PROPERTY_ADDED, {[name]: value});
|
|
144
|
+
public addGlobalLoaderProp(name: string, value: string): void {
|
|
145
|
+
this.dispatchAction(Action.LOADING_PROPERTY_ADDED, { [name]: value });
|
|
143
146
|
}
|
|
144
147
|
|
|
145
148
|
/**
|
|
@@ -147,11 +150,11 @@ export default class DataUnit {
|
|
|
147
150
|
*
|
|
148
151
|
* @returns - Todas as propriedades desde o final do último loader.
|
|
149
152
|
*/
|
|
150
|
-
public getGlobalLoaderProps(): Map<string, string>{
|
|
153
|
+
public getGlobalLoaderProps(): Map<string, string> {
|
|
151
154
|
return getLoadingProperties(this._stateManager) || new Map();
|
|
152
155
|
}
|
|
153
156
|
|
|
154
|
-
public get dataUnitId(): string{
|
|
157
|
+
public get dataUnitId(): string {
|
|
155
158
|
return this._uuid;
|
|
156
159
|
}
|
|
157
160
|
|
|
@@ -167,7 +170,7 @@ export default class DataUnit {
|
|
|
167
170
|
* Define se o dataUnit tem um recarregamento pendente.
|
|
168
171
|
* @param isWaiting
|
|
169
172
|
*/
|
|
170
|
-
public setWaitingToReload(isWaiting: boolean){
|
|
173
|
+
public setWaitingToReload(isWaiting: boolean) {
|
|
171
174
|
this._waitingToReload = isWaiting;
|
|
172
175
|
}
|
|
173
176
|
|
|
@@ -197,7 +200,7 @@ export default class DataUnit {
|
|
|
197
200
|
*/
|
|
198
201
|
public set isMultipleEdition(isMultipleEdition) {
|
|
199
202
|
this._isMultipleEdition = isMultipleEdition;
|
|
200
|
-
this.dispatchAction(Action.MULTIPLE_EDITION_CHANGED, {isMultipleEdition});
|
|
203
|
+
this.dispatchAction(Action.MULTIPLE_EDITION_CHANGED, { isMultipleEdition });
|
|
201
204
|
}
|
|
202
205
|
|
|
203
206
|
/**
|
|
@@ -233,7 +236,7 @@ export default class DataUnit {
|
|
|
233
236
|
*
|
|
234
237
|
*/
|
|
235
238
|
private onDataUnitParentEvent = (action: DataUnitAction) => {
|
|
236
|
-
switch(action.type){
|
|
239
|
+
switch (action.type) {
|
|
237
240
|
case Action.SELECTION_CHANGED:
|
|
238
241
|
case Action.NEXT_SELECTED:
|
|
239
242
|
case Action.PREVIOUS_SELECTED:
|
|
@@ -242,7 +245,7 @@ export default class DataUnit {
|
|
|
242
245
|
case Action.EDITION_CANCELED:
|
|
243
246
|
this.clearDataUnit();
|
|
244
247
|
const selectedRecord = this._parentDataUnit?.getSelectedRecord();
|
|
245
|
-
if(selectedRecord != undefined && !this.isNewRecord(selectedRecord.__record__id__)){
|
|
248
|
+
if (selectedRecord != undefined && !this.isNewRecord(selectedRecord.__record__id__)) {
|
|
246
249
|
this.loadData();
|
|
247
250
|
}
|
|
248
251
|
break;
|
|
@@ -278,15 +281,15 @@ export default class DataUnit {
|
|
|
278
281
|
*/
|
|
279
282
|
private executeLoadData(request: LoadDataRequest, executionCtx?: ExecutionContext, checkLastFilter?: boolean, selectFirstRecord?: boolean): Promise<LoadDataResponse> {
|
|
280
283
|
|
|
281
|
-
if(checkLastFilter && this.isSameRequest(request)){
|
|
282
|
-
const paginationInfo = getPaginationInfo(
|
|
283
|
-
if(paginationInfo){
|
|
284
|
+
if (checkLastFilter && this.isSameRequest(request)) {
|
|
285
|
+
const paginationInfo = this.getPaginationInfo();
|
|
286
|
+
if (paginationInfo) {
|
|
284
287
|
const response: LoadDataResponse = {
|
|
285
288
|
records: getRecords(this._stateManager),
|
|
286
|
-
paginationInfo
|
|
289
|
+
paginationInfo
|
|
287
290
|
};
|
|
288
291
|
|
|
289
|
-
if(selectFirstRecord){
|
|
292
|
+
if (selectFirstRecord) {
|
|
290
293
|
this.requestSelectFirst(executionCtx);
|
|
291
294
|
}
|
|
292
295
|
|
|
@@ -300,21 +303,21 @@ export default class DataUnit {
|
|
|
300
303
|
this.dataLoader(this, request).then(
|
|
301
304
|
async response => {
|
|
302
305
|
await this.dispatchAction(
|
|
303
|
-
Action.DATA_LOADED,
|
|
304
|
-
{...response, keepSelection: request.keepSelection, filters: request.filters, selectFirstRecord},
|
|
306
|
+
Action.DATA_LOADED,
|
|
307
|
+
{ ...response, keepSelection: request.keepSelection, filters: request.filters, selectFirstRecord },
|
|
305
308
|
executionCtx
|
|
306
309
|
);
|
|
307
310
|
|
|
308
311
|
await this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
309
312
|
|
|
310
|
-
if(selectFirstRecord){
|
|
313
|
+
if (selectFirstRecord) {
|
|
311
314
|
this.requestSelectFirst(executionCtx);
|
|
312
315
|
}
|
|
313
316
|
resolve(response);
|
|
314
317
|
}
|
|
315
318
|
).catch(error => {
|
|
316
319
|
console.error(error);
|
|
317
|
-
const {errorCode} = error;
|
|
320
|
+
const { errorCode } = error;
|
|
318
321
|
this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
319
322
|
fail(new ErrorException("Erro ao carregar registros", error, errorCode))
|
|
320
323
|
});
|
|
@@ -323,13 +326,13 @@ export default class DataUnit {
|
|
|
323
326
|
});
|
|
324
327
|
}
|
|
325
328
|
|
|
326
|
-
private requestSelectFirst(executionCtx?: ExecutionContext){
|
|
329
|
+
private requestSelectFirst(executionCtx?: ExecutionContext) {
|
|
327
330
|
window.requestAnimationFrame(() => {
|
|
328
331
|
this.selectFirst(executionCtx);
|
|
329
332
|
})
|
|
330
333
|
}
|
|
331
334
|
|
|
332
|
-
private isSameRequest(request: LoadDataRequest): boolean{
|
|
335
|
+
private isSameRequest(request: LoadDataRequest): boolean {
|
|
333
336
|
const lastRequest = getCurrentRequest(this._stateManager);
|
|
334
337
|
return ObjectUtils.objectToString(request) === ObjectUtils.objectToString(lastRequest || {});
|
|
335
338
|
}
|
|
@@ -354,7 +357,7 @@ export default class DataUnit {
|
|
|
354
357
|
resolve(this.metadata);
|
|
355
358
|
}
|
|
356
359
|
).catch(error => {
|
|
357
|
-
const {errorCode} = error;
|
|
360
|
+
const { errorCode } = error;
|
|
358
361
|
fail(new ErrorException("Erro ao carregar metadados", error, errorCode))
|
|
359
362
|
});
|
|
360
363
|
}
|
|
@@ -362,7 +365,7 @@ export default class DataUnit {
|
|
|
362
365
|
}
|
|
363
366
|
}
|
|
364
367
|
|
|
365
|
-
public async loadDataWithParams({source, keepSelection, selectFirstRecord, executionCtx, checkLastFilter, quickFilter}: LoadDataParams): Promise<LoadDataResponse> {
|
|
368
|
+
public async loadDataWithParams({ source, keepSelection, selectFirstRecord, executionCtx, checkLastFilter, quickFilter }: LoadDataParams): Promise<LoadDataResponse> {
|
|
366
369
|
return await this.loadData(quickFilter, executionCtx, checkLastFilter, source, selectFirstRecord, keepSelection);
|
|
367
370
|
}
|
|
368
371
|
|
|
@@ -378,13 +381,13 @@ export default class DataUnit {
|
|
|
378
381
|
*
|
|
379
382
|
*/
|
|
380
383
|
public async loadData(quickFilter?: QuickFilter, executionCtx?: ExecutionContext, checkLastFilter?: boolean, source?: string, selectFirstRecord?: boolean, keepSelection?: boolean): Promise<LoadDataResponse> {
|
|
381
|
-
|
|
384
|
+
|
|
382
385
|
await this.processLoadingLockers();
|
|
383
386
|
|
|
384
387
|
if (this._parentDataUnit) {
|
|
385
388
|
const parentRecord = this._parentDataUnit.getSelectedRecord();
|
|
386
|
-
if(parentRecord == undefined || this._parentDataUnit.isNewRecord(parentRecord.__record__id__)){
|
|
387
|
-
if(this.records){
|
|
389
|
+
if (parentRecord == undefined || this._parentDataUnit.isNewRecord(parentRecord.__record__id__)) {
|
|
390
|
+
if (this.records) {
|
|
388
391
|
this.clearDataUnit();
|
|
389
392
|
}
|
|
390
393
|
return Promise.resolve({
|
|
@@ -408,7 +411,7 @@ export default class DataUnit {
|
|
|
408
411
|
*
|
|
409
412
|
*/
|
|
410
413
|
public async gotoPage(page: number, executionCtx?: ExecutionContext): Promise<LoadDataResponse | void> {
|
|
411
|
-
if(this._pageSize === 0) {
|
|
414
|
+
if (this._pageSize === 0) {
|
|
412
415
|
return;
|
|
413
416
|
}
|
|
414
417
|
|
|
@@ -479,13 +482,13 @@ export default class DataUnit {
|
|
|
479
482
|
return request;
|
|
480
483
|
}
|
|
481
484
|
|
|
482
|
-
private async notifySavingData(executionCtx?: ExecutionContext): Promise<boolean>{
|
|
485
|
+
private async notifySavingData(executionCtx?: ExecutionContext): Promise<boolean> {
|
|
483
486
|
const notifyPromises: Array<Promise<boolean>> = [];
|
|
484
487
|
Array.from(this._childByName.values()).forEach(
|
|
485
488
|
child => notifyPromises.push(child.notifySavingData(executionCtx))
|
|
486
489
|
);
|
|
487
|
-
|
|
488
|
-
if(isDirty(this._stateManager)){
|
|
490
|
+
|
|
491
|
+
if (isDirty(this._stateManager)) {
|
|
489
492
|
notifyPromises.push(this.dispatchAction(Action.SAVING_DATA, undefined, executionCtx));
|
|
490
493
|
}
|
|
491
494
|
|
|
@@ -494,8 +497,8 @@ export default class DataUnit {
|
|
|
494
497
|
}));
|
|
495
498
|
}
|
|
496
499
|
|
|
497
|
-
private getBeforeSavePromisses(): Array<Promise<any
|
|
498
|
-
let promises = getWaitingChangePromisses(this._stateManager)||[];
|
|
500
|
+
private getBeforeSavePromisses(): Array<Promise<any> | undefined> {
|
|
501
|
+
let promises = getWaitingChangePromisses(this._stateManager) || [];
|
|
499
502
|
promises = promises.concat(this._savingLockers);
|
|
500
503
|
return promises;
|
|
501
504
|
}
|
|
@@ -513,15 +516,18 @@ export default class DataUnit {
|
|
|
513
516
|
const blockingWaitingChanges = getBlockingWaitingChanges(this._stateManager);
|
|
514
517
|
|
|
515
518
|
if (blockingWaitingChanges && blockingWaitingChanges.size > 0) {
|
|
516
|
-
const
|
|
517
|
-
|
|
519
|
+
const entry = blockingWaitingChanges.entries().next().value;
|
|
520
|
+
if (entry) {
|
|
521
|
+
const [_, waitingChange] = entry;
|
|
522
|
+
return Promise.reject(new WaitingChangeException("Aguardando alteração de campo", waitingChange.waitmessage));
|
|
523
|
+
}
|
|
518
524
|
} else {
|
|
519
525
|
if (this.isDirty()) {
|
|
520
526
|
|
|
521
527
|
if (await this.notifySavingData(executionCtx)) {
|
|
522
528
|
const promisses = this.getBeforeSavePromisses();
|
|
523
529
|
return new Promise((resolve, fail) => {
|
|
524
|
-
Promise.all(promisses
|
|
530
|
+
Promise.all(promisses).then(() => {
|
|
525
531
|
this._savingLockers = [];
|
|
526
532
|
if (this.saveLoader) {
|
|
527
533
|
const changes: Array<Change> = this.getAllChangesToSave();
|
|
@@ -534,21 +540,21 @@ export default class DataUnit {
|
|
|
534
540
|
for (const [ownerDataUnitName, splittedRecords] of recordsByDataUnit) {
|
|
535
541
|
const ownerDataUnit = DataUnitStorage.get(ownerDataUnitName);
|
|
536
542
|
const changesByDataUnit = changes.filter(change => change.dataUnit === ownerDataUnitName);
|
|
537
|
-
|
|
538
|
-
if(ownerDataUnit){
|
|
543
|
+
|
|
544
|
+
if (ownerDataUnit) {
|
|
539
545
|
dispatchPromisses.push(ownerDataUnit.dispatchAction(Action.DATA_SAVED, { changes: changesByDataUnit, records: splittedRecords }, executionCtx));
|
|
540
546
|
}
|
|
541
547
|
}
|
|
542
548
|
Promise.all(dispatchPromisses).then(() => resolve());
|
|
543
549
|
}).catch(cause => {
|
|
544
|
-
const {errorCode} = cause;
|
|
550
|
+
const { errorCode } = cause;
|
|
545
551
|
this.dispatchAction(Action.SAVING_ERROR);
|
|
546
552
|
this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
547
|
-
if(cause instanceof ServiceCanceledException){
|
|
553
|
+
if (cause instanceof ServiceCanceledException) {
|
|
548
554
|
console.debug("Service canceled: " + cause.message);
|
|
549
555
|
resolve();
|
|
550
|
-
}
|
|
551
|
-
if(cause instanceof SilentException){
|
|
556
|
+
}
|
|
557
|
+
if (cause instanceof SilentException) {
|
|
552
558
|
fail(cause);
|
|
553
559
|
return;
|
|
554
560
|
}
|
|
@@ -576,17 +582,17 @@ export default class DataUnit {
|
|
|
576
582
|
* @returns - Mudanças realizadas no DataUnit atual
|
|
577
583
|
*
|
|
578
584
|
*/
|
|
579
|
-
public buildChangesToSave(): Array<Change>{
|
|
585
|
+
public buildChangesToSave(): Array<Change> {
|
|
580
586
|
return getChangesToSave(this._name, this._stateManager);
|
|
581
587
|
}
|
|
582
588
|
|
|
583
589
|
public buildChangesToSaveFromChild(allChanges: Array<Change>, dataUnit: DataUnit): void {
|
|
584
|
-
dataUnit._childByName
|
|
590
|
+
dataUnit._childByName.forEach((dataUnitChild: DataUnit) => {
|
|
585
591
|
if (dataUnitChild.isDirty()) {
|
|
586
|
-
|
|
587
|
-
|
|
592
|
+
allChanges.push(...getChangesToSave(dataUnitChild.name, dataUnitChild._stateManager));
|
|
593
|
+
this.buildChangesToSaveFromChild(allChanges, dataUnitChild);
|
|
588
594
|
}
|
|
589
|
-
|
|
595
|
+
});
|
|
590
596
|
}
|
|
591
597
|
|
|
592
598
|
/**
|
|
@@ -617,15 +623,18 @@ export default class DataUnit {
|
|
|
617
623
|
*/
|
|
618
624
|
public async removeSelectedRecords(buffered: boolean = false, silent: boolean = false): Promise<Array<string>> {
|
|
619
625
|
const selection = this.getSelectionInfo();
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
const records = selection?.records as Array<Record> || [];
|
|
625
|
-
const recordIds = selection?.recordIds as Array<string> || [];
|
|
626
|
-
return this.removeRecords(recordIds, records, buffered, undefined, silent);
|
|
626
|
+
|
|
627
|
+
if (selection.isAllRecords()) {
|
|
628
|
+
throw new Error("Exclusão remota não implementada.");
|
|
627
629
|
}
|
|
628
|
-
|
|
630
|
+
|
|
631
|
+
if (!selection.records || !selection.records.length) {
|
|
632
|
+
return Promise.resolve([]);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
const records = selection.records;
|
|
636
|
+
const recordIds = selection.recordIds as Array<string>;
|
|
637
|
+
return this.removeRecords(recordIds, records, buffered, undefined, silent);
|
|
629
638
|
}
|
|
630
639
|
|
|
631
640
|
/**
|
|
@@ -647,7 +656,7 @@ export default class DataUnit {
|
|
|
647
656
|
this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
648
657
|
this.dispatchAction(Action.RECORDS_REMOVED, { records: recordIds, cachedRecords, buffered: true }, executionCtx);
|
|
649
658
|
} else {
|
|
650
|
-
if (await this.dispatchAction(Action.REMOVING_RECORDS, {silent}, executionCtx)) {
|
|
659
|
+
if (await this.dispatchAction(Action.REMOVING_RECORDS, { silent }, executionCtx)) {
|
|
651
660
|
|
|
652
661
|
return new Promise((resolve, fail) => {
|
|
653
662
|
if (this.removeLoader) {
|
|
@@ -668,7 +677,7 @@ export default class DataUnit {
|
|
|
668
677
|
}
|
|
669
678
|
).catch(error => {
|
|
670
679
|
this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
671
|
-
const {errorCode} = error;
|
|
680
|
+
const { errorCode } = error;
|
|
672
681
|
fail(new ErrorException("Erro ao remover registros", error, errorCode))
|
|
673
682
|
});
|
|
674
683
|
}
|
|
@@ -727,11 +736,11 @@ export default class DataUnit {
|
|
|
727
736
|
const descriptor = this.getField(fieldName);
|
|
728
737
|
if (value == undefined) {
|
|
729
738
|
value = this.getFieldValue(fieldName);
|
|
730
|
-
} else if (typeof value === "string" && descriptor?.dataType != DataType.TEXT){
|
|
739
|
+
} else if (typeof value === "string" && descriptor?.dataType != DataType.TEXT) {
|
|
731
740
|
value = this.valueFromString(fieldName, value);
|
|
732
741
|
}
|
|
733
742
|
|
|
734
|
-
if(value == undefined){
|
|
743
|
+
if (value == undefined) {
|
|
735
744
|
return "";
|
|
736
745
|
}
|
|
737
746
|
|
|
@@ -778,7 +787,7 @@ export default class DataUnit {
|
|
|
778
787
|
* @param provider - FilterProvider que será removido.
|
|
779
788
|
*
|
|
780
789
|
*/
|
|
781
|
-
|
|
790
|
+
public removeFilterProvider(provider: FilterProvider): boolean {
|
|
782
791
|
return this._filterProviders.delete(this.getFielterProviderKey(provider));
|
|
783
792
|
}
|
|
784
793
|
|
|
@@ -843,18 +852,18 @@ export default class DataUnit {
|
|
|
843
852
|
return getMetadata(this._stateManager);
|
|
844
853
|
}
|
|
845
854
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
public getChildInfo(name: string): ChildDescriptor|undefined {
|
|
855
|
+
/**
|
|
856
|
+
*
|
|
857
|
+
* Obtém informações da ligação para um DataUnit filho.
|
|
858
|
+
*
|
|
859
|
+
* @param name - Nome do DataUnit que se deseja.
|
|
860
|
+
*
|
|
861
|
+
* @returns - As informações sobre a ligação solicitada. Pode retornar undefined.
|
|
862
|
+
*
|
|
863
|
+
*/
|
|
864
|
+
public getChildInfo(name: string): ChildDescriptor | undefined {
|
|
856
865
|
const children = this.metadata?.children;
|
|
857
|
-
if(children == undefined){
|
|
866
|
+
if (children == undefined) {
|
|
858
867
|
return;
|
|
859
868
|
}
|
|
860
869
|
|
|
@@ -960,41 +969,41 @@ export default class DataUnit {
|
|
|
960
969
|
*/
|
|
961
970
|
public copySelected(executionCtx?: ExecutionContext): void {
|
|
962
971
|
const selectionInfo = this.getSelectionInfo();
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
+
|
|
973
|
+
if (selectionInfo.isAllRecords()) {
|
|
974
|
+
throw new Error("Erro interno: Impossível copiar os registros selecionados pois a seleção atual é virtual.");
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
const selectedRecords = selectionInfo.records;
|
|
978
|
+
|
|
979
|
+
if (selectedRecords.length) {
|
|
980
|
+
this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
|
|
972
981
|
}
|
|
973
982
|
}
|
|
974
|
-
|
|
983
|
+
|
|
975
984
|
private getRecordsByDataUnit(records: Array<Record>): Map<string, Array<Record>> {
|
|
976
985
|
const recordsMap = new Map<string, Array<Record>>();
|
|
977
|
-
|
|
986
|
+
|
|
978
987
|
records.forEach(record => {
|
|
979
988
|
let { __owner__dataunit__name__: ownerDataUnitName } = record;
|
|
980
|
-
|
|
981
|
-
if(!ownerDataUnitName){
|
|
989
|
+
|
|
990
|
+
if (!ownerDataUnitName) {
|
|
982
991
|
ownerDataUnitName = this.name;
|
|
983
992
|
}
|
|
984
993
|
let changes = recordsMap.get(ownerDataUnitName);
|
|
985
|
-
|
|
986
|
-
if(!changes){
|
|
994
|
+
|
|
995
|
+
if (!changes) {
|
|
987
996
|
changes = [];
|
|
988
997
|
recordsMap.set(ownerDataUnitName, changes);
|
|
989
998
|
}
|
|
990
999
|
|
|
991
1000
|
changes.push(record);
|
|
992
1001
|
});
|
|
993
|
-
|
|
1002
|
+
|
|
994
1003
|
return recordsMap;
|
|
995
1004
|
}
|
|
996
1005
|
|
|
997
|
-
private getParentRecordId(){
|
|
1006
|
+
private getParentRecordId() {
|
|
998
1007
|
const parentRecord = this._parentDataUnit?.getSelectedRecord();
|
|
999
1008
|
return parentRecord?.__record__id__;
|
|
1000
1009
|
}
|
|
@@ -1036,27 +1045,27 @@ export default class DataUnit {
|
|
|
1036
1045
|
* @returns - Promise que será resolvida quando o novo valor for persistido no state.
|
|
1037
1046
|
*
|
|
1038
1047
|
*/
|
|
1039
|
-
public async setFieldValue(fieldName: string, newValue: any, records?: Array<string>, options?:DataUnitEventOptions): Promise<boolean> {
|
|
1048
|
+
public async setFieldValue(fieldName: string, newValue: any, records?: Array<string>, options?: DataUnitEventOptions): Promise<boolean> {
|
|
1040
1049
|
const noRecordSelected = !this.hasNewRecord() && !this.getSelectedRecord();
|
|
1041
1050
|
|
|
1042
1051
|
const suppressCreateNewRecord = options?.suppressCreateNewRecord;
|
|
1043
1052
|
|
|
1044
|
-
if(noRecordSelected && suppressCreateNewRecord) return Promise.resolve(false);
|
|
1053
|
+
if (noRecordSelected && suppressCreateNewRecord) return Promise.resolve(false);
|
|
1045
1054
|
|
|
1046
|
-
if(noRecordSelected) await this.addRecord();
|
|
1055
|
+
if (noRecordSelected) await this.addRecord();
|
|
1047
1056
|
|
|
1048
1057
|
const typedValue = this.validateAndTypeValue(fieldName, newValue);
|
|
1049
1058
|
const currentValue = this.getFieldValue(fieldName);
|
|
1050
1059
|
|
|
1051
|
-
if(this.areEquivalentValues(newValue, currentValue, typedValue)) {
|
|
1060
|
+
if (this.areEquivalentValues(newValue, currentValue, typedValue)) {
|
|
1052
1061
|
return Promise.resolve(false);
|
|
1053
1062
|
}
|
|
1054
1063
|
|
|
1055
|
-
if(newValue instanceof Promise){
|
|
1056
|
-
const promise:Promise<boolean> = new Promise(accept => {
|
|
1064
|
+
if (newValue instanceof Promise) {
|
|
1065
|
+
const promise: Promise<boolean> = new Promise(accept => {
|
|
1057
1066
|
newValue.then(resolvedValue => {
|
|
1058
1067
|
this.dispatchAction(Action.DATA_RESOLVED, { [fieldName]: resolvedValue, records }, undefined);
|
|
1059
|
-
accept(this.setFieldValue(fieldName, resolvedValue, records,
|
|
1068
|
+
accept(this.setFieldValue(fieldName, resolvedValue, records, options));
|
|
1060
1069
|
});
|
|
1061
1070
|
});
|
|
1062
1071
|
this._savingLockers.push(promise);
|
|
@@ -1074,8 +1083,8 @@ export default class DataUnit {
|
|
|
1074
1083
|
|
|
1075
1084
|
private areEquivalentValues(newValue: any, currentValue: any, typedValue: any) {
|
|
1076
1085
|
return !(newValue instanceof Promise)
|
|
1077
|
-
|
|
1078
|
-
|
|
1086
|
+
&& ObjectUtils.hasEquivalentProps(currentValue, typedValue)
|
|
1087
|
+
&& !this.isMultipleEdition;
|
|
1079
1088
|
}
|
|
1080
1089
|
|
|
1081
1090
|
/**
|
|
@@ -1099,7 +1108,7 @@ export default class DataUnit {
|
|
|
1099
1108
|
* @param recordId - Indica qual registro está com os campos inválido.
|
|
1100
1109
|
*
|
|
1101
1110
|
*/
|
|
1102
|
-
public savingCanceled(fields: Array<{name: string, message: string}>, recordId: string): void {
|
|
1111
|
+
public savingCanceled(fields: Array<{ name: string, message: string }>, recordId: string): void {
|
|
1103
1112
|
this.dispatchAction(Action.SAVING_CANCELED, { fields, recordId }, undefined);
|
|
1104
1113
|
}
|
|
1105
1114
|
|
|
@@ -1123,7 +1132,7 @@ export default class DataUnit {
|
|
|
1123
1132
|
* @param fieldName - Nome do campo.
|
|
1124
1133
|
*
|
|
1125
1134
|
*/
|
|
1126
|
-
public getInvalidMessage(recordId: string, fieldName: string): string|undefined {
|
|
1135
|
+
public getInvalidMessage(recordId: string, fieldName: string): string | undefined {
|
|
1127
1136
|
return getInvalidFieldMessage(this._stateManager, fieldName, recordId);
|
|
1128
1137
|
}
|
|
1129
1138
|
|
|
@@ -1157,7 +1166,6 @@ export default class DataUnit {
|
|
|
1157
1166
|
public hasWaitingChanges(): boolean {
|
|
1158
1167
|
const waitingChanges = getWaitingChanges(this._stateManager);
|
|
1159
1168
|
return waitingChanges ? !!waitingChanges.size : false;
|
|
1160
|
-
|
|
1161
1169
|
}
|
|
1162
1170
|
|
|
1163
1171
|
/**
|
|
@@ -1210,7 +1218,7 @@ export default class DataUnit {
|
|
|
1210
1218
|
public setSelection(selection: Array<string> | SelectionMode.ALL_RECORDS, executionCtx?: ExecutionContext): Promise<SelectionInfo> {
|
|
1211
1219
|
return new Promise(resolve => {
|
|
1212
1220
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }, executionCtx)
|
|
1213
|
-
.then(()=>resolve(this.getSelectionInfo()));
|
|
1221
|
+
.then(() => resolve(this.getSelectionInfo()));
|
|
1214
1222
|
});
|
|
1215
1223
|
}
|
|
1216
1224
|
|
|
@@ -1221,7 +1229,7 @@ export default class DataUnit {
|
|
|
1221
1229
|
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
1222
1230
|
*
|
|
1223
1231
|
*/
|
|
1224
|
-
public clearSelection(executionCtx?: ExecutionContext){
|
|
1232
|
+
public clearSelection(executionCtx?: ExecutionContext) {
|
|
1225
1233
|
this.setSelection([], executionCtx);
|
|
1226
1234
|
}
|
|
1227
1235
|
|
|
@@ -1233,19 +1241,19 @@ export default class DataUnit {
|
|
|
1233
1241
|
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
1234
1242
|
* @returns - Informações sobre a seleção.
|
|
1235
1243
|
*/
|
|
1236
|
-
public updatePageSelection(selection
|
|
1237
|
-
if(!selection) return Promise.resolve(this.getSelectionInfo());
|
|
1244
|
+
public updatePageSelection(selection?: Array<string>, executionCtx?: ExecutionContext): Promise<SelectionInfo | undefined> {
|
|
1245
|
+
if (!selection) return Promise.resolve(this.getSelectionInfo());
|
|
1238
1246
|
|
|
1239
1247
|
return new Promise(resolve => {
|
|
1240
1248
|
const newSelection: Set<string> = new Set(selection);
|
|
1241
1249
|
|
|
1242
1250
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) }, executionCtx)
|
|
1243
|
-
.then(()=> resolve(this.getSelectionInfo()));
|
|
1251
|
+
.then(() => resolve(this.getSelectionInfo()));
|
|
1244
1252
|
});
|
|
1245
1253
|
}
|
|
1246
1254
|
|
|
1247
1255
|
|
|
1248
|
-
private updatePageSelectionAll(addRecords: boolean): Promise<SelectionInfo|undefined>{
|
|
1256
|
+
private updatePageSelectionAll(addRecords: boolean): Promise<SelectionInfo | undefined> {
|
|
1249
1257
|
return new Promise(resolve => {
|
|
1250
1258
|
const newSelection: Set<string> = new Set<string>();
|
|
1251
1259
|
|
|
@@ -1253,10 +1261,10 @@ export default class DataUnit {
|
|
|
1253
1261
|
cachedSelection.forEach(item => newSelection.add(item));
|
|
1254
1262
|
|
|
1255
1263
|
const recordsIds = this.records.map(r => r.__record__id__);
|
|
1256
|
-
recordsIds.forEach(id => addRecords ? newSelection.add(id): newSelection.delete(id));
|
|
1264
|
+
recordsIds.forEach(id => addRecords ? newSelection.add(id) : newSelection.delete(id));
|
|
1257
1265
|
|
|
1258
1266
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) })
|
|
1259
|
-
|
|
1267
|
+
.then(() => resolve(this.getSelectionInfo()));
|
|
1260
1268
|
});
|
|
1261
1269
|
}
|
|
1262
1270
|
|
|
@@ -1265,8 +1273,8 @@ export default class DataUnit {
|
|
|
1265
1273
|
*
|
|
1266
1274
|
* @returns - Informações sobre a seleção.
|
|
1267
1275
|
*/
|
|
1268
|
-
|
|
1269
|
-
|
|
1276
|
+
public selectAllRecords(): Promise<SelectionInfo | undefined> {
|
|
1277
|
+
return this.updatePageSelectionAll(true);
|
|
1270
1278
|
}
|
|
1271
1279
|
|
|
1272
1280
|
/**
|
|
@@ -1274,9 +1282,9 @@ export default class DataUnit {
|
|
|
1274
1282
|
*
|
|
1275
1283
|
* @returns - Informações sobre a seleção.
|
|
1276
1284
|
*/
|
|
1277
|
-
|
|
1285
|
+
public unSelectAllRecords(): Promise<SelectionInfo | undefined> {
|
|
1278
1286
|
return this.updatePageSelectionAll(false);
|
|
1279
|
-
|
|
1287
|
+
}
|
|
1280
1288
|
|
|
1281
1289
|
/**
|
|
1282
1290
|
*
|
|
@@ -1284,13 +1292,13 @@ export default class DataUnit {
|
|
|
1284
1292
|
*
|
|
1285
1293
|
* @returns - Objeto com informações como registros selecionados e seleção por critério.
|
|
1286
1294
|
*
|
|
1287
|
-
**/
|
|
1288
|
-
public getSelectionInfo(): SelectionInfo{
|
|
1295
|
+
**/
|
|
1296
|
+
public getSelectionInfo(): SelectionInfo {
|
|
1289
1297
|
const selectionInfo: SelectionInfo = getSelectionInfo(this._stateManager);
|
|
1290
1298
|
selectionInfo.getAllRecords = () => {
|
|
1291
|
-
|
|
1299
|
+
|
|
1292
1300
|
let records = this.allRecordsLoader?.(this) ?? [];
|
|
1293
|
-
|
|
1301
|
+
|
|
1294
1302
|
if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
|
|
1295
1303
|
const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort)
|
|
1296
1304
|
records = [...records].sort(sortingFunction);
|
|
@@ -1301,7 +1309,7 @@ export default class DataUnit {
|
|
|
1301
1309
|
|
|
1302
1310
|
if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
|
|
1303
1311
|
const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort)
|
|
1304
|
-
selectionInfo.records
|
|
1312
|
+
selectionInfo.records.sort(sortingFunction)
|
|
1305
1313
|
}
|
|
1306
1314
|
|
|
1307
1315
|
return selectionInfo;
|
|
@@ -1315,7 +1323,7 @@ export default class DataUnit {
|
|
|
1315
1323
|
*
|
|
1316
1324
|
*/
|
|
1317
1325
|
public getSelectedRecord(): Record | undefined {
|
|
1318
|
-
|
|
1326
|
+
return getSelectedRecord(this._stateManager);
|
|
1319
1327
|
}
|
|
1320
1328
|
|
|
1321
1329
|
/**
|
|
@@ -1345,17 +1353,17 @@ export default class DataUnit {
|
|
|
1345
1353
|
*
|
|
1346
1354
|
*
|
|
1347
1355
|
*/
|
|
1348
|
-
public nextRecord(executionCtx?: ExecutionContext): void {
|
|
1349
|
-
if(!hasNext(this._stateManager)){
|
|
1350
|
-
if(hasMorePages(this._stateManager)){
|
|
1351
|
-
this.nextPage({
|
|
1352
|
-
before: act =>{
|
|
1353
|
-
if(executionCtx && executionCtx.before){
|
|
1356
|
+
public async nextRecord(executionCtx?: ExecutionContext): Promise<void> {
|
|
1357
|
+
if (!hasNext(this._stateManager)) {
|
|
1358
|
+
if (hasMorePages(this._stateManager)) {
|
|
1359
|
+
await this.nextPage({
|
|
1360
|
+
before: (act) => {
|
|
1361
|
+
if (executionCtx && executionCtx.before) {
|
|
1354
1362
|
act = executionCtx.before(act);
|
|
1355
1363
|
}
|
|
1356
1364
|
return act;
|
|
1357
1365
|
},
|
|
1358
|
-
after:
|
|
1366
|
+
after: () => {
|
|
1359
1367
|
this.selectFirst(executionCtx);
|
|
1360
1368
|
}
|
|
1361
1369
|
});
|
|
@@ -1372,17 +1380,17 @@ export default class DataUnit {
|
|
|
1372
1380
|
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
1373
1381
|
*
|
|
1374
1382
|
*/
|
|
1375
|
-
public previousRecord(executionCtx?: ExecutionContext): void {
|
|
1376
|
-
if(!hasPrevious(this._stateManager)){
|
|
1377
|
-
if(hasPreviousPages(this._stateManager)){
|
|
1378
|
-
this.previousPage({
|
|
1379
|
-
before: act =>{
|
|
1380
|
-
if(executionCtx && executionCtx.before){
|
|
1383
|
+
public async previousRecord(executionCtx?: ExecutionContext): Promise<void> {
|
|
1384
|
+
if (!hasPrevious(this._stateManager)) {
|
|
1385
|
+
if (hasPreviousPages(this._stateManager)) {
|
|
1386
|
+
await this.previousPage({
|
|
1387
|
+
before: (act) => {
|
|
1388
|
+
if (executionCtx && executionCtx.before) {
|
|
1381
1389
|
act = executionCtx.before(act);
|
|
1382
1390
|
}
|
|
1383
1391
|
return act;
|
|
1384
1392
|
},
|
|
1385
|
-
after:
|
|
1393
|
+
after: () => {
|
|
1386
1394
|
this.selectLast(executionCtx);
|
|
1387
1395
|
}
|
|
1388
1396
|
});
|
|
@@ -1401,14 +1409,14 @@ export default class DataUnit {
|
|
|
1401
1409
|
*
|
|
1402
1410
|
*/
|
|
1403
1411
|
public async cancelEdition(executionCtx?: ExecutionContext, fromParent?: boolean, silent: boolean = false): Promise<boolean> {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
}
|
|
1412
|
+
const cancelledAction = await this.dispatchAction(Action.EDITION_CANCELED, { fromParent, silent }, executionCtx);
|
|
1413
|
+
for (const [, dataUnit] of this._childByName) {
|
|
1414
|
+
if (dataUnit.isDirty()) {
|
|
1415
|
+
dataUnit.cancelEdition(undefined, true, silent);
|
|
1409
1416
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1417
|
+
}
|
|
1418
|
+
return Promise.resolve(cancelledAction);
|
|
1419
|
+
|
|
1412
1420
|
}
|
|
1413
1421
|
|
|
1414
1422
|
/**
|
|
@@ -1418,9 +1426,9 @@ export default class DataUnit {
|
|
|
1418
1426
|
* @param ignoreChildren: Define se deverá ignorar alterações pendentes no DataUnit filho.
|
|
1419
1427
|
* @returns Verdadeiro se existir alterações pendentes.
|
|
1420
1428
|
*
|
|
1421
|
-
*/
|
|
1429
|
+
*/
|
|
1422
1430
|
public isDirty(ignoreChildren?: boolean): boolean {
|
|
1423
|
-
if(ignoreChildren) return isDirty(this._stateManager);
|
|
1431
|
+
if (ignoreChildren) return isDirty(this._stateManager);
|
|
1424
1432
|
|
|
1425
1433
|
return isDirty(this._stateManager) || this.childrenIsDirty();
|
|
1426
1434
|
}
|
|
@@ -1442,10 +1450,10 @@ export default class DataUnit {
|
|
|
1442
1450
|
*
|
|
1443
1451
|
* @returns Verdadeiro se existir alterações pendentes em algum DataUnit detail.
|
|
1444
1452
|
*
|
|
1445
|
-
*/
|
|
1446
|
-
private childrenIsDirty():boolean {
|
|
1447
|
-
for (let [
|
|
1448
|
-
if(dataUnitChild.isDirty()) return true;
|
|
1453
|
+
*/
|
|
1454
|
+
private childrenIsDirty(): boolean {
|
|
1455
|
+
for (let [_, dataUnitChild] of this._childByName) {
|
|
1456
|
+
if (dataUnitChild.isDirty()) return true;
|
|
1449
1457
|
}
|
|
1450
1458
|
return false;
|
|
1451
1459
|
}
|
|
@@ -1470,7 +1478,7 @@ export default class DataUnit {
|
|
|
1470
1478
|
*/
|
|
1471
1479
|
public hasNext(): boolean {
|
|
1472
1480
|
let result = hasNext(this._stateManager);
|
|
1473
|
-
if(!result){
|
|
1481
|
+
if (!result) {
|
|
1474
1482
|
result = hasMorePages(this._stateManager);
|
|
1475
1483
|
}
|
|
1476
1484
|
return result;
|
|
@@ -1485,7 +1493,7 @@ export default class DataUnit {
|
|
|
1485
1493
|
*/
|
|
1486
1494
|
public hasPrevious(): boolean {
|
|
1487
1495
|
let result = hasPrevious(this._stateManager);
|
|
1488
|
-
if(!result){
|
|
1496
|
+
if (!result) {
|
|
1489
1497
|
result = hasPreviousPages(this._stateManager);
|
|
1490
1498
|
}
|
|
1491
1499
|
return result;
|
|
@@ -1501,7 +1509,7 @@ export default class DataUnit {
|
|
|
1501
1509
|
*/
|
|
1502
1510
|
public isNewRecord(recordId: string): boolean {
|
|
1503
1511
|
const newRecords = getAddedRecords(this._stateManager);
|
|
1504
|
-
if(newRecords && newRecords.length > 0){
|
|
1512
|
+
if (newRecords && newRecords.length > 0) {
|
|
1505
1513
|
const record = newRecords.find(newRecord => newRecord.__record__id__ === recordId);
|
|
1506
1514
|
return record != undefined;
|
|
1507
1515
|
}
|
|
@@ -1529,10 +1537,11 @@ export default class DataUnit {
|
|
|
1529
1537
|
*/
|
|
1530
1538
|
public hasCopiedRecord(): boolean {
|
|
1531
1539
|
const newRecords = getAddedRecords(this._stateManager);
|
|
1532
|
-
|
|
1540
|
+
|
|
1541
|
+
if (newRecords == undefined) {
|
|
1533
1542
|
return false;
|
|
1534
1543
|
}
|
|
1535
|
-
for(let record of newRecords){
|
|
1544
|
+
for (let record of newRecords) {
|
|
1536
1545
|
if (record['__record__source__id__'] != undefined) {
|
|
1537
1546
|
return true
|
|
1538
1547
|
}
|
|
@@ -1608,7 +1617,7 @@ export default class DataUnit {
|
|
|
1608
1617
|
* @returns - Verdadeiro se ação iniciada.
|
|
1609
1618
|
*
|
|
1610
1619
|
*/
|
|
1611
|
-
private async dispatchAction(actionType: Action, payload?: any, executionCtx?: ExecutionContext, options?:DataUnitEventOptions): Promise<boolean> {
|
|
1620
|
+
private async dispatchAction(actionType: Action, payload?: any, executionCtx?: ExecutionContext, options?: DataUnitEventOptions): Promise<boolean> {
|
|
1612
1621
|
return new Promise(async resolve => {
|
|
1613
1622
|
let action = new DataUnitAction(actionType, payload);
|
|
1614
1623
|
if (executionCtx && executionCtx.before) {
|
|
@@ -1656,7 +1665,7 @@ export default class DataUnit {
|
|
|
1656
1665
|
* @param action - Ações em execução no DataUnit.
|
|
1657
1666
|
*
|
|
1658
1667
|
*/
|
|
1659
|
-
private doDispatchAction(action: DataUnitAction, options:DataUnitEventOptions = {}): void {
|
|
1668
|
+
private doDispatchAction(action: DataUnitAction, options: DataUnitEventOptions = {}): void {
|
|
1660
1669
|
this._stateManager.process(action);
|
|
1661
1670
|
this?._parentDataUnit?.dispatchAction(Action.CHILD_CHANGED, { srcAction: action, srcDataUnit: this });
|
|
1662
1671
|
this._observers.forEach(f => {
|
|
@@ -1676,7 +1685,7 @@ export default class DataUnit {
|
|
|
1676
1685
|
* @param name - Nome do dataunit filho.
|
|
1677
1686
|
*
|
|
1678
1687
|
*/
|
|
1679
|
-
public getChildDataunit(name:string){
|
|
1688
|
+
public getChildDataunit(name: string) {
|
|
1680
1689
|
const detail: DataUnit = new DataUnit(name, this);
|
|
1681
1690
|
this._childByName.set(name, detail);
|
|
1682
1691
|
return detail;
|
|
@@ -1689,10 +1698,10 @@ export default class DataUnit {
|
|
|
1689
1698
|
* @param name - Nome do dataunit filho.
|
|
1690
1699
|
*
|
|
1691
1700
|
*/
|
|
1692
|
-
public removeChildDataunit(name:string){
|
|
1701
|
+
public removeChildDataunit(name: string) {
|
|
1693
1702
|
this._childByName.delete(name);
|
|
1694
1703
|
}
|
|
1695
|
-
|
|
1704
|
+
|
|
1696
1705
|
/**
|
|
1697
1706
|
*
|
|
1698
1707
|
* Adiciona um novo observer no DataUnit.
|
|
@@ -1738,17 +1747,17 @@ export default class DataUnit {
|
|
|
1738
1747
|
* @returns - Dados atualizados do registro selecionado.
|
|
1739
1748
|
*
|
|
1740
1749
|
*/
|
|
1741
|
-
public reloadCurrentRecord(): Promise<Array<Record>>{
|
|
1750
|
+
public reloadCurrentRecord(): Promise<Array<Record>> {
|
|
1742
1751
|
return new Promise(async (resolve, fail) => {
|
|
1743
1752
|
const selection = getSelection(this._stateManager);
|
|
1744
1753
|
await this.dispatchAction(Action.LOADING_RECORD, selection);
|
|
1745
|
-
|
|
1746
|
-
if(!this.recordLoader || !this.dataLoader) {
|
|
1754
|
+
|
|
1755
|
+
if (!this.recordLoader || !this.dataLoader) {
|
|
1747
1756
|
await this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
1748
1757
|
resolve([]);
|
|
1749
1758
|
return;
|
|
1750
1759
|
}
|
|
1751
|
-
|
|
1760
|
+
|
|
1752
1761
|
this.recordLoader(this, selection).then(async response => {
|
|
1753
1762
|
await this.dispatchAction(Action.RECORD_LOADED, response)
|
|
1754
1763
|
await this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
@@ -1756,7 +1765,7 @@ export default class DataUnit {
|
|
|
1756
1765
|
resolve(response);
|
|
1757
1766
|
}).catch(async cause => {
|
|
1758
1767
|
await this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
1759
|
-
const {errorCode} = cause;
|
|
1768
|
+
const { errorCode } = cause;
|
|
1760
1769
|
fail(new ErrorException("Erro ao recarregar registro", cause, errorCode));
|
|
1761
1770
|
});
|
|
1762
1771
|
});
|
|
@@ -1780,7 +1789,7 @@ export default class DataUnit {
|
|
|
1780
1789
|
* @returns - Lista de filtros.
|
|
1781
1790
|
*
|
|
1782
1791
|
*/
|
|
1783
|
-
public getFilters(): Array<Filter> | undefined {
|
|
1792
|
+
public getFilters(): Array<Filter> | undefined {
|
|
1784
1793
|
let filters: Array<Filter> | undefined = undefined;
|
|
1785
1794
|
this._filterProviders.forEach(p => {
|
|
1786
1795
|
const f = p.getFilter(this.name);
|
|
@@ -1797,18 +1806,18 @@ export default class DataUnit {
|
|
|
1797
1806
|
*
|
|
1798
1807
|
* @returns - As informações de filtro e paginação.
|
|
1799
1808
|
*
|
|
1800
|
-
*/
|
|
1809
|
+
*/
|
|
1801
1810
|
public getLastLoadRequest(): LoadDataRequest | undefined {
|
|
1802
1811
|
return getCurrentRequest(this._stateManager);
|
|
1803
1812
|
}
|
|
1804
|
-
|
|
1813
|
+
|
|
1805
1814
|
/**
|
|
1806
1815
|
*
|
|
1807
1816
|
* Obtém os filtros aplicados.
|
|
1808
1817
|
*
|
|
1809
1818
|
* @returns - Lista de filtros.
|
|
1810
1819
|
*
|
|
1811
|
-
*/
|
|
1820
|
+
*/
|
|
1812
1821
|
public getAppliedFilters(): Array<Filter> | undefined {
|
|
1813
1822
|
const { filters }: LoadDataRequest = getCurrentRequest(this._stateManager) || {};
|
|
1814
1823
|
return filters
|
|
@@ -1820,12 +1829,16 @@ export default class DataUnit {
|
|
|
1820
1829
|
* @param fieldName - nome do campo para ser habilitado.
|
|
1821
1830
|
*
|
|
1822
1831
|
*/
|
|
1823
|
-
public enableField(fieldName:string) {
|
|
1832
|
+
public enableField(fieldName: string) {
|
|
1824
1833
|
const fieldDescriptor = this.getField(fieldName);
|
|
1825
1834
|
|
|
1826
|
-
if(fieldDescriptor
|
|
1835
|
+
if (!fieldDescriptor) {
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
if (fieldDescriptor.readOnly) {
|
|
1827
1840
|
fieldDescriptor.readOnly = false;
|
|
1828
|
-
this.metadata = {...this.metadata};
|
|
1841
|
+
this.metadata = { ...this.metadata };
|
|
1829
1842
|
}
|
|
1830
1843
|
}
|
|
1831
1844
|
|
|
@@ -1835,12 +1848,16 @@ export default class DataUnit {
|
|
|
1835
1848
|
* @param fieldName - nome do campo para ficar desabilitado.
|
|
1836
1849
|
*
|
|
1837
1850
|
*/
|
|
1838
|
-
public disableField(fieldName:string) {
|
|
1851
|
+
public disableField(fieldName: string) {
|
|
1839
1852
|
const fieldDescriptor = this.getField(fieldName);
|
|
1840
1853
|
|
|
1841
|
-
if(fieldDescriptor
|
|
1854
|
+
if (!fieldDescriptor) {
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
if (!fieldDescriptor.readOnly) {
|
|
1842
1859
|
fieldDescriptor.readOnly = true;
|
|
1843
|
-
this.metadata = {...this.metadata};
|
|
1860
|
+
this.metadata = { ...this.metadata };
|
|
1844
1861
|
}
|
|
1845
1862
|
}
|
|
1846
1863
|
|
|
@@ -1850,13 +1867,21 @@ export default class DataUnit {
|
|
|
1850
1867
|
* @param fieldName - nome do campo para ficar invisível.
|
|
1851
1868
|
*
|
|
1852
1869
|
*/
|
|
1853
|
-
public hideField(fieldName:string, options
|
|
1870
|
+
public hideField(fieldName: string, options?: HideFieldOptions) {
|
|
1854
1871
|
const fieldDescriptor = this.getField(fieldName);
|
|
1855
1872
|
|
|
1856
|
-
if(fieldDescriptor
|
|
1873
|
+
if (!fieldDescriptor) {
|
|
1874
|
+
return;
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
if (fieldDescriptor.visible) {
|
|
1857
1878
|
fieldDescriptor.visible = false;
|
|
1858
|
-
|
|
1859
|
-
|
|
1879
|
+
|
|
1880
|
+
if (options) {
|
|
1881
|
+
fieldDescriptor.properties = { ...fieldDescriptor.properties, visibleOnConfig: options.visibleOnConfig };
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
this.metadata = { ...this.metadata };
|
|
1860
1885
|
}
|
|
1861
1886
|
}
|
|
1862
1887
|
|
|
@@ -1866,15 +1891,19 @@ export default class DataUnit {
|
|
|
1866
1891
|
* @param fieldName - nome do campo para ficar visível.
|
|
1867
1892
|
*
|
|
1868
1893
|
*/
|
|
1869
|
-
public showField(fieldName:string) {
|
|
1894
|
+
public showField(fieldName: string) {
|
|
1870
1895
|
const fieldDescriptor = this.getField(fieldName);
|
|
1871
1896
|
|
|
1872
|
-
if(fieldDescriptor
|
|
1897
|
+
if (!fieldDescriptor) {
|
|
1898
|
+
return;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
if (!fieldDescriptor.visible) {
|
|
1873
1902
|
fieldDescriptor.visible = true;
|
|
1874
|
-
this.metadata = {...this.metadata};
|
|
1903
|
+
this.metadata = { ...this.metadata };
|
|
1875
1904
|
}
|
|
1876
1905
|
}
|
|
1877
|
-
|
|
1906
|
+
|
|
1878
1907
|
/**
|
|
1879
1908
|
*
|
|
1880
1909
|
* Obtém todos os registros selecionados.
|
|
@@ -1890,7 +1919,7 @@ export default class DataUnit {
|
|
|
1890
1919
|
console.warn("DataUnit: O método `getSelectedRecords` foi descontinuado. Use o método `getSelectionInfo`.");
|
|
1891
1920
|
const selection = this.getSelectionInfo();
|
|
1892
1921
|
|
|
1893
|
-
if(selection != undefined && selection.isAllRecords()){
|
|
1922
|
+
if (selection != undefined && selection.isAllRecords()) {
|
|
1894
1923
|
throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
|
|
1895
1924
|
}
|
|
1896
1925
|
|
|
@@ -1913,11 +1942,11 @@ export default class DataUnit {
|
|
|
1913
1942
|
public getSelection(): Array<string> {
|
|
1914
1943
|
console.warn("DataUnit: O método `getSelection` foi descontinuado. Use o método `getSelectionInfo`.");
|
|
1915
1944
|
const selection = this.getSelectionInfo();
|
|
1916
|
-
if(selection == undefined){
|
|
1945
|
+
if (selection == undefined) {
|
|
1917
1946
|
return [];
|
|
1918
1947
|
}
|
|
1919
1948
|
|
|
1920
|
-
if(selection.isAllRecords()){
|
|
1949
|
+
if (selection.isAllRecords()) {
|
|
1921
1950
|
throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
|
|
1922
1951
|
}
|
|
1923
1952
|
|
|
@@ -1929,7 +1958,7 @@ export default class DataUnit {
|
|
|
1929
1958
|
*
|
|
1930
1959
|
* @deprecated - metodo depreciado, utilizar o metodo addField
|
|
1931
1960
|
*/
|
|
1932
|
-
public addStandAloneField()
|
|
1961
|
+
public addStandAloneField(): void {
|
|
1933
1962
|
console.warn("metodo depreciado, para adicionar um campo standAlone, utilizar o metodo addField")
|
|
1934
1963
|
}
|
|
1935
1964
|
|
|
@@ -1938,9 +1967,9 @@ export default class DataUnit {
|
|
|
1938
1967
|
*
|
|
1939
1968
|
* @param field - Campo a ser adicionado.
|
|
1940
1969
|
*/
|
|
1941
|
-
public addField(field: Omit<FieldDescriptor, 'standAlone'>)
|
|
1942
|
-
const standAloneField = {...field, standAlone: true};
|
|
1943
|
-
this.metadata = {...this.metadata, fields: [...this.metadata.fields, standAloneField]};
|
|
1970
|
+
public addField(field: Omit<FieldDescriptor, 'standAlone'>): void {
|
|
1971
|
+
const standAloneField = { ...field, standAlone: true };
|
|
1972
|
+
this.metadata = { ...this.metadata, fields: [...this.metadata.fields, standAloneField] };
|
|
1944
1973
|
}
|
|
1945
1974
|
|
|
1946
1975
|
/**
|
|
@@ -1948,16 +1977,16 @@ export default class DataUnit {
|
|
|
1948
1977
|
* @returns Retorna uma função responsável por liberar o lock adicionado.
|
|
1949
1978
|
*/
|
|
1950
1979
|
public addLoadingLocker(): Function {
|
|
1951
|
-
let loadingLockerResolver;
|
|
1980
|
+
let loadingLockerResolver = () => {};
|
|
1952
1981
|
|
|
1953
1982
|
this._loadingLockers.push(new Promise((resolve) => {
|
|
1954
1983
|
loadingLockerResolver = resolve;
|
|
1955
1984
|
}));
|
|
1956
|
-
|
|
1957
|
-
return loadingLockerResolver
|
|
1985
|
+
|
|
1986
|
+
return loadingLockerResolver;
|
|
1958
1987
|
}
|
|
1959
1988
|
|
|
1960
|
-
public set allowReleaseCallbacks(allow: boolean){
|
|
1989
|
+
public set allowReleaseCallbacks(allow: boolean) {
|
|
1961
1990
|
this._allowReleaseCallbacks = allow;
|
|
1962
1991
|
}
|
|
1963
1992
|
|
|
@@ -1965,19 +1994,19 @@ export default class DataUnit {
|
|
|
1965
1994
|
/**
|
|
1966
1995
|
* Adiciona um mapeamento de origem dos dados de um determinado campo
|
|
1967
1996
|
*/
|
|
1968
|
-
public addSourceFieldValue(sourceFieldName:string, targetFieldName:string): void{
|
|
1997
|
+
public addSourceFieldValue(sourceFieldName: string, targetFieldName: string): void {
|
|
1969
1998
|
this._fieldSourceValue.set(sourceFieldName, targetFieldName);
|
|
1970
1999
|
}
|
|
1971
2000
|
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
return this._fieldSourceValue.get(
|
|
2001
|
+
/**
|
|
2002
|
+
* Retornar o campo de origem dos dados caso exista mapeamento
|
|
2003
|
+
*/
|
|
2004
|
+
public getSourceFieldValue(sourceFieldName: string): string | undefined {
|
|
2005
|
+
return this._fieldSourceValue.get(sourceFieldName);
|
|
1977
2006
|
}
|
|
1978
2007
|
|
|
1979
|
-
private async processLoadingLockers(){
|
|
1980
|
-
if(this._loadingLockers.length) {
|
|
2008
|
+
private async processLoadingLockers() {
|
|
2009
|
+
if (this._loadingLockers.length) {
|
|
1981
2010
|
await Promise.all(this._loadingLockers);
|
|
1982
2011
|
this._loadingLockers = [];
|
|
1983
2012
|
}
|
|
@@ -1985,200 +2014,16 @@ export default class DataUnit {
|
|
|
1985
2014
|
|
|
1986
2015
|
}
|
|
1987
2016
|
|
|
1988
|
-
export
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
export interface Record {
|
|
2002
|
-
__record__id__: string;
|
|
2003
|
-
__record__label__?: string;
|
|
2004
|
-
__parent__record__id__?: string;
|
|
2005
|
-
__owner__dataunit__name__?: string;
|
|
2006
|
-
[key: string]: any;
|
|
2007
|
-
}
|
|
2008
|
-
|
|
2009
|
-
export interface SavedRecord extends Record {
|
|
2010
|
-
__old__id__?: string;
|
|
2011
|
-
}
|
|
2012
|
-
|
|
2013
|
-
export enum ChangeOperation {
|
|
2014
|
-
INSERT = "INSERT",
|
|
2015
|
-
COPY = "COPY",
|
|
2016
|
-
UPDATE = "UPDATE",
|
|
2017
|
-
DELETE = "DELETE",
|
|
2018
|
-
}
|
|
2019
|
-
|
|
2020
|
-
/***
|
|
2021
|
-
* `Change`: Dados que representam uma alteração.
|
|
2022
|
-
*/
|
|
2023
|
-
export class Change {
|
|
2024
|
-
|
|
2025
|
-
public dataUnit: string;
|
|
2026
|
-
public record: Record;
|
|
2027
|
-
public sourceId: string | undefined;
|
|
2028
|
-
public updatingFields: any;
|
|
2029
|
-
|
|
2030
|
-
private _operation: ChangeOperation;
|
|
2031
|
-
|
|
2032
|
-
constructor(dataUnit: string, record: Record, updates: any, operation: ChangeOperation, sourceId?: string) {
|
|
2033
|
-
this.dataUnit = dataUnit;
|
|
2034
|
-
this.record = record;
|
|
2035
|
-
this.sourceId = sourceId;
|
|
2036
|
-
this.updatingFields = updates;
|
|
2037
|
-
this._operation = operation;
|
|
2038
|
-
}
|
|
2039
|
-
|
|
2040
|
-
/**
|
|
2041
|
-
*
|
|
2042
|
-
* Obtém o tipo de operação que está sendo realizada.
|
|
2043
|
-
*
|
|
2044
|
-
* @returns - Ação que está sendo executada.
|
|
2045
|
-
*
|
|
2046
|
-
*/
|
|
2047
|
-
public get operation(): string {
|
|
2048
|
-
return this._operation.toString();
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
/**
|
|
2052
|
-
*
|
|
2053
|
-
* Retorna se o DataUnit está em uma operação de inserção.
|
|
2054
|
-
*
|
|
2055
|
-
* @returns - Verdadeiro se a operação for de inserção.
|
|
2056
|
-
*
|
|
2057
|
-
*/
|
|
2058
|
-
public isInsert(): boolean {
|
|
2059
|
-
return this._operation === ChangeOperation.INSERT;
|
|
2060
|
-
}
|
|
2061
|
-
|
|
2062
|
-
/**
|
|
2063
|
-
*
|
|
2064
|
-
* Retorna se o DataUnit está em uma operação de cópia.
|
|
2065
|
-
*
|
|
2066
|
-
* @returns - Verdadeiro se a operação for de cópia.
|
|
2067
|
-
*
|
|
2068
|
-
*/
|
|
2069
|
-
public isCopy(): boolean {
|
|
2070
|
-
return this._operation === ChangeOperation.COPY;
|
|
2071
|
-
}
|
|
2072
|
-
|
|
2073
|
-
/**
|
|
2074
|
-
*
|
|
2075
|
-
* Retorna se o DataUnit está em uma operação de deleção.
|
|
2076
|
-
*
|
|
2077
|
-
* @returns - Verdadeiro se a operação for de deleção.
|
|
2078
|
-
*
|
|
2079
|
-
*/
|
|
2080
|
-
public isDelete(): boolean {
|
|
2081
|
-
return this._operation === ChangeOperation.DELETE;
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
/**
|
|
2085
|
-
*
|
|
2086
|
-
* Retorna se o DataUnit está em uma operação de atualização.
|
|
2087
|
-
*
|
|
2088
|
-
* @returns - Verdadeiro se a operação for de atualização.
|
|
2089
|
-
*
|
|
2090
|
-
*/
|
|
2091
|
-
public isUpdate(): boolean {
|
|
2092
|
-
return this._operation === ChangeOperation.UPDATE;
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
|
-
export interface WaitingChange {
|
|
2097
|
-
waitmessage: string;
|
|
2098
|
-
blocking: boolean;
|
|
2099
|
-
promise?: Promise<any>;
|
|
2100
|
-
}
|
|
2101
|
-
|
|
2102
|
-
export interface PageRequest {
|
|
2103
|
-
limit: number;
|
|
2104
|
-
offset: number;
|
|
2105
|
-
quickFilter?: QuickFilter;
|
|
2106
|
-
}
|
|
2107
|
-
|
|
2108
|
-
export interface QuickFilter {
|
|
2109
|
-
term: string;
|
|
2110
|
-
fields?: Array<string>;
|
|
2111
|
-
filter?: Filter;
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
export interface PageResponse {
|
|
2115
|
-
limit: number;
|
|
2116
|
-
offset: number;
|
|
2117
|
-
total: number;
|
|
2118
|
-
hasMore: boolean;
|
|
2119
|
-
records: Array<Record>;
|
|
2120
|
-
}
|
|
2121
|
-
|
|
2122
|
-
export enum SelectionMode{
|
|
2123
|
-
ALL_RECORDS = "ALL_RECORDS",
|
|
2124
|
-
SOME_RECORDS = "SOME_RECORDS"
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
export class SelectionInfo{
|
|
2128
|
-
|
|
2129
|
-
public mode: SelectionMode;
|
|
2130
|
-
public filters?: Array<Filter>;
|
|
2131
|
-
public sort?: Array<Sort>;
|
|
2132
|
-
public getAllRecords?: () => Array<Record> | undefined;
|
|
2133
|
-
private _records: Array<Record>;
|
|
2134
|
-
private _total?: number;
|
|
2135
|
-
|
|
2136
|
-
constructor(records: Array<Record>, mode: SelectionMode = SelectionMode.SOME_RECORDS, total?:number, filters?: Array<Filter>, sort?: Array<Sort>){
|
|
2137
|
-
this._records = records;
|
|
2138
|
-
this._total = total;
|
|
2139
|
-
this.mode = mode;
|
|
2140
|
-
this.filters = filters;
|
|
2141
|
-
this.sort = sort;
|
|
2142
|
-
}
|
|
2143
|
-
|
|
2144
|
-
public get records(): Array<Record> | undefined{
|
|
2145
|
-
if(this.isAllRecords()){
|
|
2146
|
-
if(this.getAllRecords != undefined){
|
|
2147
|
-
return this.getAllRecords();
|
|
2148
|
-
}
|
|
2149
|
-
throw new Error("Erro interno: Impossível retornar os registros selecionados numa seleção virtual.");
|
|
2150
|
-
}
|
|
2151
|
-
return this._records;
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
public get recordIds(): Array<string> | undefined{
|
|
2155
|
-
|
|
2156
|
-
const records = this.records;
|
|
2157
|
-
|
|
2158
|
-
if(records == undefined){
|
|
2159
|
-
return undefined;
|
|
2160
|
-
}
|
|
2161
|
-
return records.map(record => record.__record__id__);
|
|
2162
|
-
}
|
|
2163
|
-
|
|
2164
|
-
public get length(): number{
|
|
2165
|
-
if(this.isAllRecords()){
|
|
2166
|
-
return this._total || 0;
|
|
2167
|
-
}
|
|
2168
|
-
return this.records == undefined ? 0 : (this.records as Array<Record>).length;
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
public isAllRecords(): boolean{
|
|
2172
|
-
return this.mode === SelectionMode.ALL_RECORDS;
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
|
-
public isEmpty(): boolean{
|
|
2176
|
-
return this.length === 0;
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2180
|
-
export type DataUnitEventOptions = {[key:string]: any};
|
|
2181
|
-
|
|
2182
|
-
export type HideFieldOptions = {
|
|
2183
|
-
visibleOnConfig: boolean
|
|
2184
|
-
};
|
|
2017
|
+
export {
|
|
2018
|
+
Record,
|
|
2019
|
+
Change,
|
|
2020
|
+
SelectionInfo,
|
|
2021
|
+
SelectionMode,
|
|
2022
|
+
LoadDataParams,
|
|
2023
|
+
DUActionInterceptor,
|
|
2024
|
+
SavedRecord,
|
|
2025
|
+
WaitingChange,
|
|
2026
|
+
QuickFilter,
|
|
2027
|
+
DataUnitEventOptions,
|
|
2028
|
+
HideFieldOptions
|
|
2029
|
+
}
|