@sankhyalabs/sankhyablocks 1.3.7 → 1.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ const patchEsm = () => {
14
14
  const defineCustomElements = (win, options) => {
15
15
  if (typeof window === 'undefined') return Promise.resolve();
16
16
  return patchEsm().then(() => {
17
- return index.bootstrapLazy([["snk-pesquisa.cjs",[[1,"snk-pesquisa",{"searchLoader":[16],"onSelectItem":[16],"argument":[1025]}]]],["snk-application.cjs",[[2,"snk-application",{"getStringParam":[64],"getIntParam":[64],"getFloatParam":[64],"getBooleanParam":[64],"getDateParam":[64],"showPopUp":[64],"closePopUp":[64],"temOpcional":[64],"getAttributeFromHTMLWrapper":[64],"openApp":[64],"createDataunit":[64],"getResourceID":[64],"alert":[64],"error":[64],"confirm":[64],"info":[64],"loadFormConfig":[64]}]]],["teste-pesquisa.cjs",[[1,"teste-pesquisa"]]]], options);
17
+ return index.bootstrapLazy([["snk-pesquisa.cjs",[[1,"snk-pesquisa",{"searchLoader":[16],"onSelectItem":[16],"argument":[1025]}]]],["snk-application.cjs",[[2,"snk-application",{"getStringParam":[64],"getIntParam":[64],"getFloatParam":[64],"getBooleanParam":[64],"getDateParam":[64],"showPopUp":[64],"closePopUp":[64],"temOpcional":[64],"getConfig":[64],"saveConfig":[64],"getAttributeFromHTMLWrapper":[64],"openApp":[64],"createDataunit":[64],"getResourceID":[64],"alert":[64],"error":[64],"confirm":[64],"info":[64],"loadFormConfig":[64],"loadGridConfig":[64],"saveGridConfig":[64]}]]],["teste-pesquisa.cjs",[[1,"teste-pesquisa"]]]], options);
18
18
  });
19
19
  };
20
20
 
@@ -15,5 +15,5 @@ const patchBrowser = () => {
15
15
  };
16
16
 
17
17
  patchBrowser().then(options => {
18
- return index.bootstrapLazy([["snk-pesquisa.cjs",[[1,"snk-pesquisa",{"searchLoader":[16],"onSelectItem":[16],"argument":[1025]}]]],["snk-application.cjs",[[2,"snk-application",{"getStringParam":[64],"getIntParam":[64],"getFloatParam":[64],"getBooleanParam":[64],"getDateParam":[64],"showPopUp":[64],"closePopUp":[64],"temOpcional":[64],"getAttributeFromHTMLWrapper":[64],"openApp":[64],"createDataunit":[64],"getResourceID":[64],"alert":[64],"error":[64],"confirm":[64],"info":[64],"loadFormConfig":[64]}]]],["teste-pesquisa.cjs",[[1,"teste-pesquisa"]]]], options);
18
+ return index.bootstrapLazy([["snk-pesquisa.cjs",[[1,"snk-pesquisa",{"searchLoader":[16],"onSelectItem":[16],"argument":[1025]}]]],["snk-application.cjs",[[2,"snk-application",{"getStringParam":[64],"getIntParam":[64],"getFloatParam":[64],"getBooleanParam":[64],"getDateParam":[64],"showPopUp":[64],"closePopUp":[64],"temOpcional":[64],"getConfig":[64],"saveConfig":[64],"getAttributeFromHTMLWrapper":[64],"openApp":[64],"createDataunit":[64],"getResourceID":[64],"alert":[64],"error":[64],"confirm":[64],"info":[64],"loadFormConfig":[64],"loadGridConfig":[64],"saveGridConfig":[64]}]]],["teste-pesquisa.cjs",[[1,"teste-pesquisa"]]]], options);
19
19
  });
@@ -6692,7 +6692,7 @@ class DataUnitFetcher {
6692
6692
  }
6693
6693
  }
6694
6694
  }`);
6695
- this.templateByQuery.set("fetchData", dist.gql `query($dataunit: String! $limit: Int $offset:Int $filter: [Filter!] $sort: [Sort!]) {
6695
+ this.templateByQuery.set("fetchData", dist.gql `query($dataunit: String! $limit: Int $offset:Int $filter: [InputFilter!] $sort: [InputSort!]) {
6696
6696
  $queryAlias$: fetchDataUnit(name: $dataunit){
6697
6697
  data(limit: $limit offset: $offset filters: $filter sort: $sort){
6698
6698
  limit
@@ -6709,8 +6709,8 @@ class DataUnitFetcher {
6709
6709
  }
6710
6710
  }
6711
6711
  }`);
6712
- this.templateByQuery.set("saveData", dist.gql `mutation($changes: [Change!]!) {
6713
- $queryAlias$: saveDataUnitChanges(changes: $changes){
6712
+ this.templateByQuery.set("saveData", dist.gql `mutation($changes: [InputBatchChange!]!) {
6713
+ $queryAlias$: batchOperationDataUnit(changes: $changes){
6714
6714
  oldId
6715
6715
  id
6716
6716
  fields {
@@ -6757,19 +6757,22 @@ class DataUnitFetcher {
6757
6757
  });
6758
6758
  });
6759
6759
  }
6760
- loadData(dataUnit, page, sort, filters) {
6760
+ loadData(dataUnit, page, sort, filter) {
6761
6761
  return new Promise((resolve, reject) => {
6762
- const variables = { dataunit: dataUnit.name, sort, filters };
6762
+ const variables = { dataunit: dataUnit.name, sort, filter };
6763
6763
  if (page) {
6764
6764
  variables.limit = page.limit;
6765
6765
  variables.offset = page.offset;
6766
6766
  }
6767
6767
  if (!core.StringUtils.isEmpty(page === null || page === void 0 ? void 0 : page.quickFilter)) {
6768
- variables.filter = [{
6769
- name: "__ALL_SEARCHABLE_FIELDS__",
6770
- expression: "__ALL_SEARCHABLE_FIELDS__",
6771
- params: [{ name: "term", value: page.quickFilter }]
6772
- }];
6768
+ if (variables.filter === undefined) {
6769
+ variables.filter = [];
6770
+ }
6771
+ variables.filter.push({
6772
+ name: "__ALL_SEARCHABLE_FIELDS__",
6773
+ expression: "__ALL_SEARCHABLE_FIELDS__",
6774
+ params: [{ name: "term", value: page.quickFilter }]
6775
+ });
6773
6776
  }
6774
6777
  DataFetcher.get()
6775
6778
  .callGraphQL({
@@ -6799,10 +6802,10 @@ class DataUnitFetcher {
6799
6802
  let parsedUpdatingFields;
6800
6803
  if (updatingFields) {
6801
6804
  parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
6802
- return { fieldName, value: formatValueToServer(value) };
6805
+ return { fieldName, value: dataUnit.valueToString(fieldName, value) };
6803
6806
  });
6804
6807
  }
6805
- const reqChange = { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6808
+ const reqChange = { dataUnit: changeDU, fields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6806
6809
  if (change.sourceId) {
6807
6810
  reqChange.sourceId = change.sourceId;
6808
6811
  }
@@ -6852,21 +6855,6 @@ class DataUnitFetcher {
6852
6855
  });
6853
6856
  }
6854
6857
  }
6855
- const formatValueToServer = (value) => {
6856
- if (value === undefined)
6857
- return value;
6858
- try {
6859
- if (value instanceof Date) {
6860
- return value.toString();
6861
- }
6862
- //Any others objects
6863
- value = JSON.stringify(value);
6864
- }
6865
- catch (_a) {
6866
- value = value.toString();
6867
- }
6868
- return value;
6869
- };
6870
6858
 
6871
6859
  var _a;
6872
6860
  class Workspace {
@@ -6945,6 +6933,9 @@ class ResourceFetcher {
6945
6933
  resource
6946
6934
  }
6947
6935
  }`);
6936
+ this.templateByQuery.set("saveResource", dist.gql `mutation($resource: ResourceToSave!) {
6937
+ $queryAlias$: saveResource(resource: $resource)
6938
+ }`);
6948
6939
  }
6949
6940
  loadResource(name) {
6950
6941
  return new Promise((resolve, reject) => {
@@ -6961,6 +6952,26 @@ class ResourceFetcher {
6961
6952
  });
6962
6953
  });
6963
6954
  }
6955
+ saveResource(resource, name) {
6956
+ return new Promise((resolve, reject) => {
6957
+ DataFetcher.get()
6958
+ .callGraphQL({
6959
+ values: {
6960
+ resource: {
6961
+ name: name,
6962
+ resource: JSON.stringify(resource)
6963
+ }
6964
+ },
6965
+ query: this.templateByQuery.get("saveResource")
6966
+ })
6967
+ .then((resp) => {
6968
+ resolve(resp);
6969
+ })
6970
+ .catch((error) => {
6971
+ reject(error);
6972
+ });
6973
+ });
6974
+ }
6964
6975
  }
6965
6976
 
6966
6977
  class FormConfigFetcher extends ResourceFetcher {
@@ -6973,7 +6984,7 @@ class FormConfigFetcher extends ResourceFetcher {
6973
6984
  const { tabs, fields } = config;
6974
6985
  if (tabs) {
6975
6986
  const allTabs = new Map(tabs.map(t => [t.label, t]));
6976
- fields.forEach(f => f.tab = allTabs.get(f.tab));
6987
+ fields.forEach(f => f.tab = allTabs.get(this.getTabName(f.tab)));
6977
6988
  }
6978
6989
  accept(fields);
6979
6990
  }
@@ -6986,6 +6997,41 @@ class FormConfigFetcher extends ResourceFetcher {
6986
6997
  });
6987
6998
  });
6988
6999
  }
7000
+ getTabName(tab) {
7001
+ if (typeof tab === 'object') { // TabConfig type
7002
+ return tab.label;
7003
+ }
7004
+ return tab; //string type
7005
+ }
7006
+ }
7007
+
7008
+ class GridConfigFetcher extends ResourceFetcher {
7009
+ getConfig(resourceID) {
7010
+ const completePath = `cfg://grid/GrdCfgHtml5:${resourceID}`;
7011
+ return new Promise((resolve, reject) => {
7012
+ this.loadResource(completePath)
7013
+ .then(loadedResource => {
7014
+ if (loadedResource) {
7015
+ let config = JSON.parse(loadedResource);
7016
+ resolve(config);
7017
+ }
7018
+ }).catch((error) => {
7019
+ reject(error);
7020
+ });
7021
+ });
7022
+ }
7023
+ saveConfig(config, resourceID) {
7024
+ const completePath = `cfg://grid/GrdCfgHtml5:${resourceID}`;
7025
+ return new Promise((resolve, reject) => {
7026
+ this.saveResource(config, completePath)
7027
+ .then((resp) => {
7028
+ resolve(resp);
7029
+ })
7030
+ .catch((error) => {
7031
+ reject(error);
7032
+ });
7033
+ });
7034
+ }
6989
7035
  }
6990
7036
 
6991
7037
  class PesquisaFetcher {
@@ -7139,6 +7185,41 @@ const SnkApplication = class {
7139
7185
  });
7140
7186
  });
7141
7187
  }
7188
+ async getConfig(key) {
7189
+ let payload = {
7190
+ "serviceName": "SystemUtilsSP.getConf",
7191
+ "requestBody": {
7192
+ "config": {
7193
+ "chave": key,
7194
+ "tipo": "T"
7195
+ }
7196
+ }
7197
+ };
7198
+ return new Promise((resolve, reject) => {
7199
+ DataFetcher.get()
7200
+ .callServiceBroker("SystemUtilsSP.getConf", JSON.stringify(payload))
7201
+ .then(result => { var _a; return resolve((_a = result.config) === null || _a === void 0 ? void 0 : _a.data); })
7202
+ .catch(error => reject(error));
7203
+ });
7204
+ }
7205
+ async saveConfig(key, data) {
7206
+ let payload = {
7207
+ "serviceName": "SystemUtilsSP.saveConf",
7208
+ "requestBody": {
7209
+ "config": {
7210
+ "chave": key,
7211
+ "tipo": "T",
7212
+ data
7213
+ }
7214
+ }
7215
+ };
7216
+ return new Promise((resolve, reject) => {
7217
+ DataFetcher.get()
7218
+ .callServiceBroker("SystemUtilsSP.saveConf", JSON.stringify(payload))
7219
+ .then(result => resolve(result))
7220
+ .catch(error => reject(error));
7221
+ });
7222
+ }
7142
7223
  async getAttributeFromHTMLWrapper(attribName) {
7143
7224
  return Promise.resolve(window[attribName]);
7144
7225
  }
@@ -7170,6 +7251,12 @@ const SnkApplication = class {
7170
7251
  async loadFormConfig(name) {
7171
7252
  return this.formConfigFetcher.loadFormConfig(name, this.resourceID);
7172
7253
  }
7254
+ async loadGridConfig() {
7255
+ return this.gridConfigFetcher.getConfig(this.resourceID);
7256
+ }
7257
+ async saveGridConfig(config) {
7258
+ return this.gridConfigFetcher.saveConfig(config, this.resourceID);
7259
+ }
7173
7260
  get urlParams() {
7174
7261
  if (!this._urlParams) {
7175
7262
  this._urlParams = UrlUtils.getQueryParams(location.search);
@@ -7188,6 +7275,12 @@ const SnkApplication = class {
7188
7275
  }
7189
7276
  return this._formConfigFetcher;
7190
7277
  }
7278
+ get gridConfigFetcher() {
7279
+ if (!this._gridConfigFetcher) {
7280
+ this._gridConfigFetcher = new GridConfigFetcher();
7281
+ }
7282
+ return this._gridConfigFetcher;
7283
+ }
7191
7284
  get pesquisaFetcher() {
7192
7285
  if (!this._pesquisaFetcher) {
7193
7286
  this._pesquisaFetcher = new PesquisaFetcher();
@@ -7202,7 +7295,7 @@ const SnkApplication = class {
7202
7295
  const { ENTITYNAME } = descriptor.properties;
7203
7296
  const dependencies = descriptor.dependencies;
7204
7297
  let criteria;
7205
- dependencies === null || dependencies === void 0 ? void 0 : dependencies.forEach(dependency => {
7298
+ dependencies === null || dependencies === void 0 ? void 0 : dependencies.filter(dep => { var _a; return (_a = dep.masterFields) === null || _a === void 0 ? void 0 : _a.every(f => { var _a; return (_a = dataUnit.getField(f)) === null || _a === void 0 ? void 0 : _a.visible; }); }).forEach(dependency => {
7206
7299
  var _a;
7207
7300
  if (dependency.type === UnitMetadata.DependencyType.SEARCHING) {
7208
7301
  if (((_a = dependency.masterFields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
@@ -7211,7 +7304,12 @@ const SnkApplication = class {
7211
7304
  params: dependency.masterFields.map(fieldName => {
7212
7305
  const masterDescriptor = dataUnit.getField(fieldName);
7213
7306
  const dataType = (masterDescriptor === null || masterDescriptor === void 0 ? void 0 : masterDescriptor.dataType) || core.DataType.TEXT;
7214
- return { name: fieldName, value: dataUnit.getFieldValue(fieldName), dataType };
7307
+ const value = dataUnit.getFieldValue(fieldName);
7308
+ if (value == undefined) {
7309
+ this.alert("Erro ao pesquisar", `É necessario informar o campo ${masterDescriptor.label} para executar a pesquisa.`);
7310
+ throw new Error(`É necessario informar o campo ${masterDescriptor.label} para executar a pesquisa.`);
7311
+ }
7312
+ return { name: fieldName, value, dataType };
7215
7313
  })
7216
7314
  };
7217
7315
  }
@@ -1,12 +1,14 @@
1
1
  import { Component, h, Method, Event } from "@stencil/core";
2
2
  import { DataType } from "@sankhyalabs/core";
3
3
  import DataUnitFetcher from "../../lib/http/data-fetcher/fetchers/dataunit-fetcher";
4
+ import { DataFetcher } from "../../lib/http/data-fetcher/DataFetcher";
4
5
  import UrlUtils from "../../lib/utils/urlutils";
5
6
  import Workspace from "../../lib/workspace/workspace";
6
7
  import ParametersFetcher from "../../lib/http/data-fetcher/fetchers/parameters-fecher";
7
8
  import { ApplicationUtils } from "@sankhyalabs/ezui/dist/collection/utils";
8
9
  import { FormConfigFetcher } from "../../lib/http/data-fetcher/fetchers/form-config-fetcher";
9
10
  import { ApplicationContext } from "@sankhyalabs/core";
11
+ import GridConfigFetcher from "../../lib/http/data-fetcher/fetchers/grid-config-fetcher";
10
12
  import { PesquisaFetcher } from "../../lib/http/data-fetcher/fetchers/pesquisa-fetcher";
11
13
  import { DependencyType } from "@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";
12
14
  export class SnkApplication {
@@ -73,6 +75,41 @@ export class SnkApplication {
73
75
  });
74
76
  });
75
77
  }
78
+ async getConfig(key) {
79
+ let payload = {
80
+ "serviceName": "SystemUtilsSP.getConf",
81
+ "requestBody": {
82
+ "config": {
83
+ "chave": key,
84
+ "tipo": "T"
85
+ }
86
+ }
87
+ };
88
+ return new Promise((resolve, reject) => {
89
+ DataFetcher.get()
90
+ .callServiceBroker("SystemUtilsSP.getConf", JSON.stringify(payload))
91
+ .then(result => { var _a; return resolve((_a = result.config) === null || _a === void 0 ? void 0 : _a.data); })
92
+ .catch(error => reject(error));
93
+ });
94
+ }
95
+ async saveConfig(key, data) {
96
+ let payload = {
97
+ "serviceName": "SystemUtilsSP.saveConf",
98
+ "requestBody": {
99
+ "config": {
100
+ "chave": key,
101
+ "tipo": "T",
102
+ data
103
+ }
104
+ }
105
+ };
106
+ return new Promise((resolve, reject) => {
107
+ DataFetcher.get()
108
+ .callServiceBroker("SystemUtilsSP.saveConf", JSON.stringify(payload))
109
+ .then(result => resolve(result))
110
+ .catch(error => reject(error));
111
+ });
112
+ }
76
113
  async getAttributeFromHTMLWrapper(attribName) {
77
114
  return Promise.resolve(window[attribName]);
78
115
  }
@@ -104,6 +141,12 @@ export class SnkApplication {
104
141
  async loadFormConfig(name) {
105
142
  return this.formConfigFetcher.loadFormConfig(name, this.resourceID);
106
143
  }
144
+ async loadGridConfig() {
145
+ return this.gridConfigFetcher.getConfig(this.resourceID);
146
+ }
147
+ async saveGridConfig(config) {
148
+ return this.gridConfigFetcher.saveConfig(config, this.resourceID);
149
+ }
107
150
  get urlParams() {
108
151
  if (!this._urlParams) {
109
152
  this._urlParams = UrlUtils.getQueryParams(location.search);
@@ -122,6 +165,12 @@ export class SnkApplication {
122
165
  }
123
166
  return this._formConfigFetcher;
124
167
  }
168
+ get gridConfigFetcher() {
169
+ if (!this._gridConfigFetcher) {
170
+ this._gridConfigFetcher = new GridConfigFetcher();
171
+ }
172
+ return this._gridConfigFetcher;
173
+ }
125
174
  get pesquisaFetcher() {
126
175
  if (!this._pesquisaFetcher) {
127
176
  this._pesquisaFetcher = new PesquisaFetcher();
@@ -138,7 +187,7 @@ export class SnkApplication {
138
187
  const { ENTITYNAME } = descriptor.properties;
139
188
  const dependencies = descriptor.dependencies;
140
189
  let criteria;
141
- dependencies === null || dependencies === void 0 ? void 0 : dependencies.forEach(dependency => {
190
+ dependencies === null || dependencies === void 0 ? void 0 : dependencies.filter(dep => { var _a; return (_a = dep.masterFields) === null || _a === void 0 ? void 0 : _a.every(f => { var _a; return (_a = dataUnit.getField(f)) === null || _a === void 0 ? void 0 : _a.visible; }); }).forEach(dependency => {
142
191
  var _a;
143
192
  if (dependency.type === DependencyType.SEARCHING) {
144
193
  if (((_a = dependency.masterFields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
@@ -147,7 +196,12 @@ export class SnkApplication {
147
196
  params: dependency.masterFields.map(fieldName => {
148
197
  const masterDescriptor = dataUnit.getField(fieldName);
149
198
  const dataType = (masterDescriptor === null || masterDescriptor === void 0 ? void 0 : masterDescriptor.dataType) || DataType.TEXT;
150
- return { name: fieldName, value: dataUnit.getFieldValue(fieldName), dataType };
199
+ const value = dataUnit.getFieldValue(fieldName);
200
+ if (value == undefined) {
201
+ this.alert("Erro ao pesquisar", `É necessario informar o campo ${masterDescriptor.label} para executar a pesquisa.`);
202
+ throw new Error(`É necessario informar o campo ${masterDescriptor.label} para executar a pesquisa.`);
203
+ }
204
+ return { name: fieldName, value, dataType };
151
205
  })
152
206
  };
153
207
  }
@@ -381,6 +435,50 @@ export class SnkApplication {
381
435
  "tags": []
382
436
  }
383
437
  },
438
+ "getConfig": {
439
+ "complexType": {
440
+ "signature": "(key: string) => Promise<any>",
441
+ "parameters": [{
442
+ "tags": [],
443
+ "text": ""
444
+ }],
445
+ "references": {
446
+ "Promise": {
447
+ "location": "global"
448
+ }
449
+ },
450
+ "return": "Promise<any>"
451
+ },
452
+ "docs": {
453
+ "text": "",
454
+ "tags": []
455
+ }
456
+ },
457
+ "saveConfig": {
458
+ "complexType": {
459
+ "signature": "(key: string, data: Object) => Promise<any>",
460
+ "parameters": [{
461
+ "tags": [],
462
+ "text": ""
463
+ }, {
464
+ "tags": [],
465
+ "text": ""
466
+ }],
467
+ "references": {
468
+ "Promise": {
469
+ "location": "global"
470
+ },
471
+ "Object": {
472
+ "location": "global"
473
+ }
474
+ },
475
+ "return": "Promise<any>"
476
+ },
477
+ "docs": {
478
+ "text": "",
479
+ "tags": []
480
+ }
481
+ },
384
482
  "getAttributeFromHTMLWrapper": {
385
483
  "complexType": {
386
484
  "signature": "(attribName: string) => Promise<string>",
@@ -614,6 +712,49 @@ export class SnkApplication {
614
712
  "text": "",
615
713
  "tags": []
616
714
  }
715
+ },
716
+ "loadGridConfig": {
717
+ "complexType": {
718
+ "signature": "() => Promise<EzGridConfig>",
719
+ "parameters": [],
720
+ "references": {
721
+ "Promise": {
722
+ "location": "global"
723
+ },
724
+ "EzGridConfig": {
725
+ "location": "import",
726
+ "path": "@sankhyalabs/ezui/dist/types/components/ez-grid/controller/EzGridController"
727
+ }
728
+ },
729
+ "return": "Promise<EzGridConfig>"
730
+ },
731
+ "docs": {
732
+ "text": "",
733
+ "tags": []
734
+ }
735
+ },
736
+ "saveGridConfig": {
737
+ "complexType": {
738
+ "signature": "(config: EzGridConfig) => Promise<boolean>",
739
+ "parameters": [{
740
+ "tags": [],
741
+ "text": ""
742
+ }],
743
+ "references": {
744
+ "Promise": {
745
+ "location": "global"
746
+ },
747
+ "EzGridConfig": {
748
+ "location": "import",
749
+ "path": "@sankhyalabs/ezui/dist/types/components/ez-grid/controller/EzGridController"
750
+ }
751
+ },
752
+ "return": "Promise<boolean>"
753
+ },
754
+ "docs": {
755
+ "text": "",
756
+ "tags": []
757
+ }
617
758
  }
618
759
  }; }
619
760
  }
@@ -31,7 +31,7 @@ export default class DataUnitFetcher {
31
31
  }
32
32
  }
33
33
  }`);
34
- this.templateByQuery.set("fetchData", gql `query($dataunit: String! $limit: Int $offset:Int $filter: [Filter!] $sort: [Sort!]) {
34
+ this.templateByQuery.set("fetchData", gql `query($dataunit: String! $limit: Int $offset:Int $filter: [InputFilter!] $sort: [InputSort!]) {
35
35
  $queryAlias$: fetchDataUnit(name: $dataunit){
36
36
  data(limit: $limit offset: $offset filters: $filter sort: $sort){
37
37
  limit
@@ -48,8 +48,8 @@ export default class DataUnitFetcher {
48
48
  }
49
49
  }
50
50
  }`);
51
- this.templateByQuery.set("saveData", gql `mutation($changes: [Change!]!) {
52
- $queryAlias$: saveDataUnitChanges(changes: $changes){
51
+ this.templateByQuery.set("saveData", gql `mutation($changes: [InputBatchChange!]!) {
52
+ $queryAlias$: batchOperationDataUnit(changes: $changes){
53
53
  oldId
54
54
  id
55
55
  fields {
@@ -96,19 +96,22 @@ export default class DataUnitFetcher {
96
96
  });
97
97
  });
98
98
  }
99
- loadData(dataUnit, page, sort, filters) {
99
+ loadData(dataUnit, page, sort, filter) {
100
100
  return new Promise((resolve, reject) => {
101
- const variables = { dataunit: dataUnit.name, sort, filters };
101
+ const variables = { dataunit: dataUnit.name, sort, filter };
102
102
  if (page) {
103
103
  variables.limit = page.limit;
104
104
  variables.offset = page.offset;
105
105
  }
106
106
  if (!StringUtils.isEmpty(page === null || page === void 0 ? void 0 : page.quickFilter)) {
107
- variables.filter = [{
108
- name: "__ALL_SEARCHABLE_FIELDS__",
109
- expression: "__ALL_SEARCHABLE_FIELDS__",
110
- params: [{ name: "term", value: page.quickFilter }]
111
- }];
107
+ if (variables.filter === undefined) {
108
+ variables.filter = [];
109
+ }
110
+ variables.filter.push({
111
+ name: "__ALL_SEARCHABLE_FIELDS__",
112
+ expression: "__ALL_SEARCHABLE_FIELDS__",
113
+ params: [{ name: "term", value: page.quickFilter }]
114
+ });
112
115
  }
113
116
  DataFetcher.get()
114
117
  .callGraphQL({
@@ -138,10 +141,10 @@ export default class DataUnitFetcher {
138
141
  let parsedUpdatingFields;
139
142
  if (updatingFields) {
140
143
  parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
141
- return { fieldName, value: formatValueToServer(value) };
144
+ return { fieldName, value: dataUnit.valueToString(fieldName, value) };
142
145
  });
143
146
  }
144
- const reqChange = { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
147
+ const reqChange = { dataUnit: changeDU, fields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
145
148
  if (change.sourceId) {
146
149
  reqChange.sourceId = change.sourceId;
147
150
  }
@@ -191,18 +194,3 @@ export default class DataUnitFetcher {
191
194
  });
192
195
  }
193
196
  }
194
- export const formatValueToServer = (value) => {
195
- if (value === undefined)
196
- return value;
197
- try {
198
- if (value instanceof Date) {
199
- return value.toString();
200
- }
201
- //Any others objects
202
- value = JSON.stringify(value);
203
- }
204
- catch (_a) {
205
- value = value.toString();
206
- }
207
- return value;
208
- };
@@ -9,7 +9,7 @@ export class FormConfigFetcher extends ResourceFetcher {
9
9
  const { tabs, fields } = config;
10
10
  if (tabs) {
11
11
  const allTabs = new Map(tabs.map(t => [t.label, t]));
12
- fields.forEach(f => f.tab = allTabs.get(f.tab));
12
+ fields.forEach(f => f.tab = allTabs.get(this.getTabName(f.tab)));
13
13
  }
14
14
  accept(fields);
15
15
  }
@@ -22,4 +22,10 @@ export class FormConfigFetcher extends ResourceFetcher {
22
22
  });
23
23
  });
24
24
  }
25
+ getTabName(tab) {
26
+ if (typeof tab === 'object') { // TabConfig type
27
+ return tab.label;
28
+ }
29
+ return tab; //string type
30
+ }
25
31
  }
@@ -1,2 +1,29 @@
1
- export class GridConfigFetcher {
1
+ import { ResourceFetcher } from "./resource-fetcher";
2
+ export default class GridConfigFetcher extends ResourceFetcher {
3
+ getConfig(resourceID) {
4
+ const completePath = `cfg://grid/GrdCfgHtml5:${resourceID}`;
5
+ return new Promise((resolve, reject) => {
6
+ this.loadResource(completePath)
7
+ .then(loadedResource => {
8
+ if (loadedResource) {
9
+ let config = JSON.parse(loadedResource);
10
+ resolve(config);
11
+ }
12
+ }).catch((error) => {
13
+ reject(error);
14
+ });
15
+ });
16
+ }
17
+ saveConfig(config, resourceID) {
18
+ const completePath = `cfg://grid/GrdCfgHtml5:${resourceID}`;
19
+ return new Promise((resolve, reject) => {
20
+ this.saveResource(config, completePath)
21
+ .then((resp) => {
22
+ resolve(resp);
23
+ })
24
+ .catch((error) => {
25
+ reject(error);
26
+ });
27
+ });
28
+ }
2
29
  }
@@ -11,6 +11,9 @@ export class ResourceFetcher {
11
11
  resource
12
12
  }
13
13
  }`);
14
+ this.templateByQuery.set("saveResource", gql `mutation($resource: ResourceToSave!) {
15
+ $queryAlias$: saveResource(resource: $resource)
16
+ }`);
14
17
  }
15
18
  loadResource(name) {
16
19
  return new Promise((resolve, reject) => {
@@ -27,4 +30,24 @@ export class ResourceFetcher {
27
30
  });
28
31
  });
29
32
  }
33
+ saveResource(resource, name) {
34
+ return new Promise((resolve, reject) => {
35
+ DataFetcher.get()
36
+ .callGraphQL({
37
+ values: {
38
+ resource: {
39
+ name: name,
40
+ resource: JSON.stringify(resource)
41
+ }
42
+ },
43
+ query: this.templateByQuery.get("saveResource")
44
+ })
45
+ .then((resp) => {
46
+ resolve(resp);
47
+ })
48
+ .catch((error) => {
49
+ reject(error);
50
+ });
51
+ });
52
+ }
30
53
  }