@sankhyalabs/sankhyablocks 8.15.3 → 8.16.0-dev.10

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 (234) hide show
  1. package/dist/cjs/{ConfigStorage-942ce74b.js → ConfigStorage-a343e418.js} +1 -0
  2. package/dist/cjs/{SnkMultiSelectionListDataSource-3c08d25c.js → IExporterProvider-597949f9.js} +94 -4
  3. package/dist/cjs/RecordIDUtils-3735135c.js +43 -0
  4. package/dist/cjs/{SnkFormConfigManager-f9dc0d28.js → SnkFormConfigManager-166cbd1f.js} +8 -7
  5. package/dist/cjs/{SnkMessageBuilder-66aa2557.js → SnkMessageBuilder-897ffd08.js} +9 -13
  6. package/dist/cjs/{pesquisa-fetcher-562d281f.js → dataunit-fetcher-688d3f05.js} +87 -180
  7. package/dist/cjs/{index-0922807b.js → index-1dfc7a6e.js} +5 -0
  8. package/dist/cjs/loader.cjs.js +1 -1
  9. package/dist/cjs/pesquisa-fetcher-680e198f.js +166 -0
  10. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  11. package/dist/cjs/snk-actions-button_4.cjs.entry.js +5 -3
  12. package/dist/cjs/snk-application.cjs.entry.js +35 -12
  13. package/dist/cjs/snk-attach.cjs.entry.js +71 -46
  14. package/dist/cjs/snk-crud.cjs.entry.js +101 -10
  15. package/dist/cjs/snk-data-exporter.cjs.entry.js +315 -85
  16. package/dist/cjs/snk-data-unit-8fa7917a.js +689 -0
  17. package/dist/cjs/snk-data-unit.cjs.entry.js +12 -2
  18. package/dist/cjs/snk-detail-view.cjs.entry.js +50 -10
  19. package/dist/cjs/snk-filter-bar.cjs.entry.js +6 -2
  20. package/dist/cjs/snk-filter-modal-item.cjs.entry.js +1 -1
  21. package/dist/cjs/snk-form-config.cjs.entry.js +1 -1
  22. package/dist/cjs/snk-form-view.cjs.entry.js +67 -0
  23. package/dist/cjs/snk-form.cjs.entry.js +52 -7
  24. package/dist/cjs/snk-grid.cjs.entry.js +165 -108
  25. package/dist/cjs/{snk-guides-viewer-bb6087cd.js → snk-guides-viewer-9c682034.js} +43 -10
  26. package/dist/cjs/snk-guides-viewer.cjs.entry.js +9 -7
  27. package/dist/cjs/snk-personalized-filter.cjs.entry.js +1 -1
  28. package/dist/cjs/snk-simple-crud.cjs.entry.js +268 -40
  29. package/dist/cjs/snk-taskbar.cjs.entry.js +4 -3
  30. package/dist/cjs/{taskbar-elements-3ecd1278.js → taskbar-elements-9ad1f9c0.js} +3 -3
  31. package/dist/collection/collection-manifest.json +1 -1
  32. package/dist/collection/components/snk-application/snk-application.js +35 -11
  33. package/dist/collection/components/snk-attach/snk-attach.js +67 -44
  34. package/dist/collection/components/snk-crud/interfaces/PropsCustomEditor.js +1 -0
  35. package/dist/collection/components/snk-crud/interfaces/PropsCustomRender.js +1 -0
  36. package/dist/collection/components/snk-crud/snk-crud.js +305 -7
  37. package/dist/collection/components/snk-crud/subcomponents/snk-detail-view/snk-detail-view.js +136 -2
  38. package/dist/collection/components/snk-crud/subcomponents/snk-form-view.js +161 -0
  39. package/dist/collection/components/snk-crud/subcomponents/snk-guides-viewer.js +134 -7
  40. package/dist/collection/components/snk-data-exporter/exporter-strategy/ClientSideExporterStrategy.js +97 -0
  41. package/dist/collection/components/snk-data-exporter/exporter-strategy/ServerSideExporterStrategy.js +74 -0
  42. package/dist/collection/components/snk-data-exporter/interfaces/IExporterProvider.js +54 -1
  43. package/dist/collection/components/snk-data-exporter/interfaces/IExporterStrategy.js +1 -0
  44. package/dist/collection/components/snk-data-exporter/providers/ClientSideExporterProvider.js +58 -0
  45. package/dist/collection/components/snk-data-exporter/providers/ServerSideExporterProvider.js +55 -0
  46. package/dist/collection/components/snk-data-exporter/snk-data-exporter.js +59 -52
  47. package/dist/collection/components/snk-data-exporter/structure/ItemBuilder.js +62 -0
  48. package/dist/collection/components/snk-data-exporter/test/resources/ClientSideExporterStrategyResources.js +88 -0
  49. package/dist/collection/components/snk-data-exporter/utils/ParserExport.js +20 -0
  50. package/dist/collection/components/snk-data-exporter/utils/RecordIDUtils.js +38 -0
  51. package/dist/collection/components/snk-data-unit/snk-data-unit.js +538 -218
  52. package/dist/collection/components/snk-data-unit/test/resources/metadataMock.js +24 -0
  53. package/dist/collection/components/snk-data-unit/test/resources/parentMetadataMock.js +18 -0
  54. package/dist/collection/components/snk-filter-bar/snk-filter-bar.js +22 -1
  55. package/dist/collection/components/snk-form/snk-form.js +102 -5
  56. package/dist/collection/components/snk-form-config/SnkFormConfigManager.js +7 -6
  57. package/dist/collection/components/snk-form-config/snk-form-config.js +1 -1
  58. package/dist/collection/components/snk-grid/snk-grid.js +240 -101
  59. package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +406 -20
  60. package/dist/collection/components/snk-taskbar/elements/taskbar-elements.js +2 -2
  61. package/dist/collection/components/snk-taskbar/snk-taskbar.js +2 -1
  62. package/dist/collection/lib/@types/index.js +5 -0
  63. package/dist/collection/lib/DefaultCustomFormatters/RmPrecisionCustomValueFormatter.js +35 -0
  64. package/dist/collection/lib/configs/ConfigStorage.js +1 -0
  65. package/dist/collection/lib/dataUnit/InMemoryLoader.js +7 -3
  66. package/dist/collection/lib/dataUnit/ValueFormatter.js +4 -0
  67. package/dist/collection/lib/dataUnit/interfaces/InMemoryLoaderConfig.js +1 -0
  68. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.js +3 -0
  69. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/ArrayRepository.js +4 -0
  70. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.js +11 -13
  71. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/dataunit-fetcher.js +1 -0
  72. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IBuildRequestBodyLoadRowMetadata.js +1 -0
  73. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRowMetadata.js +1 -0
  74. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.js +53 -4
  75. package/dist/collection/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/test/resources/metadataMock.js +22 -0
  76. package/dist/collection/lib/http/data-fetcher/fetchers/pesquisa-fetcher.js +4 -4
  77. package/dist/collection/lib/message/SnkMessageBuilder.js +5 -12
  78. package/dist/collection/lib/message/resources/snk-data-exporter.msg.js +2 -0
  79. package/dist/collection/lib/message/resources/snk-data-unit.msg.js +2 -1
  80. package/dist/components/ConfigStorage.js +1 -0
  81. package/dist/components/{field-search.js → IExporterProvider.js} +93 -6
  82. package/dist/components/ISave.js +47 -0
  83. package/dist/components/SnkFormConfigManager.js +7 -6
  84. package/dist/components/SnkMessageBuilder.js +9 -13
  85. package/dist/components/dataunit-fetcher.js +84 -182
  86. package/dist/components/index2.js +198 -33
  87. package/dist/components/pesquisa-fetcher.js +164 -0
  88. package/dist/components/snk-actions-button2.js +4 -11
  89. package/dist/components/snk-application2.js +31 -9
  90. package/dist/components/snk-attach2.js +65 -41
  91. package/dist/components/snk-crud.js +110 -11
  92. package/dist/components/snk-data-exporter2.js +309 -85
  93. package/dist/components/snk-data-unit2.js +485 -216
  94. package/dist/components/snk-detail-view2.js +96 -14
  95. package/dist/components/snk-expression-item2.js +1 -1
  96. package/dist/components/snk-filter-bar2.js +6 -1
  97. package/dist/components/snk-form-config2.js +1 -1
  98. package/dist/components/snk-form-view2.js +72 -1
  99. package/dist/components/snk-form.js +53 -6
  100. package/dist/components/snk-grid2.js +168 -106
  101. package/dist/components/snk-personalized-filter2.js +1 -1
  102. package/dist/components/snk-simple-crud2.js +263 -25
  103. package/dist/components/snk-taskbar2.js +6 -5
  104. package/dist/esm/{ConfigStorage-86187da3.js → ConfigStorage-3806514e.js} +1 -0
  105. package/dist/esm/{SnkMultiSelectionListDataSource-6a879955.js → IExporterProvider-63a188b6.js} +93 -5
  106. package/dist/esm/RecordIDUtils-87d02110.js +41 -0
  107. package/dist/esm/{SnkFormConfigManager-f53f9f87.js → SnkFormConfigManager-31b24066.js} +8 -7
  108. package/dist/esm/{SnkMessageBuilder-0a4becdd.js → SnkMessageBuilder-571462fb.js} +9 -13
  109. package/dist/esm/{pesquisa-fetcher-c7ce8ee7.js → dataunit-fetcher-264191b2.js} +83 -181
  110. package/dist/esm/{index-0ece87a6.js → index-3aa4977a.js} +6 -1
  111. package/dist/esm/loader.js +1 -1
  112. package/dist/esm/pesquisa-fetcher-03c8f919.js +164 -0
  113. package/dist/esm/sankhyablocks.js +1 -1
  114. package/dist/esm/snk-actions-button_4.entry.js +5 -3
  115. package/dist/esm/snk-application.entry.js +34 -11
  116. package/dist/esm/snk-attach.entry.js +66 -41
  117. package/dist/esm/snk-crud.entry.js +101 -10
  118. package/dist/esm/snk-data-exporter.entry.js +316 -86
  119. package/dist/esm/snk-data-unit-f5cbe64b.js +687 -0
  120. package/dist/esm/snk-data-unit.entry.js +12 -2
  121. package/dist/esm/snk-detail-view.entry.js +50 -10
  122. package/dist/esm/snk-filter-bar.entry.js +6 -2
  123. package/dist/esm/snk-filter-modal-item.entry.js +1 -1
  124. package/dist/esm/snk-form-config.entry.js +1 -1
  125. package/dist/esm/snk-form-view.entry.js +67 -0
  126. package/dist/esm/snk-form.entry.js +52 -7
  127. package/dist/esm/snk-grid.entry.js +163 -106
  128. package/dist/esm/{snk-guides-viewer-1d95ebf2.js → snk-guides-viewer-8f6960a2.js} +43 -10
  129. package/dist/esm/snk-guides-viewer.entry.js +9 -7
  130. package/dist/esm/snk-personalized-filter.entry.js +1 -1
  131. package/dist/esm/snk-simple-crud.entry.js +256 -28
  132. package/dist/esm/snk-taskbar.entry.js +4 -3
  133. package/dist/esm/{taskbar-elements-2473c8ac.js → taskbar-elements-d59867f1.js} +3 -3
  134. package/dist/sankhyablocks/p-17def7cd.js +1 -0
  135. package/dist/sankhyablocks/p-1db45d26.entry.js +1 -0
  136. package/dist/sankhyablocks/p-28ee0972.js +1 -0
  137. package/dist/sankhyablocks/p-2a408684.js +1 -0
  138. package/dist/sankhyablocks/{p-eae7a817.entry.js → p-2c68b3ae.entry.js} +1 -1
  139. package/dist/sankhyablocks/p-30cf616e.js +1 -0
  140. package/dist/sankhyablocks/p-3a212712.js +1 -0
  141. package/dist/sankhyablocks/p-450c60e4.entry.js +1 -0
  142. package/dist/sankhyablocks/{p-a1d72395.entry.js → p-47db7e88.entry.js} +1 -1
  143. package/dist/sankhyablocks/p-4e5e1313.entry.js +1 -0
  144. package/dist/sankhyablocks/{p-aff76a53.js → p-52920496.js} +1 -1
  145. package/dist/sankhyablocks/p-62ba211a.entry.js +1 -0
  146. package/dist/sankhyablocks/p-6bb2f3e9.entry.js +1 -0
  147. package/dist/sankhyablocks/p-7505da04.entry.js +1 -0
  148. package/dist/sankhyablocks/p-7619bdb1.entry.js +11 -0
  149. package/dist/sankhyablocks/p-7a85fd49.entry.js +1 -0
  150. package/dist/sankhyablocks/{p-ae4fc9a9.js → p-7e7a7473.js} +1 -1
  151. package/dist/sankhyablocks/p-7ef9c55c.js +1 -0
  152. package/dist/sankhyablocks/p-80042dc6.entry.js +1 -0
  153. package/dist/sankhyablocks/p-8c59edd7.entry.js +1 -0
  154. package/dist/sankhyablocks/p-9606509c.entry.js +1 -0
  155. package/dist/sankhyablocks/p-9863d682.js +1 -0
  156. package/dist/sankhyablocks/p-ae93d46a.entry.js +1 -0
  157. package/dist/sankhyablocks/p-af8efd95.js +6 -0
  158. package/dist/sankhyablocks/p-d6e26ea8.entry.js +1 -0
  159. package/dist/sankhyablocks/p-f2809746.entry.js +1 -0
  160. package/dist/sankhyablocks/p-f4450320.entry.js +1 -0
  161. package/dist/sankhyablocks/p-fe79f83a.js +60 -0
  162. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  163. package/dist/types/components/snk-application/snk-application.d.ts +7 -3
  164. package/dist/types/components/snk-attach/snk-attach.d.ts +11 -9
  165. package/dist/types/components/snk-crud/interfaces/PropsCustomEditor.d.ts +4 -0
  166. package/dist/types/components/snk-crud/interfaces/PropsCustomRender.d.ts +4 -0
  167. package/dist/types/components/snk-crud/snk-crud.d.ts +45 -1
  168. package/dist/types/components/snk-crud/subcomponents/snk-detail-view/snk-detail-view.d.ts +23 -0
  169. package/dist/types/components/snk-crud/subcomponents/snk-form-view.d.ts +28 -3
  170. package/dist/types/components/snk-crud/subcomponents/snk-guides-viewer.d.ts +24 -0
  171. package/dist/types/components/snk-data-exporter/exporter-strategy/ClientSideExporterStrategy.d.ts +14 -0
  172. package/dist/types/components/snk-data-exporter/exporter-strategy/ServerSideExporterStrategy.d.ts +12 -0
  173. package/dist/types/components/snk-data-exporter/interfaces/IExporterProvider.d.ts +24 -4
  174. package/dist/types/components/snk-data-exporter/interfaces/IExporterStrategy.d.ts +5 -0
  175. package/dist/types/components/snk-data-exporter/providers/ClientSideExporterProvider.d.ts +17 -0
  176. package/dist/types/components/snk-data-exporter/providers/ServerSideExporterProvider.d.ts +17 -0
  177. package/dist/types/components/snk-data-exporter/snk-data-exporter.d.ts +4 -1
  178. package/dist/types/components/snk-data-exporter/structure/ItemBuilder.d.ts +21 -0
  179. package/dist/types/components/snk-data-exporter/test/resources/ClientSideExporterStrategyResources.d.ts +77 -0
  180. package/dist/types/components/snk-data-exporter/utils/ParserExport.d.ts +4 -0
  181. package/dist/types/components/snk-data-exporter/utils/RecordIDUtils.d.ts +3 -0
  182. package/dist/types/components/snk-data-unit/snk-data-unit.d.ts +66 -2
  183. package/dist/types/components/snk-data-unit/test/resources/metadataMock.d.ts +3 -0
  184. package/dist/types/components/snk-data-unit/test/resources/parentMetadataMock.d.ts +3 -0
  185. package/dist/types/components/snk-filter-bar/snk-filter-bar.d.ts +4 -0
  186. package/dist/types/components/snk-form/snk-form.d.ts +14 -0
  187. package/dist/types/components/snk-form-config/SnkFormConfigManager.d.ts +2 -2
  188. package/dist/types/components/snk-grid/snk-grid.d.ts +46 -6
  189. package/dist/types/components/snk-simple-crud/snk-simple-crud.d.ts +62 -4
  190. package/dist/types/components/snk-taskbar/elements/taskbar-elements.d.ts +1 -1
  191. package/dist/types/components.d.ts +261 -4
  192. package/dist/types/lib/@types/index.d.ts +5 -0
  193. package/dist/types/lib/DefaultCustomFormatters/RmPrecisionCustomValueFormatter.d.ts +11 -0
  194. package/dist/types/lib/dataUnit/InMemoryLoader.d.ts +2 -1
  195. package/dist/types/lib/dataUnit/ValueFormatter.d.ts +2 -0
  196. package/dist/types/lib/dataUnit/interfaces/InMemoryLoaderConfig.d.ts +3 -0
  197. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/DataUnitDataLoader.d.ts +2 -1
  198. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/cache/ArrayRepository.d.ts +1 -0
  199. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/cache/PreloadManager.d.ts +1 -0
  200. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IBuildRequestBodyLoadRowMetadata.d.ts +10 -0
  201. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/interfaces/IRowMetadata.d.ts +7 -0
  202. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy.d.ts +6 -0
  203. package/dist/types/lib/http/data-fetcher/fetchers/data-unit/loadstrategy/test/resources/metadataMock.d.ts +20 -0
  204. package/dist/types/lib/http/data-fetcher/fetchers/fetchDataExporter/interfaces/IExporterColumnMetadata.d.ts +3 -0
  205. package/dist/types/lib/http/data-fetcher/fetchers/fetchDataExporter/interfaces/IFetchDataExporterParams.d.ts +2 -1
  206. package/dist/types/lib/http/data-fetcher/fetchers/pesquisa-fetcher.d.ts +1 -0
  207. package/package.json +1 -1
  208. package/dist/cjs/snk-data-unit-41c29713.js +0 -462
  209. package/dist/collection/lib/http/data-fetcher/fetchers/fetchDataExporter/index.js +0 -34
  210. package/dist/components/index3.js +0 -199
  211. package/dist/esm/snk-data-unit-de1d140d.js +0 -460
  212. package/dist/sankhyablocks/p-032fe52e.js +0 -1
  213. package/dist/sankhyablocks/p-03dcc5ff.entry.js +0 -1
  214. package/dist/sankhyablocks/p-0594db5a.entry.js +0 -1
  215. package/dist/sankhyablocks/p-06e13db2.js +0 -1
  216. package/dist/sankhyablocks/p-07a61550.entry.js +0 -1
  217. package/dist/sankhyablocks/p-1403a4b6.entry.js +0 -1
  218. package/dist/sankhyablocks/p-14a08904.entry.js +0 -1
  219. package/dist/sankhyablocks/p-15802c59.entry.js +0 -1
  220. package/dist/sankhyablocks/p-235dc7b1.js +0 -65
  221. package/dist/sankhyablocks/p-32556aa6.js +0 -1
  222. package/dist/sankhyablocks/p-38289a55.js +0 -1
  223. package/dist/sankhyablocks/p-3c632d48.js +0 -1
  224. package/dist/sankhyablocks/p-3f833983.entry.js +0 -1
  225. package/dist/sankhyablocks/p-52c8e589.js +0 -1
  226. package/dist/sankhyablocks/p-5e1502b6.entry.js +0 -11
  227. package/dist/sankhyablocks/p-74d349c3.entry.js +0 -1
  228. package/dist/sankhyablocks/p-93167e28.entry.js +0 -1
  229. package/dist/sankhyablocks/p-add17f6a.entry.js +0 -1
  230. package/dist/sankhyablocks/p-bd47dd16.entry.js +0 -1
  231. package/dist/sankhyablocks/p-c1f88236.entry.js +0 -1
  232. package/dist/sankhyablocks/p-ccdd5332.entry.js +0 -1
  233. package/dist/sankhyablocks/p-ee9536bc.entry.js +0 -1
  234. package/dist/types/lib/http/data-fetcher/fetchers/fetchDataExporter/index.d.ts +0 -3
@@ -1,7 +1,47 @@
1
1
  import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
2
- import { Action, ObjectUtils, JSUtils, DataUnitAction, ApplicationContext, DataType } from '@sankhyalabs/core';
2
+ import { JSUtils, DataType, Action, ObjectUtils, DataUnitAction, StringUtils, ApplicationContext } from '@sankhyalabs/core';
3
3
  import { ApplicationUtils, DialogType } from '@sankhyalabs/ezui/dist/collection/utils';
4
4
  import { O as OperationMap, S as SnkMessageBuilder } from './SnkMessageBuilder.js';
5
+ import { g as getRecordValue, d as DatasetStrategy } from './dataunit-fetcher.js';
6
+ import { convertType } from '@sankhyalabs/core/dist/dataunit/metadata/DataType';
7
+
8
+ const getSelectedIDs = (dataUnit) => {
9
+ const selectionInfo = dataUnit.getSelectionInfo();
10
+ if (selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.isAllRecords()) {
11
+ return [];
12
+ }
13
+ const selectedRecordsIDsInfo = [];
14
+ const selectedRecords = selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.recordIds;
15
+ if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) > 0) {
16
+ selectedRecords.forEach(recordId => {
17
+ if (!dataUnit.isNewRecord(recordId)) {
18
+ /*
19
+ Esse if foi necessário para tratar corretamente o ID
20
+ do record quando está sendo utilizado no modo standAlone
21
+ isso não faz a exportação da grid funcionar no modo standAlone
22
+ mas deixa de causar erro nas oprações de CRUD.
23
+ */
24
+ if (!JSUtils.isBase64(recordId)) {
25
+ selectedRecordsIDsInfo.push({
26
+ name: "__record__id__",
27
+ type: DataType.TEXT,
28
+ value: recordId
29
+ });
30
+ return;
31
+ }
32
+ const revertBase64ToObject = JSON.parse(window.atob(recordId));
33
+ Object.entries(revertBase64ToObject).forEach(([name, value]) => {
34
+ const metadataField = dataUnit === null || dataUnit === void 0 ? void 0 : dataUnit.getField(name);
35
+ if (metadataField == undefined) {
36
+ return;
37
+ }
38
+ selectedRecordsIDsInfo.push(Object.assign({ name, type: metadataField.dataType }, value));
39
+ });
40
+ }
41
+ });
42
+ }
43
+ return selectedRecordsIDsInfo;
44
+ };
5
45
 
6
46
  const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
7
47
  constructor() {
@@ -10,54 +50,41 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
10
50
  this.dataStateChange = createEvent(this, "dataStateChange", 3);
11
51
  this.dataUnitReady = createEvent(this, "dataUnitReady", 3);
12
52
  this.messagesBuilderUpdated = createEvent(this, "messagesBuilderUpdated", 3);
53
+ this.dataUnitFieldsHidded = createEvent(this, "dataUnitFieldsHidded", 7);
13
54
  this.insertionMode = createEvent(this, "insertionMode", 3);
14
55
  this.cancelEdition = createEvent(this, "cancelEdition", 3);
15
56
  this._onDataUnitResolve = [];
16
57
  this._openedAlert = false;
17
- this._dataUnitObserver = (action) => {
18
- var _a, _b;
19
- const duState = this.buildDataState();
58
+ this._fieldsWithRmp = [];
59
+ this._fieldsWithRmPrecision = [];
60
+ this._metadataByRow = new Map();
61
+ this._rowMetadataCache = new Map();
62
+ this.REGEX_DATAUNIT_NAME = /dd:\/\/(.+?)\//;
63
+ this._dataUnitObserver = async (action) => {
64
+ const duState = this.buildDataState(action.type);
20
65
  this.dataState = duState;
21
- if (action.type === Action.DATA_SAVED) {
22
- if (this.ignoreSaveMessage) {
23
- return;
24
- }
25
- const msg = this.getMessage("snkDataUnit.saveInfo", action.payload.records[0]);
26
- if (msg != undefined) {
27
- this.showSuccessMessage(msg);
28
- }
29
- }
30
- if (action.type === Action.RECORDS_ADDED || action.type === Action.RECORDS_COPIED) {
31
- this.insertionMode.emit();
32
- }
33
- if (action.type === Action.EDITION_CANCELED) {
34
- this.cancelEdition.emit();
35
- }
36
- if (action.type === Action.RECORDS_REMOVED) {
37
- const cachedRecords = action.payload.cachedRecords;
38
- let removeFinishMsg;
39
- if ((cachedRecords === null || cachedRecords === void 0 ? void 0 : cachedRecords.length) > 1) {
40
- removeFinishMsg = this.getMessage("snkDataUnit.removeAllInfo", { size: cachedRecords.length });
41
- }
42
- else {
43
- removeFinishMsg = this.getMessage("snkDataUnit.removeInfo", action.payload.cachedRecords[0]);
44
- }
45
- if (removeFinishMsg != undefined) {
46
- this.showSuccessMessage(removeFinishMsg);
47
- }
48
- const recordsCount = (_b = (_a = this.dataUnit.records) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
49
- const paginationInfo = this.dataUnit.getPaginationInfo();
50
- if (paginationInfo) {
51
- if (recordsCount > 0 || paginationInfo.hasMore) {
52
- this.dataUnit.gotoPage(paginationInfo.currentPage);
53
- }
54
- else {
55
- this.dataUnit.gotoPage(0);
56
- }
57
- }
58
- }
59
66
  this.messagesBuilder.currentOperation = this.getMessageOperation();
67
+ switch (action.type) {
68
+ case Action.DATA_SAVED:
69
+ await this.handleDataSaved(action);
70
+ break;
71
+ case Action.RECORDS_ADDED:
72
+ case Action.RECORDS_COPIED:
73
+ this.insertionMode.emit();
74
+ break;
75
+ case Action.EDITION_CANCELED:
76
+ this.cancelEdition.emit();
77
+ break;
78
+ case Action.RECORDS_REMOVED:
79
+ this.handleRecordsRemoved(action);
80
+ break;
81
+ case Action.METADATA_LOADED:
82
+ this.fillFieldsWithRmp(this.dataUnit.metadata);
83
+ this.fillFieldsWithRmPrecision(this.dataUnit.metadata);
84
+ break;
85
+ }
60
86
  };
87
+ this.fieldsToLink = [];
61
88
  this.dataState = undefined;
62
89
  this.messagesBuilder = undefined;
63
90
  this.dataUnitName = undefined;
@@ -70,6 +97,7 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
70
97
  this.ignoreSaveMessage = undefined;
71
98
  this.configName = undefined;
72
99
  this.resourceID = undefined;
100
+ this.domainMessagesBuilder = undefined;
73
101
  }
74
102
  observePageSize() {
75
103
  if (this.dataUnit) {
@@ -125,169 +153,320 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
125
153
  * @returns Retorna a lista de IDs dos registros selecionados.
126
154
  */
127
155
  async getSelectedRecordsIDsInfo() {
128
- var _a;
129
- const selectionInfo = (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.getSelectionInfo();
130
- if (selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.isAllRecords()) {
131
- return [];
132
- }
133
- const selectedRecordsIDsInfo = [];
134
- const selectedRecords = selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.records;
135
- if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) > 0) {
136
- selectedRecords.forEach(({ __record__id__ }) => {
137
- if (!this.dataUnit.isNewRecord(__record__id__)) {
138
- /*
139
- Esse if foi necessário para tratar corretamente o ID
140
- do record quando está sendo utilizado no modo standAlone
141
- isso não faz a exportação da grid funcionar no modo standAlone
142
- mas deixa de causar erro nas oprações de CRUD.
143
- */
144
- if (!JSUtils.isBase64(__record__id__)) {
145
- selectedRecordsIDsInfo.push({
146
- name: "__record__id__",
147
- type: DataType.TEXT,
148
- value: __record__id__
149
- });
150
- return;
151
- }
152
- const revertBase64ToObject = JSON.parse(window.atob(__record__id__));
153
- Object.entries(revertBase64ToObject).forEach(([name, value]) => {
154
- var _a;
155
- const metadataField = (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.getField(name);
156
- if (metadataField == undefined) {
157
- return;
158
- }
159
- selectedRecordsIDsInfo.push(Object.assign({ name, type: metadataField.dataType }, value));
160
- });
161
- }
162
- });
156
+ return Promise.resolve(getSelectedIDs(this.dataUnit));
157
+ }
158
+ /**
159
+ * Retorna os campos que possuem a propriedade "rmp" (Row Metadata Provider).
160
+ */
161
+ async getFieldsWithRmp() {
162
+ return this._fieldsWithRmp;
163
+ }
164
+ /**
165
+ * Retorna os campos que possuem a propriedade "rm_precision" (Row Metadata Precision).
166
+ */
167
+ async getFieldsWithRmPrecision() {
168
+ return this._fieldsWithRmPrecision;
169
+ }
170
+ /**
171
+ * Busca os metadados da linha selecionada.
172
+ */
173
+ async getRowMetadata(record) {
174
+ return this.doGetRowMetadata(record);
175
+ }
176
+ doGetRowMetadata(record) {
177
+ const selectedRecord = this.dataUnit.getSelectedRecord();
178
+ if (!record && !selectedRecord) {
179
+ return;
180
+ }
181
+ const currentRecord = record || selectedRecord;
182
+ const recordId = typeof currentRecord === 'string' ? currentRecord : currentRecord.__record__id__;
183
+ const rowMetadata = this._metadataByRow.get(recordId);
184
+ if (!rowMetadata) {
185
+ return;
163
186
  }
164
- return selectedRecordsIDsInfo;
187
+ rowMetadata.getProp = this.buildGetPropRowMetadata(rowMetadata);
188
+ return Object.assign({}, rowMetadata);
189
+ }
190
+ buildGetPropRowMetadata(rowMetadata) {
191
+ return (propPath, fieldName) => {
192
+ if (propPath === "rm_precision") {
193
+ propPath = this.resolvePrecisionFromMetadata(fieldName);
194
+ }
195
+ return ObjectUtils.getProp(rowMetadata, propPath);
196
+ };
197
+ }
198
+ resolvePrecisionFromMetadata(fieldName) {
199
+ var _a, _b;
200
+ if (!fieldName) {
201
+ ApplicationUtils.error(this.getMessage("snkDataUnit.fieldNameRequired"));
202
+ return;
203
+ }
204
+ const rmPrecision = (_b = (_a = this.dataUnit.getField(fieldName)) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.rm_precision;
205
+ if (!rmPrecision) {
206
+ return '';
207
+ }
208
+ let rmPrecisionPath = rmPrecision.split('.').filter((_, index) => index !== 1).join('.');
209
+ return rmPrecisionPath;
165
210
  }
166
211
  getCleanOnCopyFields() {
167
212
  var _a;
168
213
  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);
169
214
  }
170
- async interceptAction(action) {
171
- return new Promise(resolve => {
172
- var _a, _b, _c, _d, _e;
173
- switch (action.type) {
174
- case Action.RECORDS_ADDED:
175
- if (this.isAllowed("INSERT")) {
176
- resolve(action);
177
- }
178
- else {
179
- ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenInsert"));
180
- }
181
- break;
182
- case Action.RECORDS_COPIED:
183
- if (this.isAllowed("CLONE")) {
184
- const cleanFields = this.getCleanOnCopyFields();
185
- if (cleanFields.length > 0) {
186
- const records = action.payload;
187
- action = new DataUnitAction(Action.RECORDS_COPIED, records.map(record => {
188
- const newRecord = Object.assign({}, record);
189
- cleanFields.forEach(fieldName => delete newRecord[fieldName]);
190
- return newRecord;
191
- }));
192
- }
193
- resolve(action);
194
- }
195
- else {
196
- ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenClone"));
197
- }
198
- break;
199
- case Action.DATA_CHANGED:
200
- case Action.CHANGING_DATA:
201
- if (this.isAllowed("UPDATE"))
202
- return resolve(action);
203
- if (this._openedAlert)
204
- return this.dataUnit.cancelEdition();
205
- this._openedAlert = true;
206
- this.dataUnit.cancelEdition();
207
- ApplicationUtils.alert(this.getMessage("snkDataUnit.forbidden"), this.getMessage("snkDataUnit.forbiddenUpdate")).then(() => {
208
- this._openedAlert = false;
209
- });
210
- break;
211
- case Action.SAVING_DATA:
212
- if (this.beforeSave) {
213
- const continueAction = this.beforeSave(this.dataUnit);
214
- if (continueAction instanceof Promise) {
215
- continueAction.then(result => resolve(result ? action : undefined));
216
- }
217
- else {
218
- resolve(continueAction ? action : undefined);
219
- }
220
- }
221
- else {
222
- resolve(action);
223
- }
224
- break;
225
- case Action.DATA_SAVED:
226
- if (this.afterSave) {
227
- this.afterSave(this.dataUnit);
228
- }
229
- else {
230
- resolve(action);
231
- }
232
- break;
233
- case Action.EDITION_CANCELED:
234
- if (!this.useCancelConfirm)
235
- return resolve(action);
236
- if (this.dataState.hasDirtyRecords) {
237
- const cancelConfirmation = this.getMessage("snkDataUnit.cancelConfirmation");
238
- if (((_a = action.payload) === null || _a === void 0 ? void 0 : _a.fromParent) || ((_b = action.payload) === null || _b === void 0 ? void 0 : _b.silent)) {
239
- resolve(action);
240
- return;
241
- }
242
- if (cancelConfirmation == undefined) {
243
- this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
244
- resolve(action);
245
- }
246
- else {
247
- const cancelConfirmationTitle = this.getMessage("snkDataUnit.cancelConfirmationTitle");
248
- ApplicationUtils.confirm(cancelConfirmationTitle, cancelConfirmation)
249
- .then((result) => {
250
- result && this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
251
- resolve(result ? action : undefined);
252
- });
253
- }
254
- }
255
- else {
256
- resolve(action);
257
- }
258
- break;
259
- case Action.REMOVING_RECORDS:
260
- if (this.isAllowed("REMOVE")) {
261
- let multipleSelection = false;
262
- let removeConfirmation = !((_c = action.payload) === null || _c === void 0 ? void 0 : _c.silent) && this.getMessage("snkDataUnit.removeConfirmation");
263
- const selection = (_d = this.dataUnit) === null || _d === void 0 ? void 0 : _d.getSelectionInfo();
264
- if (!((_e = action.payload) === null || _e === void 0 ? void 0 : _e.silent) && (selection === null || selection === void 0 ? void 0 : selection.length) > 1) {
265
- removeConfirmation = this.getMessage("snkDataUnit.removeAllConfirmation", { size: selection.length });
266
- multipleSelection = true;
267
- }
268
- if (!removeConfirmation) {
269
- resolve(action);
270
- }
271
- else {
272
- const options = {
273
- canClose: false,
274
- labelCancel: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "no" : "cancel"}`),
275
- labelConfirm: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "yes" : "delete"}`),
276
- btnConfirmDanger: false
277
- };
278
- const removeConfirmationTitle = this.getMessage("snkDataUnit.removeConfirmationTitle");
279
- ApplicationUtils.confirm(removeConfirmationTitle, removeConfirmation, null, DialogType.WARN, options)
280
- .then((result) => resolve(result ? action : undefined));
281
- }
282
- }
283
- else {
284
- ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenRemove"));
285
- }
286
- break;
287
- default:
288
- resolve(action);
215
+ fillFieldsWithRmp(payload) {
216
+ payload.fields.forEach((field) => {
217
+ var _a;
218
+ if (((_a = field.properties) === null || _a === void 0 ? void 0 : _a.rmp) && !this._fieldsWithRmp.includes(field.name)) {
219
+ this._fieldsWithRmp.push(field.name);
220
+ }
221
+ });
222
+ }
223
+ fillFieldsWithRmPrecision(payload) {
224
+ payload.fields.forEach((field) => {
225
+ var _a;
226
+ if (((_a = field.properties) === null || _a === void 0 ? void 0 : _a.rm_precision) && !this._fieldsWithRmPrecision.includes(field.name)) {
227
+ this._fieldsWithRmPrecision.push(field.name);
228
+ }
229
+ });
230
+ }
231
+ getCacheName(fieldName, metadataName, fieldValue) {
232
+ const cacheName = [fieldName, metadataName, fieldValue].join("_");
233
+ return cacheName;
234
+ }
235
+ updateDataStateRmp(newValue) {
236
+ const newRowMetadata = Object.assign({}, newValue);
237
+ this.dataState.rowMetadata = newRowMetadata;
238
+ }
239
+ saveCacheRmd(record) {
240
+ const rmd = record.__record__metadata__;
241
+ const keysRmd = Object.keys(rmd);
242
+ keysRmd.shift();
243
+ keysRmd.forEach((fieldName) => {
244
+ const fieldValue = getRecordValue(record, fieldName);
245
+ const cacheName = this.getCacheName(fieldName, rmd.provider, fieldValue);
246
+ this._rowMetadataCache.set(cacheName, Object.assign({}, rmd));
247
+ });
248
+ }
249
+ getMetadataByRow(payload) {
250
+ var _a;
251
+ if (!((_a = payload.records) === null || _a === void 0 ? void 0 : _a.length)) {
252
+ return payload;
253
+ }
254
+ if (!this._fieldsWithRmp.length) {
255
+ const records = payload.records.map((record) => {
256
+ delete record.__record__metadata__;
257
+ return record;
258
+ });
259
+ return Object.assign(Object.assign({}, payload), { records });
260
+ }
261
+ const records = payload.records.map((record) => {
262
+ if (!record.__record__metadata__) {
263
+ return record;
289
264
  }
265
+ this.saveCacheRmd(record);
266
+ const rowMetadata = Object.assign({}, record.__record__metadata__);
267
+ rowMetadata.getProp = this.buildGetPropRowMetadata(rowMetadata);
268
+ this._metadataByRow.set(record.__record__id__, rowMetadata);
269
+ delete record.__record__metadata__;
270
+ return record;
271
+ });
272
+ return Object.assign(Object.assign({}, payload), { records });
273
+ }
274
+ interceptRecordsAdded(action) {
275
+ if (!this.isAllowed("INSERT")) {
276
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenInsert"));
277
+ return;
278
+ }
279
+ return new DataUnitAction(Action.RECORDS_ADDED, this.handleLinksWithParent(action.payload));
280
+ }
281
+ interceptRecordsCopied(action) {
282
+ if (!this.isAllowed("CLONE")) {
283
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenClone"));
284
+ return;
285
+ }
286
+ return new DataUnitAction(Action.RECORDS_COPIED, this.handleRecordsCopied(action.payload));
287
+ }
288
+ async interceptDataChange(action) {
289
+ if (this.isAllowed("UPDATE")) {
290
+ return action;
291
+ }
292
+ if (this._openedAlert) {
293
+ await this.dataUnit.cancelEdition();
294
+ return;
295
+ }
296
+ this._openedAlert = true;
297
+ await this.dataUnit.cancelEdition();
298
+ await ApplicationUtils.alert(this.getMessage("snkDataUnit.forbidden"), this.getMessage("snkDataUnit.forbiddenUpdate"));
299
+ this._openedAlert = false;
300
+ }
301
+ async interceptSavingData(action) {
302
+ if (!this.beforeSave) {
303
+ return action;
304
+ }
305
+ const continueAction = this.beforeSave(this.dataUnit);
306
+ if (continueAction instanceof Promise) {
307
+ const result = await continueAction;
308
+ return result ? action : undefined;
309
+ }
310
+ return continueAction ? action : undefined;
311
+ }
312
+ interceptDataSaved(action) {
313
+ if (this.afterSave) {
314
+ this.afterSave(this.dataUnit);
315
+ return;
316
+ }
317
+ return action;
318
+ }
319
+ async interceptEditionCanceled(action) {
320
+ var _a, _b;
321
+ if (!this.useCancelConfirm || !this.dataState.hasDirtyRecords || ((_a = action.payload) === null || _a === void 0 ? void 0 : _a.fromParent) || ((_b = action.payload) === null || _b === void 0 ? void 0 : _b.silent)) {
322
+ return action;
323
+ }
324
+ const cancelConfirmation = this.getMessage("snkDataUnit.cancelConfirmation");
325
+ if (cancelConfirmation == undefined) {
326
+ this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
327
+ return action;
328
+ }
329
+ const cancelConfirmationTitle = this.getMessage("snkDataUnit.cancelConfirmationTitle");
330
+ const confirm = await ApplicationUtils.confirm(cancelConfirmationTitle, cancelConfirmation);
331
+ confirm && this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
332
+ return confirm ? action : undefined;
333
+ }
334
+ async interceptRemovingRecords(action) {
335
+ var _a, _b, _c;
336
+ if (!this.isAllowed("REMOVE")) {
337
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenRemove"));
338
+ return;
339
+ }
340
+ let multipleSelection = false;
341
+ let removeConfirmation = !((_a = action.payload) === null || _a === void 0 ? void 0 : _a.silent) && this.getMessage("snkDataUnit.removeConfirmation");
342
+ const selection = (_b = this.dataUnit) === null || _b === void 0 ? void 0 : _b.getSelectionInfo();
343
+ if (!((_c = action.payload) === null || _c === void 0 ? void 0 : _c.silent) && (selection === null || selection === void 0 ? void 0 : selection.length) > 1) {
344
+ removeConfirmation = this.getMessage("snkDataUnit.removeAllConfirmation", { size: selection.length });
345
+ multipleSelection = true;
346
+ }
347
+ if (!removeConfirmation) {
348
+ return action;
349
+ }
350
+ const options = {
351
+ canClose: false,
352
+ labelCancel: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "no" : "cancel"}`),
353
+ labelConfirm: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "yes" : "delete"}`),
354
+ btnConfirmDanger: false
355
+ };
356
+ const removeConfirmationTitle = this.getMessage("snkDataUnit.removeConfirmationTitle");
357
+ const confirm = await ApplicationUtils.confirm(removeConfirmationTitle, removeConfirmation, null, DialogType.WARN, options);
358
+ return confirm ? action : undefined;
359
+ }
360
+ interceptDataLoaded(action) {
361
+ const newPayload = this.getMetadataByRow(action.payload);
362
+ action = new DataUnitAction(Action.DATA_LOADED, newPayload);
363
+ return action;
364
+ }
365
+ interceptMetadataLoaded(action) {
366
+ this.fillFieldsWithRmp(action.payload);
367
+ this.fillFieldsWithRmPrecision(action.payload);
368
+ return new DataUnitAction(Action.METADATA_LOADED, this.handleDULinksOnMetadataLoaded(action.payload));
369
+ }
370
+ async interceptAction(action) {
371
+ switch (action.type) {
372
+ case Action.RECORDS_ADDED:
373
+ return this.interceptRecordsAdded(action);
374
+ case Action.RECORDS_COPIED:
375
+ return this.interceptRecordsCopied(action);
376
+ case Action.DATA_CHANGED:
377
+ await this.handleLoadRowMetadata(action);
378
+ return await this.interceptDataChange(action);
379
+ case Action.CHANGING_DATA:
380
+ return await this.interceptDataChange(action);
381
+ case Action.SAVING_DATA:
382
+ return await this.interceptSavingData(action);
383
+ case Action.DATA_SAVED:
384
+ return this.interceptDataSaved(action);
385
+ case Action.EDITION_CANCELED:
386
+ return await this.interceptEditionCanceled(action);
387
+ case Action.REMOVING_RECORDS:
388
+ return await this.interceptRemovingRecords(action);
389
+ case Action.DATA_LOADED:
390
+ return this.interceptDataLoaded(action);
391
+ case Action.METADATA_LOADED:
392
+ return this.interceptMetadataLoaded(action);
393
+ default:
394
+ return action;
395
+ }
396
+ }
397
+ async handleLoadRowMetadata(action) {
398
+ const record = action.type === Action.DATA_CHANGED ? action.payload : action.payload.changes[0].record;
399
+ const keysPayload = Object.keys(record);
400
+ const rmpField = keysPayload.find((field) => this._fieldsWithRmp.includes(field));
401
+ if (rmpField) {
402
+ const metadataName = this.dataUnit.getField(rmpField).properties.rmp;
403
+ const fieldValue = getRecordValue(record, rmpField);
404
+ return await this.updateRowMetadata({
405
+ fieldName: rmpField,
406
+ fieldValue,
407
+ metadataName,
408
+ updatedFields: record,
409
+ });
410
+ }
411
+ }
412
+ async updateRowMetadata({ fieldName, fieldValue, metadataName, updatedFields }) {
413
+ const cacheName = this.getCacheName(fieldName, metadataName, fieldValue);
414
+ const cacheValue = this._rowMetadataCache.get(cacheName);
415
+ if (cacheValue) {
416
+ this.updateDataStateRmp(cacheValue);
417
+ return cacheValue;
418
+ }
419
+ else {
420
+ const datasetStrategy = new DatasetStrategy();
421
+ const response = await datasetStrategy.loadRowMetadata(this, fieldName, metadataName, updatedFields);
422
+ this.updateDataStateRmp(response._rmd);
423
+ this._rowMetadataCache.set(cacheName, Object.assign({}, response._rmd));
424
+ return Object.assign({}, response._rmd);
425
+ }
426
+ }
427
+ handleDULinksOnMetadataLoaded(payload) {
428
+ const metadata = Object.assign({}, payload);
429
+ this.processLinks(metadata);
430
+ return metadata;
431
+ }
432
+ handleRecordsCopied(initialRecords) {
433
+ let records = [...initialRecords];
434
+ records = this.handleCleanOnCopy(records);
435
+ return this.handleLinksWithParent(records);
436
+ }
437
+ handleLinksWithParent(records) {
438
+ var _a, _b;
439
+ const parentDataUnit = (_a = this._parentDataUnit) !== null && _a !== void 0 ? _a : (_b = this.dataUnit) === null || _b === void 0 ? void 0 : _b.getParentDataUnit();
440
+ if (!parentDataUnit)
441
+ return records;
442
+ const parentSelectedRecord = parentDataUnit.getSelectedRecord();
443
+ const selfInfo = parentDataUnit === null || parentDataUnit === void 0 ? void 0 : parentDataUnit.getChildInfo(this.getCleanDataUnitName());
444
+ const { links } = selfInfo;
445
+ if (!links || links.length === 0)
446
+ return records;
447
+ return records.map(record => {
448
+ return this.buildRecordWithLinkedFields(record, links, parentSelectedRecord);
449
+ });
450
+ }
451
+ buildRecordWithLinkedFields(record, links, parentSelectedRecord) {
452
+ const newRecord = Object.assign({}, record);
453
+ links.forEach(link => {
454
+ const convertedParentSelectedRecord = convertType(this.dataUnit.getField(link.target).dataType, parentSelectedRecord[link.source]);
455
+ newRecord[link.target] = convertedParentSelectedRecord;
290
456
  });
457
+ return newRecord;
458
+ }
459
+ handleCleanOnCopy(records) {
460
+ const cleanFields = this.getCleanOnCopyFields();
461
+ if (cleanFields.length > 0) {
462
+ records = records.map(record => this.buildCopyWithCleanedFields(record, cleanFields));
463
+ }
464
+ return records;
465
+ }
466
+ buildCopyWithCleanedFields(record, cleanFields) {
467
+ const newRecord = Object.assign({}, record);
468
+ cleanFields.forEach(fieldName => delete newRecord[fieldName]);
469
+ return newRecord;
291
470
  }
292
471
  showSuccessMessage(message) {
293
472
  ApplicationUtils.info(message, { iconName: "check" });
@@ -295,9 +474,19 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
295
474
  isAllowed(flag) {
296
475
  return this._permissions ? this._permissions.isSup || this._permissions[flag] : false;
297
476
  }
298
- buildDataState() {
477
+ buildDataState(actionType) {
478
+ var _a;
299
479
  const selectionInfo = this.dataUnit.getSelectionInfo();
300
480
  const isStartingInsertionMode = (this.dataUnit.hasDirtyRecords() || this.dataUnit.hasWaitingChanges()) && (selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.isEmpty());
481
+ const selectedRecord = this.dataUnit.getSelectedRecord();
482
+ let rowMetadata = (_a = this.dataState) === null || _a === void 0 ? void 0 : _a.rowMetadata;
483
+ const allowedOverwrite = [Action.SELECTION_CHANGED, Action.EDITION_CANCELED, Action.NEXT_SELECTED, Action.PREVIOUS_SELECTED];
484
+ if (selectedRecord && (!rowMetadata || allowedOverwrite.includes(actionType))) {
485
+ rowMetadata = this.doGetRowMetadata(selectedRecord);
486
+ }
487
+ else if (rowMetadata) {
488
+ rowMetadata.getProp = this.buildGetPropRowMetadata(rowMetadata);
489
+ }
301
490
  return new DataStateImpl({
302
491
  insertionMode: this.dataUnit.hasNewRecord(),
303
492
  isStartingInsertionMode,
@@ -308,20 +497,62 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
308
497
  hasDirtyRecords: this.dataUnit.hasDirtyRecords(),
309
498
  selectedRecords: undefined,
310
499
  selectionInfo,
311
- selectedRecord: this.dataUnit.getSelectedRecord(),
312
- recordsIsEmpty: this.dataUnit.records.length === 0
500
+ selectedRecord,
501
+ recordsIsEmpty: this.dataUnit.records.length === 0,
502
+ metadataByRow: this._metadataByRow,
503
+ rowMetadata
313
504
  });
314
505
  }
506
+ async handleDataSaved(action) {
507
+ const newRowMetadata = await this.handleLoadRowMetadata(action);
508
+ if (newRowMetadata) {
509
+ newRowMetadata.getProp = this.buildGetPropRowMetadata(newRowMetadata);
510
+ }
511
+ const recordId = action.payload.records[0].__record__id__;
512
+ this._metadataByRow.set(recordId, newRowMetadata);
513
+ this.dataState = this.buildDataState();
514
+ if (this.ignoreSaveMessage) {
515
+ return;
516
+ }
517
+ const saveOperation = action.payload.changes[0]._operation.toLowerCase();
518
+ const msg = this.getMessage("snkDataUnit.saveInfo", action.payload.records[0], saveOperation);
519
+ if (msg != undefined) {
520
+ this.showSuccessMessage(msg);
521
+ }
522
+ }
523
+ handleRecordsRemoved(action) {
524
+ var _a, _b;
525
+ const cachedRecords = action.payload.cachedRecords;
526
+ let removeFinishMsg;
527
+ if ((cachedRecords === null || cachedRecords === void 0 ? void 0 : cachedRecords.length) > 1) {
528
+ removeFinishMsg = this.getMessage("snkDataUnit.removeAllInfo", { size: cachedRecords.length });
529
+ }
530
+ else {
531
+ removeFinishMsg = this.getMessage("snkDataUnit.removeInfo", action.payload.cachedRecords[0]);
532
+ }
533
+ if (removeFinishMsg != undefined) {
534
+ this.showSuccessMessage(removeFinishMsg);
535
+ }
536
+ const recordsCount = (_b = (_a = this.dataUnit.records) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
537
+ const paginationInfo = this.dataUnit.getPaginationInfo();
538
+ if (paginationInfo) {
539
+ const page = recordsCount > 0 || paginationInfo.hasMore ? paginationInfo.currentPage : 0;
540
+ this.dataUnit.gotoPage(page);
541
+ }
542
+ }
315
543
  /**
316
544
  * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
317
545
  * através de um pequeno modulo na estrutura da aplicação:
318
546
  * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
319
547
  * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-data-unit.msg.ts"
320
548
  */
321
- getMessage(key, params = undefined) {
549
+ getMessage(key, params = undefined, customOperation) {
322
550
  if (!params) {
323
551
  params = this.getMessageParams();
324
552
  }
553
+ if (customOperation) {
554
+ this.messagesBuilder.currentOperation = customOperation;
555
+ }
325
556
  return this.messagesBuilder.getMessage(key, params);
326
557
  }
327
558
  getMessageParams() {
@@ -353,6 +584,7 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
353
584
  }
354
585
  }
355
586
  async loadDataUnit() {
587
+ var _a;
356
588
  if (this.dataUnit == null && this._application && this.entityName) {
357
589
  this.dataUnit = await this.getDataUnitParentOrChild();
358
590
  }
@@ -361,6 +593,10 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
361
593
  this.dataUnit.unsubscribe(this._dataUnitObserver);
362
594
  this.dataUnit.addInterceptor(this);
363
595
  this.dataUnit.subscribe(this._dataUnitObserver);
596
+ await this.dataUnit.loadMetadata();
597
+ if ((_a = this.dataUnit.records) === null || _a === void 0 ? void 0 : _a.length) {
598
+ this.getMetadataByRow(this.dataUnit);
599
+ }
364
600
  this.dataState = this.buildDataState();
365
601
  let resolver;
366
602
  while (resolver = this._onDataUnitResolve.pop()) {
@@ -379,20 +615,40 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
379
615
  return;
380
616
  }
381
617
  handlerLinkFields() {
382
- var _a, _b;
383
- const metadata = Object.assign({}, this.dataUnit.metadata);
384
- if (!this._parentDataUnit)
618
+ var _a, _b, _c, _d;
619
+ const parentDU = (_a = this._parentDataUnit) !== null && _a !== void 0 ? _a : (_b = this.dataUnit) === null || _b === void 0 ? void 0 : _b.getParentDataUnit();
620
+ if (!parentDU)
385
621
  return;
386
- const child = this._parentDataUnit.getChildInfo(this.entityName);
622
+ const childName = (_c = this.entityName) !== null && _c !== void 0 ? _c : this.getCleanDataUnitName();
623
+ const child = parentDU.getChildInfo(childName);
387
624
  if (!child)
388
625
  return;
389
- const fieldsLink = (_a = child === null || child === void 0 ? void 0 : child.links) === null || _a === void 0 ? void 0 : _a.map(link => link.target);
390
- (_b = metadata === null || metadata === void 0 ? void 0 : metadata.fields) === null || _b === void 0 ? void 0 : _b.forEach(field => {
391
- if (fieldsLink === null || fieldsLink === void 0 ? void 0 : fieldsLink.includes(field.name)) {
626
+ const links = (_d = child === null || child === void 0 ? void 0 : child.links) === null || _d === void 0 ? void 0 : _d.map(link => link.target);
627
+ this.handleDUWithLinks(links);
628
+ }
629
+ handleDUWithLinks(fieldsToLink) {
630
+ this.fieldsToLink = fieldsToLink;
631
+ const metadata = Object.assign({}, this.dataUnit.metadata);
632
+ this.processLinks(metadata);
633
+ this.dataUnit.metadata = metadata;
634
+ this.dataUnitFieldsHidded.emit();
635
+ }
636
+ processLinks(metadata) {
637
+ var _a;
638
+ (_a = metadata === null || metadata === void 0 ? void 0 : metadata.fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
639
+ var _a;
640
+ if ((_a = this.fieldsToLink) === null || _a === void 0 ? void 0 : _a.includes(field.name)) {
392
641
  field.visible = false;
393
642
  }
394
643
  });
395
- this.dataUnit.metadata = metadata;
644
+ }
645
+ getCleanDataUnitName() {
646
+ var _a;
647
+ const uri = this.dataUnit.name;
648
+ if (StringUtils.isEmpty(uri))
649
+ return uri;
650
+ const matcher = this.REGEX_DATAUNIT_NAME.exec(uri);
651
+ return (_a = matcher === null || matcher === void 0 ? void 0 : matcher[1]) !== null && _a !== void 0 ? _a : uri;
396
652
  }
397
653
  static getNearestInstance(element) {
398
654
  let parent = element.parentElement;
@@ -403,6 +659,13 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
403
659
  parent = parent.parentElement;
404
660
  }
405
661
  }
662
+ instanceMessagesBuilder() {
663
+ var _a;
664
+ if (this.messagesBuilder) {
665
+ return;
666
+ }
667
+ this.messagesBuilder = new SnkMessageBuilder((_a = this.domainMessagesBuilder) !== null && _a !== void 0 ? _a : this.entityName);
668
+ }
406
669
  //---------------------------------------------
407
670
  // Lifecycle web component
408
671
  //---------------------------------------------
@@ -410,17 +673,16 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
410
673
  this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
411
674
  this._application.getAllAccess(this.resourceID).then(access => this._permissions = access);
412
675
  this._parentSnkDataUnit = this.getParentSnkDataUnit();
413
- if (this.messagesBuilder == undefined) {
414
- this.messagesBuilder = new SnkMessageBuilder(this.entityName);
415
- }
676
+ this.instanceMessagesBuilder();
416
677
  }
417
678
  disconnectedCallback() {
418
679
  if (this.dataUnit) {
419
680
  this.dataUnit.releaseCallbacks();
420
681
  }
421
682
  }
422
- componentDidLoad() {
423
- this.loadDataUnit();
683
+ async componentDidLoad() {
684
+ await this.loadDataUnit();
685
+ this.handlerLinkFields();
424
686
  }
425
687
  render() {
426
688
  return (h(Host, null));
@@ -447,8 +709,13 @@ const SnkDataUnit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
447
709
  "ignoreSaveMessage": [4, "ignore-save-message"],
448
710
  "configName": [1, "config-name"],
449
711
  "resourceID": [1, "resource-i-d"],
712
+ "domainMessagesBuilder": [1, "domain-messages-builder"],
713
+ "fieldsToLink": [32],
450
714
  "getDataUnit": [64],
451
- "getSelectedRecordsIDsInfo": [64]
715
+ "getSelectedRecordsIDsInfo": [64],
716
+ "getFieldsWithRmp": [64],
717
+ "getFieldsWithRmPrecision": [64],
718
+ "getRowMetadata": [64]
452
719
  }]);
453
720
  class DataStateImpl {
454
721
  constructor(datastate) {
@@ -462,6 +729,8 @@ class DataStateImpl {
462
729
  this.selectionInfo = datastate.selectionInfo;
463
730
  this.selectedRecord = datastate.selectedRecord;
464
731
  this.recordsIsEmpty = datastate.recordsIsEmpty;
732
+ this.metadataByRow = datastate.metadataByRow;
733
+ this.rowMetadata = datastate.rowMetadata;
465
734
  }
466
735
  get selectedRecords() {
467
736
  var _a;
@@ -486,4 +755,4 @@ function defineCustomElement() {
486
755
  } });
487
756
  }
488
757
 
489
- export { SnkDataUnit as S, defineCustomElement as d };
758
+ export { SnkDataUnit as S, defineCustomElement as d, getSelectedIDs as g };