Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103-F13-4#63 from lihongguang00/branch…
Browse files Browse the repository at this point in the history
…-Calendar-Updated

[Calendar] Improved Calendar UI
  • Loading branch information
lihongguang00 authored Oct 28, 2023
2 parents 98d2598 + ba340ff commit f19b133
Show file tree
Hide file tree
Showing 38 changed files with 1,305 additions and 55 deletions.
2 changes: 2 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "src/main/java/seedu/address/ui"
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ shadowJar {
run {
enableAssertions = true
}

defaultTasks 'clean', 'test'
1 change: 0 additions & 1 deletion src/main/java/seedu/address/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class Main {
private static Logger logger = LogsCenter.getLogger(Main.class);

public static void main(String[] args) {

// As per https://github.com/openjdk/jfx/blob/master/doc-files/release-notes-16.md
// JavaFX 16 (or later) runtime logs a warning at startup if JavaFX classes are loaded from
// the classpath instead of a module.
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.calendar.ReadOnlyCalendar;
import seedu.address.model.event.Event;
import seedu.address.model.person.Person;

Expand All @@ -31,9 +32,19 @@ public interface Logic {
*/
ReadOnlyAddressBook getAddressBook();

/** Returns an unmodifiable view of the filtered list of persons */
/**
* Returns the Calendar.
*
* @return the Calendar.
*/
ReadOnlyCalendar getCalendar();

/** Returns an unmodifiable view of the filtered list of events */
ObservableList<Event> getEventList();

/** Returns an unmodifiable view of the filtered list of events for the week */
ObservableList<Event> getCurrentWeekEventList();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.calendar.ReadOnlyCalendar;
import seedu.address.model.event.Event;
import seedu.address.model.person.Person;
import seedu.address.storage.Storage;
Expand Down Expand Up @@ -68,11 +69,21 @@ public ReadOnlyAddressBook getAddressBook() {
return model.getAddressBook();
}

@Override
public ReadOnlyCalendar getCalendar() {
return model.getCalendar();
}

@Override
public ObservableList<Event> getEventList() {
return model.getEventList();
}

@Override
public ObservableList<Event> getCurrentWeekEventList() {
return model.getCurrentWeekEventList();
}

@Override
public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public interface Model {
/** Returns a view of the event list */
ObservableList<Event> getEventList();

/** Returns a view of the event list for the current week */
ObservableList<Event> getCurrentWeekEventList();

/** Returns an unmodifiable view of the filtered person list */
ObservableList<Person> getFilteredPersonList();

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public ObservableList<Event> getEventList() {
return calendar.getEventList();
}

@Override
public ObservableList<Event> getCurrentWeekEventList() {
return calendar.getCurrentWeekEventList();
}

@Override
public boolean canAddEvent(Event event) {
return calendar.canAddEvent(event);
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/seedu/address/model/calendar/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static java.util.Objects.requireNonNull;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Optional;

Expand All @@ -15,8 +17,14 @@
* Represents a calendar that stores and manages events.
*/
public class Calendar implements ReadOnlyCalendar {
private static final int DAYS_IN_WEEK = 7;
private static final LocalDate DATE_OF_START_OF_CURRENT_WEEK = LocalDate.now().minusDays(
LocalDate.now().getDayOfWeek().getValue() - 1);
private static final LocalDate DATE_OF_END_OF_CURRENT_WEEK = LocalDate.now().plusDays(
DAYS_IN_WEEK - LocalDate.now().getDayOfWeek().getValue());
private final AllDaysEventListManager eventManager;
private final ObservableList<Event> internalList = FXCollections.observableArrayList();
private final ObservableList<Event> internalListForCurrentWeek = FXCollections.observableArrayList();

/**
* Constructs a Calendar object with an empty event tree.
Expand Down Expand Up @@ -80,6 +88,8 @@ public void addEvent(Event event) {
requireNonNull(event);
eventManager.addEvent(event);
internalList.setAll(eventManager.asUnmodifiableObservableList());
internalListForCurrentWeek.setAll(eventManager.asUnmodifiableObservableList(
DATE_OF_START_OF_CURRENT_WEEK, DATE_OF_END_OF_CURRENT_WEEK));
}

/**
Expand All @@ -90,6 +100,8 @@ public void deleteEventAt(LocalDateTime dateTime) {
requireNonNull(dateTime);
eventManager.deleteEventAt(dateTime);
internalList.setAll(eventManager.asUnmodifiableObservableList());
internalListForCurrentWeek.setAll(eventManager.asUnmodifiableObservableList(
DATE_OF_START_OF_CURRENT_WEEK, DATE_OF_END_OF_CURRENT_WEEK));
}

/**
Expand Down Expand Up @@ -145,6 +157,21 @@ public ObservableList<Event> getEventList() {
return internalList;
}

@Override
public ObservableList<Event> getCurrentWeekEventList() {
return internalListForCurrentWeek;
}

@Override
public Optional<LocalTime> getEarliestEventStartTimeInCurrentWeek() {
return getCurrentWeekEventList().stream().min(Event::compareStartTime).map(Event::getStartTime);
}

@Override
public Optional<LocalTime> getLatestEventEndTimeInCurrentWeek() {
return getCurrentWeekEventList().stream().max(Event::compareEndTime).map(Event::getEndTime);
}

@Override
public boolean equals(Object other) {
if (this == other) {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/seedu/address/model/calendar/ReadOnlyCalendar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package seedu.address.model.calendar;

import java.time.LocalTime;
import java.util.Optional;

import javafx.collections.ObservableList;
import seedu.address.model.event.Event;

Expand All @@ -13,4 +16,25 @@ public interface ReadOnlyCalendar {
* @return unmodifiable view of event list.
*/
ObservableList<Event> getEventList();

/**
* Generates an unmodifiable view of the event list for the current week.
*
* @return unmodifiable view of event list for the current week.
*/
ObservableList<Event> getCurrentWeekEventList();

/**
* Retrieves the earliest starting time of any event for the current week in a LocalTime object.
*
* @return the earliest starting time of any event for the current week in a LocalTime object.
*/
Optional<LocalTime> getEarliestEventStartTimeInCurrentWeek();

/**
* Retrieves the latest ending time of any event for the current week in a LocalTime object.
*
* @return the latest ending time of any event for the current week in a LocalTime object.
*/
Optional<LocalTime> getLatestEventEndTimeInCurrentWeek();
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void addEvent(Event event) {
if (!(dayToEventListMap.containsKey(date.toString()))) {
dayToEventListMap.put(date.toString(), new SingleDayEventList(date));
}
dayToEventListMap.get(date.toString()).addEvent(event);
dayToEventListMap.get(date.toString()).addEvent(event.boundEventByDate(date));
}
}

Expand Down Expand Up @@ -137,6 +137,25 @@ public boolean isEmpty() {
public ObservableList<Event> asUnmodifiableObservableList() {
List<Event> list = dayToEventListMap.values().stream()
.flatMap(singleDayEventList -> singleDayEventList.getDayEventList().stream())
.map(Event::getParentEvent).distinct()
.collect(Collectors.toList());

return FXCollections.observableList(list);
}

/**
* Returns the event list storing events that occur between the start and end dates as an unmodifiable
* ObservableList.
*
* @param startDate start date.
* @param endDate end date.
* @return the event list storing events that occur between the start and end dates as an unmodifiable
* ObservableList.
*/
public ObservableList<Event> asUnmodifiableObservableList(LocalDate startDate, LocalDate endDate) {
List<Event> list = dayToEventListMap.values().stream()
.flatMap(singleDayEventList -> singleDayEventList.getDayEventList().stream())
.filter(event -> event.occursBetweenDates(startDate, endDate))
.collect(Collectors.toList());

return FXCollections.observableList(list);
Expand Down
Loading

0 comments on commit f19b133

Please sign in to comment.