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