#8: Use Permissions in Nurse Controller
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
parent
ae7fc3ab64
commit
7db1c83a08
2 changed files with 55 additions and 18 deletions
|
@ -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",
|
||||||
|
|
|
@ -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,7 +78,13 @@ public class AllNurseController {
|
||||||
|
|
||||||
this.tableView.setItems(this.nurses);
|
this.tableView.setItems(this.nurses);
|
||||||
|
|
||||||
|
|
||||||
this.buttonAdd.setDisable(true);
|
this.buttonAdd.setDisable(true);
|
||||||
|
if (!hasEditPermissions) {
|
||||||
|
this.buttonLock.setDisable(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ChangeListener<String> inputNewNurseValidationListener = (observableValue, oldText, newText) ->
|
ChangeListener<String> inputNewNurseValidationListener = (observableValue, oldText, newText) ->
|
||||||
{
|
{
|
||||||
boolean isValid = isValidFirstName(this.textFieldFirstName.getText())
|
boolean isValid = isValidFirstName(this.textFieldFirstName.getText())
|
||||||
|
@ -126,8 +139,7 @@ public class AllNurseController {
|
||||||
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();
|
||||||
|
@ -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");
|
||||||
|
|
Loading…
Reference in a new issue