#8 story/pfleger-module-login-pfleger #50

Merged
SZUT-Dominik merged 7 commits from story/pfleger-module-login-pfleger into main 2024-05-22 09:46:02 +00:00
2 changed files with 55 additions and 18 deletions
Showing only changes of commit 7db1c83a08 - Show all commits

View file

@ -20,12 +20,24 @@ import java.util.List;
* @author Dorian Nemec * @author Dorian Nemec
*/ */
public class MainWindowController { public class MainWindowController {
private static MainWindowController instace;
@FXML @FXML
public TabPane mainTabPane; public TabPane mainTabPane;
private User user; private User user;
private TabManager tabManager; private TabManager tabManager;
public MainWindowController() {
instace = this;
}
public static MainWindowController getInstance() {
return instace;
}
public User getUser() {
return user;
}
/** /**
* JavaFX Initialization method that is called after the binding of all the fields. * JavaFX Initialization method that is called after the binding of all the fields.
* *
@ -33,6 +45,7 @@ public class MainWindowController {
*/ */
@FXML @FXML
public void initialize(User user) { public void initialize(User user) {
instace = this;
this.user = user; this.user = user;
this.tabManager = new TabManager(user); this.tabManager = new TabManager(user);
setupTabs(); setupTabs();
@ -63,7 +76,7 @@ public class MainWindowController {
new TabStruct( new TabStruct(
"Pfleger", "Pfleger",
"/de/hitec/nhplus/nurse/AllNurseView.fxml", "/de/hitec/nhplus/nurse/AllNurseView.fxml",
Permissions.NURSE | Permissions.MANAGEMENT Permissions.NURSE | Permissions.MANAGEMENT | Permissions.OWNER
), ),
new TabStruct( new TabStruct(
"Gesperrte Pfleger", "Gesperrte Pfleger",

View file

@ -1,8 +1,8 @@
package de.hitec.nhplus.nurse; package de.hitec.nhplus.nurse;
import static de.hitec.nhplus.utils.Validator.*;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.login.Permissions;
import de.hitec.nhplus.main.MainWindowController;
import de.hitec.nhplus.nurse.database.NurseDao; import de.hitec.nhplus.nurse.database.NurseDao;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
@ -17,6 +17,8 @@ import javafx.scene.control.cell.TextFieldTableCell;
import java.sql.SQLException; import java.sql.SQLException;
import static de.hitec.nhplus.utils.Validator.*;
/** /**
* The controller for viewing all {@link Nurse}s. * The controller for viewing all {@link Nurse}s.
* *
@ -49,12 +51,17 @@ public class AllNurseController {
private final ObservableList<Nurse> nurses = FXCollections.observableArrayList(); private final ObservableList<Nurse> nurses = FXCollections.observableArrayList();
private NurseDao dao; private NurseDao dao;
private boolean hasEditPermissions;
/** /**
* Initialization method that is called after the binding of all the fields. * Initialization method that is called after the binding of all the fields.
*/ */
@FXML @FXML
public void initialize() { public void initialize() {
int editPermissions = Permissions.MANAGEMENT | Permissions.OWNER;
int userPermissions = MainWindowController.getInstance().getUser().getPermissions();
hasEditPermissions = (userPermissions & editPermissions) != 0;
this.readAllAndShowInTableView(); this.readAllAndShowInTableView();
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id")); this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
@ -71,12 +78,18 @@ public class AllNurseController {
this.tableView.setItems(this.nurses); this.tableView.setItems(this.nurses);
this.buttonAdd.setDisable(true); this.buttonAdd.setDisable(true);
ChangeListener<String> inputNewNurseValidationListener = (observableValue, oldText, newText)-> if (!hasEditPermissions) {
this.buttonLock.setDisable(true);
return;
}
ChangeListener<String> inputNewNurseValidationListener = (observableValue, oldText, newText) ->
{ {
boolean isValid = isValidFirstName(this.textFieldFirstName.getText()) boolean isValid = isValidFirstName(this.textFieldFirstName.getText())
&& isValidSurName(this.textFieldSurName.getText()) && isValidSurName(this.textFieldSurName.getText())
&& isValidPhoneNumber(this.textFieldPhoneNumber.getText()); && isValidPhoneNumber(this.textFieldPhoneNumber.getText());
AllNurseController.this.buttonAdd.setDisable(!isValid); AllNurseController.this.buttonAdd.setDisable(!isValid);
}; };
@ -89,12 +102,12 @@ public class AllNurseController {
/** /**
* Internal method to read all data and set it to the table view. * Internal method to read all data and set it to the table view.
*/ */
private void readAllAndShowInTableView(){ private void readAllAndShowInTableView() {
this.nurses.clear(); this.nurses.clear();
this.dao = DaoFactory.getInstance().createNurseDAO(); this.dao = DaoFactory.getInstance().createNurseDAO();
try { try {
this.nurses.setAll(this.dao.readAllActive()); this.nurses.setAll(this.dao.readAllActive());
}catch (SQLException exception){ } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
@ -120,14 +133,13 @@ public class AllNurseController {
} }
@FXML @FXML
public void handleAdd(){ public void handleAdd() {
String surname=this.textFieldSurName.getText(); String surname = this.textFieldSurName.getText();
String firstName=this.textFieldFirstName.getText(); String firstName = this.textFieldFirstName.getText();
String phoneNumber=this.textFieldPhoneNumber.getText(); String phoneNumber = this.textFieldPhoneNumber.getText();
try { try {
this.dao.create(new Nurse(firstName, surname, phoneNumber)); this.dao.create(new Nurse(firstName, surname, phoneNumber));
} } catch (SQLException exception) {
catch (SQLException exception){
exception.printStackTrace(); exception.printStackTrace();
} }
readAllAndShowInTableView(); readAllAndShowInTableView();
@ -135,16 +147,16 @@ public class AllNurseController {
} }
@FXML @FXML
public void handleLock(){ public void handleLock() {
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem(); Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
if (selectedItem == null){ if (selectedItem == null) {
return; return;
} }
try { try {
selectedItem.setLocked(true); selectedItem.setLocked(true);
this.dao.update(selectedItem); this.dao.update(selectedItem);
}catch (SQLException exception){ } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
readAllAndShowInTableView(); readAllAndShowInTableView();
@ -152,6 +164,10 @@ public class AllNurseController {
@FXML @FXML
public void handleOnEditSurname(TableColumn.CellEditEvent<Nurse, String> event) { public void handleOnEditSurname(TableColumn.CellEditEvent<Nurse, String> event) {
if(!hasEditPermissions){
event.getTableView().refresh();
return;
}
String newSurName = event.getNewValue(); String newSurName = event.getNewValue();
if (!isValidSurName(newSurName)) { if (!isValidSurName(newSurName)) {
showValidationError("Nachname"); showValidationError("Nachname");
@ -164,6 +180,10 @@ public class AllNurseController {
@FXML @FXML
public void handleOnEditFirstname(TableColumn.CellEditEvent<Nurse, String> event) { public void handleOnEditFirstname(TableColumn.CellEditEvent<Nurse, String> event) {
if(!hasEditPermissions){
event.getTableView().refresh();
return;
}
String newFirstName = event.getNewValue(); String newFirstName = event.getNewValue();
if (!isValidFirstName(newFirstName)) { if (!isValidFirstName(newFirstName)) {
showValidationError("Vorname"); showValidationError("Vorname");
@ -176,6 +196,10 @@ public class AllNurseController {
@FXML @FXML
public void handleOnEditPhoneNumber(TableColumn.CellEditEvent<Nurse, String> event) { public void handleOnEditPhoneNumber(TableColumn.CellEditEvent<Nurse, String> event) {
if(!hasEditPermissions){
event.getTableView().refresh();
return;
}
String newPhoneNumber = event.getNewValue(); String newPhoneNumber = event.getNewValue();
if (!isValidPhoneNumber(newPhoneNumber)) { if (!isValidPhoneNumber(newPhoneNumber)) {
showValidationError("Telefonnummer"); showValidationError("Telefonnummer");