@sankhyalabs/core 2.3.6 → 2.4.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/ApplicationContext.md +24 -10
- package/.docs/classes/ArrayUtils.md +24 -14
- package/.docs/classes/Change.md +40 -18
- package/.docs/classes/DataUnit.md +418 -225
- package/.docs/classes/DateUtils.md +95 -36
- package/.docs/classes/ElementIDUtils.md +70 -37
- package/.docs/classes/ErrorException.md +12 -4
- package/.docs/classes/ErrorTracking.md +13 -5
- package/.docs/classes/FloatingManager.md +104 -63
- package/.docs/classes/MaskFormatter-1.md +17 -17
- package/.docs/classes/NumberUtils.md +74 -35
- package/.docs/classes/ObjectUtils.md +34 -12
- package/.docs/classes/ReadyUtil.md +18 -6
- package/.docs/classes/StringUtils.md +108 -52
- package/.docs/classes/TimeFormatter.md +9 -9
- package/.docs/classes/UserAgentUtils.md +12 -2
- package/.docs/classes/WaitingChangeException.md +9 -3
- package/.docs/classes/WarningException.md +12 -4
- package/.docs/enums/ChangeOperation.md +4 -4
- package/.docs/enums/DataType.md +5 -5
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/LoadDataRequest.md +17 -5
- package/.docs/interfaces/LoadDataResponse.md +8 -2
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/PaginationInfo.md +17 -5
- package/.docs/interfaces/QuickFilter.md +2 -2
- package/.docs/interfaces/Record.md +2 -2
- package/.docs/interfaces/SavedRecord.md +3 -3
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/.docs/modules/MaskFormatter.md +2 -2
- package/.releaserc +1 -1
- package/.reusable-default-scripts.yml +4 -2
- package/build.env +0 -2
- package/dist/dataunit/DataUnit.d.ts +516 -7
- package/dist/dataunit/DataUnit.js +511 -3
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/dataunit/loading/LoadDataRequest.d.ts +6 -0
- package/dist/dataunit/loading/LoadDataResponse.d.ts +3 -0
- package/dist/dataunit/loading/PaginationInfo.d.ts +6 -0
- package/dist/dataunit/metadata/DataType.d.ts +44 -0
- package/dist/dataunit/metadata/DataType.js +45 -0
- package/dist/dataunit/metadata/DataType.js.map +1 -1
- package/dist/exceptions/ErrorException.d.ts +6 -0
- package/dist/exceptions/ErrorException.js +3 -0
- package/dist/exceptions/ErrorException.js.map +1 -1
- package/dist/exceptions/WaitingChangeException.d.ts +5 -0
- package/dist/exceptions/WaitingChangeException.js +3 -0
- package/dist/exceptions/WaitingChangeException.js.map +1 -1
- package/dist/exceptions/WarningException.d.ts +6 -0
- package/dist/exceptions/WarningException.js +3 -0
- package/dist/exceptions/WarningException.js.map +1 -1
- package/dist/traking/ErrorTraking.d.ts +15 -0
- package/dist/traking/ErrorTraking.js +15 -0
- package/dist/traking/ErrorTraking.js.map +1 -1
- package/dist/ui/FloatingManager.d.ts +114 -0
- package/dist/ui/FloatingManager.js +128 -0
- package/dist/ui/FloatingManager.js.map +1 -1
- package/dist/utils/ApplicationContext.d.ts +21 -0
- package/dist/utils/ApplicationContext.js +21 -0
- package/dist/utils/ApplicationContext.js.map +1 -1
- package/dist/utils/ArrayUtils.d.ts +19 -4
- package/dist/utils/ArrayUtils.js +19 -4
- package/dist/utils/ArrayUtils.js.map +1 -1
- package/dist/utils/CriteriaModel.d.ts +2 -4
- package/dist/utils/CriteriaModel.js +3 -5
- package/dist/utils/CriteriaModel.js.map +1 -1
- package/dist/utils/DateUtils.d.ts +63 -0
- package/dist/utils/DateUtils.js +63 -1
- package/dist/utils/DateUtils.js.map +1 -1
- package/dist/utils/ElementIDUtils.d.ts +51 -0
- package/dist/utils/ElementIDUtils.js +51 -0
- package/dist/utils/ElementIDUtils.js.map +1 -1
- package/dist/utils/MaskFormatter.d.ts +45 -24
- package/dist/utils/MaskFormatter.js +99 -25
- package/dist/utils/MaskFormatter.js.map +1 -1
- package/dist/utils/NumberUtils.d.ts +39 -31
- package/dist/utils/NumberUtils.js +39 -31
- package/dist/utils/NumberUtils.js.map +1 -1
- package/dist/utils/ObjectUtils.d.ts +27 -0
- package/dist/utils/ObjectUtils.js +27 -0
- package/dist/utils/ObjectUtils.js.map +1 -1
- package/dist/utils/ReadyUtil.d.ts +16 -0
- package/dist/utils/ReadyUtil.js +16 -0
- package/dist/utils/ReadyUtil.js.map +1 -1
- package/dist/utils/StringUtils.d.ts +72 -28
- package/dist/utils/StringUtils.js +72 -28
- package/dist/utils/StringUtils.js.map +1 -1
- package/dist/utils/TimeFormatter.d.ts +9 -9
- package/dist/utils/TimeFormatter.js +10 -10
- package/dist/utils/TimeFormatter.js.map +1 -1
- package/dist/utils/UserAgentUtils/index.d.ts +11 -0
- package/dist/utils/UserAgentUtils/index.js +11 -0
- package/dist/utils/UserAgentUtils/index.js.map +1 -1
- package/package.json +1 -1
- package/publish-docs.sh +1 -2
- package/src/dataunit/DataUnit.ts +520 -10
- package/src/dataunit/loading/LoadDataRequest.ts +10 -0
- package/src/dataunit/loading/LoadDataResponse.ts +4 -0
- package/src/dataunit/loading/PaginationInfo.ts +11 -1
- package/src/dataunit/metadata/DataType.ts +47 -1
- package/src/exceptions/ErrorException.ts +8 -0
- package/src/exceptions/WaitingChangeException.ts +6 -1
- package/src/exceptions/WarningException.ts +8 -1
- package/src/traking/ErrorTraking.ts +17 -0
- package/src/ui/FloatingManager.ts +138 -7
- package/src/utils/ApplicationContext.ts +21 -0
- package/src/utils/ArrayUtils.ts +19 -5
- package/src/utils/CriteriaModel.ts +3 -5
- package/src/utils/DateUtils.ts +70 -6
- package/src/utils/ElementIDUtils.ts +52 -4
- package/src/utils/MaskFormatter.ts +103 -27
- package/src/utils/NumberUtils.ts +40 -36
- package/src/utils/ObjectUtils.ts +28 -0
- package/src/utils/ReadyUtil.ts +16 -0
- package/src/utils/StringUtils.ts +73 -29
- package/src/utils/TimeFormatter.ts +10 -10
- package/src/utils/UserAgentUtils/index.ts +12 -0
|
@@ -23,6 +23,9 @@ import { getSelection, hasNext, hasPrevious, SelectionReducer } from "./state/sl
|
|
|
23
23
|
import { getField, getMetadata, UnitMetadataReducer } from "./state/slice/UnitMetadataSlice.js";
|
|
24
24
|
import { getBlockingWaitingChanges, getWaitingChangePromisses, isWaiting, WaitingChangesReducer } from "./state/slice/WaitingChangesSlice.js";
|
|
25
25
|
import { canRedo, canUndo, HistReducer } from "./state/HistReducer.js";
|
|
26
|
+
/***
|
|
27
|
+
* `DataUnit`: Atua como uma camada de abstração entre o back-end e a interface do usuário.
|
|
28
|
+
*/
|
|
26
29
|
export default class DataUnit {
|
|
27
30
|
constructor(name) {
|
|
28
31
|
this._name = name;
|
|
@@ -44,14 +47,37 @@ export default class DataUnit {
|
|
|
44
47
|
this._sortingProvider = undefined;
|
|
45
48
|
this._interceptors = [];
|
|
46
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* Obtém o nome de identificação do DataUnit (geralmente em formato de URI - Uniform Resource Identifier).
|
|
53
|
+
*
|
|
54
|
+
* @returns - Nome de identificação do DataUnit.
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
47
57
|
get name() {
|
|
48
58
|
return this._name;
|
|
49
59
|
}
|
|
50
|
-
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* Obtém o valor convertido de acordo com o tipo do campo.
|
|
63
|
+
*
|
|
64
|
+
* @param fieldName - Identificador do campo.
|
|
65
|
+
* @param newValue - Novo valor que será atribuído ao campo pós validação.
|
|
66
|
+
*
|
|
67
|
+
* @returns - Novo valor convertido em um tipo valido.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
51
70
|
validateAndTypeValue(fieldName, newValue) {
|
|
52
71
|
const descriptor = this.getField(fieldName);
|
|
53
72
|
return descriptor ? convertType(descriptor.dataType, newValue) : newValue;
|
|
54
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* Obtém todos os filtros de dados.
|
|
77
|
+
*
|
|
78
|
+
* @returns - Lista de filtros.
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
55
81
|
getFilters() {
|
|
56
82
|
let filters = undefined;
|
|
57
83
|
this._filterProviders.forEach(p => {
|
|
@@ -62,15 +88,41 @@ export default class DataUnit {
|
|
|
62
88
|
});
|
|
63
89
|
return filters;
|
|
64
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* Obtém a estrutura de ordenação das colunas dos dados.
|
|
94
|
+
*
|
|
95
|
+
* @returns - Lista dos ordenáveis por prioridade.
|
|
96
|
+
*
|
|
97
|
+
*/
|
|
65
98
|
getSort() {
|
|
66
99
|
return this._sortingProvider ? this._sortingProvider.getSort(this._name) : undefined;
|
|
67
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* Obtém chave única para identificação do FilterProvider.
|
|
104
|
+
*
|
|
105
|
+
* @param provider - Interface FilterProvider na qual será retornada uma chave correspondente.
|
|
106
|
+
*
|
|
107
|
+
* @returns - A chave do provider.
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
68
110
|
getFielterProviderKey(provider) {
|
|
69
111
|
if (provider.getKey) {
|
|
70
112
|
return provider.getKey();
|
|
71
113
|
}
|
|
72
114
|
return StringUtils.hashCode(provider.getFilter.toString());
|
|
73
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* Executa o carregamento dos registros.
|
|
119
|
+
*
|
|
120
|
+
* @param request - Dados da requisição para carregamento dos registros.
|
|
121
|
+
* @param executionCtx - Contexto de execução do carregamento dos registros do DataUnit.
|
|
122
|
+
*
|
|
123
|
+
* @returns - Registros do DataUnit.
|
|
124
|
+
*
|
|
125
|
+
*/
|
|
74
126
|
executeLoadData(request, executionCtx) {
|
|
75
127
|
return new Promise((resolve, fail) => __awaiter(this, void 0, void 0, function* () {
|
|
76
128
|
if (yield this.dispatchAction(Action.LOADING_DATA, request, executionCtx)) {
|
|
@@ -87,6 +139,15 @@ export default class DataUnit {
|
|
|
87
139
|
}));
|
|
88
140
|
}
|
|
89
141
|
// Loaders
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
* Carrega os metadados do DataUnit.
|
|
145
|
+
*
|
|
146
|
+
* @param executionCtx - Contexto de execução do carregamento dos metadados do DataUnit.
|
|
147
|
+
*
|
|
148
|
+
* @returns - Metadados carregados.
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
90
151
|
loadMetadata(executionCtx) {
|
|
91
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
153
|
if (yield this.dispatchAction(Action.LOADING_METADATA, undefined, executionCtx)) {
|
|
@@ -104,6 +165,16 @@ export default class DataUnit {
|
|
|
104
165
|
}
|
|
105
166
|
});
|
|
106
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* Carrega os registros do DataUnit.
|
|
171
|
+
*
|
|
172
|
+
* @param quickFilter - Filtros a serem aplicados.
|
|
173
|
+
* @param executionCtx - Contexto de execução do carregamento dos registros.
|
|
174
|
+
*
|
|
175
|
+
* @returns - Registros requisitados.
|
|
176
|
+
*
|
|
177
|
+
*/
|
|
107
178
|
loadData(quickFilter, executionCtx) {
|
|
108
179
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
180
|
const loadDataRequest = {
|
|
@@ -118,6 +189,16 @@ export default class DataUnit {
|
|
|
118
189
|
return this.executeLoadData(loadDataRequest, executionCtx);
|
|
119
190
|
});
|
|
120
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
* Alterna entre os registros por número de página.
|
|
195
|
+
*
|
|
196
|
+
* @param page - Número da página desejada.
|
|
197
|
+
* @param executionCtx - Contexto de execução do carregamento dos registros do DataUnit.
|
|
198
|
+
*
|
|
199
|
+
* @returns - Registros da página desejada.
|
|
200
|
+
*
|
|
201
|
+
*/
|
|
121
202
|
gotoPage(page, executionCtx) {
|
|
122
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
204
|
let request = getCurrentRequest(this._stateManager);
|
|
@@ -132,16 +213,43 @@ export default class DataUnit {
|
|
|
132
213
|
}
|
|
133
214
|
});
|
|
134
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
*
|
|
218
|
+
* Vai para os registros da página seguinte.
|
|
219
|
+
*
|
|
220
|
+
* @param executionCtx - Contexto de execução do carregamento dos registros do DataUnit.
|
|
221
|
+
*
|
|
222
|
+
* @returns - Registros da página seguinte.
|
|
223
|
+
*
|
|
224
|
+
*/
|
|
135
225
|
nextPage(executionCtx) {
|
|
136
226
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
227
|
return this.gotoPage(getCurrentPage(this._stateManager) + 1, executionCtx);
|
|
138
228
|
});
|
|
139
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
*
|
|
232
|
+
* Vai para os registros da página anterior.
|
|
233
|
+
*
|
|
234
|
+
* @param executionCtx - Contexto de execução do carregamento dos registros do DataUnit.
|
|
235
|
+
*
|
|
236
|
+
* @returns - Registros da página anterior.
|
|
237
|
+
*
|
|
238
|
+
*/
|
|
140
239
|
previousPage(executionCtx) {
|
|
141
240
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
241
|
return this.gotoPage(getCurrentPage(this._stateManager) - 1, executionCtx);
|
|
143
242
|
});
|
|
144
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
*
|
|
246
|
+
* Salva o estado do registro do DataUnit.
|
|
247
|
+
*
|
|
248
|
+
* @param executionCtx - Contexto de execução da persistencia do registro do DataUnit.
|
|
249
|
+
*
|
|
250
|
+
* @returns - Resposta da solicitação.
|
|
251
|
+
*
|
|
252
|
+
*/
|
|
145
253
|
saveData(executionCtx) {
|
|
146
254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
255
|
const blockingWaitingChanges = getBlockingWaitingChanges(this._stateManager);
|
|
@@ -176,6 +284,15 @@ export default class DataUnit {
|
|
|
176
284
|
return Promise.resolve();
|
|
177
285
|
});
|
|
178
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
*
|
|
289
|
+
* Remove o registro selecionado.
|
|
290
|
+
*
|
|
291
|
+
* @param buffered - Se será utilizado buffer na solicitação.
|
|
292
|
+
*
|
|
293
|
+
* @returns - ID's dos registros removidos.
|
|
294
|
+
*
|
|
295
|
+
*/
|
|
179
296
|
removeSelectedRecords(buffered = false) {
|
|
180
297
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
298
|
const selection = getSelection(this._stateManager);
|
|
@@ -186,6 +303,18 @@ export default class DataUnit {
|
|
|
186
303
|
return Promise.resolve(selection);
|
|
187
304
|
});
|
|
188
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
*
|
|
308
|
+
* Efetua requisição para remoção dos registros.
|
|
309
|
+
*
|
|
310
|
+
* @param recordIds - Lista de IDs dos registros que serão removidos.
|
|
311
|
+
* @param cachedRecords - Dados dos registros que serão removidos.
|
|
312
|
+
* @param buffered - Se será utilizado buffer na solicitação.
|
|
313
|
+
* @param executionCtx - Contexto de execução da remoção do registro do DataUnit.
|
|
314
|
+
*
|
|
315
|
+
* @returns - ID's dos registros removidos.
|
|
316
|
+
*
|
|
317
|
+
*/
|
|
189
318
|
removeRecords(recordIds, cachedRecords, buffered = false, executionCtx) {
|
|
190
319
|
return __awaiter(this, void 0, void 0, function* () {
|
|
191
320
|
if (recordIds) {
|
|
@@ -221,70 +350,216 @@ export default class DataUnit {
|
|
|
221
350
|
});
|
|
222
351
|
}
|
|
223
352
|
// API
|
|
353
|
+
/**
|
|
354
|
+
*
|
|
355
|
+
* Obtém o valor do campo em seu formato/tipo correto a partir de uma string.
|
|
356
|
+
*
|
|
357
|
+
* @param fieldName - Nome do campo que terá o tipo identificado para conversão.
|
|
358
|
+
* @param value - Texto que será convertido de acordo com o tipo identificado no campo.
|
|
359
|
+
*
|
|
360
|
+
* @returns - Valor convertido ou ele mesmo.
|
|
361
|
+
*
|
|
362
|
+
*/
|
|
224
363
|
valueFromString(fieldName, value) {
|
|
225
364
|
const descriptor = this.getField(fieldName);
|
|
226
365
|
return descriptor ? convertType(descriptor.dataType, value) : value;
|
|
227
366
|
}
|
|
367
|
+
/**
|
|
368
|
+
*
|
|
369
|
+
* Converte o valor informado para texto de acordo com o tipo do campo informado.
|
|
370
|
+
*
|
|
371
|
+
* @param fieldName - Nome do campo utilizado para buscar o tipo de dado com o padrão de conversão para string.
|
|
372
|
+
* @param value - Valor a ser convertido.
|
|
373
|
+
*
|
|
374
|
+
* @returns - Valor informado convertido.
|
|
375
|
+
*
|
|
376
|
+
*/
|
|
228
377
|
valueToString(fieldName, value) {
|
|
229
378
|
const descriptor = this.getField(fieldName);
|
|
230
379
|
return toString(descriptor === null || descriptor === void 0 ? void 0 : descriptor.dataType, value);
|
|
231
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
*
|
|
383
|
+
* Adiciona um interceptor correspondente a uma ação do DataUnit para fazer um processamento customizado.
|
|
384
|
+
*
|
|
385
|
+
* @param interceptor - Interceptor a ser adicionado.
|
|
386
|
+
*
|
|
387
|
+
*/
|
|
232
388
|
addInterceptor(interceptor) {
|
|
233
389
|
this._interceptors.push(interceptor);
|
|
234
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
*
|
|
393
|
+
* Remove um interceptor da lista de interceptors.
|
|
394
|
+
*
|
|
395
|
+
* @param interceptor - Interceptor a ser removido.
|
|
396
|
+
*
|
|
397
|
+
*/
|
|
235
398
|
removeInterceptor(interceptor) {
|
|
236
399
|
this._interceptors = this._interceptors.filter(i => i !== interceptor);
|
|
237
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
*
|
|
403
|
+
* Adiciona um FilterProvider.
|
|
404
|
+
*
|
|
405
|
+
* @param provider - FilterProvider que será adicionado.
|
|
406
|
+
*
|
|
407
|
+
*/
|
|
238
408
|
addFilterProvider(provider) {
|
|
239
409
|
this._filterProviders.set(this.getFielterProviderKey(provider), provider);
|
|
240
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
*
|
|
413
|
+
* Obtém informações de paginação dos registros.
|
|
414
|
+
*
|
|
415
|
+
* @returns - Informações da paginação de registros.
|
|
416
|
+
*/
|
|
241
417
|
getPaginationInfo() {
|
|
242
418
|
return getPaginationInfo(this._stateManager);
|
|
243
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
*
|
|
422
|
+
* Define a lógica de ordenação dos registros.
|
|
423
|
+
*
|
|
424
|
+
* @param provider - Objeto usado para definir a propriedade sortingProvider da instância da classe.
|
|
425
|
+
*
|
|
426
|
+
*/
|
|
244
427
|
set sortingProvider(provider) {
|
|
245
428
|
this._sortingProvider = provider;
|
|
246
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
*
|
|
432
|
+
* Define a propriedade metadata 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.
|
|
433
|
+
*
|
|
434
|
+
*/
|
|
247
435
|
set metadata(md) {
|
|
248
436
|
this.dispatchAction(Action.METADATA_LOADED, md, undefined);
|
|
249
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
*
|
|
440
|
+
* Obtém os metadados do DataUnit.
|
|
441
|
+
*
|
|
442
|
+
*/
|
|
250
443
|
get metadata() {
|
|
251
444
|
return getMetadata(this._stateManager);
|
|
252
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
*
|
|
448
|
+
* 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.
|
|
449
|
+
*
|
|
450
|
+
*/
|
|
253
451
|
set records(r) {
|
|
254
452
|
this.dispatchAction(Action.DATA_LOADED, { records: this.records }, undefined);
|
|
255
453
|
}
|
|
454
|
+
/**
|
|
455
|
+
*
|
|
456
|
+
* Obtém todos os registros atuais.
|
|
457
|
+
*
|
|
458
|
+
* @returns - Todos os registros atuais.
|
|
459
|
+
*
|
|
460
|
+
*/
|
|
256
461
|
get records() {
|
|
257
462
|
const records = getCurrentRecords(this._stateManager);
|
|
258
463
|
return records ? Array.from(records.values()) : [];
|
|
259
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
*
|
|
467
|
+
* Define a quantidade de registros que será exibido por página.
|
|
468
|
+
*
|
|
469
|
+
* @param size - Quantidade de registros que será exibido por página.
|
|
470
|
+
*
|
|
471
|
+
*/
|
|
260
472
|
set pageSize(size) {
|
|
261
473
|
this._pageSize = size;
|
|
262
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
*
|
|
477
|
+
* Obtém a quantidade de registros que está sendo exibido por página.
|
|
478
|
+
*
|
|
479
|
+
* @returns - Quantidade de registros exibidos por página.
|
|
480
|
+
*
|
|
481
|
+
*/
|
|
263
482
|
get pageSize() {
|
|
264
483
|
return this._pageSize;
|
|
265
484
|
}
|
|
485
|
+
/**
|
|
486
|
+
*
|
|
487
|
+
* Obtém os registros modificados e ainda não salvos no DataUnit.
|
|
488
|
+
*
|
|
489
|
+
* @returns - Lista dos registros em edição.
|
|
490
|
+
*
|
|
491
|
+
*/
|
|
266
492
|
getModifiedRecords() {
|
|
267
493
|
const modified = getModifiedRecords(this._stateManager);
|
|
268
494
|
return modified || [];
|
|
269
495
|
}
|
|
496
|
+
/**
|
|
497
|
+
*
|
|
498
|
+
* Obtém metadados de um campo específico.
|
|
499
|
+
*
|
|
500
|
+
* @param fieldName - Identificador do campo.
|
|
501
|
+
*
|
|
502
|
+
* @returns - Metadados do campo informado.
|
|
503
|
+
*/
|
|
270
504
|
getField(fieldName) {
|
|
271
505
|
return getField(this._stateManager, fieldName);
|
|
272
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
*
|
|
509
|
+
* Adiciona um novo registro.
|
|
510
|
+
*
|
|
511
|
+
* @param executionCtx - Contexto de execução da inserção do dado no DataUnit.
|
|
512
|
+
*
|
|
513
|
+
*/
|
|
273
514
|
addRecord(executionCtx) {
|
|
274
515
|
this.dispatchAction(Action.RECORDS_ADDED, prepareAddedRecordId(this._stateManager, [{}]), executionCtx);
|
|
275
516
|
}
|
|
517
|
+
/**
|
|
518
|
+
*
|
|
519
|
+
* Efetua a cópia do registro selecionado.
|
|
520
|
+
*
|
|
521
|
+
* @param executionCtx - Contexto de execução da cópia do dado do DataUnit.
|
|
522
|
+
*
|
|
523
|
+
*/
|
|
276
524
|
copySelected(executionCtx) {
|
|
277
525
|
const selectedRecords = this.getSelectedRecords();
|
|
278
526
|
if (selectedRecords) {
|
|
279
527
|
this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords), executionCtx);
|
|
280
528
|
}
|
|
281
529
|
}
|
|
530
|
+
/**
|
|
531
|
+
*
|
|
532
|
+
* Retorna se a alteração no campo já foi concluída ou se ainda está incompleta.
|
|
533
|
+
*
|
|
534
|
+
* @param fieldName - Identificador do campo a ser verificado.
|
|
535
|
+
*
|
|
536
|
+
* @returns - Verdadeiro se ainda está pendente.
|
|
537
|
+
*
|
|
538
|
+
*/
|
|
282
539
|
waitingForChange(fieldName) {
|
|
283
540
|
return isWaiting(this._stateManager, fieldName);
|
|
284
541
|
}
|
|
542
|
+
/**
|
|
543
|
+
*
|
|
544
|
+
* Obtém valor do campo desejado.
|
|
545
|
+
*
|
|
546
|
+
* @param fieldName - Identificador do campo a ser buscado.
|
|
547
|
+
*
|
|
548
|
+
* @returns - Valor do campo.
|
|
549
|
+
*
|
|
550
|
+
*/
|
|
285
551
|
getFieldValue(fieldName) {
|
|
286
552
|
return getFieldValue(this._stateManager, fieldName);
|
|
287
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
*
|
|
556
|
+
* Insere valor no campo desejado.
|
|
557
|
+
*
|
|
558
|
+
* @param fieldName -Identificador do campo a ser modificado.
|
|
559
|
+
* @param newValue - Valor a ser inserido no campo.
|
|
560
|
+
* @param records - Indica quais registros foram afetados pela alteração no valor do campo.
|
|
561
|
+
*
|
|
562
|
+
*/
|
|
288
563
|
setFieldValue(fieldName, newValue, records) {
|
|
289
564
|
const typedValue = this.validateAndTypeValue(fieldName, newValue);
|
|
290
565
|
const currentValue = this.getFieldValue(fieldName);
|
|
@@ -292,31 +567,90 @@ export default class DataUnit {
|
|
|
292
567
|
this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records }, undefined);
|
|
293
568
|
}
|
|
294
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
*
|
|
572
|
+
* Inicia alteração no campo.
|
|
573
|
+
*
|
|
574
|
+
* @param fieldName - Identificador do campo a ser modificado.
|
|
575
|
+
* @param waitingChange - Informa que uma mudança irá iniciar.
|
|
576
|
+
*
|
|
577
|
+
*/
|
|
295
578
|
startChange(fieldName, waitingChange) {
|
|
296
579
|
this.dispatchAction(Action.CHANGING_DATA, { [fieldName]: waitingChange }, undefined);
|
|
297
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
*
|
|
583
|
+
* Cancela o início de uma alteração no campo.
|
|
584
|
+
*
|
|
585
|
+
* @param fieldName - Identificador do campo.
|
|
586
|
+
*
|
|
587
|
+
*/
|
|
298
588
|
cancelWaitingChange(fieldName) {
|
|
299
589
|
this.dispatchAction(Action.WAITING_CHANGE_CANCELED, { fieldName }, undefined);
|
|
300
590
|
}
|
|
591
|
+
/**
|
|
592
|
+
*
|
|
593
|
+
* Obtém registros selecionados.
|
|
594
|
+
*
|
|
595
|
+
* @returns - Registros selecionados.
|
|
596
|
+
*
|
|
597
|
+
*/
|
|
301
598
|
getSelection() {
|
|
302
599
|
return getSelection(this._stateManager);
|
|
303
600
|
}
|
|
601
|
+
/**
|
|
602
|
+
*
|
|
603
|
+
* Seleciona múltiplos registros por ID.
|
|
604
|
+
*
|
|
605
|
+
* @param selection - IDs para selecionar.
|
|
606
|
+
* @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
|
|
607
|
+
*
|
|
608
|
+
*/
|
|
304
609
|
setSelection(selection, executionCtx) {
|
|
305
610
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }, executionCtx);
|
|
306
611
|
}
|
|
612
|
+
/**
|
|
613
|
+
*
|
|
614
|
+
* Seleciona o primeiro registro.
|
|
615
|
+
*
|
|
616
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
617
|
+
*
|
|
618
|
+
*/
|
|
307
619
|
selectFirst(executionCtx) {
|
|
308
620
|
if (this.records.length > 0) {
|
|
309
621
|
this.setSelectionByIndex([0], executionCtx);
|
|
310
622
|
}
|
|
311
623
|
}
|
|
624
|
+
/**
|
|
625
|
+
*
|
|
626
|
+
* Seleciona o último registro.
|
|
627
|
+
*
|
|
628
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
629
|
+
*
|
|
630
|
+
*/
|
|
312
631
|
selectLast(executionCtx) {
|
|
313
632
|
if (this.records.length > 0) {
|
|
314
633
|
this.setSelectionByIndex([this.records.length - 1], executionCtx);
|
|
315
634
|
}
|
|
316
635
|
}
|
|
636
|
+
/**
|
|
637
|
+
*
|
|
638
|
+
* Seleciona múltiplos registros por índice.
|
|
639
|
+
*
|
|
640
|
+
* @param selection - Índices desejados para a seleção.
|
|
641
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
642
|
+
*
|
|
643
|
+
*/
|
|
317
644
|
setSelectionByIndex(selection, executionCtx) {
|
|
318
645
|
this.dispatchAction(Action.SELECTION_CHANGED, { type: "index", selection }, executionCtx);
|
|
319
646
|
}
|
|
647
|
+
/**
|
|
648
|
+
*
|
|
649
|
+
* Obtém todos os registros selecionados.
|
|
650
|
+
*
|
|
651
|
+
* @returns - Lista de registros selecionados.
|
|
652
|
+
*
|
|
653
|
+
*/
|
|
320
654
|
getSelectedRecords() {
|
|
321
655
|
const selection = this.getSelection();
|
|
322
656
|
if (selection) {
|
|
@@ -324,6 +658,14 @@ export default class DataUnit {
|
|
|
324
658
|
return currentRecords === null || currentRecords === void 0 ? void 0 : currentRecords.filter(r => selection.includes(r.__record__id__));
|
|
325
659
|
}
|
|
326
660
|
}
|
|
661
|
+
/**
|
|
662
|
+
*
|
|
663
|
+
* Seleciona o próximo registro.
|
|
664
|
+
*
|
|
665
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
666
|
+
*
|
|
667
|
+
*
|
|
668
|
+
*/
|
|
327
669
|
nextRecord(executionCtx) {
|
|
328
670
|
if (!hasNext(this._stateManager)) {
|
|
329
671
|
if (hasMorePages(this._stateManager)) {
|
|
@@ -344,6 +686,13 @@ export default class DataUnit {
|
|
|
344
686
|
this.dispatchAction(Action.NEXT_SELECTED, undefined, executionCtx);
|
|
345
687
|
}
|
|
346
688
|
}
|
|
689
|
+
/**
|
|
690
|
+
*
|
|
691
|
+
* Seleciona o registro anterior.
|
|
692
|
+
*
|
|
693
|
+
* @param executionCtx - Contexto de execução da seleção do registro do DataUnit.
|
|
694
|
+
*
|
|
695
|
+
*/
|
|
347
696
|
previousRecord(executionCtx) {
|
|
348
697
|
if (!hasPrevious(this._stateManager)) {
|
|
349
698
|
if (hasPreviousPages(this._stateManager)) {
|
|
@@ -364,15 +713,43 @@ export default class DataUnit {
|
|
|
364
713
|
this.dispatchAction(Action.PREVIOUS_SELECTED, undefined, executionCtx);
|
|
365
714
|
}
|
|
366
715
|
}
|
|
716
|
+
/**
|
|
717
|
+
*
|
|
718
|
+
* Cancela edição do registro atual.
|
|
719
|
+
*
|
|
720
|
+
* @param executionCtx - Contexto de execução do cancelamento da seleção dos registros.
|
|
721
|
+
*
|
|
722
|
+
*/
|
|
367
723
|
cancelEdition(executionCtx) {
|
|
368
724
|
this.dispatchAction(Action.EDITION_CANCELED, undefined, executionCtx);
|
|
369
725
|
}
|
|
726
|
+
/**
|
|
727
|
+
*
|
|
728
|
+
* Retorna se existe algum tipo de alteração pendente.
|
|
729
|
+
*
|
|
730
|
+
* @returns Verdadeiro se existir alterações pendentes.
|
|
731
|
+
*
|
|
732
|
+
*/
|
|
370
733
|
isDirty() {
|
|
371
734
|
return isDirty(this._stateManager);
|
|
372
735
|
}
|
|
736
|
+
/**
|
|
737
|
+
*
|
|
738
|
+
* Retorna se existe algum registro em modo de edição.
|
|
739
|
+
*
|
|
740
|
+
* @returns Verdadeiro se existir alterações de registros pendentes.
|
|
741
|
+
*
|
|
742
|
+
*/
|
|
373
743
|
hasDirtyRecords() {
|
|
374
744
|
return hasDirtyRecords(this._stateManager);
|
|
375
745
|
}
|
|
746
|
+
/**
|
|
747
|
+
*
|
|
748
|
+
* Retorna se existir uma pagina seguinte a atual na paginação.
|
|
749
|
+
*
|
|
750
|
+
* @returns Verdadeiro se existir uma próxima página.
|
|
751
|
+
*
|
|
752
|
+
*/
|
|
376
753
|
hasNext() {
|
|
377
754
|
let result = hasNext(this._stateManager);
|
|
378
755
|
if (!result) {
|
|
@@ -380,6 +757,13 @@ export default class DataUnit {
|
|
|
380
757
|
}
|
|
381
758
|
return result;
|
|
382
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
*
|
|
762
|
+
* Retorna se existe uma página anterior a atual na paginação.
|
|
763
|
+
*
|
|
764
|
+
* @returns Verdadeiro se existir uma página anterior.
|
|
765
|
+
*
|
|
766
|
+
*/
|
|
383
767
|
hasPrevious() {
|
|
384
768
|
let result = hasPrevious(this._stateManager);
|
|
385
769
|
if (!result) {
|
|
@@ -387,22 +771,69 @@ export default class DataUnit {
|
|
|
387
771
|
}
|
|
388
772
|
return result;
|
|
389
773
|
}
|
|
774
|
+
/**
|
|
775
|
+
*
|
|
776
|
+
* Retorna se a informação do estado anterior está salva, permitindo desfazer a ação.
|
|
777
|
+
*
|
|
778
|
+
* @returns Verdadeiro se for possível desfazer a ação.
|
|
779
|
+
*
|
|
780
|
+
*/
|
|
390
781
|
canUndo() {
|
|
391
782
|
return canUndo(this._stateManager);
|
|
392
783
|
}
|
|
784
|
+
/**
|
|
785
|
+
*
|
|
786
|
+
* Retorna se a informação do estado futuro está salva, permitindo refazer a ação.
|
|
787
|
+
*
|
|
788
|
+
* @returns Verdadeiro se for possível refazer a ação.
|
|
789
|
+
*
|
|
790
|
+
*/
|
|
393
791
|
canRedo() {
|
|
394
792
|
return canRedo(this._stateManager);
|
|
395
793
|
}
|
|
794
|
+
/**
|
|
795
|
+
*
|
|
796
|
+
* Desfaz a última ação.
|
|
797
|
+
*
|
|
798
|
+
* @param executionCtx - Contexto de execução de desfazer a última ação.
|
|
799
|
+
*
|
|
800
|
+
*
|
|
801
|
+
*/
|
|
396
802
|
undo(executionCtx) {
|
|
397
803
|
this.dispatchAction(Action.CHANGE_UNDONE, undefined, executionCtx);
|
|
398
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
*
|
|
807
|
+
* Refaz a última ação.
|
|
808
|
+
*
|
|
809
|
+
* @param executionCtx - Contexto de execução de refazer a última ação.
|
|
810
|
+
*
|
|
811
|
+
*/
|
|
399
812
|
redo(executionCtx) {
|
|
400
813
|
this.dispatchAction(Action.CHANGE_REDONE, undefined, executionCtx);
|
|
401
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
*
|
|
817
|
+
* Obtém a representação textual do DataUnit, nesse caso, o nome do DataUnit.
|
|
818
|
+
*
|
|
819
|
+
* @returns - Valor contido na propriedade name.
|
|
820
|
+
*
|
|
821
|
+
*/
|
|
402
822
|
toString() {
|
|
403
823
|
return this.name;
|
|
404
824
|
}
|
|
405
825
|
// Actions / State manager
|
|
826
|
+
/**
|
|
827
|
+
*
|
|
828
|
+
* Lança ação do DataUnit para que sejam processadas.
|
|
829
|
+
*
|
|
830
|
+
* @param actionType - Tipo de ação que será executada.
|
|
831
|
+
* @param payload - Dados que serão processados na ação.
|
|
832
|
+
* @param executionCtx - Contexto de execução de lançar a ação que será executada.
|
|
833
|
+
*
|
|
834
|
+
* @returns - Verdadeiro se ação iniciada.
|
|
835
|
+
*
|
|
836
|
+
*/
|
|
406
837
|
dispatchAction(actionType, payload, executionCtx) {
|
|
407
838
|
return __awaiter(this, void 0, void 0, function* () {
|
|
408
839
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -426,6 +857,16 @@ export default class DataUnit {
|
|
|
426
857
|
}));
|
|
427
858
|
});
|
|
428
859
|
}
|
|
860
|
+
/**
|
|
861
|
+
*
|
|
862
|
+
* Notifica os interceptors de que uma ação foi executada, para que cada interceptor possa fazer sua respectiva tratativa dos dados.
|
|
863
|
+
*
|
|
864
|
+
* @param action - Ação que foi executada.
|
|
865
|
+
* @param interceptors - Interceptors que serão notificados.
|
|
866
|
+
*
|
|
867
|
+
* @returns - Ação executada no DataUnit.
|
|
868
|
+
*
|
|
869
|
+
*/
|
|
429
870
|
intercept(action, interceptors) {
|
|
430
871
|
return __awaiter(this, void 0, void 0, function* () {
|
|
431
872
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -437,6 +878,13 @@ export default class DataUnit {
|
|
|
437
878
|
}));
|
|
438
879
|
});
|
|
439
880
|
}
|
|
881
|
+
/**
|
|
882
|
+
*
|
|
883
|
+
* Processa as ações no DataUnit e notifica os observers.
|
|
884
|
+
*
|
|
885
|
+
* @param action - Ações em execução no DataUnit.
|
|
886
|
+
*
|
|
887
|
+
*/
|
|
440
888
|
doDispatchAction(action) {
|
|
441
889
|
this._stateManager.process(action);
|
|
442
890
|
this._observers.forEach(f => {
|
|
@@ -452,12 +900,34 @@ export default class DataUnit {
|
|
|
452
900
|
}
|
|
453
901
|
});
|
|
454
902
|
}
|
|
903
|
+
/**
|
|
904
|
+
*
|
|
905
|
+
* Adiciona um novo observer no DataUnit.
|
|
906
|
+
* Ela vai ser chamada sempre que uma ação for despachada (dispatchAction()).
|
|
907
|
+
*
|
|
908
|
+
* @param observer - Função que recebe como parâmetro as ações que serão monitoradas.
|
|
909
|
+
*
|
|
910
|
+
*/
|
|
455
911
|
subscribe(observer) {
|
|
456
912
|
this._observers.push(observer);
|
|
457
913
|
}
|
|
914
|
+
/**
|
|
915
|
+
*
|
|
916
|
+
* Remove um observer existente.
|
|
917
|
+
*
|
|
918
|
+
* @param observer - Observer que se deseja remover.
|
|
919
|
+
*
|
|
920
|
+
*/
|
|
458
921
|
unsubscribe(observer) {
|
|
459
922
|
this._observers = this._observers.filter(f => f !== observer);
|
|
460
923
|
}
|
|
924
|
+
/**
|
|
925
|
+
*
|
|
926
|
+
* Recarrega registro selecionado com dados atualizados do servidor.
|
|
927
|
+
*
|
|
928
|
+
* @returns - Dados atualizados do registro selecionado.
|
|
929
|
+
*
|
|
930
|
+
*/
|
|
461
931
|
reloadCurrentRecord() {
|
|
462
932
|
return new Promise((resolve, fail) => __awaiter(this, void 0, void 0, function* () {
|
|
463
933
|
const selection = this.getSelection();
|
|
@@ -482,26 +952,64 @@ export var ChangeOperation;
|
|
|
482
952
|
ChangeOperation["UPDATE"] = "UPDATE";
|
|
483
953
|
ChangeOperation["DELETE"] = "DELETE";
|
|
484
954
|
})(ChangeOperation || (ChangeOperation = {}));
|
|
955
|
+
/***
|
|
956
|
+
* `Change`: Dados que representam uma alteração.
|
|
957
|
+
*/
|
|
485
958
|
export class Change {
|
|
486
|
-
constructor(
|
|
487
|
-
this.
|
|
959
|
+
constructor(DataUnit, record, updates, operation, sourceId) {
|
|
960
|
+
this.DataUnit = DataUnit;
|
|
488
961
|
this.record = record;
|
|
489
962
|
this.sourceId = sourceId;
|
|
490
963
|
this.updatingFields = updates;
|
|
491
964
|
this._operation = operation;
|
|
492
965
|
}
|
|
966
|
+
/**
|
|
967
|
+
*
|
|
968
|
+
* Obtém o tipo de operação que está sendo realizada.
|
|
969
|
+
*
|
|
970
|
+
* @returns - Ação que está sendo executada.
|
|
971
|
+
*
|
|
972
|
+
*/
|
|
493
973
|
get operation() {
|
|
494
974
|
return this._operation.toString();
|
|
495
975
|
}
|
|
976
|
+
/**
|
|
977
|
+
*
|
|
978
|
+
* Retorna se o DataUnit está em uma operação de inserção.
|
|
979
|
+
*
|
|
980
|
+
* @returns - Verdadeiro se a operação for de inserção.
|
|
981
|
+
*
|
|
982
|
+
*/
|
|
496
983
|
isInsert() {
|
|
497
984
|
return this._operation === ChangeOperation.INSERT;
|
|
498
985
|
}
|
|
986
|
+
/**
|
|
987
|
+
*
|
|
988
|
+
* Retorna se o DataUnit está em uma operação de cópia.
|
|
989
|
+
*
|
|
990
|
+
* @returns - Verdadeiro se a operação for de cópia.
|
|
991
|
+
*
|
|
992
|
+
*/
|
|
499
993
|
isCopy() {
|
|
500
994
|
return this._operation === ChangeOperation.COPY;
|
|
501
995
|
}
|
|
996
|
+
/**
|
|
997
|
+
*
|
|
998
|
+
* Retorna se o DataUnit está em uma operação de deleção.
|
|
999
|
+
*
|
|
1000
|
+
* @returns - Verdadeiro se a operação for de deleção.
|
|
1001
|
+
*
|
|
1002
|
+
*/
|
|
502
1003
|
isDelete() {
|
|
503
1004
|
return this._operation === ChangeOperation.DELETE;
|
|
504
1005
|
}
|
|
1006
|
+
/**
|
|
1007
|
+
*
|
|
1008
|
+
* Retorna se o DataUnit está em uma operação de atualização.
|
|
1009
|
+
*
|
|
1010
|
+
* @returns - Verdadeiro se a operação for de atualização.
|
|
1011
|
+
*
|
|
1012
|
+
*/
|
|
505
1013
|
isUpdate() {
|
|
506
1014
|
return this._operation === ChangeOperation.UPDATE;
|
|
507
1015
|
}
|