feat: improve PeopleView labels
This commit is contained in:
parent
db4a0ad407
commit
cf97709ad1
2 changed files with 20 additions and 13 deletions
|
@ -311,5 +311,4 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
|
||||||
default -> BadgeMessage.UNKNOWN;
|
default -> BadgeMessage.UNKNOWN;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package com.application.munera.views.people;
|
package com.application.munera.views.people;
|
||||||
|
|
||||||
import com.application.munera.data.Expense;
|
import com.application.munera.data.*;
|
||||||
import com.application.munera.data.Person;
|
|
||||||
import com.application.munera.services.ExpenseService;
|
import com.application.munera.services.ExpenseService;
|
||||||
import com.application.munera.services.PersonService;
|
import com.application.munera.services.PersonService;
|
||||||
import com.application.munera.views.MainLayout;
|
import com.application.munera.views.MainLayout;
|
||||||
|
import com.application.munera.views.expenses.BadgeMessage;
|
||||||
import com.vaadin.flow.component.UI;
|
import com.vaadin.flow.component.UI;
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.button.ButtonVariant;
|
import com.vaadin.flow.component.button.ButtonVariant;
|
||||||
|
@ -78,7 +78,7 @@ public class PeopleView extends Div implements BeforeEnterObserver {
|
||||||
grid.addColumn(this::getNodeCost).setHeader("Total Expenses Value").setSortable(true);
|
grid.addColumn(this::getNodeCost).setHeader("Total Expenses Value").setSortable(true);
|
||||||
grid.addColumn(new ComponentRenderer<>(persona -> {
|
grid.addColumn(new ComponentRenderer<>(persona -> {
|
||||||
if (persona instanceof Person) return createPersonBadge(personService.calculateNetBalance((Person) persona));
|
if (persona instanceof Person) return createPersonBadge(personService.calculateNetBalance((Person) persona));
|
||||||
else return createExpenseBadge(((Expense) persona).getIsPaid());
|
else return createExpenseBadge(((Expense) persona));
|
||||||
})).setHeader("Balance Status");
|
})).setHeader("Balance Status");
|
||||||
|
|
||||||
List<Person> people = (List<Person>) personService.findAll();
|
List<Person> people = (List<Person>) personService.findAll();
|
||||||
|
@ -239,18 +239,26 @@ public class PeopleView extends Div implements BeforeEnterObserver {
|
||||||
return badge;
|
return badge;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Span createExpenseBadge(Boolean isExpensePaid) {
|
private Span createExpenseBadge(final Expense expense) {
|
||||||
Span badge = new Span();
|
final var isExpensePaid = Boolean.TRUE.equals(this.expenseService.isExpensePaid(expense));
|
||||||
if (Boolean.TRUE.equals(isExpensePaid)) {
|
final var badgeMessage = determineBadgeMessage(expense.getExpenseType(), isExpensePaid);
|
||||||
badge.setText("Paid");
|
|
||||||
badge.getElement().getThemeList().add("badge success");
|
final var badge = new Span();
|
||||||
} else {
|
badge.setText(badgeMessage.getText());
|
||||||
badge.setText("Owed");
|
badge.getElement().getThemeList().add(badgeMessage.getTheme());
|
||||||
badge.getElement().getThemeList().add("badge error");
|
|
||||||
}
|
|
||||||
return badge;
|
return badge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BadgeMessage determineBadgeMessage(ExpenseType type, boolean isPaid) {
|
||||||
|
return switch (type) {
|
||||||
|
case CREDIT -> isPaid ? BadgeMessage.PAID_TO_SOMEONE : BadgeMessage.OWED_BY_SOMEONE;
|
||||||
|
case DEBIT -> isPaid ? BadgeMessage.PAID_TO_YOU : BadgeMessage.OWED_TO_YOU;
|
||||||
|
case NONE -> isPaid ? BadgeMessage.PAID : BadgeMessage.NOT_PAID;
|
||||||
|
default -> BadgeMessage.UNKNOWN;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void setGridData(List<Person> people) {
|
public void setGridData(List<Person> people) {
|
||||||
for (Person user : people) {
|
for (Person user : people) {
|
||||||
// Add the person as a root item
|
// Add the person as a root item
|
||||||
|
|
Loading…
Reference in a new issue