@sankhyalabs/sankhyablocks 5.1.3 → 5.2.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.
Files changed (136) hide show
  1. package/dist/cjs/{SnkMessageBuilder-47185d5d.js → SnkMessageBuilder-c6bd8bc7.js} +9 -2
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  4. package/dist/cjs/snk-application.cjs.entry.js +1 -1
  5. package/dist/cjs/snk-config-options.cjs.entry.js +2 -1
  6. package/dist/cjs/snk-configurator.cjs.entry.js +3 -2
  7. package/dist/cjs/snk-crud.cjs.entry.js +10 -3
  8. package/dist/cjs/snk-data-exporter.cjs.entry.js +10 -1
  9. package/dist/cjs/snk-data-unit-3b6ab2ad.js +436 -0
  10. package/dist/cjs/snk-data-unit.cjs.entry.js +6 -411
  11. package/dist/cjs/snk-detail-view.cjs.entry.js +7 -2
  12. package/dist/cjs/snk-field-config.cjs.entry.js +2 -4
  13. package/dist/cjs/snk-filter-bar.cjs.entry.js +3 -1
  14. package/dist/cjs/snk-filter-param-config.cjs.entry.js +2 -1
  15. package/dist/cjs/snk-form-config.cjs.entry.js +6 -5
  16. package/dist/cjs/snk-form.cjs.entry.js +2 -1
  17. package/dist/cjs/snk-grid.cjs.entry.js +6 -4
  18. package/dist/cjs/{snk-guides-viewer-6225bb73.js → snk-guides-viewer-8a6743d6.js} +8 -5
  19. package/dist/cjs/snk-guides-viewer.cjs.entry.js +1 -1
  20. package/dist/cjs/snk-simple-crud.cjs.entry.js +2 -1
  21. package/dist/cjs/snk-tab-config.cjs.entry.js +2 -1
  22. package/dist/cjs/snk-taskbar.cjs.entry.js +3 -1
  23. package/dist/collection/components/snk-application/snk-application.js +2 -2
  24. package/dist/collection/components/snk-configurator/snk-configurator.js +23 -2
  25. package/dist/collection/components/snk-crud/snk-crud.js +30 -3
  26. package/dist/collection/components/snk-crud/subcomponents/snk-detail-view.js +27 -2
  27. package/dist/collection/components/snk-crud/subcomponents/snk-guides-viewer.js +29 -6
  28. package/dist/collection/components/snk-data-exporter/snk-data-exporter.js +29 -1
  29. package/dist/collection/components/snk-data-unit/snk-data-unit.js +64 -3
  30. package/dist/collection/components/snk-filter-bar/snk-filter-bar.js +23 -1
  31. package/dist/collection/components/snk-form/snk-form.js +22 -1
  32. package/dist/collection/components/snk-form/subcomponents/snk-config-options/snk-config-options.js +22 -1
  33. package/dist/collection/components/snk-form/subcomponents/snk-field-config/snk-field-config.js +23 -5
  34. package/dist/collection/components/snk-form/subcomponents/snk-form-config/snk-form-config.js +26 -5
  35. package/dist/collection/components/snk-form/subcomponents/snk-tab-config/snk-tab-config.js +22 -1
  36. package/dist/collection/components/snk-grid/snk-grid.js +26 -4
  37. package/dist/collection/components/snk-personalized-filter/subcomponents/snk-filter-param-config/snk-filter-param-config.js +26 -1
  38. package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +22 -1
  39. package/dist/collection/components/snk-taskbar/snk-taskbar.js +23 -1
  40. package/dist/collection/lib/message/SnkMessageBuilder.js +9 -2
  41. package/dist/components/SnkMessageBuilder.js +9 -2
  42. package/dist/components/snk-application2.js +1 -1
  43. package/dist/components/snk-config-options2.js +3 -1
  44. package/dist/components/snk-configurator2.js +4 -2
  45. package/dist/components/snk-crud.js +11 -3
  46. package/dist/components/snk-data-exporter2.js +10 -1
  47. package/dist/components/snk-data-unit2.js +25 -4
  48. package/dist/components/snk-detail-view2.js +17 -7
  49. package/dist/components/snk-field-config2.js +5 -6
  50. package/dist/components/snk-filter-bar2.js +4 -1
  51. package/dist/components/snk-filter-param-config.js +3 -1
  52. package/dist/components/snk-form-config2.js +7 -5
  53. package/dist/components/snk-form.js +3 -1
  54. package/dist/components/snk-grid2.js +7 -4
  55. package/dist/components/snk-simple-crud.js +3 -1
  56. package/dist/components/snk-tab-config2.js +3 -1
  57. package/dist/components/snk-taskbar2.js +4 -1
  58. package/dist/esm/{SnkMessageBuilder-ec0850af.js → SnkMessageBuilder-68bbf0ae.js} +9 -2
  59. package/dist/esm/loader.js +1 -1
  60. package/dist/esm/sankhyablocks.js +1 -1
  61. package/dist/esm/snk-application.entry.js +1 -1
  62. package/dist/esm/snk-config-options.entry.js +2 -1
  63. package/dist/esm/snk-configurator.entry.js +3 -2
  64. package/dist/esm/snk-crud.entry.js +10 -3
  65. package/dist/esm/snk-data-exporter.entry.js +10 -1
  66. package/dist/esm/snk-data-unit-a8093f95.js +434 -0
  67. package/dist/esm/snk-data-unit.entry.js +5 -414
  68. package/dist/esm/snk-detail-view.entry.js +7 -2
  69. package/dist/esm/snk-field-config.entry.js +3 -5
  70. package/dist/esm/snk-filter-bar.entry.js +3 -1
  71. package/dist/esm/snk-filter-param-config.entry.js +2 -1
  72. package/dist/esm/snk-form-config.entry.js +6 -5
  73. package/dist/esm/snk-form.entry.js +2 -1
  74. package/dist/esm/snk-grid.entry.js +6 -4
  75. package/dist/esm/{snk-guides-viewer-73b9eb29.js → snk-guides-viewer-d8654e2a.js} +9 -6
  76. package/dist/esm/snk-guides-viewer.entry.js +1 -1
  77. package/dist/esm/snk-simple-crud.entry.js +2 -1
  78. package/dist/esm/snk-tab-config.entry.js +2 -1
  79. package/dist/esm/snk-taskbar.entry.js +3 -1
  80. package/dist/sankhyablocks/p-046b2563.entry.js +1 -0
  81. package/dist/sankhyablocks/p-0a1e7f75.entry.js +1 -0
  82. package/dist/sankhyablocks/{p-28c800b9.js → p-0d70c017.js} +1 -1
  83. package/dist/sankhyablocks/p-1a16426f.js +1 -0
  84. package/dist/sankhyablocks/{p-9ce550b7.entry.js → p-21a6c546.entry.js} +1 -1
  85. package/dist/sankhyablocks/p-280b1321.entry.js +1 -0
  86. package/dist/sankhyablocks/p-32599159.entry.js +1 -0
  87. package/dist/sankhyablocks/p-5b84b0c5.entry.js +1 -0
  88. package/dist/sankhyablocks/p-601e6920.entry.js +1 -0
  89. package/dist/sankhyablocks/p-69af76d4.entry.js +1 -0
  90. package/dist/sankhyablocks/p-76f04efe.entry.js +1 -0
  91. package/dist/sankhyablocks/p-93d8fe00.entry.js +1 -0
  92. package/dist/sankhyablocks/p-a12d74dc.entry.js +1 -0
  93. package/dist/sankhyablocks/p-a7468f4b.js +1 -0
  94. package/dist/sankhyablocks/p-a80c766c.entry.js +1 -0
  95. package/dist/sankhyablocks/p-b686e91a.entry.js +1 -0
  96. package/dist/sankhyablocks/p-b80cf644.entry.js +1 -0
  97. package/dist/sankhyablocks/p-d65809d5.entry.js +1 -0
  98. package/dist/sankhyablocks/{p-b9fe5ed3.entry.js → p-e999631f.entry.js} +2 -2
  99. package/dist/sankhyablocks/p-f29caa0a.entry.js +1 -0
  100. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  101. package/dist/types/components/snk-application/snk-application.d.ts +1 -4
  102. package/dist/types/components/snk-configurator/snk-configurator.d.ts +5 -0
  103. package/dist/types/components/snk-crud/snk-crud.d.ts +6 -0
  104. package/dist/types/components/snk-crud/subcomponents/snk-detail-view.d.ts +2 -3
  105. package/dist/types/components/snk-crud/subcomponents/snk-guides-viewer.d.ts +5 -1
  106. package/dist/types/components/snk-data-exporter/snk-data-exporter.d.ts +5 -0
  107. package/dist/types/components/snk-data-unit/snk-data-unit.d.ts +13 -2
  108. package/dist/types/components/snk-filter-bar/snk-filter-bar.d.ts +5 -0
  109. package/dist/types/components/snk-form/snk-form.d.ts +5 -0
  110. package/dist/types/components/snk-form/subcomponents/snk-config-options/snk-config-options.d.ts +5 -0
  111. package/dist/types/components/snk-form/subcomponents/snk-field-config/snk-field-config.d.ts +5 -2
  112. package/dist/types/components/snk-form/subcomponents/snk-form-config/snk-form-config.d.ts +5 -0
  113. package/dist/types/components/snk-form/subcomponents/snk-tab-config/snk-tab-config.d.ts +5 -0
  114. package/dist/types/components/snk-grid/snk-grid.d.ts +5 -0
  115. package/dist/types/components/snk-personalized-filter/subcomponents/snk-filter-param-config/snk-filter-param-config.d.ts +5 -0
  116. package/dist/types/components/snk-simple-crud/snk-simple-crud.d.ts +5 -0
  117. package/dist/types/components/snk-taskbar/snk-taskbar.d.ts +5 -0
  118. package/dist/types/components.d.ts +126 -12
  119. package/dist/types/lib/message/SnkMessageBuilder.d.ts +4 -2
  120. package/package.json +1 -1
  121. package/dist/sankhyablocks/p-0154ae58.entry.js +0 -1
  122. package/dist/sankhyablocks/p-10be1b2a.entry.js +0 -1
  123. package/dist/sankhyablocks/p-12d2dccf.entry.js +0 -1
  124. package/dist/sankhyablocks/p-193b0fa5.entry.js +0 -1
  125. package/dist/sankhyablocks/p-31d4e5d4.entry.js +0 -1
  126. package/dist/sankhyablocks/p-68507ace.entry.js +0 -1
  127. package/dist/sankhyablocks/p-72277163.entry.js +0 -1
  128. package/dist/sankhyablocks/p-7d4bb27a.entry.js +0 -1
  129. package/dist/sankhyablocks/p-94fef424.entry.js +0 -1
  130. package/dist/sankhyablocks/p-983fef8f.js +0 -1
  131. package/dist/sankhyablocks/p-af8cf505.entry.js +0 -1
  132. package/dist/sankhyablocks/p-c88c4f80.entry.js +0 -1
  133. package/dist/sankhyablocks/p-dd90bd52.entry.js +0 -1
  134. package/dist/sankhyablocks/p-eb7b2496.entry.js +0 -1
  135. package/dist/sankhyablocks/p-ecd3cad5.entry.js +0 -1
  136. package/dist/sankhyablocks/p-f9ca6d74.entry.js +0 -1
@@ -0,0 +1,436 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index-21bd01e1.js');
4
+ const core = require('@sankhyalabs/core');
5
+ const utils = require('@sankhyalabs/ezui/dist/collection/utils');
6
+ const SnkMessageBuilder = require('./SnkMessageBuilder-c6bd8bc7.js');
7
+
8
+ const snkDataUnitCss = ".sc-snk-data-unit-h{display:flex;flex-direction:column;height:100%;width:100%}";
9
+
10
+ const SnkDataUnit = class {
11
+ constructor(hostRef) {
12
+ index.registerInstance(this, hostRef);
13
+ this.dataStateChange = index.createEvent(this, "dataStateChange", 3);
14
+ this.dataUnitReady = index.createEvent(this, "dataUnitReady", 3);
15
+ this.messagesBuilderUpdated = index.createEvent(this, "messagesBuilderUpdated", 3);
16
+ this.insertionMode = index.createEvent(this, "insertionMode", 3);
17
+ this.cancelEdition = index.createEvent(this, "cancelEdition", 3);
18
+ this._onDataUnitResolve = [];
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
+ const msg = this.getMessage("snkDataUnit.saveInfo", action.payload.records[0]);
25
+ if (msg != undefined) {
26
+ this.showSuccessMessage(msg);
27
+ }
28
+ }
29
+ if (action.type === core.Action.RECORDS_ADDED || action.type === core.Action.RECORDS_COPIED) {
30
+ this.insertionMode.emit();
31
+ }
32
+ if (action.type === core.Action.EDITION_CANCELED) {
33
+ this.cancelEdition.emit();
34
+ }
35
+ if (action.type === core.Action.RECORDS_REMOVED) {
36
+ const cachedRecords = action.payload.cachedRecords;
37
+ let removeFinishMsg;
38
+ if ((cachedRecords === null || cachedRecords === void 0 ? void 0 : cachedRecords.length) > 1) {
39
+ removeFinishMsg = this.getMessage("snkDataUnit.removeAllInfo", { size: cachedRecords.length });
40
+ }
41
+ else {
42
+ removeFinishMsg = this.getMessage("snkDataUnit.removeInfo", action.payload.cachedRecords[0]);
43
+ }
44
+ if (removeFinishMsg != undefined) {
45
+ this.showSuccessMessage(removeFinishMsg);
46
+ }
47
+ const recordsCount = (_b = (_a = this.dataUnit.records) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
48
+ const paginationInfo = this.dataUnit.getPaginationInfo();
49
+ if (paginationInfo) {
50
+ if (recordsCount > 0 || paginationInfo.hasMore) {
51
+ this.dataUnit.gotoPage(paginationInfo.currentPage);
52
+ }
53
+ else {
54
+ this.dataUnit.gotoPage(0);
55
+ }
56
+ }
57
+ }
58
+ this.messagesBuilder.currentOperation = this.getMessageOperation();
59
+ };
60
+ this.dataState = undefined;
61
+ this.messagesBuilder = undefined;
62
+ this.dataUnitName = undefined;
63
+ this.entityName = undefined;
64
+ this.pageSize = 150;
65
+ this.dataUnit = undefined;
66
+ this.beforeSave = undefined;
67
+ this.afterSave = undefined;
68
+ }
69
+ observePageSize() {
70
+ if (this.dataUnit) {
71
+ this.dataUnit.pageSize = this.pageSize;
72
+ }
73
+ }
74
+ observeDataUnitName(newValue, oldValue) {
75
+ if (oldValue != newValue) {
76
+ if (this.dataUnit) {
77
+ this._application.updateDataunitCache(oldValue, this.dataUnitName, this.dataUnit);
78
+ }
79
+ else {
80
+ this.loadDataUnit();
81
+ }
82
+ }
83
+ }
84
+ observeEntityName(newValue, oldValue) {
85
+ if (oldValue != newValue) {
86
+ this.dataUnit = undefined;
87
+ this.entityName = newValue;
88
+ this.loadDataUnit();
89
+ }
90
+ }
91
+ observeDataState(newValue, oldValue) {
92
+ if (core.ObjectUtils.objectToString(oldValue) != core.ObjectUtils.objectToString(newValue)) {
93
+ this.dataStateChange.emit(newValue);
94
+ }
95
+ }
96
+ observeDataUnit() {
97
+ this.handlerLinkFields();
98
+ this.dataUnitReady.emit(this.dataUnit);
99
+ }
100
+ observeMessagesBuilder(newValue) {
101
+ if (newValue) {
102
+ this.messagesBuilderUpdated.emit(newValue);
103
+ }
104
+ }
105
+ /**
106
+ * Obtém o dataUnit.
107
+ */
108
+ async getDataUnit() {
109
+ return new Promise((resolve) => {
110
+ if (this.dataUnit) {
111
+ resolve(this.dataUnit);
112
+ }
113
+ else {
114
+ this._onDataUnitResolve.push(resolve);
115
+ }
116
+ });
117
+ }
118
+ /**
119
+ * Método que retorna a lista de IDs dos registros selecionados.
120
+ * @returns Retorna a lista de IDs dos registros selecionados.
121
+ */
122
+ async getSelectedRecordsIDsInfo() {
123
+ var _a;
124
+ const selectionInfo = (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.getSelectionInfo();
125
+ if (selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.isAllRecords()) {
126
+ return [];
127
+ }
128
+ const selectedRecordsIDsInfo = [];
129
+ const selectedRecords = selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.records;
130
+ if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) > 0) {
131
+ selectedRecords.forEach(({ __record__id__ }) => {
132
+ if (!this.dataUnit.isNewRecord(__record__id__)) {
133
+ /*
134
+ Esse if foi necessário para tratar corretamente o ID
135
+ do record quando está sendo utilizado no modo standAlone
136
+ isso não faz a exportação da grid funcionar no modo standAlone
137
+ mas deixa de causar erro nas oprações de CRUD.
138
+ */
139
+ if (!core.JSUtils.isBase64(__record__id__)) {
140
+ selectedRecordsIDsInfo.push({
141
+ name: "__record__id__",
142
+ type: core.DataType.TEXT,
143
+ value: __record__id__
144
+ });
145
+ return;
146
+ }
147
+ const revertBase64ToObject = JSON.parse(window.atob(__record__id__));
148
+ Object.entries(revertBase64ToObject).forEach(([name, value]) => {
149
+ var _a;
150
+ const metadataField = (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.getField(name);
151
+ if (metadataField == undefined) {
152
+ return;
153
+ }
154
+ selectedRecordsIDsInfo.push(Object.assign({ name, type: metadataField.dataType }, value));
155
+ });
156
+ }
157
+ });
158
+ }
159
+ return selectedRecordsIDsInfo;
160
+ }
161
+ async interceptAction(action) {
162
+ return new Promise(resolve => {
163
+ var _a, _b;
164
+ switch (action.type) {
165
+ case core.Action.RECORDS_ADDED:
166
+ if (this.isAllowed("INSERT")) {
167
+ resolve(action);
168
+ }
169
+ else {
170
+ utils.ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenInsert"));
171
+ }
172
+ break;
173
+ case core.Action.RECORDS_COPIED:
174
+ if (this.isAllowed("CLONE")) {
175
+ resolve(action);
176
+ }
177
+ else {
178
+ utils.ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenClone"));
179
+ }
180
+ break;
181
+ case core.Action.DATA_CHANGED:
182
+ case core.Action.CHANGING_DATA:
183
+ if (this.isAllowed("UPDATE")) {
184
+ resolve(action);
185
+ }
186
+ else {
187
+ this.dataUnit.cancelEdition();
188
+ utils.ApplicationUtils.alert(this.getMessage("snkDataUnit.forbidden"), this.getMessage("snkDataUnit.forbiddenUpdate"));
189
+ }
190
+ break;
191
+ case core.Action.SAVING_DATA:
192
+ if (this.beforeSave) {
193
+ const continueAction = this.beforeSave(this.dataUnit);
194
+ if (continueAction instanceof Promise) {
195
+ continueAction.then(result => resolve(result ? action : undefined));
196
+ }
197
+ else {
198
+ resolve(continueAction ? action : undefined);
199
+ }
200
+ }
201
+ else {
202
+ resolve(action);
203
+ }
204
+ break;
205
+ case core.Action.DATA_SAVED:
206
+ if (this.afterSave) {
207
+ this.afterSave(this.dataUnit);
208
+ }
209
+ else {
210
+ resolve(action);
211
+ }
212
+ break;
213
+ case core.Action.EDITION_CANCELED:
214
+ if (this.dataState.hasDirtyRecords) {
215
+ const cancelConfirmation = this.getMessage("snkDataUnit.cancelConfirmation");
216
+ if ((_a = action.payload) === null || _a === void 0 ? void 0 : _a.fromParent) {
217
+ resolve(action);
218
+ return;
219
+ }
220
+ if (cancelConfirmation == undefined) {
221
+ this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
222
+ resolve(action);
223
+ }
224
+ else {
225
+ const cancelConfirmationTitle = this.getMessage("snkDataUnit.cancelConfirmationTitle");
226
+ utils.ApplicationUtils.confirm(cancelConfirmationTitle, cancelConfirmation)
227
+ .then((result) => {
228
+ result && this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
229
+ resolve(result ? action : undefined);
230
+ });
231
+ }
232
+ }
233
+ else {
234
+ resolve(action);
235
+ }
236
+ break;
237
+ case core.Action.REMOVING_RECORDS:
238
+ if (this.isAllowed("REMOVE")) {
239
+ let multipleSelection = false;
240
+ let removeConfirmation = this.getMessage("snkDataUnit.removeConfirmation");
241
+ const selection = (_b = this.dataUnit) === null || _b === void 0 ? void 0 : _b.getSelectionInfo();
242
+ if ((selection === null || selection === void 0 ? void 0 : selection.length) > 1) {
243
+ removeConfirmation = this.getMessage("snkDataUnit.removeAllConfirmation", { size: selection.length });
244
+ multipleSelection = true;
245
+ }
246
+ if (removeConfirmation == undefined) {
247
+ resolve(action);
248
+ }
249
+ else {
250
+ const options = {
251
+ canClose: false,
252
+ labelCancel: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "no" : "cancel"}`),
253
+ labelConfirm: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "yes" : "delete"}`),
254
+ btnConfirmDanger: false
255
+ };
256
+ const removeConfirmationTitle = this.getMessage("snkDataUnit.removeConfirmationTitle");
257
+ utils.ApplicationUtils.confirm(removeConfirmationTitle, removeConfirmation, null, utils.DialogType.WARN, options)
258
+ .then((result) => resolve(result ? action : undefined));
259
+ }
260
+ }
261
+ else {
262
+ utils.ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenRemove"));
263
+ }
264
+ break;
265
+ default:
266
+ resolve(action);
267
+ }
268
+ });
269
+ }
270
+ showSuccessMessage(message) {
271
+ utils.ApplicationUtils.info(message, { iconName: "check" });
272
+ }
273
+ isAllowed(flag) {
274
+ return this._permissions ? this._permissions.isSup || this._permissions[flag] : false;
275
+ }
276
+ buildDataState() {
277
+ const selectionInfo = this.dataUnit.getSelectionInfo();
278
+ return new DataStateImpl({
279
+ insertionMode: this.dataUnit.hasNewRecord(),
280
+ hasNext: this.dataUnit.hasNext(),
281
+ hasPrevious: this.dataUnit.hasPrevious(),
282
+ copyMode: this.dataUnit.hasCopiedRecord(),
283
+ isDirty: this.dataUnit.isDirty(),
284
+ hasDirtyRecords: this.dataUnit.hasDirtyRecords(),
285
+ selectedRecords: undefined,
286
+ selectionInfo,
287
+ selectedRecord: this.dataUnit.getSelectedRecord()
288
+ });
289
+ }
290
+ /**
291
+ * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
292
+ * através de um pequeno modulo na estrutura da aplicação:
293
+ * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
294
+ * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-data-unit.msg.ts"
295
+ */
296
+ getMessage(key, params = undefined) {
297
+ if (!params) {
298
+ params = this.getMessageParams();
299
+ }
300
+ return this.messagesBuilder.getMessage(key, params);
301
+ }
302
+ getMessageParams() {
303
+ //FIXME: Devido ao recurso de multiseleção do dataunit, precisaremos criar um mecanismo para
304
+ //oferecer todos os registros selecionados para a mensagem, pois mensagens podem ficar incorretas.
305
+ return this.dataState.selectedRecord;
306
+ }
307
+ getMessageOperation() {
308
+ if (this.dataState.copyMode) {
309
+ return SnkMessageBuilder.OperationMap.CLONE;
310
+ }
311
+ if (this.dataState.insertionMode) {
312
+ return SnkMessageBuilder.OperationMap.INSERT;
313
+ }
314
+ if (this.dataState.isDirty) {
315
+ return SnkMessageBuilder.OperationMap.UPDATE;
316
+ }
317
+ return SnkMessageBuilder.OperationMap.CLEAN;
318
+ }
319
+ async getDataUnitParentOrChild() {
320
+ var _a;
321
+ const cacheName = this.dataUnitName ? this.dataUnitName : this.entityName;
322
+ if (this._parentSnkDataUnit) {
323
+ this._parentDataUnit = await ((_a = this._parentSnkDataUnit) === null || _a === void 0 ? void 0 : _a.getDataUnit());
324
+ return await this._application.getDataUnit(this.entityName, cacheName, this._parentDataUnit);
325
+ }
326
+ else {
327
+ return await this._application.getDataUnit(this.entityName, cacheName);
328
+ }
329
+ }
330
+ async loadDataUnit() {
331
+ if (this.dataUnit == null && this._application && this.entityName) {
332
+ this.dataUnit = await this.getDataUnitParentOrChild();
333
+ }
334
+ if (this.dataUnit) {
335
+ this.dataUnit.pageSize = this.pageSize;
336
+ this.dataUnit.unsubscribe(this._dataUnitObserver);
337
+ this.dataUnit.addInterceptor(this);
338
+ this.dataUnit.subscribe(this._dataUnitObserver);
339
+ this.dataState = this.buildDataState();
340
+ let resolver;
341
+ while (resolver = this._onDataUnitResolve.pop()) {
342
+ resolver(this.dataUnit);
343
+ }
344
+ }
345
+ }
346
+ getParentSnkDataUnit() {
347
+ let currentElement = this.element;
348
+ while (currentElement.parentNode) {
349
+ if (currentElement.parentNode.nodeName === 'SNK-DATA-UNIT') {
350
+ return currentElement.parentNode;
351
+ }
352
+ currentElement = currentElement.parentNode;
353
+ }
354
+ return;
355
+ }
356
+ handlerLinkFields() {
357
+ var _a, _b;
358
+ const metadata = Object.assign({}, this.dataUnit.metadata);
359
+ if (!this._parentDataUnit)
360
+ return;
361
+ const child = this._parentDataUnit.getChildInfo(this.entityName);
362
+ if (!child)
363
+ return;
364
+ const fieldsLink = (_a = child === null || child === void 0 ? void 0 : child.links) === null || _a === void 0 ? void 0 : _a.map(link => link.target);
365
+ (_b = metadata === null || metadata === void 0 ? void 0 : metadata.fields) === null || _b === void 0 ? void 0 : _b.forEach(field => {
366
+ if (fieldsLink === null || fieldsLink === void 0 ? void 0 : fieldsLink.includes(field.name)) {
367
+ field.visible = false;
368
+ }
369
+ });
370
+ this.dataUnit.metadata = metadata;
371
+ }
372
+ static getNearestInstance(element) {
373
+ let parent = element.parentElement;
374
+ while (parent) {
375
+ if (parent.tagName.toUpperCase() === "SNK-DATA-UNIT") {
376
+ return parent;
377
+ }
378
+ parent = parent.parentElement;
379
+ }
380
+ }
381
+ //---------------------------------------------
382
+ // Lifecycle web component
383
+ //---------------------------------------------
384
+ componentWillLoad() {
385
+ this._application = core.ApplicationContext.getContextValue("__SNK__APPLICATION__");
386
+ this._application.getAllAccess().then(access => this._permissions = access);
387
+ this._parentSnkDataUnit = this.getParentSnkDataUnit();
388
+ if (this.messagesBuilder == undefined) {
389
+ this.messagesBuilder = new SnkMessageBuilder.SnkMessageBuilder(this.entityName);
390
+ }
391
+ }
392
+ disconnectedCallback() {
393
+ if (this.dataUnit) {
394
+ this.dataUnit.unsubscribe(this._dataUnitObserver);
395
+ this.dataUnit.removeInterceptor(this);
396
+ }
397
+ }
398
+ componentDidLoad() {
399
+ this.loadDataUnit();
400
+ }
401
+ render() {
402
+ return (index.h(index.Host, null));
403
+ }
404
+ get element() { return index.getElement(this); }
405
+ static get watchers() { return {
406
+ "pageSize": ["observePageSize"],
407
+ "dataUnitName": ["observeDataUnitName"],
408
+ "entityName": ["observeEntityName"],
409
+ "dataState": ["observeDataState"],
410
+ "dataUnit": ["observeDataUnit"],
411
+ "messagesBuilder": ["observeMessagesBuilder"]
412
+ }; }
413
+ };
414
+ class DataStateImpl {
415
+ constructor(datastate) {
416
+ this.copyMode = datastate.copyMode;
417
+ this.insertionMode = datastate.insertionMode;
418
+ this.isDirty = datastate.isDirty;
419
+ this.hasDirtyRecords = datastate.hasDirtyRecords;
420
+ this.hasNext = datastate.hasNext;
421
+ this.hasPrevious = datastate.hasPrevious;
422
+ this.selectionInfo = datastate.selectionInfo;
423
+ this.selectedRecord = datastate.selectedRecord;
424
+ }
425
+ get selectedRecords() {
426
+ var _a;
427
+ console.warn("SnkDataUnit: O método `selectedRecords` foi descontinuado. Use o método `selectionInfo`.");
428
+ if ((_a = this.selectionInfo) === null || _a === void 0 ? void 0 : _a.isAllRecords()) {
429
+ throw new Error("Erro interno: Impossível obter os registros selecionados. A seleção atual é virtual. Use o atributo `selectionInfo`.");
430
+ }
431
+ return this.selectionInfo.records;
432
+ }
433
+ }
434
+ SnkDataUnit.style = snkDataUnitCss;
435
+
436
+ exports.SnkDataUnit = SnkDataUnit;