@esfaenza/extensions 15.2.8 → 15.2.10
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/esm2020/lib/services/extensions.exports.service.mjs +99 -15
- package/fesm2015/esfaenza-extensions.mjs +352 -267
- package/fesm2015/esfaenza-extensions.mjs.map +1 -1
- package/fesm2020/esfaenza-extensions.mjs +351 -267
- package/fesm2020/esfaenza-extensions.mjs.map +1 -1
- package/lib/services/extensions.exports.service.d.ts +18 -3
- package/package.json +5 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, Injectable, Optional, Inject, Pipe, NgModule, Injector } from '@angular/core';
|
|
3
3
|
import * as i1 from '@esfaenza/localizations';
|
|
4
|
-
import { LocalizationModule
|
|
4
|
+
import { LocalizationModule } from '@esfaenza/localizations';
|
|
5
5
|
import { __awaiter } from 'tslib';
|
|
6
6
|
import { first, map } from 'rxjs/operators';
|
|
7
7
|
import { Deserialize } from 'cerialize';
|
|
@@ -347,7 +347,258 @@ const exportList = "__export_list__";
|
|
|
347
347
|
/** Nome della proprietà che contiene la classe di localizzazione da utilizzare per una data esportazione */
|
|
348
348
|
const locProperty = "__loc__";
|
|
349
349
|
|
|
350
|
+
/**
|
|
351
|
+
* Mappatura del TypeCode del C#
|
|
352
|
+
*/
|
|
353
|
+
var TypeCode;
|
|
354
|
+
(function (TypeCode) {
|
|
355
|
+
/** @ignore */ TypeCode[TypeCode["Empty"] = 0] = "Empty";
|
|
356
|
+
/** @ignore */ TypeCode[TypeCode["Obj"] = 1] = "Obj";
|
|
357
|
+
/** @ignore */ TypeCode[TypeCode["DBNull"] = 2] = "DBNull";
|
|
358
|
+
/** @ignore */ TypeCode[TypeCode["Boolean"] = 3] = "Boolean";
|
|
359
|
+
/** @ignore */ TypeCode[TypeCode["Char"] = 4] = "Char";
|
|
360
|
+
/** @ignore */ TypeCode[TypeCode["SByte"] = 5] = "SByte";
|
|
361
|
+
/** @ignore */ TypeCode[TypeCode["Byte"] = 6] = "Byte";
|
|
362
|
+
/** @ignore */ TypeCode[TypeCode["Int16"] = 7] = "Int16";
|
|
363
|
+
/** @ignore */ TypeCode[TypeCode["UInt16"] = 8] = "UInt16";
|
|
364
|
+
/** @ignore */ TypeCode[TypeCode["Int32"] = 9] = "Int32";
|
|
365
|
+
/** @ignore */ TypeCode[TypeCode["UInt32"] = 10] = "UInt32";
|
|
366
|
+
/** @ignore */ TypeCode[TypeCode["Int64"] = 11] = "Int64";
|
|
367
|
+
/** @ignore */ TypeCode[TypeCode["UInt64"] = 12] = "UInt64";
|
|
368
|
+
/** @ignore */ TypeCode[TypeCode["Single"] = 13] = "Single";
|
|
369
|
+
/** @ignore */ TypeCode[TypeCode["Double"] = 14] = "Double";
|
|
370
|
+
/** @ignore */ TypeCode[TypeCode["Decimal"] = 15] = "Decimal";
|
|
371
|
+
/** @ignore */ TypeCode[TypeCode["DateTime"] = 16] = "DateTime";
|
|
372
|
+
/** @ignore */ TypeCode[TypeCode["String"] = 18] = "String";
|
|
373
|
+
})(TypeCode || (TypeCode = {}));
|
|
374
|
+
|
|
350
375
|
// Angular
|
|
376
|
+
/**
|
|
377
|
+
* Service che fornisce metodi di pubblica utilità
|
|
378
|
+
*/
|
|
379
|
+
class UtilityService {
|
|
380
|
+
/**
|
|
381
|
+
* Deseleziona il testo eventualmente selezionato
|
|
382
|
+
*/
|
|
383
|
+
clearTextSelection() {
|
|
384
|
+
if (window.getSelection) {
|
|
385
|
+
if (window.getSelection().empty) // Chrome
|
|
386
|
+
window.getSelection().empty();
|
|
387
|
+
else if (window.getSelection().removeAllRanges) // Firefox
|
|
388
|
+
window.getSelection().removeAllRanges();
|
|
389
|
+
}
|
|
390
|
+
else if (document.selection) // IE?
|
|
391
|
+
document.selection.empty();
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Partendo da una lista, dato il nome della proprietà chiave e il valore della chiave selezionata,
|
|
395
|
+
* trova e restituisce l'oggetto desiderato
|
|
396
|
+
*
|
|
397
|
+
* @param {T[]} sourceList Lista di oggetti dentro cui cercare
|
|
398
|
+
* @param {string} sourceItemIdField Nome della proprietà che rappresenta la chiave di un oggetto di tipo T
|
|
399
|
+
* @param {string} selectedValue Valore di chiave selezionato
|
|
400
|
+
*
|
|
401
|
+
* @returns {T} Oggetto la cui proprietà **sourceItemIdField** assume il valore **selectedValue**
|
|
402
|
+
*/
|
|
403
|
+
getSelectedItem(sourceList, sourceItemIdField, selectedValue) {
|
|
404
|
+
for (let i = 0; i < sourceList.length; i++) {
|
|
405
|
+
var item = sourceList[i];
|
|
406
|
+
if (item[sourceItemIdField] == selectedValue)
|
|
407
|
+
return item;
|
|
408
|
+
}
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Effettua il reset di un Form di Angular
|
|
413
|
+
*
|
|
414
|
+
* @param {NgForm} form Form da resettare
|
|
415
|
+
* @param {string} exception1 Campo da non resettare
|
|
416
|
+
* @param {string} exception2 Campo da non resettare
|
|
417
|
+
*/
|
|
418
|
+
cleanForm(form, exception1 = null, exception2 = null) {
|
|
419
|
+
for (let name in form.controls) {
|
|
420
|
+
if (name && name != exception1 && name != exception1 + "_internal" && name != exception2 && name != exception2 + "_internal") {
|
|
421
|
+
form.controls[name].reset();
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
form.controls[name].markAsPristine();
|
|
425
|
+
form.controls[name].markAsUntouched();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
//Reimposto il submitted
|
|
429
|
+
form.submitted = false;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Helper che permette di scaricare un file dato un URL (Generato da una chiamata ad **window.URL.createObjectURL**)
|
|
433
|
+
*
|
|
434
|
+
* @param {string} url ObjectURL che rappresenta il file da scaricare
|
|
435
|
+
* @param {string} filename Nome del file suggerito in fase di salvataggio
|
|
436
|
+
*/
|
|
437
|
+
fileDownload(url, fileName) {
|
|
438
|
+
var a = document.createElement("a");
|
|
439
|
+
document.body.appendChild(a);
|
|
440
|
+
a.className = "ta-display-none";
|
|
441
|
+
a.href = url;
|
|
442
|
+
a.download = fileName;
|
|
443
|
+
a.click();
|
|
444
|
+
window.URL.revokeObjectURL(url);
|
|
445
|
+
document.body.removeChild(a);
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Helper per la formattazione di un numero di millisecondi in una stringa più comprensibile per un umano
|
|
449
|
+
*
|
|
450
|
+
* @param {number} duration Tempo espresso in millisecondi
|
|
451
|
+
*
|
|
452
|
+
* @returns {string} Durata formattata
|
|
453
|
+
*/
|
|
454
|
+
msToTime(duration) {
|
|
455
|
+
if (!duration)
|
|
456
|
+
return "";
|
|
457
|
+
var milliseconds = parseInt(((duration % 1000) / 100).toString()), seconds = parseInt(((duration / 1000) % 60).toString()), minutes = parseInt(((duration / (1000 * 60)) % 60).toString()), hours = parseInt(((duration / (1000 * 60 * 60)) % 24).toString());
|
|
458
|
+
var st_hours = (hours < 10) ? "0" + hours : hours;
|
|
459
|
+
var st_minutes = (minutes < 10) ? "0" + minutes : minutes;
|
|
460
|
+
var st_seconds = (seconds < 10) ? "0" + seconds : seconds;
|
|
461
|
+
return st_hours + ":" + st_minutes + ":" + st_seconds + "." + milliseconds;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Helper che permette di scaricare un file in Base64
|
|
465
|
+
*
|
|
466
|
+
* @param {string} base64Data Base64 che rappresenta il file da scaricare
|
|
467
|
+
* @param {string} filename Nome del file suggerito in fase di salvataggio
|
|
468
|
+
*/
|
|
469
|
+
saveFile(base64Data, filename) {
|
|
470
|
+
var sampleArr = this.base64ToArrayBuffer(base64Data);
|
|
471
|
+
this.saveByteArray(sampleArr, filename);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Trasforma un Base64 in un ArrayBuffer
|
|
475
|
+
*
|
|
476
|
+
* @param {string} base64Data Base64 da trasformare
|
|
477
|
+
*
|
|
478
|
+
* @returns {Uint8Array} Array UTF8
|
|
479
|
+
*/
|
|
480
|
+
base64ToArrayBuffer(base64Data) {
|
|
481
|
+
var binaryString = window.atob(base64Data);
|
|
482
|
+
var binaryLen = binaryString.length;
|
|
483
|
+
var bytes = new Uint8Array(binaryLen);
|
|
484
|
+
for (var i = 0; i < binaryLen; i++) {
|
|
485
|
+
var ascii = binaryString.charCodeAt(i);
|
|
486
|
+
bytes[i] = ascii;
|
|
487
|
+
}
|
|
488
|
+
return bytes;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Helper che permette di scaricare un file dato un array di Byte (**Uint8Array**)
|
|
492
|
+
*
|
|
493
|
+
* @param {Uint8Array} byte Rappresentazione del file da scaricare
|
|
494
|
+
* @param {string} filename Nome del file suggerito in fase di salvataggio
|
|
495
|
+
*/
|
|
496
|
+
saveByteArray(byte, filename) {
|
|
497
|
+
var blob = new Blob([byte]);
|
|
498
|
+
var link = document.createElement("a");
|
|
499
|
+
document.body.appendChild(link);
|
|
500
|
+
link.href = window.URL.createObjectURL(blob);
|
|
501
|
+
var fileName = filename;
|
|
502
|
+
link.download = fileName;
|
|
503
|
+
link.click();
|
|
504
|
+
document.body.removeChild(link);
|
|
505
|
+
}
|
|
506
|
+
;
|
|
507
|
+
/**
|
|
508
|
+
* Utility per lo swap di due elementi di un array
|
|
509
|
+
*
|
|
510
|
+
* @param {any[]} array Array di cui invertire due elementi
|
|
511
|
+
* @param {number} x Indice del primo elemento
|
|
512
|
+
* @param {number} y Indice del secondo elemento
|
|
513
|
+
*/
|
|
514
|
+
swap(array, x, y) {
|
|
515
|
+
var b = array[x];
|
|
516
|
+
array[x] = array[y];
|
|
517
|
+
array[y] = b;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Helper di trascodifica da tipo c# a tipo Typescript
|
|
521
|
+
*
|
|
522
|
+
* @param {TypeCode} type Tipo da trascodificare
|
|
523
|
+
*
|
|
524
|
+
* @returns {"boolean" | "number" | "string" | "date"} Tipo Typescript corrispondente
|
|
525
|
+
*/
|
|
526
|
+
getJsTypeFromTypeCode(type) {
|
|
527
|
+
switch (type) {
|
|
528
|
+
case TypeCode.Boolean:
|
|
529
|
+
return "boolean";
|
|
530
|
+
case TypeCode.Decimal:
|
|
531
|
+
case TypeCode.Double:
|
|
532
|
+
case TypeCode.Single:
|
|
533
|
+
case TypeCode.Int16:
|
|
534
|
+
case TypeCode.Int32:
|
|
535
|
+
case TypeCode.Int64:
|
|
536
|
+
case TypeCode.Byte:
|
|
537
|
+
case TypeCode.SByte:
|
|
538
|
+
case TypeCode.UInt16:
|
|
539
|
+
case TypeCode.UInt32:
|
|
540
|
+
case TypeCode.UInt64:
|
|
541
|
+
return "number";
|
|
542
|
+
case TypeCode.Char:
|
|
543
|
+
case TypeCode.String:
|
|
544
|
+
return "string";
|
|
545
|
+
case TypeCode.DateTime:
|
|
546
|
+
return "date";
|
|
547
|
+
default:
|
|
548
|
+
console.log("Unrecognized input type. Typecode:" + type);
|
|
549
|
+
return "string";
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Effettua la clonazione profonda di un oggetto in maniera molto più performante che JSON.parse(JSON.stringify()).
|
|
554
|
+
*
|
|
555
|
+
* Usare solo per oggetti puri e quantomeno semplici per evitare complicazioni derivanti dalle semplificazioni che questo metodo assume
|
|
556
|
+
*
|
|
557
|
+
* @param {any} source Oggetto da clonare
|
|
558
|
+
*
|
|
559
|
+
* @return {any} Clone dell'oggetto passato
|
|
560
|
+
*/
|
|
561
|
+
deepClone(source) {
|
|
562
|
+
// Valori semplici
|
|
563
|
+
if (source == null || typeof source !== 'object')
|
|
564
|
+
return source;
|
|
565
|
+
// Pseudo Struct
|
|
566
|
+
switch (toString.call(source)) {
|
|
567
|
+
case '[object Boolean]':
|
|
568
|
+
case '[object Number]':
|
|
569
|
+
case '[object String]':
|
|
570
|
+
case '[object Date]':
|
|
571
|
+
return new source.constructor(source.valueOf());
|
|
572
|
+
default: break;
|
|
573
|
+
}
|
|
574
|
+
// Oggetti Complessi
|
|
575
|
+
return this.recursiveStep(source, Array.isArray(source) || source instanceof Array ? [] : Object.create(Object.getPrototypeOf(source)));
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* @ignore
|
|
579
|
+
* Step ricorsivo per la clonatura degli oggetti. Vedere **deepClone**
|
|
580
|
+
*/
|
|
581
|
+
recursiveStep(source, destination) {
|
|
582
|
+
if (Array.isArray(source) || source instanceof Array) {
|
|
583
|
+
for (var i = 0, ii = source.length; i < ii; i++)
|
|
584
|
+
destination.push(this.deepClone(source[i]));
|
|
585
|
+
}
|
|
586
|
+
else if (source && typeof source.hasOwnProperty === 'function') {
|
|
587
|
+
for (let key in source) {
|
|
588
|
+
if (source.hasOwnProperty(key))
|
|
589
|
+
destination[key] = this.deepClone(source[key]);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return destination;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
UtilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UtilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
596
|
+
UtilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UtilityService, providedIn: "root" });
|
|
597
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UtilityService, decorators: [{
|
|
598
|
+
type: Injectable,
|
|
599
|
+
args: [{ providedIn: "root" }]
|
|
600
|
+
}] });
|
|
601
|
+
|
|
351
602
|
/**
|
|
352
603
|
* Decoratore che fornisce la classe di localizzazione per tutte le proprietà esportate con @Export e qualsiasi altro tag che richieda localizzazioni.
|
|
353
604
|
*
|
|
@@ -518,8 +769,10 @@ class ExportService {
|
|
|
518
769
|
*
|
|
519
770
|
* @ignore
|
|
520
771
|
*/
|
|
521
|
-
constructor(dates) {
|
|
772
|
+
constructor(dates, utiExts, lc) {
|
|
522
773
|
this.dates = dates;
|
|
774
|
+
this.utiExts = utiExts;
|
|
775
|
+
this.lc = lc;
|
|
523
776
|
}
|
|
524
777
|
/**
|
|
525
778
|
* Data una lista di oggetti genera gli header per l'esportazione e integra ogni oggetto con le proprietà esportabili dalla libreria **@ctrl/ngx-csv**
|
|
@@ -625,7 +878,7 @@ class ExportService {
|
|
|
625
878
|
var headers = [];
|
|
626
879
|
// Miracle incoming
|
|
627
880
|
let exportProps = obj[exportList] || [];
|
|
628
|
-
let loc = this.
|
|
881
|
+
let loc = this.lc.generateFromType(obj[locProperty]);
|
|
629
882
|
if (exportProps.length == 0)
|
|
630
883
|
console.warn("[@esfaenza/extensions] Nessuna colonna configurata da esportare!");
|
|
631
884
|
for (let i = 0; i < exportProps.length; i++) {
|
|
@@ -652,13 +905,6 @@ class ExportService {
|
|
|
652
905
|
}
|
|
653
906
|
return headers;
|
|
654
907
|
}
|
|
655
|
-
/** Helper per ottenere il servizio di localizzazione relativo ad un'entità */
|
|
656
|
-
getLocalizationService(object) {
|
|
657
|
-
if (!object[locProperty])
|
|
658
|
-
return null;
|
|
659
|
-
const injector = Injector.create({ providers: [{ provide: LocalizationService, useClass: object[locProperty] }] });
|
|
660
|
-
return injector.get(LocalizationService);
|
|
661
|
-
}
|
|
662
908
|
/**
|
|
663
909
|
* Setup per l'esportazione di una singola proprietà.
|
|
664
910
|
* Viene generato l'header e la proprietà relativa al valore formattato o no
|
|
@@ -868,18 +1114,109 @@ class ExportService {
|
|
|
868
1114
|
* @param {any[]} items Oggetti da deserializzare
|
|
869
1115
|
* @param {any} type Tipo da usare come prototipo per la deserializzazione
|
|
870
1116
|
*
|
|
871
|
-
* @returns {any} Oggetti deserializzati
|
|
1117
|
+
* @returns {any} Oggetti deserializzati
|
|
1118
|
+
*/
|
|
1119
|
+
deserializeForExport(items, type) {
|
|
1120
|
+
return Deserialize(items, type);
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Effettua l'esportazione in file CSV
|
|
1124
|
+
*/
|
|
1125
|
+
exportCSV(fn, headers, data) {
|
|
1126
|
+
let csvData = '', row = '', sep = ';';
|
|
1127
|
+
for (let i = 0; i < headers.length; i++) {
|
|
1128
|
+
let h = headers[i];
|
|
1129
|
+
row += `${row != '' ? sep : ''}"${h.label}"`;
|
|
1130
|
+
}
|
|
1131
|
+
csvData += row + '\r\n';
|
|
1132
|
+
for (let i = 0; i < data.length; i++) {
|
|
1133
|
+
row = '';
|
|
1134
|
+
let item = data[i];
|
|
1135
|
+
for (let j = 0; j < headers.length; j++) {
|
|
1136
|
+
let val = item[headers[j].key];
|
|
1137
|
+
row += `${row != '' ? sep : ''}"${val}"`;
|
|
1138
|
+
}
|
|
1139
|
+
csvData += row + '\r\n';
|
|
1140
|
+
}
|
|
1141
|
+
var blob = new Blob([csvData], { type: 'text/csv' });
|
|
1142
|
+
var objectUrl = window.URL.createObjectURL(blob);
|
|
1143
|
+
this.utiExts.fileDownload(objectUrl, fn.endsWith('.xlsx') ? fn.replace('.xlsx', '.csv') : fn.endsWith('.csv') ? fn : fn + ".csv");
|
|
1144
|
+
}
|
|
1145
|
+
/** Effettua l'esportazione del file Excel basandosi sul modulo **ExcelJS**, sugli header **headers** e sui dati **data** */
|
|
1146
|
+
exportExcel(fn, headers, data) {
|
|
1147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1148
|
+
try {
|
|
1149
|
+
this.ExcelJS = this.ExcelJS || (yield import('exceljs'));
|
|
1150
|
+
}
|
|
1151
|
+
catch (_a) {
|
|
1152
|
+
throw "Impossibile caricare la libreria per l'esportazione in Excel";
|
|
1153
|
+
}
|
|
1154
|
+
let iFix = 1;
|
|
1155
|
+
let workbook = new this.ExcelJS.Workbook();
|
|
1156
|
+
workbook.creator = "Ema's big Es-Table";
|
|
1157
|
+
workbook.created = new Date();
|
|
1158
|
+
let sheet = workbook.addWorksheet('Data');
|
|
1159
|
+
let header = sheet.getRow(1);
|
|
1160
|
+
header.font = { bold: true };
|
|
1161
|
+
headers = headers.sort((a, b) => a.order - b.order);
|
|
1162
|
+
for (let i = 0; i < headers.length; i++) {
|
|
1163
|
+
let h = headers[i];
|
|
1164
|
+
header.getCell(i + iFix).value = h.label;
|
|
1165
|
+
}
|
|
1166
|
+
for (let i = 0; i < data.length; i++) {
|
|
1167
|
+
let row = sheet.getRow(i + iFix + 1);
|
|
1168
|
+
let item = data[i];
|
|
1169
|
+
for (let i = 0; i < headers.length; i++) {
|
|
1170
|
+
let h = headers[i];
|
|
1171
|
+
let cell = row.getCell(i + 1);
|
|
1172
|
+
let val = item[h.key];
|
|
1173
|
+
if (!val) {
|
|
1174
|
+
cell.value = "";
|
|
1175
|
+
continue;
|
|
1176
|
+
}
|
|
1177
|
+
switch (h.type) {
|
|
1178
|
+
case 'date':
|
|
1179
|
+
// ExcelJS va di default in UTC quindi rischierebbe di tirare giù 2 ore ad ogni esportazione
|
|
1180
|
+
// Bisogna aggiungere l'utc offset alla data attuale
|
|
1181
|
+
let date = this.dates.getDateConvertion(val);
|
|
1182
|
+
if (date) {
|
|
1183
|
+
let correctedDate = date.add(date.utcOffset(), 'minute');
|
|
1184
|
+
cell.value = correctedDate.toDate();
|
|
1185
|
+
cell.numFmt = val.length > 10 ? 'dd/mm/yyyy h:m:s' : '';
|
|
1186
|
+
}
|
|
1187
|
+
break;
|
|
1188
|
+
case 'number':
|
|
1189
|
+
let converted = parseFloat(val.replace(',', '.'));
|
|
1190
|
+
cell.value = isNaN(converted) ? "" : converted;
|
|
1191
|
+
break;
|
|
1192
|
+
default:
|
|
1193
|
+
cell.value = val;
|
|
1194
|
+
break;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
let buffer = yield workbook.xlsx.writeBuffer();
|
|
1199
|
+
let blob = new Blob([buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;" });
|
|
1200
|
+
let objectUrl = window.URL.createObjectURL(blob);
|
|
1201
|
+
this.utiExts.fileDownload(objectUrl, fn.endsWith('.csv') ? fn.replace('.csv', '.xlsx') : fn.endsWith('.xlsx') ? fn : fn + ".xlsx");
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Metodo che effettivamente genera gli header e i dati per l'esportazione con **ngx-csv**
|
|
1206
|
+
*
|
|
1207
|
+
* @param {any[]} items Oggetti da esportare
|
|
872
1208
|
*/
|
|
873
|
-
|
|
874
|
-
|
|
1209
|
+
export(items, format, fileName, columnsFilter, genericHeaders) {
|
|
1210
|
+
let headers = genericHeaders ? this.setupForGenericExport(items, genericHeaders) : this.setupForExport(items, columnsFilter);
|
|
1211
|
+
(format == "CSV" ? this.exportCSV : this.exportExcel)(fileName, headers, items);
|
|
875
1212
|
}
|
|
876
1213
|
}
|
|
877
|
-
ExportService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ExportService, deps: [{ token: DateService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1214
|
+
ExportService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ExportService, deps: [{ token: DateService }, { token: UtilityService }, { token: i1.LocalizationService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
878
1215
|
ExportService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ExportService, providedIn: "root" });
|
|
879
1216
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ExportService, decorators: [{
|
|
880
1217
|
type: Injectable,
|
|
881
1218
|
args: [{ providedIn: "root" }]
|
|
882
|
-
}], ctorParameters: function () { return [{ type: DateService }]; } });
|
|
1219
|
+
}], ctorParameters: function () { return [{ type: DateService }, { type: UtilityService }, { type: i1.LocalizationService }]; } });
|
|
883
1220
|
|
|
884
1221
|
/**
|
|
885
1222
|
* Service che fornisce funzionalità di alert nei tipi fondamentali: success, info, warning e danger
|
|
@@ -1776,258 +2113,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
|
|
|
1776
2113
|
args: [{ providedIn: "root" }]
|
|
1777
2114
|
}] });
|
|
1778
2115
|
|
|
1779
|
-
/**
|
|
1780
|
-
* Mappatura del TypeCode del C#
|
|
1781
|
-
*/
|
|
1782
|
-
var TypeCode;
|
|
1783
|
-
(function (TypeCode) {
|
|
1784
|
-
/** @ignore */ TypeCode[TypeCode["Empty"] = 0] = "Empty";
|
|
1785
|
-
/** @ignore */ TypeCode[TypeCode["Obj"] = 1] = "Obj";
|
|
1786
|
-
/** @ignore */ TypeCode[TypeCode["DBNull"] = 2] = "DBNull";
|
|
1787
|
-
/** @ignore */ TypeCode[TypeCode["Boolean"] = 3] = "Boolean";
|
|
1788
|
-
/** @ignore */ TypeCode[TypeCode["Char"] = 4] = "Char";
|
|
1789
|
-
/** @ignore */ TypeCode[TypeCode["SByte"] = 5] = "SByte";
|
|
1790
|
-
/** @ignore */ TypeCode[TypeCode["Byte"] = 6] = "Byte";
|
|
1791
|
-
/** @ignore */ TypeCode[TypeCode["Int16"] = 7] = "Int16";
|
|
1792
|
-
/** @ignore */ TypeCode[TypeCode["UInt16"] = 8] = "UInt16";
|
|
1793
|
-
/** @ignore */ TypeCode[TypeCode["Int32"] = 9] = "Int32";
|
|
1794
|
-
/** @ignore */ TypeCode[TypeCode["UInt32"] = 10] = "UInt32";
|
|
1795
|
-
/** @ignore */ TypeCode[TypeCode["Int64"] = 11] = "Int64";
|
|
1796
|
-
/** @ignore */ TypeCode[TypeCode["UInt64"] = 12] = "UInt64";
|
|
1797
|
-
/** @ignore */ TypeCode[TypeCode["Single"] = 13] = "Single";
|
|
1798
|
-
/** @ignore */ TypeCode[TypeCode["Double"] = 14] = "Double";
|
|
1799
|
-
/** @ignore */ TypeCode[TypeCode["Decimal"] = 15] = "Decimal";
|
|
1800
|
-
/** @ignore */ TypeCode[TypeCode["DateTime"] = 16] = "DateTime";
|
|
1801
|
-
/** @ignore */ TypeCode[TypeCode["String"] = 18] = "String";
|
|
1802
|
-
})(TypeCode || (TypeCode = {}));
|
|
1803
|
-
|
|
1804
|
-
// Angular
|
|
1805
|
-
/**
|
|
1806
|
-
* Service che fornisce metodi di pubblica utilità
|
|
1807
|
-
*/
|
|
1808
|
-
class UtilityService {
|
|
1809
|
-
/**
|
|
1810
|
-
* Deseleziona il testo eventualmente selezionato
|
|
1811
|
-
*/
|
|
1812
|
-
clearTextSelection() {
|
|
1813
|
-
if (window.getSelection) {
|
|
1814
|
-
if (window.getSelection().empty) // Chrome
|
|
1815
|
-
window.getSelection().empty();
|
|
1816
|
-
else if (window.getSelection().removeAllRanges) // Firefox
|
|
1817
|
-
window.getSelection().removeAllRanges();
|
|
1818
|
-
}
|
|
1819
|
-
else if (document.selection) // IE?
|
|
1820
|
-
document.selection.empty();
|
|
1821
|
-
}
|
|
1822
|
-
/**
|
|
1823
|
-
* Partendo da una lista, dato il nome della proprietà chiave e il valore della chiave selezionata,
|
|
1824
|
-
* trova e restituisce l'oggetto desiderato
|
|
1825
|
-
*
|
|
1826
|
-
* @param {T[]} sourceList Lista di oggetti dentro cui cercare
|
|
1827
|
-
* @param {string} sourceItemIdField Nome della proprietà che rappresenta la chiave di un oggetto di tipo T
|
|
1828
|
-
* @param {string} selectedValue Valore di chiave selezionato
|
|
1829
|
-
*
|
|
1830
|
-
* @returns {T} Oggetto la cui proprietà **sourceItemIdField** assume il valore **selectedValue**
|
|
1831
|
-
*/
|
|
1832
|
-
getSelectedItem(sourceList, sourceItemIdField, selectedValue) {
|
|
1833
|
-
for (let i = 0; i < sourceList.length; i++) {
|
|
1834
|
-
var item = sourceList[i];
|
|
1835
|
-
if (item[sourceItemIdField] == selectedValue)
|
|
1836
|
-
return item;
|
|
1837
|
-
}
|
|
1838
|
-
return null;
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* Effettua il reset di un Form di Angular
|
|
1842
|
-
*
|
|
1843
|
-
* @param {NgForm} form Form da resettare
|
|
1844
|
-
* @param {string} exception1 Campo da non resettare
|
|
1845
|
-
* @param {string} exception2 Campo da non resettare
|
|
1846
|
-
*/
|
|
1847
|
-
cleanForm(form, exception1 = null, exception2 = null) {
|
|
1848
|
-
for (let name in form.controls) {
|
|
1849
|
-
if (name && name != exception1 && name != exception1 + "_internal" && name != exception2 && name != exception2 + "_internal") {
|
|
1850
|
-
form.controls[name].reset();
|
|
1851
|
-
}
|
|
1852
|
-
else {
|
|
1853
|
-
form.controls[name].markAsPristine();
|
|
1854
|
-
form.controls[name].markAsUntouched();
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
//Reimposto il submitted
|
|
1858
|
-
form.submitted = false;
|
|
1859
|
-
}
|
|
1860
|
-
/**
|
|
1861
|
-
* Helper che permette di scaricare un file dato un URL (Generato da una chiamata ad **window.URL.createObjectURL**)
|
|
1862
|
-
*
|
|
1863
|
-
* @param {string} url ObjectURL che rappresenta il file da scaricare
|
|
1864
|
-
* @param {string} filename Nome del file suggerito in fase di salvataggio
|
|
1865
|
-
*/
|
|
1866
|
-
fileDownload(url, fileName) {
|
|
1867
|
-
var a = document.createElement("a");
|
|
1868
|
-
document.body.appendChild(a);
|
|
1869
|
-
a.className = "ta-display-none";
|
|
1870
|
-
a.href = url;
|
|
1871
|
-
a.download = fileName;
|
|
1872
|
-
a.click();
|
|
1873
|
-
window.URL.revokeObjectURL(url);
|
|
1874
|
-
document.body.removeChild(a);
|
|
1875
|
-
}
|
|
1876
|
-
/**
|
|
1877
|
-
* Helper per la formattazione di un numero di millisecondi in una stringa più comprensibile per un umano
|
|
1878
|
-
*
|
|
1879
|
-
* @param {number} duration Tempo espresso in millisecondi
|
|
1880
|
-
*
|
|
1881
|
-
* @returns {string} Durata formattata
|
|
1882
|
-
*/
|
|
1883
|
-
msToTime(duration) {
|
|
1884
|
-
if (!duration)
|
|
1885
|
-
return "";
|
|
1886
|
-
var milliseconds = parseInt(((duration % 1000) / 100).toString()), seconds = parseInt(((duration / 1000) % 60).toString()), minutes = parseInt(((duration / (1000 * 60)) % 60).toString()), hours = parseInt(((duration / (1000 * 60 * 60)) % 24).toString());
|
|
1887
|
-
var st_hours = (hours < 10) ? "0" + hours : hours;
|
|
1888
|
-
var st_minutes = (minutes < 10) ? "0" + minutes : minutes;
|
|
1889
|
-
var st_seconds = (seconds < 10) ? "0" + seconds : seconds;
|
|
1890
|
-
return st_hours + ":" + st_minutes + ":" + st_seconds + "." + milliseconds;
|
|
1891
|
-
}
|
|
1892
|
-
/**
|
|
1893
|
-
* Helper che permette di scaricare un file in Base64
|
|
1894
|
-
*
|
|
1895
|
-
* @param {string} base64Data Base64 che rappresenta il file da scaricare
|
|
1896
|
-
* @param {string} filename Nome del file suggerito in fase di salvataggio
|
|
1897
|
-
*/
|
|
1898
|
-
saveFile(base64Data, filename) {
|
|
1899
|
-
var sampleArr = this.base64ToArrayBuffer(base64Data);
|
|
1900
|
-
this.saveByteArray(sampleArr, filename);
|
|
1901
|
-
}
|
|
1902
|
-
/**
|
|
1903
|
-
* Trasforma un Base64 in un ArrayBuffer
|
|
1904
|
-
*
|
|
1905
|
-
* @param {string} base64Data Base64 da trasformare
|
|
1906
|
-
*
|
|
1907
|
-
* @returns {Uint8Array} Array UTF8
|
|
1908
|
-
*/
|
|
1909
|
-
base64ToArrayBuffer(base64Data) {
|
|
1910
|
-
var binaryString = window.atob(base64Data);
|
|
1911
|
-
var binaryLen = binaryString.length;
|
|
1912
|
-
var bytes = new Uint8Array(binaryLen);
|
|
1913
|
-
for (var i = 0; i < binaryLen; i++) {
|
|
1914
|
-
var ascii = binaryString.charCodeAt(i);
|
|
1915
|
-
bytes[i] = ascii;
|
|
1916
|
-
}
|
|
1917
|
-
return bytes;
|
|
1918
|
-
}
|
|
1919
|
-
/**
|
|
1920
|
-
* Helper che permette di scaricare un file dato un array di Byte (**Uint8Array**)
|
|
1921
|
-
*
|
|
1922
|
-
* @param {Uint8Array} byte Rappresentazione del file da scaricare
|
|
1923
|
-
* @param {string} filename Nome del file suggerito in fase di salvataggio
|
|
1924
|
-
*/
|
|
1925
|
-
saveByteArray(byte, filename) {
|
|
1926
|
-
var blob = new Blob([byte]);
|
|
1927
|
-
var link = document.createElement("a");
|
|
1928
|
-
document.body.appendChild(link);
|
|
1929
|
-
link.href = window.URL.createObjectURL(blob);
|
|
1930
|
-
var fileName = filename;
|
|
1931
|
-
link.download = fileName;
|
|
1932
|
-
link.click();
|
|
1933
|
-
document.body.removeChild(link);
|
|
1934
|
-
}
|
|
1935
|
-
;
|
|
1936
|
-
/**
|
|
1937
|
-
* Utility per lo swap di due elementi di un array
|
|
1938
|
-
*
|
|
1939
|
-
* @param {any[]} array Array di cui invertire due elementi
|
|
1940
|
-
* @param {number} x Indice del primo elemento
|
|
1941
|
-
* @param {number} y Indice del secondo elemento
|
|
1942
|
-
*/
|
|
1943
|
-
swap(array, x, y) {
|
|
1944
|
-
var b = array[x];
|
|
1945
|
-
array[x] = array[y];
|
|
1946
|
-
array[y] = b;
|
|
1947
|
-
}
|
|
1948
|
-
/**
|
|
1949
|
-
* Helper di trascodifica da tipo c# a tipo Typescript
|
|
1950
|
-
*
|
|
1951
|
-
* @param {TypeCode} type Tipo da trascodificare
|
|
1952
|
-
*
|
|
1953
|
-
* @returns {"boolean" | "number" | "string" | "date"} Tipo Typescript corrispondente
|
|
1954
|
-
*/
|
|
1955
|
-
getJsTypeFromTypeCode(type) {
|
|
1956
|
-
switch (type) {
|
|
1957
|
-
case TypeCode.Boolean:
|
|
1958
|
-
return "boolean";
|
|
1959
|
-
case TypeCode.Decimal:
|
|
1960
|
-
case TypeCode.Double:
|
|
1961
|
-
case TypeCode.Single:
|
|
1962
|
-
case TypeCode.Int16:
|
|
1963
|
-
case TypeCode.Int32:
|
|
1964
|
-
case TypeCode.Int64:
|
|
1965
|
-
case TypeCode.Byte:
|
|
1966
|
-
case TypeCode.SByte:
|
|
1967
|
-
case TypeCode.UInt16:
|
|
1968
|
-
case TypeCode.UInt32:
|
|
1969
|
-
case TypeCode.UInt64:
|
|
1970
|
-
return "number";
|
|
1971
|
-
case TypeCode.Char:
|
|
1972
|
-
case TypeCode.String:
|
|
1973
|
-
return "string";
|
|
1974
|
-
case TypeCode.DateTime:
|
|
1975
|
-
return "date";
|
|
1976
|
-
default:
|
|
1977
|
-
console.log("Unrecognized input type. Typecode:" + type);
|
|
1978
|
-
return "string";
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
/**
|
|
1982
|
-
* Effettua la clonazione profonda di un oggetto in maniera molto più performante che JSON.parse(JSON.stringify()).
|
|
1983
|
-
*
|
|
1984
|
-
* Usare solo per oggetti puri e quantomeno semplici per evitare complicazioni derivanti dalle semplificazioni che questo metodo assume
|
|
1985
|
-
*
|
|
1986
|
-
* @param {any} source Oggetto da clonare
|
|
1987
|
-
*
|
|
1988
|
-
* @return {any} Clone dell'oggetto passato
|
|
1989
|
-
*/
|
|
1990
|
-
deepClone(source) {
|
|
1991
|
-
// Valori semplici
|
|
1992
|
-
if (source == null || typeof source !== 'object')
|
|
1993
|
-
return source;
|
|
1994
|
-
// Pseudo Struct
|
|
1995
|
-
switch (toString.call(source)) {
|
|
1996
|
-
case '[object Boolean]':
|
|
1997
|
-
case '[object Number]':
|
|
1998
|
-
case '[object String]':
|
|
1999
|
-
case '[object Date]':
|
|
2000
|
-
return new source.constructor(source.valueOf());
|
|
2001
|
-
default: break;
|
|
2002
|
-
}
|
|
2003
|
-
// Oggetti Complessi
|
|
2004
|
-
return this.recursiveStep(source, Array.isArray(source) || source instanceof Array ? [] : Object.create(Object.getPrototypeOf(source)));
|
|
2005
|
-
}
|
|
2006
|
-
/**
|
|
2007
|
-
* @ignore
|
|
2008
|
-
* Step ricorsivo per la clonatura degli oggetti. Vedere **deepClone**
|
|
2009
|
-
*/
|
|
2010
|
-
recursiveStep(source, destination) {
|
|
2011
|
-
if (Array.isArray(source) || source instanceof Array) {
|
|
2012
|
-
for (var i = 0, ii = source.length; i < ii; i++)
|
|
2013
|
-
destination.push(this.deepClone(source[i]));
|
|
2014
|
-
}
|
|
2015
|
-
else if (source && typeof source.hasOwnProperty === 'function') {
|
|
2016
|
-
for (let key in source) {
|
|
2017
|
-
if (source.hasOwnProperty(key))
|
|
2018
|
-
destination[key] = this.deepClone(source[key]);
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
return destination;
|
|
2022
|
-
}
|
|
2023
|
-
}
|
|
2024
|
-
UtilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UtilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2025
|
-
UtilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UtilityService, providedIn: "root" });
|
|
2026
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UtilityService, decorators: [{
|
|
2027
|
-
type: Injectable,
|
|
2028
|
-
args: [{ providedIn: "root" }]
|
|
2029
|
-
}] });
|
|
2030
|
-
|
|
2031
2116
|
/**
|
|
2032
2117
|
* Classe che rappresenta una risposta ricevuta da un Backend
|
|
2033
2118
|
*/
|