Task 2.3 Step 1: Populate exam date, time, classroom in Course Schedule View

This commit is contained in:
Omnicscient
2025-12-16 22:02:15 +03:00
parent 09a95b271c
commit 6726f129a0

View File

@@ -8,37 +8,53 @@ import javafx.fxml.FXML;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import org.example.se302.model.Course; 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 org.example.se302.service.DataManager;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Map;
/** /**
* Controller for the Course Schedule view. * Controller for the Course Schedule view.
* Displays courses with their exam date, time, and assigned classroom.
*/ */
public class ScheduleCourseController { public class ScheduleCourseController {
@FXML private TableView<CourseScheduleEntry> courseScheduleTable; @FXML
@FXML private TableColumn<CourseScheduleEntry, String> courseCodeColumn; private TableView<CourseScheduleEntry> courseScheduleTable;
@FXML private TableColumn<CourseScheduleEntry, Number> enrolledColumn; @FXML
@FXML private TableColumn<CourseScheduleEntry, String> dateColumn; private TableColumn<CourseScheduleEntry, String> courseCodeColumn;
@FXML private TableColumn<CourseScheduleEntry, String> timeColumn; @FXML
@FXML private TableColumn<CourseScheduleEntry, String> classroomColumn; private TableColumn<CourseScheduleEntry, Number> enrolledColumn;
@FXML
private TableColumn<CourseScheduleEntry, String> dateColumn;
@FXML
private TableColumn<CourseScheduleEntry, String> timeColumn;
@FXML
private TableColumn<CourseScheduleEntry, String> classroomColumn;
private DataManager dataManager; private DataManager dataManager;
// Reference to the current schedule state (set by parent controller or loaded
// from DB)
private Map<String, ExamAssignment> currentAssignments;
private ScheduleConfiguration configuration;
@FXML @FXML
public void initialize() { public void initialize() {
dataManager = DataManager.getInstance(); dataManager = DataManager.getInstance();
// Set up table columns // Set up table columns
courseCodeColumn.setCellValueFactory(cellData -> courseCodeColumn.setCellValueFactory(
new SimpleStringProperty(cellData.getValue().getCourseCode())); cellData -> new SimpleStringProperty(cellData.getValue().getCourseCode()));
enrolledColumn.setCellValueFactory(cellData -> enrolledColumn.setCellValueFactory(
new SimpleIntegerProperty(cellData.getValue().getEnrolledCount())); cellData -> new SimpleIntegerProperty(cellData.getValue().getEnrolledCount()));
dateColumn.setCellValueFactory(cellData -> dateColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getDate()));
new SimpleStringProperty(cellData.getValue().getDate())); timeColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getTime()));
timeColumn.setCellValueFactory(cellData -> classroomColumn.setCellValueFactory(
new SimpleStringProperty(cellData.getValue().getTime())); cellData -> new SimpleStringProperty(cellData.getValue().getClassroom()));
classroomColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getClassroom()));
// Load data // Load data
loadScheduleData(); loadScheduleData();
@@ -48,17 +64,52 @@ public class ScheduleCourseController {
(javafx.collections.ListChangeListener<Course>) c -> loadScheduleData()); (javafx.collections.ListChangeListener<Course>) c -> loadScheduleData());
} }
/**
* Sets the current schedule assignments. Called by parent controller after
* schedule generation.
*/
public void setScheduleData(Map<String, ExamAssignment> assignments, ScheduleConfiguration config) {
this.currentAssignments = assignments;
this.configuration = config;
loadScheduleData();
}
private void loadScheduleData() { private void loadScheduleData() {
ObservableList<CourseScheduleEntry> entries = FXCollections.observableArrayList(); ObservableList<CourseScheduleEntry> entries = FXCollections.observableArrayList();
for (Course course : dataManager.getCourses()) { for (Course course : dataManager.getCourses()) {
entries.add(new CourseScheduleEntry( String courseCode = course.getCourseCode();
course.getCourseCode(), int enrolled = course.getEnrolledStudentsCount();
course.getEnrolledStudentsCount(),
"Not Scheduled", 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); courseScheduleTable.setItems(entries);
@@ -72,7 +123,8 @@ public class ScheduleCourseController {
private final String time; private final String time;
private final String classroom; private final String classroom;
public CourseScheduleEntry(String courseCode, int enrolledCount, String date, String time, String classroom) { public CourseScheduleEntry(String courseCode, int enrolledCount, String date, String time,
String classroom) {
this.courseCode = courseCode; this.courseCode = courseCode;
this.enrolledCount = enrolledCount; this.enrolledCount = enrolledCount;
this.date = date; this.date = date;
@@ -80,10 +132,24 @@ public class ScheduleCourseController {
this.classroom = classroom; this.classroom = classroom;
} }
public String getCourseCode() { return courseCode; } public String getCourseCode() {
public int getEnrolledCount() { return enrolledCount; } return courseCode;
public String getDate() { return date; } }
public String getTime() { return time; }
public String getClassroom() { return classroom; } public int getEnrolledCount() {
return enrolledCount;
}
public String getDate() {
return date;
}
public String getTime() {
return time;
}
public String getClassroom() {
return classroom;
}
} }
} }