diff --git a/src/main/java/org/example/se302/controller/ScheduleClassroomController.java b/src/main/java/org/example/se302/controller/ScheduleClassroomController.java index 0ceee1e..d7bcea8 100644 --- a/src/main/java/org/example/se302/controller/ScheduleClassroomController.java +++ b/src/main/java/org/example/se302/controller/ScheduleClassroomController.java @@ -10,80 +10,147 @@ import javafx.scene.control.Label; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import org.example.se302.model.Classroom; +import org.example.se302.model.ExamAssignment; +import org.example.se302.model.ScheduleConfiguration; import org.example.se302.service.DataManager; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Map; + /** * Controller for the Classroom Schedule view. + * Shows exam assignments for each classroom. */ public class ScheduleClassroomController { - @FXML private ComboBox classroomComboBox; - @FXML private Label selectedClassroomLabel; - @FXML private TableView scheduleTable; - @FXML private TableColumn dateColumn; - @FXML private TableColumn timeColumn; - @FXML private TableColumn courseColumn; - @FXML private TableColumn studentsColumn; - @FXML private TableColumn utilizationColumn; - @FXML private Label utilizationLabel; + @FXML + private ComboBox classroomComboBox; + @FXML + private Label selectedClassroomLabel; + @FXML + private TableView scheduleTable; + @FXML + private TableColumn dateColumn; + @FXML + private TableColumn timeColumn; + @FXML + private TableColumn courseColumn; + @FXML + private TableColumn studentsColumn; + @FXML + private TableColumn utilizationColumn; + @FXML + private Label utilizationLabel; - private DataManager dataManager; + private DataManager dataManager; - @FXML - public void initialize() { - dataManager = DataManager.getInstance(); + // Reference to the current schedule state (set by parent controller) + private Map currentAssignments; + private ScheduleConfiguration configuration; - // Populate classroom combo box - classroomComboBox.setItems(dataManager.getClassrooms()); + @FXML + public void initialize() { + dataManager = DataManager.getInstance(); - // Set up table columns - dateColumn.setCellValueFactory(cellData -> - new SimpleStringProperty(cellData.getValue().getDate())); - timeColumn.setCellValueFactory(cellData -> - new SimpleStringProperty(cellData.getValue().getTime())); - courseColumn.setCellValueFactory(cellData -> - new SimpleStringProperty(cellData.getValue().getCourse())); - studentsColumn.setCellValueFactory(cellData -> - new SimpleIntegerProperty(cellData.getValue().getStudentCount())); - utilizationColumn.setCellValueFactory(cellData -> - new SimpleStringProperty(cellData.getValue().getUtilization())); - } + // Populate classroom combo box + classroomComboBox.setItems(dataManager.getClassrooms()); - @FXML - private void onShowSchedule() { - Classroom selected = classroomComboBox.getValue(); - if (selected == null) return; - - selectedClassroomLabel.setText("Schedule for: " + selected.getClassroomId() + - " (Capacity: " + selected.getCapacity() + ")"); - - // For demo: show empty schedule - ObservableList entries = FXCollections.observableArrayList(); - scheduleTable.setItems(entries); - - utilizationLabel.setText("Overall Utilization: 0% (No exams scheduled)"); - } - - // Helper class for table entries - public static class ClassroomSlotEntry { - private final String date; - private final String time; - private final String course; - private final int studentCount; - private final String utilization; - - public ClassroomSlotEntry(String date, String time, String course, int studentCount, String utilization) { - this.date = date; - this.time = time; - this.course = course; - this.studentCount = studentCount; - this.utilization = utilization; + // Set up table columns + dateColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getDate())); + timeColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getTime())); + courseColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getCourse())); + studentsColumn.setCellValueFactory( + cellData -> new SimpleIntegerProperty(cellData.getValue().getStudentCount())); + utilizationColumn.setCellValueFactory( + cellData -> new SimpleStringProperty(cellData.getValue().getUtilization())); } - public String getDate() { return date; } - public String getTime() { return time; } - public String getCourse() { return course; } - public int getStudentCount() { return studentCount; } - public String getUtilization() { return utilization; } - } + /** + * Sets the current schedule assignments. Called by parent controller after + * schedule generation. + */ + public void setScheduleData(Map assignments, ScheduleConfiguration config) { + this.currentAssignments = assignments; + this.configuration = config; + } + + @FXML + private void onShowSchedule() { + Classroom selected = classroomComboBox.getValue(); + if (selected == null) + return; + + selectedClassroomLabel.setText("Schedule for: " + selected.getClassroomId() + + " (Capacity: " + selected.getCapacity() + ")"); + + ObservableList entries = FXCollections.observableArrayList(); + + // If we have assignments, filter by this classroom + if (currentAssignments != null && !currentAssignments.isEmpty()) { + for (ExamAssignment assignment : currentAssignments.values()) { + if (assignment.isAssigned() && + selected.getClassroomId().equals(assignment.getClassroomId())) { + + // Format date + String dateStr; + if (configuration != null && configuration.getStartDate() != null) { + LocalDate examDate = configuration.getStartDate() + .plusDays(assignment.getDay()); + dateStr = examDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")); + } else { + dateStr = "Day " + (assignment.getDay() + 1); + } + + // Format time + String timeStr = "Slot " + (assignment.getTimeSlotIndex() + 1); + + entries.add(new ClassroomSlotEntry( + dateStr, timeStr, assignment.getCourseCode(), + assignment.getStudentCount(), "-")); + } + } + } + + scheduleTable.setItems(entries); + utilizationLabel.setText("Exams shown: " + entries.size()); + } + + // Helper class for table entries + public static class ClassroomSlotEntry { + private final String date; + private final String time; + private final String course; + private final int studentCount; + private final String utilization; + + public ClassroomSlotEntry(String date, String time, String course, int studentCount, + String utilization) { + this.date = date; + this.time = time; + this.course = course; + this.studentCount = studentCount; + this.utilization = utilization; + } + + public String getDate() { + return date; + } + + public String getTime() { + return time; + } + + public String getCourse() { + return course; + } + + public int getStudentCount() { + return studentCount; + } + + public String getUtilization() { + return utilization; + } + } }