@sankhyalabs/core 4.3.2 → 4.4.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/Change.md +11 -11
- package/.docs/classes/DataUnit.md +197 -132
- package/.docs/classes/SelectionInfo.md +168 -0
- package/.docs/enums/Action.md +3 -14
- package/.docs/enums/ChangeOperation.md +4 -4
- package/.docs/enums/SelectionMode.md +30 -0
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/LoadDataRequest.md +13 -0
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/QuickFilter.md +13 -2
- package/.docs/interfaces/Record.md +4 -6
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/modules.md +2 -1
- package/README.md +3 -1
- package/dist/dataunit/DataUnit.d.ts +78 -44
- package/dist/dataunit/DataUnit.js +195 -101
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/loading/LoadDataRequest.d.ts +2 -0
- package/dist/dataunit/state/action/DataUnitAction.d.ts +0 -1
- package/dist/dataunit/state/action/DataUnitAction.js +0 -1
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/dataunit/state/slice/ChangesSlice.js +1 -2
- package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
- package/dist/dataunit/state/slice/LoadingControlSlice.d.ts +2 -2
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SelectionSlice.d.ts +7 -4
- package/dist/dataunit/state/slice/SelectionSlice.js +40 -32
- package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
- package/dist/dataunit/state/slice/SnapshotSlice.d.ts +18 -0
- package/dist/dataunit/state/slice/SnapshotSlice.js +85 -0
- package/dist/dataunit/state/slice/SnapshotSlice.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/dataunit/DataUnit.ts +226 -109
- package/src/dataunit/loading/LoadDataRequest.ts +3 -0
- package/src/dataunit/state/action/DataUnitAction.ts +0 -2
- package/src/dataunit/state/slice/ChangesSlice.ts +1 -1
- package/src/dataunit/state/slice/LoadingControlSlice.ts +2 -2
- package/src/dataunit/state/slice/SelectionSlice.ts +61 -45
- package/src/dataunit/state/slice/SnapshotSlice.ts +113 -0
- package/src/index.ts +4 -3
- package/.docs/interfaces/AllRecord.md +0 -96
- package/dist/dataunit/state/slice/CurrentRecordsSlice.d.ts +0 -12
- package/dist/dataunit/state/slice/CurrentRecordsSlice.js +0 -62
- package/dist/dataunit/state/slice/CurrentRecordsSlice.js.map +0 -1
- package/src/dataunit/state/slice/CurrentRecordsSlice.ts +0 -76
|
@@ -130,6 +130,7 @@ export default class DataUnit {
|
|
|
130
130
|
*
|
|
131
131
|
*/
|
|
132
132
|
previousPage(executionCtx?: ExecutionContext): Promise<LoadDataResponse | void>;
|
|
133
|
+
private getLoadDataRequest;
|
|
133
134
|
private notifySavingData;
|
|
134
135
|
/**
|
|
135
136
|
*
|
|
@@ -429,79 +430,67 @@ export default class DataUnit {
|
|
|
429
430
|
*
|
|
430
431
|
*/
|
|
431
432
|
cancelWaitingChange(fieldName: string): void;
|
|
432
|
-
/**
|
|
433
|
-
* Obtém todos os registros selecionados.
|
|
434
|
-
*
|
|
435
|
-
* @returns - Lista de todos os registros selecionados.
|
|
436
|
-
*/
|
|
437
|
-
getSelection(): Array<Record>;
|
|
438
433
|
/**
|
|
439
434
|
*
|
|
440
|
-
* Seleciona
|
|
441
|
-
*
|
|
442
|
-
* @param selection - Registros para selecionar.
|
|
443
|
-
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
435
|
+
* Seleciona o primeiro registro.
|
|
444
436
|
*
|
|
445
|
-
* @
|
|
437
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
446
438
|
*
|
|
447
439
|
*/
|
|
448
|
-
|
|
440
|
+
selectFirst(executionCtx?: ExecutionContext): void;
|
|
449
441
|
/**
|
|
450
442
|
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
* @param unselection - Registros para remover a seleção.
|
|
454
|
-
* @param executionCtx - Contexto de execução da remoção da seleção dos registros do DataUnit.
|
|
443
|
+
* Seleciona o último registro.
|
|
455
444
|
*
|
|
456
|
-
* @
|
|
445
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
457
446
|
*
|
|
458
447
|
*/
|
|
459
|
-
|
|
448
|
+
selectLast(executionCtx?: ExecutionContext): void;
|
|
460
449
|
/**
|
|
461
450
|
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
* @param executionCtx - Contexto de execução da remoção da seleção dos registros do DataUnit.
|
|
451
|
+
* Seleciona múltiplos registros por índice.
|
|
465
452
|
*
|
|
466
|
-
* @
|
|
453
|
+
* @param selection - Índices desejados para a seleção.
|
|
454
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
467
455
|
*
|
|
468
456
|
*/
|
|
469
|
-
|
|
457
|
+
setSelectionByIndex(selection: Array<number>, executionCtx?: ExecutionContext): void;
|
|
470
458
|
/**
|
|
471
459
|
*
|
|
472
|
-
* Seleciona
|
|
460
|
+
* Seleciona múltiplos registros por ID ou todos os registros (multipágina) .
|
|
461
|
+
*
|
|
462
|
+
* @param selection - IDs para selecionar ou o modo de seleção completo.
|
|
463
|
+
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
473
464
|
*
|
|
474
|
-
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
475
465
|
*
|
|
476
466
|
*/
|
|
477
|
-
|
|
467
|
+
setSelection(selection: Array<string> | SelectionMode.ALL_RECORDS, executionCtx?: ExecutionContext): Promise<SelectionInfo>;
|
|
478
468
|
/**
|
|
479
469
|
*
|
|
480
|
-
*
|
|
470
|
+
* Limpa a seleção.
|
|
481
471
|
*
|
|
482
|
-
* @param executionCtx - Contexto de execução da seleção
|
|
472
|
+
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
483
473
|
*
|
|
484
474
|
*/
|
|
485
|
-
|
|
475
|
+
clearSelection(executionCtx?: ExecutionContext): void;
|
|
486
476
|
/**
|
|
487
477
|
*
|
|
488
|
-
*
|
|
478
|
+
* Atualiza a seleção dos registros atuais.
|
|
489
479
|
*
|
|
490
|
-
* @param selection -
|
|
491
|
-
* @param executionCtx - Contexto de execução da seleção
|
|
492
|
-
*
|
|
493
|
-
* @returns - Verdadeiro se ação executada.
|
|
480
|
+
* @param selection - IDs dos registros selecionados no snapshot atual
|
|
481
|
+
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
494
482
|
*
|
|
483
|
+
* @returns - Informações sobre a seleção.
|
|
495
484
|
*/
|
|
496
|
-
|
|
485
|
+
updatePageSelection(selection: Array<string>, executionCtx?: ExecutionContext): Promise<SelectionInfo | undefined>;
|
|
497
486
|
/**
|
|
498
487
|
*
|
|
499
|
-
* Obtém
|
|
488
|
+
* Obtém informações sobre a seleção atual.
|
|
500
489
|
*
|
|
501
|
-
* @returns -
|
|
490
|
+
* @returns - Objeto com informações como registros selecionados e seleção por critério.
|
|
502
491
|
*
|
|
503
|
-
|
|
504
|
-
|
|
492
|
+
**/
|
|
493
|
+
getSelectionInfo(): SelectionInfo | undefined;
|
|
505
494
|
/**
|
|
506
495
|
*
|
|
507
496
|
* Retorna apenas um registro selecionado no Dataunit
|
|
@@ -515,7 +504,6 @@ export default class DataUnit {
|
|
|
515
504
|
* Limpa todos os registros do DataUnit
|
|
516
505
|
*
|
|
517
506
|
*
|
|
518
|
-
*
|
|
519
507
|
*/
|
|
520
508
|
clearDataUnit(): void;
|
|
521
509
|
/**
|
|
@@ -737,6 +725,14 @@ export default class DataUnit {
|
|
|
737
725
|
*
|
|
738
726
|
*/
|
|
739
727
|
getFilters(): Array<Filter> | undefined;
|
|
728
|
+
/**
|
|
729
|
+
*
|
|
730
|
+
* Obtém os filtros aplicados.
|
|
731
|
+
*
|
|
732
|
+
* @returns - Lista de filtros.
|
|
733
|
+
*
|
|
734
|
+
*/
|
|
735
|
+
getAppliedFilters(): Array<Filter> | undefined;
|
|
740
736
|
/**
|
|
741
737
|
*
|
|
742
738
|
* Habilita um campo do DataUnit
|
|
@@ -765,6 +761,30 @@ export default class DataUnit {
|
|
|
765
761
|
*
|
|
766
762
|
*/
|
|
767
763
|
showField(fieldName: string): void;
|
|
764
|
+
/**
|
|
765
|
+
*
|
|
766
|
+
* Obtém todos os registros selecionados.
|
|
767
|
+
*
|
|
768
|
+
* @returns - Lista de registros selecionados.
|
|
769
|
+
*
|
|
770
|
+
* @deprecated - Utilize o método `getSelectionInfo()` para obter os registros selecionados.
|
|
771
|
+
* Devido a seleção virtual baseada em critérios e ordenação (ALL_RECORDS), esse
|
|
772
|
+
* método foi descontinuado e pode retornar erros no caso da seleção virtual.
|
|
773
|
+
*
|
|
774
|
+
*/
|
|
775
|
+
getSelectedRecords(): Array<Record> | undefined;
|
|
776
|
+
/**
|
|
777
|
+
*
|
|
778
|
+
* Obtém ids dos registros selecionados.
|
|
779
|
+
*
|
|
780
|
+
* @returns - Lista com id de todos os registros selecionados.
|
|
781
|
+
*
|
|
782
|
+
* @deprecated - Utilize o método `getSelectionInfo()` para obter os registros selecionados.
|
|
783
|
+
* Devido a seleção virtual baseada em critérios e ordenação (ALL_RECORDS), esse
|
|
784
|
+
* método foi descontinuado e pode retornar erros no caso da seleção virtual.
|
|
785
|
+
*
|
|
786
|
+
*/
|
|
787
|
+
getSelection(): Array<string>;
|
|
768
788
|
}
|
|
769
789
|
export interface DUActionInterceptor {
|
|
770
790
|
interceptAction(action: DataUnitAction): DataUnitAction | Promise<DataUnitAction>;
|
|
@@ -779,10 +799,6 @@ export interface Record {
|
|
|
779
799
|
export interface SavedRecord extends Record {
|
|
780
800
|
__old__id__?: string;
|
|
781
801
|
}
|
|
782
|
-
export interface AllRecord extends Record {
|
|
783
|
-
filter: Array<Filter>;
|
|
784
|
-
sort: Array<Sort>;
|
|
785
|
-
}
|
|
786
802
|
export declare enum ChangeOperation {
|
|
787
803
|
INSERT = "INSERT",
|
|
788
804
|
COPY = "COPY",
|
|
@@ -853,6 +869,7 @@ export interface PageRequest {
|
|
|
853
869
|
export interface QuickFilter {
|
|
854
870
|
term: string;
|
|
855
871
|
fields?: Array<string>;
|
|
872
|
+
filter?: Filter;
|
|
856
873
|
}
|
|
857
874
|
export interface PageResponse {
|
|
858
875
|
limit: number;
|
|
@@ -861,3 +878,20 @@ export interface PageResponse {
|
|
|
861
878
|
hasMore: boolean;
|
|
862
879
|
records: Array<Record>;
|
|
863
880
|
}
|
|
881
|
+
export declare enum SelectionMode {
|
|
882
|
+
ALL_RECORDS = "ALL_RECORDS",
|
|
883
|
+
SOME_RECORDS = "SOME_RECORDS"
|
|
884
|
+
}
|
|
885
|
+
export declare class SelectionInfo {
|
|
886
|
+
private _records;
|
|
887
|
+
mode: SelectionMode;
|
|
888
|
+
private _total?;
|
|
889
|
+
filters?: Array<Filter>;
|
|
890
|
+
sort?: Array<Sort>;
|
|
891
|
+
constructor(records: Array<Record>, mode?: SelectionMode, total?: number, filters?: Array<Filter>, sort?: Array<Sort>);
|
|
892
|
+
get records(): Array<Record> | undefined;
|
|
893
|
+
get recordIds(): Array<string> | undefined;
|
|
894
|
+
get length(): number;
|
|
895
|
+
isAllRecords(): boolean;
|
|
896
|
+
isEmpty(): boolean;
|
|
897
|
+
}
|
|
@@ -16,11 +16,11 @@ import { StringUtils } from "../utils/StringUtils.js";
|
|
|
16
16
|
import ObjectUtils from "../utils/ObjectUtils.js";
|
|
17
17
|
import { AddedRecordsReducer, getAddedRecords, prepareAddedRecordId, prepareCopiedRecord } from "./state/slice/AddedRecordsSlice.js";
|
|
18
18
|
import { ChangesReducer, getChangesToSave, isDirty, hasDirtyRecords } from "./state/slice/ChangesSlice.js";
|
|
19
|
-
import {
|
|
19
|
+
import { SnapshotReducer, getCurrentRecords, getFieldValue, getModifiedRecords } from "./state/slice/SnapshotSlice.js";
|
|
20
20
|
import { getCurrentPage, getLastPage, getPaginationInfo, getCurrentRequest, LoadingControlReducer, hasMorePages, hasPreviousPages } from "./state/slice/LoadingControlSlice.js";
|
|
21
21
|
import { getRecords, RecordsReducer } from "./state/slice/RecordsSlice.js";
|
|
22
22
|
import { RemovedRecordsReducer } from "./state/slice/RemovedRecordsSlice.js";
|
|
23
|
-
import { getSelection, hasNext, hasPrevious, SelectionReducer } from "./state/slice/SelectionSlice.js";
|
|
23
|
+
import { getSelection, getSelectionInfo, hasNext, hasPrevious, SelectionReducer } from "./state/slice/SelectionSlice.js";
|
|
24
24
|
import { getField, getMetadata, UnitMetadataReducer } from "./state/slice/UnitMetadataSlice.js";
|
|
25
25
|
import { getBlockingWaitingChanges, getWaitingChangePromisses, isWaiting, WaitingChangesReducer } from "./state/slice/WaitingChangesSlice.js";
|
|
26
26
|
import { canRedo, canUndo, HistReducer } from "./state/HistReducer.js";
|
|
@@ -43,16 +43,16 @@ export default class DataUnit {
|
|
|
43
43
|
*
|
|
44
44
|
*/
|
|
45
45
|
this.onDataUnitParentEvent = (action) => {
|
|
46
|
-
var _a
|
|
46
|
+
var _a;
|
|
47
47
|
switch (action.type) {
|
|
48
48
|
case Action.SELECTION_CHANGED:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.loadData();
|
|
52
|
-
break;
|
|
49
|
+
case Action.NEXT_SELECTED:
|
|
50
|
+
case Action.PREVIOUS_SELECTED:
|
|
53
51
|
case Action.DATA_LOADED:
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
this.clearDataUnit();
|
|
53
|
+
const selectedRecord = (_a = this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.getSelectedRecord();
|
|
54
|
+
if (selectedRecord != undefined && this.isNewRecord(selectedRecord.__record__id__)) {
|
|
55
|
+
this.loadData();
|
|
56
56
|
}
|
|
57
57
|
break;
|
|
58
58
|
}
|
|
@@ -70,8 +70,8 @@ export default class DataUnit {
|
|
|
70
70
|
SelectionReducer,
|
|
71
71
|
ChangesReducer,
|
|
72
72
|
WaitingChangesReducer,
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
InvalidFieldsReducer,
|
|
74
|
+
SnapshotReducer
|
|
75
75
|
]);
|
|
76
76
|
this._observers = [];
|
|
77
77
|
this._filterProviders = new Map();
|
|
@@ -159,7 +159,7 @@ export default class DataUnit {
|
|
|
159
159
|
if (yield this.dispatchAction(Action.LOADING_DATA, request, executionCtx)) {
|
|
160
160
|
if (this.dataLoader) {
|
|
161
161
|
this.dataLoader(this, request).then(response => {
|
|
162
|
-
this.dispatchAction(Action.DATA_LOADED, response, executionCtx);
|
|
162
|
+
this.dispatchAction(Action.DATA_LOADED, Object.assign(Object.assign({}, response), { keepSelection: request.keepSelection }), executionCtx);
|
|
163
163
|
resolve(response);
|
|
164
164
|
}).catch(error => {
|
|
165
165
|
const { errorCode } = error;
|
|
@@ -213,7 +213,6 @@ export default class DataUnit {
|
|
|
213
213
|
*/
|
|
214
214
|
loadData(quickFilter, executionCtx, checkLastFilter) {
|
|
215
215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
-
yield this.clearSelection(executionCtx);
|
|
217
216
|
if (this._parentDataUnit && !this._parentDataUnit.getSelectedRecord()) {
|
|
218
217
|
if (this.records) {
|
|
219
218
|
this.clearDataUnit();
|
|
@@ -222,16 +221,7 @@ export default class DataUnit {
|
|
|
222
221
|
records: []
|
|
223
222
|
});
|
|
224
223
|
}
|
|
225
|
-
const loadDataRequest =
|
|
226
|
-
quickFilter,
|
|
227
|
-
filters: this.getFilters(),
|
|
228
|
-
sort: this.getSort(),
|
|
229
|
-
parentRecordId: this.getParentRecordId()
|
|
230
|
-
};
|
|
231
|
-
if (this._pageSize > 0) {
|
|
232
|
-
loadDataRequest.limit = this._pageSize;
|
|
233
|
-
loadDataRequest.offset = 0;
|
|
234
|
-
}
|
|
224
|
+
const loadDataRequest = this.getLoadDataRequest(quickFilter);
|
|
235
225
|
return this.executeLoadData(loadDataRequest, executionCtx, checkLastFilter);
|
|
236
226
|
});
|
|
237
227
|
}
|
|
@@ -255,7 +245,7 @@ export default class DataUnit {
|
|
|
255
245
|
};
|
|
256
246
|
}
|
|
257
247
|
if (page >= 0 && page <= getLastPage(this._stateManager, this._pageSize)) {
|
|
258
|
-
return this.executeLoadData(Object.assign(Object.assign({}, request), { limit: this._pageSize, offset: page * this._pageSize }), executionCtx);
|
|
248
|
+
return this.executeLoadData(Object.assign(Object.assign({}, request), { limit: this._pageSize, offset: page * this._pageSize, keepSelection: true }), executionCtx);
|
|
259
249
|
}
|
|
260
250
|
});
|
|
261
251
|
}
|
|
@@ -287,6 +277,21 @@ export default class DataUnit {
|
|
|
287
277
|
return this.gotoPage(getCurrentPage(this._stateManager) - 1, executionCtx);
|
|
288
278
|
});
|
|
289
279
|
}
|
|
280
|
+
getLoadDataRequest(quickFilter) {
|
|
281
|
+
const request = {
|
|
282
|
+
filters: (quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.filter) ? [quickFilter.filter] : this.getFilters(),
|
|
283
|
+
sort: this.getSort(),
|
|
284
|
+
parentRecordId: this.getParentRecordId()
|
|
285
|
+
};
|
|
286
|
+
if (quickFilter) {
|
|
287
|
+
request.quickFilter = quickFilter;
|
|
288
|
+
}
|
|
289
|
+
if (this._pageSize > 0) {
|
|
290
|
+
request.limit = this._pageSize;
|
|
291
|
+
request.offset = 0;
|
|
292
|
+
}
|
|
293
|
+
return request;
|
|
294
|
+
}
|
|
290
295
|
notifySavingData(executionCtx) {
|
|
291
296
|
return __awaiter(this, void 0, void 0, function* () {
|
|
292
297
|
const notifyPromises = [];
|
|
@@ -397,12 +402,16 @@ export default class DataUnit {
|
|
|
397
402
|
*/
|
|
398
403
|
removeSelectedRecords(buffered = false) {
|
|
399
404
|
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
-
const selection =
|
|
405
|
+
const selection = this.getSelectionInfo();
|
|
401
406
|
if (selection) {
|
|
402
|
-
|
|
403
|
-
|
|
407
|
+
if (selection.isAllRecords()) {
|
|
408
|
+
throw new Error("Exclusão remota não implementada.");
|
|
409
|
+
}
|
|
410
|
+
const records = (selection === null || selection === void 0 ? void 0 : selection.records) || [];
|
|
411
|
+
const recordIds = (selection === null || selection === void 0 ? void 0 : selection.recordIds) || [];
|
|
412
|
+
return this.removeRecords(recordIds, records, buffered);
|
|
404
413
|
}
|
|
405
|
-
return Promise.resolve(
|
|
414
|
+
return Promise.resolve([]);
|
|
406
415
|
});
|
|
407
416
|
}
|
|
408
417
|
/**
|
|
@@ -671,9 +680,12 @@ export default class DataUnit {
|
|
|
671
680
|
*
|
|
672
681
|
*/
|
|
673
682
|
copySelected(executionCtx) {
|
|
674
|
-
const
|
|
675
|
-
if (
|
|
676
|
-
|
|
683
|
+
const selectionInfo = this.getSelectionInfo();
|
|
684
|
+
if (selectionInfo) {
|
|
685
|
+
const selectedRecords = selectionInfo.records;
|
|
686
|
+
if (selectedRecords) {
|
|
687
|
+
this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
|
|
688
|
+
}
|
|
677
689
|
}
|
|
678
690
|
}
|
|
679
691
|
getRecordsByDataUnit(records) {
|
|
@@ -793,111 +805,104 @@ export default class DataUnit {
|
|
|
793
805
|
this.dispatchAction(Action.WAITING_CHANGE_CANCELED, { fieldName }, undefined);
|
|
794
806
|
}
|
|
795
807
|
/**
|
|
796
|
-
* Obtém todos os registros selecionados.
|
|
797
|
-
*
|
|
798
|
-
* @returns - Lista de todos os registros selecionados.
|
|
799
|
-
*/
|
|
800
|
-
getSelection() {
|
|
801
|
-
return getSelection(this._stateManager);
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
*
|
|
805
|
-
* Seleciona múltiplos registros.
|
|
806
808
|
*
|
|
807
|
-
*
|
|
808
|
-
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
809
|
+
* Seleciona o primeiro registro.
|
|
809
810
|
*
|
|
810
|
-
* @
|
|
811
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
811
812
|
*
|
|
812
813
|
*/
|
|
813
|
-
|
|
814
|
-
|
|
814
|
+
selectFirst(executionCtx) {
|
|
815
|
+
if (this.records.length > 0) {
|
|
816
|
+
this.setSelectionByIndex([0], executionCtx);
|
|
817
|
+
}
|
|
815
818
|
}
|
|
816
819
|
/**
|
|
817
820
|
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
* @param unselection - Registros para remover a seleção.
|
|
821
|
-
* @param executionCtx - Contexto de execução da remoção da seleção dos registros do DataUnit.
|
|
821
|
+
* Seleciona o último registro.
|
|
822
822
|
*
|
|
823
|
-
* @
|
|
823
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
824
824
|
*
|
|
825
825
|
*/
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
return this.dispatchAction(Action.SELECTION_REMOVED, { type: "id", unselection }, executionCtx);
|
|
826
|
+
selectLast(executionCtx) {
|
|
827
|
+
if (this.records.length > 0) {
|
|
828
|
+
this.setSelectionByIndex([this.records.length - 1], executionCtx);
|
|
830
829
|
}
|
|
831
|
-
return Promise.resolve(false);
|
|
832
830
|
}
|
|
833
831
|
/**
|
|
834
832
|
*
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
* @param executionCtx - Contexto de execução da remoção da seleção dos registros do DataUnit.
|
|
833
|
+
* Seleciona múltiplos registros por índice.
|
|
838
834
|
*
|
|
839
|
-
* @
|
|
835
|
+
* @param selection - Índices desejados para a seleção.
|
|
836
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
840
837
|
*
|
|
841
838
|
*/
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
if (((_a = this.getSelection()) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
845
|
-
return this.dispatchAction(Action.SELECTION_REMOVED, { type: "id", unselection: this.getSelection() }, executionCtx);
|
|
846
|
-
}
|
|
847
|
-
return Promise.resolve(false);
|
|
839
|
+
setSelectionByIndex(selection, executionCtx) {
|
|
840
|
+
this.dispatchAction(Action.SELECTION_CHANGED, { type: "index", selection }, executionCtx);
|
|
848
841
|
}
|
|
849
842
|
/**
|
|
850
843
|
*
|
|
851
|
-
* Seleciona
|
|
844
|
+
* Seleciona múltiplos registros por ID ou todos os registros (multipágina) .
|
|
845
|
+
*
|
|
846
|
+
* @param selection - IDs para selecionar ou o modo de seleção completo.
|
|
847
|
+
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
852
848
|
*
|
|
853
|
-
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
854
849
|
*
|
|
855
850
|
*/
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
this.
|
|
859
|
-
|
|
851
|
+
setSelection(selection, executionCtx) {
|
|
852
|
+
return new Promise(resolve => {
|
|
853
|
+
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }, executionCtx)
|
|
854
|
+
.then(() => resolve(getSelectionInfo(this._stateManager)));
|
|
855
|
+
});
|
|
860
856
|
}
|
|
861
857
|
/**
|
|
862
858
|
*
|
|
863
|
-
*
|
|
859
|
+
* Limpa a seleção.
|
|
864
860
|
*
|
|
865
|
-
* @param executionCtx - Contexto de execução da seleção
|
|
861
|
+
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
866
862
|
*
|
|
867
863
|
*/
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
this.setSelectionByIndex([this.records.length - 1], executionCtx);
|
|
871
|
-
}
|
|
864
|
+
clearSelection(executionCtx) {
|
|
865
|
+
this.setSelection([], executionCtx);
|
|
872
866
|
}
|
|
873
867
|
/**
|
|
874
868
|
*
|
|
875
|
-
*
|
|
876
|
-
*
|
|
877
|
-
* @param selection - Índices desejados para a seleção.
|
|
878
|
-
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
869
|
+
* Atualiza a seleção dos registros atuais.
|
|
879
870
|
*
|
|
880
|
-
* @
|
|
871
|
+
* @param selection - IDs dos registros selecionados no snapshot atual
|
|
872
|
+
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
881
873
|
*
|
|
874
|
+
* @returns - Informações sobre a seleção.
|
|
882
875
|
*/
|
|
883
|
-
|
|
884
|
-
|
|
876
|
+
updatePageSelection(selection, executionCtx) {
|
|
877
|
+
if (!selection) {
|
|
878
|
+
return Promise.resolve(this.getSelectionInfo());
|
|
879
|
+
}
|
|
880
|
+
return new Promise(resolve => {
|
|
881
|
+
const newSelection = new Set(getSelection(this._stateManager));
|
|
882
|
+
const currentRecords = getCurrentRecords(this._stateManager) || new Map();
|
|
883
|
+
Array.from(currentRecords.keys()).forEach(recordId => {
|
|
884
|
+
if (selection.includes(recordId)) {
|
|
885
|
+
newSelection.add(recordId);
|
|
886
|
+
}
|
|
887
|
+
else {
|
|
888
|
+
newSelection.delete(recordId);
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) }, executionCtx)
|
|
892
|
+
.then(() => {
|
|
893
|
+
resolve(this.getSelectionInfo());
|
|
894
|
+
});
|
|
895
|
+
});
|
|
885
896
|
}
|
|
886
897
|
/**
|
|
887
898
|
*
|
|
888
|
-
* Obtém
|
|
899
|
+
* Obtém informações sobre a seleção atual.
|
|
889
900
|
*
|
|
890
|
-
* @returns -
|
|
901
|
+
* @returns - Objeto com informações como registros selecionados e seleção por critério.
|
|
891
902
|
*
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
if (selection) {
|
|
896
|
-
const currentRecords = this.records;
|
|
897
|
-
return currentRecords === null || currentRecords === void 0 ? void 0 : currentRecords.filter((record) => {
|
|
898
|
-
return selection.some((sel) => sel.__record__id__ === record.__record__id__);
|
|
899
|
-
});
|
|
900
|
-
}
|
|
903
|
+
**/
|
|
904
|
+
getSelectionInfo() {
|
|
905
|
+
return getSelectionInfo(this._stateManager);
|
|
901
906
|
}
|
|
902
907
|
/**
|
|
903
908
|
*
|
|
@@ -907,17 +912,16 @@ export default class DataUnit {
|
|
|
907
912
|
*
|
|
908
913
|
*/
|
|
909
914
|
getSelectedRecord() {
|
|
910
|
-
const selection = this.
|
|
915
|
+
const selection = getSelection(this._stateManager);
|
|
911
916
|
if (!selection)
|
|
912
917
|
return;
|
|
913
|
-
return this.records.find(record => selection.
|
|
918
|
+
return this.records.find(record => selection.includes(record.__record__id__));
|
|
914
919
|
}
|
|
915
920
|
/**
|
|
916
921
|
*
|
|
917
922
|
* Limpa todos os registros do DataUnit
|
|
918
923
|
*
|
|
919
924
|
*
|
|
920
|
-
*
|
|
921
925
|
*/
|
|
922
926
|
clearDataUnit() {
|
|
923
927
|
this.records = [];
|
|
@@ -1285,13 +1289,13 @@ export default class DataUnit {
|
|
|
1285
1289
|
*/
|
|
1286
1290
|
reloadCurrentRecord() {
|
|
1287
1291
|
return new Promise((resolve, fail) => __awaiter(this, void 0, void 0, function* () {
|
|
1288
|
-
const selection = this.
|
|
1292
|
+
const selection = getSelection(this._stateManager);
|
|
1289
1293
|
this.dispatchAction(Action.LOADING_RECORD, selection);
|
|
1290
1294
|
if (!this.dataLoader)
|
|
1291
1295
|
return;
|
|
1292
1296
|
if (!this.recordLoader)
|
|
1293
1297
|
return;
|
|
1294
|
-
this.recordLoader(this, selection
|
|
1298
|
+
this.recordLoader(this, selection).then(response => {
|
|
1295
1299
|
this.dispatchAction(Action.RECORD_LOADED, response);
|
|
1296
1300
|
}).catch(cause => {
|
|
1297
1301
|
const { errorCode } = cause;
|
|
@@ -1326,6 +1330,17 @@ export default class DataUnit {
|
|
|
1326
1330
|
});
|
|
1327
1331
|
return filters;
|
|
1328
1332
|
}
|
|
1333
|
+
/**
|
|
1334
|
+
*
|
|
1335
|
+
* Obtém os filtros aplicados.
|
|
1336
|
+
*
|
|
1337
|
+
* @returns - Lista de filtros.
|
|
1338
|
+
*
|
|
1339
|
+
*/
|
|
1340
|
+
getAppliedFilters() {
|
|
1341
|
+
const { filters } = getCurrentRequest(this._stateManager) || {};
|
|
1342
|
+
return filters;
|
|
1343
|
+
}
|
|
1329
1344
|
/**
|
|
1330
1345
|
*
|
|
1331
1346
|
* Habilita um campo do DataUnit
|
|
@@ -1378,6 +1393,46 @@ export default class DataUnit {
|
|
|
1378
1393
|
this.metadata = Object.assign({}, this.metadata);
|
|
1379
1394
|
}
|
|
1380
1395
|
}
|
|
1396
|
+
/**
|
|
1397
|
+
*
|
|
1398
|
+
* Obtém todos os registros selecionados.
|
|
1399
|
+
*
|
|
1400
|
+
* @returns - Lista de registros selecionados.
|
|
1401
|
+
*
|
|
1402
|
+
* @deprecated - Utilize o método `getSelectionInfo()` para obter os registros selecionados.
|
|
1403
|
+
* Devido a seleção virtual baseada em critérios e ordenação (ALL_RECORDS), esse
|
|
1404
|
+
* método foi descontinuado e pode retornar erros no caso da seleção virtual.
|
|
1405
|
+
*
|
|
1406
|
+
*/
|
|
1407
|
+
getSelectedRecords() {
|
|
1408
|
+
console.warn("DataUnit: O método `getSelectedRecords` foi descontinuado. Use o método `getSelectionInfo`.");
|
|
1409
|
+
const selection = this.getSelectionInfo();
|
|
1410
|
+
if (selection != undefined && selection.isAllRecords()) {
|
|
1411
|
+
throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
|
|
1412
|
+
}
|
|
1413
|
+
if (selection) {
|
|
1414
|
+
return selection.records;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
*
|
|
1419
|
+
* Obtém ids dos registros selecionados.
|
|
1420
|
+
*
|
|
1421
|
+
* @returns - Lista com id de todos os registros selecionados.
|
|
1422
|
+
*
|
|
1423
|
+
* @deprecated - Utilize o método `getSelectionInfo()` para obter os registros selecionados.
|
|
1424
|
+
* Devido a seleção virtual baseada em critérios e ordenação (ALL_RECORDS), esse
|
|
1425
|
+
* método foi descontinuado e pode retornar erros no caso da seleção virtual.
|
|
1426
|
+
*
|
|
1427
|
+
*/
|
|
1428
|
+
getSelection() {
|
|
1429
|
+
console.warn("DataUnit: O método `getSelection` foi descontinuado. Use o método `getSelectionInfo`.");
|
|
1430
|
+
const selection = this.getSelectionInfo();
|
|
1431
|
+
if (selection != undefined && selection.isAllRecords()) {
|
|
1432
|
+
throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
|
|
1433
|
+
}
|
|
1434
|
+
return (selection === null || selection === void 0 ? void 0 : selection.recordIds) || [];
|
|
1435
|
+
}
|
|
1381
1436
|
}
|
|
1382
1437
|
export var ChangeOperation;
|
|
1383
1438
|
(function (ChangeOperation) {
|
|
@@ -1448,4 +1503,43 @@ export class Change {
|
|
|
1448
1503
|
return this._operation === ChangeOperation.UPDATE;
|
|
1449
1504
|
}
|
|
1450
1505
|
}
|
|
1506
|
+
export var SelectionMode;
|
|
1507
|
+
(function (SelectionMode) {
|
|
1508
|
+
SelectionMode["ALL_RECORDS"] = "ALL_RECORDS";
|
|
1509
|
+
SelectionMode["SOME_RECORDS"] = "SOME_RECORDS";
|
|
1510
|
+
})(SelectionMode || (SelectionMode = {}));
|
|
1511
|
+
export class SelectionInfo {
|
|
1512
|
+
constructor(records, mode = SelectionMode.SOME_RECORDS, total, filters, sort) {
|
|
1513
|
+
this._records = records;
|
|
1514
|
+
this._total = total;
|
|
1515
|
+
this.mode = mode;
|
|
1516
|
+
this.filters = filters;
|
|
1517
|
+
this.sort = sort;
|
|
1518
|
+
}
|
|
1519
|
+
get records() {
|
|
1520
|
+
if (this.isAllRecords()) {
|
|
1521
|
+
throw new Error("Erro interno: [ALL_RECORDS] - Impossível retornar os registros selecionados numa seleção virtual.");
|
|
1522
|
+
}
|
|
1523
|
+
return this._records;
|
|
1524
|
+
}
|
|
1525
|
+
get recordIds() {
|
|
1526
|
+
const records = this.records;
|
|
1527
|
+
if (records == undefined) {
|
|
1528
|
+
return undefined;
|
|
1529
|
+
}
|
|
1530
|
+
return records.map(record => record.__record__id__);
|
|
1531
|
+
}
|
|
1532
|
+
get length() {
|
|
1533
|
+
if (this.isAllRecords()) {
|
|
1534
|
+
return this._total || 0;
|
|
1535
|
+
}
|
|
1536
|
+
return this.records == undefined ? 0 : this.records.length;
|
|
1537
|
+
}
|
|
1538
|
+
isAllRecords() {
|
|
1539
|
+
return this.mode === SelectionMode.ALL_RECORDS;
|
|
1540
|
+
}
|
|
1541
|
+
isEmpty() {
|
|
1542
|
+
return this.length === 0;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1451
1545
|
//# sourceMappingURL=DataUnit.js.map
|