@sankhyalabs/sankhyablocks 8.15.0-dev.61 → 8.15.0-dev.62

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 (169) hide show
  1. package/dist/cjs/{ConfigStorage-7df9d3bb.js → ConfigStorage-9a53a42c.js} +12 -11
  2. package/dist/cjs/{form-config-fetcher-3c4daeb5.js → DataFetcher-515bda03.js} +0 -251
  3. package/dist/cjs/{IExporterProvider-c307e2b1.js → IExporterProvider-d3a3ccd1.js} +55 -12
  4. package/dist/cjs/{SnkFormConfigManager-4259edbe.js → SnkFormConfigManager-dda10d75.js} +2 -2
  5. package/dist/cjs/{SnkMessageBuilder-66aa2557.js → SnkMessageBuilder-4a95fe86.js} +6 -12
  6. package/dist/cjs/{auth-fetcher-e6112be7.js → auth-fetcher-5acb0335.js} +1 -1
  7. package/dist/cjs/{pesquisa-fetcher-cbdaba63.js → dataunit-fetcher-e2109392.js} +68 -173
  8. package/dist/cjs/form-config-fetcher-3f430aee.js +256 -0
  9. package/dist/cjs/loader.cjs.js +1 -1
  10. package/dist/cjs/pesquisa-fetcher-916a935c.js +166 -0
  11. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  12. package/dist/cjs/snk-actions-button_4.cjs.entry.js +10 -8
  13. package/dist/cjs/snk-application.cjs.entry.js +49 -39
  14. package/dist/cjs/snk-attach.cjs.entry.js +19 -17
  15. package/dist/cjs/snk-crud.cjs.entry.js +43 -9
  16. package/dist/cjs/snk-data-exporter.cjs.entry.js +9 -7
  17. package/dist/cjs/snk-data-unit-dee38ccd.js +614 -0
  18. package/dist/cjs/snk-data-unit.cjs.entry.js +10 -2
  19. package/dist/cjs/snk-detail-view.cjs.entry.js +8 -6
  20. package/dist/cjs/snk-filter-bar.cjs.entry.js +3 -2
  21. package/dist/cjs/snk-filter-modal-item.cjs.entry.js +3 -2
  22. package/dist/cjs/snk-form-config.cjs.entry.js +2 -1
  23. package/dist/cjs/snk-form-view.cjs.entry.js +36 -0
  24. package/dist/cjs/snk-form.cjs.entry.js +28 -7
  25. package/dist/cjs/snk-grid.cjs.entry.js +55 -10
  26. package/dist/cjs/{snk-guides-viewer-b0c44e0c.js → snk-guides-viewer-af4a6ae5.js} +19 -6
  27. package/dist/cjs/snk-guides-viewer.cjs.entry.js +8 -6
  28. package/dist/cjs/snk-personalized-filter.cjs.entry.js +3 -2
  29. package/dist/cjs/snk-simple-crud.cjs.entry.js +96 -14
  30. package/dist/collection/collection-manifest.json +1 -1
  31. package/dist/collection/components/snk-application/snk-application.js +37 -17
  32. package/dist/collection/components/snk-crud/snk-crud.js +109 -6
  33. package/dist/collection/components/snk-crud/subcomponents/snk-form-view.js +79 -0
  34. package/dist/collection/components/snk-crud/subcomponents/snk-guides-viewer.js +41 -4
  35. package/dist/collection/components/snk-data-exporter/interfaces/IExporterProvider.js +14 -8
  36. package/dist/collection/components/snk-data-exporter/providers/ClientSideExporterProvider.js +5 -0
  37. package/dist/collection/components/snk-data-unit/snk-data-unit.js +413 -165
  38. package/dist/collection/components/snk-data-unit/test/resources/metadataMock.js +24 -0
  39. package/dist/collection/components/snk-form/snk-form.js +50 -4
  40. package/dist/collection/components/snk-grid/snk-grid.js +96 -7
  41. package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +156 -8
  42. package/dist/collection/lib/DefaultCustomFormatters/RmPrecisionCustomValueFormatter.js +35 -0
  43. package/dist/collection/lib/dataUnit/ValueFormatter.js +4 -0
  44. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IBuildRequestBodyLoadRowMetadata.js +1 -0
  45. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRowMetadata.js +1 -0
  46. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.js +51 -1
  47. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/test/resources/metadataMock.js +22 -0
  48. package/dist/collection/lib/message/SnkMessageBuilder.js +25 -32
  49. package/dist/collection/lib/message/resources/snk-data-unit.msg.js +1 -0
  50. package/dist/components/ConfigStorage.js +2 -1
  51. package/dist/components/DataFetcher.js +7024 -0
  52. package/dist/components/IExporterProvider.js +54 -12
  53. package/dist/components/SnkMessageBuilder.js +6 -12
  54. package/dist/components/dataunit-fetcher.js +58 -164
  55. package/dist/components/form-config-fetcher.js +3 -7023
  56. package/dist/components/pesquisa-fetcher.js +164 -0
  57. package/dist/components/snk-actions-button2.js +4 -2
  58. package/dist/components/snk-application2.js +26 -17
  59. package/dist/components/snk-attach2.js +4 -2
  60. package/dist/components/snk-crud.js +46 -9
  61. package/dist/components/snk-data-exporter2.js +4 -2
  62. package/dist/components/snk-data-unit2.js +356 -166
  63. package/dist/components/snk-detail-view2.js +21 -6
  64. package/dist/components/snk-form-config2.js +1 -1
  65. package/dist/components/snk-form-view2.js +39 -1
  66. package/dist/components/snk-form.js +26 -5
  67. package/dist/components/snk-grid2.js +58 -11
  68. package/dist/components/snk-simple-crud2.js +96 -10
  69. package/dist/esm/{ConfigStorage-928c3bf4.js → ConfigStorage-174101b9.js} +2 -1
  70. package/dist/esm/{form-config-fetcher-e3094014.js → DataFetcher-4b4b7beb.js} +1 -250
  71. package/dist/esm/{IExporterProvider-e2a1195d.js → IExporterProvider-640e1f6b.js} +54 -12
  72. package/dist/esm/{SnkFormConfigManager-a87ade7a.js → SnkFormConfigManager-87bd8082.js} +2 -2
  73. package/dist/esm/{SnkMessageBuilder-0a4becdd.js → SnkMessageBuilder-3a767111.js} +6 -12
  74. package/dist/esm/{auth-fetcher-e1cb288f.js → auth-fetcher-9f86c346.js} +1 -1
  75. package/dist/esm/{pesquisa-fetcher-6d8e50bb.js → dataunit-fetcher-87ecba4a.js} +57 -163
  76. package/dist/esm/form-config-fetcher-5d72aaf1.js +253 -0
  77. package/dist/esm/loader.js +1 -1
  78. package/dist/esm/pesquisa-fetcher-9cfab836.js +164 -0
  79. package/dist/esm/sankhyablocks.js +1 -1
  80. package/dist/esm/snk-actions-button_4.entry.js +5 -3
  81. package/dist/esm/snk-application.entry.js +30 -20
  82. package/dist/esm/snk-attach.entry.js +5 -3
  83. package/dist/esm/snk-crud.entry.js +43 -9
  84. package/dist/esm/snk-data-exporter.entry.js +6 -4
  85. package/dist/esm/snk-data-unit-1132e40b.js +612 -0
  86. package/dist/esm/snk-data-unit.entry.js +10 -2
  87. package/dist/esm/snk-detail-view.entry.js +8 -6
  88. package/dist/esm/snk-filter-bar.entry.js +3 -2
  89. package/dist/esm/snk-filter-modal-item.entry.js +3 -2
  90. package/dist/esm/snk-form-config.entry.js +2 -1
  91. package/dist/esm/snk-form-view.entry.js +36 -0
  92. package/dist/esm/snk-form.entry.js +28 -7
  93. package/dist/esm/snk-grid.entry.js +56 -11
  94. package/dist/esm/{snk-guides-viewer-1fd41a25.js → snk-guides-viewer-359e39a7.js} +19 -6
  95. package/dist/esm/snk-guides-viewer.entry.js +8 -6
  96. package/dist/esm/snk-personalized-filter.entry.js +3 -2
  97. package/dist/esm/snk-simple-crud.entry.js +95 -13
  98. package/dist/sankhyablocks/p-010d475f.js +1 -0
  99. package/dist/sankhyablocks/p-08fee6e8.js +60 -0
  100. package/dist/sankhyablocks/p-0bcc6e83.js +1 -0
  101. package/dist/sankhyablocks/p-2a84e45b.entry.js +1 -0
  102. package/dist/sankhyablocks/{p-0e8702f0.js → p-2eb90860.js} +1 -1
  103. package/dist/sankhyablocks/p-33f695d6.entry.js +1 -0
  104. package/dist/sankhyablocks/p-3519a984.entry.js +1 -0
  105. package/dist/sankhyablocks/p-4ce73e88.js +1 -0
  106. package/dist/sankhyablocks/{p-e27496ed.js → p-566f5f50.js} +6 -6
  107. package/dist/sankhyablocks/p-59dccb7a.entry.js +1 -0
  108. package/dist/sankhyablocks/p-5c8a9e27.entry.js +1 -0
  109. package/dist/sankhyablocks/p-66a31d30.entry.js +11 -0
  110. package/dist/sankhyablocks/p-6b2be902.js +6 -0
  111. package/dist/sankhyablocks/p-7ecaaea2.entry.js +1 -0
  112. package/dist/sankhyablocks/p-83950924.entry.js +1 -0
  113. package/dist/sankhyablocks/p-873d2e6a.entry.js +1 -0
  114. package/dist/sankhyablocks/p-931343a1.entry.js +1 -0
  115. package/dist/sankhyablocks/p-a6dfa396.js +1 -0
  116. package/dist/sankhyablocks/p-aa854fa8.entry.js +1 -0
  117. package/dist/sankhyablocks/p-b11921ca.entry.js +1 -0
  118. package/dist/sankhyablocks/p-cb91634d.js +1 -0
  119. package/dist/sankhyablocks/p-cf9d2d1e.entry.js +1 -0
  120. package/dist/sankhyablocks/p-d29a252c.js +1 -0
  121. package/dist/sankhyablocks/p-d799aa7f.entry.js +1 -0
  122. package/dist/sankhyablocks/p-da6e3dcf.entry.js +1 -0
  123. package/dist/sankhyablocks/p-e0c27486.js +26 -0
  124. package/dist/sankhyablocks/p-f72e8835.entry.js +1 -0
  125. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  126. package/dist/types/components/snk-application/snk-application.d.ts +6 -2
  127. package/dist/types/components/snk-crud/snk-crud.d.ts +14 -1
  128. package/dist/types/components/snk-crud/subcomponents/snk-form-view.d.ts +13 -1
  129. package/dist/types/components/snk-crud/subcomponents/snk-guides-viewer.d.ts +6 -0
  130. package/dist/types/components/snk-data-exporter/interfaces/IExporterProvider.d.ts +3 -0
  131. package/dist/types/components/snk-data-unit/snk-data-unit.d.ts +45 -1
  132. package/dist/types/components/snk-data-unit/test/resources/metadataMock.d.ts +3 -0
  133. package/dist/types/components/snk-form/snk-form.d.ts +6 -0
  134. package/dist/types/components/snk-grid/snk-grid.d.ts +19 -3
  135. package/dist/types/components/snk-simple-crud/snk-simple-crud.d.ts +22 -0
  136. package/dist/types/components.d.ts +68 -4
  137. package/dist/types/lib/DefaultCustomFormatters/RmPrecisionCustomValueFormatter.d.ts +11 -0
  138. package/dist/types/lib/dataUnit/ValueFormatter.d.ts +2 -0
  139. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IBuildRequestBodyLoadRowMetadata.d.ts +10 -0
  140. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRowMetadata.d.ts +7 -0
  141. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.d.ts +6 -0
  142. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/test/resources/metadataMock.d.ts +20 -0
  143. package/dist/types/lib/http/data-fetcher/fetchers/fetchDataExporter/interfaces/IExporterColumnMetadata.d.ts +2 -0
  144. package/package.json +1 -1
  145. package/dist/cjs/snk-data-unit-abd2113f.js +0 -427
  146. package/dist/esm/snk-data-unit-29eba11a.js +0 -425
  147. package/dist/sankhyablocks/p-029bfc09.js +0 -1
  148. package/dist/sankhyablocks/p-03dcc5ff.entry.js +0 -1
  149. package/dist/sankhyablocks/p-07825198.js +0 -1
  150. package/dist/sankhyablocks/p-13ea113d.entry.js +0 -1
  151. package/dist/sankhyablocks/p-314e2d1a.entry.js +0 -1
  152. package/dist/sankhyablocks/p-32556aa6.js +0 -1
  153. package/dist/sankhyablocks/p-3357af48.js +0 -1
  154. package/dist/sankhyablocks/p-3c2a1f4d.js +0 -65
  155. package/dist/sankhyablocks/p-3e7167dd.js +0 -1
  156. package/dist/sankhyablocks/p-536eeb16.js +0 -26
  157. package/dist/sankhyablocks/p-587f9dcf.entry.js +0 -1
  158. package/dist/sankhyablocks/p-61984566.entry.js +0 -1
  159. package/dist/sankhyablocks/p-65b6dba3.entry.js +0 -1
  160. package/dist/sankhyablocks/p-6a7bc5c8.entry.js +0 -1
  161. package/dist/sankhyablocks/p-6c9edfd8.entry.js +0 -1
  162. package/dist/sankhyablocks/p-89bde7d3.entry.js +0 -1
  163. package/dist/sankhyablocks/p-91dceecf.entry.js +0 -1
  164. package/dist/sankhyablocks/p-a40cbad8.entry.js +0 -1
  165. package/dist/sankhyablocks/p-b86ea293.entry.js +0 -1
  166. package/dist/sankhyablocks/p-d8ddb2a4.entry.js +0 -11
  167. package/dist/sankhyablocks/p-df73ac00.entry.js +0 -1
  168. package/dist/sankhyablocks/p-f92f1f5f.entry.js +0 -1
  169. package/dist/sankhyablocks/p-fa84e72f.entry.js +0 -1
@@ -1,427 +0,0 @@
1
- 'use strict';
2
-
3
- const index = require('./index-f9e81701.js');
4
- const core = require('@sankhyalabs/core');
5
- const utils = require('@sankhyalabs/ezui/dist/collection/utils');
6
- const SnkMessageBuilder = require('./SnkMessageBuilder-66aa2557.js');
7
- const RecordIDUtils = require('./RecordIDUtils-3735135c.js');
8
-
9
- const SnkDataUnit = class {
10
- constructor(hostRef) {
11
- index.registerInstance(this, hostRef);
12
- this.dataStateChange = index.createEvent(this, "dataStateChange", 3);
13
- this.dataUnitReady = index.createEvent(this, "dataUnitReady", 3);
14
- this.messagesBuilderUpdated = index.createEvent(this, "messagesBuilderUpdated", 3);
15
- this.insertionMode = index.createEvent(this, "insertionMode", 3);
16
- this.cancelEdition = index.createEvent(this, "cancelEdition", 3);
17
- this._onDataUnitResolve = [];
18
- this._openedAlert = false;
19
- this._dataUnitObserver = (action) => {
20
- var _a, _b;
21
- const duState = this.buildDataState();
22
- this.dataState = duState;
23
- if (action.type === core.Action.DATA_SAVED) {
24
- if (this.ignoreSaveMessage) {
25
- return;
26
- }
27
- const msg = this.getMessage("snkDataUnit.saveInfo", action.payload.records[0]);
28
- if (msg != undefined) {
29
- this.showSuccessMessage(msg);
30
- }
31
- }
32
- if (action.type === core.Action.RECORDS_ADDED || action.type === core.Action.RECORDS_COPIED) {
33
- this.insertionMode.emit();
34
- }
35
- if (action.type === core.Action.EDITION_CANCELED) {
36
- this.cancelEdition.emit();
37
- }
38
- if (action.type === core.Action.RECORDS_REMOVED) {
39
- const cachedRecords = action.payload.cachedRecords;
40
- let removeFinishMsg;
41
- if ((cachedRecords === null || cachedRecords === void 0 ? void 0 : cachedRecords.length) > 1) {
42
- removeFinishMsg = this.getMessage("snkDataUnit.removeAllInfo", { size: cachedRecords.length });
43
- }
44
- else {
45
- removeFinishMsg = this.getMessage("snkDataUnit.removeInfo", action.payload.cachedRecords[0]);
46
- }
47
- if (removeFinishMsg != undefined) {
48
- this.showSuccessMessage(removeFinishMsg);
49
- }
50
- const recordsCount = (_b = (_a = this.dataUnit.records) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
51
- const paginationInfo = this.dataUnit.getPaginationInfo();
52
- if (paginationInfo) {
53
- if (recordsCount > 0 || paginationInfo.hasMore) {
54
- this.dataUnit.gotoPage(paginationInfo.currentPage);
55
- }
56
- else {
57
- this.dataUnit.gotoPage(0);
58
- }
59
- }
60
- }
61
- this.messagesBuilder.currentOperation = this.getMessageOperation();
62
- };
63
- this.dataState = undefined;
64
- this.messagesBuilder = undefined;
65
- this.dataUnitName = undefined;
66
- this.entityName = undefined;
67
- this.pageSize = 150;
68
- this.dataUnit = undefined;
69
- this.beforeSave = undefined;
70
- this.afterSave = undefined;
71
- this.useCancelConfirm = true;
72
- this.ignoreSaveMessage = undefined;
73
- this.configName = undefined;
74
- this.resourceID = undefined;
75
- }
76
- observePageSize() {
77
- if (this.dataUnit) {
78
- this.dataUnit.pageSize = this.pageSize;
79
- }
80
- }
81
- observeDataUnitName(newValue, oldValue) {
82
- if (oldValue != newValue) {
83
- if (this.dataUnit) {
84
- this._application.updateDataunitCache(oldValue, this.dataUnitName, this.dataUnit);
85
- }
86
- else {
87
- this.loadDataUnit();
88
- }
89
- }
90
- }
91
- observeEntityName(newValue, oldValue) {
92
- if (oldValue != newValue) {
93
- this.dataUnit = undefined;
94
- this.entityName = newValue;
95
- this.loadDataUnit();
96
- }
97
- }
98
- observeDataState(newValue, oldValue) {
99
- if (core.ObjectUtils.objectToString(oldValue) != core.ObjectUtils.objectToString(newValue)) {
100
- this.dataStateChange.emit(newValue);
101
- }
102
- }
103
- observeDataUnit() {
104
- this.handlerLinkFields();
105
- this.dataUnitReady.emit(this.dataUnit);
106
- }
107
- observeMessagesBuilder(newValue) {
108
- if (newValue) {
109
- this.messagesBuilderUpdated.emit(newValue);
110
- }
111
- }
112
- /**
113
- * Obtém o dataUnit.
114
- */
115
- async getDataUnit() {
116
- return new Promise((resolve) => {
117
- if (this.dataUnit) {
118
- resolve(this.dataUnit);
119
- }
120
- else {
121
- this._onDataUnitResolve.push(resolve);
122
- }
123
- });
124
- }
125
- /**
126
- * Método que retorna a lista de IDs dos registros selecionados.
127
- * @returns Retorna a lista de IDs dos registros selecionados.
128
- */
129
- async getSelectedRecordsIDsInfo() {
130
- return Promise.resolve(RecordIDUtils.getSelectedIDs(this.dataUnit));
131
- }
132
- getCleanOnCopyFields() {
133
- var _a;
134
- return (_a = this.dataUnit.metadata) === null || _a === void 0 ? void 0 : _a.fields.filter(field => { var _a; return (_a = field.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy; }).map(field => field.name);
135
- }
136
- async interceptAction(action) {
137
- return new Promise(resolve => {
138
- var _a, _b, _c, _d, _e;
139
- switch (action.type) {
140
- case core.Action.RECORDS_ADDED:
141
- if (this.isAllowed("INSERT")) {
142
- resolve(action);
143
- }
144
- else {
145
- utils.ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenInsert"));
146
- }
147
- break;
148
- case core.Action.RECORDS_COPIED:
149
- if (this.isAllowed("CLONE")) {
150
- const cleanFields = this.getCleanOnCopyFields();
151
- if (cleanFields.length > 0) {
152
- const records = action.payload;
153
- action = new core.DataUnitAction(core.Action.RECORDS_COPIED, records.map(record => {
154
- const newRecord = Object.assign({}, record);
155
- cleanFields.forEach(fieldName => delete newRecord[fieldName]);
156
- return newRecord;
157
- }));
158
- }
159
- resolve(action);
160
- }
161
- else {
162
- utils.ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenClone"));
163
- }
164
- break;
165
- case core.Action.DATA_CHANGED:
166
- case core.Action.CHANGING_DATA:
167
- if (this.isAllowed("UPDATE"))
168
- return resolve(action);
169
- if (this._openedAlert)
170
- return this.dataUnit.cancelEdition();
171
- this._openedAlert = true;
172
- this.dataUnit.cancelEdition();
173
- utils.ApplicationUtils.alert(this.getMessage("snkDataUnit.forbidden"), this.getMessage("snkDataUnit.forbiddenUpdate")).then(() => {
174
- this._openedAlert = false;
175
- });
176
- break;
177
- case core.Action.SAVING_DATA:
178
- if (this.beforeSave) {
179
- const continueAction = this.beforeSave(this.dataUnit);
180
- if (continueAction instanceof Promise) {
181
- continueAction.then(result => resolve(result ? action : undefined));
182
- }
183
- else {
184
- resolve(continueAction ? action : undefined);
185
- }
186
- }
187
- else {
188
- resolve(action);
189
- }
190
- break;
191
- case core.Action.DATA_SAVED:
192
- if (this.afterSave) {
193
- this.afterSave(this.dataUnit);
194
- }
195
- else {
196
- resolve(action);
197
- }
198
- break;
199
- case core.Action.EDITION_CANCELED:
200
- if (!this.useCancelConfirm)
201
- return resolve(action);
202
- if (this.dataState.hasDirtyRecords) {
203
- const cancelConfirmation = this.getMessage("snkDataUnit.cancelConfirmation");
204
- if (((_a = action.payload) === null || _a === void 0 ? void 0 : _a.fromParent) || ((_b = action.payload) === null || _b === void 0 ? void 0 : _b.silent)) {
205
- resolve(action);
206
- return;
207
- }
208
- if (cancelConfirmation == undefined) {
209
- this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
210
- resolve(action);
211
- }
212
- else {
213
- const cancelConfirmationTitle = this.getMessage("snkDataUnit.cancelConfirmationTitle");
214
- utils.ApplicationUtils.confirm(cancelConfirmationTitle, cancelConfirmation)
215
- .then((result) => {
216
- result && this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
217
- resolve(result ? action : undefined);
218
- });
219
- }
220
- }
221
- else {
222
- resolve(action);
223
- }
224
- break;
225
- case core.Action.REMOVING_RECORDS:
226
- if (this.isAllowed("REMOVE")) {
227
- let multipleSelection = false;
228
- let removeConfirmation = !((_c = action.payload) === null || _c === void 0 ? void 0 : _c.silent) && this.getMessage("snkDataUnit.removeConfirmation");
229
- const selection = (_d = this.dataUnit) === null || _d === void 0 ? void 0 : _d.getSelectionInfo();
230
- if (!((_e = action.payload) === null || _e === void 0 ? void 0 : _e.silent) && (selection === null || selection === void 0 ? void 0 : selection.length) > 1) {
231
- removeConfirmation = this.getMessage("snkDataUnit.removeAllConfirmation", { size: selection.length });
232
- multipleSelection = true;
233
- }
234
- if (!removeConfirmation) {
235
- resolve(action);
236
- }
237
- else {
238
- const options = {
239
- canClose: false,
240
- labelCancel: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "no" : "cancel"}`),
241
- labelConfirm: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "yes" : "delete"}`),
242
- btnConfirmDanger: false
243
- };
244
- const removeConfirmationTitle = this.getMessage("snkDataUnit.removeConfirmationTitle");
245
- utils.ApplicationUtils.confirm(removeConfirmationTitle, removeConfirmation, null, utils.DialogType.WARN, options)
246
- .then((result) => resolve(result ? action : undefined));
247
- }
248
- }
249
- else {
250
- utils.ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenRemove"));
251
- }
252
- break;
253
- default:
254
- resolve(action);
255
- }
256
- });
257
- }
258
- showSuccessMessage(message) {
259
- utils.ApplicationUtils.info(message, { iconName: "check" });
260
- }
261
- isAllowed(flag) {
262
- return this._permissions ? this._permissions.isSup || this._permissions[flag] : false;
263
- }
264
- buildDataState() {
265
- const selectionInfo = this.dataUnit.getSelectionInfo();
266
- const isStartingInsertionMode = (this.dataUnit.hasDirtyRecords() || this.dataUnit.hasWaitingChanges()) && (selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.isEmpty());
267
- return new DataStateImpl({
268
- insertionMode: this.dataUnit.hasNewRecord(),
269
- isStartingInsertionMode,
270
- hasNext: this.dataUnit.hasNext(),
271
- hasPrevious: this.dataUnit.hasPrevious(),
272
- copyMode: this.dataUnit.hasCopiedRecord(),
273
- isDirty: this.dataUnit.isDirty(),
274
- hasDirtyRecords: this.dataUnit.hasDirtyRecords(),
275
- selectedRecords: undefined,
276
- selectionInfo,
277
- selectedRecord: this.dataUnit.getSelectedRecord(),
278
- recordsIsEmpty: this.dataUnit.records.length === 0
279
- });
280
- }
281
- /**
282
- * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
283
- * através de um pequeno modulo na estrutura da aplicação:
284
- * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
285
- * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-data-unit.msg.ts"
286
- */
287
- getMessage(key, params = undefined) {
288
- if (!params) {
289
- params = this.getMessageParams();
290
- }
291
- return this.messagesBuilder.getMessage(key, params);
292
- }
293
- getMessageParams() {
294
- //FIXME: Devido ao recurso de multiseleção do dataunit, precisaremos criar um mecanismo para
295
- //oferecer todos os registros selecionados para a mensagem, pois mensagens podem ficar incorretas.
296
- return this.dataState.selectedRecord;
297
- }
298
- getMessageOperation() {
299
- if (this.dataState.copyMode) {
300
- return SnkMessageBuilder.OperationMap.CLONE;
301
- }
302
- if (this.dataState.insertionMode || this.dataState.isStartingInsertionMode) {
303
- return SnkMessageBuilder.OperationMap.INSERT;
304
- }
305
- if (this.dataState.isDirty) {
306
- return SnkMessageBuilder.OperationMap.UPDATE;
307
- }
308
- return SnkMessageBuilder.OperationMap.CLEAN;
309
- }
310
- async getDataUnitParentOrChild() {
311
- var _a;
312
- const cacheName = this.dataUnitName ? this.dataUnitName : this.entityName;
313
- if (this._parentSnkDataUnit) {
314
- this._parentDataUnit = await ((_a = this._parentSnkDataUnit) === null || _a === void 0 ? void 0 : _a.getDataUnit());
315
- return await this._application.getDataUnit(this.entityName, cacheName, this._parentDataUnit, this.configName, this.resourceID);
316
- }
317
- else {
318
- return await this._application.getDataUnit(this.entityName, cacheName, null, this.configName, this.resourceID);
319
- }
320
- }
321
- async loadDataUnit() {
322
- if (this.dataUnit == null && this._application && this.entityName) {
323
- this.dataUnit = await this.getDataUnitParentOrChild();
324
- }
325
- if (this.dataUnit) {
326
- this.dataUnit.pageSize = this.pageSize;
327
- this.dataUnit.unsubscribe(this._dataUnitObserver);
328
- this.dataUnit.addInterceptor(this);
329
- this.dataUnit.subscribe(this._dataUnitObserver);
330
- this.dataState = this.buildDataState();
331
- let resolver;
332
- while (resolver = this._onDataUnitResolve.pop()) {
333
- resolver(this.dataUnit);
334
- }
335
- }
336
- }
337
- getParentSnkDataUnit() {
338
- let currentElement = this.element;
339
- while (currentElement.parentNode) {
340
- if (currentElement.parentNode.nodeName === 'SNK-DATA-UNIT') {
341
- return currentElement.parentNode;
342
- }
343
- currentElement = currentElement.parentNode;
344
- }
345
- return;
346
- }
347
- handlerLinkFields() {
348
- var _a, _b;
349
- const metadata = Object.assign({}, this.dataUnit.metadata);
350
- if (!this._parentDataUnit)
351
- return;
352
- const child = this._parentDataUnit.getChildInfo(this.entityName);
353
- if (!child)
354
- return;
355
- const fieldsLink = (_a = child === null || child === void 0 ? void 0 : child.links) === null || _a === void 0 ? void 0 : _a.map(link => link.target);
356
- (_b = metadata === null || metadata === void 0 ? void 0 : metadata.fields) === null || _b === void 0 ? void 0 : _b.forEach(field => {
357
- if (fieldsLink === null || fieldsLink === void 0 ? void 0 : fieldsLink.includes(field.name)) {
358
- field.visible = false;
359
- }
360
- });
361
- this.dataUnit.metadata = metadata;
362
- }
363
- static getNearestInstance(element) {
364
- let parent = element.parentElement;
365
- while (parent) {
366
- if (parent.tagName.toUpperCase() === "SNK-DATA-UNIT") {
367
- return parent;
368
- }
369
- parent = parent.parentElement;
370
- }
371
- }
372
- //---------------------------------------------
373
- // Lifecycle web component
374
- //---------------------------------------------
375
- componentWillLoad() {
376
- this._application = core.ApplicationContext.getContextValue("__SNK__APPLICATION__");
377
- this._application.getAllAccess(this.resourceID).then(access => this._permissions = access);
378
- this._parentSnkDataUnit = this.getParentSnkDataUnit();
379
- if (this.messagesBuilder == undefined) {
380
- this.messagesBuilder = new SnkMessageBuilder.SnkMessageBuilder(this.entityName);
381
- }
382
- }
383
- disconnectedCallback() {
384
- if (this.dataUnit) {
385
- this.dataUnit.releaseCallbacks();
386
- }
387
- }
388
- componentDidLoad() {
389
- this.loadDataUnit();
390
- }
391
- render() {
392
- return (index.h(index.Host, null));
393
- }
394
- get element() { return index.getElement(this); }
395
- static get watchers() { return {
396
- "pageSize": ["observePageSize"],
397
- "dataUnitName": ["observeDataUnitName"],
398
- "entityName": ["observeEntityName"],
399
- "dataState": ["observeDataState"],
400
- "dataUnit": ["observeDataUnit"],
401
- "messagesBuilder": ["observeMessagesBuilder"]
402
- }; }
403
- };
404
- class DataStateImpl {
405
- constructor(datastate) {
406
- this.copyMode = datastate.copyMode;
407
- this.insertionMode = datastate.insertionMode;
408
- this.isStartingInsertionMode = datastate.isStartingInsertionMode;
409
- this.isDirty = datastate.isDirty;
410
- this.hasDirtyRecords = datastate.hasDirtyRecords;
411
- this.hasNext = datastate.hasNext;
412
- this.hasPrevious = datastate.hasPrevious;
413
- this.selectionInfo = datastate.selectionInfo;
414
- this.selectedRecord = datastate.selectedRecord;
415
- this.recordsIsEmpty = datastate.recordsIsEmpty;
416
- }
417
- get selectedRecords() {
418
- var _a;
419
- console.warn("SnkDataUnit: O método `selectedRecords` foi descontinuado. Use o método `selectionInfo`.");
420
- if ((_a = this.selectionInfo) === null || _a === void 0 ? void 0 : _a.isAllRecords()) {
421
- throw new Error("Erro interno: Impossível obter os registros selecionados. A seleção atual é virtual. Use o atributo `selectionInfo`.");
422
- }
423
- return this.selectionInfo.records;
424
- }
425
- }
426
-
427
- exports.SnkDataUnit = SnkDataUnit;