Merge remote-tracking branch 'origin/main'

This commit is contained in:
filippo-ferrari 2024-06-18 21:55:51 +02:00
commit 02e81b4b63
5 changed files with 28 additions and 7 deletions

View file

@ -5,6 +5,8 @@ import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import java.util.Set;
@Entity
@Getter
@Setter
@ -22,4 +24,11 @@ public class Event {
@Size(max = 100)
@Column(name = "Description")
private String description;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "Event_participants",
joinColumns = @JoinColumn(name = "event_id"),
inverseJoinColumns = @JoinColumn(name = "participant_id"))
private Set<Person> participants;
}

View file

@ -44,4 +44,7 @@ public class Person {
@ManyToMany(mappedBy = "debtors")
private Set<Expense> debtorExpenses;
@ManyToMany(mappedBy = "participants")
private Set<Event> events;
}

View file

@ -1,11 +1,14 @@
package com.application.munera.views.expenses;
import com.application.munera.data.Event;
import com.application.munera.data.Person;
import com.application.munera.services.EventService;
import com.application.munera.services.PersonService;
import com.application.munera.views.MainLayout;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.combobox.MultiSelectComboBox;
import com.vaadin.flow.component.dependency.Uses;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid;
@ -48,11 +51,14 @@ public class EventsView extends Div implements BeforeEnterObserver {
private Event event;
private final EventService eventService;
private final PersonService personService;
private TextField name;
private TextArea description;
private MultiSelectComboBox<Person> participants;
public EventsView(EventService eventService) {
public EventsView(EventService eventService, PersonService personService) {
this.eventService = eventService;
this.personService = personService;
addClassNames("events-view");
// Create UI
@ -162,7 +168,10 @@ public class EventsView extends Div implements BeforeEnterObserver {
FormLayout formLayout = new FormLayout();
name = new TextField("Name");
description = new TextArea("Description");
formLayout.add(name, description);
participants = new MultiSelectComboBox<>("Participants");
participants.setItems(personService.findAll());
participants.setItemLabelGenerator(Person::getFirstName);
formLayout.add(name, description, participants);
editorDiv.add(formLayout);
createButtonLayout(editorLayoutDiv);

View file

@ -91,7 +91,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
grid.addColumn(Expense::getPeriodInterval).setHeader("Period Interval").setSortable(true);
grid.addColumn(Expense::getPeriodUnit).setHeader("Period Unit").setSortable(true);
grid.addColumn(Expense::getDate).setHeader("Date").setSortable(true).setSortProperty("date");
grid.addColumn(expenseEvent -> expenseEvent.getEvent().getName()).setHeader("Event").setSortable(true);
// grid.addColumn(expenseEvent -> expenseEvent.getEvent().getName()).setHeader("Event").setSortable(true);
grid.getColumns().forEach(col -> col.setAutoWidth(true));
grid.setItems(query -> expenseService.list(
@ -216,12 +216,12 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
creditors = new MultiSelectComboBox<>("Creditors");
creditors.setItems(personService.findAll());
creditors.setItemLabelGenerator(Person::getFirstName);
debtors = new MultiSelectComboBox<>("Debtors");
debtors.setItems(personService.findAll());
debtors.setItemLabelGenerator(Person::getFirstName);
event = new ComboBox<>("Event");
event.setItems(eventService.findAll());
event.setItemLabelGenerator(Event::getName);
debtors = new MultiSelectComboBox<>("Debtors");
debtors.setItems(personService.findAll());
debtors.setItemLabelGenerator(Person::getFirstName);
date = new DatePicker("Date");
LitRenderer<Expense> isPeriodicRenderer = LitRenderer.<Expense>of(
"<vaadin-icon icon='vaadin:${item.icon}' style='width: var(--lumo-icon-size-s); height: var(--lumo-icon-size-s); color: ${item.color};'></vaadin-icon>")

View file

@ -3,7 +3,7 @@ logging.level.org.atmosphere = warn
spring.mustache.check-template-location = false
# Launch the default browser when starting the application in development mode
vaadin.launch-browser=true
#vaadin.launch-browser=true
# PostgreSQL configuration.
spring.datasource.url = jdbc:postgresql://localhost:5432/munera_vaadin
spring.datasource.username = postgres