Skip to content

Commit

Permalink
Merge pull request #66 from justinlengch/updated-lesson-class
Browse files Browse the repository at this point in the history
Change MainWindow to update student and schedule list after each command
  • Loading branch information
leepoeaik authored Apr 4, 2024
2 parents 38fa4bd + 139a7c1 commit 0498fb8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public interface Logic {

/** Returns an unmodifiable view of the filtered list of students */
ObservableList<Student> getFilteredStudentList();

/**
* Returns the user prefs' address book file path.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public CommandResult execute(Model model) throws CommandException {
}

private String generateSuccessMessage(Student editedStudent) {
return String.format(MESSAGE_ADD_LESSON_SUCCESS, editedStudent);
return String.format(MESSAGE_ADD_LESSON_SUCCESS, Messages.format(editedStudent));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public AddLessonCommand parse(String args) throws ParseException {
LocalTime timeDetail = LocalTime.parse(lessonDetails[1], TIME_FORMATTER);
int isCompleted;
if (lessonDetails.length == 3) {
isCompleted = Integer.parseInt(lessonDetails[3]);
isCompleted = Integer.parseInt(lessonDetails[2]);
return new AddLessonCommand(index, dateDetail, timeDetail, isCompleted);
} else {
return new AddLessonCommand(index, dateDetail, timeDetail);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.function.Predicate;
import java.util.logging.Logger;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import seedu.address.commons.core.GuiSettings;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void setStudent(Student target, Student editedStudent) {
*/
@Override
public ObservableList<Student> getFilteredStudentList() {
return filteredStudents;
return FXCollections.unmodifiableObservableList(filteredStudents);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/student/Lesson.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ public int hashCode() {
* Format state as text for viewing.
*/
public String toString() {
return this.subject + " " + this.date.toString() + " " + this.time;
return this.subject + " " + this.date.toString() + " " + this.time + " ";
}
}
19 changes: 17 additions & 2 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,21 @@ private void handleExit() {
primaryStage.hide();
}

public StudentListPanel getStudentListPanel() {
return studentListPanel;
/**
* Updates Schedule List Panel.
*/
public void updateScheduleListPanel() {
scheduleListPanelPlaceholder.getChildren().clear();
scheduleListPanel = new ScheduleListPanel(logic.getFilteredStudentList());
scheduleListPanelPlaceholder.getChildren().add(scheduleListPanel.getRoot());
}
/**
* Updates Student List Panel.
*/
public void updateStudentListPanel() {
studentListPanelPlaceholder.getChildren().clear();
studentListPanel = new StudentListPanel(logic.getFilteredStudentList());
studentListPanelPlaceholder.getChildren().add(studentListPanel.getRoot());
}

/**
Expand All @@ -197,6 +210,8 @@ private CommandResult executeCommand(String commandText) throws CommandException
if (commandResult.isExit()) {
handleExit();
}
updateStudentListPanel();
updateScheduleListPanel();

return commandResult;
} catch (CommandException | ParseException e) {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/seedu/address/ui/ScheduleListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class ScheduleListPanel extends UiPart<Region> {
private static final String FXML = "ScheduleListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(ScheduleListPanel.class);
private ObservableList<Student> studentList;

@FXML
private ListView<Pair<Student, Lesson>> scheduleListView;
Expand All @@ -32,8 +33,9 @@ public class ScheduleListPanel extends UiPart<Region> {
*/
public ScheduleListPanel(ObservableList<Student> studentList) {
super(FXML);
this.studentList = studentList;

scheduleListView.setItems(transformList(studentList));
scheduleListView.setItems(transformList(this.studentList));
scheduleListView.setCellFactory(listView -> new ScheduleListViewCell());
}

Expand All @@ -48,7 +50,9 @@ public ObservableList<Pair<Student, Lesson>> transformList(ObservableList<Studen
for (Student student : studentList) {
List<Lesson> studentLesson = student.getLessons();
for (Lesson l : studentLesson) {
scheduleList.add(new Pair(student, l));
if (l.getLessonStatus() == 0) {
scheduleList.add(new Pair(student, l));
}
}
}

Expand Down Expand Up @@ -78,7 +82,6 @@ class SortDate implements Comparator<Pair<Student, Lesson>> {

@Override
public int compare(Pair<Student, Lesson> o1, Pair<Student, Lesson> o2) {
// TODO: implement your logic here
return o1.getValue().getDate().compareTo(o2.getValue().getDate());
}
}
Expand Down

0 comments on commit 0498fb8

Please sign in to comment.