|
|
@@ -1,8 +1,14 @@
|
|
|
|
package de.thpeetz.kontor.comics.views;
|
|
|
|
package de.thpeetz.kontor.comics.views;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.vaadin.flow.component.button.ButtonVariant;
|
|
|
|
|
|
|
|
import com.vaadin.flow.component.contextmenu.ContextMenu;
|
|
|
|
|
|
|
|
import com.vaadin.flow.component.contextmenu.MenuItem;
|
|
|
|
|
|
|
|
import com.vaadin.flow.component.icon.Icon;
|
|
|
|
|
|
|
|
import com.vaadin.flow.component.icon.VaadinIcon;
|
|
|
|
|
|
|
|
import de.thpeetz.kontor.admin.data.MetaDataColumn;
|
|
|
|
|
|
|
|
import de.thpeetz.kontor.admin.services.MetaDataService;
|
|
|
|
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
|
|
|
|
|
|
|
|
|
import com.vaadin.flow.component.Component;
|
|
|
|
import com.vaadin.flow.component.Component;
|
|
|
@@ -22,6 +28,8 @@ import de.thpeetz.kontor.comics.services.ComicService;
|
|
|
|
import de.thpeetz.kontor.common.views.MainLayout;
|
|
|
|
import de.thpeetz.kontor.common.views.MainLayout;
|
|
|
|
import jakarta.annotation.security.PermitAll;
|
|
|
|
import jakarta.annotation.security.PermitAll;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
@SpringComponent
|
|
|
|
@SpringComponent
|
|
|
|
@Scope("prototype")
|
|
|
|
@Scope("prototype")
|
|
|
@@ -30,11 +38,45 @@ import jakarta.annotation.security.PermitAll;
|
|
|
|
@PageTitle("Comic | Comics | Kontor")
|
|
|
|
@PageTitle("Comic | Comics | Kontor")
|
|
|
|
public class ComicView extends VerticalLayout {
|
|
|
|
public class ComicView extends VerticalLayout {
|
|
|
|
|
|
|
|
|
|
|
|
Grid<Comic> grid = new Grid<>(Comic.class);
|
|
|
|
@Getter
|
|
|
|
|
|
|
|
Grid<Comic> grid = new Grid<>(Comic.class, false);
|
|
|
|
|
|
|
|
Grid.Column<Comic> idColumn = grid.addColumn(Comic::getId)
|
|
|
|
|
|
|
|
.setHeader("ID").setResizable(true).setSortable(true);
|
|
|
|
|
|
|
|
Grid.Column<Comic> createdColumn = grid.addColumn(Comic::getCreatedDate)
|
|
|
|
|
|
|
|
.setHeader("Erstellt").setResizable(true).setSortable(true);
|
|
|
|
|
|
|
|
Grid.Column<Comic> modifiedColumn = grid.addColumn(Comic::getLastModifiedDate)
|
|
|
|
|
|
|
|
.setHeader("Geändert").setResizable(true).setSortable(true);
|
|
|
|
|
|
|
|
Grid.Column<Comic> titleColumn = grid.addColumn(Comic::getTitle)
|
|
|
|
|
|
|
|
.setHeader("Titel").setResizable(true).setSortable(true);
|
|
|
|
|
|
|
|
Grid.Column<Comic> publisherColumn = grid.addColumn(Comic::getPublisherName)
|
|
|
|
|
|
|
|
.setHeader("Verlag").setResizable(true).setSortable(true);
|
|
|
|
|
|
|
|
Grid.Column<Comic> currentOrderColumn = grid.addComponentColumn(comic -> createStatusIcon(comic.getCurrentOrder()))
|
|
|
|
|
|
|
|
.setHeader("Bestellung").setWidth("6rem").setSortable(true);
|
|
|
|
|
|
|
|
Grid.Column<Comic> completedColumn = grid.addComponentColumn(comic -> createStatusIcon(comic.getCompleted()))
|
|
|
|
|
|
|
|
.setHeader("Abgeschlossen").setWidth("6rem").setSortable(true);
|
|
|
|
TextField filterText = new TextField();
|
|
|
|
TextField filterText = new TextField();
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
ComicForm form;
|
|
|
|
ComicForm form;
|
|
|
|
ComicService service;
|
|
|
|
ComicService service;
|
|
|
|
|
|
|
|
MetaDataService metaDataService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class ColumnToggleContextMenu extends ContextMenu {
|
|
|
|
|
|
|
|
public ColumnToggleContextMenu(Component target) {
|
|
|
|
|
|
|
|
super(target);
|
|
|
|
|
|
|
|
setOpenOnClick(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void addColumnToggleItem(String label, Grid.Column<Comic> column) {
|
|
|
|
|
|
|
|
MenuItem menuItem = this.addItem(label, e -> {
|
|
|
|
|
|
|
|
column.setVisible(e.getSource().isChecked());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
menuItem.setCheckable(true);
|
|
|
|
|
|
|
|
menuItem.setChecked(column.isVisible());
|
|
|
|
|
|
|
|
menuItem.setKeepOpen(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ComicView(ComicService service) {
|
|
|
|
public ComicView(ComicService service) {
|
|
|
|
this.service = service;
|
|
|
|
this.service = service;
|
|
|
|
addClassName("comic-view");
|
|
|
|
addClassName("comic-view");
|
|
|
@@ -46,22 +88,13 @@ public class ComicView extends VerticalLayout {
|
|
|
|
updateList();
|
|
|
|
updateList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Grid<Comic> getGrid() {
|
|
|
|
|
|
|
|
return grid;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void configureGrid() {
|
|
|
|
private void configureGrid() {
|
|
|
|
grid.addClassName("comic-grid");
|
|
|
|
grid.addClassName("comic-grid");
|
|
|
|
grid.setSizeFull();
|
|
|
|
grid.setSizeFull();
|
|
|
|
grid.setColumns("title", "publisher.name", "currentOrder", "completed");
|
|
|
|
|
|
|
|
grid.getColumns().forEach(col -> col.setAutoWidth(true));
|
|
|
|
grid.getColumns().forEach(col -> col.setAutoWidth(true));
|
|
|
|
grid.asSingleSelect().addValueChangeListener(event -> editComic(event.getValue()));
|
|
|
|
grid.asSingleSelect().addValueChangeListener(event -> editComic(event.getValue()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ComicForm getForm() {
|
|
|
|
|
|
|
|
return form;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void configureForm() {
|
|
|
|
private void configureForm() {
|
|
|
|
form = new ComicForm(service.findAllPublishers(null));
|
|
|
|
form = new ComicForm(service.findAllPublishers(null));
|
|
|
|
form.setWidth("25em");
|
|
|
|
form.setWidth("25em");
|
|
|
@@ -71,6 +104,19 @@ public class ComicView extends VerticalLayout {
|
|
|
|
form.addCloseListener(e -> closeEditor());
|
|
|
|
form.addCloseListener(e -> closeEditor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Icon createStatusIcon(boolean status) {
|
|
|
|
|
|
|
|
Icon icon;
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
|
|
|
|
icon = VaadinIcon.CHECK.create();
|
|
|
|
|
|
|
|
icon.getElement().getThemeList().add("badge success");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
icon = VaadinIcon.CLOSE_SMALL.create();
|
|
|
|
|
|
|
|
icon.getElement().getThemeList().add("badge error");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
icon.getStyle().set("padding", "var(--lumo-space-xs");
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void saveComic(ComicForm.SaveEvent event) {
|
|
|
|
private void saveComic(ComicForm.SaveEvent event) {
|
|
|
|
service.saveComic(event.getComic());
|
|
|
|
service.saveComic(event.getComic());
|
|
|
|
updateList();
|
|
|
|
updateList();
|
|
|
@@ -95,13 +141,24 @@ public class ComicView extends VerticalLayout {
|
|
|
|
private HorizontalLayout getToolbar() {
|
|
|
|
private HorizontalLayout getToolbar() {
|
|
|
|
filterText.setPlaceholder("Filter by name...");
|
|
|
|
filterText.setPlaceholder("Filter by name...");
|
|
|
|
filterText.setClearButtonVisible(true);
|
|
|
|
filterText.setClearButtonVisible(true);
|
|
|
|
|
|
|
|
filterText.setPrefixComponent(new Icon(VaadinIcon.SEARCH));
|
|
|
|
filterText.setValueChangeMode(ValueChangeMode.LAZY);
|
|
|
|
filterText.setValueChangeMode(ValueChangeMode.LAZY);
|
|
|
|
filterText.addValueChangeListener(e -> updateList());
|
|
|
|
filterText.addValueChangeListener(e -> updateList());
|
|
|
|
|
|
|
|
|
|
|
|
Button addComicButton = new Button("Add comic");
|
|
|
|
Button addComicButton = new Button("Add comic");
|
|
|
|
addComicButton.addClickListener(click -> addComic());
|
|
|
|
addComicButton.addClickListener(click -> addComic());
|
|
|
|
|
|
|
|
|
|
|
|
HorizontalLayout toolbar = new HorizontalLayout(filterText, addComicButton);
|
|
|
|
Button menuButton = new Button("Show/Hide Columns");
|
|
|
|
|
|
|
|
menuButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
|
|
|
|
|
|
|
|
ColumnToggleContextMenu columnToggleContextMenu = new ColumnToggleContextMenu(menuButton);
|
|
|
|
|
|
|
|
columnToggleContextMenu.addColumnToggleItem("ID", idColumn);
|
|
|
|
|
|
|
|
columnToggleContextMenu.addColumnToggleItem("Erstellt", createdColumn);
|
|
|
|
|
|
|
|
columnToggleContextMenu.addColumnToggleItem("Geändert", modifiedColumn);
|
|
|
|
|
|
|
|
columnToggleContextMenu.addColumnToggleItem("Titel", titleColumn);
|
|
|
|
|
|
|
|
columnToggleContextMenu.addColumnToggleItem("Verlag", publisherColumn);
|
|
|
|
|
|
|
|
columnToggleContextMenu.addColumnToggleItem(currentOrderColumn.getHeaderText(), currentOrderColumn);
|
|
|
|
|
|
|
|
columnToggleContextMenu.addColumnToggleItem(completedColumn.getHeaderText(), completedColumn);
|
|
|
|
|
|
|
|
HorizontalLayout toolbar = new HorizontalLayout(filterText, addComicButton, menuButton);
|
|
|
|
toolbar.addClassName("toolbar");
|
|
|
|
toolbar.addClassName("toolbar");
|
|
|
|
return toolbar;
|
|
|
|
return toolbar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|