@angel199/exporter 0.0.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/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Exporter
|
|
2
|
+
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.2.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build exporter
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
cd dist/exporter
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
40
|
+
```bash
|
|
41
|
+
npm publish
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Running unit tests
|
|
45
|
+
|
|
46
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
ng test
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Running end-to-end tests
|
|
53
|
+
|
|
54
|
+
For end-to-end (e2e) testing, run:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
ng e2e
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
61
|
+
|
|
62
|
+
## Additional Resources
|
|
63
|
+
|
|
64
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Component, Injectable } from '@angular/core';
|
|
3
|
+
import { MessageService } from 'primeng/api';
|
|
4
|
+
import * as FileSaver from 'file-saver';
|
|
5
|
+
|
|
6
|
+
class Exporter {
|
|
7
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: Exporter, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
8
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.0", type: Exporter, isStandalone: true, selector: "lib-exporter", ngImport: i0, template: ``, isInline: true, styles: [""] });
|
|
9
|
+
}
|
|
10
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: Exporter, decorators: [{
|
|
11
|
+
type: Component,
|
|
12
|
+
args: [{ selector: 'lib-exporter', imports: [], template: `` }]
|
|
13
|
+
}] });
|
|
14
|
+
|
|
15
|
+
class ExportService {
|
|
16
|
+
// istanza diretta
|
|
17
|
+
messagesService = new MessageService();
|
|
18
|
+
// esempio metodo notifiche
|
|
19
|
+
notify(message) {
|
|
20
|
+
this.messagesService.add({ severity: 'info', summary: 'Export', detail: message });
|
|
21
|
+
}
|
|
22
|
+
exportDataTable(data, allColumns, format, fileName) {
|
|
23
|
+
const fieldsToKeep = allColumns.map(col => col.field);
|
|
24
|
+
const headers = allColumns.map(col => col.header);
|
|
25
|
+
const filteredArray = data.map(item => {
|
|
26
|
+
const result = {};
|
|
27
|
+
fieldsToKeep.forEach(field => {
|
|
28
|
+
const column = allColumns.find(c => c.field === field);
|
|
29
|
+
if (column && item[field] !== undefined) {
|
|
30
|
+
result[column.header] = item[field];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return result;
|
|
34
|
+
});
|
|
35
|
+
this.notify("Attendere, il report è in fase di caricamento.");
|
|
36
|
+
if (format === 'XLSX') {
|
|
37
|
+
this.exportExcel(filteredArray, headers, fileName);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.exportPdf(filteredArray, headers, fileName);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exportExcel(data, headers, fileName) {
|
|
44
|
+
import('xlsx').then(xlsx => {
|
|
45
|
+
const worksheet = xlsx.utils.json_to_sheet(data, {
|
|
46
|
+
header: headers
|
|
47
|
+
});
|
|
48
|
+
const workbook = {
|
|
49
|
+
Sheets: { [fileName]: worksheet },
|
|
50
|
+
SheetNames: [fileName]
|
|
51
|
+
};
|
|
52
|
+
const excelBuffer = xlsx.write(workbook, {
|
|
53
|
+
bookType: 'xlsx',
|
|
54
|
+
type: 'array'
|
|
55
|
+
});
|
|
56
|
+
const blob = new Blob([excelBuffer], {
|
|
57
|
+
type: 'application/octet-stream'
|
|
58
|
+
});
|
|
59
|
+
FileSaver.saveAs(blob, `${fileName}.xlsx`);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async exportPdf(data, headers, fileName) {
|
|
63
|
+
const { default: jsPDF } = await import('jspdf');
|
|
64
|
+
const { default: autoTable } = await import('jspdf-autotable');
|
|
65
|
+
const doc = new jsPDF();
|
|
66
|
+
autoTable(doc, {
|
|
67
|
+
head: [headers],
|
|
68
|
+
body: data.map(obj => headers.map(h => obj[h] ?? ''))
|
|
69
|
+
});
|
|
70
|
+
doc.save(`${fileName}.pdf`);
|
|
71
|
+
}
|
|
72
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: ExportService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
73
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: ExportService, providedIn: 'root' });
|
|
74
|
+
}
|
|
75
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImport: i0, type: ExportService, decorators: [{
|
|
76
|
+
type: Injectable,
|
|
77
|
+
args: [{
|
|
78
|
+
providedIn: 'root'
|
|
79
|
+
}]
|
|
80
|
+
}] });
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* Public API Surface of exporter
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Generated bundle index. Do not edit.
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
export { ExportService, Exporter };
|
|
91
|
+
//# sourceMappingURL=angel199-exporter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angel199-exporter.mjs","sources":["../../../projects/exporter/src/lib/exporter.ts","../../../projects/exporter/src/lib/exporter.service.ts","../../../projects/exporter/src/public-api.ts","../../../projects/exporter/src/angel199-exporter.ts"],"sourcesContent":["import { Component } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'lib-exporter',\r\n imports: [],\r\n template: ``,\r\n styles: ``,\r\n})\r\nexport class Exporter {\r\n\r\n}\r\n","import { Injectable, inject } from '@angular/core';\r\nimport { MessageService } from 'primeng/api'; // uso diretto della libreria\r\n\r\nimport jsPDF from 'jspdf';\r\nimport autoTable from 'jspdf-autotable';\r\nimport * as FileSaver from 'file-saver';\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class ExportService {\r\n\r\n // istanza diretta\r\n private messagesService = new MessageService();\r\n\r\n // esempio metodo notifiche\r\n private notify(message: string) {\r\n this.messagesService.add({ severity: 'info', summary: 'Export', detail: message });\r\n }\r\n\r\n exportDataTable(\r\n data: any[],\r\n allColumns: any[],\r\n format: 'PDF' | 'XLSX',\r\n fileName: string\r\n ) {\r\n\r\n const fieldsToKeep = allColumns.map(col => col.field);\r\n const headers = allColumns.map(col => col.header);\r\n\r\n const filteredArray = data.map(item => {\r\n const result: any = {};\r\n\r\n fieldsToKeep.forEach(field => {\r\n const column = allColumns.find(c => c.field === field);\r\n if (column && item[field] !== undefined) {\r\n result[column.header] = item[field];\r\n }\r\n });\r\n\r\n return result;\r\n });\r\n\r\n this.notify(\"Attendere, il report è in fase di caricamento.\");\r\n\r\n if (format === 'XLSX') {\r\n this.exportExcel(filteredArray, headers, fileName);\r\n } else {\r\n this.exportPdf(filteredArray, headers, fileName);\r\n }\r\n }\r\n\r\n private exportExcel(\r\n data: Record<string, any>[],\r\n headers: string[],\r\n fileName: string\r\n ) {\r\n import('xlsx').then(xlsx => {\r\n\r\n const worksheet = xlsx.utils.json_to_sheet(data, {\r\n header: headers\r\n });\r\n\r\n const workbook = {\r\n Sheets: { [fileName]: worksheet },\r\n SheetNames: [fileName]\r\n };\r\n\r\n const excelBuffer = xlsx.write(workbook, {\r\n bookType: 'xlsx',\r\n type: 'array'\r\n });\r\n\r\n const blob = new Blob([excelBuffer], {\r\n type: 'application/octet-stream'\r\n });\r\n\r\n FileSaver.saveAs(blob, `${fileName}.xlsx`);\r\n });\r\n }\r\n\r\n async exportPdf(data: any[], headers: string[], fileName: string) {\r\n\r\n const { default: jsPDF } = await import('jspdf');\r\n const { default: autoTable } = await import('jspdf-autotable');\r\n\r\n const doc = new jsPDF();\r\n\r\n autoTable(doc, {\r\n head: [headers],\r\n body: data.map(obj => headers.map(h => obj[h] ?? ''))\r\n });\r\n\r\n doc.save(`${fileName}.pdf`);\r\n}\r\n}\r\n\r\n","/*\r\n * Public API Surface of exporter\r\n */\r\n\r\nexport * from './lib/exporter';\r\nexport * from './lib/exporter.service';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAQ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|
|
9
|
+
"primeicons": "^6.0.0 || ^7.0.0",
|
|
10
|
+
"file-saver": "^2.0.5",
|
|
11
|
+
"jspdf": "^2.5.0",
|
|
12
|
+
"xlsx": "^0.18.5",
|
|
13
|
+
"jspdf-autotable": "^3.8.0"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"tslib": "^2.3.0"
|
|
17
|
+
},
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"module": "fesm2022/angel199-exporter.mjs",
|
|
20
|
+
"typings": "types/angel199-exporter.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": {
|
|
23
|
+
"default": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./types/angel199-exporter.d.ts",
|
|
27
|
+
"default": "./fesm2022/angel199-exporter.mjs"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
|
|
3
|
+
declare class Exporter {
|
|
4
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Exporter, never>;
|
|
5
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<Exporter, "lib-exporter", never, {}, {}, never, never, true, never>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare class ExportService {
|
|
9
|
+
private messagesService;
|
|
10
|
+
private notify;
|
|
11
|
+
exportDataTable(data: any[], allColumns: any[], format: 'PDF' | 'XLSX', fileName: string): void;
|
|
12
|
+
private exportExcel;
|
|
13
|
+
exportPdf(data: any[], headers: string[], fileName: string): Promise<void>;
|
|
14
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ExportService, never>;
|
|
15
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ExportService>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { ExportService, Exporter };
|