Run and Download direct table reports as XLS file
This commit is contained in:
committed by
Adam Saghy
parent
780c469ee4
commit
ba7a5dbca9
@@ -2,7 +2,7 @@
|
||||
|
||||
<mat-card *ngIf="!isCollapsed">
|
||||
|
||||
<form [formGroup]="reportForm" (ngSubmit)="run()">
|
||||
<form [formGroup]="reportForm">
|
||||
|
||||
<mat-card-content fxLayout="column">
|
||||
|
||||
@@ -78,10 +78,14 @@
|
||||
|
||||
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
|
||||
<button type="button" mat-raised-button [routerLink]="['/reports']">{{"labels.buttons.Cancel" | translate}}</button>
|
||||
<button mat-raised-button color="primary" [disabled]="!reportForm.valid" id="runreport">
|
||||
<button mat-raised-button color="primary" [disabled]="!reportForm.valid || isProcessing" id="runreport" (click)="run()">
|
||||
<fa-icon icon="file-export" class="m-r-10"></fa-icon>
|
||||
{{"labels.buttons.Run Report" | translate}}
|
||||
</button>
|
||||
<button *ngIf="isTableReport()" mat-raised-button color="primary" [disabled]="!reportForm.valid || isProcessing" (click)="runReportAndExport($event)">
|
||||
<fa-icon icon="download" class="m-r-10"></fa-icon>
|
||||
{{"labels.buttons.Run and Download Report" | translate}}
|
||||
</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</form>
|
||||
|
||||
@@ -12,7 +12,9 @@ import { ReportParameter } from '../common-models/report-parameter.model';
|
||||
import { SelectOption } from '../common-models/select-option.model';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { GlobalConfiguration } from 'app/system/configurations/global-configurations-tab/configuration.model';
|
||||
import { ProgressBarService } from 'app/core/progress-bar/progress-bar.service';
|
||||
|
||||
import * as XLSX from 'xlsx';
|
||||
import { AlertService } from 'app/core/alert/alert.service';
|
||||
|
||||
/**
|
||||
* Run report component.
|
||||
@@ -60,6 +62,8 @@ export class RunReportComponent implements OnInit {
|
||||
exportToS3Repository: string;
|
||||
outputTypeOptions: any[] = [];
|
||||
|
||||
isProcessing = false;
|
||||
|
||||
/**
|
||||
* Fetches report specifications from route params and retrieves report parameters data from `resolve`.
|
||||
* @param {ActivatedRoute} route ActivatedRoute.
|
||||
@@ -70,8 +74,8 @@ export class RunReportComponent implements OnInit {
|
||||
constructor(private route: ActivatedRoute,
|
||||
private reportsService: ReportsService,
|
||||
private settingsService: SettingsService,
|
||||
private dateUtils: Dates,
|
||||
private progressBarService: ProgressBarService) {
|
||||
private alertService: AlertService,
|
||||
private dateUtils: Dates) {
|
||||
this.report.name = this.route.snapshot.params['name'];
|
||||
this.route.queryParams.subscribe((queryParams: { type: any, id: any }) => {
|
||||
this.report.type = queryParams.type;
|
||||
@@ -290,4 +294,48 @@ export class RunReportComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
runReportAndExport($event: Event): void {
|
||||
$event.stopPropagation();
|
||||
this.isProcessing = true;
|
||||
const userResponseValues = this.formatUserResponse(this.reportForm.value);
|
||||
|
||||
const reportName = this.report.name;
|
||||
const payload = {
|
||||
...userResponseValues,
|
||||
decimalChoice: this.decimalChoice.value,
|
||||
// exportCSV: true
|
||||
};
|
||||
this.reportsService.getRunReportData(reportName, payload)
|
||||
.subscribe( (res: any) => {
|
||||
if (res.data.length > 0) {
|
||||
this.alertService.alert({type: 'Report generation', message: `Report: ${reportName} data generated`});
|
||||
|
||||
const displayedColumns: string[] = [];
|
||||
res.columnHeaders.forEach((header: any) => {
|
||||
displayedColumns.push(header.columnName);
|
||||
});
|
||||
|
||||
this.exportToXLS(reportName, res.data, displayedColumns);
|
||||
} else {
|
||||
this.alertService.alert({type: 'Report generation', message: `Report: ${reportName} without data generated`});
|
||||
}
|
||||
this.isProcessing = false;
|
||||
});
|
||||
}
|
||||
|
||||
exportToXLS(reportName: string, csvData: any, displayedColumns: string[]): void {
|
||||
const fileName = `${reportName}.xlsx`;
|
||||
const data = csvData.map((object: any) => {
|
||||
const row = {};
|
||||
for (let i = 0; i < displayedColumns.length; i++) {
|
||||
row[displayedColumns[i]] = object.row[i];
|
||||
}
|
||||
return row;
|
||||
});
|
||||
const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(data, {header: displayedColumns});
|
||||
const wb: XLSX.WorkBook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(wb, ws, 'report');
|
||||
XLSX.writeFile(wb, fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export class ViewUserComponent implements OnInit {
|
||||
if (response.delete) {
|
||||
this.usersService.deleteUser(this.userData.id)
|
||||
.subscribe(() => {
|
||||
this.router.navigate(['/users']);
|
||||
this.router.navigate(['/appusers']);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -74,7 +74,7 @@ export class ViewUserComponent implements OnInit {
|
||||
const firstname = this.userData.firstname;
|
||||
const data = {password: password, repeatPassword: repeatPassword, firstname: firstname};
|
||||
this.usersService.changePassword(this.userData.id, data).subscribe(() => {
|
||||
this.router.navigate(['/users']);
|
||||
this.router.navigate(['/appusers']);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "Obnovit heslo",
|
||||
"Retrieve": "Načíst",
|
||||
"Revert Transaction": "Vrátit transakci",
|
||||
"Run and Download Report": "Spusťte a stahujte zprávu",
|
||||
"Run Catch-Up": "Spusťte Catch-Up",
|
||||
"Run Periodic Accruals": "Spusťte periodické časové rozlišení",
|
||||
"Run Report": "Spustit zprávu",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "Passwort zurücksetzen",
|
||||
"Retrieve": "Abrufen",
|
||||
"Revert Transaction": "Transaktion rückgängig machen",
|
||||
"Run and Download Report": "Bericht ausführen und herunterladen",
|
||||
"Run Catch-Up": "Führen Sie Catch-Up durch",
|
||||
"Run Periodic Accruals": "Führen Sie periodische Rückstellungen durch",
|
||||
"Run Report": "Bericht ausführen",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "Reset Password",
|
||||
"Retrieve": "Retrieve",
|
||||
"Revert Transaction": "Revert Transaction",
|
||||
"Run and Download Report": "Run and Download Report",
|
||||
"Run Catch-Up": "Run Catch-Up",
|
||||
"Run Periodic Accruals": "Run Periodic Accruals",
|
||||
"Run Report": "Run Report",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "Restablecer la contraseña",
|
||||
"Retrieve": "Recuperar",
|
||||
"Revert Transaction": "Revertir transacción",
|
||||
"Run and Download Report": "Ejecutar y descargar informe",
|
||||
"Run Catch-Up": "Correr para ponerse al día",
|
||||
"Run Periodic Accruals": "Ejecutar acumulaciones periódicas",
|
||||
"Run Report": "Sacar un reporte",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "réinitialiser le mot de passe",
|
||||
"Retrieve": "Récupérer",
|
||||
"Revert Transaction": "Annuler la transaction",
|
||||
"Run and Download Report": "Rapport d'exécution et de téléchargement",
|
||||
"Run Catch-Up": "Exécuter un rattrapage",
|
||||
"Run Periodic Accruals": "Exécuter des régularisations périodiques",
|
||||
"Run Report": "Rapport d'exécution",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "Resetta la password",
|
||||
"Retrieve": "Recuperare",
|
||||
"Revert Transaction": "Annulla transazione",
|
||||
"Run and Download Report": "Esegui e scarica il rapporto",
|
||||
"Run Catch-Up": "Esegui il recupero",
|
||||
"Run Periodic Accruals": "Esegui ratei periodici",
|
||||
"Run Report": "Esegui rapporto",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "암호를 재설정",
|
||||
"Retrieve": "검색하다",
|
||||
"Revert Transaction": "거래 되돌리기",
|
||||
"Run and Download Report": "보고서를 실행하고 다운로드하십시오",
|
||||
"Run Catch-Up": "따라잡기 실행",
|
||||
"Run Periodic Accruals": "정기적인 발생 실행",
|
||||
"Run Report": "보고서 실행",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "Atstatyti slaptažodį",
|
||||
"Retrieve": "Atgauti",
|
||||
"Revert Transaction": "Grąžinti operaciją",
|
||||
"Run and Download Report": "Paleisti ir atsisiųsti ataskaitą",
|
||||
"Run Catch-Up": "Vykdykite „Catch-Up“.",
|
||||
"Run Periodic Accruals": "Vykdykite periodinius kaupimus",
|
||||
"Run Report": "Vykdyti ataskaitą",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "Atiestatīt paroli",
|
||||
"Retrieve": "Atgūt",
|
||||
"Revert Transaction": "Atsaukt darījumu",
|
||||
"Run and Download Report": "Palaist un lejupielādēt pārskatu",
|
||||
"Run Catch-Up": "Palaist Catch-Up",
|
||||
"Run Periodic Accruals": "Veiciet periodiskus uzkrājumus",
|
||||
"Run Report": "Palaist ziņojumu",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "पासवर्ड रिसेट",
|
||||
"Retrieve": "पुन: प्राप्त गर्नुहोस्",
|
||||
"Revert Transaction": "लेनदेन उल्टाउनुहोस्",
|
||||
"Run and Download Report": "रन र डाउनलोड रिपोर्ट डाउनलोड गर्नुहोस्",
|
||||
"Run Catch-Up": "क्याच-अप चलाउनुहोस्",
|
||||
"Run Periodic Accruals": "आवधिक आम्दानी चलाउनुहोस्",
|
||||
"Run Report": "रिपोर्ट चलाउनुहोस्",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "Redefinir senha",
|
||||
"Retrieve": "Recuperar",
|
||||
"Revert Transaction": "Reverter transação",
|
||||
"Run and Download Report": "Relatório de execução e download",
|
||||
"Run Catch-Up": "Execute o catch-up",
|
||||
"Run Periodic Accruals": "Executar acumulações periódicas",
|
||||
"Run Report": "Executar relatório",
|
||||
|
||||
@@ -446,6 +446,7 @@
|
||||
"Reset Password": "Weka upya Nenosiri",
|
||||
"Retrieve": "Rejesha",
|
||||
"Revert Transaction": "Rejesha Muamala",
|
||||
"Run and Download Report": "Kukimbia na kupakua ripoti",
|
||||
"Run Catch-Up": "Run Catch-Up",
|
||||
"Run Periodic Accruals": "Endesha Mapato ya Mara kwa Mara",
|
||||
"Run Report": "Endesha Ripoti",
|
||||
|
||||
Reference in New Issue
Block a user