uni-manager 0.1.0 → 0.1.1
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/uni-manager-http.mjs +80 -81
- package/fesm2022/uni-manager-http.mjs.map +1 -1
- package/fesm2022/uni-manager-locale.mjs +3 -3
- package/fesm2022/uni-manager-locale.mjs.map +1 -1
- package/fesm2022/uni-manager-toast.mjs +16 -14
- package/fesm2022/uni-manager-toast.mjs.map +1 -1
- package/fesm2022/uni-manager.mjs +99 -98
- package/fesm2022/uni-manager.mjs.map +1 -1
- package/package.json +1 -1
- package/types/uni-manager-http.d.ts +6 -11
- package/types/uni-manager-locale.d.ts +1 -1
- package/types/uni-manager-toast.d.ts +2 -4
- package/types/uni-manager.d.ts +9 -16
|
@@ -27,22 +27,24 @@ class UniToastManager {
|
|
|
27
27
|
* Mostra un toast di successo basato su una risposta HTTP e una label di traduzione.
|
|
28
28
|
*/
|
|
29
29
|
static showHttp(config, res) {
|
|
30
|
-
const {
|
|
30
|
+
const { params, resParams, formatters } = config;
|
|
31
31
|
/* Parametri statici di base */
|
|
32
|
-
const allParams = { ...
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
const allParams = { ...params };
|
|
33
|
+
if (res !== undefined && res !== null) {
|
|
34
|
+
/* Se è un array aggiunge il parametro 'count' con la lunghezza dell'array */
|
|
35
|
+
if (Array.isArray(res)) {
|
|
36
|
+
allParams['count'] = res.length;
|
|
37
|
+
}
|
|
38
|
+
else if (typeof res === 'object' && resParams?.length) {
|
|
39
|
+
// Se la proprietà NON esiste nella risposta, allora salta
|
|
40
|
+
for (const resParam of resParams ?? []) {
|
|
41
|
+
if (!(resParam in res))
|
|
42
|
+
continue;
|
|
43
|
+
// Se esiste un formatter per questa chiave lo si usa, altrimenti valore grezzo
|
|
44
|
+
const rawValue = res[resParam];
|
|
45
|
+
allParams[resParam] = formatters?.[resParam] ? formatters[resParam](rawValue) : rawValue;
|
|
46
|
+
}
|
|
41
47
|
}
|
|
42
|
-
}
|
|
43
|
-
/* Config parametro lunghezza risposta: conteggio array */
|
|
44
|
-
if (resLengthParam && Array.isArray(res)) {
|
|
45
|
-
allParams[resLengthParam] = res.length;
|
|
46
48
|
}
|
|
47
49
|
/* Messaggio tradotto */
|
|
48
50
|
this.show({ ...config, params: allParams });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uni-manager-toast.mjs","sources":["../../../projects/uni-manager/toast/manager.ts","../../../projects/uni-manager/toast/uni-manager-toast.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\r\nimport { UniLocaleManager } from 'uni-manager/locale';\r\nimport type { IToastManager, ToastConfig, ToastHttpConfig } from './model';\r\n\r\nexport class UniToastManager {\r\n /* ------------------------------------------------------------------------------- */\r\n /* ----------------------------------- Config ------------------------------------ */\r\n /* ------------------------------------------------------------------------------- */\r\n /** Riferimento interno all'istanza */\r\n private static manager: IToastManager;\r\n\r\n /* ------------------------------------------------------------------------------- */\r\n /* -------------------------------- Metodi: setup -------------------------------- */\r\n /* ------------------------------------------------------------------------------- */\r\n /**\r\n * Inizializza il manager con una serie di operazioni\r\n */\r\n public static setup(operations: IToastManager): void {\r\n this.manager = operations;\r\n }\r\n\r\n /* ------------------------------------------------------------------------------- */\r\n /* -------------------------------- Metodi: show --------------------------------- */\r\n /* ------------------------------------------------------------------------------- */\r\n /**\r\n * Mostra un toast di successo basato su una risposta HTTP e una label di traduzione.\r\n */\r\n public static show(\r\n config:
|
|
1
|
+
{"version":3,"file":"uni-manager-toast.mjs","sources":["../../../projects/uni-manager/toast/manager.ts","../../../projects/uni-manager/toast/uni-manager-toast.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\r\nimport { UniLocaleManager } from 'uni-manager/locale';\r\nimport type { IToastManager, ToastConfig, ToastHttpConfig } from './model';\r\n\r\nexport class UniToastManager {\r\n /* ------------------------------------------------------------------------------- */\r\n /* ----------------------------------- Config ------------------------------------ */\r\n /* ------------------------------------------------------------------------------- */\r\n /** Riferimento interno all'istanza */\r\n private static manager: IToastManager;\r\n\r\n /* ------------------------------------------------------------------------------- */\r\n /* -------------------------------- Metodi: setup -------------------------------- */\r\n /* ------------------------------------------------------------------------------- */\r\n /**\r\n * Inizializza il manager con una serie di operazioni\r\n */\r\n public static setup(operations: IToastManager): void {\r\n this.manager = operations;\r\n }\r\n\r\n /* ------------------------------------------------------------------------------- */\r\n /* -------------------------------- Metodi: show --------------------------------- */\r\n /* ------------------------------------------------------------------------------- */\r\n /**\r\n * Mostra un toast di successo basato su una risposta HTTP e una label di traduzione.\r\n */\r\n public static show(\r\n config: ToastConfig & {\r\n prefix?: string;\r\n suffix?: string;\r\n },\r\n ): void {\r\n /* Messaggio tradotto */\r\n const msg = UniLocaleManager.translate(config.label, 'toast', config.params);\r\n const msgFixed = `${config.prefix ?? ''}${msg}${config.suffix ?? ''}`;\r\n this.manager[config.type ?? 'info'](msgFixed, config);\r\n }\r\n\r\n /**\r\n * Mostra un toast di successo basato su una risposta HTTP e una label di traduzione.\r\n */\r\n public static showHttp<T>(config: ToastConfig & ToastHttpConfig<T>, res: T | undefined): void {\r\n const { params, resParams, formatters } = config;\r\n\r\n /* Parametri statici di base */\r\n const allParams: Record<string, any> = { ...params };\r\n\r\n if (res !== undefined && res !== null) {\r\n /* Se è un array aggiunge il parametro 'count' con la lunghezza dell'array */\r\n if (Array.isArray(res)) {\r\n allParams['count'] = res.length;\r\n } else if (typeof res === 'object' && resParams?.length) {\r\n // Se la proprietà NON esiste nella risposta, allora salta\r\n for (const resParam of resParams ?? []) {\r\n if (!(resParam in res)) continue;\r\n\r\n // Se esiste un formatter per questa chiave lo si usa, altrimenti valore grezzo\r\n const rawValue = res[resParam];\r\n allParams[resParam] = formatters?.[resParam] ? formatters[resParam](rawValue) : rawValue;\r\n }\r\n }\r\n }\r\n\r\n /* Messaggio tradotto */\r\n this.show({ ...config, params: allParams });\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAAA;MAIa,eAAe,CAAA;;;;AAU1B;;AAEG;IACI,OAAO,KAAK,CAAC,UAAyB,EAAA;AAC3C,QAAA,IAAI,CAAC,OAAO,GAAG,UAAU;IAC3B;;;;AAKA;;AAEG;IACI,OAAO,IAAI,CAChB,MAGC,EAAA;;AAGD,QAAA,MAAM,GAAG,GAAG,gBAAgB,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;AAC5E,QAAA,MAAM,QAAQ,GAAG,CAAA,EAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAA,EAAG,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE;AACrE,QAAA,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC;IACvD;AAEA;;AAEG;AACI,IAAA,OAAO,QAAQ,CAAI,MAAwC,EAAE,GAAkB,EAAA;QACpF,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM;;AAGhD,QAAA,MAAM,SAAS,GAAwB,EAAE,GAAG,MAAM,EAAE;QAEpD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;;AAErC,YAAA,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;AACtB,gBAAA,SAAS,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,MAAM;YACjC;iBAAO,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,SAAS,EAAE,MAAM,EAAE;;AAEvD,gBAAA,KAAK,MAAM,QAAQ,IAAI,SAAS,IAAI,EAAE,EAAE;AACtC,oBAAA,IAAI,EAAE,QAAQ,IAAI,GAAG,CAAC;wBAAE;;AAGxB,oBAAA,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;oBAC9B,SAAS,CAAC,QAAQ,CAAC,GAAG,UAAU,GAAG,QAAQ,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,QAAQ;gBAC1F;YACF;QACF;;AAGA,QAAA,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC7C;AACD;;ACnED;;AAEG;;;;"}
|
package/fesm2022/uni-manager.mjs
CHANGED
|
@@ -207,28 +207,27 @@ function operatorHandler(operator) {
|
|
|
207
207
|
}
|
|
208
208
|
function errorHandler(err, errorMode, ref) {
|
|
209
209
|
// Controllo: sia effettivamente un errore di tipo 'UniHttpError'
|
|
210
|
-
if (
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
case PollingErrorMode.STOP: {
|
|
228
|
-
UniErrorManager$1.add(ref, err);
|
|
229
|
-
return throwError(() => err);
|
|
210
|
+
if (err instanceof UniHttpError) {
|
|
211
|
+
switch (errorMode) {
|
|
212
|
+
case PollingErrorMode.IGNORE: {
|
|
213
|
+
return of();
|
|
214
|
+
}
|
|
215
|
+
case PollingErrorMode.SKIP: {
|
|
216
|
+
return EMPTY;
|
|
217
|
+
}
|
|
218
|
+
case PollingErrorMode.IGNORE_WITH_ERROR: {
|
|
219
|
+
UniErrorManager$1.add(ref, err);
|
|
220
|
+
return of();
|
|
221
|
+
}
|
|
222
|
+
case PollingErrorMode.STOP: {
|
|
223
|
+
UniErrorManager$1.add(ref, err);
|
|
224
|
+
return throwError(() => err);
|
|
225
|
+
}
|
|
230
226
|
}
|
|
231
227
|
}
|
|
228
|
+
else {
|
|
229
|
+
return throwError(() => err);
|
|
230
|
+
}
|
|
232
231
|
}
|
|
233
232
|
|
|
234
233
|
/* ------------------------------------------------------------------------------- */
|
|
@@ -263,6 +262,8 @@ function http$(url, refType, config, promiseFactory) {
|
|
|
263
262
|
}
|
|
264
263
|
},
|
|
265
264
|
}), catchError((err) => {
|
|
265
|
+
// Aggiorna la ref nella map
|
|
266
|
+
updateHasError(ref, true);
|
|
266
267
|
/* Gestione errore */
|
|
267
268
|
return errorHandler(err, PollingErrorMode.STOP, ref);
|
|
268
269
|
}), finalize(() => {
|
|
@@ -308,6 +309,8 @@ function httpPolling$(url, config, promiseFactory) {
|
|
|
308
309
|
UniToastManager$1.showHttp(firstIteration.toast, res);
|
|
309
310
|
}
|
|
310
311
|
}), catchError((err) => {
|
|
312
|
+
// Aggiorna la ref nella map
|
|
313
|
+
updateHasError(ref, true);
|
|
311
314
|
/* Gestione errore */
|
|
312
315
|
return errorHandler(err, errorMode, ref);
|
|
313
316
|
}), finalize(() => {
|
|
@@ -409,15 +412,6 @@ function updateHasError(id, hasError) {
|
|
|
409
412
|
// Aggiorna il nuovo stato notificando l'observer
|
|
410
413
|
UniHttpManager.store.next(newMap);
|
|
411
414
|
}
|
|
412
|
-
/**
|
|
413
|
-
* Svuota completamente la lista delle refs
|
|
414
|
-
*/
|
|
415
|
-
function removeAll() {
|
|
416
|
-
// Crea una nuova istanza della Map
|
|
417
|
-
const newMap = new Map();
|
|
418
|
-
// Aggiorna il nuovo stato notificando l'observer
|
|
419
|
-
UniHttpManager.store.next(newMap);
|
|
420
|
-
}
|
|
421
415
|
|
|
422
416
|
async function execute(url, init) {
|
|
423
417
|
try {
|
|
@@ -427,39 +421,44 @@ async function execute(url, init) {
|
|
|
427
421
|
if (res.status === 204) {
|
|
428
422
|
return undefined;
|
|
429
423
|
}
|
|
430
|
-
/*
|
|
431
|
-
|
|
432
|
-
|
|
424
|
+
/* Risposta ok */
|
|
425
|
+
if (res.ok) {
|
|
426
|
+
return res;
|
|
427
|
+
}
|
|
433
428
|
/* Errore HTTP (quindi risposta ricevuta ma non ok) */
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
429
|
+
let errorBody;
|
|
430
|
+
try {
|
|
431
|
+
/* Clona risposta per leggerla senza consumare la originale */
|
|
432
|
+
const resClone = res.clone();
|
|
433
|
+
/* Recupero se è un json */
|
|
434
|
+
const contentType = res.headers.get('content-type') ?? '';
|
|
435
|
+
const isJson = contentType.startsWith('application/json');
|
|
436
|
+
/* Aggiorna body con struttura errore */
|
|
437
|
+
errorBody = isJson ? await resClone.json() : await resClone.text();
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
// Se il clone o il parsing falliscono, si usa una stringa di fallback sicura
|
|
441
|
+
errorBody = `Failed to parse error response body (Status: ${res.status})`;
|
|
442
|
+
}
|
|
443
|
+
if (isHttpErrorBody(errorBody)) {
|
|
444
|
+
const type = errorBody.exceptionType.includes('HttpRequestException') ? 'be' : 'ice';
|
|
445
|
+
throw new UniHttpError(type, res.status, url, errorBody);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
const error = new Error(`HTTP ${res.statusText}`);
|
|
449
|
+
throw new UniHttpError('base', res.status, url, {
|
|
450
|
+
exceptionMessage: error.message,
|
|
451
|
+
exceptionType: 'ErrorBase',
|
|
452
|
+
message: error.message,
|
|
453
|
+
stackTrace: error.stack ?? '',
|
|
454
|
+
});
|
|
458
455
|
}
|
|
459
|
-
/* Risposta ok */
|
|
460
|
-
return res;
|
|
461
456
|
}
|
|
462
457
|
catch (error) {
|
|
458
|
+
// Se l'errore è già un UniHttpError (lanciato sopra) bypassa tutto il resto
|
|
459
|
+
if (error instanceof UniHttpError) {
|
|
460
|
+
throw error;
|
|
461
|
+
}
|
|
463
462
|
if (error instanceof TypeError) {
|
|
464
463
|
throw new UniHttpError('network', -1, url, {
|
|
465
464
|
exceptionMessage: `${error.name}: ${error.message}\n${error.stack}`,
|
|
@@ -468,7 +467,7 @@ async function execute(url, init) {
|
|
|
468
467
|
stackTrace: error.stack ?? '',
|
|
469
468
|
});
|
|
470
469
|
}
|
|
471
|
-
// Fallback
|
|
470
|
+
// Fallback per qualsiasi altro tipo di errore sconosciuto
|
|
472
471
|
throw error;
|
|
473
472
|
}
|
|
474
473
|
}
|
|
@@ -515,16 +514,16 @@ async function executeBlob(url, init) {
|
|
|
515
514
|
* Costruisce un URL completo per l'API partendo dai parametri di configurazione.
|
|
516
515
|
*/
|
|
517
516
|
function getUrl(hostname, port, config) {
|
|
518
|
-
const {
|
|
517
|
+
const { pathParams, path, hasApiPrefix } = config;
|
|
519
518
|
// Costruzione url
|
|
520
|
-
const prefix = hasApiPrefix ? '
|
|
519
|
+
const prefix = hasApiPrefix === false ? '' : 'api';
|
|
521
520
|
const cleanPath = path.startsWith('/') ? path.slice(1) : path;
|
|
522
521
|
const pathFixed = prefix ? `${prefix}/${cleanPath}` : cleanPath;
|
|
523
522
|
const url = new URL(pathFixed, `http://${hostname}:${port}`);
|
|
524
|
-
if (
|
|
523
|
+
if (pathParams) {
|
|
525
524
|
// Regex per intercettare stringhe in formato ISO string
|
|
526
525
|
const isoDateRegex = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?$/;
|
|
527
|
-
for (const [key, rawValue] of Object.entries(
|
|
526
|
+
for (const [key, rawValue] of Object.entries(pathParams)) {
|
|
528
527
|
if (rawValue === undefined || rawValue === null) {
|
|
529
528
|
continue;
|
|
530
529
|
}
|
|
@@ -641,7 +640,7 @@ class UniHttpManager {
|
|
|
641
640
|
...config.init,
|
|
642
641
|
method: 'GET',
|
|
643
642
|
};
|
|
644
|
-
/*
|
|
643
|
+
/* API */
|
|
645
644
|
const url = getUrl(this.hostname, this.port, config);
|
|
646
645
|
return http$(url, 'one', config, () => executeHttp(url, initCustom)).pipe(tap((res) => {
|
|
647
646
|
if (Array.isArray(res) && config.toast === undefined) {
|
|
@@ -667,12 +666,12 @@ class UniHttpManager {
|
|
|
667
666
|
},
|
|
668
667
|
body: JSON.stringify(normalizeHttpBody(body)),
|
|
669
668
|
};
|
|
670
|
-
/*
|
|
669
|
+
/* Config custom (toast di default) */
|
|
671
670
|
const configCustom = {
|
|
672
671
|
...config,
|
|
673
|
-
toast: config.
|
|
672
|
+
toast: config.hasToast === false ? undefined : (config.toast ?? CONFIG_TOAST_DEFAULT),
|
|
674
673
|
};
|
|
675
|
-
/*
|
|
674
|
+
/* API */
|
|
676
675
|
const url = getUrl(this.hostname, this.port, config);
|
|
677
676
|
return http$(url, 'one', configCustom, () => executeHttp(url, initCustom));
|
|
678
677
|
}
|
|
@@ -689,12 +688,12 @@ class UniHttpManager {
|
|
|
689
688
|
};
|
|
690
689
|
initCustom.body = JSON.stringify(normalizeHttpBody(body));
|
|
691
690
|
}
|
|
692
|
-
/*
|
|
691
|
+
/* Config custom (toast di default) */
|
|
693
692
|
const configCustom = {
|
|
694
693
|
...config,
|
|
695
|
-
toast: config.
|
|
694
|
+
toast: config.hasToast === false ? undefined : (config.toast ?? CONFIG_TOAST_DEFAULT),
|
|
696
695
|
};
|
|
697
|
-
/*
|
|
696
|
+
/* API */
|
|
698
697
|
const url = getUrl(this.hostname, this.port, config);
|
|
699
698
|
return http$(url, 'one', configCustom, () => executeHttp(url, initCustom));
|
|
700
699
|
}
|
|
@@ -708,12 +707,12 @@ class UniHttpManager {
|
|
|
708
707
|
...config.init,
|
|
709
708
|
method: 'DELETE',
|
|
710
709
|
};
|
|
711
|
-
/*
|
|
710
|
+
/* Config custom (toast di default) */
|
|
712
711
|
const configCustom = {
|
|
713
712
|
...config,
|
|
714
|
-
toast: config.
|
|
713
|
+
toast: config.hasToast === false ? undefined : (config.toast ?? CONFIG_TOAST_DEFAULT),
|
|
715
714
|
};
|
|
716
|
-
/*
|
|
715
|
+
/* API */
|
|
717
716
|
const url = getUrl(this.hostname, this.port, config);
|
|
718
717
|
return http$(url, 'one', configCustom, () => executeHttp(url, initCustom));
|
|
719
718
|
}
|
|
@@ -730,9 +729,9 @@ class UniHttpManager {
|
|
|
730
729
|
...config.init,
|
|
731
730
|
method: 'GET',
|
|
732
731
|
};
|
|
733
|
-
/*
|
|
732
|
+
/* API */
|
|
734
733
|
const url = getUrl(this.hostname, this.port, config);
|
|
735
|
-
return http$(url, '
|
|
734
|
+
return http$(url, 'image', config, () => executeBlob(url, initCustom));
|
|
736
735
|
}
|
|
737
736
|
/**
|
|
738
737
|
* Recupera un file (es. PDF) tramite una richiesta GET e restituisce un Object URL temporaneo.
|
|
@@ -744,12 +743,12 @@ class UniHttpManager {
|
|
|
744
743
|
...config.init,
|
|
745
744
|
method: 'GET',
|
|
746
745
|
};
|
|
747
|
-
/*
|
|
746
|
+
/* Config custom (toast di default) */
|
|
748
747
|
const configCustom = {
|
|
749
748
|
...config,
|
|
750
|
-
toast: config.
|
|
749
|
+
toast: config.hasToast === false ? undefined : (config.toast ?? CONFIG_TOAST_DEFAULT),
|
|
751
750
|
};
|
|
752
|
-
/*
|
|
751
|
+
/* API */
|
|
753
752
|
const url = getUrl(this.hostname, this.port, config);
|
|
754
753
|
return http$(url, 'file', configCustom, () => executeBlob(url, initCustom));
|
|
755
754
|
}
|
|
@@ -766,7 +765,7 @@ class UniHttpManager {
|
|
|
766
765
|
...config.init,
|
|
767
766
|
method: 'GET',
|
|
768
767
|
};
|
|
769
|
-
/*
|
|
768
|
+
/* API */
|
|
770
769
|
const url = getUrl(this.hostname, this.port, config);
|
|
771
770
|
return httpPolling$(url, config, () => executeHttp(url, initCustom));
|
|
772
771
|
}
|
|
@@ -782,7 +781,7 @@ class UniHttpManager {
|
|
|
782
781
|
headers: { 'Content-Type': 'application/json' },
|
|
783
782
|
body: JSON.stringify(body),
|
|
784
783
|
};
|
|
785
|
-
/*
|
|
784
|
+
/* API */
|
|
786
785
|
const url = getUrl(this.hostname, this.port, config);
|
|
787
786
|
return httpPolling$(url, config, () => executeHttp(url, initCustom));
|
|
788
787
|
}
|
|
@@ -802,7 +801,7 @@ class UniHttpManager {
|
|
|
802
801
|
};
|
|
803
802
|
initCustom.body = JSON.stringify(body);
|
|
804
803
|
}
|
|
805
|
-
/*
|
|
804
|
+
/* API */
|
|
806
805
|
const url = getUrl(this.hostname, this.port, config);
|
|
807
806
|
return httpPolling$(url, config, () => executeHttp(url, initCustom));
|
|
808
807
|
}
|
|
@@ -878,7 +877,7 @@ class UniLocaleManager {
|
|
|
878
877
|
* Traduce una label in base al dizionario caricato.
|
|
879
878
|
* Gestisce la composizione della chiave, i parametri dinamici (interpolazione) e il fallback.
|
|
880
879
|
*/
|
|
881
|
-
static translate(key, prefix = 'lbl',
|
|
880
|
+
static translate(key, prefix = 'lbl', params) {
|
|
882
881
|
if (!key)
|
|
883
882
|
return '-';
|
|
884
883
|
// Costruzione chiave: prefissoGlobale + prefissoLocale + LabelConInizialeMaiuscola
|
|
@@ -895,8 +894,8 @@ class UniLocaleManager {
|
|
|
895
894
|
return `🔑 ${finalKey}`;
|
|
896
895
|
}
|
|
897
896
|
// Interpolazione variabili
|
|
898
|
-
if (
|
|
899
|
-
for (const [key, value] of Object.entries(
|
|
897
|
+
if (params) {
|
|
898
|
+
for (const [key, value] of Object.entries(params)) {
|
|
900
899
|
const displayValue = value instanceof Date ? value.toLocaleDateString(this._locale) : String(value);
|
|
901
900
|
translation = translation.replaceAll(`{{${key}}}`, displayValue);
|
|
902
901
|
}
|
|
@@ -995,22 +994,24 @@ class UniToastManager {
|
|
|
995
994
|
* Mostra un toast di successo basato su una risposta HTTP e una label di traduzione.
|
|
996
995
|
*/
|
|
997
996
|
static showHttp(config, res) {
|
|
998
|
-
const {
|
|
997
|
+
const { params, resParams, formatters } = config;
|
|
999
998
|
/* Parametri statici di base */
|
|
1000
|
-
const allParams = { ...
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
999
|
+
const allParams = { ...params };
|
|
1000
|
+
if (res !== undefined && res !== null) {
|
|
1001
|
+
/* Se è un array aggiunge il parametro 'count' con la lunghezza dell'array */
|
|
1002
|
+
if (Array.isArray(res)) {
|
|
1003
|
+
allParams['count'] = res.length;
|
|
1004
|
+
}
|
|
1005
|
+
else if (typeof res === 'object' && resParams?.length) {
|
|
1006
|
+
// Se la proprietà NON esiste nella risposta, allora salta
|
|
1007
|
+
for (const resParam of resParams ?? []) {
|
|
1008
|
+
if (!(resParam in res))
|
|
1009
|
+
continue;
|
|
1010
|
+
// Se esiste un formatter per questa chiave lo si usa, altrimenti valore grezzo
|
|
1011
|
+
const rawValue = res[resParam];
|
|
1012
|
+
allParams[resParam] = formatters?.[resParam] ? formatters[resParam](rawValue) : rawValue;
|
|
1013
|
+
}
|
|
1009
1014
|
}
|
|
1010
|
-
}
|
|
1011
|
-
/* Config parametro lunghezza risposta: conteggio array */
|
|
1012
|
-
if (resLengthParam && Array.isArray(res)) {
|
|
1013
|
-
allParams[resLengthParam] = res.length;
|
|
1014
1015
|
}
|
|
1015
1016
|
/* Messaggio tradotto */
|
|
1016
1017
|
this.show({ ...config, params: allParams });
|