@esfaenza/extensions 15.2.9 → 15.2.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.
@@ -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,9 @@ class ExportService {
518
769
  *
519
770
  * @ignore
520
771
  */
521
- constructor(dates, lc) {
772
+ constructor(dates, utiExts, lc) {
522
773
  this.dates = dates;
774
+ this.utiExts = utiExts;
523
775
  this.lc = lc;
524
776
  }
525
777
  /**
@@ -862,18 +1114,109 @@ class ExportService {
862
1114
  * @param {any[]} items Oggetti da deserializzare
863
1115
  * @param {any} type Tipo da usare come prototipo per la deserializzazione
864
1116
  *
865
- * @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
866
1208
  */
867
- deserializeForExport(items, type) {
868
- return Deserialize(items, type);
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);
869
1212
  }
870
1213
  }
871
- ExportService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ExportService, deps: [{ token: DateService }, { token: i1.LocalizationService }], 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 });
872
1215
  ExportService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ExportService, providedIn: "root" });
873
1216
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ExportService, decorators: [{
874
1217
  type: Injectable,
875
1218
  args: [{ providedIn: "root" }]
876
- }], ctorParameters: function () { return [{ type: DateService }, { type: i1.LocalizationService }]; } });
1219
+ }], ctorParameters: function () { return [{ type: DateService }, { type: UtilityService }, { type: i1.LocalizationService }]; } });
877
1220
 
878
1221
  /**
879
1222
  * Service che fornisce funzionalità di alert nei tipi fondamentali: success, info, warning e danger
@@ -1770,258 +2113,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1770
2113
  args: [{ providedIn: "root" }]
1771
2114
  }] });
1772
2115
 
1773
- /**
1774
- * Mappatura del TypeCode del C#
1775
- */
1776
- var TypeCode;
1777
- (function (TypeCode) {
1778
- /** @ignore */ TypeCode[TypeCode["Empty"] = 0] = "Empty";
1779
- /** @ignore */ TypeCode[TypeCode["Obj"] = 1] = "Obj";
1780
- /** @ignore */ TypeCode[TypeCode["DBNull"] = 2] = "DBNull";
1781
- /** @ignore */ TypeCode[TypeCode["Boolean"] = 3] = "Boolean";
1782
- /** @ignore */ TypeCode[TypeCode["Char"] = 4] = "Char";
1783
- /** @ignore */ TypeCode[TypeCode["SByte"] = 5] = "SByte";
1784
- /** @ignore */ TypeCode[TypeCode["Byte"] = 6] = "Byte";
1785
- /** @ignore */ TypeCode[TypeCode["Int16"] = 7] = "Int16";
1786
- /** @ignore */ TypeCode[TypeCode["UInt16"] = 8] = "UInt16";
1787
- /** @ignore */ TypeCode[TypeCode["Int32"] = 9] = "Int32";
1788
- /** @ignore */ TypeCode[TypeCode["UInt32"] = 10] = "UInt32";
1789
- /** @ignore */ TypeCode[TypeCode["Int64"] = 11] = "Int64";
1790
- /** @ignore */ TypeCode[TypeCode["UInt64"] = 12] = "UInt64";
1791
- /** @ignore */ TypeCode[TypeCode["Single"] = 13] = "Single";
1792
- /** @ignore */ TypeCode[TypeCode["Double"] = 14] = "Double";
1793
- /** @ignore */ TypeCode[TypeCode["Decimal"] = 15] = "Decimal";
1794
- /** @ignore */ TypeCode[TypeCode["DateTime"] = 16] = "DateTime";
1795
- /** @ignore */ TypeCode[TypeCode["String"] = 18] = "String";
1796
- })(TypeCode || (TypeCode = {}));
1797
-
1798
- // Angular
1799
- /**
1800
- * Service che fornisce metodi di pubblica utilità
1801
- */
1802
- class UtilityService {
1803
- /**
1804
- * Deseleziona il testo eventualmente selezionato
1805
- */
1806
- clearTextSelection() {
1807
- if (window.getSelection) {
1808
- if (window.getSelection().empty) // Chrome
1809
- window.getSelection().empty();
1810
- else if (window.getSelection().removeAllRanges) // Firefox
1811
- window.getSelection().removeAllRanges();
1812
- }
1813
- else if (document.selection) // IE?
1814
- document.selection.empty();
1815
- }
1816
- /**
1817
- * Partendo da una lista, dato il nome della proprietà chiave e il valore della chiave selezionata,
1818
- * trova e restituisce l'oggetto desiderato
1819
- *
1820
- * @param {T[]} sourceList Lista di oggetti dentro cui cercare
1821
- * @param {string} sourceItemIdField Nome della proprietà che rappresenta la chiave di un oggetto di tipo T
1822
- * @param {string} selectedValue Valore di chiave selezionato
1823
- *
1824
- * @returns {T} Oggetto la cui proprietà **sourceItemIdField** assume il valore **selectedValue**
1825
- */
1826
- getSelectedItem(sourceList, sourceItemIdField, selectedValue) {
1827
- for (let i = 0; i < sourceList.length; i++) {
1828
- var item = sourceList[i];
1829
- if (item[sourceItemIdField] == selectedValue)
1830
- return item;
1831
- }
1832
- return null;
1833
- }
1834
- /**
1835
- * Effettua il reset di un Form di Angular
1836
- *
1837
- * @param {NgForm} form Form da resettare
1838
- * @param {string} exception1 Campo da non resettare
1839
- * @param {string} exception2 Campo da non resettare
1840
- */
1841
- cleanForm(form, exception1 = null, exception2 = null) {
1842
- for (let name in form.controls) {
1843
- if (name && name != exception1 && name != exception1 + "_internal" && name != exception2 && name != exception2 + "_internal") {
1844
- form.controls[name].reset();
1845
- }
1846
- else {
1847
- form.controls[name].markAsPristine();
1848
- form.controls[name].markAsUntouched();
1849
- }
1850
- }
1851
- //Reimposto il submitted
1852
- form.submitted = false;
1853
- }
1854
- /**
1855
- * Helper che permette di scaricare un file dato un URL (Generato da una chiamata ad **window.URL.createObjectURL**)
1856
- *
1857
- * @param {string} url ObjectURL che rappresenta il file da scaricare
1858
- * @param {string} filename Nome del file suggerito in fase di salvataggio
1859
- */
1860
- fileDownload(url, fileName) {
1861
- var a = document.createElement("a");
1862
- document.body.appendChild(a);
1863
- a.className = "ta-display-none";
1864
- a.href = url;
1865
- a.download = fileName;
1866
- a.click();
1867
- window.URL.revokeObjectURL(url);
1868
- document.body.removeChild(a);
1869
- }
1870
- /**
1871
- * Helper per la formattazione di un numero di millisecondi in una stringa più comprensibile per un umano
1872
- *
1873
- * @param {number} duration Tempo espresso in millisecondi
1874
- *
1875
- * @returns {string} Durata formattata
1876
- */
1877
- msToTime(duration) {
1878
- if (!duration)
1879
- return "";
1880
- 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());
1881
- var st_hours = (hours < 10) ? "0" + hours : hours;
1882
- var st_minutes = (minutes < 10) ? "0" + minutes : minutes;
1883
- var st_seconds = (seconds < 10) ? "0" + seconds : seconds;
1884
- return st_hours + ":" + st_minutes + ":" + st_seconds + "." + milliseconds;
1885
- }
1886
- /**
1887
- * Helper che permette di scaricare un file in Base64
1888
- *
1889
- * @param {string} base64Data Base64 che rappresenta il file da scaricare
1890
- * @param {string} filename Nome del file suggerito in fase di salvataggio
1891
- */
1892
- saveFile(base64Data, filename) {
1893
- var sampleArr = this.base64ToArrayBuffer(base64Data);
1894
- this.saveByteArray(sampleArr, filename);
1895
- }
1896
- /**
1897
- * Trasforma un Base64 in un ArrayBuffer
1898
- *
1899
- * @param {string} base64Data Base64 da trasformare
1900
- *
1901
- * @returns {Uint8Array} Array UTF8
1902
- */
1903
- base64ToArrayBuffer(base64Data) {
1904
- var binaryString = window.atob(base64Data);
1905
- var binaryLen = binaryString.length;
1906
- var bytes = new Uint8Array(binaryLen);
1907
- for (var i = 0; i < binaryLen; i++) {
1908
- var ascii = binaryString.charCodeAt(i);
1909
- bytes[i] = ascii;
1910
- }
1911
- return bytes;
1912
- }
1913
- /**
1914
- * Helper che permette di scaricare un file dato un array di Byte (**Uint8Array**)
1915
- *
1916
- * @param {Uint8Array} byte Rappresentazione del file da scaricare
1917
- * @param {string} filename Nome del file suggerito in fase di salvataggio
1918
- */
1919
- saveByteArray(byte, filename) {
1920
- var blob = new Blob([byte]);
1921
- var link = document.createElement("a");
1922
- document.body.appendChild(link);
1923
- link.href = window.URL.createObjectURL(blob);
1924
- var fileName = filename;
1925
- link.download = fileName;
1926
- link.click();
1927
- document.body.removeChild(link);
1928
- }
1929
- ;
1930
- /**
1931
- * Utility per lo swap di due elementi di un array
1932
- *
1933
- * @param {any[]} array Array di cui invertire due elementi
1934
- * @param {number} x Indice del primo elemento
1935
- * @param {number} y Indice del secondo elemento
1936
- */
1937
- swap(array, x, y) {
1938
- var b = array[x];
1939
- array[x] = array[y];
1940
- array[y] = b;
1941
- }
1942
- /**
1943
- * Helper di trascodifica da tipo c# a tipo Typescript
1944
- *
1945
- * @param {TypeCode} type Tipo da trascodificare
1946
- *
1947
- * @returns {"boolean" | "number" | "string" | "date"} Tipo Typescript corrispondente
1948
- */
1949
- getJsTypeFromTypeCode(type) {
1950
- switch (type) {
1951
- case TypeCode.Boolean:
1952
- return "boolean";
1953
- case TypeCode.Decimal:
1954
- case TypeCode.Double:
1955
- case TypeCode.Single:
1956
- case TypeCode.Int16:
1957
- case TypeCode.Int32:
1958
- case TypeCode.Int64:
1959
- case TypeCode.Byte:
1960
- case TypeCode.SByte:
1961
- case TypeCode.UInt16:
1962
- case TypeCode.UInt32:
1963
- case TypeCode.UInt64:
1964
- return "number";
1965
- case TypeCode.Char:
1966
- case TypeCode.String:
1967
- return "string";
1968
- case TypeCode.DateTime:
1969
- return "date";
1970
- default:
1971
- console.log("Unrecognized input type. Typecode:" + type);
1972
- return "string";
1973
- }
1974
- }
1975
- /**
1976
- * Effettua la clonazione profonda di un oggetto in maniera molto più performante che JSON.parse(JSON.stringify()).
1977
- *
1978
- * Usare solo per oggetti puri e quantomeno semplici per evitare complicazioni derivanti dalle semplificazioni che questo metodo assume
1979
- *
1980
- * @param {any} source Oggetto da clonare
1981
- *
1982
- * @return {any} Clone dell'oggetto passato
1983
- */
1984
- deepClone(source) {
1985
- // Valori semplici
1986
- if (source == null || typeof source !== 'object')
1987
- return source;
1988
- // Pseudo Struct
1989
- switch (toString.call(source)) {
1990
- case '[object Boolean]':
1991
- case '[object Number]':
1992
- case '[object String]':
1993
- case '[object Date]':
1994
- return new source.constructor(source.valueOf());
1995
- default: break;
1996
- }
1997
- // Oggetti Complessi
1998
- return this.recursiveStep(source, Array.isArray(source) || source instanceof Array ? [] : Object.create(Object.getPrototypeOf(source)));
1999
- }
2000
- /**
2001
- * @ignore
2002
- * Step ricorsivo per la clonatura degli oggetti. Vedere **deepClone**
2003
- */
2004
- recursiveStep(source, destination) {
2005
- if (Array.isArray(source) || source instanceof Array) {
2006
- for (var i = 0, ii = source.length; i < ii; i++)
2007
- destination.push(this.deepClone(source[i]));
2008
- }
2009
- else if (source && typeof source.hasOwnProperty === 'function') {
2010
- for (let key in source) {
2011
- if (source.hasOwnProperty(key))
2012
- destination[key] = this.deepClone(source[key]);
2013
- }
2014
- }
2015
- return destination;
2016
- }
2017
- }
2018
- UtilityService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UtilityService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
2019
- UtilityService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UtilityService, providedIn: "root" });
2020
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: UtilityService, decorators: [{
2021
- type: Injectable,
2022
- args: [{ providedIn: "root" }]
2023
- }] });
2024
-
2025
2116
  /**
2026
2117
  * Classe che rappresenta una risposta ricevuta da un Backend
2027
2118
  */