diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index cca56f8..c8dc029 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -234,6 +234,7 @@ public class MainController { vBox.getChildren().add(btnHBox); Label nameLabel = new Label(event.getName()); + nameLabel.setWrapText(true); vBox.getChildren().add(nameLabel); if (event.getStart() != null || event.getEnd() != null) { @@ -251,6 +252,7 @@ public class MainController { if (event.isFullDay()) { Label fullDayLabel = new Label("Dieser Termin bockiert den ganzen Tag!"); + fullDayLabel.setWrapText(true); vBox.getChildren().add(fullDayLabel); } diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index bca3c9f..2e82e48 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -17,12 +17,15 @@ import javafx.stage.Modality; import javafx.stage.Stage; import container.DataController; import container.User; +import users.EditUserController; +import java.awt.*; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Consumer; public class OptionController { @@ -68,11 +71,20 @@ public class OptionController { } public void onCreateBtnClick(ActionEvent actionEvent) { - loadUserScene(actionEvent, "User erstellen", "../users/create-user.fxml"); + loadUserScene(actionEvent, "User erstellen", "../users/create-user.fxml", null); } public void onUpdateBtnClick(ActionEvent actionEvent) { - loadUserScene(actionEvent, "User bearbeiten", "../users/edit-user.fxml"); + int editIndex = comboBox.getSelectionModel().getSelectedIndex(); + + if(editIndex < 0 || editIndex >= users.size()) return; + + FXMLLoader fxmlLoader = loadUserScene( + actionEvent, + "User bearbeiten", + "../users/edit-user.fxml", + this::setUserAtController + ); } public void onDeleteBtnClick(ActionEvent actionEvent) { @@ -92,12 +104,11 @@ public class OptionController { } } - private Scene loadUserScene(ActionEvent actionEvent, String title, String fxml) { + private FXMLLoader loadUserScene(ActionEvent actionEvent, String title, String fxml, Consumer method) { FXMLLoader fxmlLoader = new FXMLLoader( MainApplication.class.getResource(fxml)); - Scene scene = null; try { - scene = new Scene(fxmlLoader.load(), 800, 650); + Scene scene = new Scene(fxmlLoader.load(), 800, 650); scene.getStylesheets().add(Objects.requireNonNull( MainApplication.class.getResource("../users/create-user.css")).toExternalForm()); Stage stage = new Stage(); @@ -105,12 +116,22 @@ public class OptionController { stage.setScene(scene); stage.initModality(Modality.APPLICATION_MODAL); stage.setResizable(false); + + if(method != null)method.accept(fxmlLoader); + stage.showAndWait(); Stage stageOld = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); stageOld.close(); } catch (IOException e) { e.printStackTrace(); + e.printStackTrace(); } - return scene; + return fxmlLoader; + } + + private void setUserAtController(FXMLLoader fxmlLoader){ + int editIndex = comboBox.getSelectionModel().getSelectedIndex(); + EditUserController editUserController = fxmlLoader.getController(); + editUserController.setCurrentUser(users.get(editIndex)); } } diff --git a/client/app/src/main/java/users/CreateUserController.java b/client/app/src/main/java/users/CreateUserController.java index bfce642..82f795d 100644 --- a/client/app/src/main/java/users/CreateUserController.java +++ b/client/app/src/main/java/users/CreateUserController.java @@ -56,11 +56,13 @@ public class CreateUserController { user.setForename(textForename.getText().trim()); user.setName(textName.getText().trim()); user.setPassword(textPassword.getText().trim()); + user.setAdmin(checkButtonIsAdmin.isSelected()); try { sendHttpRequest(user); } catch (HttpRequestException e) { labelError.setText(e.getMessage()); + return; } Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); diff --git a/client/app/src/main/java/users/EditUserController.java b/client/app/src/main/java/users/EditUserController.java index 6063a59..fa021e4 100644 --- a/client/app/src/main/java/users/EditUserController.java +++ b/client/app/src/main/java/users/EditUserController.java @@ -1,6 +1,14 @@ package users; +import container.DataController; import container.User; +import helper.HttpRequestException; +import javafx.event.ActionEvent; +import javafx.scene.Node; +import javafx.scene.control.Alert; +import javafx.stage.Stage; + +import java.util.Objects; public class EditUserController extends CreateUserController{ private User currentUser; @@ -15,5 +23,70 @@ public class EditUserController extends CreateUserController{ textForename.setText(currentUser.getForename()); textName.setText(currentUser.getName()); textLogin.setText(currentUser.getLogin()); + checkButtonIsAdmin.setSelected(currentUser.isAdmin()); + } + + @Override + protected void createUser(ActionEvent event){ + if (textLogin.getText().trim().isEmpty()){ + labelError.setText("Bitte Login Namen angeben"); + return; + } + if (textForename.getText().trim().isEmpty()) { + labelError.setText("Bitte Vornamen eingeben!"); + return; + } + if (textName.getText().trim().isEmpty()) { + labelError.setText("Bitte Nachnamen eingeben!"); + return; + } + + User user = new User(); + + if(!textPassword.getText().trim().isEmpty() || !textPasswordSecond.getText().trim().isEmpty()){ + if (textPassword.getText().trim().isEmpty()) { + labelError.setText("Bitte Passwort eingeben!"); + return; + } + if (textPassword.getText().trim().length() < 8) { + labelError.setText("Das Passwort muss mindestens 8 Zeichen lang sein!"); + return; + } + if (!Objects.equals(textPassword.getText(), textPasswordSecond.getText())){ + labelError.setText("Passwörter stimmen nicht überein!"); + return; + } + user.setPassword(textPassword.getText().trim()); + } + + user.setUserId(currentUser.getUserId()); + user.setLogin(textLogin.getText().trim()); + user.setForename(textForename.getText().trim()); + user.setName(textName.getText().trim()); + user.setAdmin(checkButtonIsAdmin.isSelected()); + + try { + sendHttpRequest(user); + } catch (HttpRequestException e) { + labelError.setText(e.getMessage()); + return; + } + + if(currentUser.getUserId() == DataController.USER_ID){ + Alert alert = new Alert( + Alert.AlertType.WARNING, + "Bitte starte das Programm neu um die Änderungen anzuwenden." + ); + alert.showAndWait(); + } + + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + stage.close(); + } + + @Override + protected void sendHttpRequest(User user) throws HttpRequestException { + DataController dataController = new DataController(); + dataController.editUser(user); } } diff --git a/client/app/src/main/resources/users/create-user.fxml b/client/app/src/main/resources/users/create-user.fxml index c4741a9..ec367cc 100644 --- a/client/app/src/main/resources/users/create-user.fxml +++ b/client/app/src/main/resources/users/create-user.fxml @@ -43,7 +43,7 @@ -