@sankhyalabs/sankhyablocks 8.15.0-rc.12 → 8.15.0-rc.14

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 (73) hide show
  1. package/dist/cjs/{ConfigStorage-34be11ce.js → ConfigStorage-8d4e9d53.js} +1 -1
  2. package/dist/cjs/{SnkFormConfigManager-531a191c.js → SnkFormConfigManager-33995e92.js} +2 -2
  3. package/dist/cjs/{SnkMultiSelectionListDataSource-5213120b.js → SnkMultiSelectionListDataSource-1438f8f2.js} +1 -1
  4. package/dist/cjs/{auth-fetcher-5161d082.js → auth-fetcher-bb8e9ae4.js} +1 -1
  5. package/dist/cjs/{form-config-fetcher-9f1a13ca.js → form-config-fetcher-d73f4449.js} +12 -0
  6. package/dist/cjs/loader.cjs.js +1 -1
  7. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  8. package/dist/cjs/snk-actions-button_4.cjs.entry.js +2 -2
  9. package/dist/cjs/snk-application.cjs.entry.js +3 -3
  10. package/dist/cjs/snk-attach.cjs.entry.js +2 -2
  11. package/dist/cjs/snk-crud.cjs.entry.js +2 -2
  12. package/dist/cjs/snk-detail-view.cjs.entry.js +4 -4
  13. package/dist/cjs/snk-filter-bar.cjs.entry.js +2 -2
  14. package/dist/cjs/snk-filter-modal-item.cjs.entry.js +2 -2
  15. package/dist/cjs/snk-form-config.cjs.entry.js +1 -1
  16. package/dist/cjs/snk-form.cjs.entry.js +3 -3
  17. package/dist/cjs/snk-grid.cjs.entry.js +3 -3
  18. package/dist/cjs/{snk-guides-viewer-76b4c346.js → snk-guides-viewer-25721856.js} +2 -2
  19. package/dist/cjs/snk-guides-viewer.cjs.entry.js +4 -4
  20. package/dist/cjs/snk-personalized-filter.cjs.entry.js +2 -2
  21. package/dist/cjs/snk-simple-crud.cjs.entry.js +60 -42
  22. package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +76 -39
  23. package/dist/collection/lib/http/data-fetcher/fetchers/form-config-fetcher.js +12 -0
  24. package/dist/components/form-config-fetcher.js +12 -0
  25. package/dist/components/snk-simple-crud2.js +58 -39
  26. package/dist/esm/{ConfigStorage-101a2b4c.js → ConfigStorage-6e241cd7.js} +1 -1
  27. package/dist/esm/{SnkFormConfigManager-02ecf57f.js → SnkFormConfigManager-7a4e678f.js} +2 -2
  28. package/dist/esm/{SnkMultiSelectionListDataSource-7e7eada5.js → SnkMultiSelectionListDataSource-aad5d4ff.js} +1 -1
  29. package/dist/esm/{auth-fetcher-17dc5b5e.js → auth-fetcher-8ec448b0.js} +1 -1
  30. package/dist/esm/{form-config-fetcher-f121f880.js → form-config-fetcher-765b8498.js} +12 -0
  31. package/dist/esm/loader.js +1 -1
  32. package/dist/esm/sankhyablocks.js +1 -1
  33. package/dist/esm/snk-actions-button_4.entry.js +2 -2
  34. package/dist/esm/snk-application.entry.js +3 -3
  35. package/dist/esm/snk-attach.entry.js +2 -2
  36. package/dist/esm/snk-crud.entry.js +2 -2
  37. package/dist/esm/snk-detail-view.entry.js +4 -4
  38. package/dist/esm/snk-filter-bar.entry.js +2 -2
  39. package/dist/esm/snk-filter-modal-item.entry.js +2 -2
  40. package/dist/esm/snk-form-config.entry.js +1 -1
  41. package/dist/esm/snk-form.entry.js +3 -3
  42. package/dist/esm/snk-grid.entry.js +3 -3
  43. package/dist/esm/{snk-guides-viewer-90ca9105.js → snk-guides-viewer-b94752f2.js} +2 -2
  44. package/dist/esm/snk-guides-viewer.entry.js +4 -4
  45. package/dist/esm/snk-personalized-filter.entry.js +2 -2
  46. package/dist/esm/snk-simple-crud.entry.js +60 -42
  47. package/dist/sankhyablocks/p-004c356e.js +26 -0
  48. package/dist/sankhyablocks/{p-5c0b53ce.js → p-0624f62d.js} +1 -1
  49. package/dist/sankhyablocks/{p-d01ceda6.entry.js → p-0bba5c9f.entry.js} +1 -1
  50. package/dist/sankhyablocks/{p-663ff67b.entry.js → p-1048bd26.entry.js} +1 -1
  51. package/dist/sankhyablocks/p-125bb902.js +1 -0
  52. package/dist/sankhyablocks/{p-7ddd95b6.entry.js → p-24ed6ad6.entry.js} +1 -1
  53. package/dist/sankhyablocks/{p-1f3174cb.entry.js → p-2d919e32.entry.js} +1 -1
  54. package/dist/sankhyablocks/{p-1fa5a18c.entry.js → p-400097f2.entry.js} +1 -1
  55. package/dist/sankhyablocks/{p-2897fb8c.js → p-6c9adfca.js} +1 -1
  56. package/dist/sankhyablocks/{p-b41a622a.entry.js → p-85ba3d6b.entry.js} +1 -1
  57. package/dist/sankhyablocks/{p-384fd6ae.js → p-88b29791.js} +1 -1
  58. package/dist/sankhyablocks/{p-ba4871b5.entry.js → p-9e8618ec.entry.js} +1 -1
  59. package/dist/sankhyablocks/p-a043314f.entry.js +1 -0
  60. package/dist/sankhyablocks/{p-e7c1bce4.entry.js → p-a1642e7c.entry.js} +1 -1
  61. package/dist/sankhyablocks/{p-6b28cc74.entry.js → p-ac77949b.entry.js} +1 -1
  62. package/dist/sankhyablocks/{p-2cfe0c2c.entry.js → p-b47c2963.entry.js} +1 -1
  63. package/dist/sankhyablocks/{p-7e05bd83.entry.js → p-bf39bdb8.entry.js} +1 -1
  64. package/dist/sankhyablocks/{p-8111f63f.entry.js → p-d5cb4b5a.entry.js} +1 -1
  65. package/dist/sankhyablocks/{p-fad4c2fe.js → p-efeca7ba.js} +1 -1
  66. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  67. package/dist/types/components/snk-simple-crud/snk-simple-crud.d.ts +11 -3
  68. package/dist/types/components.d.ts +8 -0
  69. package/dist/types/lib/http/data-fetcher/fetchers/form-config-fetcher.d.ts +2 -0
  70. package/package.json +1 -1
  71. package/dist/sankhyablocks/p-50783a8b.js +0 -1
  72. package/dist/sankhyablocks/p-a13ccb86.js +0 -26
  73. package/dist/sankhyablocks/p-a83487a0.entry.js +0 -1
@@ -8,16 +8,16 @@ const constants = require('./constants-35ddd366.js');
8
8
  const taskbarElements = require('./taskbar-elements-3ecd1278.js');
9
9
  require('./DataFetcher-99f0f6ed.js');
10
10
  const pesquisaFetcher = require('./pesquisa-fetcher-94f6b316.js');
11
- const SnkMultiSelectionListDataSource = require('./SnkMultiSelectionListDataSource-5213120b.js');
11
+ const SnkMultiSelectionListDataSource = require('./SnkMultiSelectionListDataSource-1438f8f2.js');
12
12
  const index$1 = require('./index-0922807b.js');
13
13
  require('./ISave-e91b70a7.js');
14
14
  require('@sankhyalabs/ezui/dist/collection/utils/constants');
15
15
  require('@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata');
16
16
  require('./filter-item-type.enum-a7ffdaa6.js');
17
- require('./form-config-fetcher-9f1a13ca.js');
17
+ const formConfigFetcher = require('./form-config-fetcher-d73f4449.js');
18
18
  const fieldSearch = require('./field-search-f56aa7d6.js');
19
- const ConfigStorage = require('./ConfigStorage-34be11ce.js');
20
- const SnkFormConfigManager = require('./SnkFormConfigManager-531a191c.js');
19
+ const ConfigStorage = require('./ConfigStorage-8d4e9d53.js');
20
+ const SnkFormConfigManager = require('./SnkFormConfigManager-33995e92.js');
21
21
  require('./index-102ba62d.js');
22
22
  require('./PrintUtils-bcaeb82f.js');
23
23
  require('@sankhyalabs/ezui/dist/collection/components/ez-grid/utils');
@@ -40,6 +40,7 @@ const SnkSimpleCrud = class {
40
40
  this.configuratorCancel = index.createEvent(this, "configuratorCancel", 7);
41
41
  this._multiSelectionListDataSource = new SnkMultiSelectionListDataSource.SnkMultiSelectionListDataSource();
42
42
  this._keyDownHandler = (event) => this.keyDownListener(event);
43
+ this._formConfigFetcher = new formConfigFetcher.FormConfigFetcher();
43
44
  this._taskbarProcessor = new fieldSearch.TaskbarProcessor({
44
45
  "snkSimpleCrudTaskbar.form_regular": this.getButtons(false, taskbarElements.TaskbarElement.GRID_MODE),
45
46
  "snkSimpleCrudTaskbar.grid_regular": this.getButtons(false, taskbarElements.TaskbarElement.FORM_MODE),
@@ -61,6 +62,7 @@ const SnkSimpleCrud = class {
61
62
  this._formFields = [];
62
63
  this.multipleSelection = undefined;
63
64
  this.useCancelConfirm = true;
65
+ this.resourceID = undefined;
64
66
  this.taskbarManager = undefined;
65
67
  this.messagesBuilder = undefined;
66
68
  this.useEnterLikeTab = false;
@@ -71,6 +73,16 @@ const SnkSimpleCrud = class {
71
73
  this.formLegacyConfigName = undefined;
72
74
  this.ignoreReadOnlyFormFields = false;
73
75
  }
76
+ handleResourceIDChanged(newValue, oldValue) {
77
+ if (core.StringUtils.isEmpty(newValue)) {
78
+ return;
79
+ }
80
+ if (newValue === oldValue) {
81
+ return;
82
+ }
83
+ this.loadFormConfig(true);
84
+ this.loadGridConfig(true);
85
+ }
74
86
  getButtons(selected, changeModeBtn) {
75
87
  return this.addConfigButton(this.resolveInMemoryBtns(selected ? REGULAR_SELECTED_BTNS : REGULAR_DEFAULT_BTNS)
76
88
  .concat(changeModeBtn));
@@ -123,43 +135,29 @@ const SnkSimpleCrud = class {
123
135
  this.dataStateChange.emit(newValue);
124
136
  }
125
137
  }
126
- async observeFormLegacy() {
127
- await this.handleUpdateFormLegacyConfig();
138
+ async observeFormLegacy(newValue, oldValue) {
139
+ await this.handleUpdateFormLegacyConfig(newValue, oldValue);
128
140
  }
129
- async observeGridLegacy() {
130
- await this.handleUpdateGridLegacyConfig();
141
+ async observeGridLegacy(newValue, oldValue) {
142
+ await this.handleUpdateGridLegacyConfig(newValue, oldValue);
131
143
  }
132
- async handleUpdateGridLegacyConfig() {
133
- if (this.gridLegacyConfigName) {
134
- this.addGridLegacyConfigName();
135
- if (this._gridConfigAlreadyLoaded) {
136
- await this.loadGridConfig(true);
137
- }
144
+ async handleUpdateGridLegacyConfig(newValue, oldValue) {
145
+ if (newValue == undefined || newValue == oldValue) {
146
+ return;
138
147
  }
139
- }
140
- async handleUpdateFormLegacyConfig() {
141
- var _a, _b, _c;
142
- if (this.formLegacyConfigName) {
143
- const legacyConfig = await this.fetchFormLegacyConfig();
144
- if (!legacyConfig)
145
- return;
146
- const rawFields = (_c = (_b = (_a = legacyConfig === null || legacyConfig === void 0 ? void 0 : legacyConfig.formConfig) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.field) !== null && _c !== void 0 ? _c : [];
147
- const fields = Array.isArray(rawFields) ? rawFields : [rawFields];
148
- const newConfig = { emptyConfig: false, fields: fields };
149
- this.setFormConfig(newConfig, true);
150
- this._formConfigManager.setConfig(this.formConfig);
148
+ if (!this._gridConfigAlreadyLoaded) {
149
+ return;
151
150
  }
151
+ await this.loadGridConfig(true);
152
152
  }
153
- async fetchFormLegacyConfig() {
154
- const payload = {
155
- 'requestBody': {
156
- 'config': {
157
- 'chave': this.formLegacyConfigName,
158
- 'tipo': 'T',
159
- },
160
- },
161
- };
162
- return await this.application.callServiceBroker('SystemUtilsSP.getConf', JSON.stringify(payload));
153
+ async handleUpdateFormLegacyConfig(newValue, oldValue) {
154
+ if (newValue == undefined || newValue == oldValue) {
155
+ return;
156
+ }
157
+ if (!this._formConfigAlreadyLoaded) {
158
+ return;
159
+ }
160
+ this.loadFormConfig(true);
163
161
  }
164
162
  openConfig(viewMode) {
165
163
  this._snkConfigurator.close();
@@ -190,12 +188,16 @@ const SnkSimpleCrud = class {
190
188
  }
191
189
  }
192
190
  loadGridConfig(forceUpdate) {
191
+ if (this.configName === undefined) {
192
+ return;
193
+ }
193
194
  if ((this.gridConfig != undefined || this._gridConfigAlreadyLoaded) && !forceUpdate) {
194
195
  return;
195
196
  }
197
+ this.addGridLegacyConfigName();
196
198
  this._gridConfigAlreadyLoaded = true;
197
199
  return new Promise((accept, reject) => {
198
- ConfigStorage.ConfigStorage.loadGridConfig(this.configName, this._resourceID)
200
+ ConfigStorage.ConfigStorage.loadGridConfig(this.configName, this.resolveResourceID())
199
201
  .then(config => {
200
202
  this.setGridConfig(config);
201
203
  accept();
@@ -205,15 +207,27 @@ const SnkSimpleCrud = class {
205
207
  });
206
208
  });
207
209
  }
208
- async loadFormConfig() {
210
+ formConfigIsLoaded() {
211
+ return this.formConfig != undefined || this._formConfigAlreadyLoaded;
212
+ }
213
+ async loadFormConfig(forceLoad = false) {
214
+ if (this.configName === undefined) {
215
+ return;
216
+ }
209
217
  if (this._formConfigManager == undefined) {
210
- this._formConfigManager = new SnkFormConfigManager.SnkFormConfigManager(this.configName, this._resourceID);
218
+ this._formConfigManager = new SnkFormConfigManager.SnkFormConfigManager(this.configName, this.resolveResourceID());
211
219
  this._formConfigManager.setConfig(this.formConfig);
212
220
  }
213
- if (this.formConfig != undefined || this._formConfigAlreadyLoaded) {
221
+ if (this.formConfigIsLoaded() && !forceLoad) {
214
222
  return;
215
223
  }
216
224
  this._formConfigAlreadyLoaded = true;
225
+ let loadedLegacyConfig = await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);
226
+ if (loadedLegacyConfig != undefined) {
227
+ this._formConfigManager.setConfig(loadedLegacyConfig);
228
+ this.setFormConfig(loadedLegacyConfig);
229
+ return;
230
+ }
217
231
  this.setFormConfig(await this._formConfigManager.loadConfig());
218
232
  }
219
233
  async componentWillRender() {
@@ -469,7 +483,7 @@ const SnkSimpleCrud = class {
469
483
  }
470
484
  gridConfigChangeHandler(evt) {
471
485
  const config = evt.detail;
472
- ConfigStorage.ConfigStorage.saveGridConfig(config, this.configName, this._resourceID);
486
+ ConfigStorage.ConfigStorage.saveGridConfig(config, this.configName, this.resolveResourceID());
473
487
  evt.stopPropagation();
474
488
  }
475
489
  modalConfigChangeHandler(evt) {
@@ -500,6 +514,9 @@ const SnkSimpleCrud = class {
500
514
  handleShowFormConfig() {
501
515
  return this._showFormConfig && !this.formLegacyConfigName;
502
516
  }
517
+ resolveResourceID() {
518
+ return core.StringUtils.isEmpty(this.resourceID) ? this._resourceID : this.resourceID;
519
+ }
503
520
  /* istanbul ignore next */
504
521
  render() {
505
522
  var _a, _b, _c;
@@ -508,10 +525,11 @@ const SnkSimpleCrud = class {
508
525
  }
509
526
  return (index.h("snk-data-unit", { class: "simple-crud__container", dataUnit: this.dataUnit, useCancelConfirm: this.useCancelConfirm, onDataStateChange: evt => this.onDataStateChange(evt), onCancelEdition: this.handleCancelEdit.bind(this), onInsertionMode: () => this.goToView(constants.VIEW_MODE.FORM), onDataUnitReady: (evt) => this.dataUnitReady.emit(evt.detail), ignoreSaveMessage: this._currentViewMode === constants.VIEW_MODE.GRID, onMessagesBuilderUpdated: evt => this.messagesBuilder = evt.detail }, index.h("header", null, index.h("slot", { name: "snkSimpleCrudHeader" })), index.h("section", { class: "ez-box ez-box--shadow simple-crud__container-section" }, index.h("snk-taskbar", { class: "ez-box ez-box--shadow ez-padding--medium", dataUnit: this.dataUnit, primaryButton: ((_a = this.dataState) === null || _a === void 0 ? void 0 : _a.isDirty) ? "SAVE" : "INSERT", "data-element-id": "grid_left", messagesBuilder: this.messagesBuilder, buttons: this._taskbarProcessor.buttons, actionsList: this.getActionsList(), disabledButtons: this._taskbarProcessor.disabledButtons, customButtons: this._taskbarProcessor.customButtons, slot: "leftButtons", presentationMode: index$1.PresentationMode.SECONDARY }, index.h("slot", { name: "TASKBAR_CUSTOM_ELEMENTS" })), index.h("ez-view-stack", { ref: (ref) => this._viewStack = ref, "data-element-id": "simple-crud" }, index.h("stack-item", null, index.h("ez-grid", { class: "ez-margin-bottom--large", ref: ref => this._grid = ref, dataUnit: this.dataUnit, config: this.gridConfig, "no-header": true, multipleSelection: this.multipleSelection, onEzDoubleClick: () => this.goToView(constants.VIEW_MODE.FORM), onConfigChange: evt => this.gridConfigChangeHandler(evt), columnfilterDataSource: this.dataUnit.name && this.dataUnit.name.includes(pesquisaFetcher.InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME)
510
527
  ? undefined
511
- : this._multiSelectionListDataSource, useEnterLikeTab: this.useEnterLikeTab }, index.h("div", { slot: "footer" }, index.h("slot", { name: "snkSimpleCrudFooter" })))), index.h("stack-item", null, index.h("ez-form", { class: `ez-margin-top--large ${this.handleShowFormConfig() ? "simple-crud__form--hidden" : ""}`, dataUnit: this.dataUnit, config: (_b = this._formConfigManager) === null || _b === void 0 ? void 0 : _b.getConfig((_c = this.dataState) === null || _c === void 0 ? void 0 : _c.insertionMode, this.dataUnit, this.ignoreReadOnlyFormFields), fieldToFocus: this._fieldToGetFocus, onEzFormSetFields: (evt) => this.handleFormSetFields(evt.detail), onEzFormRequestClearFieldToFocus: this.clearFieldToFocusHandler.bind(this) }), this.handleShowFormConfig() && index.h("snk-form-config", { messagesBuilder: this.messagesBuilder, dataUnit: this.dataUnit, configManager: this._formConfigManager, onConfigClose: () => this.closeFormConfig() })), this.messagesBuilder && index.h("snk-configurator", { ref: (ref) => this._snkConfigurator = ref, viewMode: this._currentViewMode, messagesBuilder: this.messagesBuilder, onConfigSelected: (evt) => this.goToView(evt.detail), onOpenConfig: (evt) => this.openConfig(evt.detail), showActionButtons: this.showConfiguratorButtons, onSave: evt => this.handleConfiguratorEvent(evt, 'SAVE'), onCancel: evt => this.handleConfiguratorEvent(evt, 'CANCEL'), resourceID: this._resourceID, customContainerId: this._customContainerId })), index.h("div", { id: `${this._customContainerId}` }, index.h("slot", { name: "SnkConfigContainerSlot" }))), index.h("ez-modal", { modalSize: "small", closeEsc: false, closeOutsideClick: false, opened: this._showPopUpGridConfig, onEzCloseModal: () => this.closeGridConfig() }, index.h("snk-grid-config", { ref: ref => this._snkGridConfig = ref, config: this.gridConfig, "data-element-id": this._element.getAttribute(core.ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME), selectedIndex: 0, configName: this.configName, onConfigChange: (evt) => this.modalConfigChangeHandler(evt), onConfigCancel: () => this.closeGridConfig(), resourceID: this._resourceID }))));
528
+ : this._multiSelectionListDataSource, useEnterLikeTab: this.useEnterLikeTab }, index.h("div", { slot: "footer" }, index.h("slot", { name: "snkSimpleCrudFooter" })))), index.h("stack-item", null, index.h("ez-form", { class: `ez-margin-top--large ${this.handleShowFormConfig() ? "simple-crud__form--hidden" : ""}`, dataUnit: this.dataUnit, config: (_b = this._formConfigManager) === null || _b === void 0 ? void 0 : _b.getConfig((_c = this.dataState) === null || _c === void 0 ? void 0 : _c.insertionMode, this.dataUnit, this.ignoreReadOnlyFormFields), fieldToFocus: this._fieldToGetFocus, onEzFormSetFields: (evt) => this.handleFormSetFields(evt.detail), onEzFormRequestClearFieldToFocus: this.clearFieldToFocusHandler.bind(this) }), this.handleShowFormConfig() && index.h("snk-form-config", { messagesBuilder: this.messagesBuilder, dataUnit: this.dataUnit, configManager: this._formConfigManager, onConfigClose: () => this.closeFormConfig() })), this.messagesBuilder && index.h("snk-configurator", { ref: (ref) => this._snkConfigurator = ref, viewMode: this._currentViewMode, messagesBuilder: this.messagesBuilder, onConfigSelected: (evt) => this.goToView(evt.detail), onOpenConfig: (evt) => this.openConfig(evt.detail), showActionButtons: this.showConfiguratorButtons, onSave: evt => this.handleConfiguratorEvent(evt, 'SAVE'), onCancel: evt => this.handleConfiguratorEvent(evt, 'CANCEL'), resourceID: this.resolveResourceID(), customContainerId: this._customContainerId })), index.h("div", { id: `${this._customContainerId}` }, index.h("slot", { name: "SnkConfigContainerSlot" }))), index.h("ez-modal", { modalSize: "small", closeEsc: false, closeOutsideClick: false, opened: this._showPopUpGridConfig, onEzCloseModal: () => this.closeGridConfig() }, index.h("snk-grid-config", { ref: ref => this._snkGridConfig = ref, config: this.gridConfig, "data-element-id": this._element.getAttribute(core.ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME), selectedIndex: 0, configName: this.configName, onConfigChange: (evt) => this.modalConfigChangeHandler(evt), onConfigCancel: () => this.closeGridConfig(), resourceID: this.resolveResourceID() }))));
512
529
  }
513
530
  get _element() { return index.getElement(this); }
514
531
  static get watchers() { return {
532
+ "resourceID": ["handleResourceIDChanged"],
515
533
  "mode": ["onModeChange"],
516
534
  "dataState": ["observeDataState"],
517
535
  "formLegacyConfigName": ["observeFormLegacy"],
@@ -2,7 +2,7 @@ import { ApplicationContext, DataType, ElementIDUtils, FloatingManager, JSUtils,
2
2
  import { h } from '@stencil/core';
3
3
  import { SIMPLE_CRUD_MODE, VIEW_MODE } from '../../lib/utils/constants';
4
4
  import { TaskbarElement } from '../snk-taskbar/elements/taskbar-elements';
5
- import { CrudUtils, PresentationMode } from '../../lib';
5
+ import { CrudUtils, FormConfigFetcher, PresentationMode } from '../../lib';
6
6
  import TaskbarProcessor from '../snk-taskbar/processor/taskbar-processor';
7
7
  import InMemoryLoader from '../../lib/dataUnit/InMemoryLoader';
8
8
  import SnkMultiSelectionListDataSource from '../snk-grid/filtercolumn/SnkMultiSelectionListDataSource';
@@ -14,6 +14,7 @@ export class SnkSimpleCrud {
14
14
  constructor() {
15
15
  this._multiSelectionListDataSource = new SnkMultiSelectionListDataSource();
16
16
  this._keyDownHandler = (event) => this.keyDownListener(event);
17
+ this._formConfigFetcher = new FormConfigFetcher();
17
18
  this._taskbarProcessor = new TaskbarProcessor({
18
19
  "snkSimpleCrudTaskbar.form_regular": this.getButtons(false, TaskbarElement.GRID_MODE),
19
20
  "snkSimpleCrudTaskbar.grid_regular": this.getButtons(false, TaskbarElement.FORM_MODE),
@@ -35,6 +36,7 @@ export class SnkSimpleCrud {
35
36
  this._formFields = [];
36
37
  this.multipleSelection = undefined;
37
38
  this.useCancelConfirm = true;
39
+ this.resourceID = undefined;
38
40
  this.taskbarManager = undefined;
39
41
  this.messagesBuilder = undefined;
40
42
  this.useEnterLikeTab = false;
@@ -45,6 +47,16 @@ export class SnkSimpleCrud {
45
47
  this.formLegacyConfigName = undefined;
46
48
  this.ignoreReadOnlyFormFields = false;
47
49
  }
50
+ handleResourceIDChanged(newValue, oldValue) {
51
+ if (StringUtils.isEmpty(newValue)) {
52
+ return;
53
+ }
54
+ if (newValue === oldValue) {
55
+ return;
56
+ }
57
+ this.loadFormConfig(true);
58
+ this.loadGridConfig(true);
59
+ }
48
60
  getButtons(selected, changeModeBtn) {
49
61
  return this.addConfigButton(this.resolveInMemoryBtns(selected ? REGULAR_SELECTED_BTNS : REGULAR_DEFAULT_BTNS)
50
62
  .concat(changeModeBtn));
@@ -97,43 +109,29 @@ export class SnkSimpleCrud {
97
109
  this.dataStateChange.emit(newValue);
98
110
  }
99
111
  }
100
- async observeFormLegacy() {
101
- await this.handleUpdateFormLegacyConfig();
112
+ async observeFormLegacy(newValue, oldValue) {
113
+ await this.handleUpdateFormLegacyConfig(newValue, oldValue);
102
114
  }
103
- async observeGridLegacy() {
104
- await this.handleUpdateGridLegacyConfig();
115
+ async observeGridLegacy(newValue, oldValue) {
116
+ await this.handleUpdateGridLegacyConfig(newValue, oldValue);
105
117
  }
106
- async handleUpdateGridLegacyConfig() {
107
- if (this.gridLegacyConfigName) {
108
- this.addGridLegacyConfigName();
109
- if (this._gridConfigAlreadyLoaded) {
110
- await this.loadGridConfig(true);
111
- }
118
+ async handleUpdateGridLegacyConfig(newValue, oldValue) {
119
+ if (newValue == undefined || newValue == oldValue) {
120
+ return;
112
121
  }
113
- }
114
- async handleUpdateFormLegacyConfig() {
115
- var _a, _b, _c;
116
- if (this.formLegacyConfigName) {
117
- const legacyConfig = await this.fetchFormLegacyConfig();
118
- if (!legacyConfig)
119
- return;
120
- const rawFields = (_c = (_b = (_a = legacyConfig === null || legacyConfig === void 0 ? void 0 : legacyConfig.formConfig) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.field) !== null && _c !== void 0 ? _c : [];
121
- const fields = Array.isArray(rawFields) ? rawFields : [rawFields];
122
- const newConfig = { emptyConfig: false, fields: fields };
123
- this.setFormConfig(newConfig, true);
124
- this._formConfigManager.setConfig(this.formConfig);
122
+ if (!this._gridConfigAlreadyLoaded) {
123
+ return;
125
124
  }
125
+ await this.loadGridConfig(true);
126
126
  }
127
- async fetchFormLegacyConfig() {
128
- const payload = {
129
- 'requestBody': {
130
- 'config': {
131
- 'chave': this.formLegacyConfigName,
132
- 'tipo': 'T',
133
- },
134
- },
135
- };
136
- return await this.application.callServiceBroker('SystemUtilsSP.getConf', JSON.stringify(payload));
127
+ async handleUpdateFormLegacyConfig(newValue, oldValue) {
128
+ if (newValue == undefined || newValue == oldValue) {
129
+ return;
130
+ }
131
+ if (!this._formConfigAlreadyLoaded) {
132
+ return;
133
+ }
134
+ this.loadFormConfig(true);
137
135
  }
138
136
  openConfig(viewMode) {
139
137
  this._snkConfigurator.close();
@@ -164,12 +162,16 @@ export class SnkSimpleCrud {
164
162
  }
165
163
  }
166
164
  loadGridConfig(forceUpdate) {
165
+ if (this.configName === undefined) {
166
+ return;
167
+ }
167
168
  if ((this.gridConfig != undefined || this._gridConfigAlreadyLoaded) && !forceUpdate) {
168
169
  return;
169
170
  }
171
+ this.addGridLegacyConfigName();
170
172
  this._gridConfigAlreadyLoaded = true;
171
173
  return new Promise((accept, reject) => {
172
- ConfigStorage.loadGridConfig(this.configName, this._resourceID)
174
+ ConfigStorage.loadGridConfig(this.configName, this.resolveResourceID())
173
175
  .then(config => {
174
176
  this.setGridConfig(config);
175
177
  accept();
@@ -179,15 +181,27 @@ export class SnkSimpleCrud {
179
181
  });
180
182
  });
181
183
  }
182
- async loadFormConfig() {
184
+ formConfigIsLoaded() {
185
+ return this.formConfig != undefined || this._formConfigAlreadyLoaded;
186
+ }
187
+ async loadFormConfig(forceLoad = false) {
188
+ if (this.configName === undefined) {
189
+ return;
190
+ }
183
191
  if (this._formConfigManager == undefined) {
184
- this._formConfigManager = new SnkFormConfigManager(this.configName, this._resourceID);
192
+ this._formConfigManager = new SnkFormConfigManager(this.configName, this.resolveResourceID());
185
193
  this._formConfigManager.setConfig(this.formConfig);
186
194
  }
187
- if (this.formConfig != undefined || this._formConfigAlreadyLoaded) {
195
+ if (this.formConfigIsLoaded() && !forceLoad) {
188
196
  return;
189
197
  }
190
198
  this._formConfigAlreadyLoaded = true;
199
+ let loadedLegacyConfig = await this._formConfigFetcher.fetchLegacyConfigurableForm(this.formLegacyConfigName);
200
+ if (loadedLegacyConfig != undefined) {
201
+ this._formConfigManager.setConfig(loadedLegacyConfig);
202
+ this.setFormConfig(loadedLegacyConfig);
203
+ return;
204
+ }
191
205
  this.setFormConfig(await this._formConfigManager.loadConfig());
192
206
  }
193
207
  async componentWillRender() {
@@ -443,7 +457,7 @@ export class SnkSimpleCrud {
443
457
  }
444
458
  gridConfigChangeHandler(evt) {
445
459
  const config = evt.detail;
446
- ConfigStorage.saveGridConfig(config, this.configName, this._resourceID);
460
+ ConfigStorage.saveGridConfig(config, this.configName, this.resolveResourceID());
447
461
  evt.stopPropagation();
448
462
  }
449
463
  modalConfigChangeHandler(evt) {
@@ -474,6 +488,9 @@ export class SnkSimpleCrud {
474
488
  handleShowFormConfig() {
475
489
  return this._showFormConfig && !this.formLegacyConfigName;
476
490
  }
491
+ resolveResourceID() {
492
+ return StringUtils.isEmpty(this.resourceID) ? this._resourceID : this.resourceID;
493
+ }
477
494
  /* istanbul ignore next */
478
495
  render() {
479
496
  var _a, _b, _c;
@@ -482,7 +499,7 @@ export class SnkSimpleCrud {
482
499
  }
483
500
  return (h("snk-data-unit", { class: "simple-crud__container", dataUnit: this.dataUnit, useCancelConfirm: this.useCancelConfirm, onDataStateChange: evt => this.onDataStateChange(evt), onCancelEdition: this.handleCancelEdit.bind(this), onInsertionMode: () => this.goToView(VIEW_MODE.FORM), onDataUnitReady: (evt) => this.dataUnitReady.emit(evt.detail), ignoreSaveMessage: this._currentViewMode === VIEW_MODE.GRID, onMessagesBuilderUpdated: evt => this.messagesBuilder = evt.detail }, h("header", null, h("slot", { name: "snkSimpleCrudHeader" })), h("section", { class: "ez-box ez-box--shadow simple-crud__container-section" }, h("snk-taskbar", { class: "ez-box ez-box--shadow ez-padding--medium", dataUnit: this.dataUnit, primaryButton: ((_a = this.dataState) === null || _a === void 0 ? void 0 : _a.isDirty) ? "SAVE" : "INSERT", "data-element-id": "grid_left", messagesBuilder: this.messagesBuilder, buttons: this._taskbarProcessor.buttons, actionsList: this.getActionsList(), disabledButtons: this._taskbarProcessor.disabledButtons, customButtons: this._taskbarProcessor.customButtons, slot: "leftButtons", presentationMode: PresentationMode.SECONDARY }, h("slot", { name: "TASKBAR_CUSTOM_ELEMENTS" })), h("ez-view-stack", { ref: (ref) => this._viewStack = ref, "data-element-id": "simple-crud" }, h("stack-item", null, h("ez-grid", { class: "ez-margin-bottom--large", ref: ref => this._grid = ref, dataUnit: this.dataUnit, config: this.gridConfig, "no-header": true, multipleSelection: this.multipleSelection, onEzDoubleClick: () => this.goToView(VIEW_MODE.FORM), onConfigChange: evt => this.gridConfigChangeHandler(evt), columnfilterDataSource: this.dataUnit.name && this.dataUnit.name.includes(InMemoryLoader.IN_MEMORY_DATA_UNIT_NAME)
484
501
  ? undefined
485
- : this._multiSelectionListDataSource, useEnterLikeTab: this.useEnterLikeTab }, h("div", { slot: "footer" }, h("slot", { name: "snkSimpleCrudFooter" })))), h("stack-item", null, h("ez-form", { class: `ez-margin-top--large ${this.handleShowFormConfig() ? "simple-crud__form--hidden" : ""}`, dataUnit: this.dataUnit, config: (_b = this._formConfigManager) === null || _b === void 0 ? void 0 : _b.getConfig((_c = this.dataState) === null || _c === void 0 ? void 0 : _c.insertionMode, this.dataUnit, this.ignoreReadOnlyFormFields), fieldToFocus: this._fieldToGetFocus, onEzFormSetFields: (evt) => this.handleFormSetFields(evt.detail), onEzFormRequestClearFieldToFocus: this.clearFieldToFocusHandler.bind(this) }), this.handleShowFormConfig() && h("snk-form-config", { messagesBuilder: this.messagesBuilder, dataUnit: this.dataUnit, configManager: this._formConfigManager, onConfigClose: () => this.closeFormConfig() })), this.messagesBuilder && h("snk-configurator", { ref: (ref) => this._snkConfigurator = ref, viewMode: this._currentViewMode, messagesBuilder: this.messagesBuilder, onConfigSelected: (evt) => this.goToView(evt.detail), onOpenConfig: (evt) => this.openConfig(evt.detail), showActionButtons: this.showConfiguratorButtons, onSave: evt => this.handleConfiguratorEvent(evt, 'SAVE'), onCancel: evt => this.handleConfiguratorEvent(evt, 'CANCEL'), resourceID: this._resourceID, customContainerId: this._customContainerId })), h("div", { id: `${this._customContainerId}` }, h("slot", { name: "SnkConfigContainerSlot" }))), h("ez-modal", { modalSize: "small", closeEsc: false, closeOutsideClick: false, opened: this._showPopUpGridConfig, onEzCloseModal: () => this.closeGridConfig() }, h("snk-grid-config", { ref: ref => this._snkGridConfig = ref, config: this.gridConfig, "data-element-id": this._element.getAttribute(ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME), selectedIndex: 0, configName: this.configName, onConfigChange: (evt) => this.modalConfigChangeHandler(evt), onConfigCancel: () => this.closeGridConfig(), resourceID: this._resourceID }))));
502
+ : this._multiSelectionListDataSource, useEnterLikeTab: this.useEnterLikeTab }, h("div", { slot: "footer" }, h("slot", { name: "snkSimpleCrudFooter" })))), h("stack-item", null, h("ez-form", { class: `ez-margin-top--large ${this.handleShowFormConfig() ? "simple-crud__form--hidden" : ""}`, dataUnit: this.dataUnit, config: (_b = this._formConfigManager) === null || _b === void 0 ? void 0 : _b.getConfig((_c = this.dataState) === null || _c === void 0 ? void 0 : _c.insertionMode, this.dataUnit, this.ignoreReadOnlyFormFields), fieldToFocus: this._fieldToGetFocus, onEzFormSetFields: (evt) => this.handleFormSetFields(evt.detail), onEzFormRequestClearFieldToFocus: this.clearFieldToFocusHandler.bind(this) }), this.handleShowFormConfig() && h("snk-form-config", { messagesBuilder: this.messagesBuilder, dataUnit: this.dataUnit, configManager: this._formConfigManager, onConfigClose: () => this.closeFormConfig() })), this.messagesBuilder && h("snk-configurator", { ref: (ref) => this._snkConfigurator = ref, viewMode: this._currentViewMode, messagesBuilder: this.messagesBuilder, onConfigSelected: (evt) => this.goToView(evt.detail), onOpenConfig: (evt) => this.openConfig(evt.detail), showActionButtons: this.showConfiguratorButtons, onSave: evt => this.handleConfiguratorEvent(evt, 'SAVE'), onCancel: evt => this.handleConfiguratorEvent(evt, 'CANCEL'), resourceID: this.resolveResourceID(), customContainerId: this._customContainerId })), h("div", { id: `${this._customContainerId}` }, h("slot", { name: "SnkConfigContainerSlot" }))), h("ez-modal", { modalSize: "small", closeEsc: false, closeOutsideClick: false, opened: this._showPopUpGridConfig, onEzCloseModal: () => this.closeGridConfig() }, h("snk-grid-config", { ref: ref => this._snkGridConfig = ref, config: this.gridConfig, "data-element-id": this._element.getAttribute(ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME), selectedIndex: 0, configName: this.configName, onConfigChange: (evt) => this.modalConfigChangeHandler(evt), onConfigCancel: () => this.closeGridConfig(), resourceID: this.resolveResourceID() }))));
486
503
  }
487
504
  static get is() { return "snk-simple-crud"; }
488
505
  static get encapsulation() { return "scoped"; }
@@ -636,6 +653,23 @@ export class SnkSimpleCrud {
636
653
  "reflect": false,
637
654
  "defaultValue": "true"
638
655
  },
656
+ "resourceID": {
657
+ "type": "string",
658
+ "mutable": false,
659
+ "complexType": {
660
+ "original": "string",
661
+ "resolved": "string",
662
+ "references": {}
663
+ },
664
+ "required": false,
665
+ "optional": false,
666
+ "docs": {
667
+ "tags": [],
668
+ "text": "Identificador de recursos como configura\u00E7\u00F5es e acesso."
669
+ },
670
+ "attribute": "resource-i-d",
671
+ "reflect": false
672
+ },
639
673
  "taskbarManager": {
640
674
  "type": "unknown",
641
675
  "mutable": false,
@@ -1060,6 +1094,9 @@ export class SnkSimpleCrud {
1060
1094
  static get elementRef() { return "_element"; }
1061
1095
  static get watchers() {
1062
1096
  return [{
1097
+ "propName": "resourceID",
1098
+ "methodName": "handleResourceIDChanged"
1099
+ }, {
1063
1100
  "propName": "mode",
1064
1101
  "methodName": "onModeChange"
1065
1102
  }, {
@@ -168,6 +168,18 @@ export class FormConfigFetcher extends ResourceFetcher {
168
168
  }
169
169
  return `cfg://${authority}/${resourceID}`;
170
170
  }
171
+ async fetchLegacyConfigurableForm(configName) {
172
+ const payload = { 'requestBody': { 'config': { 'chave': configName, 'tipo': 'T' } } };
173
+ const response = await DataFetcher.get().callServiceBroker('SystemUtilsSP.getConf', JSON.stringify(payload));
174
+ if (ObjectUtils.isEmpty(response))
175
+ return undefined;
176
+ return this.buildLegacyConfigurableForm(response);
177
+ }
178
+ buildLegacyConfigurableForm(config) {
179
+ var _a, _b, _c;
180
+ const rawFields = (_c = (_b = (_a = config === null || config === void 0 ? void 0 : config.formConfig) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.field) !== null && _c !== void 0 ? _c : [];
181
+ return { emptyConfig: false, fields: Array.isArray(rawFields) ? rawFields : [rawFields] };
182
+ }
171
183
  }
172
184
  export var UserConfigType;
173
185
  (function (UserConfigType) {
@@ -230,6 +230,18 @@ class FormConfigFetcher extends ResourceFetcher {
230
230
  }
231
231
  return `cfg://${authority}/${resourceID}`;
232
232
  }
233
+ async fetchLegacyConfigurableForm(configName) {
234
+ const payload = { 'requestBody': { 'config': { 'chave': configName, 'tipo': 'T' } } };
235
+ const response = await DataFetcher.get().callServiceBroker('SystemUtilsSP.getConf', JSON.stringify(payload));
236
+ if (ObjectUtils.isEmpty(response))
237
+ return undefined;
238
+ return this.buildLegacyConfigurableForm(response);
239
+ }
240
+ buildLegacyConfigurableForm(config) {
241
+ var _a, _b, _c;
242
+ const rawFields = (_c = (_b = (_a = config === null || config === void 0 ? void 0 : config.formConfig) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.field) !== null && _c !== void 0 ? _c : [];
243
+ return { emptyConfig: false, fields: Array.isArray(rawFields) ? rawFields : [rawFields] };
244
+ }
233
245
  }
234
246
  var UserConfigType;
235
247
  (function (UserConfigType) {