diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/EventDetails.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/EventDetails.java new file mode 100644 index 0000000..7fac5e8 --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/EventDetails.java @@ -0,0 +1,67 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; + +import com.vaadin.navigator.Navigator; +import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.GridLayout; + +import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.SingleEventView; + +public class EventDetails extends GridLayout implements NamedView { + + public static final String VIEW_NAME = "EventDetails"; + private static final long serialVersionUID = 8290150079638390995L; + + private final EventBusiness eventBusiness; + private final PersonDao personDao; + private final GroupDao groupDao; + + private Person loggedinPerson; + private ClubEvent currentEvent; + private SingleEventView eventView; + private PersonGrid personGrid; + + public EventDetails(PersonDao personDao, GroupDao groupDao, EventBusiness eventBusiness) { + super(3, 5); + this.eventBusiness = eventBusiness; + this.personDao = personDao; + this.groupDao = groupDao; + } + + @Override + public void enter(ViewChangeEvent event) { + Navigator navigator = event.getNavigator(); + loggedinPerson = (Person) getSession().getAttribute(Person.SESSION_LOGIN); + currentEvent = eventBusiness.getCurrent(); + + eventView = new SingleEventView(); + eventView.setEvent(currentEvent); + + personGrid = new PersonGrid(groupDao, personDao); + personGrid.setEvent(currentEvent); + personGrid.setSelectedOnly(); + personGrid.hideFilter(); + personGrid.setSelectionMode(SelectionMode.NONE); + + Button back = new Button("Zurück"); + back.addClickListener(ev -> navigator.navigateTo(((NamedView) event.getOldView()).getViewName())); + + addComponent(eventView, 0, 0, 1, 0); + addComponent(personGrid, 0, 1, 1, 1); + addComponent(back, 1, 4); + setSizeFull(); + } + + @Override + public String getViewName() { + return VIEW_NAME; + } + +} diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/HeadView.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/HeadView.java index 25fd999..d3ce39e 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/HeadView.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/HeadView.java @@ -10,6 +10,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Supplier; @@ -20,6 +21,7 @@ import org.slf4j.LoggerFactory; import com.vaadin.contextmenu.ContextMenu; import com.vaadin.icons.VaadinIcons; import com.vaadin.server.StreamResource; +import com.vaadin.server.VaadinSession; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Alignment; import com.vaadin.ui.BrowserFrame; @@ -32,6 +34,7 @@ import com.vaadin.ui.Notification; import com.vaadin.ui.Window; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; import de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper.CalendarCreator; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent.ClubEventProvider; @@ -55,6 +58,10 @@ public class HeadView extends HorizontalLayout { private int monthItemId; + private Label personLabel; + + private Person loggedinPerson; + public HeadView(Supplier startTime, Supplier endTime, ClubEventProvider dataProvider) { @@ -68,11 +75,16 @@ public class HeadView extends HorizontalLayout { popupButton.addClickListener(ev -> openPopupMenu(ev)); popupButton.setWidth(null); + personLabel = new Label(); + personLabel.setStyleName("title_caption"); + this.addComponent(popupButton); this.addComponent(monthName); + this.addComponent(personLabel); setComponentAlignment(popupButton, Alignment.MIDDLE_LEFT); setComponentAlignment(monthName, Alignment.MIDDLE_CENTER); + setComponentAlignment(personLabel, Alignment.MIDDLE_RIGHT); setExpandRatio(monthName, 1.0f); setSizeFull(); @@ -82,6 +94,16 @@ public class HeadView extends HorizontalLayout { this.dataProvider = dataProvider; } + public void updateLoggedinPerson() { + + loggedinPerson = (Person) getSession().getAttribute(Person.SESSION_LOGIN); + if (loggedinPerson != null) { + personLabel.setCaption(loggedinPerson.getSurname() + ", " + loggedinPerson.getPrename()); + } else { + personLabel.setCaption(""); + } + } + public void updateMonthText(ZonedDateTime startDate) { String monthValue = dfMonth.format(startDate); log.debug("Changed Month title to {}", monthValue); @@ -91,16 +113,30 @@ public class HeadView extends HorizontalLayout { private void openPopupMenu(ClickEvent ev) { Button button = ev.getButton(); - Person loggedinPerson = (Person) getSession().getAttribute(Person.SESSION_LOGIN); + VaadinSession session = getSession(); + Person loggedinPerson = (Person) session.getAttribute(Person.SESSION_LOGIN); ContextMenu contextMenu = new ContextMenu(button, true); monthItemId = contextMenu.addItem("Export Monat", ev1 -> calendarExport(ev1)).getId(); contextMenu.addItem("Export Jahr", ev1 -> calendarExport(ev1)); if (loggedinPerson != null) { - contextMenu.addItem("Personen verwalten", ev1 -> switchToPersonEditUi()); + Set groups = loggedinPerson.getGroups(); + if (contains(groups, "ADMIN") || contains(groups, "Übungsleiter")) { + contextMenu.addItem("Personen verwalten", ev1 -> switchToPersonEditUi()); + } + contextMenu.addItem("Abmelden", ev1 -> session.setAttribute(Person.SESSION_LOGIN, null)); } contextMenu.open(50, 50); } + public boolean contains(Set groups, String name) { + for (GroupDef g : groups) { + if (g.getName().toLowerCase().contentEquals(name.toLowerCase())) { + return true; + } + } + return false; + } + private void switchToPersonEditUi() { } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java index 03e3e06..4e30648 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java @@ -1,7 +1,6 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; import com.vaadin.navigator.Navigator; -import com.vaadin.navigator.View; import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; import com.vaadin.ui.Alignment; import com.vaadin.ui.LoginForm; @@ -11,7 +10,7 @@ import com.vaadin.ui.VerticalLayout; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; -public class LoginUI extends VerticalLayout implements View { +public class LoginUI extends VerticalLayout implements NamedView { private static final long serialVersionUID = 4339018452507960084L; public static final String VIEW_NAME = "LoginUI"; @@ -45,8 +44,12 @@ public class LoginUI extends VerticalLayout implements View { @Override public void enter(ViewChangeEvent event) { - View.super.enter(event); navigator = event.getNavigator(); parameters = event.getParameters(); } + + @Override + public String getViewName() { + return VIEW_NAME; + } } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java index 4fcc57e..ef1b32c 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java @@ -42,13 +42,13 @@ public class MainUi extends UI { getPage().setTitle("Vereinshelfer"); - // Create a navigator to control the views Navigator navigator = new Navigator(this, this); // Create and register the views navigator.addView(MainView.VIEW_NAME, new MainView(personDao, groupDao, eventBusiness)); navigator.addView(LoginUI.VIEW_NAME, new LoginUI(personDao)); navigator.addView(PersonEditView.VIEW_NAME, new PersonEditView(groupDao, personDao)); + navigator.addView(EventDetails.VIEW_NAME, new EventDetails(personDao, groupDao, eventBusiness)); navigator.navigateTo(MainView.VIEW_NAME); } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainView.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainView.java index 50a1993..0b63a82 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainView.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainView.java @@ -12,8 +12,9 @@ import org.vaadin.addon.calendar.ui.CalendarComponentEvents; import com.vaadin.event.selection.SelectionEvent; import com.vaadin.navigator.Navigator; -import com.vaadin.navigator.View; import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; +import com.vaadin.ui.Button; +import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; @@ -27,7 +28,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarCompone import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.SingleEventView; -public class MainView extends BorderLayout implements View { +public class MainView extends BorderLayout implements NamedView { public static final String VIEW_NAME = ""; @@ -48,6 +49,8 @@ public class MainView extends BorderLayout implements View { private SingleEventView eventView; + private HorizontalLayout eventButtonLayout; + public MainView(PersonDao personDao, GroupDao groupDao, EventBusiness eventBusiness) { this.personDao = personDao; this.groupDao = groupDao; @@ -56,20 +59,21 @@ public class MainView extends BorderLayout implements View { @Override public void enter(ViewChangeEvent event) { - View.super.enter(event); if (this.navigator == null) { - initUI(event); LOGGER.info("Loaded UI and started fetch of Events"); } else { loggedinPerson = (Person) getSession().getAttribute(Person.SESSION_LOGIN); + if (loggedinPerson != null) { LOGGER.info("{} already initialized - opening Person View.", getClass().getName()); openPersonViewForEvent(eventBusiness.getCurrent()); calendar.setToday(eventBusiness.getCurrent().getStart()); + head.updateLoggedinPerson(); } else { LOGGER.info("{} already initialized - but not loggedin.", getClass().getName()); + head.updateLoggedinPerson(); } } } @@ -82,15 +86,30 @@ public class MainView extends BorderLayout implements View { personGrid = new PersonGrid(groupDao, personDao); personGrid.setCaption("Personen"); - personGrid.onClosedFunction(() -> detailClosed()); personGrid.onPersonSelect(ev -> personSelectionChange(ev)); personGrid.setVisible(false); + Button close = new Button("Schließen", ev -> { + detailClosed(); + }); + close.setId("person.close"); + + Button eventDetails = new Button("Veranstaltung Details", ev -> { + navigator.navigateTo(EventDetails.VIEW_NAME); + }); + eventDetails.setId("person.eventDetails"); + + eventButtonLayout = new HorizontalLayout(); + eventButtonLayout.setSpacing(true); + eventButtonLayout.addComponents(close, eventDetails); + eventButtonLayout.setVisible(false); + VerticalLayout eastLayout = new VerticalLayout(); - eastLayout.addComponents(eventView, personGrid); + eastLayout.addComponents(eventView, personGrid, eventButtonLayout); ClubEventProvider dataProvider = new ClubEventProvider(); calendar = new CalendarComponent(dataProvider); + calendar.setSizeFull(); calendar.setId("main.calendar"); calendar.setHandler(this::onItemClick); @@ -128,6 +147,7 @@ public class MainView extends BorderLayout implements View { LOGGER.debug("Closing detail view."); personGrid.setVisible(false); eventView.setVisible(false); + eventButtonLayout.setVisible(false); } private void onItemClick(CalendarComponentEvents.ItemClickEvent event) { @@ -155,8 +175,14 @@ public class MainView extends BorderLayout implements View { personGrid.setVisible(true); eventView.setVisible(true); + eventButtonLayout.setVisible(true); eventBusiness.setSelected(ev); } + @Override + public String getViewName() { + return VIEW_NAME; + } + } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/NamedView.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/NamedView.java new file mode 100644 index 0000000..c2c6cba --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/NamedView.java @@ -0,0 +1,12 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; + +import com.vaadin.navigator.View; + +public interface NamedView extends View { + /** + * Navigation view name used for this view. + * + * @return view name. + */ + String getViewName(); +} diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/PersonEditView.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/PersonEditView.java index 961cb16..ba8f38a 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/PersonEditView.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/PersonEditView.java @@ -1,6 +1,5 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; -import com.vaadin.navigator.View; import com.vaadin.ui.HorizontalLayout; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao; @@ -9,7 +8,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonEditDialog; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid; -public class PersonEditView extends HorizontalLayout implements View { +public class PersonEditView extends HorizontalLayout implements NamedView { public static final String VIEW_NAME = "PersonEditView"; private static final long serialVersionUID = 1770993670570422036L; @@ -31,4 +30,9 @@ public class PersonEditView extends HorizontalLayout implements View { getUI().addWindow(dlg); } + @Override + public String getViewName() { + return VIEW_NAME; + } + } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilter.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilter.java index 59a036c..3e99c64 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilter.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilter.java @@ -97,7 +97,9 @@ public class PersonFilter implements SerializablePredicate, DataProvider @Override public void onDataChange(DataChangeEvent event) { publishedList.clear(); - publishedList.addAll(personDao.listAll().stream().filter(this).collect(Collectors.toList())); + List listAll = personDao.listAll(); + List filtered = listAll.stream().filter(this).collect(Collectors.toList()); + publishedList.addAll(filtered); updateHandler.fireUpdateEvent(); } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java index 5291a57..161bda9 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java @@ -26,6 +26,7 @@ import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Layout; import com.vaadin.ui.MultiSelect; import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.components.grid.GridSelectionModel; import com.vaadin.ui.themes.ValoTheme; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao; @@ -47,7 +48,6 @@ public class PersonGrid extends VerticalLayout { private final CheckBox checkIncluded; private final ComboBox comboGroups; - private transient ClosedFunction closedFunction = null; private transient Consumer onPersonEdit; private Boolean selectedOnlyFilter; @@ -57,6 +57,7 @@ public class PersonGrid extends VerticalLayout { private ClubEvent currentEvent; private Column startpassColumn; private Column editButtonColumn; + private Layout filters; public PersonGrid(GroupDao groupDao, PersonDao personDao) { @@ -66,7 +67,7 @@ public class PersonGrid extends VerticalLayout { checkIncluded = new CheckBox("Nur gemeldete"); comboGroups = new ComboBox<>("Gruppenfilter"); - Layout filters = setupFilterComponents(); + filters = setupFilterComponents(); allGroups = groupDao.listAll(); comboGroups.setItems(allGroups); @@ -78,16 +79,8 @@ public class PersonGrid extends VerticalLayout { setupPersonGrid(personDao); - Button close = new Button("Schließen", ev -> { - PersonGrid.this.setVisible(false); - if (closedFunction != null) { - closedFunction.closed(); - } - }); - close.setId("person.close"); - setMargin(false); - addComponents(filters, grid, close); + addComponents(filters, grid); } public void setupPersonGrid(PersonDao personDao) { @@ -98,17 +91,23 @@ public class PersonGrid extends VerticalLayout { grid.setDataProvider(dataProvider); grid.setId("person.grid"); + setSelectionMode(SelectionMode.MULTI); + grid.setSizeFull(); + grid.addColumn(Person::getPrename).setCaption("Vorname"); grid.addColumn(Person::getSurname).setCaption("Nachname"); grid.addColumn(Person::getBirth, b -> b != null ? birthFormat.format(b) : "").setCaption("Geburtstag"); + startpassColumn = grid.addColumn(Person::getStartpass).setCaption("Startpass Nr."); editButtonColumn = grid.addComponentColumn(this::buildPersonEditButton); - grid.setSelectionMode(SelectionMode.MULTI); - startpassColumn.setHidden(false); editButtonColumn.setHidden(true); } + public GridSelectionModel setSelectionMode(SelectionMode selectionMode) { + return grid.setSelectionMode(selectionMode); + } + private Layout setupFilterComponents() { checkIncluded.setId("person.filter.checked"); checkIncluded.addValueChangeListener(ev -> onSelectedOnly(ev)); @@ -131,21 +130,26 @@ public class PersonGrid extends VerticalLayout { return button; } + public void hideFilter() { + filters.setVisible(false); + } + private void showPersonDetails(Person p) { if (onPersonEdit != null) { onPersonEdit.accept(p); } } - public void onClosedFunction(ClosedFunction closedFunction) { - this.closedFunction = closedFunction; - } - private void onSelectedOnly(ValueChangeEvent ev) { this.selectedOnlyFilter = ev.getValue(); updateFilter(); } + public void setSelectedOnly() { + this.selectedOnlyFilter = true; + updateFilter(); + } + private void updateFilter() { if (selectedOnlyFilter != null && selectedOnlyFilter.equals(Boolean.TRUE)) { filter.setSelectedPersons(grid.getSelectedItems()); @@ -154,7 +158,6 @@ public class PersonGrid extends VerticalLayout { } filter.setSelectedGroups(groupMemberFilter); - dataProvider.refreshAll(); } @@ -198,10 +201,6 @@ public class PersonGrid extends VerticalLayout { updateFilter(); } - public interface ClosedFunction { - void closed(); - } - public void onPersonEdit(Consumer function) { this.onPersonEdit = function; startpassColumn.setHidden(true); @@ -216,6 +215,7 @@ public class PersonGrid extends VerticalLayout { selectItems(new Person[0]); } this.currentEvent = ev; +// updateFilter(); } public void updateSelection(ClubEvent ev) {