From 3e016d2bf98493874cf762b167db66d8c28f2a8c Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Sat, 7 Sep 2024 21:33:01 +0200 Subject: [PATCH] feat: 1st try on confirmation dialog --- .../munera/views/people/PeopleView.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/com/application/munera/views/people/PeopleView.java b/src/main/java/com/application/munera/views/people/PeopleView.java index 2b177d9..c950c9c 100644 --- a/src/main/java/com/application/munera/views/people/PeopleView.java +++ b/src/main/java/com/application/munera/views/people/PeopleView.java @@ -13,6 +13,7 @@ import com.vaadin.flow.component.dependency.Uses; import com.vaadin.flow.component.formlayout.FormLayout; import com.vaadin.flow.component.grid.GridVariant; import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.html.Span; import com.vaadin.flow.component.icon.Icon; import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.notification.Notification.Position; @@ -82,6 +83,16 @@ public class PeopleView extends Div implements BeforeEnterObserver { else return this.viewService.createExpenseBadge(((Expense) persona)); })).setHeader("Balance Status"); + grid.addColumn(new ComponentRenderer<>(person -> { + if (person instanceof Person) { + Button markPaidButton = new Button("Mark All Expenses Paid", event -> markExpensesPaid((Person) person)); + markPaidButton.addThemeVariants(ButtonVariant.LUMO_SMALL, ButtonVariant.LUMO_PRIMARY); + return markPaidButton; + } else { + return new Span(); + } + })).setHeader("Actions"); + List people = (List) personService.findAll(); this.setGridData(people); @@ -243,4 +254,20 @@ public class PeopleView extends Div implements BeforeEnterObserver { for (Expense expense : expenses) grid.getTreeData().addItem(user, expense); } } + + private void markExpensesPaid(Person person) { + try { + List expenses = expenseService.findCreditByUser(person).stream().toList(); + for (Expense expense : expenses) { + expense.setIsPaid(true); + expenseService.update(expense); + } + Notification.show("All expenses marked as paid for " + person.getFirstName() + " " + person.getLastName()); + refreshGrid(); + } catch (Exception e) { + Notification n = Notification.show("Error marking expenses as paid: " + e.getMessage()); + n.setPosition(Position.MIDDLE); + n.addThemeVariants(NotificationVariant.LUMO_ERROR); + } + } } \ No newline at end of file