@sankhyalabs/core 6.1.1 → 6.2.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/Change.md +11 -11
- package/.docs/classes/ColumnFilterManager.md +6 -6
- package/.docs/classes/DataUnit.md +158 -158
- package/.docs/classes/DataUnitLoaderUtils.md +6 -6
- package/.docs/classes/LangUtils.md +195 -0
- 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/globals.md +1 -0
- 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/formatting/PrettyFormatter.js +5 -3
- package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
- 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 +6 -2
- package/dist/index.js +6 -2
- 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/LangUtils.d.ts +83 -0
- package/dist/utils/LangUtils.js +121 -0
- package/dist/utils/LangUtils.js.map +1 -0
- package/dist/utils/SortingUtils.d.ts +1 -1
- package/package.json +2 -1
- package/reports/test-report.xml +657 -440
- 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/formatting/PrettyFormatter.ts +4 -5
- 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 +6 -2
- package/src/utils/ColumnFilterManager.ts +2 -1
- package/src/utils/LangUtils.ts +129 -0
- 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/formatting/PrettyFormatter.spec.ts +1 -1
- 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/test/util/LangUtils.spec.ts +117 -0
- package/tsconfig.json +1 -0
- package/src/dataunit/test/DataUnit.spec.ts +0 -44
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ChangeOperation } from "./interfaces/dataUnit.js";
|
|
2
|
+
/***
|
|
3
|
+
* `Change`: Dados que representam uma alteração.
|
|
4
|
+
*/
|
|
5
|
+
export class Change {
|
|
6
|
+
constructor(dataUnit, record, updates, operation, sourceId) {
|
|
7
|
+
this.dataUnit = dataUnit;
|
|
8
|
+
this.record = record;
|
|
9
|
+
this.sourceId = sourceId;
|
|
10
|
+
this.updatingFields = updates;
|
|
11
|
+
this._operation = operation;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* Obtém o tipo de operação que está sendo realizada.
|
|
16
|
+
*
|
|
17
|
+
* @returns - Ação que está sendo executada.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
get operation() {
|
|
21
|
+
return this._operation.toString();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* Retorna se o DataUnit está em uma operação de inserção.
|
|
26
|
+
*
|
|
27
|
+
* @returns - Verdadeiro se a operação for de inserção.
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
isInsert() {
|
|
31
|
+
return this._operation === ChangeOperation.INSERT;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* Retorna se o DataUnit está em uma operação de cópia.
|
|
36
|
+
*
|
|
37
|
+
* @returns - Verdadeiro se a operação for de cópia.
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
isCopy() {
|
|
41
|
+
return this._operation === ChangeOperation.COPY;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* Retorna se o DataUnit está em uma operação de deleção.
|
|
46
|
+
*
|
|
47
|
+
* @returns - Verdadeiro se a operação for de deleção.
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
isDelete() {
|
|
51
|
+
return this._operation === ChangeOperation.DELETE;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* Retorna se o DataUnit está em uma operação de atualização.
|
|
56
|
+
*
|
|
57
|
+
* @returns - Verdadeiro se a operação for de atualização.
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
isUpdate() {
|
|
61
|
+
return this._operation === ChangeOperation.UPDATE;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=Changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Changes.js","sourceRoot":"","sources":["../../src/dataunit/Changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAU,MAAM,0BAA0B,CAAC;AAEnE;;GAEG;AACH,MAAM,OAAO,MAAM;IASf,YAAY,QAAgB,EAAE,MAAc,EAAE,OAAY,EAAE,SAA0B,EAAE,QAAiB;QACrG,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACX,OAAO,IAAI,CAAC,UAAU,KAAK,eAAe,CAAC,MAAM,CAAC;IACtD,CAAC;IAED;;;;;;OAMG;IACI,MAAM;QACT,OAAO,IAAI,CAAC,UAAU,KAAK,eAAe,CAAC,IAAI,CAAC;IACpD,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACX,OAAO,IAAI,CAAC,UAAU,KAAK,eAAe,CAAC,MAAM,CAAC;IACtD,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACX,OAAO,IAAI,CAAC,UAAU,KAAK,eAAe,CAAC,MAAM,CAAC;IACtD,CAAC;CACJ"}
|
|
@@ -3,6 +3,9 @@ import { DataUnitAction, ExecutionContext } from "./state/action/DataUnitAction.
|
|
|
3
3
|
import { LoadDataRequest } from "./loading/LoadDataRequest.js";
|
|
4
4
|
import { LoadDataResponse } from "./loading/LoadDataResponse.js";
|
|
5
5
|
import { PaginationInfo } from "./loading/PaginationInfo.js";
|
|
6
|
+
import { DataUnitEventOptions, DUActionInterceptor, HideFieldOptions, LoadDataParams, QuickFilter, Record, SavedRecord, SelectionMode, WaitingChange } from "./interfaces/dataUnit.js";
|
|
7
|
+
import { Change } from "./Changes.js";
|
|
8
|
+
import { SelectionInfo } from "./SelectionInfo.js";
|
|
6
9
|
/***
|
|
7
10
|
* `DataUnit`: Atua como uma camada de abstração entre o back-end e a interface do usuário.
|
|
8
11
|
*/
|
|
@@ -601,7 +604,7 @@ export default class DataUnit {
|
|
|
601
604
|
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
602
605
|
* @returns - Informações sobre a seleção.
|
|
603
606
|
*/
|
|
604
|
-
updatePageSelection(selection
|
|
607
|
+
updatePageSelection(selection?: Array<string>, executionCtx?: ExecutionContext): Promise<SelectionInfo | undefined>;
|
|
605
608
|
private updatePageSelectionAll;
|
|
606
609
|
/**
|
|
607
610
|
* Seleciona todos os registros da página.
|
|
@@ -652,7 +655,7 @@ export default class DataUnit {
|
|
|
652
655
|
*
|
|
653
656
|
*
|
|
654
657
|
*/
|
|
655
|
-
nextRecord(executionCtx?: ExecutionContext): void
|
|
658
|
+
nextRecord(executionCtx?: ExecutionContext): Promise<void>;
|
|
656
659
|
/**
|
|
657
660
|
*
|
|
658
661
|
* Seleciona o registro anterior.
|
|
@@ -660,7 +663,7 @@ export default class DataUnit {
|
|
|
660
663
|
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
661
664
|
*
|
|
662
665
|
*/
|
|
663
|
-
previousRecord(executionCtx?: ExecutionContext): void
|
|
666
|
+
previousRecord(executionCtx?: ExecutionContext): Promise<void>;
|
|
664
667
|
/**
|
|
665
668
|
*
|
|
666
669
|
* Cancela edição do registro atual.
|
|
@@ -909,7 +912,7 @@ export default class DataUnit {
|
|
|
909
912
|
* @param fieldName - nome do campo para ficar invisível.
|
|
910
913
|
*
|
|
911
914
|
*/
|
|
912
|
-
hideField(fieldName: string, options
|
|
915
|
+
hideField(fieldName: string, options?: HideFieldOptions): void;
|
|
913
916
|
/**
|
|
914
917
|
*
|
|
915
918
|
* Deixa um campo do DataUnit visível
|
|
@@ -966,130 +969,7 @@ export default class DataUnit {
|
|
|
966
969
|
/**
|
|
967
970
|
* Retornar o campo de origem dos dados caso exista mapeamento
|
|
968
971
|
*/
|
|
969
|
-
getSourceFieldValue(
|
|
972
|
+
getSourceFieldValue(sourceFieldName: string): string | undefined;
|
|
970
973
|
private processLoadingLockers;
|
|
971
974
|
}
|
|
972
|
-
export
|
|
973
|
-
quickFilter?: QuickFilter;
|
|
974
|
-
executionCtx?: ExecutionContext;
|
|
975
|
-
checkLastFilter?: boolean;
|
|
976
|
-
source?: string;
|
|
977
|
-
selectFirstRecord?: boolean;
|
|
978
|
-
keepSelection?: boolean;
|
|
979
|
-
}
|
|
980
|
-
export interface DUActionInterceptor {
|
|
981
|
-
interceptAction(action: DataUnitAction): DataUnitAction | Promise<DataUnitAction>;
|
|
982
|
-
}
|
|
983
|
-
export interface Record {
|
|
984
|
-
__record__id__: string;
|
|
985
|
-
__record__label__?: string;
|
|
986
|
-
__parent__record__id__?: string;
|
|
987
|
-
__owner__dataunit__name__?: string;
|
|
988
|
-
[key: string]: any;
|
|
989
|
-
}
|
|
990
|
-
export interface SavedRecord extends Record {
|
|
991
|
-
__old__id__?: string;
|
|
992
|
-
}
|
|
993
|
-
export declare enum ChangeOperation {
|
|
994
|
-
INSERT = "INSERT",
|
|
995
|
-
COPY = "COPY",
|
|
996
|
-
UPDATE = "UPDATE",
|
|
997
|
-
DELETE = "DELETE"
|
|
998
|
-
}
|
|
999
|
-
/***
|
|
1000
|
-
* `Change`: Dados que representam uma alteração.
|
|
1001
|
-
*/
|
|
1002
|
-
export declare class Change {
|
|
1003
|
-
dataUnit: string;
|
|
1004
|
-
record: Record;
|
|
1005
|
-
sourceId: string | undefined;
|
|
1006
|
-
updatingFields: any;
|
|
1007
|
-
private _operation;
|
|
1008
|
-
constructor(dataUnit: string, record: Record, updates: any, operation: ChangeOperation, sourceId?: string);
|
|
1009
|
-
/**
|
|
1010
|
-
*
|
|
1011
|
-
* Obtém o tipo de operação que está sendo realizada.
|
|
1012
|
-
*
|
|
1013
|
-
* @returns - Ação que está sendo executada.
|
|
1014
|
-
*
|
|
1015
|
-
*/
|
|
1016
|
-
get operation(): string;
|
|
1017
|
-
/**
|
|
1018
|
-
*
|
|
1019
|
-
* Retorna se o DataUnit está em uma operação de inserção.
|
|
1020
|
-
*
|
|
1021
|
-
* @returns - Verdadeiro se a operação for de inserção.
|
|
1022
|
-
*
|
|
1023
|
-
*/
|
|
1024
|
-
isInsert(): boolean;
|
|
1025
|
-
/**
|
|
1026
|
-
*
|
|
1027
|
-
* Retorna se o DataUnit está em uma operação de cópia.
|
|
1028
|
-
*
|
|
1029
|
-
* @returns - Verdadeiro se a operação for de cópia.
|
|
1030
|
-
*
|
|
1031
|
-
*/
|
|
1032
|
-
isCopy(): boolean;
|
|
1033
|
-
/**
|
|
1034
|
-
*
|
|
1035
|
-
* Retorna se o DataUnit está em uma operação de deleção.
|
|
1036
|
-
*
|
|
1037
|
-
* @returns - Verdadeiro se a operação for de deleção.
|
|
1038
|
-
*
|
|
1039
|
-
*/
|
|
1040
|
-
isDelete(): boolean;
|
|
1041
|
-
/**
|
|
1042
|
-
*
|
|
1043
|
-
* Retorna se o DataUnit está em uma operação de atualização.
|
|
1044
|
-
*
|
|
1045
|
-
* @returns - Verdadeiro se a operação for de atualização.
|
|
1046
|
-
*
|
|
1047
|
-
*/
|
|
1048
|
-
isUpdate(): boolean;
|
|
1049
|
-
}
|
|
1050
|
-
export interface WaitingChange {
|
|
1051
|
-
waitmessage: string;
|
|
1052
|
-
blocking: boolean;
|
|
1053
|
-
promise?: Promise<any>;
|
|
1054
|
-
}
|
|
1055
|
-
export interface PageRequest {
|
|
1056
|
-
limit: number;
|
|
1057
|
-
offset: number;
|
|
1058
|
-
quickFilter?: QuickFilter;
|
|
1059
|
-
}
|
|
1060
|
-
export interface QuickFilter {
|
|
1061
|
-
term: string;
|
|
1062
|
-
fields?: Array<string>;
|
|
1063
|
-
filter?: Filter;
|
|
1064
|
-
}
|
|
1065
|
-
export interface PageResponse {
|
|
1066
|
-
limit: number;
|
|
1067
|
-
offset: number;
|
|
1068
|
-
total: number;
|
|
1069
|
-
hasMore: boolean;
|
|
1070
|
-
records: Array<Record>;
|
|
1071
|
-
}
|
|
1072
|
-
export declare enum SelectionMode {
|
|
1073
|
-
ALL_RECORDS = "ALL_RECORDS",
|
|
1074
|
-
SOME_RECORDS = "SOME_RECORDS"
|
|
1075
|
-
}
|
|
1076
|
-
export declare class SelectionInfo {
|
|
1077
|
-
mode: SelectionMode;
|
|
1078
|
-
filters?: Array<Filter>;
|
|
1079
|
-
sort?: Array<Sort>;
|
|
1080
|
-
getAllRecords?: () => Array<Record> | undefined;
|
|
1081
|
-
private _records;
|
|
1082
|
-
private _total?;
|
|
1083
|
-
constructor(records: Array<Record>, mode?: SelectionMode, total?: number, filters?: Array<Filter>, sort?: Array<Sort>);
|
|
1084
|
-
get records(): Array<Record> | undefined;
|
|
1085
|
-
get recordIds(): Array<string> | undefined;
|
|
1086
|
-
get length(): number;
|
|
1087
|
-
isAllRecords(): boolean;
|
|
1088
|
-
isEmpty(): boolean;
|
|
1089
|
-
}
|
|
1090
|
-
export type DataUnitEventOptions = {
|
|
1091
|
-
[key: string]: any;
|
|
1092
|
-
};
|
|
1093
|
-
export type HideFieldOptions = {
|
|
1094
|
-
visibleOnConfig: boolean;
|
|
1095
|
-
};
|
|
975
|
+
export { Record, Change, SelectionInfo, SelectionMode, LoadDataParams, DUActionInterceptor, SavedRecord, WaitingChange, QuickFilter, DataUnitEventOptions, HideFieldOptions };
|
|
@@ -32,6 +32,9 @@ import { getLoadingProperties, LoadingPropertiesReducer } from "./state/slice/Lo
|
|
|
32
32
|
import SortingUtils from "../utils/SortingUtils.js";
|
|
33
33
|
import ServiceCanceledException from "../exceptions/ServiceCanceledException.js";
|
|
34
34
|
import SilentException from "../exceptions/SilentException.js";
|
|
35
|
+
import { SelectionMode } from "./interfaces/dataUnit.js";
|
|
36
|
+
import { Change } from "./Changes.js";
|
|
37
|
+
import { SelectionInfo } from "./SelectionInfo.js";
|
|
35
38
|
/***
|
|
36
39
|
* `DataUnit`: Atua como uma camada de abstração entre o back-end e a interface do usuário.
|
|
37
40
|
*/
|
|
@@ -237,7 +240,7 @@ export default class DataUnit {
|
|
|
237
240
|
*/
|
|
238
241
|
executeLoadData(request, executionCtx, checkLastFilter, selectFirstRecord) {
|
|
239
242
|
if (checkLastFilter && this.isSameRequest(request)) {
|
|
240
|
-
const paginationInfo = getPaginationInfo(
|
|
243
|
+
const paginationInfo = this.getPaginationInfo();
|
|
241
244
|
if (paginationInfo) {
|
|
242
245
|
const response = {
|
|
243
246
|
records: getRecords(this._stateManager),
|
|
@@ -441,15 +444,18 @@ export default class DataUnit {
|
|
|
441
444
|
return __awaiter(this, void 0, void 0, function* () {
|
|
442
445
|
const blockingWaitingChanges = getBlockingWaitingChanges(this._stateManager);
|
|
443
446
|
if (blockingWaitingChanges && blockingWaitingChanges.size > 0) {
|
|
444
|
-
const
|
|
445
|
-
|
|
447
|
+
const entry = blockingWaitingChanges.entries().next().value;
|
|
448
|
+
if (entry) {
|
|
449
|
+
const [_, waitingChange] = entry;
|
|
450
|
+
return Promise.reject(new WaitingChangeException("Aguardando alteração de campo", waitingChange.waitmessage));
|
|
451
|
+
}
|
|
446
452
|
}
|
|
447
453
|
else {
|
|
448
454
|
if (this.isDirty()) {
|
|
449
455
|
if (yield this.notifySavingData(executionCtx)) {
|
|
450
456
|
const promisses = this.getBeforeSavePromisses();
|
|
451
457
|
return new Promise((resolve, fail) => {
|
|
452
|
-
Promise.all(promisses
|
|
458
|
+
Promise.all(promisses).then(() => {
|
|
453
459
|
this._savingLockers = [];
|
|
454
460
|
if (this.saveLoader) {
|
|
455
461
|
const changes = this.getAllChangesToSave();
|
|
@@ -505,8 +511,7 @@ export default class DataUnit {
|
|
|
505
511
|
return getChangesToSave(this._name, this._stateManager);
|
|
506
512
|
}
|
|
507
513
|
buildChangesToSaveFromChild(allChanges, dataUnit) {
|
|
508
|
-
|
|
509
|
-
(_a = dataUnit._childByName) === null || _a === void 0 ? void 0 : _a.forEach((dataUnitChild) => {
|
|
514
|
+
dataUnit._childByName.forEach((dataUnitChild) => {
|
|
510
515
|
if (dataUnitChild.isDirty()) {
|
|
511
516
|
allChanges.push(...getChangesToSave(dataUnitChild.name, dataUnitChild._stateManager));
|
|
512
517
|
this.buildChangesToSaveFromChild(allChanges, dataUnitChild);
|
|
@@ -541,15 +546,15 @@ export default class DataUnit {
|
|
|
541
546
|
removeSelectedRecords(buffered = false, silent = false) {
|
|
542
547
|
return __awaiter(this, void 0, void 0, function* () {
|
|
543
548
|
const selection = this.getSelectionInfo();
|
|
544
|
-
if (selection) {
|
|
545
|
-
|
|
546
|
-
throw new Error("Exclusão remota não implementada.");
|
|
547
|
-
}
|
|
548
|
-
const records = (selection === null || selection === void 0 ? void 0 : selection.records) || [];
|
|
549
|
-
const recordIds = (selection === null || selection === void 0 ? void 0 : selection.recordIds) || [];
|
|
550
|
-
return this.removeRecords(recordIds, records, buffered, undefined, silent);
|
|
549
|
+
if (selection.isAllRecords()) {
|
|
550
|
+
throw new Error("Exclusão remota não implementada.");
|
|
551
551
|
}
|
|
552
|
-
|
|
552
|
+
if (!selection.records || !selection.records.length) {
|
|
553
|
+
return Promise.resolve([]);
|
|
554
|
+
}
|
|
555
|
+
const records = selection.records;
|
|
556
|
+
const recordIds = selection.recordIds;
|
|
557
|
+
return this.removeRecords(recordIds, records, buffered, undefined, silent);
|
|
553
558
|
});
|
|
554
559
|
}
|
|
555
560
|
/**
|
|
@@ -869,14 +874,12 @@ export default class DataUnit {
|
|
|
869
874
|
*/
|
|
870
875
|
copySelected(executionCtx) {
|
|
871
876
|
const selectionInfo = this.getSelectionInfo();
|
|
872
|
-
if (selectionInfo) {
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
|
|
879
|
-
}
|
|
877
|
+
if (selectionInfo.isAllRecords()) {
|
|
878
|
+
throw new Error("Erro interno: Impossível copiar os registros selecionados pois a seleção atual é virtual.");
|
|
879
|
+
}
|
|
880
|
+
const selectedRecords = selectionInfo.records;
|
|
881
|
+
if (selectedRecords.length) {
|
|
882
|
+
this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
|
|
880
883
|
}
|
|
881
884
|
}
|
|
882
885
|
getRecordsByDataUnit(records) {
|
|
@@ -1157,7 +1160,6 @@ export default class DataUnit {
|
|
|
1157
1160
|
*
|
|
1158
1161
|
**/
|
|
1159
1162
|
getSelectionInfo() {
|
|
1160
|
-
var _a;
|
|
1161
1163
|
const selectionInfo = getSelectionInfo(this._stateManager);
|
|
1162
1164
|
selectionInfo.getAllRecords = () => {
|
|
1163
1165
|
var _a, _b;
|
|
@@ -1170,7 +1172,7 @@ export default class DataUnit {
|
|
|
1170
1172
|
};
|
|
1171
1173
|
if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
|
|
1172
1174
|
const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort);
|
|
1173
|
-
|
|
1175
|
+
selectionInfo.records.sort(sortingFunction);
|
|
1174
1176
|
}
|
|
1175
1177
|
return selectionInfo;
|
|
1176
1178
|
}
|
|
@@ -1210,24 +1212,26 @@ export default class DataUnit {
|
|
|
1210
1212
|
*
|
|
1211
1213
|
*/
|
|
1212
1214
|
nextRecord(executionCtx) {
|
|
1213
|
-
|
|
1214
|
-
if (
|
|
1215
|
-
this.
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1216
|
+
if (!hasNext(this._stateManager)) {
|
|
1217
|
+
if (hasMorePages(this._stateManager)) {
|
|
1218
|
+
yield this.nextPage({
|
|
1219
|
+
before: (act) => {
|
|
1220
|
+
if (executionCtx && executionCtx.before) {
|
|
1221
|
+
act = executionCtx.before(act);
|
|
1222
|
+
}
|
|
1223
|
+
return act;
|
|
1224
|
+
},
|
|
1225
|
+
after: () => {
|
|
1226
|
+
this.selectFirst(executionCtx);
|
|
1219
1227
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
after: act => {
|
|
1223
|
-
this.selectFirst(executionCtx);
|
|
1224
|
-
}
|
|
1225
|
-
});
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1226
1230
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
}
|
|
1231
|
+
else {
|
|
1232
|
+
this.dispatchAction(Action.NEXT_SELECTED, undefined, executionCtx);
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1231
1235
|
}
|
|
1232
1236
|
/**
|
|
1233
1237
|
*
|
|
@@ -1237,24 +1241,26 @@ export default class DataUnit {
|
|
|
1237
1241
|
*
|
|
1238
1242
|
*/
|
|
1239
1243
|
previousRecord(executionCtx) {
|
|
1240
|
-
|
|
1241
|
-
if (
|
|
1242
|
-
this.
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1245
|
+
if (!hasPrevious(this._stateManager)) {
|
|
1246
|
+
if (hasPreviousPages(this._stateManager)) {
|
|
1247
|
+
yield this.previousPage({
|
|
1248
|
+
before: (act) => {
|
|
1249
|
+
if (executionCtx && executionCtx.before) {
|
|
1250
|
+
act = executionCtx.before(act);
|
|
1251
|
+
}
|
|
1252
|
+
return act;
|
|
1253
|
+
},
|
|
1254
|
+
after: () => {
|
|
1255
|
+
this.selectLast(executionCtx);
|
|
1246
1256
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
after: act => {
|
|
1250
|
-
this.selectLast(executionCtx);
|
|
1251
|
-
}
|
|
1252
|
-
});
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1253
1259
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
}
|
|
1260
|
+
else {
|
|
1261
|
+
this.dispatchAction(Action.PREVIOUS_SELECTED, undefined, executionCtx);
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1258
1264
|
}
|
|
1259
1265
|
/**
|
|
1260
1266
|
*
|
|
@@ -1306,7 +1312,7 @@ export default class DataUnit {
|
|
|
1306
1312
|
*
|
|
1307
1313
|
*/
|
|
1308
1314
|
childrenIsDirty() {
|
|
1309
|
-
for (let [
|
|
1315
|
+
for (let [_, dataUnitChild] of this._childByName) {
|
|
1310
1316
|
if (dataUnitChild.isDirty())
|
|
1311
1317
|
return true;
|
|
1312
1318
|
}
|
|
@@ -1666,7 +1672,10 @@ export default class DataUnit {
|
|
|
1666
1672
|
*/
|
|
1667
1673
|
enableField(fieldName) {
|
|
1668
1674
|
const fieldDescriptor = this.getField(fieldName);
|
|
1669
|
-
if (
|
|
1675
|
+
if (!fieldDescriptor) {
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
if (fieldDescriptor.readOnly) {
|
|
1670
1679
|
fieldDescriptor.readOnly = false;
|
|
1671
1680
|
this.metadata = Object.assign({}, this.metadata);
|
|
1672
1681
|
}
|
|
@@ -1679,7 +1688,10 @@ export default class DataUnit {
|
|
|
1679
1688
|
*/
|
|
1680
1689
|
disableField(fieldName) {
|
|
1681
1690
|
const fieldDescriptor = this.getField(fieldName);
|
|
1682
|
-
if (
|
|
1691
|
+
if (!fieldDescriptor) {
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
if (!fieldDescriptor.readOnly) {
|
|
1683
1695
|
fieldDescriptor.readOnly = true;
|
|
1684
1696
|
this.metadata = Object.assign({}, this.metadata);
|
|
1685
1697
|
}
|
|
@@ -1692,9 +1704,14 @@ export default class DataUnit {
|
|
|
1692
1704
|
*/
|
|
1693
1705
|
hideField(fieldName, options) {
|
|
1694
1706
|
const fieldDescriptor = this.getField(fieldName);
|
|
1695
|
-
if (
|
|
1707
|
+
if (!fieldDescriptor) {
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
if (fieldDescriptor.visible) {
|
|
1696
1711
|
fieldDescriptor.visible = false;
|
|
1697
|
-
|
|
1712
|
+
if (options) {
|
|
1713
|
+
fieldDescriptor.properties = Object.assign(Object.assign({}, fieldDescriptor.properties), { visibleOnConfig: options.visibleOnConfig });
|
|
1714
|
+
}
|
|
1698
1715
|
this.metadata = Object.assign({}, this.metadata);
|
|
1699
1716
|
}
|
|
1700
1717
|
}
|
|
@@ -1706,7 +1723,10 @@ export default class DataUnit {
|
|
|
1706
1723
|
*/
|
|
1707
1724
|
showField(fieldName) {
|
|
1708
1725
|
const fieldDescriptor = this.getField(fieldName);
|
|
1709
|
-
if (
|
|
1726
|
+
if (!fieldDescriptor) {
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
if (!fieldDescriptor.visible) {
|
|
1710
1730
|
fieldDescriptor.visible = true;
|
|
1711
1731
|
this.metadata = Object.assign({}, this.metadata);
|
|
1712
1732
|
}
|
|
@@ -1776,11 +1796,11 @@ export default class DataUnit {
|
|
|
1776
1796
|
* @returns Retorna uma função responsável por liberar o lock adicionado.
|
|
1777
1797
|
*/
|
|
1778
1798
|
addLoadingLocker() {
|
|
1779
|
-
let loadingLockerResolver;
|
|
1799
|
+
let loadingLockerResolver = () => { };
|
|
1780
1800
|
this._loadingLockers.push(new Promise((resolve) => {
|
|
1781
1801
|
loadingLockerResolver = resolve;
|
|
1782
1802
|
}));
|
|
1783
|
-
return loadingLockerResolver
|
|
1803
|
+
return loadingLockerResolver;
|
|
1784
1804
|
}
|
|
1785
1805
|
set allowReleaseCallbacks(allow) {
|
|
1786
1806
|
this._allowReleaseCallbacks = allow;
|
|
@@ -1794,8 +1814,8 @@ export default class DataUnit {
|
|
|
1794
1814
|
/**
|
|
1795
1815
|
* Retornar o campo de origem dos dados caso exista mapeamento
|
|
1796
1816
|
*/
|
|
1797
|
-
getSourceFieldValue(
|
|
1798
|
-
return this._fieldSourceValue.get(
|
|
1817
|
+
getSourceFieldValue(sourceFieldName) {
|
|
1818
|
+
return this._fieldSourceValue.get(sourceFieldName);
|
|
1799
1819
|
}
|
|
1800
1820
|
processLoadingLockers() {
|
|
1801
1821
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1809,115 +1829,5 @@ export default class DataUnit {
|
|
|
1809
1829
|
DataUnit.CHANGING_PAGE_LOADING_SOURCE = "CHANGING_PAGE_LOADING_SOURCE";
|
|
1810
1830
|
DataUnit.ALL_RECORDS_SELECTION_SOURCE = "ALL_RECORDS_SELECTION_SOURCE";
|
|
1811
1831
|
DataUnit.DEFAULT_DATAUNIT_NAME = "dataunit";
|
|
1812
|
-
export
|
|
1813
|
-
(function (ChangeOperation) {
|
|
1814
|
-
ChangeOperation["INSERT"] = "INSERT";
|
|
1815
|
-
ChangeOperation["COPY"] = "COPY";
|
|
1816
|
-
ChangeOperation["UPDATE"] = "UPDATE";
|
|
1817
|
-
ChangeOperation["DELETE"] = "DELETE";
|
|
1818
|
-
})(ChangeOperation || (ChangeOperation = {}));
|
|
1819
|
-
/***
|
|
1820
|
-
* `Change`: Dados que representam uma alteração.
|
|
1821
|
-
*/
|
|
1822
|
-
export class Change {
|
|
1823
|
-
constructor(dataUnit, record, updates, operation, sourceId) {
|
|
1824
|
-
this.dataUnit = dataUnit;
|
|
1825
|
-
this.record = record;
|
|
1826
|
-
this.sourceId = sourceId;
|
|
1827
|
-
this.updatingFields = updates;
|
|
1828
|
-
this._operation = operation;
|
|
1829
|
-
}
|
|
1830
|
-
/**
|
|
1831
|
-
*
|
|
1832
|
-
* Obtém o tipo de operação que está sendo realizada.
|
|
1833
|
-
*
|
|
1834
|
-
* @returns - Ação que está sendo executada.
|
|
1835
|
-
*
|
|
1836
|
-
*/
|
|
1837
|
-
get operation() {
|
|
1838
|
-
return this._operation.toString();
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
*
|
|
1842
|
-
* Retorna se o DataUnit está em uma operação de inserção.
|
|
1843
|
-
*
|
|
1844
|
-
* @returns - Verdadeiro se a operação for de inserção.
|
|
1845
|
-
*
|
|
1846
|
-
*/
|
|
1847
|
-
isInsert() {
|
|
1848
|
-
return this._operation === ChangeOperation.INSERT;
|
|
1849
|
-
}
|
|
1850
|
-
/**
|
|
1851
|
-
*
|
|
1852
|
-
* Retorna se o DataUnit está em uma operação de cópia.
|
|
1853
|
-
*
|
|
1854
|
-
* @returns - Verdadeiro se a operação for de cópia.
|
|
1855
|
-
*
|
|
1856
|
-
*/
|
|
1857
|
-
isCopy() {
|
|
1858
|
-
return this._operation === ChangeOperation.COPY;
|
|
1859
|
-
}
|
|
1860
|
-
/**
|
|
1861
|
-
*
|
|
1862
|
-
* Retorna se o DataUnit está em uma operação de deleção.
|
|
1863
|
-
*
|
|
1864
|
-
* @returns - Verdadeiro se a operação for de deleção.
|
|
1865
|
-
*
|
|
1866
|
-
*/
|
|
1867
|
-
isDelete() {
|
|
1868
|
-
return this._operation === ChangeOperation.DELETE;
|
|
1869
|
-
}
|
|
1870
|
-
/**
|
|
1871
|
-
*
|
|
1872
|
-
* Retorna se o DataUnit está em uma operação de atualização.
|
|
1873
|
-
*
|
|
1874
|
-
* @returns - Verdadeiro se a operação for de atualização.
|
|
1875
|
-
*
|
|
1876
|
-
*/
|
|
1877
|
-
isUpdate() {
|
|
1878
|
-
return this._operation === ChangeOperation.UPDATE;
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
export var SelectionMode;
|
|
1882
|
-
(function (SelectionMode) {
|
|
1883
|
-
SelectionMode["ALL_RECORDS"] = "ALL_RECORDS";
|
|
1884
|
-
SelectionMode["SOME_RECORDS"] = "SOME_RECORDS";
|
|
1885
|
-
})(SelectionMode || (SelectionMode = {}));
|
|
1886
|
-
export class SelectionInfo {
|
|
1887
|
-
constructor(records, mode = SelectionMode.SOME_RECORDS, total, filters, sort) {
|
|
1888
|
-
this._records = records;
|
|
1889
|
-
this._total = total;
|
|
1890
|
-
this.mode = mode;
|
|
1891
|
-
this.filters = filters;
|
|
1892
|
-
this.sort = sort;
|
|
1893
|
-
}
|
|
1894
|
-
get records() {
|
|
1895
|
-
if (this.isAllRecords()) {
|
|
1896
|
-
if (this.getAllRecords != undefined) {
|
|
1897
|
-
return this.getAllRecords();
|
|
1898
|
-
}
|
|
1899
|
-
throw new Error("Erro interno: Impossível retornar os registros selecionados numa seleção virtual.");
|
|
1900
|
-
}
|
|
1901
|
-
return this._records;
|
|
1902
|
-
}
|
|
1903
|
-
get recordIds() {
|
|
1904
|
-
const records = this.records;
|
|
1905
|
-
if (records == undefined) {
|
|
1906
|
-
return undefined;
|
|
1907
|
-
}
|
|
1908
|
-
return records.map(record => record.__record__id__);
|
|
1909
|
-
}
|
|
1910
|
-
get length() {
|
|
1911
|
-
if (this.isAllRecords()) {
|
|
1912
|
-
return this._total || 0;
|
|
1913
|
-
}
|
|
1914
|
-
return this.records == undefined ? 0 : this.records.length;
|
|
1915
|
-
}
|
|
1916
|
-
isAllRecords() {
|
|
1917
|
-
return this.mode === SelectionMode.ALL_RECORDS;
|
|
1918
|
-
}
|
|
1919
|
-
isEmpty() {
|
|
1920
|
-
return this.length === 0;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1832
|
+
export { Change, SelectionInfo, SelectionMode };
|
|
1923
1833
|
//# sourceMappingURL=DataUnit.js.map
|