@sankhyalabs/core 1.0.71-beta.5 → 1.0.71
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/.eslintrc.cjs +1 -2
- package/dist/dataunit/DataUnit.d.ts +18 -32
- package/dist/dataunit/DataUnit.js +84 -195
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/state/action/DataUnitAction.d.ts +0 -4
- package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
- package/dist/dataunit/state/slice/RecordsSlice.js +2 -2
- package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
- package/dist/dataunit/state/slice/WaitingChangesSlice.js.map +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/StringUtils.d.ts +2 -0
- package/dist/utils/StringUtils.js +15 -1
- package/dist/utils/StringUtils.js.map +1 -1
- package/jest.config.ts +5 -5
- package/package.json +1 -1
- package/src/dataunit/DataUnit.ts +92 -213
- package/src/dataunit/state/action/DataUnitAction.ts +0 -4
- package/src/dataunit/state/slice/RecordsSlice.ts +5 -3
- package/src/dataunit/state/slice/WaitingChangesSlice.ts +1 -0
- package/src/index.ts +3 -13
- package/src/utils/StringUtils.ts +17 -1
- package/dist/dataunit/loading/LoadDataRequest.d.ts +0 -9
- package/dist/dataunit/loading/LoadDataRequest.js +0 -2
- package/dist/dataunit/loading/LoadDataRequest.js.map +0 -1
- package/dist/dataunit/loading/LoadDataResponse.d.ts +0 -6
- package/dist/dataunit/loading/LoadDataResponse.js +0 -2
- package/dist/dataunit/loading/LoadDataResponse.js.map +0 -1
- package/dist/dataunit/loading/PaginationInfo.d.ts +0 -7
- package/dist/dataunit/loading/PaginationInfo.js +0 -2
- package/dist/dataunit/loading/PaginationInfo.js.map +0 -1
- package/dist/dataunit/state/slice/LoadingControlSlice.d.ts +0 -19
- package/dist/dataunit/state/slice/LoadingControlSlice.js +0 -45
- package/dist/dataunit/state/slice/LoadingControlSlice.js.map +0 -1
- package/src/dataunit/loading/LoadDataRequest.ts +0 -10
- package/src/dataunit/loading/LoadDataResponse.ts +0 -7
- package/src/dataunit/loading/PaginationInfo.ts +0 -8
- package/src/dataunit/state/slice/LoadingControlSlice.ts +0 -60
package/src/dataunit/DataUnit.ts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
+
import { UnitMetadata, FieldDescriptor, SortingProvider, FilterProvider, Sort, Filter } from "./metadata/UnitMetadata.js";
|
|
1
2
|
import { convertType, toString } from "./metadata/DataType.js";
|
|
2
|
-
import { FieldDescriptor, Filter, FilterProvider, Sort, SortingProvider, UnitMetadata } from "./metadata/UnitMetadata.js";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { DataUnitAction, Action } from "./state/action/DataUnitAction.js";
|
|
5
5
|
import StateManager from "./state/StateManager.js";
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { StringUtils } from "../utils/StringUtils.js";
|
|
10
|
-
import { LoadDataRequest } from "./loading/LoadDataRequest.js";
|
|
11
|
-
import { LoadDataResponse } from "./loading/LoadDataResponse.js";
|
|
12
|
-
import { PaginationInfo } from "./loading/PaginationInfo.js";
|
|
13
|
-
import { AddedRecordsReducer, prepareAddedRecordId, prepareCopiedRecord } from "./state/slice/AddedRecordsSlice.js";
|
|
14
|
-
import { ChangesReducer, getChangesToSave, isDirty } from "./state/slice/ChangesSlice.js";
|
|
15
|
-
import { CurrentRecordsReducer, getCurrentRecords, getFieldValue, getModifiedRecords } from "./state/slice/CurrentRecordsSlice.js";
|
|
16
|
-
import { getCurrentPage, getLastPage, getPaginationInfo, getCurrentRequest, LoadingControlReducer, hasMorePages, hasPreviousPages } from "./state/slice/LoadingControlSlice.js";
|
|
7
|
+
import { HistReducer, canRedo, canUndo } from "./state/HistReducer.js";
|
|
8
|
+
import { UnitMetadataReducer, getField, getMetadata } from "./state/slice/UnitMetadataSlice.js";
|
|
17
9
|
import { RecordsReducer } from "./state/slice/RecordsSlice.js";
|
|
10
|
+
import { SelectionReducer, getSelection, hasNext, hasPrevious } from "./state/slice/SelectionSlice.js";
|
|
11
|
+
import { ChangesReducer, isDirty, getChangesToSave } from "./state/slice/ChangesSlice.js";
|
|
18
12
|
import { RemovedRecordsReducer } from "./state/slice/RemovedRecordsSlice.js";
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { getBlockingWaitingChanges, getWaitingChangePromisses, isWaiting, WaitingChangesReducer } from "./state/slice/WaitingChangesSlice.js";
|
|
22
|
-
import
|
|
13
|
+
import { AddedRecordsReducer, prepareAddedRecordId, prepareCopiedRecord } from "./state/slice/AddedRecordsSlice.js";
|
|
14
|
+
import { CurrentRecordsReducer, getCurrentRecords, getFieldValue, getModifiedRecords } from "./state/slice/CurrentRecordsSlice.js";
|
|
15
|
+
import { getBlockingWaitingChanges, getWaitingChangePromisses, getWaitingChanges, isWaiting, WaitingChangesReducer } from "./state/slice/WaitingChangesSlice.js";
|
|
16
|
+
import WaitingChangeException from "../exceptions/WaitingChangeException.js";
|
|
17
|
+
import ErrorException from "../exceptions/ErrorException.js";
|
|
18
|
+
import { StringUtils } from "../utils/StringUtils.js";
|
|
23
19
|
|
|
24
20
|
export default class DataUnit {
|
|
25
21
|
|
|
@@ -29,21 +25,18 @@ export default class DataUnit {
|
|
|
29
25
|
private _filterProviders: Map<string, FilterProvider>;
|
|
30
26
|
private _stateManager: StateManager;
|
|
31
27
|
private _interceptors: Array<DUActionInterceptor>;
|
|
32
|
-
private _pageSize: number;
|
|
33
28
|
|
|
34
29
|
public metadataLoader?: (dataUnit: DataUnit) => Promise<UnitMetadata>;
|
|
35
|
-
public dataLoader?: (dataUnit: DataUnit,
|
|
30
|
+
public dataLoader?: (dataUnit: DataUnit, page?: PageRequest, sort?: Array<Sort>, filters?: Array<Filter>) => Promise<PageResponse>;
|
|
36
31
|
public saveLoader?: (dataUnit: DataUnit, changes: Array<Change>) => Promise<Array<SavedRecord>>;
|
|
37
32
|
public removeLoader?: (dataUnit: DataUnit, recordIds: Array<string>) => Promise<Array<string>>;
|
|
38
33
|
|
|
39
34
|
constructor(name: string) {
|
|
40
35
|
this._name = name;
|
|
41
|
-
this._pageSize = 0;
|
|
42
36
|
this._stateManager = new StateManager(
|
|
43
37
|
[
|
|
44
38
|
HistReducer,
|
|
45
39
|
UnitMetadataReducer,
|
|
46
|
-
LoadingControlReducer,
|
|
47
40
|
RecordsReducer,
|
|
48
41
|
RemovedRecordsReducer,
|
|
49
42
|
AddedRecordsReducer,
|
|
@@ -65,6 +58,7 @@ export default class DataUnit {
|
|
|
65
58
|
|
|
66
59
|
// Métodos privados
|
|
67
60
|
private validateAndTypeValue(fieldName: string, newValue: any): any {
|
|
61
|
+
//FIXME: Validações devem ser feitas aqui
|
|
68
62
|
const descriptor: FieldDescriptor | undefined = this.getField(fieldName);
|
|
69
63
|
return descriptor ? convertType(descriptor.dataType, newValue) : newValue;
|
|
70
64
|
}
|
|
@@ -84,31 +78,16 @@ export default class DataUnit {
|
|
|
84
78
|
return this._sortingProvider ? this._sortingProvider.getSort(this._name) : undefined;
|
|
85
79
|
}
|
|
86
80
|
|
|
87
|
-
private getFielterProviderKey(provider:
|
|
88
|
-
if
|
|
81
|
+
private getFielterProviderKey(provider:FilterProvider):string{
|
|
82
|
+
if(provider.getKey){
|
|
89
83
|
return provider.getKey();
|
|
90
84
|
}
|
|
91
85
|
return StringUtils.hashCode(provider.getFilter.toString());
|
|
92
86
|
}
|
|
93
87
|
|
|
94
|
-
private executeLoadData(request: LoadDataRequest, executionCtx?: ExecutionContext): Promise<LoadDataResponse> {
|
|
95
|
-
return new Promise(async (resolve, fail) => {
|
|
96
|
-
if (await this.dispatchAction(Action.LOADING_DATA, request, executionCtx)) {
|
|
97
|
-
if (this.dataLoader) {
|
|
98
|
-
this.dataLoader(this, request).then(
|
|
99
|
-
response => {
|
|
100
|
-
this.dispatchAction(Action.DATA_LOADED, response, executionCtx);
|
|
101
|
-
resolve(response);
|
|
102
|
-
}
|
|
103
|
-
).catch(error => fail(new ErrorException("Problema carregando registros", error)));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
88
|
// Loaders
|
|
110
|
-
public async loadMetadata(
|
|
111
|
-
if
|
|
89
|
+
public async loadMetadata(): Promise<UnitMetadata|void> {
|
|
90
|
+
if(this.dispatchAction(Action.LOADING_METADATA)){
|
|
112
91
|
return new Promise((resolve, fail) => {
|
|
113
92
|
if (this.metadataLoader) {
|
|
114
93
|
this.metadataLoader(this).then(
|
|
@@ -122,51 +101,24 @@ export default class DataUnit {
|
|
|
122
101
|
}
|
|
123
102
|
}
|
|
124
103
|
|
|
125
|
-
public async loadData(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public async gotoPage(page: number, executionCtx?: ExecutionContext): Promise<LoadDataResponse | void> {
|
|
142
|
-
|
|
143
|
-
let request = getCurrentRequest(this._stateManager);
|
|
144
|
-
|
|
145
|
-
if (!request) {
|
|
146
|
-
request = {
|
|
147
|
-
filters: this.getFilters(),
|
|
148
|
-
sort: this.getSort()
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (page >= 0 && page <= getLastPage(this._stateManager, this._pageSize)) {
|
|
153
|
-
return this.executeLoadData({
|
|
154
|
-
...request,
|
|
155
|
-
limit: this._pageSize,
|
|
156
|
-
offset: page * this._pageSize
|
|
157
|
-
}, executionCtx);
|
|
104
|
+
public async loadData(page?: PageRequest): Promise<PageResponse|void> {
|
|
105
|
+
if(this.dispatchAction(Action.LOADING_DATA)){
|
|
106
|
+
return new Promise((resolve, fail) => {
|
|
107
|
+
if (this.dataLoader) {
|
|
108
|
+
const sort = this.getSort();
|
|
109
|
+
const filters = this.getFilters();
|
|
110
|
+
this.dataLoader(this, page, sort, filters).then(
|
|
111
|
+
pageRes => {
|
|
112
|
+
this.records = pageRes.records;
|
|
113
|
+
resolve(pageRes);
|
|
114
|
+
}
|
|
115
|
+
).catch(error => fail(new ErrorException("Problema carregando registros", error)));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
158
118
|
}
|
|
159
119
|
}
|
|
160
120
|
|
|
161
|
-
public async
|
|
162
|
-
return this.gotoPage(getCurrentPage(this._stateManager) + 1, executionCtx);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
public async previousPage(executionCtx?: ExecutionContext): Promise<LoadDataResponse | void> {
|
|
166
|
-
return this.gotoPage(getCurrentPage(this._stateManager) - 1, executionCtx);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public async saveData(executionCtx?: ExecutionContext): Promise<void> {
|
|
121
|
+
public async saveData(): Promise<void> {
|
|
170
122
|
const blockingWaitingChanges = getBlockingWaitingChanges(this._stateManager);
|
|
171
123
|
|
|
172
124
|
if (blockingWaitingChanges && blockingWaitingChanges.size > 0) {
|
|
@@ -174,8 +126,8 @@ export default class DataUnit {
|
|
|
174
126
|
return Promise.reject(new WaitingChangeException("Aguardando alteração de campo", (waitingChange as WaitingChange).waitmessage));
|
|
175
127
|
} else {
|
|
176
128
|
if (isDirty(this._stateManager)) {
|
|
177
|
-
|
|
178
|
-
if (
|
|
129
|
+
|
|
130
|
+
if (this.dispatchAction(Action.SAVING_DATA)) {
|
|
179
131
|
const promisses = getWaitingChangePromisses(this._stateManager);
|
|
180
132
|
return new Promise((resolve, fail) => {
|
|
181
133
|
Promise.all(promisses || []).then(() => {
|
|
@@ -183,7 +135,7 @@ export default class DataUnit {
|
|
|
183
135
|
const changes: Array<Change> = getChangesToSave(this._name, this._stateManager);
|
|
184
136
|
this.saveLoader(this, changes).then(
|
|
185
137
|
records => {
|
|
186
|
-
this.dispatchAction(Action.DATA_SAVED, { changes, records }
|
|
138
|
+
this.dispatchAction(Action.DATA_SAVED, { changes, records });
|
|
187
139
|
resolve();
|
|
188
140
|
}
|
|
189
141
|
).catch(cause => fail(new ErrorException("Erro salvando alterações", cause)));
|
|
@@ -207,12 +159,12 @@ export default class DataUnit {
|
|
|
207
159
|
return Promise.resolve(selection);
|
|
208
160
|
}
|
|
209
161
|
|
|
210
|
-
public async removeRecords(records: Array<string>, buffered: boolean = false
|
|
162
|
+
public async removeRecords(records: Array<string>, buffered: boolean = false): Promise<Array<string>> {
|
|
211
163
|
if (records) {
|
|
212
164
|
if (buffered || !this.removeLoader) {
|
|
213
|
-
this.dispatchAction(Action.RECORDS_REMOVED, { records, buffered: true }
|
|
165
|
+
this.dispatchAction(Action.RECORDS_REMOVED, { records, buffered: true });
|
|
214
166
|
} else {
|
|
215
|
-
if (
|
|
167
|
+
if (this.dispatchAction(Action.REMOVING_RECORDS)) {
|
|
216
168
|
|
|
217
169
|
return new Promise((resolve, fail) => {
|
|
218
170
|
if (this.removeLoader) {
|
|
@@ -230,7 +182,7 @@ export default class DataUnit {
|
|
|
230
182
|
currentIndex++
|
|
231
183
|
});
|
|
232
184
|
|
|
233
|
-
this.dispatchAction(Action.RECORDS_REMOVED, { records, removedIndex, buffered: false }
|
|
185
|
+
this.dispatchAction(Action.RECORDS_REMOVED, { records, removedIndex, buffered: false });
|
|
234
186
|
resolve(records);
|
|
235
187
|
}
|
|
236
188
|
).catch(error => fail(new ErrorException("Problema removendo registros", error)));
|
|
@@ -265,16 +217,12 @@ export default class DataUnit {
|
|
|
265
217
|
this._filterProviders.set(this.getFielterProviderKey(provider), provider);
|
|
266
218
|
}
|
|
267
219
|
|
|
268
|
-
public getPaginationInfo(): PaginationInfo | void {
|
|
269
|
-
return getPaginationInfo(this._stateManager);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
220
|
public set sortingProvider(provider: SortingProvider) {
|
|
273
221
|
this._sortingProvider = provider;
|
|
274
222
|
}
|
|
275
223
|
|
|
276
224
|
public set metadata(md: UnitMetadata) {
|
|
277
|
-
this.dispatchAction(Action.METADATA_LOADED, md
|
|
225
|
+
this.dispatchAction(Action.METADATA_LOADED, md);
|
|
278
226
|
}
|
|
279
227
|
|
|
280
228
|
public get metadata(): UnitMetadata {
|
|
@@ -282,7 +230,7 @@ export default class DataUnit {
|
|
|
282
230
|
}
|
|
283
231
|
|
|
284
232
|
public set records(r: Array<Record>) {
|
|
285
|
-
this.dispatchAction(Action.DATA_LOADED,
|
|
233
|
+
this.dispatchAction(Action.DATA_LOADED, r);
|
|
286
234
|
}
|
|
287
235
|
|
|
288
236
|
public get records(): Array<Record> {
|
|
@@ -290,14 +238,6 @@ export default class DataUnit {
|
|
|
290
238
|
return records ? Array.from(records.values()) : [];
|
|
291
239
|
}
|
|
292
240
|
|
|
293
|
-
public set pageSize(size: number) {
|
|
294
|
-
this._pageSize = size;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
public get pageSize(): number {
|
|
298
|
-
return this._pageSize;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
241
|
public getModifiedRecords(): Array<Record> {
|
|
302
242
|
const modified = getModifiedRecords(this._stateManager);
|
|
303
243
|
return modified || [];
|
|
@@ -307,14 +247,14 @@ export default class DataUnit {
|
|
|
307
247
|
return getField(this._stateManager, fieldName);
|
|
308
248
|
}
|
|
309
249
|
|
|
310
|
-
public addRecord(
|
|
311
|
-
this.dispatchAction(Action.RECORDS_ADDED, prepareAddedRecordId(this._stateManager, [{}])
|
|
250
|
+
public addRecord(): void {
|
|
251
|
+
this.dispatchAction(Action.RECORDS_ADDED, prepareAddedRecordId(this._stateManager, [{}]));
|
|
312
252
|
}
|
|
313
253
|
|
|
314
|
-
public copySelected(
|
|
254
|
+
public copySelected(): void {
|
|
315
255
|
const selectedRecords = this.getSelectedRecords();
|
|
316
256
|
if (selectedRecords) {
|
|
317
|
-
this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords)
|
|
257
|
+
this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords));
|
|
318
258
|
}
|
|
319
259
|
}
|
|
320
260
|
|
|
@@ -332,42 +272,38 @@ export default class DataUnit {
|
|
|
332
272
|
const currentValue = this.getFieldValue(fieldName);
|
|
333
273
|
|
|
334
274
|
if (currentValue !== typedValue) {
|
|
335
|
-
this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records }
|
|
275
|
+
this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records });
|
|
336
276
|
}
|
|
337
277
|
}
|
|
338
278
|
|
|
339
279
|
public startChange(fieldName: string, waitingChange: WaitingChange): void {
|
|
340
|
-
this.dispatchAction(Action.CHANGING_DATA, { [fieldName]: waitingChange }
|
|
280
|
+
this.dispatchAction(Action.CHANGING_DATA, { [fieldName]: waitingChange });
|
|
341
281
|
}
|
|
342
282
|
|
|
343
283
|
public cancelWaitingChange(fieldName: string): void {
|
|
344
|
-
this.dispatchAction(Action.WAITING_CHANGE_CANCELED, { fieldName }
|
|
284
|
+
this.dispatchAction(Action.WAITING_CHANGE_CANCELED, { fieldName });
|
|
345
285
|
}
|
|
346
286
|
|
|
347
287
|
public getSelection(): Array<string> {
|
|
348
288
|
return getSelection(this._stateManager);
|
|
349
289
|
}
|
|
350
290
|
|
|
351
|
-
public setSelection(selection: Array<string
|
|
352
|
-
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }
|
|
291
|
+
public setSelection(selection: Array<string>): void {
|
|
292
|
+
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection });
|
|
353
293
|
}
|
|
354
294
|
|
|
355
|
-
public selectFirst(
|
|
356
|
-
if
|
|
357
|
-
this.
|
|
295
|
+
public selectFirst(): void {
|
|
296
|
+
if(this.records.length > 0){
|
|
297
|
+
this.dispatchAction(Action.SELECTION_CHANGED, { type: "index", selection: [0] });
|
|
358
298
|
}
|
|
359
299
|
}
|
|
360
300
|
|
|
361
|
-
public selectLast(
|
|
362
|
-
if
|
|
363
|
-
this.
|
|
301
|
+
public selectLast(): void {
|
|
302
|
+
if(this.records.length > 0){
|
|
303
|
+
this.dispatchAction(Action.SELECTION_CHANGED, { type: "index", selection: [this.records.length - 1] });
|
|
364
304
|
}
|
|
365
305
|
}
|
|
366
306
|
|
|
367
|
-
public setSelectionByIndex(selection: Array<number>, executionCtx?: ExecutionContext): void {
|
|
368
|
-
this.dispatchAction(Action.SELECTION_CHANGED, { type: "index", selection }, executionCtx);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
307
|
public getSelectedRecords(): Array<Record> | undefined {
|
|
372
308
|
const selection: Array<string> = this.getSelection();
|
|
373
309
|
if (selection) {
|
|
@@ -376,48 +312,16 @@ export default class DataUnit {
|
|
|
376
312
|
}
|
|
377
313
|
}
|
|
378
314
|
|
|
379
|
-
public nextRecord(
|
|
380
|
-
|
|
381
|
-
if(hasMorePages(this._stateManager)){
|
|
382
|
-
this.nextPage({
|
|
383
|
-
before: act =>{
|
|
384
|
-
if(executionCtx && executionCtx.before){
|
|
385
|
-
act = executionCtx.before(act);
|
|
386
|
-
}
|
|
387
|
-
return act;
|
|
388
|
-
},
|
|
389
|
-
after: act => {
|
|
390
|
-
this.selectFirst(executionCtx);
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
} else {
|
|
395
|
-
this.dispatchAction(Action.NEXT_SELECTED, undefined, executionCtx);
|
|
396
|
-
}
|
|
315
|
+
public nextRecord(): void {
|
|
316
|
+
this.dispatchAction(Action.NEXT_SELECTED);
|
|
397
317
|
}
|
|
398
318
|
|
|
399
|
-
public previousRecord(
|
|
400
|
-
|
|
401
|
-
if(hasPreviousPages(this._stateManager)){
|
|
402
|
-
this.previousPage({
|
|
403
|
-
before: act =>{
|
|
404
|
-
if(executionCtx && executionCtx.before){
|
|
405
|
-
act = executionCtx.before(act);
|
|
406
|
-
}
|
|
407
|
-
return act;
|
|
408
|
-
},
|
|
409
|
-
after: act => {
|
|
410
|
-
this.selectLast(executionCtx);
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
} else {
|
|
415
|
-
this.dispatchAction(Action.PREVIOUS_SELECTED, undefined, executionCtx);
|
|
416
|
-
}
|
|
319
|
+
public previousRecord(): void {
|
|
320
|
+
this.dispatchAction(Action.PREVIOUS_SELECTED);
|
|
417
321
|
}
|
|
418
322
|
|
|
419
|
-
public cancelEdition(
|
|
420
|
-
this.dispatchAction(Action.EDITION_CANCELED
|
|
323
|
+
public cancelEdition(): void {
|
|
324
|
+
this.dispatchAction(Action.EDITION_CANCELED);
|
|
421
325
|
}
|
|
422
326
|
|
|
423
327
|
public isDirty(): boolean {
|
|
@@ -425,19 +329,11 @@ export default class DataUnit {
|
|
|
425
329
|
}
|
|
426
330
|
|
|
427
331
|
public hasNext(): boolean {
|
|
428
|
-
|
|
429
|
-
if(!result){
|
|
430
|
-
result = hasMorePages(this._stateManager);
|
|
431
|
-
}
|
|
432
|
-
return result;
|
|
332
|
+
return hasNext(this._stateManager);
|
|
433
333
|
}
|
|
434
334
|
|
|
435
335
|
public hasPrevious(): boolean {
|
|
436
|
-
|
|
437
|
-
if(!result){
|
|
438
|
-
result = hasPreviousPages(this._stateManager);
|
|
439
|
-
}
|
|
440
|
-
return result;
|
|
336
|
+
return hasPrevious(this._stateManager);
|
|
441
337
|
}
|
|
442
338
|
|
|
443
339
|
public canUndo(): boolean {
|
|
@@ -448,12 +344,12 @@ export default class DataUnit {
|
|
|
448
344
|
return canRedo(this._stateManager);
|
|
449
345
|
}
|
|
450
346
|
|
|
451
|
-
public undo(
|
|
452
|
-
this.dispatchAction(Action.CHANGE_UNDONE
|
|
347
|
+
public undo() {
|
|
348
|
+
this.dispatchAction(Action.CHANGE_UNDONE);
|
|
453
349
|
}
|
|
454
350
|
|
|
455
|
-
public redo(
|
|
456
|
-
this.dispatchAction(Action.CHANGE_REDONE
|
|
351
|
+
public redo() {
|
|
352
|
+
this.dispatchAction(Action.CHANGE_REDONE);
|
|
457
353
|
}
|
|
458
354
|
|
|
459
355
|
public toString() {
|
|
@@ -461,50 +357,33 @@ export default class DataUnit {
|
|
|
461
357
|
}
|
|
462
358
|
|
|
463
359
|
// Actions / State manager
|
|
464
|
-
private
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
action = executionCtx.before(action);
|
|
469
|
-
}
|
|
470
|
-
if (action && this._interceptors && this._interceptors.length > 0) {
|
|
471
|
-
action = await this.intercept(action, this._interceptors.values());
|
|
472
|
-
}
|
|
360
|
+
private dispatchAction(actionType: Action, payload?: any): boolean {
|
|
361
|
+
let action = new DataUnitAction(actionType, payload);
|
|
362
|
+
|
|
363
|
+
this._interceptors?.forEach(interceptor => {
|
|
473
364
|
if (action) {
|
|
474
|
-
|
|
475
|
-
if (executionCtx && executionCtx.after) {
|
|
476
|
-
executionCtx.after(action)
|
|
477
|
-
}
|
|
478
|
-
resolve(true);
|
|
479
|
-
} else {
|
|
480
|
-
resolve(false);
|
|
365
|
+
action = interceptor.interceptAction(action);
|
|
481
366
|
}
|
|
482
367
|
});
|
|
483
|
-
}
|
|
484
368
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
while (action && !(ite = interceptors.next()).done) {
|
|
489
|
-
action = await ite.value.interceptAction(action);
|
|
490
|
-
}
|
|
491
|
-
resolve(action);
|
|
492
|
-
});
|
|
493
|
-
}
|
|
369
|
+
if (!action) {
|
|
370
|
+
return false;
|
|
371
|
+
} else {
|
|
494
372
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
}
|
|
373
|
+
this._stateManager.process(action);
|
|
374
|
+
this._observers.forEach(f => {
|
|
375
|
+
/*
|
|
376
|
+
if some observer throws exceptions,
|
|
377
|
+
should be continued
|
|
378
|
+
*/
|
|
379
|
+
try {
|
|
380
|
+
f(action);
|
|
381
|
+
} catch (e) {
|
|
382
|
+
console.warn("[DataUnit] error while call observer", e);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
return true;
|
|
508
387
|
}
|
|
509
388
|
|
|
510
389
|
public subscribe(observer: (action: DataUnitAction) => void) {
|
|
@@ -517,7 +396,7 @@ export default class DataUnit {
|
|
|
517
396
|
}
|
|
518
397
|
|
|
519
398
|
export interface DUActionInterceptor {
|
|
520
|
-
interceptAction(action: DataUnitAction): DataUnitAction
|
|
399
|
+
interceptAction(action: DataUnitAction): DataUnitAction;
|
|
521
400
|
}
|
|
522
401
|
|
|
523
402
|
export interface Record {
|
|
@@ -19,10 +19,6 @@ export class DataUnitAction implements StateAction{
|
|
|
19
19
|
return this._payload;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
export interface ExecutionContext{
|
|
23
|
-
before?: (action: DataUnitAction) => DataUnitAction;
|
|
24
|
-
after?: (action: DataUnitAction) => void;
|
|
25
|
-
}
|
|
26
22
|
|
|
27
23
|
export enum Action{
|
|
28
24
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
|
|
1
2
|
import { ActionReducer, StateAction } from "../StateManager.js";
|
|
2
|
-
import StateManager from "../StateManager.js";
|
|
3
|
-
import { getRemovedRecords } from "./RemovedRecordsSlice.js";
|
|
4
3
|
import { Action } from "../action/DataUnitAction.js";
|
|
4
|
+
import StateManager from "../StateManager.js";
|
|
5
5
|
import { Record, SavedRecord } from "../../DataUnit.js";
|
|
6
|
+
import { getRemovedRecords } from "./RemovedRecordsSlice.js";
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
class RecordsReducerImpl implements ActionReducer {
|
|
8
10
|
|
|
@@ -12,7 +14,7 @@ class RecordsReducerImpl implements ActionReducer {
|
|
|
12
14
|
switch (action.type) {
|
|
13
15
|
|
|
14
16
|
case Action.DATA_LOADED:
|
|
15
|
-
return action.payload
|
|
17
|
+
return action.payload;
|
|
16
18
|
case Action.RECORDS_REMOVED:
|
|
17
19
|
|
|
18
20
|
const {records, buffered} = action.payload;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { WaitingChange } from "../../DataUnit.js";
|
|
3
3
|
import { Action } from "../action/DataUnitAction.js";
|
|
4
4
|
import StateManager, { ActionReducer, StateAction } from "../StateManager.js";
|
|
5
|
+
import { getSelection } from "./SelectionSlice.js";
|
|
5
6
|
|
|
6
7
|
class WaitingCheangesReducerImpl implements ActionReducer{
|
|
7
8
|
|
package/src/index.ts
CHANGED
|
@@ -10,8 +10,8 @@ import { RequestMetadata } from "./http/RequestMetadata.js";
|
|
|
10
10
|
import { AuthorizedServiceCaller } from "./http/AuthorizedServiceCaller.js";
|
|
11
11
|
import DataUnit, {SavedRecord, Record, Change, ChangeOperation, DUActionInterceptor, WaitingChange, PageRequest, QuickFilter} from "./dataunit/DataUnit.js";
|
|
12
12
|
import { DataType } from "./dataunit/metadata/DataType.js";
|
|
13
|
-
import { UnitMetadata, FieldDescriptor, UserInterface, Sort,
|
|
14
|
-
import { DataUnitAction, Action
|
|
13
|
+
import { UnitMetadata, FieldDescriptor, UserInterface, Sort, Filter } from "./dataunit/metadata/UnitMetadata.js";
|
|
14
|
+
import { DataUnitAction, Action } from "./dataunit/state/action/DataUnitAction.js";
|
|
15
15
|
import ApplicationContext from "./utils/ApplicationContext.js";
|
|
16
16
|
import ReadyUtil from "./utils/ReadyUtil.js";
|
|
17
17
|
import ObjectUtils from "./utils/ObjectUtils.js";
|
|
@@ -19,9 +19,6 @@ import WarningException from "./exceptions/WarningException.js";
|
|
|
19
19
|
import WaitingChangeException from "./exceptions/WaitingChangeException.js";
|
|
20
20
|
import ErrorException from "./exceptions/ErrorException.js";
|
|
21
21
|
import { ErrorTracking } from "./traking/ErrorTraking.js";
|
|
22
|
-
import { PaginationInfo } from "./dataunit/loading/PaginationInfo.js";
|
|
23
|
-
import { LoadDataRequest } from "./dataunit/loading/LoadDataRequest.js";
|
|
24
|
-
import { LoadDataResponse } from "./dataunit/loading/LoadDataResponse.js";
|
|
25
22
|
|
|
26
23
|
/*Classes públicas no pacote*/
|
|
27
24
|
export {
|
|
@@ -42,7 +39,6 @@ export {
|
|
|
42
39
|
UnitMetadata,
|
|
43
40
|
FieldDescriptor,
|
|
44
41
|
UserInterface,
|
|
45
|
-
DependencyType,
|
|
46
42
|
DataUnitAction,
|
|
47
43
|
Action,
|
|
48
44
|
Change,
|
|
@@ -59,11 +55,5 @@ export {
|
|
|
59
55
|
WarningException,
|
|
60
56
|
WaitingChangeException,
|
|
61
57
|
ErrorException,
|
|
62
|
-
ErrorTracking
|
|
63
|
-
ExecutionContext,
|
|
64
|
-
PaginationInfo,
|
|
65
|
-
SortingProvider,
|
|
66
|
-
SortMode,
|
|
67
|
-
LoadDataRequest,
|
|
68
|
-
LoadDataResponse
|
|
58
|
+
ErrorTracking
|
|
69
59
|
};
|
package/src/utils/StringUtils.ts
CHANGED
|
@@ -55,7 +55,7 @@ export class StringUtils {
|
|
|
55
55
|
text = text.replace(/[Û]/, "U");
|
|
56
56
|
text = text.replace(/[Ü]/, "U");
|
|
57
57
|
text = text.replace(/[Ç]/, "C");
|
|
58
|
-
return text.replace(/[^a-z0-9]/gi,
|
|
58
|
+
return text.replace(/[^a-z0-9]/gi, "");
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
@@ -91,4 +91,20 @@ export class StringUtils {
|
|
|
91
91
|
return defaultValue;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
+
|
|
95
|
+
static padStart(str: string, len: number, pad: string = " "): string {
|
|
96
|
+
str = str != undefined ? str : "";
|
|
97
|
+
while (str.length < len) {
|
|
98
|
+
str = pad + str;
|
|
99
|
+
}
|
|
100
|
+
return str;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static padEnd(str: string, len: number, pad: string = " "): string {
|
|
104
|
+
str = str != undefined ? str : "";
|
|
105
|
+
while (str.length < len) {
|
|
106
|
+
str = str + pad;
|
|
107
|
+
}
|
|
108
|
+
return str;
|
|
109
|
+
}
|
|
94
110
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LoadDataRequest.js","sourceRoot":"","sources":["../../../src/dataunit/loading/LoadDataRequest.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LoadDataResponse.js","sourceRoot":"","sources":["../../../src/dataunit/loading/LoadDataResponse.ts"],"names":[],"mappings":""}
|