@sankhyalabs/sankhyablocks 1.3.2 → 1.3.3

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 +227 -57
  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 +17 -16
  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 +7269 -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 +228 -58
  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-106c4d7b.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 +1 -1
  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-76b95007.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
@@ -6709,7 +6781,7 @@ class DataUnitFetcher {
6709
6781
  const changes = duChanges.map((change) => {
6710
6782
  const { dataUnit: changeDU, record, updatingFields, operation } = change;
6711
6783
  const parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
6712
- return { fieldName, value: this.formatValueToServer(value) };
6784
+ return { fieldName, value: formatValueToServer(value) };
6713
6785
  });
6714
6786
  return { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6715
6787
  });
@@ -6738,21 +6810,6 @@ class DataUnitFetcher {
6738
6810
  });
6739
6811
  });
6740
6812
  }
6741
- formatValueToServer(value) {
6742
- if (value === undefined)
6743
- return value;
6744
- try {
6745
- if (value instanceof Date || typeof value === 'string') {
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
6813
  removeRecords(dataUnit, recordIds) {
6757
6814
  const changes = recordIds.map((recordId) => {
6758
6815
  return { dataUnit: dataUnit.name, operation: ChangeOperation.DELETE, recordId };
@@ -6772,38 +6829,30 @@ class DataUnitFetcher {
6772
6829
  });
6773
6830
  }
6774
6831
  }
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"]);
6832
+ const formatValueToServer = (value) => {
6833
+ if (value === undefined)
6834
+ return value;
6835
+ try {
6836
+ if (value instanceof Date) {
6837
+ return value.toString();
6792
6838
  }
6793
- return params;
6839
+ //Any others objects
6840
+ value = JSON.stringify(value);
6794
6841
  }
6795
- static getUrlBase() {
6796
- return `${location.protocol}"//"${location.hostname}${location.port ? ":" + location.port : ""}`;
6842
+ catch (_a) {
6843
+ value = value.toString();
6797
6844
  }
6798
- }
6845
+ return value;
6846
+ };
6799
6847
 
6848
+ var _a;
6800
6849
  class Workspace {
6801
6850
  static openAppActivity(resourceId, pkObject) {
6802
6851
  var _a;
6803
6852
  (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.openAppActivity(resourceId, pkObject);
6804
6853
  }
6805
6854
  }
6806
- Workspace.resourceID = window["workspace"].resourceID;
6855
+ Workspace.resourceID = (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.resourceID;
6807
6856
 
6808
6857
  class ParametersFetcher {
6809
6858
  constructor() {
@@ -6916,22 +6965,85 @@ class FormConfigFetcher extends ResourceFetcher {
6916
6965
  }
6917
6966
  }
6918
6967
 
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
- };
6968
+ class PesquisaFetcher {
6969
+ constructor() {
6970
+ this.templateByQuery = new Map();
6971
+ this.buldTemplates();
6972
+ }
6973
+ buldTemplates() {
6974
+ this.templateByQuery.set("search", dist.gql `query($entityName: String! $argument: String $criteria: SearchCriteria) {
6975
+ $queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria){
6976
+ value
6977
+ label
6978
+ }
6979
+ }`);
6980
+ }
6981
+ loadSearchOptions(entityName, argument, criteria) {
6982
+ return new Promise((resolve, reject) => {
6983
+ HttpFetcher.get()
6984
+ .callGraphQL({
6985
+ values: { argument, entityName, criteria },
6986
+ query: this.templateByQuery.get("search"),
6987
+ })
6988
+ .then((result) => {
6989
+ resolve(result);
6990
+ })
6991
+ .catch((error) => {
6992
+ reject(error);
6993
+ });
6994
+ });
6995
+ }
6996
+ loadAdvancedSearch(entityName, argument, criteria) {
6997
+ const serviceName = "PesquisaSP.getSuggestion";
6998
+ const externalCriteria = {
6999
+ query: {
7000
+ $: criteria === null || criteria === void 0 ? void 0 : criteria.expression
7001
+ }
7002
+ };
7003
+ if ((criteria === null || criteria === void 0 ? void 0 : criteria.params.length) > 0) {
7004
+ externalCriteria.params = {
7005
+ param: criteria.params.map(p => { return { $: p.value, type: convertParamType(p.dataType) }; })
7006
+ };
7007
+ }
7008
+ const reqBody = {
7009
+ "serviceName": serviceName,
7010
+ "requestBody": {
7011
+ "criteria": {
7012
+ "entityName": entityName,
7013
+ "compacted": false,
7014
+ "ignoreEntityCriteria": false,
7015
+ "limit": "5",
7016
+ "query": { "$": argument },
7017
+ "orderByDesc": false,
7018
+ "options": { "showInactives": false },
7019
+ "externalCriteria": externalCriteria
7020
+ },
7021
+ "clientEventList": {
7022
+ "clientEvent": []
7023
+ }
7024
+ }
7025
+ };
7026
+ return new Promise((resolve, reject) => {
7027
+ HttpFetcher.get()
7028
+ .callServiceBroker("PesquisaSP.getSuggestion", JSON.stringify(reqBody))
7029
+ .then(result => resolve(result))
7030
+ .catch(error => reject(error));
7031
+ });
7032
+ }
7033
+ }
7034
+ function convertParamType(dataType) {
7035
+ //Alerta: Cuidado pra não contaminar o DataType com a implementação
7036
+ //atual da pesquisa... em geral, somente inteiros,
7037
+ //data (com ou sem hora) e string são realmente relevantes
7038
+ switch (dataType) {
7039
+ case DataType.NUMBER:
7040
+ return "I";
7041
+ case DataType.DATE:
7042
+ return "D";
7043
+ default:
7044
+ return "S";
7045
+ }
7046
+ }
6935
7047
 
6936
7048
  const snkApplicationCss = ".sc-snk-application-h{display:flex;flex-direction:column;height:100%}";
6937
7049
 
@@ -6971,6 +7083,16 @@ const SnkApplication = class {
6971
7083
  async getDateParam(name) {
6972
7084
  return this.parameters.asDate(name, this.resourceID);
6973
7085
  }
7086
+ async showPopUp(content) {
7087
+ this._popUp.appendChild(content);
7088
+ this._popUp["opened"] = true;
7089
+ }
7090
+ async closePopUp() {
7091
+ Array.from(this._popUp.children).forEach(c => {
7092
+ this._popUp.removeChild(c);
7093
+ });
7094
+ this._popUp["opened"] = false;
7095
+ }
6974
7096
  async temOpcional(opcional) {
6975
7097
  const opts = opcional.split(",");
6976
7098
  return new Promise((resolve, reject) => {
@@ -7043,8 +7165,56 @@ const SnkApplication = class {
7043
7165
  }
7044
7166
  return this._formConfigFetcher;
7045
7167
  }
7168
+ get pesquisaFetcher() {
7169
+ if (!this._pesquisaFetcher) {
7170
+ this._pesquisaFetcher = new PesquisaFetcher();
7171
+ }
7172
+ return this._pesquisaFetcher;
7173
+ }
7174
+ executeSearch(searchArgument, fieldName, dataUnit) {
7175
+ const descriptor = dataUnit.getField(fieldName);
7176
+ if (!descriptor) ;
7177
+ else {
7178
+ const { mode, argument } = searchArgument;
7179
+ const { ENTITYNAME } = descriptor.properties;
7180
+ const dependencies = descriptor.dependencies;
7181
+ let criteria;
7182
+ dependencies === null || dependencies === void 0 ? void 0 : dependencies.forEach(dependency => {
7183
+ var _a;
7184
+ if (dependency.type === DependencyType.SEARCHING) {
7185
+ if (((_a = dependency.masterFields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
7186
+ criteria = {
7187
+ expression: dependency.expression,
7188
+ params: dependency.masterFields.map(fieldName => {
7189
+ const masterDescriptor = dataUnit.getField(fieldName);
7190
+ const dataType = (masterDescriptor === null || masterDescriptor === void 0 ? void 0 : masterDescriptor.dataType) || DataType.TEXT;
7191
+ return { name: fieldName, value: dataUnit.getFieldValue(fieldName), dataType };
7192
+ })
7193
+ };
7194
+ }
7195
+ }
7196
+ });
7197
+ if (mode === "ADVANCED") {
7198
+ return new Promise(accept => {
7199
+ const pesquisaContent = document.createElement("snk-pesquisa");
7200
+ pesquisaContent.argument = argument;
7201
+ pesquisaContent.searchLoader = (text) => this.pesquisaFetcher.loadAdvancedSearch(ENTITYNAME, text, criteria);
7202
+ pesquisaContent.onSelectItem = (option) => {
7203
+ accept(option);
7204
+ this.closePopUp();
7205
+ };
7206
+ this.showPopUp(pesquisaContent);
7207
+ });
7208
+ }
7209
+ else {
7210
+ return this.pesquisaFetcher.loadSearchOptions(ENTITYNAME, argument, criteria);
7211
+ }
7212
+ }
7213
+ }
7046
7214
  componentWillLoad() {
7047
- ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", pesquisaLoadOptions);
7215
+ ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", (searchArgument, fieldName, dataUnit) => {
7216
+ return this.executeSearch(searchArgument, fieldName, dataUnit);
7217
+ });
7048
7218
  }
7049
7219
  componentDidLoad() {
7050
7220
  this.applicationLoading.emit(true);
@@ -7053,7 +7223,7 @@ const SnkApplication = class {
7053
7223
  });
7054
7224
  }
7055
7225
  render() {
7056
- return (h("div", null));
7226
+ return (h("div", null, h("ez-popup", { opened: false, ref: (ref) => this._popUp = ref, onEzClosePopup: () => this.closePopUp() })));
7057
7227
  }
7058
7228
  };
7059
7229
  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 };