feat: export to CSV

This commit is contained in:
filippo-ferrari 2024-09-12 11:53:01 +02:00
parent 157287c68c
commit 575a92022d

View file

@ -69,7 +69,7 @@ public class MainLayout extends AppLayout {
logout.getStyle().set("padding", "10px"); // Add padding to the logout button logout.getStyle().set("padding", "10px"); // Add padding to the logout button
// Create the Export to CSV button // Create the Export to CSV button
Button exportToCSVButton = new Button("Export to CSV"); Button exportToCSVButton = new Button("Export Expenses to CSV");
exportToCSVButton.addClickListener(event -> { exportToCSVButton.addClickListener(event -> {
// Call the CSV service to create the CSV resource // Call the CSV service to create the CSV resource
StreamResource resource = this.csvService.createCSVResource(this.expenseService.findAll()); StreamResource resource = this.csvService.createCSVResource(this.expenseService.findAll());
@ -84,6 +84,7 @@ public class MainLayout extends AppLayout {
// Programmatically click the link to start the download // Programmatically click the link to start the download
downloadLink.getElement().callJsFunction("click"); downloadLink.getElement().callJsFunction("click");
}); });
exportToCSVButton.getStyle().set("margin", "15px"); // Add margin to the Export to CSV button
// Create the header layout and add all elements // Create the header layout and add all elements
HorizontalLayout header = new HorizontalLayout(userInfoLayout, logout); HorizontalLayout header = new HorizontalLayout(userInfoLayout, logout);
@ -133,4 +134,4 @@ public class MainLayout extends AppLayout {
PageTitle title = getContent().getClass().getAnnotation(PageTitle.class); PageTitle title = getContent().getClass().getAnnotation(PageTitle.class);
return title == null ? "" : title.value(); return title == null ? "" : title.value();
} }
} }