From 6726f129a0aa3e01f88897472c13218452896d89 Mon Sep 17 00:00:00 2001 From: Omnicscient <115184891+Omnicscient@users.noreply.github.com> Date: Tue, 16 Dec 2025 22:02:15 +0300 Subject: [PATCH] Task 2.3 Step 1: Populate exam date, time, classroom in Course Schedule View --- .../controller/ScheduleCourseController.java | 188 ++++++++++++------ 1 file changed, 127 insertions(+), 61 deletions(-) diff --git a/src/main/java/org/example/se302/controller/ScheduleCourseController.java b/src/main/java/org/example/se302/controller/ScheduleCourseController.java index 8d7bcc6..7409730 100644 --- a/src/main/java/org/example/se302/controller/ScheduleCourseController.java +++ b/src/main/java/org/example/se302/controller/ScheduleCourseController.java @@ -8,82 +8,148 @@ import javafx.fxml.FXML; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import org.example.se302.model.Course; +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 Course Schedule view. + * Displays courses with their exam date, time, and assigned classroom. */ public class ScheduleCourseController { - @FXML private TableView courseScheduleTable; - @FXML private TableColumn courseCodeColumn; - @FXML private TableColumn enrolledColumn; - @FXML private TableColumn dateColumn; - @FXML private TableColumn timeColumn; - @FXML private TableColumn classroomColumn; + @FXML + private TableView courseScheduleTable; + @FXML + private TableColumn courseCodeColumn; + @FXML + private TableColumn enrolledColumn; + @FXML + private TableColumn dateColumn; + @FXML + private TableColumn timeColumn; + @FXML + private TableColumn classroomColumn; - private DataManager dataManager; + private DataManager dataManager; - @FXML - public void initialize() { - dataManager = DataManager.getInstance(); + // Reference to the current schedule state (set by parent controller or loaded + // from DB) + private Map currentAssignments; + private ScheduleConfiguration configuration; - // Set up table columns - courseCodeColumn.setCellValueFactory(cellData -> - new SimpleStringProperty(cellData.getValue().getCourseCode())); - enrolledColumn.setCellValueFactory(cellData -> - new SimpleIntegerProperty(cellData.getValue().getEnrolledCount())); - dateColumn.setCellValueFactory(cellData -> - new SimpleStringProperty(cellData.getValue().getDate())); - timeColumn.setCellValueFactory(cellData -> - new SimpleStringProperty(cellData.getValue().getTime())); - classroomColumn.setCellValueFactory(cellData -> - new SimpleStringProperty(cellData.getValue().getClassroom())); + @FXML + public void initialize() { + dataManager = DataManager.getInstance(); - // Load data - loadScheduleData(); + // Set up table columns + courseCodeColumn.setCellValueFactory( + cellData -> new SimpleStringProperty(cellData.getValue().getCourseCode())); + enrolledColumn.setCellValueFactory( + cellData -> new SimpleIntegerProperty(cellData.getValue().getEnrolledCount())); + dateColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getDate())); + timeColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getTime())); + classroomColumn.setCellValueFactory( + cellData -> new SimpleStringProperty(cellData.getValue().getClassroom())); - // Listen for data changes - dataManager.getCourses().addListener( - (javafx.collections.ListChangeListener) c -> loadScheduleData()); - } + // Load data + loadScheduleData(); - private void loadScheduleData() { - ObservableList entries = FXCollections.observableArrayList(); - - for (Course course : dataManager.getCourses()) { - entries.add(new CourseScheduleEntry( - course.getCourseCode(), - course.getEnrolledStudentsCount(), - "Not Scheduled", - "-", - "-" - )); + // Listen for data changes + dataManager.getCourses().addListener( + (javafx.collections.ListChangeListener) c -> loadScheduleData()); } - courseScheduleTable.setItems(entries); - } - - // Helper class for table entries - public static class CourseScheduleEntry { - private final String courseCode; - private final int enrolledCount; - private final String date; - private final String time; - private final String classroom; - - public CourseScheduleEntry(String courseCode, int enrolledCount, String date, String time, String classroom) { - this.courseCode = courseCode; - this.enrolledCount = enrolledCount; - this.date = date; - this.time = time; - this.classroom = classroom; + /** + * 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; + loadScheduleData(); } - public String getCourseCode() { return courseCode; } - public int getEnrolledCount() { return enrolledCount; } - public String getDate() { return date; } - public String getTime() { return time; } - public String getClassroom() { return classroom; } - } + private void loadScheduleData() { + ObservableList entries = FXCollections.observableArrayList(); + + for (Course course : dataManager.getCourses()) { + String courseCode = course.getCourseCode(); + int enrolled = course.getEnrolledStudentsCount(); + + String dateStr = "Not Scheduled"; + String timeStr = "-"; + String classroomStr = "-"; + + // Check if we have an assignment for this course + if (currentAssignments != null && currentAssignments.containsKey(courseCode)) { + ExamAssignment assignment = currentAssignments.get(courseCode); + + if (assignment.isAssigned()) { + // Format date based on configuration start date + day offset + if (configuration != null && configuration.getStartDate() != null) { + LocalDate examDate = configuration.getStartDate() + .plusDays(assignment.getDay()); + dateStr = examDate.format( + DateTimeFormatter.ofPattern("dd/MM/yyyy (EEEE)")); + } else { + dateStr = "Day " + (assignment.getDay() + 1); + } + + // Format time slot + timeStr = "Slot " + (assignment.getTimeSlotIndex() + 1); + + // Classroom + classroomStr = assignment.getClassroomId() != null ? assignment.getClassroomId() + : "-"; + } + } + + entries.add(new CourseScheduleEntry(courseCode, enrolled, dateStr, timeStr, classroomStr)); + } + + courseScheduleTable.setItems(entries); + } + + // Helper class for table entries + public static class CourseScheduleEntry { + private final String courseCode; + private final int enrolledCount; + private final String date; + private final String time; + private final String classroom; + + public CourseScheduleEntry(String courseCode, int enrolledCount, String date, String time, + String classroom) { + this.courseCode = courseCode; + this.enrolledCount = enrolledCount; + this.date = date; + this.time = time; + this.classroom = classroom; + } + + public String getCourseCode() { + return courseCode; + } + + public int getEnrolledCount() { + return enrolledCount; + } + + public String getDate() { + return date; + } + + public String getTime() { + return time; + } + + public String getClassroom() { + return classroom; + } + } }