@sankhyalabs/core 5.20.0-dev.5 → 5.20.0-dev.50

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.
Files changed (179) hide show
  1. package/.docs/README.md +3 -1
  2. package/.docs/classes/ApplicationContext.md +31 -32
  3. package/.docs/classes/ArrayUtils.md +95 -83
  4. package/.docs/classes/AuthorizedServiceCaller.md +25 -34
  5. package/.docs/classes/Change.md +59 -74
  6. package/.docs/classes/DataUnit.md +1180 -1086
  7. package/.docs/classes/DataUnitAction.md +25 -42
  8. package/.docs/classes/DataUnitStorage.md +40 -43
  9. package/.docs/classes/DateUtils.md +140 -133
  10. package/.docs/classes/ElementIDUtils.md +123 -122
  11. package/.docs/classes/ErrorException.md +67 -88
  12. package/.docs/classes/ErrorTracking.md +20 -23
  13. package/.docs/classes/FieldComparator.md +35 -39
  14. package/.docs/classes/FloatingManager.md +195 -198
  15. package/.docs/classes/HTMLBuilder.md +14 -20
  16. package/.docs/classes/HttpProvider.md +45 -41
  17. package/.docs/classes/IDBRepository.md +201 -196
  18. package/.docs/classes/JSUtils.md +65 -66
  19. package/.docs/classes/KeyboardManager.md +95 -87
  20. package/.docs/classes/{MaskFormatter-1.md → MaskFormatter.md} +93 -128
  21. package/.docs/classes/NumberUtils.md +163 -152
  22. package/.docs/classes/ObjectUtils.md +206 -70
  23. package/.docs/classes/OnboardingUtils.md +36 -51
  24. package/.docs/classes/OverflowWatcher.md +533 -0
  25. package/.docs/classes/PromiseSync.md +25 -42
  26. package/.docs/classes/ReadyUtil.md +31 -41
  27. package/.docs/classes/RequestMetadata.md +29 -30
  28. package/.docs/classes/SearchUtils.md +18 -20
  29. package/.docs/classes/SelectionInfo.md +73 -74
  30. package/.docs/classes/ServiceCanceledException.md +193 -0
  31. package/.docs/classes/SkwHttpProvider.md +33 -45
  32. package/.docs/classes/StringUtils.md +297 -322
  33. package/.docs/classes/TimeFormatter.md +43 -44
  34. package/.docs/classes/UserAgentUtils.md +17 -20
  35. package/.docs/classes/VersionUtils.md +15 -18
  36. package/.docs/classes/WaitingChangeException.md +63 -84
  37. package/.docs/classes/WarningException.md +67 -88
  38. package/.docs/enumerations/Action.md +317 -0
  39. package/.docs/enumerations/ChangeOperation.md +47 -0
  40. package/.docs/enumerations/DataType.md +57 -0
  41. package/.docs/enumerations/DependencyType.md +37 -0
  42. package/.docs/enumerations/OverflowDirection.md +29 -0
  43. package/.docs/enumerations/SelectionMode.md +27 -0
  44. package/.docs/enumerations/SortMode.md +27 -0
  45. package/.docs/enumerations/UserInterface.md +177 -0
  46. package/.docs/functions/defaultDataLoader.md +25 -0
  47. package/.docs/{modules.md → globals.md} +27 -36
  48. package/.docs/interfaces/ChildDescriptor.md +12 -16
  49. package/.docs/interfaces/ChildLink.md +9 -12
  50. package/.docs/interfaces/DUActionInterceptor.md +10 -14
  51. package/.docs/interfaces/ExecutionContext.md +17 -32
  52. package/.docs/interfaces/FieldDescriptor.md +52 -66
  53. package/.docs/interfaces/Filter.md +13 -17
  54. package/.docs/interfaces/IElementIDInfo.md +11 -14
  55. package/.docs/interfaces/ILoadResult.md +11 -16
  56. package/.docs/interfaces/IRepository.md +106 -93
  57. package/.docs/interfaces/IRepositoryIndex.md +23 -30
  58. package/.docs/interfaces/LoadDataRequest.md +36 -45
  59. package/.docs/interfaces/LoadDataResponse.md +11 -14
  60. package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
  61. package/.docs/interfaces/PageRequest.md +16 -20
  62. package/.docs/interfaces/PaginationInfo.md +24 -31
  63. package/.docs/interfaces/PromiseSyncCallback.md +13 -17
  64. package/.docs/interfaces/QuickFilter.md +17 -21
  65. package/.docs/interfaces/Record.md +26 -33
  66. package/.docs/interfaces/SavedRecord.md +33 -41
  67. package/.docs/interfaces/Sort.md +12 -16
  68. package/.docs/interfaces/SortingProvider.md +10 -13
  69. package/.docs/interfaces/UnitMetadata.md +16 -21
  70. package/.docs/interfaces/WaitingChange.md +16 -20
  71. package/.docs/namespaces/MaskFormatter/README.md +17 -0
  72. package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +13 -0
  73. package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +13 -0
  74. package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
  75. package/.docs/type-aliases/OnOverflowCallBack.md +25 -0
  76. package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
  77. package/dist/dataunit/DataUnit.d.ts +67 -6
  78. package/dist/dataunit/DataUnit.js +151 -32
  79. package/dist/dataunit/DataUnit.js.map +1 -1
  80. package/dist/dataunit/DataUnitHelper.js +6 -5
  81. package/dist/dataunit/DataUnitHelper.js.map +1 -1
  82. package/dist/dataunit/formatting/PrettyFormatter.js +8 -6
  83. package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
  84. package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
  85. package/dist/dataunit/metadata/DataType.js +13 -1
  86. package/dist/dataunit/metadata/DataType.js.map +1 -1
  87. package/dist/dataunit/state/action/DataUnitAction.d.ts +5 -1
  88. package/dist/dataunit/state/action/DataUnitAction.js +4 -0
  89. package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
  90. package/dist/dataunit/state/slice/ChangesSlice.js +12 -11
  91. package/dist/dataunit/state/slice/ChangesSlice.js.map +1 -1
  92. package/dist/dataunit/state/slice/InvalidFieldsSlice.js +2 -0
  93. package/dist/dataunit/state/slice/InvalidFieldsSlice.js.map +1 -1
  94. package/dist/dataunit/state/slice/LoadingProperties.d.ts +9 -0
  95. package/dist/dataunit/state/slice/LoadingProperties.js +31 -0
  96. package/dist/dataunit/state/slice/LoadingProperties.js.map +1 -0
  97. package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
  98. package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
  99. package/dist/dataunit/state/slice/SelectionSlice.js +4 -4
  100. package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
  101. package/dist/exceptions/ServiceCanceledException.d.ts +14 -0
  102. package/dist/exceptions/ServiceCanceledException.js +13 -0
  103. package/dist/exceptions/ServiceCanceledException.js.map +1 -0
  104. package/dist/index.d.ts +4 -2
  105. package/dist/index.js +3 -1
  106. package/dist/index.js.map +1 -1
  107. package/dist/repository/IRepository.d.ts +6 -0
  108. package/dist/repository/indexeddb/IDBRepository.d.ts +1 -0
  109. package/dist/repository/indexeddb/IDBRepository.js +3 -0
  110. package/dist/repository/indexeddb/IDBRepository.js.map +1 -1
  111. package/dist/utils/DateUtils.js +3 -0
  112. package/dist/utils/DateUtils.js.map +1 -1
  113. package/dist/utils/ElementUtils.d.ts +2 -0
  114. package/dist/utils/ElementUtils.js +9 -0
  115. package/dist/utils/ElementUtils.js.map +1 -0
  116. package/dist/utils/MaskFormatter.d.ts +2 -1
  117. package/dist/utils/MaskFormatter.js +5 -1
  118. package/dist/utils/MaskFormatter.js.map +1 -1
  119. package/dist/utils/ObjectUtils.d.ts +38 -0
  120. package/dist/utils/ObjectUtils.js +51 -0
  121. package/dist/utils/ObjectUtils.js.map +1 -1
  122. package/dist/utils/OnboardingUtils.js +1 -1
  123. package/dist/utils/OnboardingUtils.js.map +1 -1
  124. package/dist/utils/OverflowWatcher/index.d.ts +59 -0
  125. package/dist/utils/OverflowWatcher/index.js +188 -0
  126. package/dist/utils/OverflowWatcher/index.js.map +1 -0
  127. package/dist/utils/OverflowWatcher/types/overflow-callback.d.ts +6 -0
  128. package/dist/utils/OverflowWatcher/types/overflow-callback.js +2 -0
  129. package/dist/utils/OverflowWatcher/types/overflow-callback.js.map +1 -0
  130. package/dist/utils/OverflowWatcher/types/overflow-direction.d.ts +7 -0
  131. package/dist/utils/OverflowWatcher/types/overflow-direction.js +9 -0
  132. package/dist/utils/OverflowWatcher/types/overflow-direction.js.map +1 -0
  133. package/dist/utils/SortingUtils.d.ts +9 -0
  134. package/dist/utils/SortingUtils.js +24 -0
  135. package/dist/utils/SortingUtils.js.map +1 -0
  136. package/jest.config.ts +3 -1
  137. package/package.json +12 -4
  138. package/reports/test-report.xml +175 -0
  139. package/setupTests.js +7 -0
  140. package/sonar-project.properties +10 -0
  141. package/src/dataunit/DataUnit.ts +179 -46
  142. package/src/dataunit/DataUnitHelper.ts +6 -5
  143. package/src/dataunit/formatting/PrettyFormatter.ts +7 -6
  144. package/src/dataunit/loading/LoadDataRequest.ts +1 -1
  145. package/src/dataunit/metadata/DataType.ts +13 -1
  146. package/src/dataunit/state/action/DataUnitAction.ts +5 -1
  147. package/src/dataunit/state/slice/ChangesSlice.ts +15 -14
  148. package/src/dataunit/state/slice/InvalidFieldsSlice.ts +2 -0
  149. package/src/dataunit/state/slice/LoadingProperties.ts +37 -0
  150. package/src/dataunit/state/slice/RecordsSlice.ts +1 -1
  151. package/src/dataunit/state/slice/SelectionSlice.ts +4 -4
  152. package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +45 -0
  153. package/src/dataunit/test/DataUnit.spec.ts +44 -0
  154. package/src/exceptions/ServiceCanceledException.ts +25 -0
  155. package/src/index.ts +10 -1
  156. package/src/repository/IRepository.ts +7 -0
  157. package/src/repository/indexeddb/IDBRepository.ts +4 -0
  158. package/src/utils/DateUtils.ts +3 -0
  159. package/src/utils/ElementUtils.ts +10 -0
  160. package/src/utils/MaskFormatter.ts +5 -1
  161. package/src/utils/ObjectUtils.ts +56 -0
  162. package/src/utils/OnboardingUtils.ts +1 -1
  163. package/src/utils/OverflowWatcher/index.ts +243 -0
  164. package/src/utils/OverflowWatcher/types/overflow-callback.ts +6 -0
  165. package/src/utils/OverflowWatcher/types/overflow-direction.ts +7 -0
  166. package/src/utils/SortingUtils.ts +30 -0
  167. package/src/utils/test/objectUtils.spec.ts +109 -0
  168. package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
  169. package/test/util/ElementUtils.spec.ts +34 -0
  170. package/test/util/OverflowWatcher.spec.ts +152 -0
  171. package/.docs/.nojekyll +0 -1
  172. package/.docs/enums/Action.md +0 -305
  173. package/.docs/enums/ChangeOperation.md +0 -52
  174. package/.docs/enums/DataType.md +0 -63
  175. package/.docs/enums/DependencyType.md +0 -41
  176. package/.docs/enums/SelectionMode.md +0 -30
  177. package/.docs/enums/SortMode.md +0 -30
  178. package/.docs/enums/UserInterface.md +0 -195
  179. package/.docs/modules/MaskFormatter.md +0 -37
@@ -8,6 +8,7 @@ import { PaginationInfo } from "./loading/PaginationInfo.js";
8
8
  */
9
9
  export default class DataUnit {
10
10
  static CHANGING_PAGE_LOADING_SOURCE: string;
11
+ static ALL_RECORDS_SELECTION_SOURCE: string;
11
12
  static DEFAULT_DATAUNIT_NAME: string;
12
13
  private _uuid;
13
14
  private _name;
@@ -22,11 +23,14 @@ export default class DataUnit {
22
23
  private _loadingLockers;
23
24
  private _savingLockers;
24
25
  private _defaultSorting;
26
+ private _allowReleaseCallbacks;
27
+ private _waitingToReload;
25
28
  metadataLoader?: (dataUnit: DataUnit) => Promise<UnitMetadata>;
26
29
  dataLoader?: (dataUnit: DataUnit, request: LoadDataRequest) => Promise<LoadDataResponse>;
27
30
  saveLoader?: (dataUnit: DataUnit, changes: Array<Change>) => Promise<Array<SavedRecord>>;
28
31
  removeLoader?: (dataUnit: DataUnit, recordIds: Array<string>) => Promise<Array<string>>;
29
32
  recordLoader?: (dataUnit: DataUnit, recordIds: Array<string>) => Promise<Array<Record>>;
33
+ allRecordsLoader?: (dataUnit: DataUnit) => Array<Record> | undefined;
30
34
  constructor(name?: string, parentDataUnit?: DataUnit);
31
35
  /**
32
36
  * Desfaz vinculos do DataUnit. Chamado quando o DU não é mais necessário.
@@ -43,7 +47,32 @@ export default class DataUnit {
43
47
  * - Sorting Providers
44
48
  */
45
49
  releaseCallbacks(): void;
50
+ /**
51
+ * Adiciona uma propriedade transacional que será envida aos
52
+ * loaders (dataLoader, saveLoader, removeLoader e recordLoader) na chamada.
53
+ * Essas propriedades serão limpas ao final da execução de cada método.
54
+ *
55
+ * @param name - Nome da propriedade
56
+ * @param value - Valor da propriedade
57
+ *
58
+ */
59
+ addGlobalLoaderProp(name: string, value: string): void;
60
+ /**
61
+ * Retorna as propriedades transacionais adicionados anteriores à chamada.
62
+ *
63
+ * @returns - Todas as propriedades desde o final do último loader.
64
+ */
65
+ getGlobalLoaderProps(): Map<string, string>;
46
66
  get dataUnitId(): string;
67
+ /**
68
+ * Retorna se o dataUnit está com recarregamento pendente.
69
+ */
70
+ isWaitingToReload(): boolean;
71
+ /**
72
+ * Define se o dataUnit tem um recarregamento pendente.
73
+ * @param isWaiting
74
+ */
75
+ setWaitingToReload(isWaiting: boolean): void;
47
76
  /**
48
77
  *
49
78
  * Obtém o nome de identificação do DataUnit (geralmente em formato de URI - Uniform Resource Identifier).
@@ -429,7 +458,7 @@ export default class DataUnit {
429
458
  * @returns - Promise que será resolvida quando o novo valor for persistido no state.
430
459
  *
431
460
  */
432
- setFieldValue(fieldName: string, newValue: any, records?: Array<string>): Promise<boolean>;
461
+ setFieldValue(fieldName: string, newValue: any, records?: Array<string>, options?: DataUnitEventOptions): Promise<boolean>;
433
462
  /**
434
463
  *
435
464
  * Marca campos como inválidos.
@@ -440,6 +469,18 @@ export default class DataUnit {
440
469
  *
441
470
  */
442
471
  setInvalidField(fieldName: string, message: string, recordId: string): void;
472
+ /**
473
+ *
474
+ * Cancela o saving exibindo os campos invalidos.
475
+ *
476
+ * @param filds - Lista dos campos
477
+ * @param recordId - Indica qual registro está com os campos inválido.
478
+ *
479
+ */
480
+ savingCanceled(fields: Array<{
481
+ name: string;
482
+ message: string;
483
+ }>, recordId: string): void;
443
484
  /**
444
485
  *
445
486
  * Limpa campos inválidos.
@@ -540,7 +581,7 @@ export default class DataUnit {
540
581
  * @returns - Objeto com informações como registros selecionados e seleção por critério.
541
582
  *
542
583
  **/
543
- getSelectionInfo(): SelectionInfo | undefined;
584
+ getSelectionInfo(): SelectionInfo;
544
585
  /**
545
586
  *
546
587
  * Retorna apenas um registro selecionado no Dataunit
@@ -549,6 +590,12 @@ export default class DataUnit {
549
590
  *
550
591
  */
551
592
  getSelectedRecord(): Record | undefined;
593
+ /**
594
+ * Retorna o DataUnit pai
595
+ *
596
+ * @returns DataUnit pai ou undefined
597
+ */
598
+ getParentDataUnit(): DataUnit | undefined;
552
599
  /**
553
600
  *
554
601
  * Limpa todos os registros do DataUnit
@@ -586,10 +633,19 @@ export default class DataUnit {
586
633
  *
587
634
  * Retorna se existe algum tipo de alteração pendente.
588
635
  *
636
+ * @param ignoreChildren: Define se deverá ignorar alterações pendentes no DataUnit filho.
589
637
  * @returns Verdadeiro se existir alterações pendentes.
590
638
  *
591
639
  */
592
- isDirty(): boolean;
640
+ isDirty(ignoreChildren?: boolean): boolean;
641
+ /**
642
+ *
643
+ * Retorna se existe alterações pendentes no DataUnit pai.
644
+ *
645
+ * @returns Verdadeiro se existir alterações pendentes e Falso caso não exista alterações ou não exista DataUnit pai.
646
+ *
647
+ */
648
+ isParentDirty(): boolean;
593
649
  /**
594
650
  *
595
651
  * Retorna se existe algum DataUnit detail com alterações pendentes.
@@ -743,7 +799,7 @@ export default class DataUnit {
743
799
  * @param observer - Função que recebe como parâmetro as ações que serão monitoradas.
744
800
  *
745
801
  */
746
- subscribe(observer: (action: DataUnitAction) => void): void;
802
+ subscribe(observer: (action: DataUnitAction, options?: DataUnitEventOptions) => void | Promise<void>): void;
747
803
  /**
748
804
  *
749
805
  * Remove um observer existente.
@@ -861,6 +917,7 @@ export default class DataUnit {
861
917
  * @returns Retorna uma função responsável por liberar o lock adicionado.
862
918
  */
863
919
  addLoadingLocker(): Function;
920
+ set allowReleaseCallbacks(allow: boolean);
864
921
  private processLoadingLockers;
865
922
  }
866
923
  export interface DUActionInterceptor {
@@ -960,11 +1017,12 @@ export declare enum SelectionMode {
960
1017
  SOME_RECORDS = "SOME_RECORDS"
961
1018
  }
962
1019
  export declare class SelectionInfo {
963
- private _records;
964
1020
  mode: SelectionMode;
965
- private _total?;
966
1021
  filters?: Array<Filter>;
967
1022
  sort?: Array<Sort>;
1023
+ getAllRecords?: () => Array<Record> | undefined;
1024
+ private _records;
1025
+ private _total?;
968
1026
  constructor(records: Array<Record>, mode?: SelectionMode, total?: number, filters?: Array<Filter>, sort?: Array<Sort>);
969
1027
  get records(): Array<Record> | undefined;
970
1028
  get recordIds(): Array<string> | undefined;
@@ -972,3 +1030,6 @@ export declare class SelectionInfo {
972
1030
  isAllRecords(): boolean;
973
1031
  isEmpty(): boolean;
974
1032
  }
1033
+ export type DataUnitEventOptions = {
1034
+ [key: string]: any;
1035
+ };
@@ -28,6 +28,9 @@ import { getFormattedValue } from "./formatting/PrettyFormatter.js";
28
28
  import { v4 as uuid } from "uuid";
29
29
  import { DataUnitStorage } from "./DataUnitStorage.js";
30
30
  import { getInvalidFieldMessage, InvalidFieldsReducer } from "./state/slice/InvalidFieldsSlice.js";
31
+ import { getLoadingProperties, LoadingPropertiesReducer } from "./state/slice/LoadingProperties.js";
32
+ import SortingUtils from "../utils/SortingUtils.js";
33
+ import ServiceCanceledException from "../exceptions/ServiceCanceledException.js";
31
34
  /***
32
35
  * `DataUnit`: Atua como uma camada de abstração entre o back-end e a interface do usuário.
33
36
  */
@@ -36,6 +39,7 @@ export default class DataUnit {
36
39
  var _a;
37
40
  this._childByName = new Map();
38
41
  this._savingLockers = [];
42
+ this._waitingToReload = false;
39
43
  /**
40
44
  *
41
45
  * Trata as Actions do DataUnit Parent
@@ -49,6 +53,8 @@ export default class DataUnit {
49
53
  case Action.NEXT_SELECTED:
50
54
  case Action.PREVIOUS_SELECTED:
51
55
  case Action.DATA_LOADED:
56
+ case Action.RECORDS_ADDED:
57
+ case Action.EDITION_CANCELED:
52
58
  this.clearDataUnit();
53
59
  const selectedRecord = (_a = this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.getSelectedRecord();
54
60
  if (selectedRecord != undefined && !this.isNewRecord(selectedRecord.__record__id__)) {
@@ -62,6 +68,7 @@ export default class DataUnit {
62
68
  this._pageSize = 0;
63
69
  this._stateManager = new StateManager([
64
70
  HistReducer,
71
+ LoadingPropertiesReducer,
65
72
  UnitMetadataReducer,
66
73
  LoadingControlReducer,
67
74
  RecordsReducer,
@@ -77,7 +84,8 @@ export default class DataUnit {
77
84
  this._filterProviders = new Map();
78
85
  this._sortingProvider = undefined;
79
86
  this._defaultSorting = [];
80
- this._interceptors = [];
87
+ this._allowReleaseCallbacks = true;
88
+ this._interceptors = new Map();
81
89
  this._parentDataUnit = parentDataUnit;
82
90
  (_a = this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.subscribe(this.onDataUnitParentEvent);
83
91
  this._loadingLockers = [];
@@ -105,14 +113,49 @@ export default class DataUnit {
105
113
  * - Sorting Providers
106
114
  */
107
115
  releaseCallbacks() {
116
+ if (!this._allowReleaseCallbacks)
117
+ return;
108
118
  this._observers = [];
109
119
  this._filterProviders = new Map();
110
120
  this._sortingProvider = undefined;
111
- this._interceptors = [];
121
+ this._interceptors = new Map();
122
+ }
123
+ /**
124
+ * Adiciona uma propriedade transacional que será envida aos
125
+ * loaders (dataLoader, saveLoader, removeLoader e recordLoader) na chamada.
126
+ * Essas propriedades serão limpas ao final da execução de cada método.
127
+ *
128
+ * @param name - Nome da propriedade
129
+ * @param value - Valor da propriedade
130
+ *
131
+ */
132
+ addGlobalLoaderProp(name, value) {
133
+ this.dispatchAction(Action.LOADING_PROPERTY_ADDED, { [name]: value });
134
+ }
135
+ /**
136
+ * Retorna as propriedades transacionais adicionados anteriores à chamada.
137
+ *
138
+ * @returns - Todas as propriedades desde o final do último loader.
139
+ */
140
+ getGlobalLoaderProps() {
141
+ return getLoadingProperties(this._stateManager) || new Map();
112
142
  }
113
143
  get dataUnitId() {
114
144
  return this._uuid;
115
145
  }
146
+ /**
147
+ * Retorna se o dataUnit está com recarregamento pendente.
148
+ */
149
+ isWaitingToReload() {
150
+ return this._waitingToReload;
151
+ }
152
+ /**
153
+ * Define se o dataUnit tem um recarregamento pendente.
154
+ * @param isWaiting
155
+ */
156
+ setWaitingToReload(isWaiting) {
157
+ this._waitingToReload = isWaiting;
158
+ }
116
159
  /**
117
160
  *
118
161
  * Obtém o nome de identificação do DataUnit (geralmente em formato de URI - Uniform Resource Identifier).
@@ -180,15 +223,17 @@ export default class DataUnit {
180
223
  return new Promise((resolve, fail) => __awaiter(this, void 0, void 0, function* () {
181
224
  if (yield this.dispatchAction(Action.LOADING_DATA, request, executionCtx)) {
182
225
  if (this.dataLoader) {
183
- this.dataLoader(this, request).then(response => {
184
- this.dispatchAction(Action.DATA_LOADED, Object.assign(Object.assign({}, response), { keepSelection: request.keepSelection, filters: request.filters }), executionCtx);
226
+ this.dataLoader(this, request).then((response) => __awaiter(this, void 0, void 0, function* () {
227
+ yield this.dispatchAction(Action.DATA_LOADED, Object.assign(Object.assign({}, response), { keepSelection: request.keepSelection, filters: request.filters, selectFirstRecord }), executionCtx);
228
+ yield this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
185
229
  if (selectFirstRecord) {
186
230
  this.requestSelectFirst(executionCtx);
187
231
  }
188
232
  resolve(response);
189
- }).catch(error => {
233
+ })).catch(error => {
190
234
  console.error(error);
191
235
  const { errorCode } = error;
236
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
192
237
  fail(new ErrorException("Erro ao carregar registros", error, errorCode));
193
238
  });
194
239
  }
@@ -245,13 +290,16 @@ export default class DataUnit {
245
290
  loadData(quickFilter, executionCtx, checkLastFilter, source, selectFirstRecord) {
246
291
  return __awaiter(this, void 0, void 0, function* () {
247
292
  yield this.processLoadingLockers();
248
- if (this._parentDataUnit && !this._parentDataUnit.getSelectedRecord()) {
249
- if (this.records) {
250
- this.clearDataUnit();
293
+ if (this._parentDataUnit) {
294
+ const parentRecord = this._parentDataUnit.getSelectedRecord();
295
+ if (parentRecord == undefined || this._parentDataUnit.isNewRecord(parentRecord.__record__id__)) {
296
+ if (this.records) {
297
+ this.clearDataUnit();
298
+ }
299
+ return Promise.resolve({
300
+ records: []
301
+ });
251
302
  }
252
- return Promise.resolve({
253
- records: []
254
- });
255
303
  }
256
304
  const loadDataRequest = this.getLoadDataRequest(quickFilter, source);
257
305
  return this.executeLoadData(loadDataRequest, executionCtx, checkLastFilter, selectFirstRecord);
@@ -368,6 +416,7 @@ export default class DataUnit {
368
416
  if (this.saveLoader) {
369
417
  const changes = this.getAllChangesToSave();
370
418
  this.saveLoader(this, changes).then((records) => {
419
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
371
420
  const recordsByDataUnit = this.getRecordsByDataUnit(records);
372
421
  const dispatchPromisses = [];
373
422
  for (const [ownerDataUnitName, splittedRecords] of recordsByDataUnit) {
@@ -380,10 +429,19 @@ export default class DataUnit {
380
429
  Promise.all(dispatchPromisses).then(() => resolve());
381
430
  }).catch(cause => {
382
431
  const { errorCode } = cause;
383
- fail(new ErrorException("Erro ao salvar alterações", cause, errorCode));
432
+ this.dispatchAction(Action.SAVING_ERROR);
433
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
434
+ if (cause instanceof ServiceCanceledException) {
435
+ console.debug("Service canceled: " + cause.message);
436
+ resolve();
437
+ }
438
+ else {
439
+ fail(new ErrorException("Erro ao salvar alterações", cause, errorCode));
440
+ }
384
441
  });
385
442
  }
386
443
  else {
444
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
387
445
  resolve();
388
446
  }
389
447
  });
@@ -471,6 +529,7 @@ export default class DataUnit {
471
529
  return __awaiter(this, void 0, void 0, function* () {
472
530
  if (recordIds) {
473
531
  if (buffered || !this.removeLoader) {
532
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
474
533
  this.dispatchAction(Action.RECORDS_REMOVED, { records: recordIds, cachedRecords, buffered: true }, executionCtx);
475
534
  }
476
535
  else {
@@ -481,12 +540,15 @@ export default class DataUnit {
481
540
  const currentRecordsKeys = Array.from(getCurrentRecords(this._stateManager).keys());
482
541
  const removedIndex = recordIds
483
542
  .map(id => currentRecordsKeys.indexOf(id))
484
- .filter(index => index > -1);
543
+ .filter(index => index > -1)
544
+ .sort((a, b) => a - b);
485
545
  const nextIndex = Math.min(removedIndex.slice(-1)[0] + 1, currentRecordsKeys.length);
486
- const selectionAfterRemove = [currentRecordsKeys[nextIndex]];
546
+ const selectionAfterRemove = currentRecordsKeys[nextIndex] ? [currentRecordsKeys[nextIndex]] : [];
487
547
  this.dispatchAction(Action.RECORDS_REMOVED, { records: removedIds, cachedRecords, removedIndex, buffered: false, selectionAfterRemove }, executionCtx);
548
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
488
549
  resolve(removedIds);
489
550
  }).catch(error => {
551
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
490
552
  const { errorCode } = error;
491
553
  fail(new ErrorException("Erro ao remover registros", error, errorCode));
492
554
  });
@@ -561,7 +623,7 @@ export default class DataUnit {
561
623
  *
562
624
  */
563
625
  addInterceptor(interceptor) {
564
- this._interceptors.push(interceptor);
626
+ this._interceptors.set(interceptor.interceptAction.toString(), interceptor);
565
627
  }
566
628
  /**
567
629
  *
@@ -571,7 +633,7 @@ export default class DataUnit {
571
633
  *
572
634
  */
573
635
  removeInterceptor(interceptor) {
574
- this._interceptors = this._interceptors.filter(i => i !== interceptor);
636
+ this._interceptors.delete(interceptor.interceptAction.toString());
575
637
  }
576
638
  /**
577
639
  *
@@ -757,6 +819,9 @@ export default class DataUnit {
757
819
  copySelected(executionCtx) {
758
820
  const selectionInfo = this.getSelectionInfo();
759
821
  if (selectionInfo) {
822
+ if (selectionInfo.isAllRecords()) {
823
+ throw new Error("Erro interno: Impossível copiar os registros selecionados pois a seleção atual é virtual.");
824
+ }
760
825
  const selectedRecords = selectionInfo.records;
761
826
  if (selectedRecords) {
762
827
  this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
@@ -818,12 +883,15 @@ export default class DataUnit {
818
883
  * @returns - Promise que será resolvida quando o novo valor for persistido no state.
819
884
  *
820
885
  */
821
- setFieldValue(fieldName, newValue, records) {
886
+ setFieldValue(fieldName, newValue, records, options) {
822
887
  return __awaiter(this, void 0, void 0, function* () {
823
888
  if (!this.hasNewRecord() && !this.getSelectedRecord())
824
889
  yield this.addRecord();
825
890
  const typedValue = this.validateAndTypeValue(fieldName, newValue);
826
891
  const currentValue = this.getFieldValue(fieldName);
892
+ if (!(newValue instanceof Promise) && ObjectUtils.hasEquivalentProps(currentValue, typedValue)) {
893
+ return Promise.resolve(false);
894
+ }
827
895
  if (newValue instanceof Promise) {
828
896
  const promise = new Promise(accept => {
829
897
  newValue.then(resolvedValue => {
@@ -835,7 +903,7 @@ export default class DataUnit {
835
903
  return promise;
836
904
  }
837
905
  if (currentValue !== typedValue) {
838
- const promise = this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records }, undefined);
906
+ const promise = this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records }, undefined, options);
839
907
  this._savingLockers.push(promise);
840
908
  return promise;
841
909
  }
@@ -854,6 +922,17 @@ export default class DataUnit {
854
922
  setInvalidField(fieldName, message, recordId) {
855
923
  this.dispatchAction(Action.FIELD_INVALIDATED, { fieldName, message, recordId }, undefined);
856
924
  }
925
+ /**
926
+ *
927
+ * Cancela o saving exibindo os campos invalidos.
928
+ *
929
+ * @param filds - Lista dos campos
930
+ * @param recordId - Indica qual registro está com os campos inválido.
931
+ *
932
+ */
933
+ savingCanceled(fields, recordId) {
934
+ this.dispatchAction(Action.SAVING_CANCELED, { fields, recordId }, undefined);
935
+ }
857
936
  /**
858
937
  *
859
938
  * Limpa campos inválidos.
@@ -952,7 +1031,7 @@ export default class DataUnit {
952
1031
  setSelection(selection, executionCtx) {
953
1032
  return new Promise(resolve => {
954
1033
  this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }, executionCtx)
955
- .then(() => resolve(getSelectionInfo(this._stateManager)));
1034
+ .then(() => resolve(this.getSelectionInfo()));
956
1035
  });
957
1036
  }
958
1037
  /**
@@ -1003,7 +1082,14 @@ export default class DataUnit {
1003
1082
  *
1004
1083
  **/
1005
1084
  getSelectionInfo() {
1006
- return getSelectionInfo(this._stateManager);
1085
+ var _a;
1086
+ const selectionInfo = getSelectionInfo(this._stateManager);
1087
+ selectionInfo.getAllRecords = () => { var _a; return (_a = this.allRecordsLoader) === null || _a === void 0 ? void 0 : _a.call(this, this); };
1088
+ if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
1089
+ const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort);
1090
+ (_a = selectionInfo.records) === null || _a === void 0 ? void 0 : _a.sort(sortingFunction);
1091
+ }
1092
+ return selectionInfo;
1007
1093
  }
1008
1094
  /**
1009
1095
  *
@@ -1015,6 +1101,14 @@ export default class DataUnit {
1015
1101
  getSelectedRecord() {
1016
1102
  return getSelectedRecord(this._stateManager);
1017
1103
  }
1104
+ /**
1105
+ * Retorna o DataUnit pai
1106
+ *
1107
+ * @returns DataUnit pai ou undefined
1108
+ */
1109
+ getParentDataUnit() {
1110
+ return this._parentDataUnit;
1111
+ }
1018
1112
  /**
1019
1113
  *
1020
1114
  * Limpa todos os registros do DataUnit
@@ -1102,12 +1196,25 @@ export default class DataUnit {
1102
1196
  *
1103
1197
  * Retorna se existe algum tipo de alteração pendente.
1104
1198
  *
1199
+ * @param ignoreChildren: Define se deverá ignorar alterações pendentes no DataUnit filho.
1105
1200
  * @returns Verdadeiro se existir alterações pendentes.
1106
1201
  *
1107
1202
  */
1108
- isDirty() {
1203
+ isDirty(ignoreChildren) {
1204
+ if (ignoreChildren)
1205
+ return isDirty(this._stateManager);
1109
1206
  return isDirty(this._stateManager) || this.childrenIsDirty();
1110
1207
  }
1208
+ /**
1209
+ *
1210
+ * Retorna se existe alterações pendentes no DataUnit pai.
1211
+ *
1212
+ * @returns Verdadeiro se existir alterações pendentes e Falso caso não exista alterações ou não exista DataUnit pai.
1213
+ *
1214
+ */
1215
+ isParentDirty() {
1216
+ return this._parentDataUnit ? this._parentDataUnit.isDirty(true) : false;
1217
+ }
1111
1218
  /**
1112
1219
  *
1113
1220
  * Retorna se existe algum DataUnit detail com alterações pendentes.
@@ -1269,18 +1376,18 @@ export default class DataUnit {
1269
1376
  * @returns - Verdadeiro se ação iniciada.
1270
1377
  *
1271
1378
  */
1272
- dispatchAction(actionType, payload, executionCtx) {
1379
+ dispatchAction(actionType, payload, executionCtx, options) {
1273
1380
  return __awaiter(this, void 0, void 0, function* () {
1274
1381
  return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
1275
1382
  let action = new DataUnitAction(actionType, payload);
1276
1383
  if (executionCtx && executionCtx.before) {
1277
1384
  action = executionCtx.before(action);
1278
1385
  }
1279
- if (action && this._interceptors && this._interceptors.length > 0) {
1386
+ if (action && this._interceptors && this._interceptors.size > 0) {
1280
1387
  action = yield this.intercept(action, this._interceptors.values());
1281
1388
  }
1282
1389
  if (action) {
1283
- this.doDispatchAction(action);
1390
+ this.doDispatchAction(action, options);
1284
1391
  if (executionCtx && executionCtx.after) {
1285
1392
  executionCtx.after(action);
1286
1393
  }
@@ -1320,7 +1427,7 @@ export default class DataUnit {
1320
1427
  * @param action - Ações em execução no DataUnit.
1321
1428
  *
1322
1429
  */
1323
- doDispatchAction(action) {
1430
+ doDispatchAction(action, options = {}) {
1324
1431
  var _a;
1325
1432
  this._stateManager.process(action);
1326
1433
  (_a = this === null || this === void 0 ? void 0 : this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.dispatchAction(Action.CHILD_CHANGED, { srcAction: action, srcDataUnit: this });
@@ -1330,7 +1437,7 @@ export default class DataUnit {
1330
1437
  should be continued
1331
1438
  */
1332
1439
  try {
1333
- f(action);
1440
+ f(action, options);
1334
1441
  }
1335
1442
  catch (e) {
1336
1443
  console.warn("[DataUnit] error while call observer", e);
@@ -1391,13 +1498,15 @@ export default class DataUnit {
1391
1498
  return new Promise((resolve, fail) => __awaiter(this, void 0, void 0, function* () {
1392
1499
  const selection = getSelection(this._stateManager);
1393
1500
  this.dispatchAction(Action.LOADING_RECORD, selection);
1394
- if (!this.dataLoader)
1395
- return;
1396
- if (!this.recordLoader)
1501
+ if (!this.recordLoader || !this.dataLoader) {
1502
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
1397
1503
  return;
1504
+ }
1398
1505
  this.recordLoader(this, selection).then(response => {
1399
1506
  this.dispatchAction(Action.RECORD_LOADED, response);
1507
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
1400
1508
  }).catch(cause => {
1509
+ this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
1401
1510
  const { errorCode } = cause;
1402
1511
  fail(new ErrorException("Erro ao recarregar registro", cause, errorCode));
1403
1512
  });
@@ -1538,10 +1647,13 @@ export default class DataUnit {
1538
1647
  getSelection() {
1539
1648
  console.warn("DataUnit: O método `getSelection` foi descontinuado. Use o método `getSelectionInfo`.");
1540
1649
  const selection = this.getSelectionInfo();
1541
- if (selection != undefined && selection.isAllRecords()) {
1650
+ if (selection == undefined) {
1651
+ return [];
1652
+ }
1653
+ if (selection.isAllRecords()) {
1542
1654
  throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
1543
1655
  }
1544
- return (selection === null || selection === void 0 ? void 0 : selection.recordIds) || [];
1656
+ return selection === null || selection === void 0 ? void 0 : selection.recordIds;
1545
1657
  }
1546
1658
  /**
1547
1659
  * Adiciona um campo stand-alone ao dataUnit.
@@ -1571,6 +1683,9 @@ export default class DataUnit {
1571
1683
  }));
1572
1684
  return loadingLockerResolver || Promise.resolve;
1573
1685
  }
1686
+ set allowReleaseCallbacks(allow) {
1687
+ this._allowReleaseCallbacks = allow;
1688
+ }
1574
1689
  processLoadingLockers() {
1575
1690
  return __awaiter(this, void 0, void 0, function* () {
1576
1691
  if (this._loadingLockers.length) {
@@ -1581,6 +1696,7 @@ export default class DataUnit {
1581
1696
  }
1582
1697
  }
1583
1698
  DataUnit.CHANGING_PAGE_LOADING_SOURCE = "CHANGING_PAGE_LOADING_SOURCE";
1699
+ DataUnit.ALL_RECORDS_SELECTION_SOURCE = "ALL_RECORDS_SELECTION_SOURCE";
1584
1700
  DataUnit.DEFAULT_DATAUNIT_NAME = "dataunit";
1585
1701
  export var ChangeOperation;
1586
1702
  (function (ChangeOperation) {
@@ -1666,7 +1782,10 @@ export class SelectionInfo {
1666
1782
  }
1667
1783
  get records() {
1668
1784
  if (this.isAllRecords()) {
1669
- throw new Error("Erro interno: [ALL_RECORDS] - Impossível retornar os registros selecionados numa seleção virtual.");
1785
+ if (this.getAllRecords != undefined) {
1786
+ return this.getAllRecords();
1787
+ }
1788
+ throw new Error("Erro interno: Impossível retornar os registros selecionados numa seleção virtual.");
1670
1789
  }
1671
1790
  return this._records;
1672
1791
  }