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