Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -33,25 +39,70 @@ public class StaffAccountsScreenController implements Initializable {
private Button addNewEmployeeButton;

@FXML
private TableView staffAccountTableView;
private TableView<Employee> staffAccountsTableView;

@FXML
private TableColumn idColumn;
private TableColumn<Employee,String> employeeNameColumn;

@FXML
private TableColumn nameColumn;
private TableColumn<Employee,Boolean> isManagerColumn;

@FXML
private TableColumn managerColumn;
private TableColumn<Employee,String> employeeIdColumn;

private final Image appLogo = new Image("images/Logo.png");

private ObservableList<Employee> 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() {
Expand All @@ -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")
);
Expand All @@ -79,20 +138,19 @@ 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();
}

public void onAddNewEmployeeButtonClicked() throws IOException {
Stage dialogStage = new Stage();
dialogStage.getIcons().add(appLogo);
Parent dialogRoot = FXMLLoader.load(
getClass().getResource("/fxml/CreateStaffAccountDialog.fxml")
);
Expand All @@ -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;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/fxml/StaffAccountsScreen.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</Separator>
<TableView fx:id="staffAccountsTableView" maxWidth="-Infinity" prefHeight="300.0" prefWidth="800.0">
<TableView fx:id="staffAccountsTableView" maxWidth="-Infinity" prefHeight="800.0" prefWidth="800.0">
<columns>
<TableColumn fx:id="employeeIdColumn" editable="false" prefWidth="100.0" resizable="false" text="Id #" />
<TableColumn fx:id="employeeNameColumn" editable="false" prefWidth="580.0" resizable="false" text="Name (Last, First)" />
Expand Down