-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add LagerobjektaufnehmenView, fix LagerobjekteErfassenView objekt lös…
…chen beim verlassen der seite wenn nicht gespeichert werden soll
- Loading branch information
1 parent
8b63e0b
commit 2aa88f8
Showing
3 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/com/samic/samic/views/lagerobjekt_aufnehmen/LagerobjektAufnehmenView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.samic.samic.views.lagerobjekt_aufnehmen; | ||
|
||
import com.samic.samic.components.UIFactory; | ||
import com.samic.samic.data.entity.StorageObject; | ||
import com.samic.samic.security.AuthenticatedUser; | ||
import com.samic.samic.services.ServiceStorageObject; | ||
import com.samic.samic.services.ServiceUser; | ||
import com.samic.samic.views.MainLayout; | ||
import com.vaadin.flow.component.UI; | ||
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.data.converter.StringToLongConverter; | ||
import com.vaadin.flow.router.PageTitle; | ||
import com.vaadin.flow.router.Route; | ||
import jakarta.annotation.security.PermitAll; | ||
import java.util.NoSuchElementException; | ||
|
||
|
||
@PageTitle("Lagerobjekt aufnehmen") | ||
@Route(value = "lagerobjektAufnehmen", layout = MainLayout.class) | ||
@PermitAll | ||
public class LagerobjektAufnehmenView extends VerticalLayout { | ||
|
||
private final ServiceStorageObject storageObjectService; | ||
private StorageObject storageObject; | ||
private final TextField storageObjectID = new TextField("Lager ID"); | ||
private final Binder<StorageObject> binderStorageObject = new Binder<>(StorageObject.class, true); | ||
private final AuthenticatedUser authenticatedUser; | ||
private final ServiceUser userService; | ||
|
||
|
||
LagerobjektAufnehmenView(ServiceStorageObject storageObjectService, AuthenticatedUser authenticatedUser, ServiceUser userService) { | ||
this.storageObjectService = storageObjectService; | ||
this.authenticatedUser = authenticatedUser; | ||
this.userService = userService; | ||
initUI(); | ||
} | ||
|
||
private void initBinder() { | ||
binderStorageObject.forField(storageObjectID).asRequired("Lager ID muss augefüllt werden").withConverter( | ||
new StringToLongConverter("Id is not Long")).bind(StorageObject::getId, null); | ||
binderStorageObject.setBean(storageObject); | ||
} | ||
|
||
private void initUI() { | ||
add(UIFactory.rootComponentContainer("", | ||
UIFactory.childContainer(JustifyContentMode.START, storageObjectID), | ||
UIFactory.childContainer(JustifyContentMode.END, | ||
UIFactory.btnPrimary("Aufnehmen", event -> onSave()), | ||
UIFactory.btnPrimaryError("Abbrechen", event -> onCancel())))); | ||
} | ||
|
||
private void onCancel() { | ||
UI.getCurrent().getPage().reload(); | ||
} | ||
|
||
private void onSave() { | ||
try { | ||
var toEdit = storageObjectService.findStorageObjectById(Long.valueOf(storageObjectID.getValue())); | ||
if (toEdit != null) { | ||
if (toEdit.getStoredAtUser() == null) { | ||
toEdit.setStoredAtUser(authenticatedUser.getUser().orElse(userService.findUserByID(authenticatedUser.getUser().get().getId()))); | ||
toEdit.setStorage(null); | ||
storageObjectService.saveStorageObject(toEdit); | ||
storageObjectID.setValue(""); | ||
UIFactory.NotificationSuccess("Lagerobjekt wurde aufgenommen").open(); | ||
} else { | ||
UIFactory.NotificationError("Lagerobjekt von jemandem aufgenommen worden").open(); | ||
} | ||
} | ||
} catch (NoSuchElementException e) { | ||
UIFactory.NotificationError("Konnte nicht aufgenommen werden, da das Lagerobjekt nicht existiert").open(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters