@sankhyalabs/sankhyablocks 3.4.0 → 3.4.2

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 (63) hide show
  1. package/dist/cjs/{ConfigStorage-8b5e3261.js → ConfigStorage-cfac5a0b.js} +184 -36
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  4. package/dist/cjs/snk-application.cjs.entry.js +1 -111
  5. package/dist/cjs/snk-configurator_3.cjs.entry.js +9 -8
  6. package/dist/cjs/snk-data-exporter_8.cjs.entry.js +23 -33
  7. package/dist/cjs/snk-form-config.cjs.entry.js +3 -5
  8. package/dist/cjs/snk-form.cjs.entry.js +10 -12
  9. package/dist/collection/components/snk-application/snk-application.js +2 -129
  10. package/dist/collection/components/snk-filter-bar/snk-filter-bar.js +15 -12
  11. package/dist/collection/components/snk-form/snk-form.js +9 -11
  12. package/dist/collection/components/snk-form/subcomponents/snk-form-config/snk-form-config.js +2 -4
  13. package/dist/collection/components/snk-grid/snk-grid.js +8 -7
  14. package/dist/collection/components/snk-grid/subcomponents/snk-grid-config/snk-grid-config.js +23 -45
  15. package/dist/collection/lib/configs/ConfigStorage.js +22 -12
  16. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +49 -2
  17. package/dist/collection/lib/http/data-fetcher/fetchers/filter-bar-config-fetcher.js +8 -2
  18. package/dist/collection/lib/http/data-fetcher/fetchers/form-config-fetcher.js +23 -18
  19. package/dist/collection/lib/http/data-fetcher/fetchers/grid-config-fetcher.js +11 -5
  20. package/dist/collection/lib/http/data-fetcher/interfaces/IClientEventResponse.js +1 -0
  21. package/dist/collection/lib/http/data-fetcher/recaller/DataFetcherRecaller.js +14 -0
  22. package/dist/components/ConfigStorage.js +123 -35
  23. package/dist/components/DataFetcher.js +62 -2
  24. package/dist/components/index.d.ts +1 -1
  25. package/dist/components/snk-application2.js +0 -113
  26. package/dist/components/snk-filter-bar2.js +15 -12
  27. package/dist/components/snk-form-config2.js +2 -4
  28. package/dist/components/snk-form2.js +9 -11
  29. package/dist/components/snk-grid-config.js +2 -2
  30. package/dist/components/snk-grid-config2.js +9 -21
  31. package/dist/components/snk-grid2.js +8 -7
  32. package/dist/esm/{ConfigStorage-4654f57b.js → ConfigStorage-77bd9902.js} +185 -37
  33. package/dist/esm/loader.js +1 -1
  34. package/dist/esm/sankhyablocks.js +1 -1
  35. package/dist/esm/snk-application.entry.js +1 -111
  36. package/dist/esm/snk-configurator_3.entry.js +9 -8
  37. package/dist/esm/snk-data-exporter_8.entry.js +23 -33
  38. package/dist/esm/snk-form-config.entry.js +3 -5
  39. package/dist/esm/snk-form.entry.js +10 -12
  40. package/dist/sankhyablocks/p-032e1308.entry.js +1 -0
  41. package/dist/sankhyablocks/{p-e906ba66.entry.js → p-32f9dc8a.entry.js} +5 -5
  42. package/dist/sankhyablocks/p-43c135c4.entry.js +1 -0
  43. package/dist/sankhyablocks/{p-f559c71a.entry.js → p-705b7671.entry.js} +1 -1
  44. package/dist/sankhyablocks/{p-93d8ea09.js → p-bbd0cf7a.js} +6 -6
  45. package/dist/sankhyablocks/p-db6d6b59.entry.js +1 -0
  46. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  47. package/dist/types/components/snk-application/snk-application.d.ts +1 -16
  48. package/dist/types/components/snk-filter-bar/snk-filter-bar.d.ts +1 -1
  49. package/dist/types/components/snk-grid/snk-grid.d.ts +2 -2
  50. package/dist/types/components/snk-grid/subcomponents/snk-grid-config/snk-grid-config.d.ts +5 -5
  51. package/dist/types/components.d.ts +8 -16
  52. package/dist/types/lib/configs/ConfigStorage.d.ts +7 -2
  53. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +7 -1
  54. package/dist/types/lib/http/data-fetcher/fetchers/filter-bar-config-fetcher.d.ts +3 -2
  55. package/dist/types/lib/http/data-fetcher/fetchers/form-config-fetcher.d.ts +2 -1
  56. package/dist/types/lib/http/data-fetcher/fetchers/grid-config-fetcher.d.ts +3 -2
  57. package/dist/types/lib/http/data-fetcher/fetchers/resource-fetcher.d.ts +5 -1
  58. package/dist/types/lib/http/data-fetcher/interfaces/IClientEventResponse.d.ts +4 -0
  59. package/dist/types/lib/http/data-fetcher/recaller/DataFetcherRecaller.d.ts +7 -0
  60. package/package.json +1 -1
  61. package/dist/sankhyablocks/p-125c2d01.entry.js +0 -1
  62. package/dist/sankhyablocks/p-a2ea13ed.entry.js +0 -1
  63. package/dist/sankhyablocks/p-b326cf51.entry.js +0 -1
@@ -93,15 +93,17 @@ class FormConfigFetcher extends ResourceFetcher {
93
93
  }
94
94
  loadFormConfig(formName, resourceID) {
95
95
  return new Promise((accept, reject) => {
96
- this.loadResource(`cfg://form/${resourceID}/${formName}`)
97
- .then((configAsString) => {
98
- if (configAsString) {
99
- const config = JSON.parse(configAsString);
100
- const { tabs, fields } = config;
101
- if (tabs) {
102
- const allTabs = new Map(tabs.map(t => [t.label, t]));
103
- fields === null || fields === void 0 ? void 0 : fields.forEach(f => { var _a; return f.tab = ((_a = allTabs.get(this.getTabName(f.tab))) === null || _a === void 0 ? void 0 : _a.label) || allTabs.get(this.getTabName(f.tab)); });
104
- }
96
+ Promise.all([
97
+ this.loadResource(this.getPath(resourceID, formName))
98
+ ])
99
+ .then(([configAsString]) => {
100
+ const config = configAsString ? JSON.parse(configAsString) : {};
101
+ const { tabs, fields } = config;
102
+ if (tabs) {
103
+ const allTabs = new Map(tabs.map(t => [t.label, t]));
104
+ fields === null || fields === void 0 ? void 0 : fields.forEach(f => { var _a; return f.tab = ((_a = allTabs.get(this.getTabName(f.tab))) === null || _a === void 0 ? void 0 : _a.label) || allTabs.get(this.getTabName(f.tab)); });
105
+ }
106
+ if (fields) {
105
107
  config.fields = fields === null || fields === void 0 ? void 0 : fields.map((field) => {
106
108
  if ("readonly" in field) {
107
109
  const readOnly = field['readonly'] === true;
@@ -110,11 +112,8 @@ class FormConfigFetcher extends ResourceFetcher {
110
112
  }
111
113
  return field;
112
114
  });
113
- accept(config);
114
- }
115
- else {
116
- reject(`Sem configuração pro formulário "${formName}".`);
117
115
  }
116
+ accept(config);
118
117
  })
119
118
  .catch((error) => {
120
119
  reject(error);
@@ -128,11 +127,11 @@ class FormConfigFetcher extends ResourceFetcher {
128
127
  return tab; //string type
129
128
  }
130
129
  saveConfig(config, formName, resourceID) {
131
- const completePath = `cfg://form/${resourceID}/${formName}`;
130
+ const completePath = this.getPath(resourceID, formName);
132
131
  return new Promise((resolve, reject) => {
133
132
  this.saveResource(config, completePath)
134
133
  .then((resp) => {
135
- resolve(resp);
134
+ resolve(JSON.parse(resp.resource));
136
135
  })
137
136
  .catch((error) => {
138
137
  reject(error);
@@ -140,7 +139,7 @@ class FormConfigFetcher extends ResourceFetcher {
140
139
  });
141
140
  }
142
141
  fetchUserAvailableConfigs(formName, resourceID) {
143
- const name = `cfg://form/${resourceID}/${formName}`;
142
+ const name = this.getPath(resourceID, formName);
144
143
  return new Promise((resolve, reject) => {
145
144
  DataFetcher.get()
146
145
  .callGraphQL({
@@ -156,7 +155,7 @@ class FormConfigFetcher extends ResourceFetcher {
156
155
  });
157
156
  }
158
157
  fetchLegacyConfig(formName, resourceID) {
159
- const name = `cfg://form/${resourceID}/${formName}`;
158
+ const name = this.getPath(resourceID, formName);
160
159
  return new Promise((resolve, reject) => {
161
160
  DataFetcher.get()
162
161
  .callGraphQL({
@@ -172,7 +171,7 @@ class FormConfigFetcher extends ResourceFetcher {
172
171
  });
173
172
  }
174
173
  fetchDefaultConfig(formName, resourceID) {
175
- const name = `cfg://form/${resourceID}/${formName}`;
174
+ const name = this.getPath(resourceID, formName);
176
175
  return new Promise((resolve, reject) => {
177
176
  DataFetcher.get()
178
177
  .callGraphQL({
@@ -187,6 +186,12 @@ class FormConfigFetcher extends ResourceFetcher {
187
186
  });
188
187
  });
189
188
  }
189
+ getPath(resourceID, name, authority = "form") {
190
+ if (name) {
191
+ return `cfg://${authority}/${resourceID}/${name}`;
192
+ }
193
+ return `cfg://${authority}/${resourceID}`;
194
+ }
190
195
  }
191
196
  var UserConfigType;
192
197
  (function (UserConfigType) {
@@ -200,8 +205,8 @@ class GridConfigFetcher extends ResourceFetcher {
200
205
  super(...arguments);
201
206
  this.GRID_CONFIG_VERSION = "V3:";
202
207
  }
203
- getConfig(_gridName, resourceID) {
204
- const completePath = `cfg://grid/${this.GRID_CONFIG_VERSION}${resourceID}`;
208
+ getConfig(gridName, resourceID) {
209
+ const completePath = this.getPath(resourceID, gridName);
205
210
  return new Promise((resolve, reject) => {
206
211
  this.loadResource(completePath)
207
212
  .then(loadedResource => {
@@ -215,23 +220,98 @@ class GridConfigFetcher extends ResourceFetcher {
215
220
  });
216
221
  });
217
222
  }
218
- saveConfig(config, resourceID) {
219
- const completePath = `cfg://grid/${this.GRID_CONFIG_VERSION}${resourceID}`;
223
+ saveConfig(config, gridName, resourceID) {
224
+ const completePath = this.getPath(resourceID, gridName);
220
225
  return new Promise((resolve, reject) => {
221
226
  this.saveResource(config, completePath)
222
227
  .then((resp) => {
223
- resolve(resp);
228
+ resolve(JSON.parse(resp.resource));
224
229
  })
225
230
  .catch((error) => {
226
231
  reject(error);
227
232
  });
228
233
  });
229
234
  }
235
+ getPath(resourceID, name) {
236
+ if (name) {
237
+ return `cfg://grid/${this.GRID_CONFIG_VERSION}${resourceID}/${name}`;
238
+ }
239
+ return `cfg://grid/${this.GRID_CONFIG_VERSION}${resourceID}`;
240
+ }
241
+ }
242
+
243
+ function normalizeValue(value) {
244
+ if (value == undefined) {
245
+ return value;
246
+ }
247
+ if (value instanceof Date) {
248
+ return value.toISOString();
249
+ }
250
+ if (typeof value === "object") {
251
+ if (value instanceof Array) {
252
+ return value.map(item => normalizeValue(item));
253
+ }
254
+ else {
255
+ const normalized = Object.assign({}, value);
256
+ Object.keys(value).forEach(prop => {
257
+ if (value[prop]) {
258
+ normalized[prop] = normalizeValue(value[prop]);
259
+ }
260
+ else {
261
+ delete normalized[prop];
262
+ }
263
+ });
264
+ return normalized;
265
+ }
266
+ }
267
+ return value;
268
+ }
269
+ class FilterBarConfigFetcher extends ResourceFetcher {
270
+ saveConfig(items, resourceID, configName) {
271
+ const state = items.map(item => {
272
+ const { id, value, fixed, visible } = item;
273
+ const stateItem = { id };
274
+ if (value) {
275
+ stateItem["value"] = normalizeValue(value);
276
+ }
277
+ if (fixed) {
278
+ stateItem["fixed"] = fixed;
279
+ }
280
+ if (visible) {
281
+ stateItem["visible"] = true;
282
+ }
283
+ return stateItem;
284
+ });
285
+ return this.saveResource(state, this.getPath(resourceID, configName));
286
+ }
287
+ getConfig(resourceID, configName) {
288
+ return new Promise((accept, reject) => {
289
+ this.loadResource(this.getPath(resourceID, configName))
290
+ .then((configAsString) => {
291
+ let fieldsList;
292
+ if (configAsString) {
293
+ const filterBarConfig = JSON.parse(configAsString);
294
+ fieldsList = filterBarConfig.items;
295
+ }
296
+ accept(fieldsList || []);
297
+ })
298
+ .catch((error) => {
299
+ reject(error);
300
+ });
301
+ });
302
+ }
303
+ getPath(resourceID, name) {
304
+ if (name) {
305
+ return `cfg://filter/FilterBarState:${resourceID}/${name}`;
306
+ }
307
+ return `cfg://filter/FilterBarState:${resourceID}`;
308
+ }
230
309
  }
231
310
 
232
311
  const CONFIG_SOURCE = {
233
312
  form: "form",
234
- grid: "grid"
313
+ grid: "grid",
314
+ filterBar: "filterBar"
235
315
  };
236
316
  class ConfigStorage {
237
317
  static async get() {
@@ -242,16 +322,21 @@ class ConfigStorage {
242
322
  const resourceID = await application.getResourceID();
243
323
  ConfigStorage.instance = new ConfigStorage();
244
324
  ConfigStorage.resourceID = resourceID;
325
+ ConfigStorage.instance.loadFilterBarConfig(configName);
245
326
  ConfigStorage.instance.loadFormConfig(configName);
246
327
  ConfigStorage.instance.loadGridConfig(configName);
247
328
  }
248
329
  }
249
330
  return this.instance;
250
331
  }
251
- async loadFormConfig(name) {
252
- if (name == undefined) {
253
- return;
332
+ async loadFilterBarConfig(name) {
333
+ const cacheID = ConfigStorage.buildCacheID(name, CONFIG_SOURCE.filterBar);
334
+ if (!ConfigStorage.configById.has(cacheID)) {
335
+ ConfigStorage.configById.set(cacheID, ConfigStorage.filterBarConfigFetcher.getConfig(ConfigStorage.resourceID, name));
254
336
  }
337
+ return ConfigStorage.configById.get(cacheID);
338
+ }
339
+ async loadFormConfig(name) {
255
340
  const cacheID = ConfigStorage.buildCacheID(name, CONFIG_SOURCE.form);
256
341
  if (!ConfigStorage.configById.has(cacheID)) {
257
342
  ConfigStorage.configById.set(cacheID, ConfigStorage.formConfigFetcher.loadFormConfig(name, ConfigStorage.resourceID));
@@ -259,36 +344,39 @@ class ConfigStorage {
259
344
  return ConfigStorage.configById.get(cacheID);
260
345
  }
261
346
  async loadGridConfig(name) {
262
- if (name == undefined) {
263
- return;
264
- }
265
347
  const cacheID = ConfigStorage.buildCacheID(name, CONFIG_SOURCE.grid);
266
348
  if (!ConfigStorage.configById.has(cacheID)) {
267
349
  ConfigStorage.configById.set(cacheID, ConfigStorage.gridConfigFetcher.getConfig(name, ConfigStorage.resourceID));
268
350
  }
269
351
  return ConfigStorage.configById.get(cacheID);
270
352
  }
353
+ static async saveFilterBarConfig(config, name) {
354
+ const cacheID = this.buildCacheID(name, CONFIG_SOURCE.filterBar);
355
+ this.configById.delete(cacheID);
356
+ return this.filterBarConfigFetcher.saveConfig(config, this.resourceID, name);
357
+ }
271
358
  static async saveFormConfig(config, name) {
272
- if (config == undefined || name == undefined) {
273
- return;
274
- }
275
359
  const cacheID = this.buildCacheID(name, CONFIG_SOURCE.form);
276
360
  this.configById.delete(cacheID);
277
361
  return this.formConfigFetcher.saveConfig(config, name, this.resourceID);
278
362
  }
279
363
  static async saveGridConfig(config, name) {
280
- if (config == undefined || name == undefined) {
364
+ if (config == undefined) {
281
365
  return;
282
366
  }
283
367
  const cacheID = this.buildCacheID(name, CONFIG_SOURCE.grid);
284
368
  this.configById.delete(cacheID);
285
- return this.gridConfigFetcher.saveConfig(config, this.resourceID);
369
+ return this.gridConfigFetcher.saveConfig(config, name, this.resourceID);
286
370
  }
287
371
  static buildCacheID(name, source) {
372
+ if (name == undefined) {
373
+ return `req_${source}_${this.resourceID}`;
374
+ }
288
375
  return `req_${source}_${name}_${this.resourceID}`;
289
376
  }
290
377
  }
291
378
  ConfigStorage.configById = new Map();
379
+ ConfigStorage.filterBarConfigFetcher = new FilterBarConfigFetcher();
292
380
  ConfigStorage.formConfigFetcher = new FormConfigFetcher();
293
381
  ConfigStorage.gridConfigFetcher = new GridConfigFetcher();
294
382
 
@@ -1,4 +1,4 @@
1
- import { ErrorException, WarningException, StringUtils } from '@sankhyalabs/core';
1
+ import { ErrorException, WarningException, ObjectUtils, StringUtils } from '@sankhyalabs/core';
2
2
  import { c as createCommonjsModule, a as commonjsGlobal } from './_commonjsHelpers.js';
3
3
 
4
4
  var browserPonyfill = createCommonjsModule(function (module, exports) {
@@ -6435,6 +6435,20 @@ class UrlUtils {
6435
6435
  }
6436
6436
  }
6437
6437
 
6438
+ class DataFetcherRecaller {
6439
+ constructor(serviceName, requestBody, callback) {
6440
+ this.serviceName = serviceName;
6441
+ this.requestBody = requestBody;
6442
+ this.callback = callback;
6443
+ }
6444
+ reCall(requestBody) {
6445
+ if (requestBody) {
6446
+ this.requestBody = requestBody;
6447
+ }
6448
+ DataFetcher.get().callServiceBroker(this.serviceName, this.requestBody);
6449
+ }
6450
+ }
6451
+
6438
6452
  class DataFetcher {
6439
6453
  constructor() {
6440
6454
  this.GRAPHQL_PATH = "/mge/graphql";
@@ -6534,14 +6548,44 @@ class DataFetcher {
6534
6548
  const url = `${ctx.baseUrl}?serviceName=${name}&counter=21&application=${ctx.appName}&outputType=json&preventTransform=false&mgeSession=${ctx.mgeSession}&resourceID=${ctx.resourceID}&globalID=${ctx.globalID}&allowConcurrentCalls=true`;
6535
6549
  document.cookie = `JSESSIONID=${ctx.mgeSession};`;
6536
6550
  const http = new XMLHttpRequest();
6551
+ var payloadJson = {};
6552
+ if ('string' == typeof payload) {
6553
+ payload = ObjectUtils.stringToObject(payload);
6554
+ }
6555
+ if (!payload.hasOwnProperty('requestBody')) {
6556
+ payloadJson['requestBody'] = payload;
6557
+ }
6558
+ else {
6559
+ payloadJson = payload;
6560
+ }
6561
+ for (let [key] of DataFetcher.clientEventsByID) {
6562
+ if (!payloadJson['requestBody'].hasOwnProperty('clientEventList')) {
6563
+ payloadJson['requestBody']['clientEventList'] = {
6564
+ clientEvent: []
6565
+ };
6566
+ }
6567
+ payloadJson['requestBody']['clientEventList'].clientEvent.push({ $: key });
6568
+ }
6537
6569
  DataFetcher.requestListener.forEach(listener => listener.onRequestStart({ url: url, requestBody: payload }));
6538
6570
  http.open("POST", url, true);
6539
6571
  http.withCredentials = true;
6540
- http.send(payload);
6572
+ http.send(ObjectUtils.objectToString(payloadJson));
6541
6573
  http.onreadystatechange = function () {
6542
6574
  if (this.readyState == 4 && this.status == 200) {
6543
6575
  try {
6544
6576
  const jsonResp = JSON.parse(this.responseText);
6577
+ if (jsonResp.hasOwnProperty('clientEvents')) {
6578
+ jsonResp.clientEvents.forEach(clientEvent => {
6579
+ if (DataFetcher.hasClientEvent(clientEvent.id)) {
6580
+ var handlers = DataFetcher.clientEventsByID.get(clientEvent.id);
6581
+ handlers.forEach(handler => {
6582
+ handler({ id: clientEvent.id, content: clientEvent }, new DataFetcherRecaller(serviceName, payloadJson, accept));
6583
+ });
6584
+ }
6585
+ });
6586
+ if (jsonResp.status == 4)
6587
+ return;
6588
+ }
6545
6589
  if (jsonResp.status == 1) {
6546
6590
  accept(jsonResp.responseBody);
6547
6591
  }
@@ -6664,9 +6708,25 @@ class DataFetcher {
6664
6708
  error.index = Number(requestIndex);
6665
6709
  return error;
6666
6710
  }
6711
+ static addClientEvent(eventID, handler) {
6712
+ let clientEvent = DataFetcher.clientEventsByID.get(eventID);
6713
+ if (clientEvent != undefined) {
6714
+ clientEvent.push(handler);
6715
+ }
6716
+ else {
6717
+ DataFetcher.clientEventsByID.set(eventID, [handler]);
6718
+ }
6719
+ }
6720
+ static hasClientEvent(eventID) {
6721
+ return DataFetcher.clientEventsByID.has(eventID);
6722
+ }
6723
+ static removeClientEvent(eventID) {
6724
+ return DataFetcher.clientEventsByID.delete(eventID);
6725
+ }
6667
6726
  }
6668
6727
  DataFetcher.appTagName = "snk-application";
6669
6728
  DataFetcher.requestListener = [];
6729
+ DataFetcher.clientEventsByID = new Map();
6670
6730
  class WaitingRequest {
6671
6731
  constructor(req) {
6672
6732
  this._resolve = () => { };
@@ -23,7 +23,7 @@ export { SnkFilterText as SnkFilterText } from '../types/components/snk-filter-b
23
23
  export { SnkForm as SnkForm } from '../types/components/snk-form/snk-form';
24
24
  export { SnkFormConfig as SnkFormConfig } from '../types/components/snk-form/subcomponents/snk-form-config/snk-form-config';
25
25
  export { SnkGrid as SnkGrid } from '../types/components/snk-grid/snk-grid';
26
- export { EzGridConfig as SnkGridConfig } from '../types/components/snk-grid/subcomponents/snk-grid-config/snk-grid-config';
26
+ export { SnkGridConfig as SnkGridConfig } from '../types/components/snk-grid/subcomponents/snk-grid-config/snk-grid-config';
27
27
  export { SnkPesquisa as SnkPesquisa } from '../types/components/snk-pesquisa/snk-pesquisa';
28
28
  export { SelectBox as SnkSelectBox } from '../types/components/snk-grid/subcomponents/snk-select-box/snk-select-box';
29
29
  export { SnkTabConfig as SnkTabConfig } from '../types/components/snk-form/subcomponents/snk-tab-config/snk-tab-config';
@@ -623,68 +623,6 @@ var AutorizationType;
623
623
  AutorizationType["CONFIG_GRID"] = "G";
624
624
  })(AutorizationType || (AutorizationType = {}));
625
625
 
626
- function normalizeValue(value) {
627
- if (value == undefined) {
628
- return value;
629
- }
630
- if (value instanceof Date) {
631
- return value.toISOString();
632
- }
633
- if (typeof value === "object") {
634
- if (value instanceof Array) {
635
- return value.map(item => normalizeValue(item));
636
- }
637
- else {
638
- const normalized = Object.assign({}, value);
639
- Object.keys(value).forEach(prop => {
640
- if (value[prop]) {
641
- normalized[prop] = normalizeValue(value[prop]);
642
- }
643
- else {
644
- delete normalized[prop];
645
- }
646
- });
647
- return normalized;
648
- }
649
- }
650
- return value;
651
- }
652
- class FilterBarConfigFetcher extends ResourceFetcher {
653
- saveConfig(items, resourceID, configName) {
654
- const state = items.map(item => {
655
- const { id, value, fixed, visible } = item;
656
- const stateItem = { id };
657
- if (value) {
658
- stateItem["value"] = normalizeValue(value);
659
- }
660
- if (fixed) {
661
- stateItem["fixed"] = fixed;
662
- }
663
- if (visible) {
664
- stateItem["visible"] = true;
665
- }
666
- return stateItem;
667
- });
668
- return this.saveResource(state, `cfg://filter/FilterBarState:${resourceID}/${configName}`);
669
- }
670
- getConfig(resourceID, configName) {
671
- return new Promise((accept, reject) => {
672
- this.loadResource(`cfg://filter/FilterBarState:${resourceID}/${configName}`)
673
- .then((configAsString) => {
674
- let fieldsList;
675
- if (configAsString) {
676
- const filterBarConfig = JSON.parse(configAsString);
677
- fieldsList = filterBarConfig.items;
678
- }
679
- accept(fieldsList || []);
680
- })
681
- .catch((error) => {
682
- reject(error);
683
- });
684
- });
685
- }
686
- }
687
-
688
626
  const snkApplicationCss = ".sc-snk-application-h{display:flex;flex-direction:column;height:100%}";
689
627
 
690
628
  const SnkApplication = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
@@ -1073,38 +1011,6 @@ const SnkApplication = /*@__PURE__*/ proxyCustomElement(class extends HTMLElemen
1073
1011
  async loadTotals(name, resourceID, filters) {
1074
1012
  return this.totalsFetcher.fetchTotals(name, resourceID, filters);
1075
1013
  }
1076
- /**
1077
- * Salva a configuração de grade.
1078
- */
1079
- async saveGridConfig(config) {
1080
- return this.gridConfigFetcher.saveConfig(config, this.resourceID);
1081
- }
1082
- /**
1083
- * Obtém as configurações da barra de filtros
1084
- */
1085
- async getFilterBarConfig(name) {
1086
- return new Promise((accept, reject) => {
1087
- if (this.configName === name && this._filterBarConfig) {
1088
- accept(this._filterBarConfig);
1089
- }
1090
- else if (this.configName === name && this._filterConfigPromise != undefined) {
1091
- Promise.all([this._filterConfigPromise])
1092
- .then(result => accept(result[0]))
1093
- .catch(reason => reject(reason[0]));
1094
- }
1095
- else {
1096
- this.filterBarConfigFetcher.getConfig(this.resourceID, name)
1097
- .then(config => accept(config))
1098
- .catch(reason => reject(reason));
1099
- }
1100
- });
1101
- }
1102
- /**
1103
- * Salva as configurações da barra de filtros
1104
- */
1105
- async saveFilterBarConfig(config, name) {
1106
- return this.filterBarConfigFetcher.saveConfig(config, this.resourceID, name);
1107
- }
1108
1014
  /**
1109
1015
  * Salva a configuração de formulário.
1110
1016
  */
@@ -1168,12 +1074,6 @@ const SnkApplication = /*@__PURE__*/ proxyCustomElement(class extends HTMLElemen
1168
1074
  }
1169
1075
  return this._authFetcher;
1170
1076
  }
1171
- get filterBarConfigFetcher() {
1172
- if (!this._filterBarConfigFetcher) {
1173
- this._filterBarConfigFetcher = new FilterBarConfigFetcher();
1174
- }
1175
- return this._filterBarConfigFetcher;
1176
- }
1177
1077
  get defaultValuesFetcher() {
1178
1078
  if (!this._defaultValuesFetcher) {
1179
1079
  this._defaultValuesFetcher = new DefaultValuesFetcher();
@@ -1281,16 +1181,6 @@ const SnkApplication = /*@__PURE__*/ proxyCustomElement(class extends HTMLElemen
1281
1181
  return this.executeSearch(searchArgument, fieldName, dataUnit);
1282
1182
  });
1283
1183
  ApplicationContext.setContextValue("__EZUI__GRID_LICENSE__", agGridLicense);
1284
- if (this.configName) {
1285
- this._filterConfigPromise = new Promise((accept, reject) => {
1286
- this.filterBarConfigFetcher.getConfig(this.resourceID, this.configName)
1287
- .then(config => {
1288
- this._filterBarConfig = config;
1289
- accept(config);
1290
- })
1291
- .catch(reason => reject(reason));
1292
- });
1293
- }
1294
1184
  ErrorTracking.init();
1295
1185
  ConfigStorage.get();
1296
1186
  this.getDefaultValues().then((defaultValues) => {
@@ -1353,9 +1243,6 @@ const SnkApplication = /*@__PURE__*/ proxyCustomElement(class extends HTMLElemen
1353
1243
  "fetchLegacyConfig": [64],
1354
1244
  "fetchDefaultConfig": [64],
1355
1245
  "loadTotals": [64],
1356
- "saveGridConfig": [64],
1357
- "getFilterBarConfig": [64],
1358
- "saveFilterBarConfig": [64],
1359
1246
  "saveFormConfig": [64],
1360
1247
  "getDefaultValues": [64],
1361
1248
  "getDefaultValue": [64],
@@ -4,6 +4,7 @@ import { EzScrollDirection } from '@sankhyalabs/ezui/dist/collection/components/
4
4
  import { F as FilterItemType } from './filter-item-type.enum.js';
5
5
  import { ModalAction } from '@sankhyalabs/ezui/dist/collection/components/ez-modal-container';
6
6
  import { toString } from '@sankhyalabs/core/dist/dataunit/metadata/DataType';
7
+ import { C as ConfigStorage } from './ConfigStorage.js';
7
8
  import { d as defineCustomElement$4 } from './snk-filter-detail2.js';
8
9
  import { d as defineCustomElement$3 } from './snk-filter-item2.js';
9
10
  import { d as defineCustomElement$2 } from './snk-filter-list2.js';
@@ -191,7 +192,7 @@ const SnkFilterBar = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement
191
192
  }
192
193
  if (this._configUpdated) {
193
194
  this._configUpdated = false;
194
- this._application.saveFilterBarConfig(this.filterConfig, this.configName);
195
+ ConfigStorage.saveFilterBarConfig(this.filterConfig, this.configName);
195
196
  }
196
197
  }
197
198
  /**
@@ -397,16 +398,18 @@ const SnkFilterBar = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement
397
398
  loadPermitions() {
398
399
  this._application.isUserSup().then(value => this.allowDefault = value);
399
400
  }
400
- loadConfigFromApplication() {
401
- this._application.getFilterBarConfig(this.configName)
402
- .then((filters) => {
403
- this.filterConfig = filters.map(item => this.normalizeItem(item));
404
- if (this.dataUnit) {
405
- this.dataUnit.loadData();
406
- }
407
- })
408
- .catch(reason => {
409
- throw new ErrorException(this.getMessage("snkFilterBar.failToLoadConfig"), reason);
401
+ loadConfigFromStorage() {
402
+ ConfigStorage.get().then(instance => {
403
+ instance.loadFilterBarConfig(this.configName)
404
+ .then((filters) => {
405
+ this.filterConfig = filters.map(item => this.normalizeItem(item));
406
+ if (this.dataUnit) {
407
+ this.dataUnit.loadData(undefined, undefined);
408
+ }
409
+ })
410
+ .catch(reason => {
411
+ throw new ErrorException(this.getMessage("snkFilterBar.failToLoadConfig"), reason);
412
+ });
410
413
  });
411
414
  }
412
415
  attachDataUnit() {
@@ -470,7 +473,7 @@ const SnkFilterBar = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement
470
473
  this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
471
474
  if (this._application) {
472
475
  this.loadPermitions();
473
- this.loadConfigFromApplication();
476
+ this.loadConfigFromStorage();
474
477
  }
475
478
  this.attachDataUnit();
476
479
  }
@@ -200,10 +200,8 @@ const SnkFormConfig = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement
200
200
  this._optionFormConfigChanged = false;
201
201
  ConfigStorage.saveFormConfig(formConfig, this.configName)
202
202
  .then((response) => {
203
- if ((response === null || response === void 0 ? void 0 : response.resource) != undefined) {
204
- ApplicationUtils.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"), { iconName: "check" });
205
- this.configChange.emit(formConfig);
206
- }
203
+ ApplicationUtils.info(this.getMessage("snkFormConfig.info.successfullyConfigSaved"), { iconName: "check" });
204
+ this.configChange.emit(response);
207
205
  });
208
206
  }
209
207
  applyOptionConfig() {
@@ -60,9 +60,6 @@ const SnkForm = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
60
60
  }
61
61
  }
62
62
  loadConfig() {
63
- if (this.configName == undefined) {
64
- return;
65
- }
66
63
  ConfigStorage.get()
67
64
  .then((instance) => {
68
65
  instance.loadFormConfig(this.configName)
@@ -118,16 +115,17 @@ const SnkForm = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
118
115
  }
119
116
  }
120
117
  loadInsertionConfig() {
121
- var _a;
122
118
  if (this._dataUnit) {
123
119
  const copyFormConfig = ObjectUtils.copy(this._editionFormConfig || {});
124
- copyFormConfig.fields = (_a = copyFormConfig.fields) === null || _a === void 0 ? void 0 : _a.filter(field => {
125
- const def = this._dataUnit.getField(field.name);
126
- if (def === null || def === void 0 ? void 0 : def.readOnly) {
127
- return false;
128
- }
129
- return true;
130
- });
120
+ if (copyFormConfig.fields) {
121
+ copyFormConfig.fields = copyFormConfig.fields.filter(field => {
122
+ const def = this._dataUnit.getField(field.name);
123
+ if (def === null || def === void 0 ? void 0 : def.readOnly) {
124
+ return false;
125
+ }
126
+ return true;
127
+ });
128
+ }
131
129
  this._insertionFormConfig = copyFormConfig;
132
130
  }
133
131
  }
@@ -1,6 +1,6 @@
1
- import { E as EzGridConfig, d as defineCustomElement$1 } from './snk-grid-config2.js';
1
+ import { S as SnkGridConfig$1, d as defineCustomElement$1 } from './snk-grid-config2.js';
2
2
 
3
- const SnkGridConfig = EzGridConfig;
3
+ const SnkGridConfig = SnkGridConfig$1;
4
4
  const defineCustomElement = defineCustomElement$1;
5
5
 
6
6
  export { SnkGridConfig, defineCustomElement };