@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
@@ -2,9 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index = require('./index-4720dab8.js');
5
+ const index = require('./index-8272993f.js');
6
6
  const core = require('@sankhyalabs/core');
7
7
  const utils = require('@sankhyalabs/ezui/dist/collection/utils');
8
+ const UnitMetadata = require('@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata');
8
9
 
9
10
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
10
11
 
@@ -6433,6 +6434,30 @@ Object.defineProperty(exports, "GraphQLWebSocketClient", { enumerable: true, get
6433
6434
  //# sourceMappingURL=index.js.map
6434
6435
  });
6435
6436
 
6437
+ class UrlUtils {
6438
+ static getQueryParams(queryString) {
6439
+ const params = new Map();
6440
+ const re = /[?&]?([^=]+)=([^&]*)/g;
6441
+ let tokens;
6442
+ //Necessário por causa da tela Histórico Padrão que possui resourceID com acento
6443
+ queryString = window.unescape(queryString);
6444
+ queryString = queryString.split("+").join(" ");
6445
+ while ((tokens = re.exec(queryString))) {
6446
+ params.set(window.decodeURIComponent(tokens[1]), tokens[2]);
6447
+ }
6448
+ //Inserimos a urlBase no params.
6449
+ params.set("urlBase", this.getUrlBase());
6450
+ if (window["moduleID"] && window["URIServiceBroker"]) {
6451
+ params.set("moduleID", window["moduleID"]);
6452
+ params.set("URIServiceBroker", window["URIServiceBroker"]);
6453
+ }
6454
+ return params;
6455
+ }
6456
+ static getUrlBase() {
6457
+ return `${location.protocol}"//"${location.hostname}${location.port ? ":" + location.port : ""}`;
6458
+ }
6459
+ }
6460
+
6436
6461
  class HttpFetcher {
6437
6462
  constructor() {
6438
6463
  this.watingRequestsById = new Map();
@@ -6479,6 +6504,52 @@ class HttpFetcher {
6479
6504
  return (_a = this.getWatingRequest(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
6480
6505
  }
6481
6506
  }
6507
+ resolveURL() {
6508
+ if (window['mock_url'])
6509
+ return window['mock_url'];
6510
+ return UrlUtils.getUrlBase();
6511
+ }
6512
+ getContext() {
6513
+ const urlParams = UrlUtils.getQueryParams(location.search);
6514
+ return {
6515
+ baseUrl: `${this.resolveURL()}/mge/service.sbr`,
6516
+ appName: "SankhyaBlocks",
6517
+ mgeSession: `${window['skw_session'] || urlParams.mgeSession}`,
6518
+ globalID: "85C0093DFA240EAB699B4E47A10215BD",
6519
+ resourceID: "br.com.sankhya.mov.bancaria"
6520
+ };
6521
+ }
6522
+ async callServiceBroker(serviceName, payload) {
6523
+ return new Promise((accept, reject) => {
6524
+ const ctx = this.getContext();
6525
+ 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`;
6526
+ document.cookie = `JSESSIONID=${ctx.mgeSession};`;
6527
+ const http = new XMLHttpRequest();
6528
+ http.open("POST", url, true);
6529
+ http.withCredentials = true;
6530
+ http.send(payload);
6531
+ http.onreadystatechange = function () {
6532
+ if (this.readyState == 4 && this.status == 200) {
6533
+ try {
6534
+ const jsonResp = JSON.parse(this.responseText);
6535
+ if (jsonResp.status == 1) {
6536
+ accept(jsonResp.responseBody);
6537
+ }
6538
+ else {
6539
+ reject(jsonResp);
6540
+ }
6541
+ }
6542
+ catch (e) {
6543
+ console.warn(`callServiceBroker error to parser response to JSON ${e}`);
6544
+ reject(this.responseText);
6545
+ }
6546
+ }
6547
+ else if (this.readyState == 4 && this.status != 200) {
6548
+ reject(this.responseText);
6549
+ }
6550
+ };
6551
+ });
6552
+ }
6482
6553
  getReqKey(req) {
6483
6554
  return window.btoa(this.hashCode(`${req.query}${JSON.stringify(req.values || "")}`)).replace(/=/g, "");
6484
6555
  }
@@ -6604,6 +6675,7 @@ class DataUnitFetcher {
6604
6675
  name
6605
6676
  defaultValue
6606
6677
  label
6678
+ visible
6607
6679
  readOnly
6608
6680
  required
6609
6681
  dataType
@@ -6712,10 +6784,17 @@ class DataUnitFetcher {
6712
6784
  saveData(dataUnit, duChanges) {
6713
6785
  const changes = duChanges.map((change) => {
6714
6786
  const { dataUnit: changeDU, record, updatingFields, operation } = change;
6715
- const parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
6716
- return { fieldName, value: this.formatValueToServer(value) };
6717
- });
6718
- return { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6787
+ let parsedUpdatingFields;
6788
+ if (updatingFields) {
6789
+ parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
6790
+ return { fieldName, value: formatValueToServer(value) };
6791
+ });
6792
+ }
6793
+ const reqChange = { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6794
+ if (change.sourceId) {
6795
+ reqChange.sourceId = change.sourceId;
6796
+ }
6797
+ return reqChange;
6719
6798
  });
6720
6799
  return new Promise((resolve, reject) => {
6721
6800
  HttpFetcher.get()
@@ -6742,21 +6821,6 @@ class DataUnitFetcher {
6742
6821
  });
6743
6822
  });
6744
6823
  }
6745
- formatValueToServer(value) {
6746
- if (value === undefined)
6747
- return value;
6748
- try {
6749
- if (value instanceof Date) {
6750
- return value.toString();
6751
- }
6752
- //Any others objects
6753
- value = JSON.stringify(value);
6754
- }
6755
- catch (_a) {
6756
- value = value.toString();
6757
- }
6758
- return value;
6759
- }
6760
6824
  removeRecords(dataUnit, recordIds) {
6761
6825
  const changes = recordIds.map((recordId) => {
6762
6826
  return { dataUnit: dataUnit.name, operation: core.ChangeOperation.DELETE, recordId };
@@ -6776,38 +6840,30 @@ class DataUnitFetcher {
6776
6840
  });
6777
6841
  }
6778
6842
  }
6779
-
6780
- class UrlUtils {
6781
- static getQueryParams(queryString) {
6782
- const params = new Map();
6783
- const re = /[?&]?([^=]+)=([^&]*)/g;
6784
- let tokens;
6785
- //Necessário por causa da tela Histórico Padrão que possui resourceID com acento
6786
- queryString = window.unescape(queryString);
6787
- queryString = queryString.split("+").join(" ");
6788
- while ((tokens = re.exec(queryString))) {
6789
- params.set(window.decodeURIComponent(tokens[1]), tokens[2]);
6790
- }
6791
- //Inserimos a urlBase no params.
6792
- params.set("urlBase", this.getUrlBase());
6793
- if (window["moduleID"] && window["URIServiceBroker"]) {
6794
- params.set("moduleID", window["moduleID"]);
6795
- params.set("URIServiceBroker", window["URIServiceBroker"]);
6843
+ const formatValueToServer = (value) => {
6844
+ if (value === undefined)
6845
+ return value;
6846
+ try {
6847
+ if (value instanceof Date) {
6848
+ return value.toString();
6796
6849
  }
6797
- return params;
6850
+ //Any others objects
6851
+ value = JSON.stringify(value);
6798
6852
  }
6799
- static getUrlBase() {
6800
- return `${location.protocol}"//"${location.hostname}${location.port ? ":" + location.port : ""}`;
6853
+ catch (_a) {
6854
+ value = value.toString();
6801
6855
  }
6802
- }
6856
+ return value;
6857
+ };
6803
6858
 
6859
+ var _a;
6804
6860
  class Workspace {
6805
6861
  static openAppActivity(resourceId, pkObject) {
6806
6862
  var _a;
6807
6863
  (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.openAppActivity(resourceId, pkObject);
6808
6864
  }
6809
6865
  }
6810
- Workspace.resourceID = window["workspace"].resourceID;
6866
+ Workspace.resourceID = (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.resourceID;
6811
6867
 
6812
6868
  class ParametersFetcher {
6813
6869
  constructor() {
@@ -6920,22 +6976,85 @@ class FormConfigFetcher extends ResourceFetcher {
6920
6976
  }
6921
6977
  }
6922
6978
 
6923
- const mockByEntity = {
6924
- "ImplantacaoSaldoConta": [{ "value": 6, "label": "Conta Financeiro" }, { "value": 7, "label": "Conta Banco do Brasil" }],
6925
- "HistoricoBancario": [{ "value": 9, "label": "Lanç. Origem" }, { "value": 8, "label": "Lanç. Origem 2" }],
6926
- "ContaDestino": [{ "value": 10, "label": "Conta BB" }, { "value": 7, "label": "Conta Santander" }],
6927
- "HistoricoBancarioDestino": [{ "value": 11, "label": "Contra Bradesco" }, { "value": 13, "label": "Contra Destino" }],
6928
- "Usuario": [{ "value": 0, "label": "SUP" }],
6929
- "ContaBancaria": [{ "value": 10, "label": "Conta 10" }, { "value": 17, "label": "Conta 17" }],
6930
- "TipoOperacao": [{ "value": 4, "label": "Entrada NFse" }, { "value": 5, "label": "Outra top" }, { "value": 6, "label": "Top 6" }]
6931
- };
6932
- const pesquisaLoadOptions = (searchArgument, fieldName, dataUnit) => {
6933
- var _a;
6934
- console.log(searchArgument);
6935
- const field = dataUnit.getField(fieldName);
6936
- const entityName = (_a = field.properties) === null || _a === void 0 ? void 0 : _a.ENTITYNAME;
6937
- return (mockByEntity[entityName] || []);
6938
- };
6979
+ class PesquisaFetcher {
6980
+ constructor() {
6981
+ this.templateByQuery = new Map();
6982
+ this.buldTemplates();
6983
+ }
6984
+ buldTemplates() {
6985
+ this.templateByQuery.set("search", dist.gql `query($entityName: String! $argument: String $criteria: SearchCriteria) {
6986
+ $queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria){
6987
+ value
6988
+ label
6989
+ }
6990
+ }`);
6991
+ }
6992
+ loadSearchOptions(entityName, argument, criteria) {
6993
+ return new Promise((resolve, reject) => {
6994
+ HttpFetcher.get()
6995
+ .callGraphQL({
6996
+ values: { argument, entityName, criteria },
6997
+ query: this.templateByQuery.get("search"),
6998
+ })
6999
+ .then((result) => {
7000
+ resolve(result);
7001
+ })
7002
+ .catch((error) => {
7003
+ reject(error);
7004
+ });
7005
+ });
7006
+ }
7007
+ loadAdvancedSearch(entityName, argument, criteria) {
7008
+ const serviceName = "PesquisaSP.getSuggestion";
7009
+ const externalCriteria = {
7010
+ query: {
7011
+ $: criteria === null || criteria === void 0 ? void 0 : criteria.expression
7012
+ }
7013
+ };
7014
+ if ((criteria === null || criteria === void 0 ? void 0 : criteria.params.length) > 0) {
7015
+ externalCriteria.params = {
7016
+ param: criteria.params.map(p => { return { $: p.value, type: convertParamType(p.dataType) }; })
7017
+ };
7018
+ }
7019
+ const reqBody = {
7020
+ "serviceName": serviceName,
7021
+ "requestBody": {
7022
+ "criteria": {
7023
+ "entityName": entityName,
7024
+ "compacted": false,
7025
+ "ignoreEntityCriteria": false,
7026
+ "limit": "5",
7027
+ "query": { "$": argument },
7028
+ "orderByDesc": false,
7029
+ "options": { "showInactives": false },
7030
+ "externalCriteria": externalCriteria
7031
+ },
7032
+ "clientEventList": {
7033
+ "clientEvent": []
7034
+ }
7035
+ }
7036
+ };
7037
+ return new Promise((resolve, reject) => {
7038
+ HttpFetcher.get()
7039
+ .callServiceBroker("PesquisaSP.getSuggestion", JSON.stringify(reqBody))
7040
+ .then(result => resolve(result))
7041
+ .catch(error => reject(error));
7042
+ });
7043
+ }
7044
+ }
7045
+ function convertParamType(dataType) {
7046
+ //Alerta: Cuidado pra não contaminar o DataType com a implementação
7047
+ //atual da pesquisa... em geral, somente inteiros,
7048
+ //data (com ou sem hora) e string são realmente relevantes
7049
+ switch (dataType) {
7050
+ case core.DataType.NUMBER:
7051
+ return "I";
7052
+ case core.DataType.DATE:
7053
+ return "D";
7054
+ default:
7055
+ return "S";
7056
+ }
7057
+ }
6939
7058
 
6940
7059
  const snkApplicationCss = ".sc-snk-application-h{display:flex;flex-direction:column;height:100%}";
6941
7060
 
@@ -6975,6 +7094,16 @@ const SnkApplication = class {
6975
7094
  async getDateParam(name) {
6976
7095
  return this.parameters.asDate(name, this.resourceID);
6977
7096
  }
7097
+ async showPopUp(content) {
7098
+ this._popUp.appendChild(content);
7099
+ this._popUp["opened"] = true;
7100
+ }
7101
+ async closePopUp() {
7102
+ Array.from(this._popUp.children).forEach(c => {
7103
+ this._popUp.removeChild(c);
7104
+ });
7105
+ this._popUp["opened"] = false;
7106
+ }
6978
7107
  async temOpcional(opcional) {
6979
7108
  const opts = opcional.split(",");
6980
7109
  return new Promise((resolve, reject) => {
@@ -7047,8 +7176,56 @@ const SnkApplication = class {
7047
7176
  }
7048
7177
  return this._formConfigFetcher;
7049
7178
  }
7179
+ get pesquisaFetcher() {
7180
+ if (!this._pesquisaFetcher) {
7181
+ this._pesquisaFetcher = new PesquisaFetcher();
7182
+ }
7183
+ return this._pesquisaFetcher;
7184
+ }
7185
+ executeSearch(searchArgument, fieldName, dataUnit) {
7186
+ const descriptor = dataUnit.getField(fieldName);
7187
+ if (!descriptor) ;
7188
+ else {
7189
+ const { mode, argument } = searchArgument;
7190
+ const { ENTITYNAME } = descriptor.properties;
7191
+ const dependencies = descriptor.dependencies;
7192
+ let criteria;
7193
+ dependencies === null || dependencies === void 0 ? void 0 : dependencies.forEach(dependency => {
7194
+ var _a;
7195
+ if (dependency.type === UnitMetadata.DependencyType.SEARCHING) {
7196
+ if (((_a = dependency.masterFields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
7197
+ criteria = {
7198
+ expression: dependency.expression,
7199
+ params: dependency.masterFields.map(fieldName => {
7200
+ const masterDescriptor = dataUnit.getField(fieldName);
7201
+ const dataType = (masterDescriptor === null || masterDescriptor === void 0 ? void 0 : masterDescriptor.dataType) || core.DataType.TEXT;
7202
+ return { name: fieldName, value: dataUnit.getFieldValue(fieldName), dataType };
7203
+ })
7204
+ };
7205
+ }
7206
+ }
7207
+ });
7208
+ if (mode === "ADVANCED") {
7209
+ return new Promise(accept => {
7210
+ const pesquisaContent = document.createElement("snk-pesquisa");
7211
+ pesquisaContent.argument = argument;
7212
+ pesquisaContent.searchLoader = (text) => this.pesquisaFetcher.loadAdvancedSearch(ENTITYNAME, text, criteria);
7213
+ pesquisaContent.onSelectItem = (option) => {
7214
+ accept(option);
7215
+ this.closePopUp();
7216
+ };
7217
+ this.showPopUp(pesquisaContent);
7218
+ });
7219
+ }
7220
+ else {
7221
+ return this.pesquisaFetcher.loadSearchOptions(ENTITYNAME, argument, criteria);
7222
+ }
7223
+ }
7224
+ }
7050
7225
  componentWillLoad() {
7051
- core.ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", pesquisaLoadOptions);
7226
+ core.ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", (searchArgument, fieldName, dataUnit) => {
7227
+ return this.executeSearch(searchArgument, fieldName, dataUnit);
7228
+ });
7052
7229
  }
7053
7230
  componentDidLoad() {
7054
7231
  this.applicationLoading.emit(true);
@@ -7057,7 +7234,7 @@ const SnkApplication = class {
7057
7234
  });
7058
7235
  }
7059
7236
  render() {
7060
- return (index.h("div", null));
7237
+ return (index.h("div", null, index.h("ez-popup", { opened: false, ref: (ref) => this._popUp = ref, onEzClosePopup: () => this.closePopUp() })));
7061
7238
  }
7062
7239
  };
7063
7240
  SnkApplication.style = snkApplicationCss;
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-8272993f.js');
6
+
7
+ const snkPesquisaCss = ":host{display:block}";
8
+
9
+ const SnkPesquisa = class {
10
+ constructor(hostRef) {
11
+ index.registerInstance(this, hostRef);
12
+ }
13
+ render() {
14
+ return (index.h(index.Host, null, index.h("ez-text-input", { ref: ref => this._textInput = ref, value: this.argument }), index.h("button", { onClick: () => this.searchLoader(this._textInput["value"]) }, "pesquisar"), index.h("button", { onClick: () => this.onSelectItem({ value: "10", label: "Zé das couves" }) }, "selecionar")));
15
+ }
16
+ };
17
+ SnkPesquisa.style = snkPesquisaCss;
18
+
19
+ exports.snk_pesquisa = SnkPesquisa;
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-8272993f.js');
6
+ const core = require('@sankhyalabs/core');
7
+
8
+ const testePesquisaCss = ":host{display:block}";
9
+
10
+ const TestePesquisa = class {
11
+ constructor(hostRef) {
12
+ index.registerInstance(this, hostRef);
13
+ }
14
+ componentWillLoad() {
15
+ this.dataUnit = new core.DataUnit("testes_com_formulario");
16
+ this.dataUnit.metadata = {
17
+ name: "dd://br.com.sankhya.fin.cad.movimentacaoFinanceira/Financeiro",
18
+ label: "Parceiro",
19
+ fields: [
20
+ {
21
+ name: "CODPARC",
22
+ label: "Parceiro",
23
+ dataType: core.DataType.NUMBER,
24
+ userInterface: core.UserInterface.SEARCH,
25
+ required: true,
26
+ properties: { ENTITYNAME: "Parceiro" }
27
+ }
28
+ ]
29
+ };
30
+ }
31
+ render() {
32
+ return (index.h("snk-application", null, index.h("ez-form", { dataUnit: this.dataUnit })));
33
+ }
34
+ };
35
+ TestePesquisa.style = testePesquisaCss;
36
+
37
+ exports.teste_pesquisa = TestePesquisa;
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "entries": [
3
- "./components/snk-application/snk-application.js"
3
+ "./components/snk-application/snk-application.js",
4
+ "./components/snk-pesquisa/snk-pesquisa.js",
5
+ "./components/teste-pesquisa/teste-pesquisa.js"
4
6
  ],
5
7
  "compiler": {
6
8
  "name": "@stencil/core",
@@ -1,4 +1,5 @@
1
1
  import { Component, h, Method, Event } from "@stencil/core";
2
+ import { DataType } from "@sankhyalabs/core";
2
3
  import DataUnitFetcher from "../../lib/http/data-fetcher/fetchers/dataunit-fetcher";
3
4
  import UrlUtils from "../../lib/utils/urlutils";
4
5
  import Workspace from "../../lib/workspace/workspace";
@@ -6,7 +7,8 @@ import ParametersFetcher from "../../lib/http/data-fetcher/fetchers/parameters-f
6
7
  import { ApplicationUtils } from "@sankhyalabs/ezui/dist/collection/utils";
7
8
  import { FormConfigFetcher } from "../../lib/http/data-fetcher/fetchers/form-config-fetcher";
8
9
  import { ApplicationContext } from "@sankhyalabs/core";
9
- import { pesquisaLoadOptions } from "../../lib/utils/pesquisa";
10
+ import { PesquisaFetcher } from "../../lib/http/data-fetcher/fetchers/pesquisa-fetcher";
11
+ import { DependencyType } from "@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata";
10
12
  export class SnkApplication {
11
13
  get parameters() {
12
14
  if (!this._parameters) {
@@ -38,6 +40,16 @@ export class SnkApplication {
38
40
  async getDateParam(name) {
39
41
  return this.parameters.asDate(name, this.resourceID);
40
42
  }
43
+ async showPopUp(content) {
44
+ this._popUp.appendChild(content);
45
+ this._popUp["opened"] = true;
46
+ }
47
+ async closePopUp() {
48
+ Array.from(this._popUp.children).forEach(c => {
49
+ this._popUp.removeChild(c);
50
+ });
51
+ this._popUp["opened"] = false;
52
+ }
41
53
  async temOpcional(opcional) {
42
54
  const opts = opcional.split(",");
43
55
  return new Promise((resolve, reject) => {
@@ -110,8 +122,58 @@ export class SnkApplication {
110
122
  }
111
123
  return this._formConfigFetcher;
112
124
  }
125
+ get pesquisaFetcher() {
126
+ if (!this._pesquisaFetcher) {
127
+ this._pesquisaFetcher = new PesquisaFetcher();
128
+ }
129
+ return this._pesquisaFetcher;
130
+ }
131
+ executeSearch(searchArgument, fieldName, dataUnit) {
132
+ const descriptor = dataUnit.getField(fieldName);
133
+ if (!descriptor) {
134
+ //TODO: Implementar mensagem de erro
135
+ }
136
+ else {
137
+ const { mode, argument } = searchArgument;
138
+ const { ENTITYNAME } = descriptor.properties;
139
+ const dependencies = descriptor.dependencies;
140
+ let criteria;
141
+ dependencies === null || dependencies === void 0 ? void 0 : dependencies.forEach(dependency => {
142
+ var _a;
143
+ if (dependency.type === DependencyType.SEARCHING) {
144
+ if (((_a = dependency.masterFields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
145
+ criteria = {
146
+ expression: dependency.expression,
147
+ params: dependency.masterFields.map(fieldName => {
148
+ const masterDescriptor = dataUnit.getField(fieldName);
149
+ const dataType = (masterDescriptor === null || masterDescriptor === void 0 ? void 0 : masterDescriptor.dataType) || DataType.TEXT;
150
+ return { name: fieldName, value: dataUnit.getFieldValue(fieldName), dataType };
151
+ })
152
+ };
153
+ }
154
+ }
155
+ });
156
+ if (mode === "ADVANCED") {
157
+ return new Promise(accept => {
158
+ const pesquisaContent = document.createElement("snk-pesquisa");
159
+ pesquisaContent.argument = argument;
160
+ pesquisaContent.searchLoader = (text) => this.pesquisaFetcher.loadAdvancedSearch(ENTITYNAME, text, criteria);
161
+ pesquisaContent.onSelectItem = (option) => {
162
+ accept(option);
163
+ this.closePopUp();
164
+ };
165
+ this.showPopUp(pesquisaContent);
166
+ });
167
+ }
168
+ else {
169
+ return this.pesquisaFetcher.loadSearchOptions(ENTITYNAME, argument, criteria);
170
+ }
171
+ }
172
+ }
113
173
  componentWillLoad() {
114
- ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", pesquisaLoadOptions);
174
+ ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", (searchArgument, fieldName, dataUnit) => {
175
+ return this.executeSearch(searchArgument, fieldName, dataUnit);
176
+ });
115
177
  }
116
178
  componentDidLoad() {
117
179
  this.applicationLoading.emit(true);
@@ -120,7 +182,8 @@ export class SnkApplication {
120
182
  });
121
183
  }
122
184
  render() {
123
- return (h("div", null));
185
+ return (h("div", null,
186
+ h("ez-popup", { opened: false, ref: (ref) => this._popUp = ref, onEzClosePopup: () => this.closePopUp() })));
124
187
  }
125
188
  static get is() { return "snk-application"; }
126
189
  static get encapsulation() { return "scoped"; }
@@ -260,6 +323,44 @@ export class SnkApplication {
260
323
  "tags": []
261
324
  }
262
325
  },
326
+ "showPopUp": {
327
+ "complexType": {
328
+ "signature": "(content: HTMLElement) => Promise<void>",
329
+ "parameters": [{
330
+ "tags": [],
331
+ "text": ""
332
+ }],
333
+ "references": {
334
+ "Promise": {
335
+ "location": "global"
336
+ },
337
+ "HTMLElement": {
338
+ "location": "global"
339
+ }
340
+ },
341
+ "return": "Promise<void>"
342
+ },
343
+ "docs": {
344
+ "text": "",
345
+ "tags": []
346
+ }
347
+ },
348
+ "closePopUp": {
349
+ "complexType": {
350
+ "signature": "() => Promise<void>",
351
+ "parameters": [],
352
+ "references": {
353
+ "Promise": {
354
+ "location": "global"
355
+ }
356
+ },
357
+ "return": "Promise<void>"
358
+ },
359
+ "docs": {
360
+ "text": "",
361
+ "tags": []
362
+ }
363
+ },
263
364
  "temOpcional": {
264
365
  "complexType": {
265
366
  "signature": "(opcional: string) => Promise<boolean>",
@@ -0,0 +1,3 @@
1
+ :host {
2
+ display: block;
3
+ }
@@ -0,0 +1,74 @@
1
+ import { Component, Host, h, Prop } from '@stencil/core';
2
+ export class SnkPesquisa {
3
+ render() {
4
+ return (h(Host, null,
5
+ h("ez-text-input", { ref: ref => this._textInput = ref, value: this.argument }),
6
+ h("button", { onClick: () => this.searchLoader(this._textInput["value"]) }, "pesquisar"),
7
+ h("button", { onClick: () => this.onSelectItem({ value: "10", label: "Zé das couves" }) }, "selecionar")));
8
+ }
9
+ static get is() { return "snk-pesquisa"; }
10
+ static get encapsulation() { return "shadow"; }
11
+ static get originalStyleUrls() { return {
12
+ "$": ["snk-pesquisa.css"]
13
+ }; }
14
+ static get styleUrls() { return {
15
+ "$": ["snk-pesquisa.css"]
16
+ }; }
17
+ static get properties() { return {
18
+ "searchLoader": {
19
+ "type": "unknown",
20
+ "mutable": false,
21
+ "complexType": {
22
+ "original": "Function",
23
+ "resolved": "Function",
24
+ "references": {
25
+ "Function": {
26
+ "location": "global"
27
+ }
28
+ }
29
+ },
30
+ "required": false,
31
+ "optional": false,
32
+ "docs": {
33
+ "tags": [],
34
+ "text": ""
35
+ }
36
+ },
37
+ "onSelectItem": {
38
+ "type": "unknown",
39
+ "mutable": false,
40
+ "complexType": {
41
+ "original": "Function",
42
+ "resolved": "Function",
43
+ "references": {
44
+ "Function": {
45
+ "location": "global"
46
+ }
47
+ }
48
+ },
49
+ "required": false,
50
+ "optional": false,
51
+ "docs": {
52
+ "tags": [],
53
+ "text": ""
54
+ }
55
+ },
56
+ "argument": {
57
+ "type": "string",
58
+ "mutable": true,
59
+ "complexType": {
60
+ "original": "string",
61
+ "resolved": "string",
62
+ "references": {}
63
+ },
64
+ "required": false,
65
+ "optional": false,
66
+ "docs": {
67
+ "tags": [],
68
+ "text": ""
69
+ },
70
+ "attribute": "argument",
71
+ "reflect": false
72
+ }
73
+ }; }
74
+ }
@@ -0,0 +1,3 @@
1
+ :host {
2
+ display: block;
3
+ }