Skip to content

Commit

Permalink
Merge pull request #199 from SeaHogs/branch-sync-timetable
Browse files Browse the repository at this point in the history
Branch sync timetable
  • Loading branch information
Ella-e authored Apr 15, 2024
2 parents 42f917f + 8acf42a commit b23602f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
4 changes: 0 additions & 4 deletions src/main/java/vitalconnect/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ public ObservableList<Appointment> findAppointmentsByNric(Nric nric) {
}
@Override
public ObservableList<Appointment> getFoundAppointmentList() {
System.out.println("found apt list");
for (Appointment a: foundApt) {
System.out.println(a);
}
FXCollections.sort(foundApt, Comparator.comparing(Appointment::getDateTime));
return foundApt;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vitalconnect/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void fillInnerParts() {
CommandBox commandBox = new CommandBox(this::executeCommand);
commandBoxPlaceholder.getChildren().add(commandBox.getRoot());

timetable = new Timetable(logic.getFilteredAppointmentList());
timetable = new Timetable(logic.getFilteredAppointmentList(), logic.getFilteredPersonList());
calendarViewPlaceholder.getChildren().add(timetable.getCalendarView());
calendarViewPlaceholder.addEventFilter(MouseEvent.MOUSE_DRAGGED , new EventHandler<MouseEvent>() {
@Override
Expand Down
39 changes: 28 additions & 11 deletions src/main/java/vitalconnect/ui/Timetable.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import vitalconnect.model.Appointment;
import vitalconnect.model.person.Person;

/**
* A custom UI component representing a timetable view with appointments displayed using a calendar view.
Expand All @@ -28,9 +29,11 @@ public class Timetable extends UiPart<Region> {

/**
* Constructs a new Timetable instance.
* @param appointmentList The list of appointments to be displayed in the timetable.
*
* @param appointmentList The list of appointments to be displayed in the timetable.
* @param personList The list of persons to be displayed in the timetable.
*/
public Timetable(ObservableList<Appointment> appointmentList) {
public Timetable(ObservableList<Appointment> appointmentList, ObservableList<Person> personList) {
super(FXML);
this.appointmentList = appointmentList;
calendarView = new CalendarView();
Expand All @@ -48,13 +51,29 @@ public Timetable(ObservableList<Appointment> appointmentList) {
for (Appointment removedAppointment : change.getRemoved()) {
removeAppointmentFromCalendar(removedAppointment);
}
} else if (change.wasUpdated()) {
// dummy code to test where edit is going
// edita does not go through model as expected
// calendarView.getCalendarSources().get(0).getCalendars().get(0).clear();
// for (Appointment updatedAppointment : appointmentList) {
// addAppointmentToCalendar(updatedAppointment);
// }
} else if (change.wasReplaced() || change.wasUpdated()
|| change.wasPermutated() || change.wasUpdated()) {
calendarView.getCalendarSources().get(0).getCalendars().get(0).clear();
for (Appointment updatedAppointment : appointmentList) {
addAppointmentToCalendar(updatedAppointment);
}
}
}
});

// A listener to update the calendar view when the person list changes
// because someone's code need lista to update appointment list (ಠ_ಠ)
personList.addListener((ListChangeListener<Person>) change -> {
while (change.next()) {
if (change.wasReplaced()) {
for (Person person : change.getAddedSubList()) {
calendarView.getCalendarSources().get(0).getCalendars().get(0)
.findEntries(person.getIdentificationInformation().getNric().nric)
.forEach(entry -> {
entry.setTitle(person.getIdentificationInformation().getName().fullName
+ " " + person.getIdentificationInformation().getNric().nric);
});
}
}
}
});
Expand Down Expand Up @@ -160,8 +179,6 @@ private void addEntriesToCalendar(Calendar appointmentOfTheDay) {
entry.changeEndDate(app.getDateTime().toLocalDate());
entry.changeStartTime(app.getDateTime().toLocalTime());
entry.changeEndTime(app.getDateTime().toLocalTime().plusMinutes(app.getDuration() * 15L));
System.out.println(app.getDateTime().toLocalTime());
System.out.println(entry);
appointmentOfTheDay.addEntries(entry);
}
}
Expand Down

0 comments on commit b23602f

Please sign in to comment.