-
ArktikHunter authoredArktikHunter authored
Controller.java 15.35 KiB
package com.example.schedulerapp;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
public class Controller {
@FXML
BorderPane myBorderPane;
@FXML
VBox leftSideButtons;
@FXML
public BorderPane rootBorderPane;
@FXML
TextArea employees;
@FXML
private TextField addFirstName;
@FXML
private TextField addLastName;
@FXML
private TextField removeID;
@FXML
Button addShiftSubmitButton;
@FXML
DatePicker addShiftDatePicker;
@FXML
TextField addShiftStartTime;
@FXML
TextField addShiftEndTime;
@FXML
ComboBox addShiftEmployeeBox;
@FXML
HBox addShiftEmployeeHBox;
@FXML
ComboBox removeEmployeeBox;
@FXML
ComboBox addShiftStartTimeBox;
@FXML
ComboBox addShiftEndTimeBox;
@FXML
Label currentDateText;
@FXML
TextField loginField;
Stage popupStage;
Scene popupScene;
Model model;
DailyView dailyView;
WeeklyView weeklyView;
BorderPane root;
Parent header;
Parent sidePanel;
Parent bottomPanel;
static boolean isDaily;
public void scheduleButtonClicked() throws IOException {
System.out.println("schedule button clicked");
dailyScheduleButtonClicked();
leftSideButtons.setVisible(true);
}
public void paystubButtonClicked() throws IOException {
System.out.println("paystub button clicked");
FXMLLoader fxmlLoader = new FXMLLoader(ScheduleApp.class.getResource("paystubView.fxml"));
fxmlLoader.setController(this);
myBorderPane.setCenter(fxmlLoader.load());
leftSideButtons.setVisible(false);
}
public void availabilityButtonClicked() {
System.out.println("availability button clicked");
}
public void timeoffButtonClicked () {
System.out.println("timeoff button clicked");
}
public void dailyScheduleButtonClicked() throws IOException {
System.out.println("daily schedule button clicked");
root.setTop(header);
root.setLeft(sidePanel);
root.setBottom(bottomPanel);
root.setCenter(dailyView);
}
public void weeklyScheduleButtonClicked() throws Exception {
System.out.println("weekly schedule button clicked");
root.setTop(header);
root.setLeft(sidePanel);
root.setBottom(bottomPanel);
root.setCenter(weeklyView);
}
public void pickupsButtonClicked () {
System.out.println("pickups button clicked");
}
public void prevButtonClicked (MouseEvent event) throws Exception {
System.out.println("prev button clicked");
model.datePrev();
updateCurrentDate(event);
}
public void jumpButtonClicked (MouseEvent event) throws Exception {
System.out.println("jump button clicked");
//model.dateJump();
updateCurrentDate(event);
}
public void nextButtonClicked (MouseEvent event) throws Exception {
System.out.println("next button clicked");
System.out.println(isDaily);
model.dateNext();
updateCurrentDate(event);
}
public void addShiftClicked() throws IOException {
FXMLLoader popupLoader = new FXMLLoader(this.getClass().getResource("addShiftPopup.fxml"));
popupLoader.setController(this);
popupScene = new Scene(popupLoader.load(),500,500);
popupStage = new Stage();
popupStage.setScene(popupScene);
popupStage.show();
}
public void populateEmployeeBox(MouseEvent event) {
ArrayList<String> aList = model.returnFormattedEmployeeNames();
ObservableList<String> list = FXCollections.observableArrayList();
aList.forEach(employee-> list.add(employee));
ComboBox test = (ComboBox) event.getSource();
test.setItems(list);
}
public void addShiftSubmitClicked(MouseEvent event){
System.out.println("submit clicked");
String employee = (String) addShiftEmployeeBox.getValue();
int index = addShiftEmployeeBox.getSelectionModel().getSelectedIndex();
String startTime = (String) addShiftStartTimeBox.getValue();
String endTime = (String) addShiftEndTimeBox.getValue();
LocalDate date = addShiftDatePicker.getValue();
System.out.println(date.toString());
model.addShift(model.getIDbyIndex(index),date.toString(),Integer.parseInt(startTime),Integer.parseInt(endTime));
System.out.println(model.getIDbyIndex(index) + "20210101" + Integer.parseInt(startTime) + Integer.parseInt(endTime));
//System.out.println(employee + startTime + endTime + date);
}
public void managerScheduleClicked(MouseEvent event) throws IOException {
System.out.println("manager schedule clicked");
isDaily = false;
managerLoginClicked(event);
}
public void managerDailyScheduleClicked(MouseEvent mouseEvent) throws IOException{
System.out.println("manager daily clicked");
isDaily = true;
System.out.println(isDaily);
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("schedSidePanel.fxml"));
sideLoader.setController(this);
sidePanel = sideLoader.load();
FXMLLoader bottomLoader = new FXMLLoader(this.getClass().getResource("schedBottomPanelManager.fxml"));
bottomLoader.setController(this);
bottomPanel = bottomLoader.load();
root.setTop(header);;
root.setLeft(sidePanel);
root.setBottom(bottomPanel);
root.setCenter(dailyView);
HBox box = (HBox) bottomPanel.getChildrenUnmodifiable().get(1);
Label currentDateText = (Label) box.getChildren().get(1);
currentDateText.setText("Current Date: " + model.date);
System.out.println(isDaily);
}
public void removeEmployeeBoxClicked(MouseEvent event){
System.out.println("remove employee box clicked");
populateEmployeeBox(event);
}
public void addShiftTimeBoxClicked(MouseEvent event){
System.out.println("add shift time box clicked");
ArrayList<String> times = new ArrayList<>();
for (int i = 8; i < 24; i++){
String j = i + "00";
String k = i + "30";
if (i < 10) {
j = "0" + j;
k = "0" + k;
}
times.add(j);
times.add(k);
}
ComboBox box = (ComboBox) event.getSource();
ObservableList<String> list = FXCollections.observableArrayList(times);
System.out.println(list);
box.setItems(list);
}
public void updateCurrentDate(MouseEvent event) throws Exception {
if(currentDateText == null){
currentDateText = new Label();
}
currentDateText.setText("Current Date: " + model.date.toString());
System.out.println(isDaily);
updateScheduleViews(event);
}
public void updateScheduleViews(MouseEvent event) throws Exception {
if(isDaily){
managerDailyScheduleClicked(event);
}
else{
managerScheduleClicked(event);
}
}
// Login Page
public void managerLoginClicked(MouseEvent mouseEvent) throws IOException {
root = new BorderPane();
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("schedSidePanel.fxml"));
sideLoader.setController(this);
sidePanel = sideLoader.load();
FXMLLoader bottomLoader = new FXMLLoader(this.getClass().getResource("schedBottomPanelManager.fxml"));
bottomLoader.setController(this);
bottomPanel = bottomLoader.load();
model = new Model("localhost", 8989);
model.setIsManager(true);
model.setThisEmployee(Integer.parseInt(loginField.getText())); //todo:need guard to allow only #
dailyView = new DailyView();
dailyView.setModel(model);
model.addSubscriber(dailyView);
weeklyView = new WeeklyView();
weeklyView.setModel(model);
model.addSubscriber(weeklyView);
root.setTop(header);
root.setLeft(sidePanel);
root.setBottom(bottomPanel);
root.setCenter(dailyView);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
HBox box = (HBox) bottomPanel.getChildrenUnmodifiable().get(1);
Label currentDateText = (Label) box.getChildren().get(1);
currentDateText.setText("Current Date: " + model.date);
}
public void employeeLoginClicked(MouseEvent mouseEvent) throws IOException {
FXMLLoader employeeLoader = new FXMLLoader(this.getClass().getResource("mainView.fxml"));
employeeLoader.setController(this);
Parent root = employeeLoader.load();
dailyView = new DailyView();
dailyView.setModel(model);
weeklyView = new WeeklyView();
weeklyView.setModel(model);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
}
// Header
public void mangerLogoutClicked(MouseEvent mouseEvent) throws IOException {
FXMLLoader loginLoader = new FXMLLoader(this.getClass().getResource("login.fxml"));
loginLoader.setController(this);
Parent root = loginLoader.load();
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
}
// Manager Page
// Staff Section
// Switch to Staff Page
public void staffManagerClicked(MouseEvent mouseEvent) throws IOException {
BorderPane root = new BorderPane();
FXMLLoader gridLoader = new FXMLLoader(this.getClass().getResource("addEmployee.fxml"));
gridLoader.setController(this);
Parent grid = gridLoader.load();
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
Parent header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("staffManagerSidePanel.fxml"));
sideLoader.setController(this);
Parent sidePanel = sideLoader.load();
root.setTop(header);
root.setLeft(sidePanel);
root.setCenter(grid);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
}
// Side Panel
// Switch to Edit Employee
public void editStaffSidePanelClicked(MouseEvent mouseEvent) throws IOException {
BorderPane root = new BorderPane();
FXMLLoader gridLoader = new FXMLLoader(this.getClass().getResource("editEmployee.fxml"));
gridLoader.setController(this);
Parent grid = gridLoader.load();
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
Parent header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("staffManagerSidePanel.fxml"));
sideLoader.setController(this);
Parent sidePanel = sideLoader.load();
root.setTop(header);
root.setLeft(sidePanel);
root.setCenter(grid);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
}
// Switch to Remove Employee
public void removeStaffSidePanelClicked(MouseEvent mouseEvent) throws IOException {
System.out.println("remove staff side panel clicked");
BorderPane root = new BorderPane();
FXMLLoader gridLoader = new FXMLLoader(this.getClass().getResource("removeEmployee.fxml"));
gridLoader.setController(this);
Parent grid = gridLoader.load();
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
Parent header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("staffManagerSidePanel.fxml"));
sideLoader.setController(this);
Parent sidePanel = sideLoader.load();
root.setTop(header);
root.setLeft(sidePanel);
root.setCenter(grid);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
}
// Switch to View Employees
public void viewStaffSidePanelClicked(MouseEvent mouseEvent) throws IOException {
BorderPane root = new BorderPane();
FXMLLoader gridLoader = new FXMLLoader(this.getClass().getResource("viewEmployees.fxml"));
gridLoader.setController(this);
Parent grid = gridLoader.load();
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
Parent header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("staffManagerSidePanel.fxml"));
sideLoader.setController(this);
Parent sidePanel = sideLoader.load();
root.setTop(header);
root.setLeft(sidePanel);
root.setCenter(grid);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
}
// Add, Edit, Remove Functions
// Add Employee
public void addEmployeeClicked(MouseEvent mouseEvent) {
String firstName = addFirstName.getText();
String lastName = addLastName.getText();
model.addEmployee(firstName, lastName);
System.out.println("Employee " + firstName + " " + lastName + " added to Staff. Welcome "
+ firstName + "!");
}
// Edit employee
public void editEmployeeClicked(MouseEvent mouseEvent) {
//edit employee
}
// Remove Employee
public void removeEmployeeClicked(MouseEvent mouseEvent) {
int index = removeEmployeeBox.getSelectionModel().getSelectedIndex();
String id = String.valueOf(model.getIDbyIndex(index));
model.removeEmployee(id);
removeEmployeeBox.getSelectionModel().clearSelection();
}
// View Employees
}