@sankhyalabs/sankhyablocks 1.3.1 → 1.3.4

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 (47) hide show
  1. package/dist/cjs/{index-4720dab8.js → index-8272993f.js} +439 -7
  2. package/dist/cjs/loader.cjs.js +2 -2
  3. package/dist/cjs/sankhyablocks.cjs.js +2 -2
  4. package/dist/cjs/snk-application.cjs.entry.js +237 -60
  5. package/dist/cjs/snk-pesquisa.cjs.entry.js +19 -0
  6. package/dist/cjs/teste-pesquisa.cjs.entry.js +37 -0
  7. package/dist/collection/collection-manifest.json +3 -1
  8. package/dist/collection/components/snk-application/snk-application.js +104 -3
  9. package/dist/collection/components/snk-pesquisa/snk-pesquisa.css +3 -0
  10. package/dist/collection/components/snk-pesquisa/snk-pesquisa.js +74 -0
  11. package/dist/collection/components/teste-pesquisa/teste-pesquisa.css +3 -0
  12. package/dist/collection/components/teste-pesquisa/teste-pesquisa.js +33 -0
  13. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +47 -0
  14. package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +27 -19
  15. package/dist/collection/lib/http/data-fetcher/fetchers/pesquisa-fetcher.js +82 -0
  16. package/dist/collection/lib/workspace/workspace.js +2 -1
  17. package/dist/components/snk-application.js +1 -7089
  18. package/dist/components/snk-application2.js +7276 -0
  19. package/dist/components/snk-pesquisa.d.ts +11 -0
  20. package/dist/components/snk-pesquisa.js +6 -0
  21. package/dist/components/snk-pesquisa2.js +34 -0
  22. package/dist/components/teste-pesquisa.d.ts +11 -0
  23. package/dist/components/teste-pesquisa.js +63 -0
  24. package/dist/esm/{index-72d4e2e0.js → index-427447f8.js} +439 -8
  25. package/dist/esm/loader.js +2 -2
  26. package/dist/esm/sankhyablocks.js +2 -2
  27. package/dist/esm/snk-application.entry.js +238 -61
  28. package/dist/esm/snk-pesquisa.entry.js +15 -0
  29. package/dist/esm/teste-pesquisa.entry.js +33 -0
  30. package/dist/sankhyablocks/p-62f86dd6.entry.js +63 -0
  31. package/dist/sankhyablocks/p-91ca1a98.entry.js +1 -0
  32. package/dist/sankhyablocks/p-e6ba985e.entry.js +1 -0
  33. package/dist/sankhyablocks/p-ee5a384b.js +2 -0
  34. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  35. package/dist/types/components/snk-application/snk-application.d.ts +8 -0
  36. package/dist/types/components/snk-pesquisa/snk-pesquisa.d.ts +7 -0
  37. package/dist/types/components/teste-pesquisa/teste-pesquisa.d.ts +6 -0
  38. package/dist/types/components.d.ts +34 -0
  39. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +3 -0
  40. package/dist/types/lib/http/data-fetcher/fetchers/dataunit-fetcher.d.ts +1 -1
  41. package/dist/types/lib/http/data-fetcher/fetchers/pesquisa-fetcher.d.ts +17 -0
  42. package/package.json +8 -4
  43. package/react/components.d.ts +2 -0
  44. package/react/components.js +2 -0
  45. package/react/components.js.map +1 -1
  46. package/dist/sankhyablocks/p-5d8ddbda.entry.js +0 -57
  47. package/dist/sankhyablocks/p-a33afc3b.js +0 -2
@@ -1,6 +1,7 @@
1
- import { r as registerInstance, c as createEvent, h } from './index-72d4e2e0.js';
2
- import { DataUnit, ChangeOperation, DateUtils, StringUtils, ApplicationContext } from '@sankhyalabs/core';
1
+ import { r as registerInstance, c as createEvent, h } from './index-427447f8.js';
2
+ import { DataUnit, ChangeOperation, DateUtils, StringUtils, DataType, ApplicationContext } from '@sankhyalabs/core';
3
3
  import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';
4
+ import { DependencyType } from '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
4
5
 
5
6
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6
7
 
@@ -6429,6 +6430,30 @@ Object.defineProperty(exports, "GraphQLWebSocketClient", { enumerable: true, get
6429
6430
  //# sourceMappingURL=index.js.map
6430
6431
  });
6431
6432
 
6433
+ class UrlUtils {
6434
+ static getQueryParams(queryString) {
6435
+ const params = new Map();
6436
+ const re = /[?&]?([^=]+)=([^&]*)/g;
6437
+ let tokens;
6438
+ //Necessário por causa da tela Histórico Padrão que possui resourceID com acento
6439
+ queryString = window.unescape(queryString);
6440
+ queryString = queryString.split("+").join(" ");
6441
+ while ((tokens = re.exec(queryString))) {
6442
+ params.set(window.decodeURIComponent(tokens[1]), tokens[2]);
6443
+ }
6444
+ //Inserimos a urlBase no params.
6445
+ params.set("urlBase", this.getUrlBase());
6446
+ if (window["moduleID"] && window["URIServiceBroker"]) {
6447
+ params.set("moduleID", window["moduleID"]);
6448
+ params.set("URIServiceBroker", window["URIServiceBroker"]);
6449
+ }
6450
+ return params;
6451
+ }
6452
+ static getUrlBase() {
6453
+ return `${location.protocol}"//"${location.hostname}${location.port ? ":" + location.port : ""}`;
6454
+ }
6455
+ }
6456
+
6432
6457
  class HttpFetcher {
6433
6458
  constructor() {
6434
6459
  this.watingRequestsById = new Map();
@@ -6475,6 +6500,52 @@ class HttpFetcher {
6475
6500
  return (_a = this.getWatingRequest(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
6476
6501
  }
6477
6502
  }
6503
+ resolveURL() {
6504
+ if (window['mock_url'])
6505
+ return window['mock_url'];
6506
+ return UrlUtils.getUrlBase();
6507
+ }
6508
+ getContext() {
6509
+ const urlParams = UrlUtils.getQueryParams(location.search);
6510
+ return {
6511
+ baseUrl: `${this.resolveURL()}/mge/service.sbr`,
6512
+ appName: "SankhyaBlocks",
6513
+ mgeSession: `${window['skw_session'] || urlParams.mgeSession}`,
6514
+ globalID: "85C0093DFA240EAB699B4E47A10215BD",
6515
+ resourceID: "br.com.sankhya.mov.bancaria"
6516
+ };
6517
+ }
6518
+ async callServiceBroker(serviceName, payload) {
6519
+ return new Promise((accept, reject) => {
6520
+ const ctx = this.getContext();
6521
+ const url = `${ctx.baseUrl}?serviceName=${serviceName}&counter=21&application=${ctx.appName}&outputType=json&preventTransform=false&mgeSession=${ctx.mgeSession}&resourceID=${ctx.resourceID}&globalID=${ctx.globalID}&allowConcurrentCalls=true`;
6522
+ document.cookie = `JSESSIONID=${ctx.mgeSession};`;
6523
+ const http = new XMLHttpRequest();
6524
+ http.open("POST", url, true);
6525
+ http.withCredentials = true;
6526
+ http.send(payload);
6527
+ http.onreadystatechange = function () {
6528
+ if (this.readyState == 4 && this.status == 200) {
6529
+ try {
6530
+ const jsonResp = JSON.parse(this.responseText);
6531
+ if (jsonResp.status == 1) {
6532
+ accept(jsonResp.responseBody);
6533
+ }
6534
+ else {
6535
+ reject(jsonResp);
6536
+ }
6537
+ }
6538
+ catch (e) {
6539
+ console.warn(`callServiceBroker error to parser response to JSON ${e}`);
6540
+ reject(this.responseText);
6541
+ }
6542
+ }
6543
+ else if (this.readyState == 4 && this.status != 200) {
6544
+ reject(this.responseText);
6545
+ }
6546
+ };
6547
+ });
6548
+ }
6478
6549
  getReqKey(req) {
6479
6550
  return window.btoa(this.hashCode(`${req.query}${JSON.stringify(req.values || "")}`)).replace(/=/g, "");
6480
6551
  }
@@ -6600,6 +6671,7 @@ class DataUnitFetcher {
6600
6671
  name
6601
6672
  defaultValue
6602
6673
  label
6674
+ visible
6603
6675
  readOnly
6604
6676
  required
6605
6677
  dataType
@@ -6708,10 +6780,17 @@ class DataUnitFetcher {
6708
6780
  saveData(dataUnit, duChanges) {
6709
6781
  const changes = duChanges.map((change) => {
6710
6782
  const { dataUnit: changeDU, record, updatingFields, operation } = change;
6711
- const parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
6712
- return { fieldName, value: this.formatValueToServer(value) };
6713
- });
6714
- return { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6783
+ let parsedUpdatingFields;
6784
+ if (updatingFields) {
6785
+ parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
6786
+ return { fieldName, value: formatValueToServer(value) };
6787
+ });
6788
+ }
6789
+ const reqChange = { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6790
+ if (change.sourceId) {
6791
+ reqChange.sourceId = change.sourceId;
6792
+ }
6793
+ return reqChange;
6715
6794
  });
6716
6795
  return new Promise((resolve, reject) => {
6717
6796
  HttpFetcher.get()
@@ -6738,21 +6817,6 @@ class DataUnitFetcher {
6738
6817
  });
6739
6818
  });
6740
6819
  }
6741
- formatValueToServer(value) {
6742
- if (value === undefined)
6743
- return value;
6744
- try {
6745
- if (value instanceof Date) {
6746
- return value.toString();
6747
- }
6748
- //Any others objects
6749
- value = JSON.stringify(value);
6750
- }
6751
- catch (_a) {
6752
- value = value.toString();
6753
- }
6754
- return value;
6755
- }
6756
6820
  removeRecords(dataUnit, recordIds) {
6757
6821
  const changes = recordIds.map((recordId) => {
6758
6822
  return { dataUnit: dataUnit.name, operation: ChangeOperation.DELETE, recordId };
@@ -6772,38 +6836,30 @@ class DataUnitFetcher {
6772
6836
  });
6773
6837
  }
6774
6838
  }
6775
-
6776
- class UrlUtils {
6777
- static getQueryParams(queryString) {
6778
- const params = new Map();
6779
- const re = /[?&]?([^=]+)=([^&]*)/g;
6780
- let tokens;
6781
- //Necessário por causa da tela Histórico Padrão que possui resourceID com acento
6782
- queryString = window.unescape(queryString);
6783
- queryString = queryString.split("+").join(" ");
6784
- while ((tokens = re.exec(queryString))) {
6785
- params.set(window.decodeURIComponent(tokens[1]), tokens[2]);
6786
- }
6787
- //Inserimos a urlBase no params.
6788
- params.set("urlBase", this.getUrlBase());
6789
- if (window["moduleID"] && window["URIServiceBroker"]) {
6790
- params.set("moduleID", window["moduleID"]);
6791
- params.set("URIServiceBroker", window["URIServiceBroker"]);
6839
+ const formatValueToServer = (value) => {
6840
+ if (value === undefined)
6841
+ return value;
6842
+ try {
6843
+ if (value instanceof Date) {
6844
+ return value.toString();
6792
6845
  }
6793
- return params;
6846
+ //Any others objects
6847
+ value = JSON.stringify(value);
6794
6848
  }
6795
- static getUrlBase() {
6796
- return `${location.protocol}"//"${location.hostname}${location.port ? ":" + location.port : ""}`;
6849
+ catch (_a) {
6850
+ value = value.toString();
6797
6851
  }
6798
- }
6852
+ return value;
6853
+ };
6799
6854
 
6855
+ var _a;
6800
6856
  class Workspace {
6801
6857
  static openAppActivity(resourceId, pkObject) {
6802
6858
  var _a;
6803
6859
  (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.openAppActivity(resourceId, pkObject);
6804
6860
  }
6805
6861
  }
6806
- Workspace.resourceID = window["workspace"].resourceID;
6862
+ Workspace.resourceID = (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.resourceID;
6807
6863
 
6808
6864
  class ParametersFetcher {
6809
6865
  constructor() {
@@ -6916,22 +6972,85 @@ class FormConfigFetcher extends ResourceFetcher {
6916
6972
  }
6917
6973
  }
6918
6974
 
6919
- const mockByEntity = {
6920
- "ImplantacaoSaldoConta": [{ "value": 6, "label": "Conta Financeiro" }, { "value": 7, "label": "Conta Banco do Brasil" }],
6921
- "HistoricoBancario": [{ "value": 9, "label": "Lanç. Origem" }, { "value": 8, "label": "Lanç. Origem 2" }],
6922
- "ContaDestino": [{ "value": 10, "label": "Conta BB" }, { "value": 7, "label": "Conta Santander" }],
6923
- "HistoricoBancarioDestino": [{ "value": 11, "label": "Contra Bradesco" }, { "value": 13, "label": "Contra Destino" }],
6924
- "Usuario": [{ "value": 0, "label": "SUP" }],
6925
- "ContaBancaria": [{ "value": 10, "label": "Conta 10" }, { "value": 17, "label": "Conta 17" }],
6926
- "TipoOperacao": [{ "value": 4, "label": "Entrada NFse" }, { "value": 5, "label": "Outra top" }, { "value": 6, "label": "Top 6" }]
6927
- };
6928
- const pesquisaLoadOptions = (searchArgument, fieldName, dataUnit) => {
6929
- var _a;
6930
- console.log(searchArgument);
6931
- const field = dataUnit.getField(fieldName);
6932
- const entityName = (_a = field.properties) === null || _a === void 0 ? void 0 : _a.ENTITYNAME;
6933
- return (mockByEntity[entityName] || []);
6934
- };
6975
+ class PesquisaFetcher {
6976
+ constructor() {
6977
+ this.templateByQuery = new Map();
6978
+ this.buldTemplates();
6979
+ }
6980
+ buldTemplates() {
6981
+ this.templateByQuery.set("search", dist.gql `query($entityName: String! $argument: String $criteria: SearchCriteria) {
6982
+ $queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria){
6983
+ value
6984
+ label
6985
+ }
6986
+ }`);
6987
+ }
6988
+ loadSearchOptions(entityName, argument, criteria) {
6989
+ return new Promise((resolve, reject) => {
6990
+ HttpFetcher.get()
6991
+ .callGraphQL({
6992
+ values: { argument, entityName, criteria },
6993
+ query: this.templateByQuery.get("search"),
6994
+ })
6995
+ .then((result) => {
6996
+ resolve(result);
6997
+ })
6998
+ .catch((error) => {
6999
+ reject(error);
7000
+ });
7001
+ });
7002
+ }
7003
+ loadAdvancedSearch(entityName, argument, criteria) {
7004
+ const serviceName = "PesquisaSP.getSuggestion";
7005
+ const externalCriteria = {
7006
+ query: {
7007
+ $: criteria === null || criteria === void 0 ? void 0 : criteria.expression
7008
+ }
7009
+ };
7010
+ if ((criteria === null || criteria === void 0 ? void 0 : criteria.params.length) > 0) {
7011
+ externalCriteria.params = {
7012
+ param: criteria.params.map(p => { return { $: p.value, type: convertParamType(p.dataType) }; })
7013
+ };
7014
+ }
7015
+ const reqBody = {
7016
+ "serviceName": serviceName,
7017
+ "requestBody": {
7018
+ "criteria": {
7019
+ "entityName": entityName,
7020
+ "compacted": false,
7021
+ "ignoreEntityCriteria": false,
7022
+ "limit": "5",
7023
+ "query": { "$": argument },
7024
+ "orderByDesc": false,
7025
+ "options": { "showInactives": false },
7026
+ "externalCriteria": externalCriteria
7027
+ },
7028
+ "clientEventList": {
7029
+ "clientEvent": []
7030
+ }
7031
+ }
7032
+ };
7033
+ return new Promise((resolve, reject) => {
7034
+ HttpFetcher.get()
7035
+ .callServiceBroker("PesquisaSP.getSuggestion", JSON.stringify(reqBody))
7036
+ .then(result => resolve(result))
7037
+ .catch(error => reject(error));
7038
+ });
7039
+ }
7040
+ }
7041
+ function convertParamType(dataType) {
7042
+ //Alerta: Cuidado pra não contaminar o DataType com a implementação
7043
+ //atual da pesquisa... em geral, somente inteiros,
7044
+ //data (com ou sem hora) e string são realmente relevantes
7045
+ switch (dataType) {
7046
+ case DataType.NUMBER:
7047
+ return "I";
7048
+ case DataType.DATE:
7049
+ return "D";
7050
+ default:
7051
+ return "S";
7052
+ }
7053
+ }
6935
7054
 
6936
7055
  const snkApplicationCss = ".sc-snk-application-h{display:flex;flex-direction:column;height:100%}";
6937
7056
 
@@ -6971,6 +7090,16 @@ const SnkApplication = class {
6971
7090
  async getDateParam(name) {
6972
7091
  return this.parameters.asDate(name, this.resourceID);
6973
7092
  }
7093
+ async showPopUp(content) {
7094
+ this._popUp.appendChild(content);
7095
+ this._popUp["opened"] = true;
7096
+ }
7097
+ async closePopUp() {
7098
+ Array.from(this._popUp.children).forEach(c => {
7099
+ this._popUp.removeChild(c);
7100
+ });
7101
+ this._popUp["opened"] = false;
7102
+ }
6974
7103
  async temOpcional(opcional) {
6975
7104
  const opts = opcional.split(",");
6976
7105
  return new Promise((resolve, reject) => {
@@ -7043,8 +7172,56 @@ const SnkApplication = class {
7043
7172
  }
7044
7173
  return this._formConfigFetcher;
7045
7174
  }
7175
+ get pesquisaFetcher() {
7176
+ if (!this._pesquisaFetcher) {
7177
+ this._pesquisaFetcher = new PesquisaFetcher();
7178
+ }
7179
+ return this._pesquisaFetcher;
7180
+ }
7181
+ executeSearch(searchArgument, fieldName, dataUnit) {
7182
+ const descriptor = dataUnit.getField(fieldName);
7183
+ if (!descriptor) ;
7184
+ else {
7185
+ const { mode, argument } = searchArgument;
7186
+ const { ENTITYNAME } = descriptor.properties;
7187
+ const dependencies = descriptor.dependencies;
7188
+ let criteria;
7189
+ dependencies === null || dependencies === void 0 ? void 0 : dependencies.forEach(dependency => {
7190
+ var _a;
7191
+ if (dependency.type === DependencyType.SEARCHING) {
7192
+ if (((_a = dependency.masterFields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
7193
+ criteria = {
7194
+ expression: dependency.expression,
7195
+ params: dependency.masterFields.map(fieldName => {
7196
+ const masterDescriptor = dataUnit.getField(fieldName);
7197
+ const dataType = (masterDescriptor === null || masterDescriptor === void 0 ? void 0 : masterDescriptor.dataType) || DataType.TEXT;
7198
+ return { name: fieldName, value: dataUnit.getFieldValue(fieldName), dataType };
7199
+ })
7200
+ };
7201
+ }
7202
+ }
7203
+ });
7204
+ if (mode === "ADVANCED") {
7205
+ return new Promise(accept => {
7206
+ const pesquisaContent = document.createElement("snk-pesquisa");
7207
+ pesquisaContent.argument = argument;
7208
+ pesquisaContent.searchLoader = (text) => this.pesquisaFetcher.loadAdvancedSearch(ENTITYNAME, text, criteria);
7209
+ pesquisaContent.onSelectItem = (option) => {
7210
+ accept(option);
7211
+ this.closePopUp();
7212
+ };
7213
+ this.showPopUp(pesquisaContent);
7214
+ });
7215
+ }
7216
+ else {
7217
+ return this.pesquisaFetcher.loadSearchOptions(ENTITYNAME, argument, criteria);
7218
+ }
7219
+ }
7220
+ }
7046
7221
  componentWillLoad() {
7047
- ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", pesquisaLoadOptions);
7222
+ ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", (searchArgument, fieldName, dataUnit) => {
7223
+ return this.executeSearch(searchArgument, fieldName, dataUnit);
7224
+ });
7048
7225
  }
7049
7226
  componentDidLoad() {
7050
7227
  this.applicationLoading.emit(true);
@@ -7053,7 +7230,7 @@ const SnkApplication = class {
7053
7230
  });
7054
7231
  }
7055
7232
  render() {
7056
- return (h("div", null));
7233
+ return (h("div", null, h("ez-popup", { opened: false, ref: (ref) => this._popUp = ref, onEzClosePopup: () => this.closePopUp() })));
7057
7234
  }
7058
7235
  };
7059
7236
  SnkApplication.style = snkApplicationCss;
@@ -0,0 +1,15 @@
1
+ import { r as registerInstance, h, H as Host } from './index-427447f8.js';
2
+
3
+ const snkPesquisaCss = ":host{display:block}";
4
+
5
+ const SnkPesquisa = class {
6
+ constructor(hostRef) {
7
+ registerInstance(this, hostRef);
8
+ }
9
+ render() {
10
+ return (h(Host, null, h("ez-text-input", { ref: ref => this._textInput = ref, value: this.argument }), h("button", { onClick: () => this.searchLoader(this._textInput["value"]) }, "pesquisar"), h("button", { onClick: () => this.onSelectItem({ value: "10", label: "Zé das couves" }) }, "selecionar")));
11
+ }
12
+ };
13
+ SnkPesquisa.style = snkPesquisaCss;
14
+
15
+ export { SnkPesquisa as snk_pesquisa };
@@ -0,0 +1,33 @@
1
+ import { r as registerInstance, h } from './index-427447f8.js';
2
+ import { DataUnit, DataType, UserInterface } from '@sankhyalabs/core';
3
+
4
+ const testePesquisaCss = ":host{display:block}";
5
+
6
+ const TestePesquisa = class {
7
+ constructor(hostRef) {
8
+ registerInstance(this, hostRef);
9
+ }
10
+ componentWillLoad() {
11
+ this.dataUnit = new DataUnit("testes_com_formulario");
12
+ this.dataUnit.metadata = {
13
+ name: "dd://br.com.sankhya.fin.cad.movimentacaoFinanceira/Financeiro",
14
+ label: "Parceiro",
15
+ fields: [
16
+ {
17
+ name: "CODPARC",
18
+ label: "Parceiro",
19
+ dataType: DataType.NUMBER,
20
+ userInterface: UserInterface.SEARCH,
21
+ required: true,
22
+ properties: { ENTITYNAME: "Parceiro" }
23
+ }
24
+ ]
25
+ };
26
+ }
27
+ render() {
28
+ return (h("snk-application", null, h("ez-form", { dataUnit: this.dataUnit })));
29
+ }
30
+ };
31
+ TestePesquisa.style = testePesquisaCss;
32
+
33
+ export { TestePesquisa as teste_pesquisa };