mirror of
https://github.com/sabazadam/Se302.git
synced 2025-12-31 20:31:22 +00:00
Task 2.4 Step 1: Show actual exam assignments per classroom
This commit is contained in:
@@ -10,80 +10,147 @@ import javafx.scene.control.Label;
|
|||||||
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.Classroom;
|
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 org.example.se302.service.DataManager;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for the Classroom Schedule view.
|
* Controller for the Classroom Schedule view.
|
||||||
|
* Shows exam assignments for each classroom.
|
||||||
*/
|
*/
|
||||||
public class ScheduleClassroomController {
|
public class ScheduleClassroomController {
|
||||||
|
|
||||||
@FXML private ComboBox<Classroom> classroomComboBox;
|
@FXML
|
||||||
@FXML private Label selectedClassroomLabel;
|
private ComboBox<Classroom> classroomComboBox;
|
||||||
@FXML private TableView<ClassroomSlotEntry> scheduleTable;
|
@FXML
|
||||||
@FXML private TableColumn<ClassroomSlotEntry, String> dateColumn;
|
private Label selectedClassroomLabel;
|
||||||
@FXML private TableColumn<ClassroomSlotEntry, String> timeColumn;
|
@FXML
|
||||||
@FXML private TableColumn<ClassroomSlotEntry, String> courseColumn;
|
private TableView<ClassroomSlotEntry> scheduleTable;
|
||||||
@FXML private TableColumn<ClassroomSlotEntry, Number> studentsColumn;
|
@FXML
|
||||||
@FXML private TableColumn<ClassroomSlotEntry, String> utilizationColumn;
|
private TableColumn<ClassroomSlotEntry, String> dateColumn;
|
||||||
@FXML private Label utilizationLabel;
|
@FXML
|
||||||
|
private TableColumn<ClassroomSlotEntry, String> timeColumn;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<ClassroomSlotEntry, String> courseColumn;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<ClassroomSlotEntry, Number> studentsColumn;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<ClassroomSlotEntry, String> utilizationColumn;
|
||||||
|
@FXML
|
||||||
|
private Label utilizationLabel;
|
||||||
|
|
||||||
private DataManager dataManager;
|
private DataManager dataManager;
|
||||||
|
|
||||||
@FXML
|
// Reference to the current schedule state (set by parent controller)
|
||||||
public void initialize() {
|
private Map<String, ExamAssignment> currentAssignments;
|
||||||
dataManager = DataManager.getInstance();
|
private ScheduleConfiguration configuration;
|
||||||
|
|
||||||
// Populate classroom combo box
|
@FXML
|
||||||
classroomComboBox.setItems(dataManager.getClassrooms());
|
public void initialize() {
|
||||||
|
dataManager = DataManager.getInstance();
|
||||||
|
|
||||||
// Set up table columns
|
// Populate classroom combo box
|
||||||
dateColumn.setCellValueFactory(cellData ->
|
classroomComboBox.setItems(dataManager.getClassrooms());
|
||||||
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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
// Set up table columns
|
||||||
private void onShowSchedule() {
|
dateColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getDate()));
|
||||||
Classroom selected = classroomComboBox.getValue();
|
timeColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getTime()));
|
||||||
if (selected == null) return;
|
courseColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getCourse()));
|
||||||
|
studentsColumn.setCellValueFactory(
|
||||||
selectedClassroomLabel.setText("Schedule for: " + selected.getClassroomId() +
|
cellData -> new SimpleIntegerProperty(cellData.getValue().getStudentCount()));
|
||||||
" (Capacity: " + selected.getCapacity() + ")");
|
utilizationColumn.setCellValueFactory(
|
||||||
|
cellData -> new SimpleStringProperty(cellData.getValue().getUtilization()));
|
||||||
// For demo: show empty schedule
|
|
||||||
ObservableList<ClassroomSlotEntry> 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDate() { return date; }
|
/**
|
||||||
public String getTime() { return time; }
|
* Sets the current schedule assignments. Called by parent controller after
|
||||||
public String getCourse() { return course; }
|
* schedule generation.
|
||||||
public int getStudentCount() { return studentCount; }
|
*/
|
||||||
public String getUtilization() { return utilization; }
|
public void setScheduleData(Map<String, ExamAssignment> 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<ClassroomSlotEntry> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user