feat: events

This commit is contained in:
Filippo Ferrari 2024-06-15 22:21:53 +02:00
parent 5ec3fef8fd
commit 8369ed6439
6 changed files with 51 additions and 7 deletions

23
frontend/index.html Normal file
View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<!--
This file is auto-generated by Vaadin.
-->
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body, #outlet {
height: 100vh;
width: 100%;
margin: 0;
}
</style>
<!-- index.ts is included here automatically (either by the dev server or during the build) -->
</head>
<body>
<!-- This outlet div is where the views are rendered -->
<div id="outlet"></div>
</body>
</html>

View file

@ -5,6 +5,8 @@ import jakarta.validation.constraints.Size;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.Set;
@Entity @Entity
@Getter @Getter
@Setter @Setter
@ -22,4 +24,11 @@ public class Event {
@Size(max = 100) @Size(max = 100)
@Column(name = "Description") @Column(name = "Description")
private String 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") @ManyToMany(mappedBy = "debtors")
private Set<Expense> debtorExpenses; private Set<Expense> debtorExpenses;
@ManyToMany(mappedBy = "participants")
private Set<Event> events;
} }

View file

@ -1,11 +1,14 @@
package com.application.munera.views.expenses; package com.application.munera.views.expenses;
import com.application.munera.data.Event; import com.application.munera.data.Event;
import com.application.munera.data.Person;
import com.application.munera.services.EventService; import com.application.munera.services.EventService;
import com.application.munera.services.PersonService;
import com.application.munera.views.MainLayout; import com.application.munera.views.MainLayout;
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;
import com.vaadin.flow.component.combobox.MultiSelectComboBox;
import com.vaadin.flow.component.dependency.Uses; import com.vaadin.flow.component.dependency.Uses;
import com.vaadin.flow.component.formlayout.FormLayout; import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.grid.Grid;
@ -48,11 +51,14 @@ public class EventsView extends Div implements BeforeEnterObserver {
private Event event; private Event event;
private final EventService eventService; private final EventService eventService;
private final PersonService personService;
private TextField name; private TextField name;
private TextArea description; private TextArea description;
private MultiSelectComboBox<Person> participants;
public EventsView(EventService eventService) { public EventsView(EventService eventService, PersonService personService) {
this.eventService = eventService; this.eventService = eventService;
this.personService = personService;
addClassNames("events-view"); addClassNames("events-view");
// Create UI // Create UI
@ -162,7 +168,10 @@ public class EventsView extends Div implements BeforeEnterObserver {
FormLayout formLayout = new FormLayout(); FormLayout formLayout = new FormLayout();
name = new TextField("Name"); name = new TextField("Name");
description = new TextArea("Description"); 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); editorDiv.add(formLayout);
createButtonLayout(editorLayoutDiv); 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::getPeriodInterval).setHeader("Period Interval").setSortable(true);
grid.addColumn(Expense::getPeriodUnit).setHeader("Period Unit").setSortable(true); grid.addColumn(Expense::getPeriodUnit).setHeader("Period Unit").setSortable(true);
grid.addColumn(Expense::getDate).setHeader("Date").setSortable(true).setSortProperty("date"); 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.getColumns().forEach(col -> col.setAutoWidth(true));
grid.setItems(query -> expenseService.list( grid.setItems(query -> expenseService.list(
@ -216,12 +216,12 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
creditors = new MultiSelectComboBox<>("Creditors"); creditors = new MultiSelectComboBox<>("Creditors");
creditors.setItems(personService.findAll()); creditors.setItems(personService.findAll());
creditors.setItemLabelGenerator(Person::getFirstName); creditors.setItemLabelGenerator(Person::getFirstName);
debtors = new MultiSelectComboBox<>("Debtors");
debtors.setItems(personService.findAll());
debtors.setItemLabelGenerator(Person::getFirstName);
event = new ComboBox<>("Event"); event = new ComboBox<>("Event");
event.setItems(eventService.findAll()); event.setItems(eventService.findAll());
event.setItemLabelGenerator(Event::getName); event.setItemLabelGenerator(Event::getName);
debtors = new MultiSelectComboBox<>("Debtors");
debtors.setItems(personService.findAll());
debtors.setItemLabelGenerator(Person::getFirstName);
date = new DatePicker("Date"); date = new DatePicker("Date");
LitRenderer<Expense> isPeriodicRenderer = LitRenderer.<Expense>of( 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>") "<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 spring.mustache.check-template-location = false
# Launch the default browser when starting the application in development mode # Launch the default browser when starting the application in development mode
vaadin.launch-browser=true #vaadin.launch-browser=true
# PostgreSQL configuration. # PostgreSQL configuration.
spring.datasource.url = jdbc:postgresql://localhost:5432/munera_vaadin spring.datasource.url = jdbc:postgresql://localhost:5432/munera_vaadin
spring.datasource.username = postgres spring.datasource.username = postgres