Refactor
This commit is contained in:
parent
245314a887
commit
db339eeada
@ -234,6 +234,7 @@ public class MainController {
|
|||||||
vBox.getChildren().add(btnHBox);
|
vBox.getChildren().add(btnHBox);
|
||||||
|
|
||||||
Label nameLabel = new Label(event.getName());
|
Label nameLabel = new Label(event.getName());
|
||||||
|
nameLabel.setWrapText(true);
|
||||||
vBox.getChildren().add(nameLabel);
|
vBox.getChildren().add(nameLabel);
|
||||||
|
|
||||||
if (event.getStart() != null || event.getEnd() != null) {
|
if (event.getStart() != null || event.getEnd() != null) {
|
||||||
@ -251,6 +252,7 @@ public class MainController {
|
|||||||
|
|
||||||
if (event.isFullDay()) {
|
if (event.isFullDay()) {
|
||||||
Label fullDayLabel = new Label("Dieser Termin bockiert den ganzen Tag!");
|
Label fullDayLabel = new Label("Dieser Termin bockiert den ganzen Tag!");
|
||||||
|
fullDayLabel.setWrapText(true);
|
||||||
vBox.getChildren().add(fullDayLabel);
|
vBox.getChildren().add(fullDayLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,15 @@ import javafx.stage.Modality;
|
|||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import container.DataController;
|
import container.DataController;
|
||||||
import container.User;
|
import container.User;
|
||||||
|
import users.EditUserController;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class OptionController {
|
public class OptionController {
|
||||||
|
|
||||||
@ -68,11 +71,20 @@ public class OptionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onCreateBtnClick(ActionEvent actionEvent) {
|
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) {
|
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) {
|
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<FXMLLoader> method) {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(
|
FXMLLoader fxmlLoader = new FXMLLoader(
|
||||||
MainApplication.class.getResource(fxml));
|
MainApplication.class.getResource(fxml));
|
||||||
Scene scene = null;
|
|
||||||
try {
|
try {
|
||||||
scene = new Scene(fxmlLoader.load(), 800, 650);
|
Scene scene = new Scene(fxmlLoader.load(), 800, 650);
|
||||||
scene.getStylesheets().add(Objects.requireNonNull(
|
scene.getStylesheets().add(Objects.requireNonNull(
|
||||||
MainApplication.class.getResource("../users/create-user.css")).toExternalForm());
|
MainApplication.class.getResource("../users/create-user.css")).toExternalForm());
|
||||||
Stage stage = new Stage();
|
Stage stage = new Stage();
|
||||||
@ -105,12 +116,22 @@ public class OptionController {
|
|||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.initModality(Modality.APPLICATION_MODAL);
|
stage.initModality(Modality.APPLICATION_MODAL);
|
||||||
stage.setResizable(false);
|
stage.setResizable(false);
|
||||||
|
|
||||||
|
if(method != null)method.accept(fxmlLoader);
|
||||||
|
|
||||||
stage.showAndWait();
|
stage.showAndWait();
|
||||||
Stage stageOld = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
|
Stage stageOld = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
|
||||||
stageOld.close();
|
stageOld.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,11 +56,13 @@ public class CreateUserController {
|
|||||||
user.setForename(textForename.getText().trim());
|
user.setForename(textForename.getText().trim());
|
||||||
user.setName(textName.getText().trim());
|
user.setName(textName.getText().trim());
|
||||||
user.setPassword(textPassword.getText().trim());
|
user.setPassword(textPassword.getText().trim());
|
||||||
|
user.setAdmin(checkButtonIsAdmin.isSelected());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sendHttpRequest(user);
|
sendHttpRequest(user);
|
||||||
} catch (HttpRequestException e) {
|
} catch (HttpRequestException e) {
|
||||||
labelError.setText(e.getMessage());
|
labelError.setText(e.getMessage());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
package users;
|
package users;
|
||||||
|
|
||||||
|
import container.DataController;
|
||||||
import container.User;
|
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{
|
public class EditUserController extends CreateUserController{
|
||||||
private User currentUser;
|
private User currentUser;
|
||||||
@ -15,5 +23,70 @@ public class EditUserController extends CreateUserController{
|
|||||||
textForename.setText(currentUser.getForename());
|
textForename.setText(currentUser.getForename());
|
||||||
textName.setText(currentUser.getName());
|
textName.setText(currentUser.getName());
|
||||||
textLogin.setText(currentUser.getLogin());
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
<JFXToggleButton fx:id="checkButtonIsAdmin" GridPane.columnIndex="2" GridPane.rowIndex="6"/>
|
<JFXToggleButton fx:id="checkButtonIsAdmin" GridPane.columnIndex="2" GridPane.rowIndex="6"/>
|
||||||
|
|
||||||
<Label fx:id="labelError" styleClass="errorMessage" GridPane.columnIndex="2" GridPane.rowIndex="7"/>
|
<Label fx:id="labelError" wrapText="true" styleClass="errorMessage" GridPane.columnIndex="2" GridPane.rowIndex="7"/>
|
||||||
|
|
||||||
<HBox GridPane.columnIndex="2" GridPane.rowIndex="8" alignment="CENTER_RIGHT">
|
<HBox GridPane.columnIndex="2" GridPane.rowIndex="8" alignment="CENTER_RIGHT">
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
<JFXToggleButton fx:id="checkButtonIsAdmin" GridPane.columnIndex="2" GridPane.rowIndex="6"/>
|
<JFXToggleButton fx:id="checkButtonIsAdmin" GridPane.columnIndex="2" GridPane.rowIndex="6"/>
|
||||||
|
|
||||||
<Label fx:id="labelError" styleClass="errorMessage" GridPane.columnIndex="2" GridPane.rowIndex="7"/>
|
<Label fx:id="labelError" wrapText="true" styleClass="errorMessage" GridPane.columnIndex="2" GridPane.rowIndex="7"/>
|
||||||
|
|
||||||
<HBox GridPane.columnIndex="2" GridPane.rowIndex="8" alignment="CENTER_RIGHT">
|
<HBox GridPane.columnIndex="2" GridPane.rowIndex="8" alignment="CENTER_RIGHT">
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
|
@ -125,7 +125,8 @@ public class DataController {
|
|||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
objectMapper.findAndRegisterModules();
|
objectMapper.findAndRegisterModules();
|
||||||
return (ArrayList<Event>) objectMapper.readValue(jsonResponse, new TypeReference<List<Event>>() {});
|
return (ArrayList<Event>) objectMapper.readValue(jsonResponse, new TypeReference<List<Event>>() {
|
||||||
|
});
|
||||||
|
|
||||||
} catch (HttpRequestException e) {
|
} catch (HttpRequestException e) {
|
||||||
throw e;
|
throw e;
|
||||||
@ -148,7 +149,13 @@ public class DataController {
|
|||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
objectMapper.findAndRegisterModules();
|
objectMapper.findAndRegisterModules();
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(userJSON, new TypeReference<>() {});
|
List<User> list = objectMapper.readValue(userJSON, new TypeReference<>() {
|
||||||
|
});
|
||||||
|
|
||||||
|
for(User u : list){
|
||||||
|
System.out.println(u);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -175,10 +182,18 @@ public class DataController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editUser(User oldUser, User user) throws HttpRequestException {
|
public void editUser(User user) throws HttpRequestException {
|
||||||
|
String urlParam = "userId=" + user.getUserId() +
|
||||||
|
"&name=" + user.getName() +
|
||||||
|
"&forename=" + user.getForename() +
|
||||||
|
"&login=" + user.getLogin() +
|
||||||
|
"&isAdmin=" + user.isAdmin() +
|
||||||
|
(user.getPassword() == null ? "" : "&password=" + user.getPassword());
|
||||||
|
|
||||||
|
System.out.println(urlParam);
|
||||||
sendBasicHttpRequest(
|
sendBasicHttpRequest(
|
||||||
EDIT_USER_ENDPOINT,
|
EDIT_USER_ENDPOINT,
|
||||||
"",
|
urlParam,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -60,4 +60,16 @@ public class User {
|
|||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"userId=" + userId +
|
||||||
|
", login='" + login + '\'' +
|
||||||
|
", forename='" + forename + '\'' +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", password='" + password + '\'' +
|
||||||
|
", isAdmin=" + isAdmin +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user