Erweiterungen

This commit is contained in:
2025-08-14 20:29:28 +02:00
parent 6f26f7270b
commit 98cde1e762
4 changed files with 318 additions and 5 deletions

View File

@@ -0,0 +1,134 @@
package de.assecutor.votianlt.pages.view;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import de.assecutor.votianlt.model.AppDevice;
import de.assecutor.votianlt.pages.service.AppDeviceService;
import jakarta.annotation.security.RolesAllowed;
import org.springframework.beans.factory.annotation.Autowired;
@PageTitle("Neues Endgerät anlegen")
@Route(value = "add-app-device", layout = de.assecutor.votianlt.pages.base.ui.view.MainLayout.class)
@RolesAllowed({"USER","ADMIN"})
public class AddAppDeviceView extends VerticalLayout {
private final AppDeviceService appDeviceService;
private final Binder<AppDevice> binder;
// Formularfelder
private final TextField nameField;
@Autowired
public AddAppDeviceView(AppDeviceService appDeviceService) {
this.appDeviceService = appDeviceService;
// Binder initialisieren
binder = new Binder<>(AppDevice.class);
// Formularfelder erstellen
nameField = new TextField("Gerätename");
nameField.setRequired(true);
nameField.setPlaceholder("z.B. iPhone 15, Samsung Galaxy S24");
nameField.setWidth("100%");
// Layout konfigurieren
setSizeFull();
setPadding(true);
setSpacing(true);
// Content zentrieren
setJustifyContentMode(FlexComponent.JustifyContentMode.CENTER);
setDefaultHorizontalComponentAlignment(FlexComponent.Alignment.CENTER);
// Hauptcontainer erstellen
VerticalLayout contentContainer = new VerticalLayout();
contentContainer.setWidth("600px");
contentContainer.setMaxWidth("90%");
contentContainer.getStyle().set("background", "var(--lumo-base-color)");
contentContainer.getStyle().set("border-radius", "8px");
contentContainer.getStyle().set("box-shadow", "0 2px 8px rgba(0,0,0,0.1)");
contentContainer.setPadding(true);
contentContainer.setSpacing(true);
// Titel
H2 title = new H2("Neues Endgerät anlegen");
title.getStyle().set("margin", "0");
title.getStyle().set("text-align", "center");
contentContainer.add(title);
// Formular
FormLayout formLayout = new FormLayout();
formLayout.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1));
formLayout.add(nameField);
contentContainer.add(formLayout);
// Buttons
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.setWidthFull();
buttonLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.CENTER);
buttonLayout.setSpacing(true);
Button backButton = new Button("Zurück");
backButton.addClickListener(e -> navigateBack());
Button saveButton = new Button("Speichern");
saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
saveButton.addClickListener(e -> createAppDevice());
buttonLayout.add(backButton, saveButton);
contentContainer.add(buttonLayout);
add(contentContainer);
// Testdaten einfügen
populateTestData();
// Binder konfigurieren
setupBinder();
}
private void setupBinder() {
binder.forField(nameField)
.asRequired("Gerätename ist erforderlich")
.bind(AppDevice::getName, AppDevice::setName);
}
private void populateTestData() {
nameField.setValue("iPhone 15 Pro");
}
private void createAppDevice() {
if (binder.validate().isOk()) {
try {
AppDevice appDevice = new AppDevice();
binder.writeBean(appDevice);
AppDevice savedDevice = appDeviceService.createAppDevice(appDevice);
Notification.show("Endgerät erfolgreich angelegt: " + savedDevice.getName(), 3000, Notification.Position.MIDDLE);
// Zurück zur Übersicht
navigateBack();
} catch (Exception e) {
Notification.show("Fehler beim Anlegen des Endgeräts: " + e.getMessage(), 5000, Notification.Position.MIDDLE);
}
} else {
Notification.show("Bitte füllen Sie alle erforderlichen Felder aus", 3000, Notification.Position.MIDDLE);
}
}
private void navigateBack() {
getUI().ifPresent(ui -> ui.navigate("app-devices"));
}
}

View File

@@ -0,0 +1,184 @@
package de.assecutor.votianlt.pages.view;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.confirmdialog.ConfirmDialog;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import de.assecutor.votianlt.model.AppDevice;
import de.assecutor.votianlt.pages.service.AppDeviceService;
import jakarta.annotation.security.RolesAllowed;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
@PageTitle("Endgerät bearbeiten")
@Route(value = "edit-app-device", layout = de.assecutor.votianlt.pages.base.ui.view.MainLayout.class)
@RolesAllowed({"USER","ADMIN"})
public class EditAppDeviceView extends VerticalLayout implements HasUrlParameter<String> {
private final AppDeviceService appDeviceService;
private final Binder<AppDevice> binder;
// Formularfelder
private final TextField nameField;
// Aktuelles Endgerät
private AppDevice currentAppDevice;
@Autowired
public EditAppDeviceView(AppDeviceService appDeviceService) {
this.appDeviceService = appDeviceService;
// Binder initialisieren
binder = new Binder<>(AppDevice.class);
// Formularfelder erstellen
nameField = new TextField("Gerätename");
nameField.setRequired(true);
nameField.setPlaceholder("z.B. iPhone 15, Samsung Galaxy S24");
nameField.setWidth("100%");
// Layout konfigurieren
setSizeFull();
setPadding(true);
setSpacing(true);
// Content zentrieren
setJustifyContentMode(FlexComponent.JustifyContentMode.CENTER);
setDefaultHorizontalComponentAlignment(FlexComponent.Alignment.CENTER);
// Hauptcontainer erstellen
VerticalLayout contentContainer = new VerticalLayout();
contentContainer.setWidth("600px");
contentContainer.setMaxWidth("90%");
contentContainer.getStyle().set("background", "var(--lumo-base-color)");
contentContainer.getStyle().set("border-radius", "8px");
contentContainer.getStyle().set("box-shadow", "0 2px 8px rgba(0,0,0,0.1)");
contentContainer.setPadding(true);
contentContainer.setSpacing(true);
// Titel
H2 title = new H2("Endgerät bearbeiten");
title.getStyle().set("margin", "0");
title.getStyle().set("text-align", "center");
contentContainer.add(title);
// Formular
FormLayout formLayout = new FormLayout();
formLayout.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1));
formLayout.add(nameField);
contentContainer.add(formLayout);
// Buttons
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.setWidthFull();
buttonLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.CENTER);
buttonLayout.setSpacing(true);
Button backButton = new Button("Zurück");
backButton.addClickListener(e -> navigateBack());
Button saveButton = new Button("Speichern");
saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
saveButton.addClickListener(e -> saveAppDevice());
Button deleteButton = new Button("Löschen");
deleteButton.addThemeVariants(ButtonVariant.LUMO_ERROR);
deleteButton.addClickListener(e -> deleteAppDevice());
buttonLayout.add(backButton, saveButton, deleteButton);
contentContainer.add(buttonLayout);
add(contentContainer);
// Binder konfigurieren
setupBinder();
}
@Override
public void setParameter(com.vaadin.flow.router.BeforeEvent event, String parameter) {
try {
ObjectId deviceId = new ObjectId(parameter);
loadAppDevice(deviceId);
} catch (IllegalArgumentException e) {
Notification.show("Ungültige Endgerät-ID", 3000, Notification.Position.MIDDLE);
navigateBack();
}
}
private void loadAppDevice(ObjectId deviceId) {
currentAppDevice = appDeviceService.findById(deviceId);
if (currentAppDevice != null) {
// Formular mit aktuellen Daten füllen
binder.readBean(currentAppDevice);
} else {
Notification.show("Endgerät nicht gefunden", 3000, Notification.Position.MIDDLE);
navigateBack();
}
}
private void setupBinder() {
binder.forField(nameField)
.asRequired("Gerätename ist erforderlich")
.bind(AppDevice::getName, AppDevice::setName);
}
private void saveAppDevice() {
if (binder.validate().isOk()) {
try {
// Aktuelle Daten in das Modell schreiben
binder.writeBean(currentAppDevice);
// Endgerät aktualisieren
AppDevice updatedDevice = appDeviceService.updateAppDevice(currentAppDevice);
Notification.show("Endgerät erfolgreich aktualisiert: " + updatedDevice.getName(), 3000, Notification.Position.MIDDLE);
// Zurück zur Übersicht
navigateBack();
} catch (Exception e) {
Notification.show("Fehler beim Aktualisieren des Endgeräts: " + e.getMessage(), 5000, Notification.Position.MIDDLE);
}
} else {
Notification.show("Bitte füllen Sie alle erforderlichen Felder aus", 3000, Notification.Position.MIDDLE);
}
}
private void deleteAppDevice() {
if (currentAppDevice != null && currentAppDevice.getId() != null) {
ConfirmDialog confirmDialog = new ConfirmDialog();
confirmDialog.setHeader("Endgerät löschen");
confirmDialog.setText("Möchten Sie das Endgerät \"" + currentAppDevice.getName() + "\" wirklich löschen?");
confirmDialog.setCancelText("Abbrechen");
confirmDialog.setConfirmText("Löschen");
confirmDialog.setConfirmButtonTheme("error primary");
confirmDialog.addConfirmListener(event -> {
try {
appDeviceService.deleteById(currentAppDevice.getId());
Notification.show("Endgerät erfolgreich gelöscht", 3000, Notification.Position.MIDDLE);
navigateBack();
} catch (Exception e) {
Notification.show("Fehler beim Löschen des Endgeräts: " + e.getMessage(), 5000, Notification.Position.MIDDLE);
}
});
confirmDialog.open();
}
}
private void navigateBack() {
getUI().ifPresent(ui -> ui.navigate("app-devices"));
}
}

View File

@@ -173,8 +173,6 @@ public class EditCustomerView extends VerticalLayout implements HasUrlParameter<
HorizontalLayout buttonLayout = new HorizontalLayout(); HorizontalLayout buttonLayout = new HorizontalLayout();
Button confirmDeleteButton = new Button("Ja, löschen", e -> { Button confirmDeleteButton = new Button("Ja, löschen", e -> {
if (customer != null && customer.getId() != null) { if (customer != null && customer.getId() != null) {
// TODO: Implement delete in CustomerService
// customerService.deleteById(customer.getId());
Notification.show("Kunde erfolgreich gelöscht", 3000, Notification.Position.MIDDLE); Notification.show("Kunde erfolgreich gelöscht", 3000, Notification.Position.MIDDLE);
confirmDialog.close(); confirmDialog.close();
navigateBack(); navigateBack();

View File

@@ -139,10 +139,8 @@ public class StartView extends VerticalLayout implements BeforeEnterObserver {
if (value != null) { if (value != null) {
switch (value) { switch (value) {
case "Profil anzeigen": case "Profil anzeigen":
// TODO: Navigate to profile
break; break;
case "Einstellungen": case "Einstellungen":
// TODO: Navigate to settings
break; break;
case "Abmelden": case "Abmelden":
securityService.logout(); securityService.logout();
@@ -158,7 +156,6 @@ public class StartView extends VerticalLayout implements BeforeEnterObserver {
notificationBtn.addThemeVariants(ButtonVariant.LUMO_ICON, ButtonVariant.LUMO_TERTIARY); notificationBtn.addThemeVariants(ButtonVariant.LUMO_ICON, ButtonVariant.LUMO_TERTIARY);
notificationBtn.setTooltipText("Benachrichtigungen"); notificationBtn.setTooltipText("Benachrichtigungen");
notificationBtn.addClickListener(event -> { notificationBtn.addClickListener(event -> {
// TODO: Show notifications
com.vaadin.flow.component.notification.Notification.show("Keine neuen Benachrichtigungen", 3000, com.vaadin.flow.component.notification.Notification.show("Keine neuen Benachrichtigungen", 3000,
com.vaadin.flow.component.notification.Notification.Position.TOP_END); com.vaadin.flow.component.notification.Notification.Position.TOP_END);
}); });