@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
@@ -0,0 +1,33 @@
1
+ import { DataType, DataUnit, UserInterface } from '@sankhyalabs/core';
2
+ import { Component, h } from '@stencil/core';
3
+ export class TestePesquisa {
4
+ componentWillLoad() {
5
+ this.dataUnit = new DataUnit("testes_com_formulario");
6
+ this.dataUnit.metadata = {
7
+ name: "dd://br.com.sankhya.fin.cad.movimentacaoFinanceira/Financeiro",
8
+ label: "Parceiro",
9
+ fields: [
10
+ {
11
+ name: "CODPARC",
12
+ label: "Parceiro",
13
+ dataType: DataType.NUMBER,
14
+ userInterface: UserInterface.SEARCH,
15
+ required: true,
16
+ properties: { ENTITYNAME: "Parceiro" }
17
+ }
18
+ ]
19
+ };
20
+ }
21
+ render() {
22
+ return (h("snk-application", null,
23
+ h("ez-form", { dataUnit: this.dataUnit })));
24
+ }
25
+ static get is() { return "teste-pesquisa"; }
26
+ static get encapsulation() { return "shadow"; }
27
+ static get originalStyleUrls() { return {
28
+ "$": ["teste-pesquisa.css"]
29
+ }; }
30
+ static get styleUrls() { return {
31
+ "$": ["teste-pesquisa.css"]
32
+ }; }
33
+ }
@@ -1,4 +1,5 @@
1
1
  import { batchRequests } from 'graphql-request';
2
+ import UrlUtils from "../../../lib/utils/urlutils";
2
3
  export class HttpFetcher {
3
4
  constructor() {
4
5
  this.watingRequestsById = new Map();
@@ -45,6 +46,52 @@ export class HttpFetcher {
45
46
  return (_a = this.getWatingRequest(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
46
47
  }
47
48
  }
49
+ resolveURL() {
50
+ if (window['mock_url'])
51
+ return window['mock_url'];
52
+ return UrlUtils.getUrlBase();
53
+ }
54
+ getContext() {
55
+ const urlParams = UrlUtils.getQueryParams(location.search);
56
+ return {
57
+ baseUrl: `${this.resolveURL()}/mge/service.sbr`,
58
+ appName: "SankhyaBlocks",
59
+ mgeSession: `${window['skw_session'] || urlParams.mgeSession}`,
60
+ globalID: "85C0093DFA240EAB699B4E47A10215BD",
61
+ resourceID: "br.com.sankhya.mov.bancaria"
62
+ };
63
+ }
64
+ async callServiceBroker(serviceName, payload) {
65
+ return new Promise((accept, reject) => {
66
+ const ctx = this.getContext();
67
+ 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`;
68
+ document.cookie = `JSESSIONID=${ctx.mgeSession};`;
69
+ const http = new XMLHttpRequest();
70
+ http.open("POST", url, true);
71
+ http.withCredentials = true;
72
+ http.send(payload);
73
+ http.onreadystatechange = function () {
74
+ if (this.readyState == 4 && this.status == 200) {
75
+ try {
76
+ const jsonResp = JSON.parse(this.responseText);
77
+ if (jsonResp.status == 1) {
78
+ accept(jsonResp.responseBody);
79
+ }
80
+ else {
81
+ reject(jsonResp);
82
+ }
83
+ }
84
+ catch (e) {
85
+ console.warn(`callServiceBroker error to parser response to JSON ${e}`);
86
+ reject(this.responseText);
87
+ }
88
+ }
89
+ else if (this.readyState == 4 && this.status != 200) {
90
+ reject(this.responseText);
91
+ }
92
+ };
93
+ });
94
+ }
48
95
  getReqKey(req) {
49
96
  return window.btoa(this.hashCode(`${req.query}${JSON.stringify(req.values || "")}`)).replace(/=/g, "");
50
97
  }
@@ -14,6 +14,7 @@ export default class DataUnitFetcher {
14
14
  name
15
15
  defaultValue
16
16
  label
17
+ visible
17
18
  readOnly
18
19
  required
19
20
  dataType
@@ -122,10 +123,17 @@ export default class DataUnitFetcher {
122
123
  saveData(dataUnit, duChanges) {
123
124
  const changes = duChanges.map((change) => {
124
125
  const { dataUnit: changeDU, record, updatingFields, operation } = change;
125
- const parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
126
- return { fieldName, value: this.formatValueToServer(value) };
127
- });
128
- return { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
126
+ let parsedUpdatingFields;
127
+ if (updatingFields) {
128
+ parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
129
+ return { fieldName, value: formatValueToServer(value) };
130
+ });
131
+ }
132
+ const reqChange = { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
133
+ if (change.sourceId) {
134
+ reqChange.sourceId = change.sourceId;
135
+ }
136
+ return reqChange;
129
137
  });
130
138
  return new Promise((resolve, reject) => {
131
139
  HttpFetcher.get()
@@ -152,21 +160,6 @@ export default class DataUnitFetcher {
152
160
  });
153
161
  });
154
162
  }
155
- formatValueToServer(value) {
156
- if (value === undefined)
157
- return value;
158
- try {
159
- if (value instanceof Date) {
160
- return value.toString();
161
- }
162
- //Any others objects
163
- value = JSON.stringify(value);
164
- }
165
- catch (_a) {
166
- value = value.toString();
167
- }
168
- return value;
169
- }
170
163
  removeRecords(dataUnit, recordIds) {
171
164
  const changes = recordIds.map((recordId) => {
172
165
  return { dataUnit: dataUnit.name, operation: ChangeOperation.DELETE, recordId };
@@ -186,3 +179,18 @@ export default class DataUnitFetcher {
186
179
  });
187
180
  }
188
181
  }
182
+ export const formatValueToServer = (value) => {
183
+ if (value === undefined)
184
+ return value;
185
+ try {
186
+ if (value instanceof Date) {
187
+ return value.toString();
188
+ }
189
+ //Any others objects
190
+ value = JSON.stringify(value);
191
+ }
192
+ catch (_a) {
193
+ value = value.toString();
194
+ }
195
+ return value;
196
+ };
@@ -0,0 +1,82 @@
1
+ import { DataType } from "@sankhyalabs/core";
2
+ import { gql } from "graphql-request";
3
+ import { HttpFetcher } from "../DataFetcher";
4
+ export class PesquisaFetcher {
5
+ constructor() {
6
+ this.templateByQuery = new Map();
7
+ this.buldTemplates();
8
+ }
9
+ buldTemplates() {
10
+ this.templateByQuery.set("search", gql `query($entityName: String! $argument: String $criteria: SearchCriteria) {
11
+ $queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria){
12
+ value
13
+ label
14
+ }
15
+ }`);
16
+ }
17
+ loadSearchOptions(entityName, argument, criteria) {
18
+ return new Promise((resolve, reject) => {
19
+ HttpFetcher.get()
20
+ .callGraphQL({
21
+ values: { argument, entityName, criteria },
22
+ query: this.templateByQuery.get("search"),
23
+ })
24
+ .then((result) => {
25
+ resolve(result);
26
+ })
27
+ .catch((error) => {
28
+ reject(error);
29
+ });
30
+ });
31
+ }
32
+ loadAdvancedSearch(entityName, argument, criteria) {
33
+ const serviceName = "PesquisaSP.getSuggestion";
34
+ const externalCriteria = {
35
+ query: {
36
+ $: criteria === null || criteria === void 0 ? void 0 : criteria.expression
37
+ }
38
+ };
39
+ if ((criteria === null || criteria === void 0 ? void 0 : criteria.params.length) > 0) {
40
+ externalCriteria.params = {
41
+ param: criteria.params.map(p => { return { $: p.value, type: convertParamType(p.dataType) }; })
42
+ };
43
+ }
44
+ const reqBody = {
45
+ "serviceName": serviceName,
46
+ "requestBody": {
47
+ "criteria": {
48
+ "entityName": entityName,
49
+ "compacted": false,
50
+ "ignoreEntityCriteria": false,
51
+ "limit": "5",
52
+ "query": { "$": argument },
53
+ "orderByDesc": false,
54
+ "options": { "showInactives": false },
55
+ "externalCriteria": externalCriteria
56
+ },
57
+ "clientEventList": {
58
+ "clientEvent": []
59
+ }
60
+ }
61
+ };
62
+ return new Promise((resolve, reject) => {
63
+ HttpFetcher.get()
64
+ .callServiceBroker("PesquisaSP.getSuggestion", JSON.stringify(reqBody))
65
+ .then(result => resolve(result))
66
+ .catch(error => reject(error));
67
+ });
68
+ }
69
+ }
70
+ function convertParamType(dataType) {
71
+ //Alerta: Cuidado pra não contaminar o DataType com a implementação
72
+ //atual da pesquisa... em geral, somente inteiros,
73
+ //data (com ou sem hora) e string são realmente relevantes
74
+ switch (dataType) {
75
+ case DataType.NUMBER:
76
+ return "I";
77
+ case DataType.DATE:
78
+ return "D";
79
+ default:
80
+ return "S";
81
+ }
82
+ }
@@ -1,7 +1,8 @@
1
+ var _a;
1
2
  export default class Workspace {
2
3
  static openAppActivity(resourceId, pkObject) {
3
4
  var _a;
4
5
  (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.openAppActivity(resourceId, pkObject);
5
6
  }
6
7
  }
7
- Workspace.resourceID = window["workspace"].resourceID;
8
+ Workspace.resourceID = (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.resourceID;