@jvsoft/utils 0.0.13-alpha.3 → 0.0.13-alpha.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.
- package/fesm2022/jvsoft-utils-src-functions.mjs +220 -196
- package/fesm2022/jvsoft-utils-src-functions.mjs.map +1 -1
- package/fesm2022/jvsoft-utils.mjs +220 -196
- package/fesm2022/jvsoft-utils.mjs.map +1 -1
- package/functions/mat-form-controls/autocomplete.d.ts +38 -8
- package/functions/objects-arrays.d.ts +100 -0
- package/package.json +1 -1
- package/src/functions/mat-form-controls/autocomplete.d.ts +38 -8
- package/src/functions/objects-arrays.d.ts +100 -0
|
@@ -11,6 +11,14 @@ import moment from 'moment';
|
|
|
11
11
|
import swal from 'sweetalert2';
|
|
12
12
|
import { jwtDecode } from 'jwt-decode';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Realiza una fusión profunda entre dos objetos, sin modificar el original.
|
|
16
|
+
* Si el valor en target no es un objeto, lo reemplaza directamente.
|
|
17
|
+
*
|
|
18
|
+
* @param source - Objeto fuente que se clonará y fusionará.
|
|
19
|
+
* @param target - Objeto destino cuyos valores se fusionarán.
|
|
20
|
+
* @returns Un nuevo objeto con la fusión profunda.
|
|
21
|
+
*/
|
|
14
22
|
function deepMerge(source, target) {
|
|
15
23
|
// Crea un clon profundo sin usar JSON.parse(JSON.stringify)
|
|
16
24
|
let cloneSource = deepClone(source);
|
|
@@ -32,7 +40,12 @@ function deepMerge(source, target) {
|
|
|
32
40
|
}
|
|
33
41
|
return cloneSource; // Retorna el clon y no modifica el original
|
|
34
42
|
}
|
|
35
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Realiza una clonación profunda de un objeto, manejando funciones, fechas y arrays.
|
|
45
|
+
*
|
|
46
|
+
* @param obj - Objeto a clonar.
|
|
47
|
+
* @returns Una copia profunda del objeto.
|
|
48
|
+
*/
|
|
36
49
|
function deepClone(obj) {
|
|
37
50
|
if (obj === null || typeof obj !== 'object') {
|
|
38
51
|
return obj; // Devuelve el valor si no es un objeto
|
|
@@ -58,6 +71,7 @@ function deepClone(obj) {
|
|
|
58
71
|
/**
|
|
59
72
|
* Busca un elemento en un array o jerarquía de objetos según un campo y valor especificado.
|
|
60
73
|
*
|
|
74
|
+
* @param datosFn - Objeto con los parámetros de búsqueda: items, campo, valor y opcionalmente campoHijo.
|
|
61
75
|
* @returns El elemento encontrado o undefined si no existe.
|
|
62
76
|
*/
|
|
63
77
|
function buscarPorCampo(datosFn) {
|
|
@@ -84,13 +98,33 @@ function buscarPorCampo(datosFn) {
|
|
|
84
98
|
// Si no se encuentra nada, retorna undefined
|
|
85
99
|
return undefined;
|
|
86
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Suma los valores de las propiedades especificadas de un objeto.
|
|
103
|
+
*
|
|
104
|
+
* @param item - Objeto con las propiedades a sumar.
|
|
105
|
+
* @param campos - Array de nombres de las propiedades a sumar.
|
|
106
|
+
* @returns La suma de los valores de las propiedades.
|
|
107
|
+
*/
|
|
87
108
|
function sumarPropiedades(item, campos) {
|
|
88
109
|
const datosSumar = campos.map(campo => (item[campo] * 1));
|
|
89
110
|
return datosSumar.reduce((a, b) => a + b, 0);
|
|
90
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Verifica si el valor proporcionado es un número válido.
|
|
114
|
+
*
|
|
115
|
+
* @param value - Valor a verificar.
|
|
116
|
+
* @returns true si es un número, false en caso contrario.
|
|
117
|
+
*/
|
|
91
118
|
function esNumero(value) {
|
|
92
119
|
return !isNaN(Number(value));
|
|
93
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Suma los valores de las propiedades especificadas en un array de objetos.
|
|
123
|
+
*
|
|
124
|
+
* @param arrayObjetos - Array de objetos a procesar.
|
|
125
|
+
* @param campos - Array de nombres de las propiedades a sumar.
|
|
126
|
+
* @returns Objeto con la suma de cada propiedad.
|
|
127
|
+
*/
|
|
94
128
|
function sumarObjetos(arrayObjetos, campos) {
|
|
95
129
|
return arrayObjetos.reduce((accumulator, item) => {
|
|
96
130
|
campos.forEach(campo => {
|
|
@@ -102,9 +136,22 @@ function sumarObjetos(arrayObjetos, campos) {
|
|
|
102
136
|
return accumulator;
|
|
103
137
|
}, {});
|
|
104
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Obtiene los valores únicos de un array.
|
|
141
|
+
*
|
|
142
|
+
* @param array - Array de valores.
|
|
143
|
+
* @returns Array con los valores únicos.
|
|
144
|
+
*/
|
|
105
145
|
function getUniqueValues(array) {
|
|
106
146
|
return array.filter((currentValue, index, arr) => (arr.indexOf(currentValue) === index));
|
|
107
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Obtiene los objetos únicos de un array según una propiedad específica.
|
|
150
|
+
*
|
|
151
|
+
* @param objetos - Array de objetos.
|
|
152
|
+
* @param campo - Nombre de la propiedad para determinar unicidad.
|
|
153
|
+
* @returns Array de objetos únicos por la propiedad.
|
|
154
|
+
*/
|
|
108
155
|
function getUniqueValuesByProperty(objetos, campo) {
|
|
109
156
|
const objetosUnicos = {};
|
|
110
157
|
objetos.forEach(objeto => {
|
|
@@ -120,6 +167,14 @@ function getUniqueValuesByProperty(objetos, campo) {
|
|
|
120
167
|
// Convertir el objeto de claves únicas de vuelta a una lista de objetos
|
|
121
168
|
return Object.values(objetosUnicos);
|
|
122
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Ordena un array de valores numéricos o alfabéticos.
|
|
172
|
+
*
|
|
173
|
+
* @param array - Array a ordenar.
|
|
174
|
+
* @param numeros - Si es true, ordena como números.
|
|
175
|
+
* @param sentido - 'ASC' para ascendente, 'DESC' para descendente.
|
|
176
|
+
* @returns Array ordenado.
|
|
177
|
+
*/
|
|
123
178
|
function ordenarArray(array, numeros = false, sentido = 'ASC') {
|
|
124
179
|
if (numeros) {
|
|
125
180
|
if (sentido != 'ASC') {
|
|
@@ -129,9 +184,24 @@ function ordenarArray(array, numeros = false, sentido = 'ASC') {
|
|
|
129
184
|
}
|
|
130
185
|
return array.sort((a, b) => (a > b) ? 1 : ((b > a) ? -1 : 0));
|
|
131
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Ordena un array de objetos por una propiedad específica.
|
|
189
|
+
*
|
|
190
|
+
* @param objData - Array de objetos a ordenar.
|
|
191
|
+
* @param propiedad - Propiedad por la que se ordena.
|
|
192
|
+
* @param numeros - (Obsoleto) Si es true, ordena como números.
|
|
193
|
+
* @returns Array ordenado.
|
|
194
|
+
*/
|
|
132
195
|
function ordenarPorPropiedad(objData, propiedad, /**@deprecated*/ numeros = false) {
|
|
133
196
|
return ordenarPorPropiedades(objData, { propiedades: [propiedad], direcciones: ['asc'] });
|
|
134
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Ordena un array de objetos por varias propiedades y direcciones.
|
|
200
|
+
*
|
|
201
|
+
* @param arr - Array de objetos a ordenar.
|
|
202
|
+
* @param options - Opciones con propiedades y direcciones de orden.
|
|
203
|
+
* @returns Array ordenado.
|
|
204
|
+
*/
|
|
135
205
|
function ordenarPorPropiedades(arr, options) {
|
|
136
206
|
const { propiedades, direcciones = [] } = options;
|
|
137
207
|
const orden = direcciones.map(d => d === 'desc' ? -1 : 1);
|
|
@@ -151,6 +221,13 @@ function ordenarPorPropiedades(arr, options) {
|
|
|
151
221
|
}, 0);
|
|
152
222
|
});
|
|
153
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Agrupa los elementos de un array según una clave o función de clave.
|
|
226
|
+
*
|
|
227
|
+
* @param array - Array de objetos a agrupar.
|
|
228
|
+
* @param key - Propiedad o función para agrupar.
|
|
229
|
+
* @returns Objeto con los grupos por clave.
|
|
230
|
+
*/
|
|
154
231
|
function groupBy(array, key) {
|
|
155
232
|
const keyFn = key instanceof Function ? key : (obj) => obj[key];
|
|
156
233
|
return array.reduce((objectsByKeyValue, obj) => {
|
|
@@ -159,6 +236,13 @@ function groupBy(array, key) {
|
|
|
159
236
|
return objectsByKeyValue;
|
|
160
237
|
}, {});
|
|
161
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Agrupa y anida los elementos de un array según una lista de propiedades.
|
|
241
|
+
*
|
|
242
|
+
* @param arr - Array de objetos a agrupar.
|
|
243
|
+
* @param properties - Propiedades para agrupar de forma anidada.
|
|
244
|
+
* @returns Objeto anidado por los grupos de propiedades.
|
|
245
|
+
*/
|
|
162
246
|
function nestGroupsBy(arr, properties) {
|
|
163
247
|
const fnGroupBy = (conversions, property2) => {
|
|
164
248
|
return conversions.reduce((acc, obj) => {
|
|
@@ -232,6 +316,13 @@ function eliminarColumnaPorIndex(data, columnIndex) {
|
|
|
232
316
|
return newRow;
|
|
233
317
|
});
|
|
234
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Elimina elementos duplicados de un array de objetos según claves específicas.
|
|
321
|
+
*
|
|
322
|
+
* @param array - Array de objetos.
|
|
323
|
+
* @param claves - Claves para determinar unicidad. Si no se especifica, compara todo el objeto.
|
|
324
|
+
* @returns Array sin duplicados.
|
|
325
|
+
*/
|
|
235
326
|
function eliminarDuplicados(array, claves) {
|
|
236
327
|
const unicos = new Map();
|
|
237
328
|
for (const item of array) {
|
|
@@ -244,6 +335,14 @@ function eliminarDuplicados(array, claves) {
|
|
|
244
335
|
}
|
|
245
336
|
return Array.from(unicos.values());
|
|
246
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Elimina elementos de un array origen que estén presentes en otro array, según claves específicas.
|
|
340
|
+
*
|
|
341
|
+
* @param origen - Array original.
|
|
342
|
+
* @param elementosAEliminar - Elementos a eliminar del array origen.
|
|
343
|
+
* @param claves - Claves para comparar los objetos. Si no se especifica, compara todo el objeto.
|
|
344
|
+
* @returns Array filtrado sin los elementos eliminados.
|
|
345
|
+
*/
|
|
247
346
|
function eliminarElementos(origen, elementosAEliminar, claves) {
|
|
248
347
|
const clavesSet = new Set();
|
|
249
348
|
for (const item of elementosAEliminar) {
|
|
@@ -260,227 +359,152 @@ function eliminarElementos(origen, elementosAEliminar, claves) {
|
|
|
260
359
|
});
|
|
261
360
|
}
|
|
262
361
|
|
|
362
|
+
/**
|
|
363
|
+
* Devuelve un valor de visualización para un elemento buscado.
|
|
364
|
+
* Compatible con listas simples, objetos y campos múltiples.
|
|
365
|
+
*/
|
|
263
366
|
function mostrarValorEnBusqueda(campos, idxSel) {
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
console.log(vD);
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
vD = campos.lista.find((x) => x[campos.campoId] == idxSel);
|
|
273
|
-
}
|
|
274
|
-
if (!vD && campos.opcExtra) {
|
|
275
|
-
console.log('eval ', campos.opcExtra);
|
|
276
|
-
if (campos.campoId == '*object*' || campos.campoId == '*objeto*') {
|
|
277
|
-
console.log(campos);
|
|
278
|
-
vD = campos.opcExtra.find((x) => JSON.stringify(x).trim() == JSON.stringify(idxSel).trim());
|
|
279
|
-
console.log(vD);
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
vD = campos.opcExtra.find((x) => x[campos.campoId] == idxSel);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (vD) {
|
|
286
|
-
let txtFinal = '';
|
|
287
|
-
if (Array.isArray(campos.campoValue)) {
|
|
288
|
-
campos.campoValue.forEach((vCampo, idx) => {
|
|
289
|
-
txtFinal += (vD[vCampo] ?? '');
|
|
290
|
-
if (idx < campos.campoValue.length - 1) {
|
|
291
|
-
txtFinal += ' - ';
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
txtFinal = vD[campos.campoValue] ?? '';
|
|
297
|
-
}
|
|
298
|
-
return txtFinal.trim();
|
|
367
|
+
const buscarEnLista = (lista) => {
|
|
368
|
+
if (!lista)
|
|
369
|
+
return null;
|
|
370
|
+
if (campos.campoId === '*object*' || campos.campoId === '*objeto*') {
|
|
371
|
+
return lista.find((x) => JSON.stringify(x).trim() === JSON.stringify(idxSel).trim());
|
|
299
372
|
}
|
|
300
|
-
|
|
301
|
-
|
|
373
|
+
return lista.find((x) => x[campos.campoId] === idxSel);
|
|
374
|
+
};
|
|
375
|
+
const impDataMostrar = () => {
|
|
376
|
+
let vD = buscarEnLista(campos.lista) || (campos.opcExtra && buscarEnLista(campos.opcExtra));
|
|
377
|
+
if (!vD)
|
|
378
|
+
return '';
|
|
379
|
+
if (Array.isArray(campos.campoValue)) {
|
|
380
|
+
return campos.campoValue.map((vCampo) => vD[vCampo] ?? '').join(' - ').trim();
|
|
302
381
|
}
|
|
303
|
-
return '';
|
|
382
|
+
return (vD[campos.campoValue] ?? '').trim();
|
|
304
383
|
};
|
|
305
384
|
if (esNumero(idxSel)) {
|
|
306
|
-
if (idxSel > 0 && campos.lista?.length
|
|
307
|
-
return impDataMostrar();
|
|
308
|
-
}
|
|
309
|
-
else if (idxSel && typeof idxSel == 'object') {
|
|
385
|
+
if ((idxSel > 0 && campos.lista?.length) || (idxSel && typeof idxSel === 'object')) {
|
|
310
386
|
return impDataMostrar();
|
|
311
387
|
}
|
|
312
388
|
}
|
|
313
|
-
else {
|
|
314
|
-
|
|
315
|
-
return impDataMostrar();
|
|
316
|
-
}
|
|
389
|
+
else if (campos.lista?.length) {
|
|
390
|
+
return impDataMostrar();
|
|
317
391
|
}
|
|
318
392
|
return '';
|
|
319
393
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
if (isNaN(Number(value))) {
|
|
348
|
-
return dat[dataFiltro.campoBuscar].toLowerCase().includes(value?.toString().toLowerCase());
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
return dat[dataFiltro.campoBuscar].toString().includes(value?.toString());
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
return varN;
|
|
357
|
-
}
|
|
358
|
-
return false;
|
|
359
|
-
}));
|
|
394
|
+
/**
|
|
395
|
+
* Filtra datos locales de un array basado en un valor de búsqueda.
|
|
396
|
+
*/
|
|
397
|
+
function filtrarDatosLocal(data, value, campoBuscar) {
|
|
398
|
+
if (!value)
|
|
399
|
+
return data;
|
|
400
|
+
const normalizar = (val) => val?.toString()?.toLowerCase() ?? '';
|
|
401
|
+
const esNum = !isNaN(Number(value));
|
|
402
|
+
return data.filter(item => {
|
|
403
|
+
const campos = Array.isArray(campoBuscar) ? campoBuscar : [campoBuscar];
|
|
404
|
+
return campos.some(campo => {
|
|
405
|
+
const campoVal = item[campo];
|
|
406
|
+
if (campoVal == null)
|
|
407
|
+
return false;
|
|
408
|
+
return esNum
|
|
409
|
+
? campoVal.toString().includes(value.toString())
|
|
410
|
+
: normalizar(campoVal).includes(normalizar(value));
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Vincula un FormControl a datos locales para autocompletado.
|
|
416
|
+
*/
|
|
417
|
+
function changeSelectData(objThis, { formControl, data, campoBuscar, variableResultado }) {
|
|
418
|
+
objThis.filtrados[variableResultado] = formControl.valueChanges.pipe(untilDestroyed(objThis)).pipe(startWith(''), map(value => data ? filtrarDatosLocal(data, value, campoBuscar) : []));
|
|
360
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Vincula un FormControl a datos locales obtenidos de dataServidor o dataServidorSuscripcion.
|
|
422
|
+
*/
|
|
361
423
|
function changeSelect(control, formControl, tipo, campoBuscar, campoFiltro = null) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
// console.warn( Object.keys(formGroup).find(name => formControl === formGroup[name]) || null );
|
|
365
|
-
if (!campoFiltro) {
|
|
366
|
-
campoFiltro = tipo;
|
|
367
|
-
}
|
|
368
|
-
control['filtrados'][campoFiltro ?? '__'] = formControl.valueChanges.pipe(untilDestroyed(control)).pipe(startWith(''), map(value => {
|
|
369
|
-
// console.warn(value);
|
|
424
|
+
const filtro = campoFiltro ?? tipo;
|
|
425
|
+
control.filtrados[filtro] = formControl.valueChanges.pipe(untilDestroyed(control)).pipe(startWith(''), map(value => {
|
|
370
426
|
const partes = tipo.split('.');
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
else if (control['dataServidorSuscripcion']) {
|
|
376
|
-
varN = control['dataServidorSuscripcion'][tipo].getValue();
|
|
377
|
-
}
|
|
378
|
-
if (varN) {
|
|
379
|
-
if (value) {
|
|
380
|
-
return varN.map((x) => x).filter((dat) => {
|
|
381
|
-
if (Array.isArray(campoBuscar)) {
|
|
382
|
-
let encontrado = false;
|
|
383
|
-
for (const vCampo of campoBuscar) {
|
|
384
|
-
// console.log(vCampo, value, dat[vCampo]);
|
|
385
|
-
if (isNaN(Number(value))) {
|
|
386
|
-
// NO ES NUMERO
|
|
387
|
-
if (value && dat[vCampo] && dat[vCampo].toLowerCase().includes(value?.toString().toLowerCase())) {
|
|
388
|
-
encontrado = true;
|
|
389
|
-
break;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
if (value && dat[vCampo] && dat[vCampo].toString().includes(value?.toString())) {
|
|
394
|
-
encontrado = true;
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return encontrado;
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
if (isNaN(Number(value))) {
|
|
403
|
-
return dat[campoBuscar].toLowerCase().includes(value?.toString().toLowerCase());
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
return dat[campoBuscar].toString().includes(value?.toString());
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
return varN;
|
|
412
|
-
}
|
|
413
|
-
return false;
|
|
427
|
+
const varN = control.dataServidor?.[partes[0]]?.[partes[1]] ??
|
|
428
|
+
control.dataServidor?.[tipo] ??
|
|
429
|
+
control.dataServidorSuscripcion?.[tipo]?.getValue();
|
|
430
|
+
return varN ? filtrarDatosLocal(varN, value, campoBuscar) : [];
|
|
414
431
|
}));
|
|
415
432
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
433
|
+
/**
|
|
434
|
+
* Función genérica para vincular un FormControl con datos desde API o Promise.
|
|
435
|
+
* Preparada para migrar a signals en el futuro.
|
|
436
|
+
*/
|
|
437
|
+
function changeSelectReformateado(config) {
|
|
438
|
+
const { objThis, tipoReq, formControl, queryService, campoId, minLength = 3, dataExtra = {}, dataExtraVariable = [], anonimo = false, variableResultado = tipoReq, } = config;
|
|
439
|
+
formControl.valueChanges.pipe(debounceTime(500), tap(() => {
|
|
440
|
+
objThis.filtrados[variableResultado + 'tmp'] = isObservable(objThis.filtrados[variableResultado])
|
|
441
|
+
? []
|
|
442
|
+
: objThis.filtrados[variableResultado] || [];
|
|
443
|
+
if (objThis.filtrados[variableResultado] !== objThis.filtrados[variableResultado + 'tmp']) {
|
|
444
|
+
objThis.filtrados[variableResultado] = [];
|
|
425
445
|
}
|
|
426
446
|
objThis.isLoading = true;
|
|
427
447
|
}), switchMap(value => {
|
|
428
|
-
if (
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
return !value || value.length < (dataFiltro.minLength ?? 3) ? [] : (dataFiltro.queryService.getDataMethod('GET', dataFiltro.tipoReq, {
|
|
435
|
-
...(dataFiltro.dataExtra ?? {}),
|
|
436
|
-
...(dataFiltro.dataExtraVariable ? Object.fromEntries(dataFiltro.dataExtraVariable.map((objData) => [objData.campo, objData.ctrlValue.value])) : {}),
|
|
437
|
-
txtBuscar: value,
|
|
438
|
-
}, dataFiltro.anonimo).pipe(finalize(() => objThis.isLoading = false)));
|
|
439
|
-
})).subscribe((data) => {
|
|
440
|
-
objThis.filtrados[idFiltrado] = data[dataFiltro.tipoReq] ?? [];
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
function changeSelectApi(control, queryService, formControl, tipo, dataExtra = {}, dataExtraVariable = null, minLength = 1, anonimo = false) {
|
|
444
|
-
formControl.valueChanges.pipe(debounceTime(500), tap((value) => {
|
|
445
|
-
control['filtrados'][tipo + 'tmp'] = isObservable(control['filtrados'][tipo]) ? [] : control['filtrados'][tipo];
|
|
446
|
-
if (control['filtrados'][tipo] != control['filtrados'][tipo + 'tmp']) {
|
|
447
|
-
control['filtrados'][tipo] = [];
|
|
448
|
-
}
|
|
449
|
-
control['isLoading'] = true;
|
|
450
|
-
}), switchMap(value => {
|
|
451
|
-
const formGroup = formControl.parent?.controls;
|
|
452
|
-
const nombreControl = Object.keys(formGroup).find(name => formControl === formGroup[name]) || null;
|
|
453
|
-
if (nombreControl && control['filtrados'][tipo + 'tmp'] && control['filtrados'][tipo + 'tmp'].length > 0) {
|
|
454
|
-
const busquedaActual = control['filtrados'][tipo + 'tmp'].findIndex((item) => item[nombreControl] == value);
|
|
455
|
-
if (busquedaActual >= 0) {
|
|
456
|
-
const vRet = {};
|
|
457
|
-
vRet[tipo] = control['filtrados'][tipo + 'tmp'];
|
|
458
|
-
control['isLoading'] = false;
|
|
459
|
-
return of(vRet);
|
|
448
|
+
if (campoId) {
|
|
449
|
+
const existe = objThis.filtrados[variableResultado + 'tmp']
|
|
450
|
+
.findIndex((item) => item[campoId] === value);
|
|
451
|
+
if (existe >= 0) {
|
|
452
|
+
return of({ [tipoReq]: objThis.filtrados[variableResultado + 'tmp'] });
|
|
460
453
|
}
|
|
461
454
|
}
|
|
462
455
|
if (!value || value.length < minLength) {
|
|
463
|
-
|
|
456
|
+
objThis.isLoading = false;
|
|
457
|
+
return of({ [tipoReq]: [] });
|
|
464
458
|
}
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
459
|
+
const extraVars = Object.fromEntries(dataExtraVariable.map(v => [v.campo, v.ctrlValue.value]));
|
|
460
|
+
const query = queryService.getDataMethod('GET', tipoReq, { ...dataExtra, ...extraVars, txtBuscar: value }, anonimo);
|
|
461
|
+
if (esPromise(query)) {
|
|
462
|
+
return query.then((data) => ({ [tipoReq]: data[tipoReq] ?? [] }))
|
|
463
|
+
.finally(() => { objThis.isLoading = false; });
|
|
471
464
|
}
|
|
472
|
-
return
|
|
473
|
-
control['isLoading'] = false;
|
|
474
|
-
}));
|
|
465
|
+
return query.pipe(finalize(() => { objThis.isLoading = false; }));
|
|
475
466
|
})).subscribe((data) => {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
467
|
+
objThis.filtrados[variableResultado] = data[tipoReq] ?? [];
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Alias para compatibilidad.
|
|
472
|
+
*/
|
|
473
|
+
function changeSelectDataApi(objThis, dataFiltro) {
|
|
474
|
+
return changeSelectReformateado({
|
|
475
|
+
objThis,
|
|
476
|
+
tipoReq: dataFiltro.tipoReq,
|
|
477
|
+
formControl: dataFiltro.formControl,
|
|
478
|
+
queryService: dataFiltro.queryService,
|
|
479
|
+
campoId: dataFiltro.campoId,
|
|
480
|
+
minLength: dataFiltro.minLength,
|
|
481
|
+
dataExtra: dataFiltro.dataExtra,
|
|
482
|
+
dataExtraVariable: dataFiltro.dataExtraVariable,
|
|
483
|
+
anonimo: dataFiltro.anonimo,
|
|
484
|
+
variableResultado: dataFiltro.variableResultado,
|
|
482
485
|
});
|
|
483
486
|
}
|
|
487
|
+
/**
|
|
488
|
+
* Alias para compatibilidad.
|
|
489
|
+
*/
|
|
490
|
+
function changeSelectApi(control, queryService, formControl, tipo, dataExtra = {}, dataExtraVariable = null, minLength = 1, anonimo = false) {
|
|
491
|
+
return changeSelectReformateado({
|
|
492
|
+
objThis: control,
|
|
493
|
+
tipoReq: tipo,
|
|
494
|
+
formControl,
|
|
495
|
+
queryService,
|
|
496
|
+
minLength,
|
|
497
|
+
dataExtra,
|
|
498
|
+
dataExtraVariable: dataExtraVariable ?? [],
|
|
499
|
+
anonimo,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Comprueba si un valor es una Promesa.
|
|
504
|
+
*/
|
|
505
|
+
function esPromise(valor) {
|
|
506
|
+
return !!valor && typeof valor.then === 'function';
|
|
507
|
+
}
|
|
484
508
|
|
|
485
509
|
function seleccionarTextoInput(event) {
|
|
486
510
|
event.target.select();
|
|
@@ -1363,5 +1387,5 @@ function verificarRUC(ruc) {
|
|
|
1363
1387
|
* Generated bundle index. Do not edit.
|
|
1364
1388
|
*/
|
|
1365
1389
|
|
|
1366
|
-
export { b64Decode, b64Encode, buscarPorCampo, changeSelect, changeSelectApi, changeSelectData, changeSelectDataApi, convertirBytes, deepClone, deepMerge, delLocalStorage, desencriptar, downLoadFileStream, eliminarColumnaPorIndex, eliminarDuplicados, eliminarElementos, encriptar, esNumero, establecerQuitarRequired, extraerDominio, formatearFecha, formatearFechaCadena, formatearFechaFormato, generateRandomString, getBrowserName, getCambiarPwd, getDataArchivoFromPath, getFormValidationErrors, getLocalStorage, getUniqueValues, getUniqueValuesByProperty, groupBy, inicializarVariablesSessionStorage, isEmail, jwtToken, jwtTokenData, jwtTokenExpiracion, jwtTokenExpiracionFaltante, localStorageKeys, markAsTouchedWithoutEmitEvent, maskEmail, mensajeAlerta, mensajeConfirmacion, mensajeTimer, mensajeToast, mensajesDeError, mensajesErrorFormControl, mostrarValorEnBusqueda, nestGroupsBy, numberToWords, objectPropertiesBoolean, objectPropertiesToType, obtenerHostDesdeUrl, obtenerMimeType, obtenerUltimoOrden, ordenarArray, ordenarPorPropiedad, ordenarPorPropiedades, roundToDecimal, sanitizarNombreArchivo, seleccionarTextoInput, setCambiarPwd, setControlDesdeLista, setJwtTokenData, setLocalStorage, sumarObjetos, sumarPropiedades, toFormData, transformarFechasPorNombreDeCampo, verificarRUC };
|
|
1390
|
+
export { b64Decode, b64Encode, buscarPorCampo, changeSelect, changeSelectApi, changeSelectData, changeSelectDataApi, changeSelectReformateado, convertirBytes, deepClone, deepMerge, delLocalStorage, desencriptar, downLoadFileStream, eliminarColumnaPorIndex, eliminarDuplicados, eliminarElementos, encriptar, esNumero, establecerQuitarRequired, extraerDominio, formatearFecha, formatearFechaCadena, formatearFechaFormato, generateRandomString, getBrowserName, getCambiarPwd, getDataArchivoFromPath, getFormValidationErrors, getLocalStorage, getUniqueValues, getUniqueValuesByProperty, groupBy, inicializarVariablesSessionStorage, isEmail, jwtToken, jwtTokenData, jwtTokenExpiracion, jwtTokenExpiracionFaltante, localStorageKeys, markAsTouchedWithoutEmitEvent, maskEmail, mensajeAlerta, mensajeConfirmacion, mensajeTimer, mensajeToast, mensajesDeError, mensajesErrorFormControl, mostrarValorEnBusqueda, nestGroupsBy, numberToWords, objectPropertiesBoolean, objectPropertiesToType, obtenerHostDesdeUrl, obtenerMimeType, obtenerUltimoOrden, ordenarArray, ordenarPorPropiedad, ordenarPorPropiedades, roundToDecimal, sanitizarNombreArchivo, seleccionarTextoInput, setCambiarPwd, setControlDesdeLista, setJwtTokenData, setLocalStorage, sumarObjetos, sumarPropiedades, toFormData, transformarFechasPorNombreDeCampo, verificarRUC };
|
|
1367
1391
|
//# sourceMappingURL=jvsoft-utils-src-functions.mjs.map
|