diff --git a/src/main/java/com/samic/samic/components/UIFactory.java b/src/main/java/com/samic/samic/components/UIFactory.java index c9edf39..c71c6c0 100644 --- a/src/main/java/com/samic/samic/components/UIFactory.java +++ b/src/main/java/com/samic/samic/components/UIFactory.java @@ -80,15 +80,6 @@ public static Button btnPrimary(String text, HashMap cssKeyValue return btnPrimary; } - public static Button btnPrimary( - String text, - ComponentEventListener> listener, - HashMap cssKeyValuePairs) { - Button btnPrimary = UIFactory.btnPrimary(text, cssKeyValuePairs); - btnPrimary.addClickListener(listener); - return btnPrimary; - } - public static Button btnPrimaryError(String text) { Button btnPrimary = new Button(text); btnPrimary.getStyle().setBackground("#FF3101").setColor("#FFFFFF"); @@ -140,7 +131,7 @@ public static Notification notificationInfoNoDuration(String text) { ///////////---------------------GridUtils≈---------------------/////////// public static VerticalLayout LazyComponent(SerializableSupplier component) { VerticalLayout container = UIFactory.rootComponentContainer(""); - + container.setHeightFull(); container.addAttachListener(e -> { if (container.getElement().getChildCount() == 1) { container.add(component.get()); diff --git a/src/main/java/com/samic/samic/components/form/UserForm.java b/src/main/java/com/samic/samic/components/form/UserForm.java index f59a37c..e6a7769 100644 --- a/src/main/java/com/samic/samic/components/form/UserForm.java +++ b/src/main/java/com/samic/samic/components/form/UserForm.java @@ -17,37 +17,53 @@ @Component @Scope("prototype") public class UserForm extends VerticalLayout { - private TextField mail = new TextField("Email"); - private PasswordField password = new PasswordField("Passwort"); - private PasswordField passwordConfirm = new PasswordField("Passwort bestätigen"); - private TextField surename = new TextField("Vorname"); - private TextField lastname = new TextField("Nachname"); - private TextField username = new TextField("Benutzername"); - private ComboBox role = new ComboBox<>("Rolle"); - private Binder binderUser = new Binder<>(User.class); + private final TextField mail = new TextField("Email"); + private final PasswordField password = new PasswordField("Passwort"); + private final PasswordField passwordConfirm = new PasswordField("Passwort bestätigen"); + private final TextField surname = new TextField("Vorname"); + private final TextField lastname = new TextField("Nachname"); + private final TextField username = new TextField("Benutzername"); + private final ComboBox role = new ComboBox<>("Rolle"); + + private final Binder binderUser = new Binder<>(User.class); @PostConstruct private void initUI() { - binderUser.forField(mail).asRequired().withValidator(new EmailValidator("Eingabe ist keine E-Mail")).bind(User::getMail, User::setMail); - binderUser.forField(password).asRequired().bind(User::getHashedPassword, User::setHashedPassword); - binderUser.forField(surename).asRequired().bind("profile.firstName"); + add( + UIFactory.childContainer(JustifyContentMode.BETWEEN, + role), + UIFactory.childContainer(JustifyContentMode.START, mail, password, passwordConfirm), + UIFactory.childContainer(JustifyContentMode.START, surname, lastname, username) + ); + + initBinder(); + initRolesComboBox(); + initRolesData(); + } + + private void initBinder() { + binderUser.forField(mail).asRequired() + .withValidator(new EmailValidator("Eingabe ist keine E-Mail")) + .bind(User::getMail, User::setMail); + binderUser.forField(password).asRequired() + .bind(User::getHashedPassword, User::setHashedPassword); + binderUser.forField(surname).asRequired().bind("profile.firstName"); binderUser.forField(lastname).asRequired().bind("profile.lastName"); binderUser.forField(username).bind("profile.username"); binderUser.forField(role).asRequired().bind(User::getRole, User::setRole); + } - role.setItems(Role.values()); + private void initRolesComboBox() { role.setItemLabelGenerator(Role::getLongVersion); role.setAllowCustomValue(false); role.setWidth("300px"); role.setRequired(true); - add( - UIFactory.childContainer(JustifyContentMode.BETWEEN, - role), - UIFactory.childContainer(JustifyContentMode.START,mail, password, passwordConfirm), - UIFactory.childContainer(JustifyContentMode.START,surename, lastname, username) - ); + } + + private void initRolesData() { + role.setItems(Role.values()); } public void setBean(User user) { @@ -58,7 +74,7 @@ public User saveBean() { return binderUser.getBean(); } - public Boolean isValid(){ + public Boolean isValid() { binderUser.validate(); return binderUser.isValid(); } @@ -70,5 +86,4 @@ public void clearFields() { } - } diff --git a/src/main/java/com/samic/samic/components/grid/ReservationGrid.java b/src/main/java/com/samic/samic/components/grid/ReservationGrid.java index 515f76e..75ea75d 100644 --- a/src/main/java/com/samic/samic/components/grid/ReservationGrid.java +++ b/src/main/java/com/samic/samic/components/grid/ReservationGrid.java @@ -14,7 +14,7 @@ public class ReservationGrid extends Grid { @PostConstruct private void initUI() { addColumn(r -> r.getStorageObject() != null ? r.getStorageObject().getId() : "" - ).setHeader("Lager ID"); + ).setHeader("LagerID"); addColumn(r -> r.getStorageObject().getObjectTypeName().getName()).setHeader( "Gerätetyp").setAutoWidth(true); addColumn(Reservation::getReservedDescription).setHeader("Beschreibung"); diff --git a/src/main/java/com/samic/samic/views/abfragen/AbfragenView.java b/src/main/java/com/samic/samic/views/abfragen/AbfragenView.java index 68a81a2..ccd0549 100644 --- a/src/main/java/com/samic/samic/views/abfragen/AbfragenView.java +++ b/src/main/java/com/samic/samic/views/abfragen/AbfragenView.java @@ -24,46 +24,35 @@ @PermitAll public class AbfragenView extends VerticalLayout { - private DatePicker dateFrom = new DatePicker("Von"); - private DatePicker dateTo = new DatePicker("Bis"); - - private RadioButtonGroup inOut = new RadioButtonGroup<>("Flussrichtung"); - - private ComboBox deviceType = new ComboBox("Gerätetyp"); - - private TextField usageAsProjectHardwareValue = new TextField(); - private TextField usagAsStandardHardware = new TextField(); - private TextField amountPrepared = new TextField(); - private TextField amountNew = new TextField(); - + private final DatePicker dateFrom = new DatePicker("Von"); + private final DatePicker dateTo = new DatePicker("Bis"); + private final RadioButtonGroup inOut = new RadioButtonGroup<>("Flussrichtung"); + private final ComboBox deviceType = new ComboBox<>("Gerätetyp"); + private final TextField usageAsProjectHardwareValue = new TextField(); + private final TextField usagAsStandardHardware = new TextField(); + private final TextField amountPrepared = new TextField(); + private final TextField amountNew = new TextField(); private final Binder statObjectBinder = new Binder<>(StatObject.class); - private final DataProviderAbfragen dataProviderAbfragen; - public AbfragenView(DataProviderAbfragen dataProviderAbfragen){ - this.dataProviderAbfragen = dataProviderAbfragen; + private static final List MONTH_NAMES = List.of("Januar", "Februar", "März", "April", + "Mai", + "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"); + private static final List WEEK_DAYS_NAMES = List.of + ("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"); + private static final List WEEK_DAYS_NAMES_SHORT = List.of("So", "Mo", "Di", "Mi", "Do", + "Fr", "Sa"); - statObjectBinder.forField(usagAsStandardHardware) - .withConverter(new StringToIntegerConverter("")) - .bind(StatObject::getAmountStandardHardware, null); - statObjectBinder.forField(usageAsProjectHardwareValue) - .withConverter(new StringToIntegerConverter("")) - .bind(StatObject::getAmountProjectHardware, null); - statObjectBinder.forField(amountNew) - .withConverter(new StringToIntegerConverter("")) - .bind(StatObject::getAmountnewHardware, null); - statObjectBinder.forField(amountPrepared) - .withConverter(new StringToIntegerConverter("")) - .bind(StatObject::getAmountPrepared, null); + public AbfragenView(DataProviderAbfragen dataProviderAbfragen) { + this.dataProviderAbfragen = dataProviderAbfragen; + initBinder(); initUI(); - }; + initActions(); + } private void initUI() { - dateFrom.addValueChangeListener(e -> dateFrom.setMin(e.getValue())); - dateTo.addValueChangeListener(e -> dateTo.setMin(e.getValue())); - usagAsStandardHardware.isReadOnly(); usageAsProjectHardwareValue.isReadOnly(); amountNew.isReadOnly(); @@ -77,15 +66,11 @@ private void initUI() { deviceType.setItemLabelGenerator(Type::getLongVersion); deviceType.setItems(Type.values()); - //Internationalization - DatePicker.DatePickerI18n germanI18n = new DatePickerI18n(); - germanI18n.setMonthNames(List.of("Januar", "Februar", "März", "April", "Mai", "Juni", - "Juli", "August", "September", "Oktober", "November", "Dezember")); - germanI18n.setWeekdays(List.of - ("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag")); - germanI18n.setWeekdaysShort(List.of("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa")); + germanI18n.setMonthNames(MONTH_NAMES); + germanI18n.setWeekdays(WEEK_DAYS_NAMES); + germanI18n.setWeekdaysShort(WEEK_DAYS_NAMES_SHORT); germanI18n.setFirstDayOfWeek(1); germanI18n.setDateFormat("dd.MM.yyyy"); @@ -94,24 +79,43 @@ private void initUI() { inOut.setItems("Rein", "Raus"); add(UIFactory.rootComponentContainer("", - UIFactory.childContainer(JustifyContentMode.START, - dateFrom, - dateTo, - inOut, - deviceType - )), + UIFactory.childContainer(JustifyContentMode.START, + dateFrom, + dateTo, + inOut, + deviceType + )), UIFactory.rootComponentContainer("", UIFactory.childContainer(JustifyContentMode.BETWEEN, new FormLayout(new Text("Verbr. als Projekthardware"), usageAsProjectHardwareValue), new FormLayout(new Text("Verbr. als Standard Hardware"), usagAsStandardHardware), new FormLayout(new Text("Anz. Aufbereitet"), amountPrepared), new FormLayout(new Text("Anz. Neu"), amountNew) - ) - )); - + ) + )); //Display dummy Object statObjectBinder.setBean(dataProviderAbfragen.getStatObject()); + } + + private void initActions() { + dateFrom.addValueChangeListener(e -> dateFrom.setMin(e.getValue())); + dateTo.addValueChangeListener(e -> dateTo.setMin(e.getValue())); + + } + private void initBinder() { + statObjectBinder.forField(usagAsStandardHardware) + .withConverter(new StringToIntegerConverter("")) + .bind(StatObject::getAmountStandardHardware, null); + statObjectBinder.forField(usageAsProjectHardwareValue) + .withConverter(new StringToIntegerConverter("")) + .bind(StatObject::getAmountProjectHardware, null); + statObjectBinder.forField(amountNew) + .withConverter(new StringToIntegerConverter("")) + .bind(StatObject::getAmountnewHardware, null); + statObjectBinder.forField(amountPrepared) + .withConverter(new StringToIntegerConverter("")) + .bind(StatObject::getAmountPrepared, null); } } diff --git a/src/main/java/com/samic/samic/views/administration/AdministrationView.java b/src/main/java/com/samic/samic/views/administration/AdministrationView.java index e37f88b..e40fa56 100644 --- a/src/main/java/com/samic/samic/views/administration/AdministrationView.java +++ b/src/main/java/com/samic/samic/views/administration/AdministrationView.java @@ -14,6 +14,7 @@ public class AdministrationView extends TabSheet { private final UserManagement userManagement; private final AppSettings appSettings; + public AdministrationView(UserManagement userManagement, AppSettings appSettings) { @@ -22,9 +23,9 @@ public AdministrationView(UserManagement userManagement, initUI(); } + public void initUI() { add("App Einstellungen", appSettings); add("Benutzerverwaltung", userManagement); - } } diff --git a/src/main/java/com/samic/samic/views/administration/AppSettings.java b/src/main/java/com/samic/samic/views/administration/AppSettings.java index 99e2a8d..88125b5 100644 --- a/src/main/java/com/samic/samic/views/administration/AppSettings.java +++ b/src/main/java/com/samic/samic/views/administration/AppSettings.java @@ -42,25 +42,36 @@ public AppSettings(DataProviderAdmin dataProvider, ServiceStorage storageService this.objectTypeService = objectTypeService1; this.notificationLimitForm = notificationLimitForm; this.storageForm = storageForm; + } - reservationMaxDuration.setRequired(true); - reservationMaxDuration.setValue(dataProvider.getReservationDuration()); - notificationLimitsGrid.setItems(objectTypeService.findAll().toList()); - notificationLimitsGrid.addColumn(ObjectType::getName); - //TODO add min field to ObjectType - //notificationLimitsGrid.addColumn(item -> "Min " + item.getMinAmount().toString()); - notificationLimitsGrid.getStyle().setBorder("0px"); - notificationLimitsGrid.setMaxHeight("200px"); - //notificationLimitsGrid.setWidthFull(); - notificationLimitsGrid.addThemeVariants(GridVariant.LUMO_NO_ROW_BORDERS); - notificationLimitsGrid.addComponentColumn(item -> new Span( - UIFactory.btnIconWithTooltip(LineAwesomeIcon.EDIT.create(), "Bearbeiten", - e -> onEdit(item)), - UIFactory.btnIconWithTooltip(LineAwesomeIcon.TRASH_SOLID.create(), "Löschen", - e -> onRemove(item)))).setFrozenToEnd(true); - storageGrid.setItems(storageService.findAll().toList()); + @PostConstruct + private void initUI() { + add( + UIFactory.childContainer(JustifyContentMode.START, + UIFactory.rootComponentContainer("Reservierungsdauer", + reservationMaxDuration, + UIFactory.btnPrimary("Speichern", e -> onSave(reservationMaxDuration.getValue())) + ), + UIFactory.rootComponentContainer("Benachrichtigungslimits", + UIFactory.childContainer(JustifyContentMode.START, + notificationLimitsGrid, + storageGrid + )), + UIFactory.rootComponentContainer("Lager bearbeiten", + UIFactory.childContainer(JustifyContentMode.START, + storageGrid))) + ); + initStorageGrid(); + initStorageGridData(); + initNotificationLimitsGrid(); + initNotificationLimitsGridData(); + initMaxDuration(); + initMaxDurationData(); + } + + private void initStorageGrid() { storageGrid.addColumn(Storage::getName); storageGrid.addColumn(storage -> storage.getAddress().getStreet()); storageGrid.addColumn(storage -> storage.getAddress().getHouseNo()); @@ -75,28 +86,37 @@ public AppSettings(DataProviderAdmin dataProvider, ServiceStorage storageService e -> onEdit(item)), UIFactory.btnIconWithTooltip(LineAwesomeIcon.TRASH_SOLID.create(), "Löschen", e -> onRemove(item))) : new Span("")).setFrozenToEnd(true); + } + + private void initStorageGridData() { + storageGrid.setItems(storageService.findAll().toList()); + } + private void initNotificationLimitsGrid() { + notificationLimitsGrid.addColumn(ObjectType::getName); + //TODO add min field to ObjectType + //notificationLimitsGrid.addColumn(item -> "Min " + item.getMinAmount().toString()); + notificationLimitsGrid.getStyle().setBorder("0px"); + notificationLimitsGrid.setMaxHeight("200px"); + //notificationLimitsGrid.setWidthFull(); + notificationLimitsGrid.addThemeVariants(GridVariant.LUMO_NO_ROW_BORDERS); + notificationLimitsGrid.addComponentColumn(item -> new Span( + UIFactory.btnIconWithTooltip(LineAwesomeIcon.EDIT.create(), "Bearbeiten", + e -> onEdit(item)), + UIFactory.btnIconWithTooltip(LineAwesomeIcon.TRASH_SOLID.create(), "Löschen", + e -> onRemove(item)))).setFrozenToEnd(true); + } + private void initNotificationLimitsGridData() { + notificationLimitsGrid.setItems(objectTypeService.findAll().toList()); } + private void initMaxDuration() { + reservationMaxDuration.setRequired(true); + } - @PostConstruct - private void initUI() { - add( - UIFactory.childContainer(JustifyContentMode.START, - UIFactory.rootComponentContainer("Reservierungsdauer", - reservationMaxDuration, - UIFactory.btnPrimary("Speichern", e -> onSave(reservationMaxDuration.getValue())) - ), - UIFactory.rootComponentContainer("Benachrichtigungslimits", - UIFactory.childContainer(JustifyContentMode.START, - notificationLimitsGrid, - storageGrid - )), - UIFactory.rootComponentContainer("Lager bearbeiten", - UIFactory.childContainer(JustifyContentMode.START, - storageGrid))) - ); + private void initMaxDurationData() { + reservationMaxDuration.setValue(dataProvider.getReservationDuration()); } private void onRemove(ObjectType item) { @@ -121,14 +141,13 @@ private void onEdit(ObjectType item) { UIFactory.childContainer( JustifyContentMode.START, UIFactory.btnPrimary("Speichern", e -> { - onSave(); + onSaveNotificationLimit(); dialog.close(); }), UIFactory.btnPrimaryError("Abbrechen", e -> dialog.close()) ) ) ); - dialog.open(); } @@ -155,7 +174,7 @@ private void onEdit(Storage item) { dialog.open(); } - private void onSave() { + private void onSaveNotificationLimit() { if (notificationLimitForm.isValid()) { objectTypeService.saveObjectTypeByObject(notificationLimitForm.saveBean()); UIFactory.notificationSuccess("Benachrichtigungslimit gespeichert").open(); @@ -175,7 +194,6 @@ private void onSave(Storage storage) { storageGrid.getDataProvider().refreshAll(); } - private void onSave(Integer value) { dataProvider.saveReservationDuration(value); reservationMaxDuration.setValue(dataProvider.getReservationDuration()); diff --git a/src/main/java/com/samic/samic/views/administration/UserManagement.java b/src/main/java/com/samic/samic/views/administration/UserManagement.java index 8ba21dd..cac0c22 100644 --- a/src/main/java/com/samic/samic/views/administration/UserManagement.java +++ b/src/main/java/com/samic/samic/views/administration/UserManagement.java @@ -30,70 +30,17 @@ public class UserManagement extends VerticalLayout { private final UserForm userForm; private final UserForm userFormDialog; VirtualList virtualList = new VirtualList<>(); - private final ComponentRenderer userComponentRenderer = - new ComponentRenderer<>( - user -> { - HorizontalLayout cardLayout = new HorizontalLayout(); - cardLayout.setMargin(true); - - Avatar avatar = new Avatar(user.getProfile().getFirstName() - + " " + user.getProfile().getLastName() - /*person.getPictureUrl()*/); - avatar.setHeight("64px"); - avatar.setWidth("64px"); - - VerticalLayout infoLayout = new VerticalLayout(); - infoLayout.setSpacing(false); - infoLayout.setPadding(false); - infoLayout.getElement().appendChild( - ElementFactory.createStrong(user.getProfile().getFirstName() - + " " + user.getProfile().getLastName())); - infoLayout.add(new Div( - UIFactory.btnIconWithTooltip(LineAwesomeIcon.BAN_SOLID.create(), "Deaktivieren", - e -> onDeactivate(user)), - UIFactory.btnIconWithTooltip(LineAwesomeIcon.TRASH_SOLID.create(), "Löschen", - e -> onDelete(user)), - UIFactory.btnIconWithTooltip(LineAwesomeIcon.EDIT.create(), "Bearbeiten", - e -> onEdit(user)) - )); - infoLayout.add(new Div(new Text(user.getRole().getLongVersion()))); - - VerticalLayout contactLayout = new VerticalLayout(); - contactLayout.setSpacing(false); - contactLayout.setPadding(false); - contactLayout.add(new Div(new Text(user.getMail()))); - String status = - (user.getActivated() != null && user.getActivated()) ? "Aktiviert" : "Deaktiviert"; - contactLayout - .add(new Div( - new Text("Registriert seit: " + DateTimeFormatter.ofPattern(DATE_PATTERN) - .format(user.getCreatedAt()))), - new Div(new Text("Letzer Login: " + DateTimeFormatter.ofPattern(DATE_PATTERN) - .format(user.getLastLogin()))), - new Div(new Text("Status: " + status))); - infoLayout - .add(new Details("Benutzereigenschaften", contactLayout)); - - cardLayout.add(avatar, infoLayout); - return cardLayout; - }); + private ComponentRenderer userComponentRenderer; public UserManagement(ServiceUser userService, UserForm userForm, UserForm userFormDialog) { this.userService = userService; this.userForm = userForm; this.userFormDialog = userFormDialog; - userForm.setBean(User.builder().profile(Profile.builder().build()).build()); } @PostConstruct private void initUI() { - virtualList.setItems(userService.findAll()); - virtualList.setRenderer(userComponentRenderer); - userForm.add( - UIFactory.childContainer(JustifyContentMode.START, - UIFactory.btnPrimary("Erstellen", e -> onCreate()), - UIFactory.btnPrimary("Abbrechen", e -> onCancel()))); add( UIFactory.childContainer(JustifyContentMode.START, UIFactory.rootComponentContainer("Benutzer anlegen", @@ -101,7 +48,81 @@ private void initUI() { UIFactory.rootComponentContainer("Benutzer", virtualList))); + initUserForm(); + initFormActions(); + initVirtualList(); + initVirtualListData(); + } + + private void initFormActions() { + userForm.add( + UIFactory.childContainer(JustifyContentMode.START, + UIFactory.btnPrimary("Erstellen", e -> onCreate()), + UIFactory.btnPrimary("Abbrechen", e -> onCancel()))); + } + + private void initUserForm() { + userForm.setBean(User.builder().profile(Profile.builder().build()).build()); + } + + private void initVirtualList() { + initComponentRenderer(); + virtualList.setRenderer(userComponentRenderer); + } + + private void initVirtualListData() { + virtualList.setItems(userService.findAll()); + } + private void initComponentRenderer() { + userComponentRenderer = + new ComponentRenderer<>( + user -> { + HorizontalLayout cardLayout = new HorizontalLayout(); + cardLayout.setMargin(true); + + Avatar avatar = new Avatar(user.getProfile().getFirstName() + + " " + user.getProfile().getLastName() + /*person.getPictureUrl()*/); + avatar.setHeight("64px"); + avatar.setWidth("64px"); + + VerticalLayout infoLayout = new VerticalLayout(); + infoLayout.setSpacing(false); + infoLayout.setPadding(false); + infoLayout.getElement().appendChild( + ElementFactory.createStrong(user.getProfile().getFirstName() + + " " + user.getProfile().getLastName())); + infoLayout.add(new Div( + UIFactory.btnIconWithTooltip(LineAwesomeIcon.BAN_SOLID.create(), "Deaktivieren", + e -> onDeactivate(user)), + UIFactory.btnIconWithTooltip(LineAwesomeIcon.TRASH_SOLID.create(), "Löschen", + e -> onDelete(user)), + UIFactory.btnIconWithTooltip(LineAwesomeIcon.EDIT.create(), "Bearbeiten", + e -> onEdit(user)) + )); + infoLayout.add(new Div(new Text(user.getRole().getLongVersion()))); + + VerticalLayout contactLayout = new VerticalLayout(); + contactLayout.setSpacing(false); + contactLayout.setPadding(false); + contactLayout.add(new Div(new Text(user.getMail()))); + String status = + (user.getActivated() != null && user.getActivated()) ? "Aktiviert" + : "Deaktiviert"; + contactLayout + .add(new Div( + new Text("Registriert seit: " + DateTimeFormatter.ofPattern(DATE_PATTERN) + .format(user.getCreatedAt()))), + new Div(new Text("Letzer Login: " + DateTimeFormatter.ofPattern(DATE_PATTERN) + .format(user.getLastLogin()))), + new Div(new Text("Status: " + status))); + infoLayout + .add(new Details("Benutzereigenschaften", contactLayout)); + + cardLayout.add(avatar, infoLayout); + return cardLayout; + }); } private void onCancel() { diff --git a/src/main/java/com/samic/samic/views/freie_lagerobjekte/FreieLagerobjekteView.java b/src/main/java/com/samic/samic/views/freie_lagerobjekte/FreieLagerobjekteView.java index 81fd5b3..f0a21e7 100644 --- a/src/main/java/com/samic/samic/views/freie_lagerobjekte/FreieLagerobjekteView.java +++ b/src/main/java/com/samic/samic/views/freie_lagerobjekte/FreieLagerobjekteView.java @@ -41,14 +41,12 @@ public class FreieLagerobjekteView extends VerticalLayout { private final ComboBox filterObjectType = new ComboBox<>(); private final Dialog reservationDialog = new Dialog(); private final Grid grid = new Grid<>(StorageObject.class, false); - private final ServiceStorageObject storageObjectService; private final ServiceObjectType objectTypeService; private final AuthenticatedUser authenticatedUser; private final ServiceStorage storageService; private final ReservationForm reservationForm; private final ServiceReservation reservationService; - private StorageObject storageObjectToSave; @@ -71,14 +69,73 @@ private void initUI() { reservationDialog.add( UIFactory.rootComponentContainer("Gerät reservieren", reservationForm, UIFactory.childContainer(JustifyContentMode.START, - UIFactory.btnPrimary("Reservieren", onClick -> reserve()), + UIFactory.btnPrimary("Reservieren", onClick -> onReserve()), UIFactory.btnPrimaryError("Abbrechen", onClick -> onCancel()))) ); + + add( + UIFactory.rootComponentContainer("", + UIFactory.childContainer( + JustifyContentMode.START, + searchField, + filterStorage, + filterObjectType + )), + UIFactory.rootComponentContainerFullHeight("", + UIFactory.childContainerFullHeight( + JustifyContentMode.START, + grid)), + reservationDialog); + + initSearchField(); + initFilterStorage(); + initGrid(); + initGridData(); + initFilterObjectType(); + initValueChangeListeners(); + } + + private void initValueChangeListeners() { + searchField.addValueChangeListener( + e -> listFilteredStorageObjects(e.getValue(), filterStorage.getValue() + .getId())); + filterStorage.addValueChangeListener( + e -> listFilteredStorageObjects(searchField.getValue(), e.getValue().getId())); + } + + private void initFilterObjectType() { + filterObjectType.setItemLabelGenerator(ObjectType::getName); + filterObjectType.setPlaceholder("Gerätetyp auswählen"); + filterObjectType.setWidth("250px"); + initFilterObjectTypeData(); + } + + private void initFilterObjectTypeData() { + filterObjectType.setItems(objectTypeService.findAll().toList()); + } + + private void initSearchField() { searchField.setWidth("20%"); searchField.setPlaceholder("Suchen..."); searchField.setPrefixComponent(new Icon(VaadinIcon.SEARCH)); searchField.setValueChangeMode(ValueChangeMode.EAGER); + } + + private void initFilterStorage() { + initFilterStorageData(); + filterStorage.setItemLabelGenerator(Storage::getName); + filterStorage.setAllowCustomValue(false); + filterStorage.setValue(filterStorage.getListDataView() + .getItem(0)); + filterStorage.setPlaceholder("Lager auswählen"); + } + + private void initFilterStorageData() { + filterStorage.setItems(storageService.findAll().toList()); + } + + private void initGrid() { grid.addColumn(StorageObject::getId).setHeader("Lager ID").setAutoWidth(true).setFlexGrow(0); grid.addColumn(so -> so.getObjectTypeName() != null ? so.getObjectTypeName().getName() : so.getSupply().getDescription()).setHeader("Gerätetyp").setAutoWidth(true) @@ -92,43 +149,10 @@ private void initUI() { .setAutoWidth(true).setFrozenToEnd(true); grid.setItemDetailsRenderer(createStorageObjectDetailsRenderer()); grid.getStyle().setBorder("0px"); - grid.setHeightFull(); - - setHeightFull(); - - filterStorage.setItemLabelGenerator(Storage::getName); - filterStorage.setItems(storageService.findAll().toList()); - filterStorage.setAllowCustomValue(false); - filterStorage.setValue(filterStorage.getListDataView() - .getItem(0)); - filterStorage.setPlaceholder("Lager auswählen"); - - filterObjectType.setItemLabelGenerator(ObjectType::getName); - filterObjectType.setItems(objectTypeService.findAll().toList()); - filterObjectType.setPlaceholder("Gerätetyp auswählen"); - filterObjectType.setWidth("250px"); + } + private void initGridData() { listFilteredStorageObjects("%", filterStorage.getValue().getId()); - - searchField.addValueChangeListener( - e -> listFilteredStorageObjects(e.getValue(), filterStorage.getValue() - .getId())); - filterStorage.addValueChangeListener( - e -> listFilteredStorageObjects(searchField.getValue(), e.getValue().getId())); - - add( - UIFactory.rootComponentContainer("", - UIFactory.childContainer( - JustifyContentMode.START, - searchField, - filterStorage, - filterObjectType - )), - UIFactory.rootComponentContainerFullHeight("", - UIFactory.childContainerFullHeight( - JustifyContentMode.START, - grid)), - reservationDialog); } private void listFilteredStorageObjects(String filterString, Long storageId) { @@ -143,7 +167,7 @@ private void onCancel() { this.storageObjectToSave = null; } - private void reserve() { + private void onReserve() { Reservation reservationToSave = reservationForm.save(); reservationToSave.setReservedFrom(authenticatedUser.getUser().get()); @@ -164,7 +188,6 @@ private ComponentRenderer createStorage StorageObjectDetailsForm::setStorageObject); } - private void openReservationForm(StorageObject storageObject) { this.storageObjectToSave = storageObject; reservationForm.setBean( diff --git a/src/main/java/com/samic/samic/views/lagerobjekt_erfassen/LagerobjektErfassenView.java b/src/main/java/com/samic/samic/views/lagerobjekt_erfassen/LagerobjektErfassenView.java index 619c12a..0274dc9 100644 --- a/src/main/java/com/samic/samic/views/lagerobjekt_erfassen/LagerobjektErfassenView.java +++ b/src/main/java/com/samic/samic/views/lagerobjekt_erfassen/LagerobjektErfassenView.java @@ -34,8 +34,7 @@ @PageTitle("Lagerobjekt erfassen") @Route(value = "lagerobjektErfassen", layout = MainLayout.class) @PermitAll -public class LagerobjektErfassenView extends VerticalLayout implements BeforeLeaveObserver { - +public class LagerobjektErfassenView extends VerticalLayout { private final ServiceProducer producerService; private final ServiceStorage storageService; @@ -43,25 +42,19 @@ public class LagerobjektErfassenView extends VerticalLayout implements BeforeLea private final CPEForm cpeForm; private final SFPForm sfpForm; private final SupplyForm supplyForm; - - private final ServiceLagerObjectErfassen lagerObjectErfassenService; - private final ServiceProducer getProducerService; - - HorizontalLayout formChildContainer = UIFactory.childContainer(JustifyContentMode.START); - ComboBox storageComboBox; - ComboBox typeComboBox = new ComboBox<>("Typ auswählen"); - - ComboBox producerSelect = new ComboBox<>("Hersteller"); - private VerticalLayout storageContainer; + private final HorizontalLayout formChildContainer = UIFactory.childContainer( + JustifyContentMode.START); + private final ComboBox storageComboBox = new ComboBox<>("Lager auswählen"); + private final ComboBox typeComboBox = new ComboBox<>("Typ auswählen"); + private final ComboBox producerSelect = new ComboBox<>("Hersteller"); public LagerobjektErfassenView(ServiceStorageObject storageObjectService, ServiceProducer producerService, ServiceStorage storageService, ServiceObjectType serviceObjectType, CPEForm cpeForm, SFPForm sfpForm, - SupplyForm supplyForm, ServiceLagerObjectErfassen lagerObjectErfassenService, - ServiceProducer getProducerService) { + SupplyForm supplyForm, ServiceLagerObjectErfassen lagerObjectErfassenService) { this.producerService = producerService; this.storageService = storageService; @@ -70,37 +63,15 @@ public LagerobjektErfassenView(ServiceStorageObject storageObjectService, this.sfpForm = sfpForm; this.supplyForm = supplyForm; this.lagerObjectErfassenService = lagerObjectErfassenService; - this.getProducerService = getProducerService; initUI(); } private void initUI() { - List producers = producerService.findAll().toList(); - producerSelect.setItemLabelGenerator(Producer::getName); - producerSelect.setItems(producers); - - storageComboBox = new ComboBox<>("Lager auswählen"); - List storages = storageService.findAll().toList(); - storageComboBox.setItems(storages); - storageComboBox.setItemLabelGenerator(Storage::getName); - storageComboBox.setValue(storages.get(0)); - - typeComboBox.setItems(Type.class.getEnumConstants()); - typeComboBox.setRequired(true); - typeComboBox.setItemLabelGenerator(Type::getLongVersion); - typeComboBox.addValueChangeListener( - event -> changeForm(event.getValue(), storageComboBox.getValue())); - - Stream.of(producerSelect, typeComboBox, storageComboBox).forEach(i -> { - i.setRequired(true); - i.setAllowCustomValue(false); - }); - this.storageContainer = + add( UIFactory.rootComponentContainer( "", - UIFactory.childContainer(JustifyContentMode.START, storageComboBox)); - add(storageContainer); + UIFactory.childContainer(JustifyContentMode.START, storageComboBox))); VerticalLayout formRootContainer = UIFactory.rootComponentContainer( @@ -117,6 +88,50 @@ private void initUI() { UIFactory.btnPrimaryError("Abbrechen", buttonClickEvent -> onCancel()))); add(formRootContainer); + + initProducerSelect(); + initProducerSelectData(); + initStorageComboBox(); + initStorageComboBoxData(); + initTypeComoBox(); + initTypeComboBoxData(); + } + + private void initTypeComoBox() { + typeComboBox.setRequired(true); + typeComboBox.setItemLabelGenerator(Type::getLongVersion); + typeComboBox.addValueChangeListener( + event -> changeForm(event.getValue(), storageComboBox.getValue())); + typeComboBox.setRequired(true); + typeComboBox.setAllowCustomValue(false); + } + + private void initTypeComboBoxData() { + typeComboBox.setItems(Type.class.getEnumConstants()); + } + + private void initStorageComboBox() { + storageComboBox.setItemLabelGenerator(Storage::getName); + storageComboBox.setRequired(true); + storageComboBox.setAllowCustomValue(false); + } + + private void initStorageComboBoxData() { + List storages = + storageService.findAll().filter(storage -> !storage.getName().equals("Kunde")).toList(); + + storageComboBox.setItems(storages); + storageComboBox.setValue(storages.get(0)); + } + + private void initProducerSelect() { + producerSelect.setRequired(true); + producerSelect.setAllowCustomValue(false); + producerSelect.setItemLabelGenerator(Producer::getName); + } + + private void initProducerSelectData() { + producerSelect.setItems(producerService.findAll().toList()); } private void changeForm(Type value, Storage storage) { @@ -209,9 +224,4 @@ private void onSave(Type selectedType, Storage value, Producer producer) { } changeForm(selectedType, value); } - - @Override - public void beforeLeave(BeforeLeaveEvent beforeLeaveEvent) { - //storageObjectService.deleteStorageObjectById(storageObject.getId()); - } } diff --git a/src/main/java/com/samic/samic/views/meine_hardware/MeineHardwareView.java b/src/main/java/com/samic/samic/views/meine_hardware/MeineHardwareView.java index 612e1d9..d42b571 100644 --- a/src/main/java/com/samic/samic/views/meine_hardware/MeineHardwareView.java +++ b/src/main/java/com/samic/samic/views/meine_hardware/MeineHardwareView.java @@ -32,7 +32,6 @@ @PermitAll public class MeineHardwareView extends TabSheet { - private final ReservationGrid reservationGrid; private final ServiceStorageObject storageObjectService; private final ServiceStorage storageService; @@ -40,7 +39,6 @@ public class MeineHardwareView extends TabSheet { private final StorageObjectGrid storageObjectGrid; private final ServiceReservation reservationService; private final AuthenticatedUser authenticatedUser; - private final CPEForm cpeForm; private final SFPForm sfpForm; private final SupplyForm supplyForm; @@ -66,32 +64,49 @@ public MeineHardwareView(ServiceStorage storageService, ReservationGrid reservat private void initUI() { + setHeightFull(); add("Meine Hardware", UIFactory.LazyComponent( - () -> { - storageObjectGrid.setItems( - storageObjectService.findStorageObjectByGivenUser(authenticatedUser.getUser().get()) - .toList()); - storageObjectGrid.addComponentColumn(item -> new Span( - UIFactory.btnIconWithTooltip(LineAwesomeIcon.TRUCK_MOVING_SOLID.create(), - "Ins Lager verschieben", e -> moveToStorage(item)), - UIFactory.btnIconWithTooltip(LineAwesomeIcon.EDIT_SOLID.create(), "Bearbeiten", - e -> onEdit(item)))); - return this.storageObjectGrid; - })); - + () -> storageObjectGrid)); add( "Meine Reservierungen", UIFactory.LazyComponent( - () -> { - reservationGrid.setItems( - reservationService.findAllReservationByGivenUser(authenticatedUser.getUser() - .get()).toList()); - reservationGrid.addComponentColumn(item -> new Span( - UIFactory.btnIconWithTooltip(LineAwesomeIcon.TRASH_SOLID.create(), "Löschen", - e -> onDelete(item)), - UIFactory.btnIconWithTooltip(LineAwesomeIcon.EDIT.create(), "Bearbeiten", - e -> onEdit(item)))); - return this.reservationGrid; - })); + () -> reservationGrid)); + + initStorageObjectGrid(); + initStorageObjectGridData(); + initReservationGrid(); + initReservationGridData(); + } + + private void initReservationGrid() { + reservationGrid.addComponentColumn(item -> new Span( + UIFactory.btnIconWithTooltip(LineAwesomeIcon.TRASH_SOLID.create(), "Löschen", + e -> onDelete(item)), + UIFactory.btnIconWithTooltip(LineAwesomeIcon.EDIT.create(), "Bearbeiten", + e -> onEdit(item)))); + } + + private void initReservationGridData() { + //TODO backend needs to make sure that no connection exception is thrown + // (cut off stream from repository), or make repo return list + //TODO reservation does not contain storageobject + + // reservationGrid.setItems( + // reservationService.findAllReservationByGivenUser(authenticatedUser.getUser() + // .get()).toList()); + } + + private void initStorageObjectGrid() { + storageObjectGrid.addComponentColumn(item -> new Span( + UIFactory.btnIconWithTooltip(LineAwesomeIcon.TRUCK_MOVING_SOLID.create(), + "Ins Lager verschieben", e -> moveToStorage(item)), + UIFactory.btnIconWithTooltip(LineAwesomeIcon.EDIT_SOLID.create(), "Bearbeiten", + e -> onEdit(item)))); + } + + private void initStorageObjectGridData() { + storageObjectGrid.setItems( + storageObjectService.findStorageObjectByGivenUser(authenticatedUser.getUser().get()) + .toList()); } private void onEdit(StorageObject item) {