@jtandrelevicius/utils-js-library 1.0.8 → 1.0.9
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.
- package/lib/jsk-core.js +154 -67
- package/package.json +1 -1
package/lib/jsk-core.js
CHANGED
|
@@ -2,20 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
export class ServicoDados {
|
|
4
4
|
|
|
5
|
-
// =========================================================================
|
|
6
|
-
// PARTE 1: MANIPULAÇÃO DE DADOS (Banco de Dados)
|
|
7
|
-
// =========================================================================
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Define o executor de query padrão (Legado).
|
|
11
|
-
*/
|
|
12
5
|
static definirExecutor(funcaoExecutor) {
|
|
13
6
|
this.executor = funcaoExecutor;
|
|
14
7
|
}
|
|
15
8
|
|
|
16
|
-
/**
|
|
17
|
-
* Realiza requisições POST.
|
|
18
|
-
*/
|
|
19
9
|
static async post(url, corpo, { headers, raw } = { headers: {}, raw: false }) {
|
|
20
10
|
let isJSON = true;
|
|
21
11
|
|
|
@@ -53,9 +43,6 @@ export class ServicoDados {
|
|
|
53
43
|
}
|
|
54
44
|
}
|
|
55
45
|
|
|
56
|
-
/**
|
|
57
|
-
* Normaliza a resposta da API.
|
|
58
|
-
*/
|
|
59
46
|
static normalizarResposta(valorBruto) {
|
|
60
47
|
try {
|
|
61
48
|
const valorParseado = typeof valorBruto === 'string' ? JSON.parse(valorBruto) : valorBruto;
|
|
@@ -80,9 +67,6 @@ export class ServicoDados {
|
|
|
80
67
|
}
|
|
81
68
|
}
|
|
82
69
|
|
|
83
|
-
/**
|
|
84
|
-
* Executa consulta SQL.
|
|
85
|
-
*/
|
|
86
70
|
static async consultar(query, params = null) {
|
|
87
71
|
const executor = this.executor || (typeof window !== 'undefined' ? window.executeQuery : null);
|
|
88
72
|
|
|
@@ -103,9 +87,6 @@ export class ServicoDados {
|
|
|
103
87
|
});
|
|
104
88
|
}
|
|
105
89
|
|
|
106
|
-
/**
|
|
107
|
-
* Executa consulta paginada.
|
|
108
|
-
*/
|
|
109
90
|
static async consultarPaginado(query, params = null, limite, offset) {
|
|
110
91
|
const limiteSeguro = Number(limite);
|
|
111
92
|
const offsetSeguro = Number(offset);
|
|
@@ -122,8 +103,8 @@ export class ServicoDados {
|
|
|
122
103
|
}
|
|
123
104
|
|
|
124
105
|
/**
|
|
125
|
-
*
|
|
126
|
-
|
|
106
|
+
* Metodo Salvar
|
|
107
|
+
*/
|
|
127
108
|
static async salvar(dados, entidade, chavesPrimarias = null) {
|
|
128
109
|
const url = `${window.location.origin}/mge/service.sbr?serviceName=DatasetSP.save&outputType=json`;
|
|
129
110
|
const chavesDados = Object.keys(dados);
|
|
@@ -148,10 +129,11 @@ export class ServicoDados {
|
|
|
148
129
|
}
|
|
149
130
|
|
|
150
131
|
/**
|
|
151
|
-
*
|
|
132
|
+
* Metodo Excluir
|
|
152
133
|
*/
|
|
153
134
|
static async excluir(entidade, chavesPrimarias) {
|
|
154
135
|
const url = `${window.location.origin}/mge/service.sbr?serviceName=DatasetSP.removeRecord&outputType=json`;
|
|
136
|
+
|
|
155
137
|
return ServicoDados.post(url, {
|
|
156
138
|
serviceName: 'DatasetSP.removeRecord',
|
|
157
139
|
requestBody: {
|
|
@@ -161,21 +143,137 @@ export class ServicoDados {
|
|
|
161
143
|
});
|
|
162
144
|
}
|
|
163
145
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Consulta um único registro pela Chave Primária (loadRecord)
|
|
148
|
+
*/
|
|
149
|
+
static async consultarRegistro(entidade, chaves, campos) {
|
|
150
|
+
const url = `${window.location.origin}/mge/service.sbr?serviceName=CRUDServiceProvider.loadRecord&outputType=json`;
|
|
167
151
|
|
|
168
|
-
|
|
169
|
-
|
|
152
|
+
const rowParams = {};
|
|
153
|
+
for (const [key, value] of Object.entries(chaves)) {
|
|
154
|
+
rowParams[key] = { "$": String(value) };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let entityParam = [];
|
|
158
|
+
if (typeof campos === 'string') {
|
|
159
|
+
entityParam.push({ path: "", fieldset: { list: campos } });
|
|
160
|
+
} else if (Array.isArray(campos)) {
|
|
161
|
+
entityParam = campos;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return await ServicoDados.post(url, {
|
|
165
|
+
serviceName: 'CRUDServiceProvider.loadRecord',
|
|
166
|
+
requestBody: {
|
|
167
|
+
dataSet: {
|
|
168
|
+
rootEntity: entidade,
|
|
169
|
+
entity: entityParam,
|
|
170
|
+
rows: { row: rowParams }
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
/**
|
|
173
|
-
*
|
|
174
|
-
* Requer ID (nuGdt) resolvido previamente.
|
|
177
|
+
* Consulta múltiplos registros com base em critérios e paginação (loadRecords)
|
|
175
178
|
*/
|
|
176
|
-
static
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
static async consultarRegistros(entidade, expressao, parametros = [], campos = "", opcoes = {}) {
|
|
180
|
+
const url = `${window.location.origin}/mge/service.sbr?serviceName=CRUDServiceProvider.loadRecords&outputType=json`;
|
|
181
|
+
|
|
182
|
+
const formattedParams = parametros.map(p => ({ "$": String(p.valor), "type": p.tipo }));
|
|
183
|
+
|
|
184
|
+
let entityParam = {};
|
|
185
|
+
if (typeof campos === 'string') {
|
|
186
|
+
entityParam = { fieldset: { list: campos } };
|
|
187
|
+
} else if (Array.isArray(campos)) {
|
|
188
|
+
entityParam = campos;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const dataSet = {
|
|
192
|
+
rootEntity: entidade,
|
|
193
|
+
offsetPage: opcoes.offsetPage || "0",
|
|
194
|
+
ignoreCalculatedFields: opcoes.ignoreCalculatedFields || "false",
|
|
195
|
+
includePresentationFields: opcoes.includePresentationFields || "N",
|
|
196
|
+
useFileBasedPagination: opcoes.useFileBasedPagination || "false",
|
|
197
|
+
tryJoinedFields: opcoes.tryJoinedFields || "false",
|
|
198
|
+
criteria: {
|
|
199
|
+
expression: { "$": expressao }
|
|
200
|
+
},
|
|
201
|
+
entity: entityParam
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
if (formattedParams.length > 0) {
|
|
205
|
+
dataSet.criteria.parameter = formattedParams;
|
|
206
|
+
}
|
|
207
|
+
if (opcoes.modifiedSince) {
|
|
208
|
+
dataSet.modifiedSince = opcoes.modifiedSince;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return await ServicoDados.post(url, {
|
|
212
|
+
serviceName: 'CRUDServiceProvider.loadRecords',
|
|
213
|
+
requestBody: { dataSet }
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Consulta de Views diretamente no banco de dados (loadView)
|
|
219
|
+
*/
|
|
220
|
+
static async consultarView(nomeView, campos, condicaoWhere) {
|
|
221
|
+
const url = `${window.location.origin}/mge/service.sbr?serviceName=CRUDServiceProvider.loadView&outputType=json`;
|
|
222
|
+
|
|
223
|
+
return await ServicoDados.post(url, {
|
|
224
|
+
serviceName: 'CRUDServiceProvider.loadView',
|
|
225
|
+
requestBody: {
|
|
226
|
+
query: {
|
|
227
|
+
viewName: nomeView,
|
|
228
|
+
fields: { field: { "$": campos } },
|
|
229
|
+
where: { "$": condicaoWhere }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Metodo novo de faturametno
|
|
237
|
+
*/
|
|
238
|
+
static async faturar(nunota, codTipOper, opcoesAdicionais = {}) {
|
|
239
|
+
const url = `${window.location.origin}/mgecom/service.sbr?serviceName=SelecaoDocumentoSP.faturar&outputType=json`;
|
|
240
|
+
|
|
241
|
+
const arrayNotas = Array.isArray(nunota)
|
|
242
|
+
? nunota.map(n => ({ "$": n }))
|
|
243
|
+
: [{ "$": nunota }];
|
|
244
|
+
|
|
245
|
+
const payloadNotas = {
|
|
246
|
+
codTipOper: codTipOper,
|
|
247
|
+
dtFaturamento: "",
|
|
248
|
+
tipoFaturamento: "FaturamentoNormal",
|
|
249
|
+
dataValidada: true,
|
|
250
|
+
notasComMoeda: {},
|
|
251
|
+
nota: arrayNotas,
|
|
252
|
+
codLocalDestino: "",
|
|
253
|
+
faturarTodosItens: true,
|
|
254
|
+
umaNotaParaCada: "false",
|
|
255
|
+
ehWizardFaturamento: true,
|
|
256
|
+
dtFixaVenc: "",
|
|
257
|
+
ehPedidoWeb: false,
|
|
258
|
+
nfeDevolucaoViaRecusa: false,
|
|
259
|
+
...opcoesAdicionais
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
return await ServicoDados.post(url, {
|
|
264
|
+
serviceName: 'SelecaoDocumentoSP.faturar',
|
|
265
|
+
requestBody: {
|
|
266
|
+
notas: payloadNotas
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
static getUrl(path) {
|
|
272
|
+
return `${window.location.origin}${path ? '/' + path.replace('/', '') : ''}`;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
static async removerFrame({ nuGdt, paginaInicial, ...opcoes } = { nuGdt: 0, paginaInicial: 'app.jsp' }) {
|
|
276
|
+
const o = await new Promise(resolve => {
|
|
179
277
|
[window.parent.document, window.parent.parent.document].forEach(doc => {
|
|
180
278
|
if (doc && doc.getElementsByTagName('body').length) {
|
|
181
279
|
const alertBox = doc.querySelector('div.gwt-PopupPanel.alert-box.box-shadow');
|
|
@@ -185,38 +283,33 @@ export class ServicoDados {
|
|
|
185
283
|
});
|
|
186
284
|
|
|
187
285
|
resolve({ gadGetID: 'html5_z6dld', nuGdt: nuGdt || 0, ...opcoes });
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
styleEl.parentElement.parentElement.getElementsByTagName('body')[0].style.overflow = 'hidden';
|
|
211
|
-
}
|
|
286
|
+
});
|
|
287
|
+
return setTimeout(() => {
|
|
288
|
+
if (typeof window.parent.document.getElementsByClassName('DashWindow')[0] != 'undefined') {
|
|
289
|
+
const opcoesUrl = Object.keys(o)
|
|
290
|
+
.filter(item => !['params', 'UID', 'instance', 'nuGdg', 'gadGetID'].includes(item))
|
|
291
|
+
.map(item_1 => `&${item_1}=${o[item_1]}`)
|
|
292
|
+
.join('');
|
|
293
|
+
|
|
294
|
+
const url = `/mge/html5component.mge?entryPoint=${paginaInicial}&nuGdg=${o.nuGdt}${opcoesUrl}`;
|
|
295
|
+
|
|
296
|
+
const gadgetDiv = window.parent.document.getElementsByClassName('dyna-gadget')[0];
|
|
297
|
+
if (gadgetDiv) {
|
|
298
|
+
gadgetDiv.innerHTML = `<iframe src="${url}" class="gwt-Frame" style="width: 100%; height: 100%;"></iframe>`;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const popup = document.getElementsByClassName('popupContent')[0];
|
|
302
|
+
if (popup && popup.parentElement) popup.parentElement.remove();
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
const styleEl = document.getElementById('stndz-style');
|
|
306
|
+
if (styleEl && styleEl.parentElement && styleEl.parentElement.parentElement) {
|
|
307
|
+
styleEl.parentElement.parentElement.getElementsByTagName('body')[0].style.overflow = 'hidden';
|
|
212
308
|
}
|
|
213
|
-
}
|
|
214
|
-
);
|
|
309
|
+
}
|
|
310
|
+
}, 500);
|
|
215
311
|
}
|
|
216
312
|
|
|
217
|
-
/**
|
|
218
|
-
* Abre Nova Guia.
|
|
219
|
-
*/
|
|
220
313
|
static novaGuia(forcado = false) {
|
|
221
314
|
const isSankhya = !!window.parent.parent.document.querySelector('.Taskbar-container');
|
|
222
315
|
if ((isSankhya && !forcado) || forcado) {
|
|
@@ -224,9 +317,6 @@ export class ServicoDados {
|
|
|
224
317
|
}
|
|
225
318
|
}
|
|
226
319
|
|
|
227
|
-
/**
|
|
228
|
-
* Abre Pagina no Sankhya-W.
|
|
229
|
-
*/
|
|
230
320
|
static abrirPagina(resourceID, chavesPrimarias) {
|
|
231
321
|
let url = ServicoDados.getUrl(`/mge/system.jsp#app/%resID`);
|
|
232
322
|
url = url.replace('%resID', btoa(resourceID));
|
|
@@ -240,9 +330,6 @@ export class ServicoDados {
|
|
|
240
330
|
Object.assign(document.createElement('a'), { target: '_top', href: url }).click();
|
|
241
331
|
}
|
|
242
332
|
|
|
243
|
-
/**
|
|
244
|
-
* Fecha a Pagina atual.
|
|
245
|
-
*/
|
|
246
333
|
static fecharPagina() {
|
|
247
334
|
const closeBtn = window.parent.parent.document.querySelector('li.ListItem.AppItem.AppItem-selected div.Taskbar-icon.icon-close');
|
|
248
335
|
if (closeBtn) closeBtn.click();
|