diff --git a/src/main/java/com/gitrekt/resort/controller/StaffAccountsScreenController.java b/src/main/java/com/gitrekt/resort/controller/StaffAccountsScreenController.java index b5d184b..8e3a422 100644 --- a/src/main/java/com/gitrekt/resort/controller/StaffAccountsScreenController.java +++ b/src/main/java/com/gitrekt/resort/controller/StaffAccountsScreenController.java @@ -1,17 +1,23 @@ package com.gitrekt.resort.controller; +import com.gitrekt.resort.model.entities.Employee; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; -import javafx.scene.image.Image; +import javafx.scene.control.cell.CheckBoxTableCell; import javafx.stage.Modality; import javafx.stage.Stage; @@ -33,25 +39,70 @@ public class StaffAccountsScreenController implements Initializable { private Button addNewEmployeeButton; @FXML - private TableView staffAccountTableView; + private TableView staffAccountsTableView; @FXML - private TableColumn idColumn; + private TableColumn employeeNameColumn; @FXML - private TableColumn nameColumn; + private TableColumn isManagerColumn; @FXML - private TableColumn managerColumn; + private TableColumn employeeIdColumn; - private final Image appLogo = new Image("images/Logo.png"); + + private ObservableList staffAccountList; /** * Initializes the controller class. */ @Override public void initialize(URL url, ResourceBundle rb) { - // TODO + staffAccountList = FXCollections.observableArrayList(); + staffAccountsTableView.setItems(staffAccountList); + + employeeIdColumn.setCellValueFactory((param) -> { + return new SimpleStringProperty( + String.valueOf(param.getValue().getId()) + ); + }); + + employeeNameColumn.setCellValueFactory((param) -> { + return new SimpleStringProperty( + param.getValue().getLastName() + + ", " + + param.getValue().getFirstName() + ); + }); + + isManagerColumn.setCellValueFactory((param) -> { + return new SimpleBooleanProperty(param.getValue().isManager()); + }); + + // Display the boolean column using checkboxes instead of strings + isManagerColumn.setCellFactory( + (param) -> { + return new CheckBoxTableCell<>(); + } + ); + + staffAccountsTableView.setPlaceholder( + new Label("We fired everyone") + ); + + // TODO: Remove test data + + Employee employee1 = new Employee(Long.valueOf(1),"1234", true, "Juan" , "Gomez"); + Employee employee2 = new Employee(Long.valueOf(2),"1234", true, "Juanito" , "Gomez"); + Employee employee3 = new Employee(Long.valueOf(3),"1234", false, "Juana" , "Gomez"); + Employee employee4 = new Employee(Long.valueOf(4),"1234", false, "Juanita" , "Gomez"); + Employee employee5 = new Employee(Long.valueOf(5),"1234", true, "Juanucho" , "Gomez"); + + staffAccountList.add(employee1); + staffAccountList.add(employee2); + staffAccountList.add(employee3); + staffAccountList.add(employee4); + staffAccountList.add(employee5); } public void onBackButtonClicked() { @@ -60,13 +111,21 @@ public void onBackButtonClicked() { ); } + /** + * Displays the dialog to delete the currently selected employee account. + */ public void onRemoveEmployeeButtonClicked() { - // TODO + Employee selectedEmployee = getSelectedEmployee(); + // TODO: Display dialog to delete employee account. } + /** + * Displays the reset password dialog for the currently selected employee. + * + * @throws IOException + */ public void onResetEmployeePasswordButtonClicked() throws IOException { Stage dialogStage = new Stage(); - dialogStage.getIcons().add(appLogo); FXMLLoader loader = new FXMLLoader( getClass().getResource("/fxml/ResetEmployeePasswordDialog.fxml") ); @@ -79,12 +138,12 @@ public void onResetEmployeePasswordButtonClicked() throws IOException { resetEmployeePasswordButton.getScene().getWindow() ); dialogStage.setResizable(false); - dialogStage.setTitle("Authentication Required"); + dialogStage.setTitle("Confirm"); dialogStage.centerOnScreen(); ResetEmployeePasswordDialogController c; c = (ResetEmployeePasswordDialogController) loader.getController(); - long employeeId = getSelectedEmployeeId(); + long employeeId = getSelectedEmployee().getId(); c.setEmployeeId(employeeId); dialogStage.show(); @@ -92,7 +151,6 @@ public void onResetEmployeePasswordButtonClicked() throws IOException { public void onAddNewEmployeeButtonClicked() throws IOException { Stage dialogStage = new Stage(); - dialogStage.getIcons().add(appLogo); Parent dialogRoot = FXMLLoader.load( getClass().getResource("/fxml/CreateStaffAccountDialog.fxml") ); @@ -103,15 +161,19 @@ public void onAddNewEmployeeButtonClicked() throws IOException { addNewEmployeeButton.getScene().getWindow() ); dialogStage.setResizable(false); - dialogStage.setTitle("Authentication Required"); + dialogStage.setTitle("Create employee"); dialogStage.centerOnScreen(); dialogStage.show(); } - private long getSelectedEmployeeId() { - // TODO: REPLACE WITH REAL IMPLEMENTATION - return 1L; + /** + * @return The currently selected employee in the employee table view. + */ + private Employee getSelectedEmployee() { + Employee selectedEmployee = + staffAccountsTableView.getSelectionModel().getSelectedItem(); + return selectedEmployee; } } diff --git a/src/main/resources/fxml/StaffAccountsScreen.fxml b/src/main/resources/fxml/StaffAccountsScreen.fxml index c761632..8211137 100644 --- a/src/main/resources/fxml/StaffAccountsScreen.fxml +++ b/src/main/resources/fxml/StaffAccountsScreen.fxml @@ -27,7 +27,7 @@ - +