@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
@@ -2,54 +2,38 @@ import { Host, h } from '@stencil/core';
2
2
  import { Action, ApplicationContext, DataUnitAction, ObjectUtils } from '@sankhyalabs/core';
3
3
  import { ApplicationUtils, DialogType } from '@sankhyalabs/ezui/dist/collection/utils';
4
4
  import { OperationMap, SnkMessageBuilder } from '../../lib/message/SnkMessageBuilder';
5
+ import { DatasetStrategy } from '../../lib/http/data-fetcher/fetchers/data-unit/loadstrategy/DatasetStrategy';
6
+ import { getRecordValue } from '../../lib/dataUnit/ValueFormatter';
5
7
  import { getSelectedIDs } from '../snk-data-exporter/utils/RecordIDUtils';
6
8
  export class SnkDataUnit {
7
9
  constructor() {
8
10
  this._onDataUnitResolve = [];
9
11
  this._openedAlert = false;
10
- this._dataUnitObserver = (action) => {
11
- var _a, _b;
12
- const duState = this.buildDataState();
12
+ this._fieldsWithRmp = [];
13
+ this._fieldsWithRmPrecision = [];
14
+ this._metadataByRow = new Map();
15
+ this._rowMetadataCache = new Map();
16
+ this._dataUnitObserver = async (action) => {
17
+ const duState = this.buildDataState(action.type);
13
18
  this.dataState = duState;
14
- if (action.type === Action.DATA_SAVED) {
15
- if (this.ignoreSaveMessage) {
16
- return;
17
- }
18
- const msg = this.getMessage("snkDataUnit.saveInfo", action.payload.records[0]);
19
- if (msg != undefined) {
20
- this.showSuccessMessage(msg);
21
- }
22
- }
23
- if (action.type === Action.RECORDS_ADDED || action.type === Action.RECORDS_COPIED) {
24
- this.insertionMode.emit();
25
- }
26
- if (action.type === Action.EDITION_CANCELED) {
27
- this.cancelEdition.emit();
28
- }
29
- if (action.type === Action.RECORDS_REMOVED) {
30
- const cachedRecords = action.payload.cachedRecords;
31
- let removeFinishMsg;
32
- if ((cachedRecords === null || cachedRecords === void 0 ? void 0 : cachedRecords.length) > 1) {
33
- removeFinishMsg = this.getMessage("snkDataUnit.removeAllInfo", { size: cachedRecords.length });
34
- }
35
- else {
36
- removeFinishMsg = this.getMessage("snkDataUnit.removeInfo", action.payload.cachedRecords[0]);
37
- }
38
- if (removeFinishMsg != undefined) {
39
- this.showSuccessMessage(removeFinishMsg);
40
- }
41
- const recordsCount = (_b = (_a = this.dataUnit.records) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
42
- const paginationInfo = this.dataUnit.getPaginationInfo();
43
- if (paginationInfo) {
44
- if (recordsCount > 0 || paginationInfo.hasMore) {
45
- this.dataUnit.gotoPage(paginationInfo.currentPage);
46
- }
47
- else {
48
- this.dataUnit.gotoPage(0);
49
- }
50
- }
51
- }
52
19
  this.messagesBuilder.currentOperation = this.getMessageOperation();
20
+ switch (action.type) {
21
+ case Action.DATA_SAVED:
22
+ await this.handleDataSaved(action);
23
+ break;
24
+ case Action.RECORDS_ADDED:
25
+ case Action.RECORDS_COPIED:
26
+ this.insertionMode.emit();
27
+ break;
28
+ case Action.EDITION_CANCELED:
29
+ this.cancelEdition.emit();
30
+ break;
31
+ case Action.RECORDS_REMOVED:
32
+ this.handleRecordsRemoved(action);
33
+ break;
34
+ default:
35
+ break;
36
+ }
53
37
  };
54
38
  this.dataState = undefined;
55
39
  this.messagesBuilder = undefined;
@@ -120,141 +104,302 @@ export class SnkDataUnit {
120
104
  async getSelectedRecordsIDsInfo() {
121
105
  return Promise.resolve(getSelectedIDs(this.dataUnit));
122
106
  }
107
+ /**
108
+ * Retorna os campos que possuem a propriedade "rmp" (Row Metadata Provider).
109
+ */
110
+ async getFieldsWithRmp() {
111
+ return this._fieldsWithRmp;
112
+ }
113
+ /**
114
+ * Retorna os campos que possuem a propriedade "rm_precision" (Row Metadata Precision).
115
+ */
116
+ async getFieldsWithRmPrecision() {
117
+ return this._fieldsWithRmPrecision;
118
+ }
119
+ /**
120
+ * Busca os metadados da linha selecionada.
121
+ */
122
+ async getRowMetadata(record) {
123
+ return this.doGetRowMetadata(record);
124
+ }
125
+ doGetRowMetadata(record) {
126
+ const selectedRecord = this.dataUnit.getSelectedRecord();
127
+ if (!record && !selectedRecord) {
128
+ return;
129
+ }
130
+ const currentRecord = record || selectedRecord;
131
+ const recordId = typeof currentRecord === 'string' ? currentRecord : currentRecord.__record__id__;
132
+ const rowMetadata = this._metadataByRow.get(recordId);
133
+ if (!rowMetadata) {
134
+ return;
135
+ }
136
+ rowMetadata.getProp = this.buildGetPropRowMetadata(rowMetadata);
137
+ return Object.assign({}, rowMetadata);
138
+ }
139
+ buildGetPropRowMetadata(rowMetadata) {
140
+ return (propPath, fieldName) => {
141
+ if (propPath === "rm_precision") {
142
+ propPath = this.resolvePrecisionFromMetadata(fieldName);
143
+ }
144
+ return ObjectUtils.getProp(rowMetadata, propPath);
145
+ };
146
+ }
147
+ resolvePrecisionFromMetadata(fieldName) {
148
+ var _a, _b;
149
+ if (!fieldName) {
150
+ ApplicationUtils.error(this.getMessage("snkDataUnit.fieldNameRequired"));
151
+ return;
152
+ }
153
+ 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;
154
+ if (!rmPrecision) {
155
+ return '';
156
+ }
157
+ let rmPrecisionPath = rmPrecision.split('.').filter((_, index) => index !== 1).join('.');
158
+ return rmPrecisionPath;
159
+ }
123
160
  getCleanOnCopyFields() {
124
161
  var _a;
125
162
  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);
126
163
  }
127
- async interceptAction(action) {
128
- return new Promise(resolve => {
129
- var _a, _b, _c, _d, _e;
130
- switch (action.type) {
131
- case Action.RECORDS_ADDED:
132
- if (this.isAllowed("INSERT")) {
133
- resolve(action);
134
- }
135
- else {
136
- ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenInsert"));
137
- }
138
- break;
139
- case Action.RECORDS_COPIED:
140
- if (this.isAllowed("CLONE")) {
141
- const cleanFields = this.getCleanOnCopyFields();
142
- if (cleanFields.length > 0) {
143
- const records = action.payload;
144
- action = new DataUnitAction(Action.RECORDS_COPIED, records.map(record => {
145
- const newRecord = Object.assign({}, record);
146
- cleanFields.forEach(fieldName => delete newRecord[fieldName]);
147
- return newRecord;
148
- }));
149
- }
150
- resolve(action);
151
- }
152
- else {
153
- ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenClone"));
154
- }
155
- break;
156
- case Action.DATA_CHANGED:
157
- case Action.CHANGING_DATA:
158
- if (this.isAllowed("UPDATE"))
159
- return resolve(action);
160
- if (this._openedAlert)
161
- return this.dataUnit.cancelEdition();
162
- this._openedAlert = true;
163
- this.dataUnit.cancelEdition();
164
- ApplicationUtils.alert(this.getMessage("snkDataUnit.forbidden"), this.getMessage("snkDataUnit.forbiddenUpdate")).then(() => {
165
- this._openedAlert = false;
166
- });
167
- break;
168
- case Action.SAVING_DATA:
169
- if (this.beforeSave) {
170
- const continueAction = this.beforeSave(this.dataUnit);
171
- if (continueAction instanceof Promise) {
172
- continueAction.then(result => resolve(result ? action : undefined));
173
- }
174
- else {
175
- resolve(continueAction ? action : undefined);
176
- }
177
- }
178
- else {
179
- resolve(action);
180
- }
181
- break;
182
- case Action.DATA_SAVED:
183
- if (this.afterSave) {
184
- this.afterSave(this.dataUnit);
185
- }
186
- else {
187
- resolve(action);
188
- }
189
- break;
190
- case Action.EDITION_CANCELED:
191
- if (!this.useCancelConfirm)
192
- return resolve(action);
193
- if (this.dataState.hasDirtyRecords) {
194
- const cancelConfirmation = this.getMessage("snkDataUnit.cancelConfirmation");
195
- if (((_a = action.payload) === null || _a === void 0 ? void 0 : _a.fromParent) || ((_b = action.payload) === null || _b === void 0 ? void 0 : _b.silent)) {
196
- resolve(action);
197
- return;
198
- }
199
- if (cancelConfirmation == undefined) {
200
- this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
201
- resolve(action);
202
- }
203
- else {
204
- const cancelConfirmationTitle = this.getMessage("snkDataUnit.cancelConfirmationTitle");
205
- ApplicationUtils.confirm(cancelConfirmationTitle, cancelConfirmation)
206
- .then((result) => {
207
- result && this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
208
- resolve(result ? action : undefined);
209
- });
210
- }
211
- }
212
- else {
213
- resolve(action);
214
- }
215
- break;
216
- case Action.REMOVING_RECORDS:
217
- if (this.isAllowed("REMOVE")) {
218
- let multipleSelection = false;
219
- let removeConfirmation = !((_c = action.payload) === null || _c === void 0 ? void 0 : _c.silent) && this.getMessage("snkDataUnit.removeConfirmation");
220
- const selection = (_d = this.dataUnit) === null || _d === void 0 ? void 0 : _d.getSelectionInfo();
221
- if (!((_e = action.payload) === null || _e === void 0 ? void 0 : _e.silent) && (selection === null || selection === void 0 ? void 0 : selection.length) > 1) {
222
- removeConfirmation = this.getMessage("snkDataUnit.removeAllConfirmation", { size: selection.length });
223
- multipleSelection = true;
224
- }
225
- if (!removeConfirmation) {
226
- resolve(action);
227
- }
228
- else {
229
- const options = {
230
- canClose: false,
231
- labelCancel: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "no" : "cancel"}`),
232
- labelConfirm: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "yes" : "delete"}`),
233
- btnConfirmDanger: false
234
- };
235
- const removeConfirmationTitle = this.getMessage("snkDataUnit.removeConfirmationTitle");
236
- ApplicationUtils.confirm(removeConfirmationTitle, removeConfirmation, null, DialogType.WARN, options)
237
- .then((result) => resolve(result ? action : undefined));
238
- }
239
- }
240
- else {
241
- ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenRemove"));
242
- }
243
- break;
244
- default:
245
- resolve(action);
164
+ fillFieldsWithRmp(payload) {
165
+ payload.fields.forEach((field) => {
166
+ var _a;
167
+ if (((_a = field.properties) === null || _a === void 0 ? void 0 : _a.rmp) && !this._fieldsWithRmp.includes(field.name)) {
168
+ this._fieldsWithRmp.push(field.name);
169
+ }
170
+ });
171
+ }
172
+ fillFieldsWithRmPrecision(payload) {
173
+ payload.fields.forEach((field) => {
174
+ var _a;
175
+ if (((_a = field.properties) === null || _a === void 0 ? void 0 : _a.rm_precision) && !this._fieldsWithRmPrecision.includes(field.name)) {
176
+ this._fieldsWithRmPrecision.push(field.name);
246
177
  }
247
178
  });
248
179
  }
180
+ getCacheName(fieldName, metadataName, fieldValue) {
181
+ const cacheName = [fieldName, metadataName, fieldValue].join("_");
182
+ return cacheName;
183
+ }
184
+ updateDataStateRmp(newValue) {
185
+ Object.assign(this.dataState.rowMetadata || {}, newValue);
186
+ }
187
+ saveCacheRmd(record) {
188
+ const rmd = record.__record__metadata__;
189
+ const keysRmd = Object.keys(rmd);
190
+ keysRmd.shift();
191
+ keysRmd.forEach((fieldName) => {
192
+ const fieldValue = getRecordValue(record, fieldName);
193
+ const cacheName = this.getCacheName(fieldName, rmd.provider, fieldValue);
194
+ this._rowMetadataCache.set(cacheName, Object.assign({}, rmd));
195
+ });
196
+ }
197
+ getMetadataByRow(payload) {
198
+ var _a;
199
+ if (!((_a = payload.records) === null || _a === void 0 ? void 0 : _a.length)) {
200
+ return payload;
201
+ }
202
+ if (!this._fieldsWithRmp.length) {
203
+ const records = payload.records.map((record) => {
204
+ delete record.__record__metadata__;
205
+ return record;
206
+ });
207
+ return Object.assign(Object.assign({}, payload), { records });
208
+ }
209
+ const records = payload.records.map((record) => {
210
+ if (!record.__record__metadata__) {
211
+ return record;
212
+ }
213
+ this.saveCacheRmd(record);
214
+ const rowMetadata = Object.assign({}, record.__record__metadata__);
215
+ rowMetadata.getProp = this.buildGetPropRowMetadata(rowMetadata);
216
+ this._metadataByRow.set(record.__record__id__, rowMetadata);
217
+ delete record.__record__metadata__;
218
+ return record;
219
+ });
220
+ return Object.assign(Object.assign({}, payload), { records });
221
+ }
222
+ interceptRecordsAdded(action) {
223
+ if (!this.isAllowed("INSERT")) {
224
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenInsert"));
225
+ return;
226
+ }
227
+ return action;
228
+ }
229
+ interceptRecordsCopied(action) {
230
+ if (!this.isAllowed("CLONE")) {
231
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenClone"));
232
+ return;
233
+ }
234
+ const cleanFields = this.getCleanOnCopyFields();
235
+ if (cleanFields.length > 0) {
236
+ const records = action.payload;
237
+ action = new DataUnitAction(Action.RECORDS_COPIED, records.map(record => {
238
+ const newRecord = Object.assign({}, record);
239
+ cleanFields.forEach(fieldName => delete newRecord[fieldName]);
240
+ return newRecord;
241
+ }));
242
+ }
243
+ return action;
244
+ }
245
+ async interceptDataChange(action) {
246
+ if (this.isAllowed("UPDATE")) {
247
+ return action;
248
+ }
249
+ if (this._openedAlert) {
250
+ await this.dataUnit.cancelEdition();
251
+ return;
252
+ }
253
+ this._openedAlert = true;
254
+ await this.dataUnit.cancelEdition();
255
+ await ApplicationUtils.alert(this.getMessage("snkDataUnit.forbidden"), this.getMessage("snkDataUnit.forbiddenUpdate"));
256
+ this._openedAlert = false;
257
+ }
258
+ async interceptSavingData(action) {
259
+ if (!this.beforeSave) {
260
+ return action;
261
+ }
262
+ const continueAction = this.beforeSave(this.dataUnit);
263
+ if (continueAction instanceof Promise) {
264
+ const result = await continueAction;
265
+ return result ? action : undefined;
266
+ }
267
+ return continueAction ? action : undefined;
268
+ }
269
+ interceptDataSaved(action) {
270
+ if (this.afterSave) {
271
+ this.afterSave(this.dataUnit);
272
+ return;
273
+ }
274
+ return action;
275
+ }
276
+ async interceptEditionCanceled(action) {
277
+ var _a, _b;
278
+ 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)) {
279
+ return action;
280
+ }
281
+ const cancelConfirmation = this.getMessage("snkDataUnit.cancelConfirmation");
282
+ if (cancelConfirmation == undefined) {
283
+ this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
284
+ return action;
285
+ }
286
+ const cancelConfirmationTitle = this.getMessage("snkDataUnit.cancelConfirmationTitle");
287
+ const confirm = await ApplicationUtils.confirm(cancelConfirmationTitle, cancelConfirmation);
288
+ confirm && this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
289
+ return confirm ? action : undefined;
290
+ }
291
+ async interceptRemovingRecords(action) {
292
+ var _a, _b, _c;
293
+ if (!this.isAllowed("REMOVE")) {
294
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenRemove"));
295
+ return;
296
+ }
297
+ let multipleSelection = false;
298
+ let removeConfirmation = !((_a = action.payload) === null || _a === void 0 ? void 0 : _a.silent) && this.getMessage("snkDataUnit.removeConfirmation");
299
+ const selection = (_b = this.dataUnit) === null || _b === void 0 ? void 0 : _b.getSelectionInfo();
300
+ if (!((_c = action.payload) === null || _c === void 0 ? void 0 : _c.silent) && (selection === null || selection === void 0 ? void 0 : selection.length) > 1) {
301
+ removeConfirmation = this.getMessage("snkDataUnit.removeAllConfirmation", { size: selection.length });
302
+ multipleSelection = true;
303
+ }
304
+ if (!removeConfirmation) {
305
+ return action;
306
+ }
307
+ const options = {
308
+ canClose: false,
309
+ labelCancel: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "no" : "cancel"}`),
310
+ labelConfirm: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "yes" : "delete"}`),
311
+ btnConfirmDanger: false
312
+ };
313
+ const removeConfirmationTitle = this.getMessage("snkDataUnit.removeConfirmationTitle");
314
+ const confirm = await ApplicationUtils.confirm(removeConfirmationTitle, removeConfirmation, null, DialogType.WARN, options);
315
+ return confirm ? action : undefined;
316
+ }
317
+ interceptDataLoaded(action) {
318
+ const newPayload = this.getMetadataByRow(action.payload);
319
+ action = new DataUnitAction(Action.DATA_LOADED, newPayload);
320
+ return action;
321
+ }
322
+ interceptMetadataLoaded(action) {
323
+ this.fillFieldsWithRmp(action.payload);
324
+ this.fillFieldsWithRmPrecision(action.payload);
325
+ return action;
326
+ }
327
+ async interceptAction(action) {
328
+ switch (action.type) {
329
+ case Action.RECORDS_ADDED:
330
+ return this.interceptRecordsAdded(action);
331
+ case Action.RECORDS_COPIED:
332
+ return this.interceptRecordsCopied(action);
333
+ case Action.DATA_CHANGED:
334
+ await this.handleLoadRowMetadata(action);
335
+ return await this.interceptDataChange(action);
336
+ case Action.CHANGING_DATA:
337
+ return await this.interceptDataChange(action);
338
+ case Action.SAVING_DATA:
339
+ return await this.interceptSavingData(action);
340
+ case Action.DATA_SAVED:
341
+ return this.interceptDataSaved(action);
342
+ case Action.EDITION_CANCELED:
343
+ return await this.interceptEditionCanceled(action);
344
+ case Action.REMOVING_RECORDS:
345
+ return await this.interceptRemovingRecords(action);
346
+ case Action.DATA_LOADED:
347
+ return this.interceptDataLoaded(action);
348
+ case Action.METADATA_LOADED:
349
+ return this.interceptMetadataLoaded(action);
350
+ default:
351
+ return action;
352
+ }
353
+ }
354
+ async handleLoadRowMetadata(action) {
355
+ const record = action.type === Action.DATA_CHANGED ? action.payload : action.payload.changes[0].record;
356
+ const keysPayload = Object.keys(record);
357
+ const rmpField = keysPayload.find((field) => this._fieldsWithRmp.includes(field));
358
+ if (rmpField) {
359
+ const metadataName = this.dataUnit.getField(rmpField).properties.rmp;
360
+ const fieldValue = getRecordValue(record, rmpField);
361
+ return await this.updateRowMetadata({
362
+ fieldName: rmpField,
363
+ fieldValue,
364
+ metadataName,
365
+ updatedFields: record,
366
+ });
367
+ }
368
+ }
369
+ async updateRowMetadata({ fieldName, fieldValue, metadataName, updatedFields }) {
370
+ const cacheName = this.getCacheName(fieldName, metadataName, fieldValue);
371
+ const cacheValue = this._rowMetadataCache.get(cacheName);
372
+ if (cacheValue) {
373
+ this.updateDataStateRmp(cacheValue);
374
+ return cacheValue;
375
+ }
376
+ else {
377
+ const datasetStrategy = new DatasetStrategy();
378
+ const response = await datasetStrategy.loadRowMetadata(this, fieldName, metadataName, updatedFields);
379
+ this.updateDataStateRmp(response._rmd);
380
+ this._rowMetadataCache.set(cacheName, Object.assign({}, response._rmd));
381
+ return Object.assign({}, response._rmd);
382
+ }
383
+ }
249
384
  showSuccessMessage(message) {
250
385
  ApplicationUtils.info(message, { iconName: "check" });
251
386
  }
252
387
  isAllowed(flag) {
253
388
  return this._permissions ? this._permissions.isSup || this._permissions[flag] : false;
254
389
  }
255
- buildDataState() {
390
+ buildDataState(actionType) {
391
+ var _a;
256
392
  const selectionInfo = this.dataUnit.getSelectionInfo();
257
393
  const isStartingInsertionMode = (this.dataUnit.hasDirtyRecords() || this.dataUnit.hasWaitingChanges()) && (selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.isEmpty());
394
+ const selectedRecord = this.dataUnit.getSelectedRecord();
395
+ let rowMetadata = (_a = this.dataState) === null || _a === void 0 ? void 0 : _a.rowMetadata;
396
+ const allowedOverwrite = [Action.SELECTION_CHANGED, Action.EDITION_CANCELED, Action.NEXT_SELECTED, Action.PREVIOUS_SELECTED];
397
+ if (selectedRecord && (!rowMetadata || allowedOverwrite.includes(actionType))) {
398
+ rowMetadata = this.doGetRowMetadata(selectedRecord);
399
+ }
400
+ else if (rowMetadata) {
401
+ rowMetadata.getProp = this.buildGetPropRowMetadata(rowMetadata);
402
+ }
258
403
  return new DataStateImpl({
259
404
  insertionMode: this.dataUnit.hasNewRecord(),
260
405
  isStartingInsertionMode,
@@ -265,10 +410,48 @@ export class SnkDataUnit {
265
410
  hasDirtyRecords: this.dataUnit.hasDirtyRecords(),
266
411
  selectedRecords: undefined,
267
412
  selectionInfo,
268
- selectedRecord: this.dataUnit.getSelectedRecord(),
269
- recordsIsEmpty: this.dataUnit.records.length === 0
413
+ selectedRecord,
414
+ recordsIsEmpty: this.dataUnit.records.length === 0,
415
+ metadataByRow: this._metadataByRow,
416
+ rowMetadata
270
417
  });
271
418
  }
419
+ async handleDataSaved(action) {
420
+ const newRowMetadata = await this.handleLoadRowMetadata(action);
421
+ if (newRowMetadata) {
422
+ newRowMetadata.getProp = this.buildGetPropRowMetadata(newRowMetadata);
423
+ }
424
+ const recordId = action.payload.records[0].__record__id__;
425
+ this._metadataByRow.set(recordId, newRowMetadata);
426
+ this.dataState = this.buildDataState();
427
+ if (this.ignoreSaveMessage) {
428
+ return;
429
+ }
430
+ const msg = this.getMessage("snkDataUnit.saveInfo", action.payload.records[0]);
431
+ if (msg != undefined) {
432
+ this.showSuccessMessage(msg);
433
+ }
434
+ }
435
+ handleRecordsRemoved(action) {
436
+ var _a, _b;
437
+ const cachedRecords = action.payload.cachedRecords;
438
+ let removeFinishMsg;
439
+ if ((cachedRecords === null || cachedRecords === void 0 ? void 0 : cachedRecords.length) > 1) {
440
+ removeFinishMsg = this.getMessage("snkDataUnit.removeAllInfo", { size: cachedRecords.length });
441
+ }
442
+ else {
443
+ removeFinishMsg = this.getMessage("snkDataUnit.removeInfo", action.payload.cachedRecords[0]);
444
+ }
445
+ if (removeFinishMsg != undefined) {
446
+ this.showSuccessMessage(removeFinishMsg);
447
+ }
448
+ const recordsCount = (_b = (_a = this.dataUnit.records) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
449
+ const paginationInfo = this.dataUnit.getPaginationInfo();
450
+ if (paginationInfo) {
451
+ const page = recordsCount > 0 || paginationInfo.hasMore ? paginationInfo.currentPage : 0;
452
+ this.dataUnit.gotoPage(page);
453
+ }
454
+ }
272
455
  /**
273
456
  * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
274
457
  * através de um pequeno modulo na estrutura da aplicação:
@@ -303,13 +486,14 @@ export class SnkDataUnit {
303
486
  const cacheName = this.dataUnitName ? this.dataUnitName : this.entityName;
304
487
  if (this._parentSnkDataUnit) {
305
488
  this._parentDataUnit = await ((_a = this._parentSnkDataUnit) === null || _a === void 0 ? void 0 : _a.getDataUnit());
306
- return await this._application.getDataUnit(this.entityName, cacheName, this._parentDataUnit, this.configName, this.resourceID);
489
+ return await this._application.getDataUnit(this.entityName, cacheName, this._parentDataUnit, this.configName, this.resourceID, { skipLoadMetadata: true });
307
490
  }
308
491
  else {
309
- return await this._application.getDataUnit(this.entityName, cacheName, null, this.configName, this.resourceID);
492
+ return await this._application.getDataUnit(this.entityName, cacheName, null, this.configName, this.resourceID, { skipLoadMetadata: true });
310
493
  }
311
494
  }
312
495
  async loadDataUnit() {
496
+ var _a;
313
497
  if (this.dataUnit == null && this._application && this.entityName) {
314
498
  this.dataUnit = await this.getDataUnitParentOrChild();
315
499
  }
@@ -318,6 +502,10 @@ export class SnkDataUnit {
318
502
  this.dataUnit.unsubscribe(this._dataUnitObserver);
319
503
  this.dataUnit.addInterceptor(this);
320
504
  this.dataUnit.subscribe(this._dataUnitObserver);
505
+ await this.dataUnit.loadMetadata();
506
+ if ((_a = this.dataUnit.records) === null || _a === void 0 ? void 0 : _a.length) {
507
+ this.getMetadataByRow(this.dataUnit);
508
+ }
321
509
  this.dataState = this.buildDataState();
322
510
  let resolver;
323
511
  while (resolver = this._onDataUnitResolve.pop()) {
@@ -750,6 +938,64 @@ export class SnkDataUnit {
750
938
  "text": "Retorna a lista de IDs dos registros selecionados."
751
939
  }]
752
940
  }
941
+ },
942
+ "getFieldsWithRmp": {
943
+ "complexType": {
944
+ "signature": "() => Promise<string[]>",
945
+ "parameters": [],
946
+ "references": {
947
+ "Promise": {
948
+ "location": "global"
949
+ }
950
+ },
951
+ "return": "Promise<string[]>"
952
+ },
953
+ "docs": {
954
+ "text": "Retorna os campos que possuem a propriedade \"rmp\" (Row Metadata Provider).",
955
+ "tags": []
956
+ }
957
+ },
958
+ "getFieldsWithRmPrecision": {
959
+ "complexType": {
960
+ "signature": "() => Promise<string[]>",
961
+ "parameters": [],
962
+ "references": {
963
+ "Promise": {
964
+ "location": "global"
965
+ }
966
+ },
967
+ "return": "Promise<string[]>"
968
+ },
969
+ "docs": {
970
+ "text": "Retorna os campos que possuem a propriedade \"rm_precision\" (Row Metadata Precision).",
971
+ "tags": []
972
+ }
973
+ },
974
+ "getRowMetadata": {
975
+ "complexType": {
976
+ "signature": "(record?: Record | string) => Promise<RowMetadata>",
977
+ "parameters": [{
978
+ "tags": [],
979
+ "text": ""
980
+ }],
981
+ "references": {
982
+ "Promise": {
983
+ "location": "global"
984
+ },
985
+ "RowMetadata": {
986
+ "location": "local"
987
+ },
988
+ "Record": {
989
+ "location": "import",
990
+ "path": "@sankhyalabs/core"
991
+ }
992
+ },
993
+ "return": "Promise<RowMetadata>"
994
+ },
995
+ "docs": {
996
+ "text": "Busca os metadados da linha selecionada.",
997
+ "tags": []
998
+ }
753
999
  }
754
1000
  };
755
1001
  }
@@ -788,6 +1034,8 @@ class DataStateImpl {
788
1034
  this.selectionInfo = datastate.selectionInfo;
789
1035
  this.selectedRecord = datastate.selectedRecord;
790
1036
  this.recordsIsEmpty = datastate.recordsIsEmpty;
1037
+ this.metadataByRow = datastate.metadataByRow;
1038
+ this.rowMetadata = datastate.rowMetadata;
791
1039
  }
792
1040
  get selectedRecords() {
793
1041
  var _a;
@@ -0,0 +1,24 @@
1
+ import { DataType } from "@sankhyalabs/core";
2
+ const metadataMock = {
3
+ label: 'metadataMock',
4
+ name: 'metadataMock',
5
+ fields: [
6
+ {
7
+ name: 'TESTE',
8
+ label: 'Teste',
9
+ dataType: DataType.TEXT,
10
+ properties: {
11
+ rm_precision: 'TESTERMP.PRODUTORMP.decVlr'
12
+ }
13
+ },
14
+ {
15
+ name: 'TESTERMP',
16
+ label: 'Teste com RMP',
17
+ dataType: DataType.TEXT,
18
+ properties: {
19
+ rmp: 'PRODUTORMP'
20
+ }
21
+ }
22
+ ]
23
+ };
24
+ export default metadataMock;