mirror of
https://github.com/sabazadam/Se302.git
synced 2025-12-31 12:21:22 +00:00
Task 2.3 Step 1: Populate exam date, time, classroom in Course Schedule View
This commit is contained in:
@@ -8,37 +8,53 @@ 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<CourseScheduleEntry> courseScheduleTable;
|
||||
@FXML private TableColumn<CourseScheduleEntry, String> courseCodeColumn;
|
||||
@FXML private TableColumn<CourseScheduleEntry, Number> enrolledColumn;
|
||||
@FXML private TableColumn<CourseScheduleEntry, String> dateColumn;
|
||||
@FXML private TableColumn<CourseScheduleEntry, String> timeColumn;
|
||||
@FXML private TableColumn<CourseScheduleEntry, String> classroomColumn;
|
||||
@FXML
|
||||
private TableView<CourseScheduleEntry> courseScheduleTable;
|
||||
@FXML
|
||||
private TableColumn<CourseScheduleEntry, String> courseCodeColumn;
|
||||
@FXML
|
||||
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;
|
||||
|
||||
// Reference to the current schedule state (set by parent controller or loaded
|
||||
// from DB)
|
||||
private Map<String, ExamAssignment> currentAssignments;
|
||||
private ScheduleConfiguration configuration;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
dataManager = DataManager.getInstance();
|
||||
|
||||
// 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()));
|
||||
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()));
|
||||
|
||||
// Load data
|
||||
loadScheduleData();
|
||||
@@ -48,17 +64,52 @@ public class ScheduleCourseController {
|
||||
(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() {
|
||||
ObservableList<CourseScheduleEntry> entries = FXCollections.observableArrayList();
|
||||
|
||||
for (Course course : dataManager.getCourses()) {
|
||||
entries.add(new CourseScheduleEntry(
|
||||
course.getCourseCode(),
|
||||
course.getEnrolledStudentsCount(),
|
||||
"Not Scheduled",
|
||||
"-",
|
||||
"-"
|
||||
));
|
||||
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);
|
||||
@@ -72,7 +123,8 @@ public class ScheduleCourseController {
|
||||
private final String time;
|
||||
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.enrolledCount = enrolledCount;
|
||||
this.date = date;
|
||||
@@ -80,10 +132,24 @@ public class ScheduleCourseController {
|
||||
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; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user