@sankhyalabs/core 6.1.0 → 6.2.0-dev.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 +178 -157
- 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 +16 -129
- package/dist/dataunit/DataUnit.js +97 -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 +3 -2
- package/reports/test-report.xml +741 -524
- package/src/dataunit/Changes.ts +77 -0
- package/src/dataunit/DataUnit.ts +253 -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
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,24 +852,35 @@ 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
|
|
|
861
870
|
return children.find(child => child.name === name);
|
|
862
871
|
}
|
|
863
872
|
|
|
873
|
+
/**
|
|
874
|
+
*
|
|
875
|
+
* Define a propriedade records da instância da classe com um novo valor e chama o método dispatchAction para notificar os observers da aplicação sobre a mudança,
|
|
876
|
+
* mantendo a seleção definida anteriormente.
|
|
877
|
+
*
|
|
878
|
+
*/
|
|
879
|
+
public setRecordsKeepingSelection(records: Array<Record>): void {
|
|
880
|
+
const paginationInfo = this.getPaginationInfo();
|
|
881
|
+
this.dispatchAction(Action.DATA_LOADED, { records, paginationInfo, keepSelection: true }, undefined);
|
|
882
|
+
}
|
|
883
|
+
|
|
864
884
|
/**
|
|
865
885
|
*
|
|
866
886
|
* Define a propriedade records da instância da classe com um novo valor e chama o método dispatchAction para notificar os observers da aplicação sobre a mudança.
|
|
@@ -960,41 +980,41 @@ export default class DataUnit {
|
|
|
960
980
|
*/
|
|
961
981
|
public copySelected(executionCtx?: ExecutionContext): void {
|
|
962
982
|
const selectionInfo = this.getSelectionInfo();
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
983
|
+
|
|
984
|
+
if (selectionInfo.isAllRecords()) {
|
|
985
|
+
throw new Error("Erro interno: Impossível copiar os registros selecionados pois a seleção atual é virtual.");
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
const selectedRecords = selectionInfo.records;
|
|
989
|
+
|
|
990
|
+
if (selectedRecords.length) {
|
|
991
|
+
this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
|
|
972
992
|
}
|
|
973
993
|
}
|
|
974
|
-
|
|
994
|
+
|
|
975
995
|
private getRecordsByDataUnit(records: Array<Record>): Map<string, Array<Record>> {
|
|
976
996
|
const recordsMap = new Map<string, Array<Record>>();
|
|
977
|
-
|
|
997
|
+
|
|
978
998
|
records.forEach(record => {
|
|
979
999
|
let { __owner__dataunit__name__: ownerDataUnitName } = record;
|
|
980
|
-
|
|
981
|
-
if(!ownerDataUnitName){
|
|
1000
|
+
|
|
1001
|
+
if (!ownerDataUnitName) {
|
|
982
1002
|
ownerDataUnitName = this.name;
|
|
983
1003
|
}
|
|
984
1004
|
let changes = recordsMap.get(ownerDataUnitName);
|
|
985
|
-
|
|
986
|
-
if(!changes){
|
|
1005
|
+
|
|
1006
|
+
if (!changes) {
|
|
987
1007
|
changes = [];
|
|
988
1008
|
recordsMap.set(ownerDataUnitName, changes);
|
|
989
1009
|
}
|
|
990
1010
|
|
|
991
1011
|
changes.push(record);
|
|
992
1012
|
});
|
|
993
|
-
|
|
1013
|
+
|
|
994
1014
|
return recordsMap;
|
|
995
1015
|
}
|
|
996
1016
|
|
|
997
|
-
private getParentRecordId(){
|
|
1017
|
+
private getParentRecordId() {
|
|
998
1018
|
const parentRecord = this._parentDataUnit?.getSelectedRecord();
|
|
999
1019
|
return parentRecord?.__record__id__;
|
|
1000
1020
|
}
|
|
@@ -1036,27 +1056,27 @@ export default class DataUnit {
|
|
|
1036
1056
|
* @returns - Promise que será resolvida quando o novo valor for persistido no state.
|
|
1037
1057
|
*
|
|
1038
1058
|
*/
|
|
1039
|
-
public async setFieldValue(fieldName: string, newValue: any, records?: Array<string>, options?:DataUnitEventOptions): Promise<boolean> {
|
|
1059
|
+
public async setFieldValue(fieldName: string, newValue: any, records?: Array<string>, options?: DataUnitEventOptions): Promise<boolean> {
|
|
1040
1060
|
const noRecordSelected = !this.hasNewRecord() && !this.getSelectedRecord();
|
|
1041
1061
|
|
|
1042
1062
|
const suppressCreateNewRecord = options?.suppressCreateNewRecord;
|
|
1043
1063
|
|
|
1044
|
-
if(noRecordSelected && suppressCreateNewRecord) return Promise.resolve(false);
|
|
1064
|
+
if (noRecordSelected && suppressCreateNewRecord) return Promise.resolve(false);
|
|
1045
1065
|
|
|
1046
|
-
if(noRecordSelected) await this.addRecord();
|
|
1066
|
+
if (noRecordSelected) await this.addRecord();
|
|
1047
1067
|
|
|
1048
1068
|
const typedValue = this.validateAndTypeValue(fieldName, newValue);
|
|
1049
1069
|
const currentValue = this.getFieldValue(fieldName);
|
|
1050
1070
|
|
|
1051
|
-
if(this.areEquivalentValues(newValue, currentValue, typedValue)) {
|
|
1071
|
+
if (this.areEquivalentValues(newValue, currentValue, typedValue)) {
|
|
1052
1072
|
return Promise.resolve(false);
|
|
1053
1073
|
}
|
|
1054
1074
|
|
|
1055
|
-
if(newValue instanceof Promise){
|
|
1056
|
-
const promise:Promise<boolean> = new Promise(accept => {
|
|
1075
|
+
if (newValue instanceof Promise) {
|
|
1076
|
+
const promise: Promise<boolean> = new Promise(accept => {
|
|
1057
1077
|
newValue.then(resolvedValue => {
|
|
1058
1078
|
this.dispatchAction(Action.DATA_RESOLVED, { [fieldName]: resolvedValue, records }, undefined);
|
|
1059
|
-
accept(this.setFieldValue(fieldName, resolvedValue, records,
|
|
1079
|
+
accept(this.setFieldValue(fieldName, resolvedValue, records, options));
|
|
1060
1080
|
});
|
|
1061
1081
|
});
|
|
1062
1082
|
this._savingLockers.push(promise);
|
|
@@ -1074,8 +1094,8 @@ export default class DataUnit {
|
|
|
1074
1094
|
|
|
1075
1095
|
private areEquivalentValues(newValue: any, currentValue: any, typedValue: any) {
|
|
1076
1096
|
return !(newValue instanceof Promise)
|
|
1077
|
-
|
|
1078
|
-
|
|
1097
|
+
&& ObjectUtils.hasEquivalentProps(currentValue, typedValue)
|
|
1098
|
+
&& !this.isMultipleEdition;
|
|
1079
1099
|
}
|
|
1080
1100
|
|
|
1081
1101
|
/**
|
|
@@ -1099,7 +1119,7 @@ export default class DataUnit {
|
|
|
1099
1119
|
* @param recordId - Indica qual registro está com os campos inválido.
|
|
1100
1120
|
*
|
|
1101
1121
|
*/
|
|
1102
|
-
public savingCanceled(fields: Array<{name: string, message: string}>, recordId: string): void {
|
|
1122
|
+
public savingCanceled(fields: Array<{ name: string, message: string }>, recordId: string): void {
|
|
1103
1123
|
this.dispatchAction(Action.SAVING_CANCELED, { fields, recordId }, undefined);
|
|
1104
1124
|
}
|
|
1105
1125
|
|
|
@@ -1123,7 +1143,7 @@ export default class DataUnit {
|
|
|
1123
1143
|
* @param fieldName - Nome do campo.
|
|
1124
1144
|
*
|
|
1125
1145
|
*/
|
|
1126
|
-
public getInvalidMessage(recordId: string, fieldName: string): string|undefined {
|
|
1146
|
+
public getInvalidMessage(recordId: string, fieldName: string): string | undefined {
|
|
1127
1147
|
return getInvalidFieldMessage(this._stateManager, fieldName, recordId);
|
|
1128
1148
|
}
|
|
1129
1149
|
|
|
@@ -1157,7 +1177,6 @@ export default class DataUnit {
|
|
|
1157
1177
|
public hasWaitingChanges(): boolean {
|
|
1158
1178
|
const waitingChanges = getWaitingChanges(this._stateManager);
|
|
1159
1179
|
return waitingChanges ? !!waitingChanges.size : false;
|
|
1160
|
-
|
|
1161
1180
|
}
|
|
1162
1181
|
|
|
1163
1182
|
/**
|
|
@@ -1210,7 +1229,7 @@ export default class DataUnit {
|
|
|
1210
1229
|
public setSelection(selection: Array<string> | SelectionMode.ALL_RECORDS, executionCtx?: ExecutionContext): Promise<SelectionInfo> {
|
|
1211
1230
|
return new Promise(resolve => {
|
|
1212
1231
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }, executionCtx)
|
|
1213
|
-
.then(()=>resolve(this.getSelectionInfo()));
|
|
1232
|
+
.then(() => resolve(this.getSelectionInfo()));
|
|
1214
1233
|
});
|
|
1215
1234
|
}
|
|
1216
1235
|
|
|
@@ -1221,7 +1240,7 @@ export default class DataUnit {
|
|
|
1221
1240
|
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
1222
1241
|
*
|
|
1223
1242
|
*/
|
|
1224
|
-
public clearSelection(executionCtx?: ExecutionContext){
|
|
1243
|
+
public clearSelection(executionCtx?: ExecutionContext) {
|
|
1225
1244
|
this.setSelection([], executionCtx);
|
|
1226
1245
|
}
|
|
1227
1246
|
|
|
@@ -1233,19 +1252,19 @@ export default class DataUnit {
|
|
|
1233
1252
|
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
1234
1253
|
* @returns - Informações sobre a seleção.
|
|
1235
1254
|
*/
|
|
1236
|
-
public updatePageSelection(selection
|
|
1237
|
-
if(!selection) return Promise.resolve(this.getSelectionInfo());
|
|
1255
|
+
public updatePageSelection(selection?: Array<string>, executionCtx?: ExecutionContext): Promise<SelectionInfo | undefined> {
|
|
1256
|
+
if (!selection) return Promise.resolve(this.getSelectionInfo());
|
|
1238
1257
|
|
|
1239
1258
|
return new Promise(resolve => {
|
|
1240
1259
|
const newSelection: Set<string> = new Set(selection);
|
|
1241
1260
|
|
|
1242
1261
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) }, executionCtx)
|
|
1243
|
-
.then(()=> resolve(this.getSelectionInfo()));
|
|
1262
|
+
.then(() => resolve(this.getSelectionInfo()));
|
|
1244
1263
|
});
|
|
1245
1264
|
}
|
|
1246
1265
|
|
|
1247
1266
|
|
|
1248
|
-
private updatePageSelectionAll(addRecords: boolean): Promise<SelectionInfo|undefined>{
|
|
1267
|
+
private updatePageSelectionAll(addRecords: boolean): Promise<SelectionInfo | undefined> {
|
|
1249
1268
|
return new Promise(resolve => {
|
|
1250
1269
|
const newSelection: Set<string> = new Set<string>();
|
|
1251
1270
|
|
|
@@ -1253,10 +1272,10 @@ export default class DataUnit {
|
|
|
1253
1272
|
cachedSelection.forEach(item => newSelection.add(item));
|
|
1254
1273
|
|
|
1255
1274
|
const recordsIds = this.records.map(r => r.__record__id__);
|
|
1256
|
-
recordsIds.forEach(id => addRecords ? newSelection.add(id): newSelection.delete(id));
|
|
1275
|
+
recordsIds.forEach(id => addRecords ? newSelection.add(id) : newSelection.delete(id));
|
|
1257
1276
|
|
|
1258
1277
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) })
|
|
1259
|
-
|
|
1278
|
+
.then(() => resolve(this.getSelectionInfo()));
|
|
1260
1279
|
});
|
|
1261
1280
|
}
|
|
1262
1281
|
|
|
@@ -1265,8 +1284,8 @@ export default class DataUnit {
|
|
|
1265
1284
|
*
|
|
1266
1285
|
* @returns - Informações sobre a seleção.
|
|
1267
1286
|
*/
|
|
1268
|
-
|
|
1269
|
-
|
|
1287
|
+
public selectAllRecords(): Promise<SelectionInfo | undefined> {
|
|
1288
|
+
return this.updatePageSelectionAll(true);
|
|
1270
1289
|
}
|
|
1271
1290
|
|
|
1272
1291
|
/**
|
|
@@ -1274,9 +1293,9 @@ export default class DataUnit {
|
|
|
1274
1293
|
*
|
|
1275
1294
|
* @returns - Informações sobre a seleção.
|
|
1276
1295
|
*/
|
|
1277
|
-
|
|
1296
|
+
public unSelectAllRecords(): Promise<SelectionInfo | undefined> {
|
|
1278
1297
|
return this.updatePageSelectionAll(false);
|
|
1279
|
-
|
|
1298
|
+
}
|
|
1280
1299
|
|
|
1281
1300
|
/**
|
|
1282
1301
|
*
|
|
@@ -1284,13 +1303,13 @@ export default class DataUnit {
|
|
|
1284
1303
|
*
|
|
1285
1304
|
* @returns - Objeto com informações como registros selecionados e seleção por critério.
|
|
1286
1305
|
*
|
|
1287
|
-
**/
|
|
1288
|
-
public getSelectionInfo(): SelectionInfo{
|
|
1306
|
+
**/
|
|
1307
|
+
public getSelectionInfo(): SelectionInfo {
|
|
1289
1308
|
const selectionInfo: SelectionInfo = getSelectionInfo(this._stateManager);
|
|
1290
1309
|
selectionInfo.getAllRecords = () => {
|
|
1291
|
-
|
|
1310
|
+
|
|
1292
1311
|
let records = this.allRecordsLoader?.(this) ?? [];
|
|
1293
|
-
|
|
1312
|
+
|
|
1294
1313
|
if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
|
|
1295
1314
|
const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort)
|
|
1296
1315
|
records = [...records].sort(sortingFunction);
|
|
@@ -1301,7 +1320,7 @@ export default class DataUnit {
|
|
|
1301
1320
|
|
|
1302
1321
|
if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
|
|
1303
1322
|
const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort)
|
|
1304
|
-
selectionInfo.records
|
|
1323
|
+
selectionInfo.records.sort(sortingFunction)
|
|
1305
1324
|
}
|
|
1306
1325
|
|
|
1307
1326
|
return selectionInfo;
|
|
@@ -1315,7 +1334,7 @@ export default class DataUnit {
|
|
|
1315
1334
|
*
|
|
1316
1335
|
*/
|
|
1317
1336
|
public getSelectedRecord(): Record | undefined {
|
|
1318
|
-
|
|
1337
|
+
return getSelectedRecord(this._stateManager);
|
|
1319
1338
|
}
|
|
1320
1339
|
|
|
1321
1340
|
/**
|
|
@@ -1345,17 +1364,17 @@ export default class DataUnit {
|
|
|
1345
1364
|
*
|
|
1346
1365
|
*
|
|
1347
1366
|
*/
|
|
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){
|
|
1367
|
+
public async nextRecord(executionCtx?: ExecutionContext): Promise<void> {
|
|
1368
|
+
if (!hasNext(this._stateManager)) {
|
|
1369
|
+
if (hasMorePages(this._stateManager)) {
|
|
1370
|
+
await this.nextPage({
|
|
1371
|
+
before: (act) => {
|
|
1372
|
+
if (executionCtx && executionCtx.before) {
|
|
1354
1373
|
act = executionCtx.before(act);
|
|
1355
1374
|
}
|
|
1356
1375
|
return act;
|
|
1357
1376
|
},
|
|
1358
|
-
after:
|
|
1377
|
+
after: () => {
|
|
1359
1378
|
this.selectFirst(executionCtx);
|
|
1360
1379
|
}
|
|
1361
1380
|
});
|
|
@@ -1372,17 +1391,17 @@ export default class DataUnit {
|
|
|
1372
1391
|
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
1373
1392
|
*
|
|
1374
1393
|
*/
|
|
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){
|
|
1394
|
+
public async previousRecord(executionCtx?: ExecutionContext): Promise<void> {
|
|
1395
|
+
if (!hasPrevious(this._stateManager)) {
|
|
1396
|
+
if (hasPreviousPages(this._stateManager)) {
|
|
1397
|
+
await this.previousPage({
|
|
1398
|
+
before: (act) => {
|
|
1399
|
+
if (executionCtx && executionCtx.before) {
|
|
1381
1400
|
act = executionCtx.before(act);
|
|
1382
1401
|
}
|
|
1383
1402
|
return act;
|
|
1384
1403
|
},
|
|
1385
|
-
after:
|
|
1404
|
+
after: () => {
|
|
1386
1405
|
this.selectLast(executionCtx);
|
|
1387
1406
|
}
|
|
1388
1407
|
});
|
|
@@ -1401,14 +1420,14 @@ export default class DataUnit {
|
|
|
1401
1420
|
*
|
|
1402
1421
|
*/
|
|
1403
1422
|
public async cancelEdition(executionCtx?: ExecutionContext, fromParent?: boolean, silent: boolean = false): Promise<boolean> {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
}
|
|
1423
|
+
const cancelledAction = await this.dispatchAction(Action.EDITION_CANCELED, { fromParent, silent }, executionCtx);
|
|
1424
|
+
for (const [, dataUnit] of this._childByName) {
|
|
1425
|
+
if (dataUnit.isDirty()) {
|
|
1426
|
+
dataUnit.cancelEdition(undefined, true, silent);
|
|
1409
1427
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1428
|
+
}
|
|
1429
|
+
return Promise.resolve(cancelledAction);
|
|
1430
|
+
|
|
1412
1431
|
}
|
|
1413
1432
|
|
|
1414
1433
|
/**
|
|
@@ -1418,9 +1437,9 @@ export default class DataUnit {
|
|
|
1418
1437
|
* @param ignoreChildren: Define se deverá ignorar alterações pendentes no DataUnit filho.
|
|
1419
1438
|
* @returns Verdadeiro se existir alterações pendentes.
|
|
1420
1439
|
*
|
|
1421
|
-
*/
|
|
1440
|
+
*/
|
|
1422
1441
|
public isDirty(ignoreChildren?: boolean): boolean {
|
|
1423
|
-
if(ignoreChildren) return isDirty(this._stateManager);
|
|
1442
|
+
if (ignoreChildren) return isDirty(this._stateManager);
|
|
1424
1443
|
|
|
1425
1444
|
return isDirty(this._stateManager) || this.childrenIsDirty();
|
|
1426
1445
|
}
|
|
@@ -1442,10 +1461,10 @@ export default class DataUnit {
|
|
|
1442
1461
|
*
|
|
1443
1462
|
* @returns Verdadeiro se existir alterações pendentes em algum DataUnit detail.
|
|
1444
1463
|
*
|
|
1445
|
-
*/
|
|
1446
|
-
private childrenIsDirty():boolean {
|
|
1447
|
-
for (let [
|
|
1448
|
-
if(dataUnitChild.isDirty()) return true;
|
|
1464
|
+
*/
|
|
1465
|
+
private childrenIsDirty(): boolean {
|
|
1466
|
+
for (let [_, dataUnitChild] of this._childByName) {
|
|
1467
|
+
if (dataUnitChild.isDirty()) return true;
|
|
1449
1468
|
}
|
|
1450
1469
|
return false;
|
|
1451
1470
|
}
|
|
@@ -1470,7 +1489,7 @@ export default class DataUnit {
|
|
|
1470
1489
|
*/
|
|
1471
1490
|
public hasNext(): boolean {
|
|
1472
1491
|
let result = hasNext(this._stateManager);
|
|
1473
|
-
if(!result){
|
|
1492
|
+
if (!result) {
|
|
1474
1493
|
result = hasMorePages(this._stateManager);
|
|
1475
1494
|
}
|
|
1476
1495
|
return result;
|
|
@@ -1485,7 +1504,7 @@ export default class DataUnit {
|
|
|
1485
1504
|
*/
|
|
1486
1505
|
public hasPrevious(): boolean {
|
|
1487
1506
|
let result = hasPrevious(this._stateManager);
|
|
1488
|
-
if(!result){
|
|
1507
|
+
if (!result) {
|
|
1489
1508
|
result = hasPreviousPages(this._stateManager);
|
|
1490
1509
|
}
|
|
1491
1510
|
return result;
|
|
@@ -1501,7 +1520,7 @@ export default class DataUnit {
|
|
|
1501
1520
|
*/
|
|
1502
1521
|
public isNewRecord(recordId: string): boolean {
|
|
1503
1522
|
const newRecords = getAddedRecords(this._stateManager);
|
|
1504
|
-
if(newRecords && newRecords.length > 0){
|
|
1523
|
+
if (newRecords && newRecords.length > 0) {
|
|
1505
1524
|
const record = newRecords.find(newRecord => newRecord.__record__id__ === recordId);
|
|
1506
1525
|
return record != undefined;
|
|
1507
1526
|
}
|
|
@@ -1529,10 +1548,11 @@ export default class DataUnit {
|
|
|
1529
1548
|
*/
|
|
1530
1549
|
public hasCopiedRecord(): boolean {
|
|
1531
1550
|
const newRecords = getAddedRecords(this._stateManager);
|
|
1532
|
-
|
|
1551
|
+
|
|
1552
|
+
if (newRecords == undefined) {
|
|
1533
1553
|
return false;
|
|
1534
1554
|
}
|
|
1535
|
-
for(let record of newRecords){
|
|
1555
|
+
for (let record of newRecords) {
|
|
1536
1556
|
if (record['__record__source__id__'] != undefined) {
|
|
1537
1557
|
return true
|
|
1538
1558
|
}
|
|
@@ -1608,7 +1628,7 @@ export default class DataUnit {
|
|
|
1608
1628
|
* @returns - Verdadeiro se ação iniciada.
|
|
1609
1629
|
*
|
|
1610
1630
|
*/
|
|
1611
|
-
private async dispatchAction(actionType: Action, payload?: any, executionCtx?: ExecutionContext, options?:DataUnitEventOptions): Promise<boolean> {
|
|
1631
|
+
private async dispatchAction(actionType: Action, payload?: any, executionCtx?: ExecutionContext, options?: DataUnitEventOptions): Promise<boolean> {
|
|
1612
1632
|
return new Promise(async resolve => {
|
|
1613
1633
|
let action = new DataUnitAction(actionType, payload);
|
|
1614
1634
|
if (executionCtx && executionCtx.before) {
|
|
@@ -1656,7 +1676,7 @@ export default class DataUnit {
|
|
|
1656
1676
|
* @param action - Ações em execução no DataUnit.
|
|
1657
1677
|
*
|
|
1658
1678
|
*/
|
|
1659
|
-
private doDispatchAction(action: DataUnitAction, options:DataUnitEventOptions = {}): void {
|
|
1679
|
+
private doDispatchAction(action: DataUnitAction, options: DataUnitEventOptions = {}): void {
|
|
1660
1680
|
this._stateManager.process(action);
|
|
1661
1681
|
this?._parentDataUnit?.dispatchAction(Action.CHILD_CHANGED, { srcAction: action, srcDataUnit: this });
|
|
1662
1682
|
this._observers.forEach(f => {
|
|
@@ -1676,7 +1696,7 @@ export default class DataUnit {
|
|
|
1676
1696
|
* @param name - Nome do dataunit filho.
|
|
1677
1697
|
*
|
|
1678
1698
|
*/
|
|
1679
|
-
public getChildDataunit(name:string){
|
|
1699
|
+
public getChildDataunit(name: string) {
|
|
1680
1700
|
const detail: DataUnit = new DataUnit(name, this);
|
|
1681
1701
|
this._childByName.set(name, detail);
|
|
1682
1702
|
return detail;
|
|
@@ -1689,10 +1709,10 @@ export default class DataUnit {
|
|
|
1689
1709
|
* @param name - Nome do dataunit filho.
|
|
1690
1710
|
*
|
|
1691
1711
|
*/
|
|
1692
|
-
public removeChildDataunit(name:string){
|
|
1712
|
+
public removeChildDataunit(name: string) {
|
|
1693
1713
|
this._childByName.delete(name);
|
|
1694
1714
|
}
|
|
1695
|
-
|
|
1715
|
+
|
|
1696
1716
|
/**
|
|
1697
1717
|
*
|
|
1698
1718
|
* Adiciona um novo observer no DataUnit.
|
|
@@ -1738,17 +1758,17 @@ export default class DataUnit {
|
|
|
1738
1758
|
* @returns - Dados atualizados do registro selecionado.
|
|
1739
1759
|
*
|
|
1740
1760
|
*/
|
|
1741
|
-
public reloadCurrentRecord(): Promise<Array<Record>>{
|
|
1761
|
+
public reloadCurrentRecord(): Promise<Array<Record>> {
|
|
1742
1762
|
return new Promise(async (resolve, fail) => {
|
|
1743
1763
|
const selection = getSelection(this._stateManager);
|
|
1744
1764
|
await this.dispatchAction(Action.LOADING_RECORD, selection);
|
|
1745
|
-
|
|
1746
|
-
if(!this.recordLoader || !this.dataLoader) {
|
|
1765
|
+
|
|
1766
|
+
if (!this.recordLoader || !this.dataLoader) {
|
|
1747
1767
|
await this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
1748
1768
|
resolve([]);
|
|
1749
1769
|
return;
|
|
1750
1770
|
}
|
|
1751
|
-
|
|
1771
|
+
|
|
1752
1772
|
this.recordLoader(this, selection).then(async response => {
|
|
1753
1773
|
await this.dispatchAction(Action.RECORD_LOADED, response)
|
|
1754
1774
|
await this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
@@ -1756,7 +1776,7 @@ export default class DataUnit {
|
|
|
1756
1776
|
resolve(response);
|
|
1757
1777
|
}).catch(async cause => {
|
|
1758
1778
|
await this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
|
|
1759
|
-
const {errorCode} = cause;
|
|
1779
|
+
const { errorCode } = cause;
|
|
1760
1780
|
fail(new ErrorException("Erro ao recarregar registro", cause, errorCode));
|
|
1761
1781
|
});
|
|
1762
1782
|
});
|
|
@@ -1780,7 +1800,7 @@ export default class DataUnit {
|
|
|
1780
1800
|
* @returns - Lista de filtros.
|
|
1781
1801
|
*
|
|
1782
1802
|
*/
|
|
1783
|
-
public getFilters(): Array<Filter> | undefined {
|
|
1803
|
+
public getFilters(): Array<Filter> | undefined {
|
|
1784
1804
|
let filters: Array<Filter> | undefined = undefined;
|
|
1785
1805
|
this._filterProviders.forEach(p => {
|
|
1786
1806
|
const f = p.getFilter(this.name);
|
|
@@ -1797,18 +1817,18 @@ export default class DataUnit {
|
|
|
1797
1817
|
*
|
|
1798
1818
|
* @returns - As informações de filtro e paginação.
|
|
1799
1819
|
*
|
|
1800
|
-
*/
|
|
1820
|
+
*/
|
|
1801
1821
|
public getLastLoadRequest(): LoadDataRequest | undefined {
|
|
1802
1822
|
return getCurrentRequest(this._stateManager);
|
|
1803
1823
|
}
|
|
1804
|
-
|
|
1824
|
+
|
|
1805
1825
|
/**
|
|
1806
1826
|
*
|
|
1807
1827
|
* Obtém os filtros aplicados.
|
|
1808
1828
|
*
|
|
1809
1829
|
* @returns - Lista de filtros.
|
|
1810
1830
|
*
|
|
1811
|
-
*/
|
|
1831
|
+
*/
|
|
1812
1832
|
public getAppliedFilters(): Array<Filter> | undefined {
|
|
1813
1833
|
const { filters }: LoadDataRequest = getCurrentRequest(this._stateManager) || {};
|
|
1814
1834
|
return filters
|
|
@@ -1820,12 +1840,16 @@ export default class DataUnit {
|
|
|
1820
1840
|
* @param fieldName - nome do campo para ser habilitado.
|
|
1821
1841
|
*
|
|
1822
1842
|
*/
|
|
1823
|
-
public enableField(fieldName:string) {
|
|
1843
|
+
public enableField(fieldName: string) {
|
|
1824
1844
|
const fieldDescriptor = this.getField(fieldName);
|
|
1825
1845
|
|
|
1826
|
-
if(fieldDescriptor
|
|
1846
|
+
if (!fieldDescriptor) {
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
if (fieldDescriptor.readOnly) {
|
|
1827
1851
|
fieldDescriptor.readOnly = false;
|
|
1828
|
-
this.metadata = {...this.metadata};
|
|
1852
|
+
this.metadata = { ...this.metadata };
|
|
1829
1853
|
}
|
|
1830
1854
|
}
|
|
1831
1855
|
|
|
@@ -1835,12 +1859,16 @@ export default class DataUnit {
|
|
|
1835
1859
|
* @param fieldName - nome do campo para ficar desabilitado.
|
|
1836
1860
|
*
|
|
1837
1861
|
*/
|
|
1838
|
-
public disableField(fieldName:string) {
|
|
1862
|
+
public disableField(fieldName: string) {
|
|
1839
1863
|
const fieldDescriptor = this.getField(fieldName);
|
|
1840
1864
|
|
|
1841
|
-
if(fieldDescriptor
|
|
1865
|
+
if (!fieldDescriptor) {
|
|
1866
|
+
return;
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
if (!fieldDescriptor.readOnly) {
|
|
1842
1870
|
fieldDescriptor.readOnly = true;
|
|
1843
|
-
this.metadata = {...this.metadata};
|
|
1871
|
+
this.metadata = { ...this.metadata };
|
|
1844
1872
|
}
|
|
1845
1873
|
}
|
|
1846
1874
|
|
|
@@ -1850,13 +1878,21 @@ export default class DataUnit {
|
|
|
1850
1878
|
* @param fieldName - nome do campo para ficar invisível.
|
|
1851
1879
|
*
|
|
1852
1880
|
*/
|
|
1853
|
-
public hideField(fieldName:string, options
|
|
1881
|
+
public hideField(fieldName: string, options?: HideFieldOptions) {
|
|
1854
1882
|
const fieldDescriptor = this.getField(fieldName);
|
|
1855
1883
|
|
|
1856
|
-
if(fieldDescriptor
|
|
1884
|
+
if (!fieldDescriptor) {
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
if (fieldDescriptor.visible) {
|
|
1857
1889
|
fieldDescriptor.visible = false;
|
|
1858
|
-
|
|
1859
|
-
|
|
1890
|
+
|
|
1891
|
+
if (options) {
|
|
1892
|
+
fieldDescriptor.properties = { ...fieldDescriptor.properties, visibleOnConfig: options.visibleOnConfig };
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
this.metadata = { ...this.metadata };
|
|
1860
1896
|
}
|
|
1861
1897
|
}
|
|
1862
1898
|
|
|
@@ -1866,15 +1902,19 @@ export default class DataUnit {
|
|
|
1866
1902
|
* @param fieldName - nome do campo para ficar visível.
|
|
1867
1903
|
*
|
|
1868
1904
|
*/
|
|
1869
|
-
public showField(fieldName:string) {
|
|
1905
|
+
public showField(fieldName: string) {
|
|
1870
1906
|
const fieldDescriptor = this.getField(fieldName);
|
|
1871
1907
|
|
|
1872
|
-
if(fieldDescriptor
|
|
1908
|
+
if (!fieldDescriptor) {
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
if (!fieldDescriptor.visible) {
|
|
1873
1913
|
fieldDescriptor.visible = true;
|
|
1874
|
-
this.metadata = {...this.metadata};
|
|
1914
|
+
this.metadata = { ...this.metadata };
|
|
1875
1915
|
}
|
|
1876
1916
|
}
|
|
1877
|
-
|
|
1917
|
+
|
|
1878
1918
|
/**
|
|
1879
1919
|
*
|
|
1880
1920
|
* Obtém todos os registros selecionados.
|
|
@@ -1890,7 +1930,7 @@ export default class DataUnit {
|
|
|
1890
1930
|
console.warn("DataUnit: O método `getSelectedRecords` foi descontinuado. Use o método `getSelectionInfo`.");
|
|
1891
1931
|
const selection = this.getSelectionInfo();
|
|
1892
1932
|
|
|
1893
|
-
if(selection != undefined && selection.isAllRecords()){
|
|
1933
|
+
if (selection != undefined && selection.isAllRecords()) {
|
|
1894
1934
|
throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
|
|
1895
1935
|
}
|
|
1896
1936
|
|
|
@@ -1913,11 +1953,11 @@ export default class DataUnit {
|
|
|
1913
1953
|
public getSelection(): Array<string> {
|
|
1914
1954
|
console.warn("DataUnit: O método `getSelection` foi descontinuado. Use o método `getSelectionInfo`.");
|
|
1915
1955
|
const selection = this.getSelectionInfo();
|
|
1916
|
-
if(selection == undefined){
|
|
1956
|
+
if (selection == undefined) {
|
|
1917
1957
|
return [];
|
|
1918
1958
|
}
|
|
1919
1959
|
|
|
1920
|
-
if(selection.isAllRecords()){
|
|
1960
|
+
if (selection.isAllRecords()) {
|
|
1921
1961
|
throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
|
|
1922
1962
|
}
|
|
1923
1963
|
|
|
@@ -1929,7 +1969,7 @@ export default class DataUnit {
|
|
|
1929
1969
|
*
|
|
1930
1970
|
* @deprecated - metodo depreciado, utilizar o metodo addField
|
|
1931
1971
|
*/
|
|
1932
|
-
public addStandAloneField()
|
|
1972
|
+
public addStandAloneField(): void {
|
|
1933
1973
|
console.warn("metodo depreciado, para adicionar um campo standAlone, utilizar o metodo addField")
|
|
1934
1974
|
}
|
|
1935
1975
|
|
|
@@ -1938,9 +1978,9 @@ export default class DataUnit {
|
|
|
1938
1978
|
*
|
|
1939
1979
|
* @param field - Campo a ser adicionado.
|
|
1940
1980
|
*/
|
|
1941
|
-
public addField(field: Omit<FieldDescriptor, 'standAlone'>)
|
|
1942
|
-
const standAloneField = {...field, standAlone: true};
|
|
1943
|
-
this.metadata = {...this.metadata, fields: [...this.metadata.fields, standAloneField]};
|
|
1981
|
+
public addField(field: Omit<FieldDescriptor, 'standAlone'>): void {
|
|
1982
|
+
const standAloneField = { ...field, standAlone: true };
|
|
1983
|
+
this.metadata = { ...this.metadata, fields: [...this.metadata.fields, standAloneField] };
|
|
1944
1984
|
}
|
|
1945
1985
|
|
|
1946
1986
|
/**
|
|
@@ -1948,16 +1988,16 @@ export default class DataUnit {
|
|
|
1948
1988
|
* @returns Retorna uma função responsável por liberar o lock adicionado.
|
|
1949
1989
|
*/
|
|
1950
1990
|
public addLoadingLocker(): Function {
|
|
1951
|
-
let loadingLockerResolver;
|
|
1991
|
+
let loadingLockerResolver = () => {};
|
|
1952
1992
|
|
|
1953
1993
|
this._loadingLockers.push(new Promise((resolve) => {
|
|
1954
1994
|
loadingLockerResolver = resolve;
|
|
1955
1995
|
}));
|
|
1956
|
-
|
|
1957
|
-
return loadingLockerResolver
|
|
1996
|
+
|
|
1997
|
+
return loadingLockerResolver;
|
|
1958
1998
|
}
|
|
1959
1999
|
|
|
1960
|
-
public set allowReleaseCallbacks(allow: boolean){
|
|
2000
|
+
public set allowReleaseCallbacks(allow: boolean) {
|
|
1961
2001
|
this._allowReleaseCallbacks = allow;
|
|
1962
2002
|
}
|
|
1963
2003
|
|
|
@@ -1965,19 +2005,19 @@ export default class DataUnit {
|
|
|
1965
2005
|
/**
|
|
1966
2006
|
* Adiciona um mapeamento de origem dos dados de um determinado campo
|
|
1967
2007
|
*/
|
|
1968
|
-
public addSourceFieldValue(sourceFieldName:string, targetFieldName:string): void{
|
|
2008
|
+
public addSourceFieldValue(sourceFieldName: string, targetFieldName: string): void {
|
|
1969
2009
|
this._fieldSourceValue.set(sourceFieldName, targetFieldName);
|
|
1970
2010
|
}
|
|
1971
2011
|
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
return this._fieldSourceValue.get(
|
|
2012
|
+
/**
|
|
2013
|
+
* Retornar o campo de origem dos dados caso exista mapeamento
|
|
2014
|
+
*/
|
|
2015
|
+
public getSourceFieldValue(sourceFieldName: string): string | undefined {
|
|
2016
|
+
return this._fieldSourceValue.get(sourceFieldName);
|
|
1977
2017
|
}
|
|
1978
2018
|
|
|
1979
|
-
private async processLoadingLockers(){
|
|
1980
|
-
if(this._loadingLockers.length) {
|
|
2019
|
+
private async processLoadingLockers() {
|
|
2020
|
+
if (this._loadingLockers.length) {
|
|
1981
2021
|
await Promise.all(this._loadingLockers);
|
|
1982
2022
|
this._loadingLockers = [];
|
|
1983
2023
|
}
|
|
@@ -1985,200 +2025,16 @@ export default class DataUnit {
|
|
|
1985
2025
|
|
|
1986
2026
|
}
|
|
1987
2027
|
|
|
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
|
-
};
|
|
2028
|
+
export {
|
|
2029
|
+
Record,
|
|
2030
|
+
Change,
|
|
2031
|
+
SelectionInfo,
|
|
2032
|
+
SelectionMode,
|
|
2033
|
+
LoadDataParams,
|
|
2034
|
+
DUActionInterceptor,
|
|
2035
|
+
SavedRecord,
|
|
2036
|
+
WaitingChange,
|
|
2037
|
+
QuickFilter,
|
|
2038
|
+
DataUnitEventOptions,
|
|
2039
|
+
HideFieldOptions
|
|
2040
|
+
}
|