@sankhyalabs/sankhyablocks 1.3.2 → 1.3.5

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 +260 -71
  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 +51 -31
  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 +7288 -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 +261 -72
  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-727ea2f4.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
@@ -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
@@ -6620,10 +6692,10 @@ class DataUnitFetcher {
6620
6692
  }
6621
6693
  }
6622
6694
  }`);
6623
- this.templateByQuery.set("fetchData", dist.gql `query($dataunit: String! $first: Int $offset:Int $filter: [Filter!] $sort: [Sort!]) {
6695
+ this.templateByQuery.set("fetchData", dist.gql `query($dataunit: String! $limit: Int $offset:Int $filter: [Filter!] $sort: [Sort!]) {
6624
6696
  $queryAlias$: fetchDataUnit(name: $dataunit){
6625
- data(first: $first offset: $offset filters: $filter sort: $sort){
6626
- first
6697
+ data(limit: $limit offset: $offset filters: $filter sort: $sort){
6698
+ limit
6627
6699
  offset
6628
6700
  total
6629
6701
  hasMore
@@ -6651,7 +6723,7 @@ class DataUnitFetcher {
6651
6723
  getDataUnit(entityName, resourceID) {
6652
6724
  const dataUnit = new core.DataUnit(`dd://${entityName}/${resourceID}`);
6653
6725
  dataUnit.metadataLoader = (dataUnit) => this.loadMetadata(dataUnit);
6654
- dataUnit.dataLoader = (dataUnit, sort, filters) => this.loadData(dataUnit, sort, filters);
6726
+ dataUnit.dataLoader = (dataUnit, page, sort, filters) => this.loadData(dataUnit, page, sort, filters);
6655
6727
  dataUnit.saveLoader = (dataUnit, changes) => this.saveData(dataUnit, changes);
6656
6728
  dataUnit.removeLoader = (dataUnit, recordIds) => this.removeRecords(dataUnit, recordIds);
6657
6729
  return dataUnit;
@@ -6685,24 +6757,36 @@ class DataUnitFetcher {
6685
6757
  });
6686
6758
  });
6687
6759
  }
6688
- loadData(dataUnit, sort, filters) {
6760
+ loadData(dataUnit, page, sort, filters) {
6689
6761
  return new Promise((resolve, reject) => {
6762
+ const variables = { dataunit: dataUnit.name, sort, filters };
6763
+ if (page) {
6764
+ variables.limit = page.limit;
6765
+ variables.offset = page.offset;
6766
+ }
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
+ }];
6773
+ }
6690
6774
  HttpFetcher.get()
6691
6775
  .callGraphQL({
6692
- values: { dataunit: dataUnit.name, sort, filters },
6776
+ values: variables,
6693
6777
  query: this.templateByQuery.get("fetchData"),
6694
6778
  })
6695
6779
  .then((resp) => {
6696
- const result = resp.data;
6697
- const dataUnitRecords = [];
6698
- result.records.forEach((responseRecord) => {
6780
+ const pageResult = resp.data;
6781
+ const records = [];
6782
+ pageResult.records.forEach((responseRecord) => {
6699
6783
  const duRecord = { __record__id__: responseRecord.id };
6700
6784
  responseRecord.fields.forEach(({ name, value }) => {
6701
6785
  duRecord[name] = dataUnit.valueFromString(name, value);
6702
6786
  });
6703
- dataUnitRecords.push(duRecord);
6787
+ records.push(duRecord);
6704
6788
  });
6705
- resolve(dataUnitRecords);
6789
+ resolve(Object.assign(Object.assign({}, pageResult), { records }));
6706
6790
  })
6707
6791
  .catch((error) => {
6708
6792
  reject(error);
@@ -6712,10 +6796,17 @@ class DataUnitFetcher {
6712
6796
  saveData(dataUnit, duChanges) {
6713
6797
  const changes = duChanges.map((change) => {
6714
6798
  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__ };
6799
+ let parsedUpdatingFields;
6800
+ if (updatingFields) {
6801
+ parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
6802
+ return { fieldName, value: formatValueToServer(value) };
6803
+ });
6804
+ }
6805
+ const reqChange = { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6806
+ if (change.sourceId) {
6807
+ reqChange.sourceId = change.sourceId;
6808
+ }
6809
+ return reqChange;
6719
6810
  });
6720
6811
  return new Promise((resolve, reject) => {
6721
6812
  HttpFetcher.get()
@@ -6742,21 +6833,6 @@ class DataUnitFetcher {
6742
6833
  });
6743
6834
  });
6744
6835
  }
6745
- formatValueToServer(value) {
6746
- if (value === undefined)
6747
- return value;
6748
- try {
6749
- if (value instanceof Date || typeof value === 'string') {
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
6836
  removeRecords(dataUnit, recordIds) {
6761
6837
  const changes = recordIds.map((recordId) => {
6762
6838
  return { dataUnit: dataUnit.name, operation: core.ChangeOperation.DELETE, recordId };
@@ -6776,38 +6852,30 @@ class DataUnitFetcher {
6776
6852
  });
6777
6853
  }
6778
6854
  }
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"]);
6855
+ const formatValueToServer = (value) => {
6856
+ if (value === undefined)
6857
+ return value;
6858
+ try {
6859
+ if (value instanceof Date) {
6860
+ return value.toString();
6796
6861
  }
6797
- return params;
6862
+ //Any others objects
6863
+ value = JSON.stringify(value);
6798
6864
  }
6799
- static getUrlBase() {
6800
- return `${location.protocol}"//"${location.hostname}${location.port ? ":" + location.port : ""}`;
6865
+ catch (_a) {
6866
+ value = value.toString();
6801
6867
  }
6802
- }
6868
+ return value;
6869
+ };
6803
6870
 
6871
+ var _a;
6804
6872
  class Workspace {
6805
6873
  static openAppActivity(resourceId, pkObject) {
6806
6874
  var _a;
6807
6875
  (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.openAppActivity(resourceId, pkObject);
6808
6876
  }
6809
6877
  }
6810
- Workspace.resourceID = window["workspace"].resourceID;
6878
+ Workspace.resourceID = (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.resourceID;
6811
6879
 
6812
6880
  class ParametersFetcher {
6813
6881
  constructor() {
@@ -6920,22 +6988,85 @@ class FormConfigFetcher extends ResourceFetcher {
6920
6988
  }
6921
6989
  }
6922
6990
 
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
- };
6991
+ class PesquisaFetcher {
6992
+ constructor() {
6993
+ this.templateByQuery = new Map();
6994
+ this.buldTemplates();
6995
+ }
6996
+ buldTemplates() {
6997
+ this.templateByQuery.set("search", dist.gql `query($entityName: String! $argument: String $criteria: SearchCriteria) {
6998
+ $queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria){
6999
+ value
7000
+ label
7001
+ }
7002
+ }`);
7003
+ }
7004
+ loadSearchOptions(entityName, argument, criteria) {
7005
+ return new Promise((resolve, reject) => {
7006
+ HttpFetcher.get()
7007
+ .callGraphQL({
7008
+ values: { argument, entityName, criteria },
7009
+ query: this.templateByQuery.get("search"),
7010
+ })
7011
+ .then((result) => {
7012
+ resolve(result);
7013
+ })
7014
+ .catch((error) => {
7015
+ reject(error);
7016
+ });
7017
+ });
7018
+ }
7019
+ loadAdvancedSearch(entityName, argument, criteria) {
7020
+ const serviceName = "PesquisaSP.getSuggestion";
7021
+ const externalCriteria = {
7022
+ query: {
7023
+ $: criteria === null || criteria === void 0 ? void 0 : criteria.expression
7024
+ }
7025
+ };
7026
+ if ((criteria === null || criteria === void 0 ? void 0 : criteria.params.length) > 0) {
7027
+ externalCriteria.params = {
7028
+ param: criteria.params.map(p => { return { $: p.value, type: convertParamType(p.dataType) }; })
7029
+ };
7030
+ }
7031
+ const reqBody = {
7032
+ "serviceName": serviceName,
7033
+ "requestBody": {
7034
+ "criteria": {
7035
+ "entityName": entityName,
7036
+ "compacted": false,
7037
+ "ignoreEntityCriteria": false,
7038
+ "limit": "5",
7039
+ "query": { "$": argument },
7040
+ "orderByDesc": false,
7041
+ "options": { "showInactives": false },
7042
+ "externalCriteria": externalCriteria
7043
+ },
7044
+ "clientEventList": {
7045
+ "clientEvent": []
7046
+ }
7047
+ }
7048
+ };
7049
+ return new Promise((resolve, reject) => {
7050
+ HttpFetcher.get()
7051
+ .callServiceBroker("PesquisaSP.getSuggestion", JSON.stringify(reqBody))
7052
+ .then(result => resolve(result))
7053
+ .catch(error => reject(error));
7054
+ });
7055
+ }
7056
+ }
7057
+ function convertParamType(dataType) {
7058
+ //Alerta: Cuidado pra não contaminar o DataType com a implementação
7059
+ //atual da pesquisa... em geral, somente inteiros,
7060
+ //data (com ou sem hora) e string são realmente relevantes
7061
+ switch (dataType) {
7062
+ case core.DataType.NUMBER:
7063
+ return "I";
7064
+ case core.DataType.DATE:
7065
+ return "D";
7066
+ default:
7067
+ return "S";
7068
+ }
7069
+ }
6939
7070
 
6940
7071
  const snkApplicationCss = ".sc-snk-application-h{display:flex;flex-direction:column;height:100%}";
6941
7072
 
@@ -6975,6 +7106,16 @@ const SnkApplication = class {
6975
7106
  async getDateParam(name) {
6976
7107
  return this.parameters.asDate(name, this.resourceID);
6977
7108
  }
7109
+ async showPopUp(content) {
7110
+ this._popUp.appendChild(content);
7111
+ this._popUp["opened"] = true;
7112
+ }
7113
+ async closePopUp() {
7114
+ Array.from(this._popUp.children).forEach(c => {
7115
+ this._popUp.removeChild(c);
7116
+ });
7117
+ this._popUp["opened"] = false;
7118
+ }
6978
7119
  async temOpcional(opcional) {
6979
7120
  const opts = opcional.split(",");
6980
7121
  return new Promise((resolve, reject) => {
@@ -7047,8 +7188,56 @@ const SnkApplication = class {
7047
7188
  }
7048
7189
  return this._formConfigFetcher;
7049
7190
  }
7191
+ get pesquisaFetcher() {
7192
+ if (!this._pesquisaFetcher) {
7193
+ this._pesquisaFetcher = new PesquisaFetcher();
7194
+ }
7195
+ return this._pesquisaFetcher;
7196
+ }
7197
+ executeSearch(searchArgument, fieldName, dataUnit) {
7198
+ const descriptor = dataUnit.getField(fieldName);
7199
+ if (!descriptor) ;
7200
+ else {
7201
+ const { mode, argument } = searchArgument;
7202
+ const { ENTITYNAME } = descriptor.properties;
7203
+ const dependencies = descriptor.dependencies;
7204
+ let criteria;
7205
+ dependencies === null || dependencies === void 0 ? void 0 : dependencies.forEach(dependency => {
7206
+ var _a;
7207
+ if (dependency.type === UnitMetadata.DependencyType.SEARCHING) {
7208
+ if (((_a = dependency.masterFields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
7209
+ criteria = {
7210
+ expression: dependency.expression,
7211
+ params: dependency.masterFields.map(fieldName => {
7212
+ const masterDescriptor = dataUnit.getField(fieldName);
7213
+ const dataType = (masterDescriptor === null || masterDescriptor === void 0 ? void 0 : masterDescriptor.dataType) || core.DataType.TEXT;
7214
+ return { name: fieldName, value: dataUnit.getFieldValue(fieldName), dataType };
7215
+ })
7216
+ };
7217
+ }
7218
+ }
7219
+ });
7220
+ if (mode === "ADVANCED") {
7221
+ return new Promise(accept => {
7222
+ const pesquisaContent = document.createElement("snk-pesquisa");
7223
+ pesquisaContent.argument = argument;
7224
+ pesquisaContent.searchLoader = (text) => this.pesquisaFetcher.loadAdvancedSearch(ENTITYNAME, text, criteria);
7225
+ pesquisaContent.onSelectItem = (option) => {
7226
+ accept(option);
7227
+ this.closePopUp();
7228
+ };
7229
+ this.showPopUp(pesquisaContent);
7230
+ });
7231
+ }
7232
+ else {
7233
+ return this.pesquisaFetcher.loadSearchOptions(ENTITYNAME, argument, criteria);
7234
+ }
7235
+ }
7236
+ }
7050
7237
  componentWillLoad() {
7051
- core.ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", pesquisaLoadOptions);
7238
+ core.ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", (searchArgument, fieldName, dataUnit) => {
7239
+ return this.executeSearch(searchArgument, fieldName, dataUnit);
7240
+ });
7052
7241
  }
7053
7242
  componentDidLoad() {
7054
7243
  this.applicationLoading.emit(true);
@@ -7057,7 +7246,7 @@ const SnkApplication = class {
7057
7246
  });
7058
7247
  }
7059
7248
  render() {
7060
- return (index.h("div", null));
7249
+ return (index.h("div", null, index.h("ez-popup", { opened: false, ref: (ref) => this._popUp = ref, onEzClosePopup: () => this.closePopUp() })));
7061
7250
  }
7062
7251
  };
7063
7252
  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
+ }