@jvsoft/utils 0.0.10 → 0.0.11
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/CHANGELOG.md +7 -0
- package/ng-package.json +7 -0
- package/package.json +9 -24
- package/src/classes/data-model.ts +150 -0
- package/src/functions/base64.ts +8 -0
- package/src/functions/browser.ts +20 -0
- package/src/functions/crypto-js.ts +29 -0
- package/src/functions/date.ts +23 -0
- package/src/functions/email.ts +17 -0
- package/src/functions/file.ts +138 -0
- package/src/functions/forms.ts +145 -0
- package/src/functions/http-client.ts +110 -0
- package/src/functions/index.ts +1 -0
- package/src/functions/local-storage.ts +102 -0
- package/src/functions/mat-form-controls/autocomplete.ts +275 -0
- package/src/functions/mat-form-controls/index.ts +6 -0
- package/src/functions/ng-package.json +5 -0
- package/src/functions/number.ts +3 -0
- package/src/functions/object-transformation.ts +37 -0
- package/src/functions/objects-arrays.ts +243 -0
- package/src/functions/public-api.ts +19 -0
- package/src/functions/string.ts +9 -0
- package/src/functions/sweetalert.ts +95 -0
- package/src/functions/utiles.ts +20 -0
- package/{interfaces/datos.d.ts → src/interfaces/datos.ts} +2 -1
- package/src/interfaces/index.ts +1 -0
- package/src/interfaces/ng-package.json +5 -0
- package/src/interfaces/otros.ts +0 -0
- package/src/interfaces/public-api.ts +3 -0
- package/src/interfaces/routes.ts +42 -0
- package/src/pipes/data-en-lista.pipe.ts +40 -0
- package/src/pipes/date-diff-string.pipe.ts +117 -0
- package/src/pipes/filtro.pipe.ts +64 -0
- package/src/pipes/form-control-is-required.pipe.ts +17 -0
- package/src/pipes/index.ts +1 -0
- package/src/pipes/json-parse.pipe.ts +18 -0
- package/src/pipes/ng-package.json +5 -0
- package/src/pipes/no-sanitize.pipe.ts +12 -0
- package/src/pipes/public-api.ts +10 -0
- package/src/pipes/tipo-valor-funcion.pipe.ts +23 -0
- package/src/pipes/zero-fill.pipe.ts +19 -0
- package/src/public-api.ts +12 -0
- package/tsconfig.lib.json +17 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +15 -0
- package/classes/data-model.d.ts +0 -25
- package/fesm2022/jvsoft-utils-src-functions.mjs +0 -1109
- package/fesm2022/jvsoft-utils-src-functions.mjs.map +0 -1
- package/fesm2022/jvsoft-utils-src-interfaces.mjs +0 -6
- package/fesm2022/jvsoft-utils-src-interfaces.mjs.map +0 -1
- package/fesm2022/jvsoft-utils-src-pipes.mjs +0 -290
- package/fesm2022/jvsoft-utils-src-pipes.mjs.map +0 -1
- package/fesm2022/jvsoft-utils.mjs +0 -1526
- package/fesm2022/jvsoft-utils.mjs.map +0 -1
- package/functions/base64.d.ts +0 -2
- package/functions/browser.d.ts +0 -1
- package/functions/crypto-js.d.ts +0 -2
- package/functions/date.d.ts +0 -3
- package/functions/email.d.ts +0 -2
- package/functions/file.d.ts +0 -10
- package/functions/forms.d.ts +0 -10
- package/functions/http-client.d.ts +0 -2
- package/functions/index.d.ts +0 -1
- package/functions/local-storage.d.ts +0 -29
- package/functions/mat-form-controls/autocomplete.d.ts +0 -21
- package/functions/mat-form-controls/index.d.ts +0 -2
- package/functions/number.d.ts +0 -1
- package/functions/object-transformation.d.ts +0 -2
- package/functions/objects-arrays.d.ts +0 -37
- package/functions/public-api.d.ts +0 -16
- package/functions/string.d.ts +0 -1
- package/functions/sweetalert.d.ts +0 -5
- package/functions/utiles.d.ts +0 -1
- package/index.d.ts +0 -5
- package/interfaces/index.d.ts +0 -1
- package/interfaces/public-api.d.ts +0 -1
- package/pipes/data-en-lista.pipe.d.ts +0 -8
- package/pipes/date-diff-string.pipe.d.ts +0 -17
- package/pipes/filtro.pipe.d.ts +0 -18
- package/pipes/form-control-is-required.pipe.d.ts +0 -9
- package/pipes/index.d.ts +0 -1
- package/pipes/json-parse.pipe.d.ts +0 -7
- package/pipes/no-sanitize.pipe.d.ts +0 -10
- package/pipes/public-api.d.ts +0 -8
- package/pipes/tipo-valor-funcion.pipe.d.ts +0 -9
- package/pipes/zero-fill.pipe.d.ts +0 -8
- package/public-api.d.ts +0 -4
- package/src/functions/base64.d.ts +0 -2
- package/src/functions/browser.d.ts +0 -1
- package/src/functions/crypto-js.d.ts +0 -2
- package/src/functions/date.d.ts +0 -3
- package/src/functions/email.d.ts +0 -2
- package/src/functions/file.d.ts +0 -10
- package/src/functions/forms.d.ts +0 -10
- package/src/functions/http-client.d.ts +0 -2
- package/src/functions/index.d.ts +0 -5
- package/src/functions/local-storage.d.ts +0 -29
- package/src/functions/mat-form-controls/autocomplete.d.ts +0 -21
- package/src/functions/mat-form-controls/index.d.ts +0 -2
- package/src/functions/number.d.ts +0 -1
- package/src/functions/object-transformation.d.ts +0 -2
- package/src/functions/objects-arrays.d.ts +0 -37
- package/src/functions/public-api.d.ts +0 -16
- package/src/functions/string.d.ts +0 -1
- package/src/functions/sweetalert.d.ts +0 -5
- package/src/functions/utiles.d.ts +0 -1
- package/src/interfaces/datos.d.ts +0 -4
- package/src/interfaces/index.d.ts +0 -5
- package/src/interfaces/public-api.d.ts +0 -1
- package/src/pipes/data-en-lista.pipe.d.ts +0 -8
- package/src/pipes/date-diff-string.pipe.d.ts +0 -17
- package/src/pipes/filtro.pipe.d.ts +0 -18
- package/src/pipes/form-control-is-required.pipe.d.ts +0 -9
- package/src/pipes/index.d.ts +0 -5
- package/src/pipes/json-parse.pipe.d.ts +0 -7
- package/src/pipes/no-sanitize.pipe.d.ts +0 -10
- package/src/pipes/public-api.d.ts +0 -8
- package/src/pipes/tipo-valor-funcion.pipe.d.ts +0 -9
- package/src/pipes/zero-fill.pipe.d.ts +0 -8
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {HttpErrorResponse} from '@angular/common/http';
|
|
2
|
+
import {mensajeAlerta, mensajeToast} from './sweetalert';
|
|
3
|
+
|
|
4
|
+
export function mensajesDeError(error: HttpErrorResponse, toast = false) {
|
|
5
|
+
let msg;
|
|
6
|
+
|
|
7
|
+
if (error.error && error.error instanceof ArrayBuffer) {
|
|
8
|
+
const msgArrayBuffer = (arrayBuffer: ArrayBuffer): string => {
|
|
9
|
+
try {
|
|
10
|
+
const mensajeError = JSON.parse(new TextDecoder("utf-8").decode(arrayBuffer));
|
|
11
|
+
return mensajeError.message || 'Error desconocido';
|
|
12
|
+
} catch (parseError) {
|
|
13
|
+
console.error('Error al analizar la respuesta JSON:', parseError);
|
|
14
|
+
return 'Error al analizar la respuesta JSON';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
msg = msgArrayBuffer(error.error);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
|
|
21
|
+
switch (error.status) {
|
|
22
|
+
case 0:
|
|
23
|
+
// msg = error.message;
|
|
24
|
+
msg = 'El servidor no responde, verifica tu conexion a la red';
|
|
25
|
+
console.log(error);
|
|
26
|
+
break;
|
|
27
|
+
case 401:
|
|
28
|
+
if (error.error && typeof error.error == 'object') {
|
|
29
|
+
if (error.error.message) {
|
|
30
|
+
msg = error.error.message;
|
|
31
|
+
}
|
|
32
|
+
else if (error.error.error) {
|
|
33
|
+
msg = error.error.error;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
msg = JSON.stringify(error.error);
|
|
37
|
+
console.log(error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (error.error && typeof error.error == 'string') {
|
|
41
|
+
msg = error.error;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
msg = 'Acceso no autorizado';
|
|
45
|
+
console.log(error);
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
case 422:
|
|
49
|
+
let strEr = '';
|
|
50
|
+
|
|
51
|
+
console.log(typeof error.error.errors);
|
|
52
|
+
console.log(error.error.errors);
|
|
53
|
+
if (error.error.errors) {
|
|
54
|
+
Object.keys(error.error.errors).forEach(o => {
|
|
55
|
+
strEr += '<li>' + error.error.errors[o][0] + '</li>';
|
|
56
|
+
});
|
|
57
|
+
msg = (error.error.message ?? '') + '<ul>' + strEr + '</ul>';
|
|
58
|
+
}
|
|
59
|
+
else if (error.error.error) {
|
|
60
|
+
msg = error.error.msg;
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case 429:
|
|
64
|
+
case 400:
|
|
65
|
+
case 500:
|
|
66
|
+
case 503:
|
|
67
|
+
msg = error.error.message;
|
|
68
|
+
break;
|
|
69
|
+
case 504:
|
|
70
|
+
msg = 'No se puede conectar al servidor. Comprueba tu conexion a la red - ' + error.statusText;
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
msg = error?.error?.message ?? 'Error de Sistema';
|
|
74
|
+
console.log(error);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!msg) {
|
|
79
|
+
msg = error.statusText ?? 'Error inesperado o datos inexistentes.';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let tituloFinal = 'Error!';
|
|
83
|
+
let mensajeFinal;
|
|
84
|
+
|
|
85
|
+
if (msg.includes('Hmac::doVerify')) {
|
|
86
|
+
console.log(error, msg);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
else if (msg == 'Server Error') {
|
|
90
|
+
console.log(error, msg);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
else if (msg.includes('[IMSSP]')) {
|
|
94
|
+
mensajeFinal = 'Error en consulta de registros.';
|
|
95
|
+
}
|
|
96
|
+
else if (msg.includes('Tiempo de espera de la')) {
|
|
97
|
+
mensajeFinal = 'Hubo un error en la solicitud de datos, por favor actualice (SHIFT + F5)';
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
mensajeFinal = msg;
|
|
101
|
+
}
|
|
102
|
+
if (toast) {
|
|
103
|
+
mensajeToast('error', tituloFinal, mensajeFinal);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
mensajeAlerta('error', tituloFinal, mensajeFinal);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
throw new Error(mensajeFinal);
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public-api'
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import {jwtDecode} from 'jwt-decode';
|
|
3
|
+
|
|
4
|
+
export interface JwtTokenResponse {
|
|
5
|
+
access_token: string;
|
|
6
|
+
expires_in: number;
|
|
7
|
+
token_type: string;
|
|
8
|
+
user: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface DataSessionStorage {
|
|
12
|
+
tokenStringKey?: string;
|
|
13
|
+
changePasswordKey?: string;
|
|
14
|
+
logoUrl?: string;
|
|
15
|
+
logoLogin?: string;
|
|
16
|
+
backgroundLogin?: string;
|
|
17
|
+
favicon?: string;
|
|
18
|
+
darkMode?: string;
|
|
19
|
+
serverTimestamp?: string;
|
|
20
|
+
apiDataKey?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let dataSessionStorageKey: DataSessionStorage = {
|
|
24
|
+
tokenStringKey: 'JVSoftTkn',
|
|
25
|
+
changePasswordKey: 'chPwd',
|
|
26
|
+
logoUrl: 'logo_url',
|
|
27
|
+
logoLogin: 'login-logo',
|
|
28
|
+
backgroundLogin: 'login-background',
|
|
29
|
+
favicon: 'favicon',
|
|
30
|
+
darkMode: 'darkMode',
|
|
31
|
+
serverTimestamp: 'srvtmstp',
|
|
32
|
+
apiDataKey: 'reqDt',
|
|
33
|
+
};
|
|
34
|
+
export let localStorageKeys = dataSessionStorageKey;
|
|
35
|
+
|
|
36
|
+
export function inicializarVariablesSessionStorage(datSesion: DataSessionStorage) {
|
|
37
|
+
dataSessionStorageKey = datSesion;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function setJwtTokenData(data: string) {
|
|
41
|
+
localStorage.setItem(<string>dataSessionStorageKey.tokenStringKey, data)
|
|
42
|
+
}
|
|
43
|
+
export function jwtTokenData(key: string = <string>dataSessionStorageKey.tokenStringKey): JwtTokenResponse | null {
|
|
44
|
+
const tokenObj = localStorage.getItem(key);
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(<string>tokenObj) as JwtTokenResponse;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function jwtToken(key: string = <string>dataSessionStorageKey.tokenStringKey) {
|
|
53
|
+
const varJwtTokenData = jwtTokenData(key);
|
|
54
|
+
if (varJwtTokenData) {
|
|
55
|
+
return varJwtTokenData.access_token;
|
|
56
|
+
}
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function jwtTokenExpiracion(key: string = <string>dataSessionStorageKey.tokenStringKey) {
|
|
61
|
+
const jwtStr = jwtToken(key);
|
|
62
|
+
if (!jwtStr) return null;
|
|
63
|
+
try {
|
|
64
|
+
const decodedToken: any = jwtDecode(jwtStr);
|
|
65
|
+
return decodedToken.exp ? decodedToken.exp * 1000:null; // Convertir a milisegundos
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function jwtTokenExpiracionFaltante() {
|
|
72
|
+
return Math.abs(moment().diff(jwtTokenExpiracion(), 'seconds'));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function setCambiarPwd(accion: boolean = true) {
|
|
76
|
+
localStorage.setItem(<string>dataSessionStorageKey.changePasswordKey, (accion ? 1:0).toString())
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function getCambiarPwd() {
|
|
80
|
+
const frmCambioPwd = localStorage.getItem(<string>dataSessionStorageKey.changePasswordKey);
|
|
81
|
+
if (!frmCambioPwd) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return frmCambioPwd == '1';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function delLocalStorage(keyElim: string[] = [
|
|
88
|
+
<string>dataSessionStorageKey.tokenStringKey,
|
|
89
|
+
<string>dataSessionStorageKey.changePasswordKey,
|
|
90
|
+
<string>dataSessionStorageKey.apiDataKey,
|
|
91
|
+
]) {
|
|
92
|
+
keyElim.forEach(key => {
|
|
93
|
+
localStorage.removeItem(key);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function getLocalStorage(key: string | undefined) {
|
|
98
|
+
return localStorage.getItem(<string>key);
|
|
99
|
+
}
|
|
100
|
+
export function setLocalStorage(key: string, value = '') {
|
|
101
|
+
localStorage.setItem(key, value.toString())
|
|
102
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import {esNumero} from '../objects-arrays';
|
|
2
|
+
import {AbstractControl} from '@angular/forms';
|
|
3
|
+
import {untilDestroyed} from '@ngneat/until-destroy';
|
|
4
|
+
import {debounceTime, finalize, isObservable, of, startWith, switchMap, tap} from 'rxjs';
|
|
5
|
+
import {map} from 'rxjs/operators';
|
|
6
|
+
|
|
7
|
+
export function mostrarValorEnBusqueda(campos: any, idxSel: any) {
|
|
8
|
+
const impDataMostrar = () => {
|
|
9
|
+
let vD;
|
|
10
|
+
if (campos.campoId == '*object*' || campos.campoId == '*objeto*') {
|
|
11
|
+
console.log(campos);
|
|
12
|
+
vD = campos.lista.find((x: any) => JSON.stringify(x).trim() == JSON.stringify(idxSel).trim());
|
|
13
|
+
console.log(vD);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
vD = campos.lista.find((x: any) => x[campos.campoId] == idxSel);
|
|
17
|
+
}
|
|
18
|
+
if (!vD && campos.opcExtra) {
|
|
19
|
+
console.log('eval ', campos.opcExtra);
|
|
20
|
+
if (campos.campoId == '*object*' || campos.campoId == '*objeto*') {
|
|
21
|
+
console.log(campos);
|
|
22
|
+
vD = campos.opcExtra.find((x: any) => JSON.stringify(x).trim() == JSON.stringify(idxSel).trim());
|
|
23
|
+
console.log(vD);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
vD = campos.opcExtra.find((x: any) => x[campos.campoId] == idxSel);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (vD) {
|
|
30
|
+
let txtFinal = '';
|
|
31
|
+
if (Array.isArray(campos.campoValue)) {
|
|
32
|
+
campos.campoValue.forEach((vCampo: any, idx: any) => {
|
|
33
|
+
txtFinal += (vD[vCampo] ?? '');
|
|
34
|
+
if (idx < campos.campoValue.length - 1) {
|
|
35
|
+
txtFinal += ' - ';
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
txtFinal = vD[campos.campoValue] ?? '';
|
|
41
|
+
}
|
|
42
|
+
return txtFinal.trim();
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
console.log('ASSSSS ----- SSSS ');
|
|
46
|
+
}
|
|
47
|
+
return '';
|
|
48
|
+
};
|
|
49
|
+
if (esNumero(idxSel)) {
|
|
50
|
+
if (idxSel > 0 && campos.lista?.length > 0) {
|
|
51
|
+
return impDataMostrar();
|
|
52
|
+
}
|
|
53
|
+
else if (idxSel && typeof idxSel == 'object') {
|
|
54
|
+
return impDataMostrar();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (campos.lista?.length > 0) {
|
|
59
|
+
return impDataMostrar();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
export function changeSelectData(objThis: any, dataFiltro: {
|
|
67
|
+
formControl: AbstractControl,
|
|
68
|
+
data: any[],
|
|
69
|
+
campoBuscar: string | string[],
|
|
70
|
+
variableResultado: string,
|
|
71
|
+
}) {
|
|
72
|
+
objThis['filtrados'][dataFiltro.variableResultado] = dataFiltro.formControl.valueChanges.pipe(untilDestroyed(objThis)).pipe(
|
|
73
|
+
startWith(''),
|
|
74
|
+
map(value => {
|
|
75
|
+
|
|
76
|
+
const varN = dataFiltro.data;
|
|
77
|
+
if (varN) {
|
|
78
|
+
if (value) {
|
|
79
|
+
return varN.map(x => x).filter(dat => {
|
|
80
|
+
if (Array.isArray(dataFiltro.campoBuscar)) {
|
|
81
|
+
let encontrado = false;
|
|
82
|
+
|
|
83
|
+
for (const vCampo of dataFiltro.campoBuscar) {
|
|
84
|
+
// console.log(vCampo, value, dat[vCampo]);
|
|
85
|
+
if (isNaN(Number(value))) {
|
|
86
|
+
// NO ES NUMERO
|
|
87
|
+
if (value && dat[vCampo] && dat[vCampo].toLowerCase().includes(value?.toString().toLowerCase())) {
|
|
88
|
+
encontrado = true;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (value && dat[vCampo] && dat[vCampo].toString().includes(value?.toString())) {
|
|
94
|
+
encontrado = true;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return encontrado;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (isNaN(Number(value))) {
|
|
103
|
+
return dat[dataFiltro.campoBuscar].toLowerCase().includes(value?.toString().toLowerCase());
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return dat[dataFiltro.campoBuscar].toString().includes(value?.toString());
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return varN;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function changeSelect(control: any, formControl: AbstractControl, tipo: any, campoBuscar: any, campoFiltro = null) {
|
|
119
|
+
// console.log(formControl);
|
|
120
|
+
// const formGroup = formControl.parent.controls;
|
|
121
|
+
// console.warn( Object.keys(formGroup).find(name => formControl === formGroup[name]) || null );
|
|
122
|
+
if (!campoFiltro) {
|
|
123
|
+
campoFiltro = tipo;
|
|
124
|
+
}
|
|
125
|
+
control['filtrados'][campoFiltro ?? '__'] = formControl.valueChanges.pipe(untilDestroyed(control)).pipe(
|
|
126
|
+
startWith(''),
|
|
127
|
+
map(value => {
|
|
128
|
+
// console.warn(value);
|
|
129
|
+
|
|
130
|
+
const partes = tipo.split('.');
|
|
131
|
+
let varN;
|
|
132
|
+
if (control['dataServidor']) {
|
|
133
|
+
varN = (partes.length > 1) ? control['dataServidor'][partes[0]][partes[1]]:control['dataServidor'][tipo];
|
|
134
|
+
}
|
|
135
|
+
else if (control['dataServidorSuscripcion']) {
|
|
136
|
+
varN = control['dataServidorSuscripcion'][tipo].getValue();
|
|
137
|
+
}
|
|
138
|
+
if (varN) {
|
|
139
|
+
if (value) {
|
|
140
|
+
return varN.map((x: any) => x).filter((dat: any) => {
|
|
141
|
+
if (Array.isArray(campoBuscar)) {
|
|
142
|
+
let encontrado = false;
|
|
143
|
+
|
|
144
|
+
for (const vCampo of campoBuscar) {
|
|
145
|
+
// console.log(vCampo, value, dat[vCampo]);
|
|
146
|
+
if (isNaN(Number(value))) {
|
|
147
|
+
// NO ES NUMERO
|
|
148
|
+
if (value && dat[vCampo] && dat[vCampo].toLowerCase().includes(value?.toString().toLowerCase())) {
|
|
149
|
+
encontrado = true;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
if (value && dat[vCampo] && dat[vCampo].toString().includes(value?.toString())) {
|
|
155
|
+
encontrado = true;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return encontrado;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
if (isNaN(Number(value))) {
|
|
164
|
+
return dat[campoBuscar].toLowerCase().includes(value?.toString().toLowerCase());
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return dat[campoBuscar].toString().includes(value?.toString());
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return varN;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function changeSelectDataApi(objThis: any, dataFiltro: {
|
|
180
|
+
tipoReq: string,
|
|
181
|
+
campoId?: string,
|
|
182
|
+
minLength?: number,
|
|
183
|
+
dataExtra?: any,
|
|
184
|
+
dataExtraVariable?: any,
|
|
185
|
+
anonimo?: boolean,
|
|
186
|
+
queryService: any,
|
|
187
|
+
|
|
188
|
+
formControl: AbstractControl,
|
|
189
|
+
variableResultado?: string,
|
|
190
|
+
}) {
|
|
191
|
+
if (!dataFiltro.variableResultado) {
|
|
192
|
+
dataFiltro.variableResultado = dataFiltro.tipoReq;
|
|
193
|
+
}
|
|
194
|
+
const idFiltrado: string = dataFiltro.variableResultado;
|
|
195
|
+
dataFiltro.formControl.valueChanges.pipe(
|
|
196
|
+
debounceTime(500),
|
|
197
|
+
tap(() => {
|
|
198
|
+
objThis.filtrados[dataFiltro.variableResultado + 'tmp'] = isObservable(objThis.filtrados[idFiltrado]) ? []:objThis.filtrados[idFiltrado] || [];
|
|
199
|
+
if (objThis.filtrados[idFiltrado] !== objThis.filtrados[idFiltrado + 'tmp']) {
|
|
200
|
+
objThis.filtrados[idFiltrado] = [];
|
|
201
|
+
}
|
|
202
|
+
objThis.isLoading = true;
|
|
203
|
+
}),
|
|
204
|
+
switchMap(value => {
|
|
205
|
+
if (dataFiltro.campoId) {
|
|
206
|
+
const busquedaActual2 = objThis.filtrados[idFiltrado + 'tmp'].findIndex((item: any) => item[dataFiltro.campoId ?? '--'] === value);
|
|
207
|
+
if (busquedaActual2 >= 0) {
|
|
208
|
+
return of({[dataFiltro.tipoReq]: objThis.filtrados[idFiltrado + 'tmp']});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return !value || value.length < (dataFiltro.minLength ?? 3) ? []:(
|
|
212
|
+
dataFiltro.queryService.getDataMethod('GET', dataFiltro.tipoReq, {
|
|
213
|
+
...(dataFiltro.dataExtra ?? {}),
|
|
214
|
+
...(dataFiltro.dataExtraVariable ? Object.fromEntries(dataFiltro.dataExtraVariable.map((objData: any) => [objData.campo, objData.ctrlValue.value])):{}),
|
|
215
|
+
txtBuscar: value,
|
|
216
|
+
}, dataFiltro.anonimo).pipe(
|
|
217
|
+
finalize(() => objThis.isLoading = false),
|
|
218
|
+
)
|
|
219
|
+
);
|
|
220
|
+
})
|
|
221
|
+
).subscribe((data: any) => {
|
|
222
|
+
objThis.filtrados[idFiltrado] = data[dataFiltro.tipoReq] ?? [];
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function changeSelectApi(control: any, queryService: any, formControl: AbstractControl, tipo: any, dataExtra = {}, dataExtraVariable: any[] | null = null, minLength = 1, anonimo = false) {
|
|
227
|
+
formControl.valueChanges.pipe(
|
|
228
|
+
debounceTime(500),
|
|
229
|
+
tap((value) => {
|
|
230
|
+
control['filtrados'][tipo + 'tmp'] = isObservable(control['filtrados'][tipo]) ? []:control['filtrados'][tipo];
|
|
231
|
+
if (control['filtrados'][tipo] != control['filtrados'][tipo + 'tmp']) {
|
|
232
|
+
control['filtrados'][tipo] = [];
|
|
233
|
+
}
|
|
234
|
+
control['isLoading'] = true;
|
|
235
|
+
}),
|
|
236
|
+
|
|
237
|
+
switchMap(value => {
|
|
238
|
+
const formGroup = <any>formControl.parent?.controls;
|
|
239
|
+
const nombreControl = Object.keys(formGroup).find(name => formControl === formGroup[name]) || null;
|
|
240
|
+
if (nombreControl && control['filtrados'][tipo + 'tmp'] && control['filtrados'][tipo + 'tmp'].length > 0) {
|
|
241
|
+
const busquedaActual = control['filtrados'][tipo + 'tmp'].findIndex((item: any) => item[nombreControl] == value);
|
|
242
|
+
if (busquedaActual >= 0) {
|
|
243
|
+
const vRet: any = {};
|
|
244
|
+
vRet[tipo] = control['filtrados'][tipo + 'tmp'];
|
|
245
|
+
control['isLoading'] = false;
|
|
246
|
+
return of(vRet);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (!value || value.length < minLength) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const dataExtraVariableData: any = {};
|
|
254
|
+
if (dataExtraVariable) {
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
for (const objData of dataExtraVariable) {
|
|
257
|
+
dataExtraVariableData[objData.campo] = objData.ctrlValue.value;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return queryService.getDataMethod('GET', tipo, {...dataExtra, ...dataExtraVariableData, ...{txtBuscar: value}}, anonimo).pipe(
|
|
261
|
+
finalize(() => {
|
|
262
|
+
control['isLoading'] = false;
|
|
263
|
+
}),
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
})
|
|
267
|
+
).subscribe((data: any) => {
|
|
268
|
+
if (data[tipo] == undefined) {
|
|
269
|
+
control['filtrados'][tipo] = [];
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
control['filtrados'][tipo] = data[tipo];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {formatDate} from '@angular/common';
|
|
2
|
+
import {formatearFecha} from './date';
|
|
3
|
+
|
|
4
|
+
export function objectPropertiesToType(formFields: Record<string, any>) {
|
|
5
|
+
Object.keys(formFields).filter(control => !!formFields[control]).forEach(control => {
|
|
6
|
+
if (/^dt[a-zA-Z]+/.test(control)) {
|
|
7
|
+
formFields[control] = formatDate(formFields[control], 'yyyy-MM-dd HH:mm', 'es-PE');
|
|
8
|
+
}
|
|
9
|
+
else if (control.startsWith('d')) {
|
|
10
|
+
formFields[control] = formatearFecha(formFields[control]);
|
|
11
|
+
}
|
|
12
|
+
else if (control.startsWith('n')) {
|
|
13
|
+
formFields[control] = Number(formFields[control]);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return formFields;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function objectPropertiesBoolean(formFields: Record<string, any>, retorno: 'boolean' | 'bit' = 'boolean') {
|
|
21
|
+
Object.keys(formFields).forEach(control => {
|
|
22
|
+
const valRetorno = (ctrl: any) => {
|
|
23
|
+
switch (retorno) {
|
|
24
|
+
case 'boolean':
|
|
25
|
+
formFields[ctrl] = formFields[ctrl] == 1;
|
|
26
|
+
break;
|
|
27
|
+
case 'bit':
|
|
28
|
+
formFields[ctrl] = formFields[ctrl] ? 1:0;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
if (control.charAt(0) == 'b' || (control.charAt(0) == 'i' && control.indexOf('Estado') !== -1)) {
|
|
33
|
+
valRetorno(control);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return formFields;
|
|
37
|
+
}
|