Skip to content

Commit

Permalink
Bug fix and add diagrams for list event
Browse files Browse the repository at this point in the history
 - Fix a bug that the events in the event list window are not sorted
 - Add activity and sequence diagrams for `list events` command
  • Loading branch information
larrywang0701 committed Nov 13, 2023
1 parent 6ee412d commit 5c9199a
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 15 deletions.
24 changes: 21 additions & 3 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,16 @@ The following activity diagram summarizes what happens when the `DeleteNoteComma
This feature allows users to add and remove `Event` to any `Person` in the contact list. It provides an easy way for users to keep track of events with the contacts.

#### Overview: Event:
The adding and removing of `Event` begins with the parsing of the `AddEventCommand` and `DeleteEventCommand` using the `AddEventCommandParser` and `DeleteEventCommandParser` respectively.
The `AddEventCommand` and `DeleteEventCommand` will then be constructed and executed by the `Model`.
The adding, listing and removing of `Event` begins with the parsing of the `AddEventCommand`, `ListEventCommand` and `DeleteEventCommand` using the `AddEventCommandParser`, `ListEventCommandParser` and `DeleteEventCommandParser` respectively.
The `AddEventCommand`, `ListEventCommand` and `DeleteEventCommand` will then be constructed and executed by the `Model`.

The activity diagram below shows the action sequence of adding an `Event` to a contact.

<puml src="diagrams/event/EventSequenceDiagram.puml"/>
<puml src="diagrams/event/AddEventSequenceDiagram.puml"/>

The activity diagram below shows the action sequence of listing events by executing `list events` command.

<puml src="diagrams/event/ListEventsSequenceDiagram.puml"/>

<box type="info" seamless>

Expand Down Expand Up @@ -454,6 +458,20 @@ The following activity diagram summarizes what happens when `AddEventCommand` is

<puml src="diagrams/event/AddEventActivityDiagram.puml"/>

##### Implementing `ListEventCommand`
`ListEventCommand` extends from the abstract class `ListCommand`,
inheriting `list` as the primary command word and having `events` as its secondary command word.
It internally stores `filterStartTime`, `filterEndTime` (both can be null if filtering is not used) and `sortAscending` which are given by the [parser](#implementing-addeventcommandparser).

When the command is executed, it carries out the following operations:
1. Using the `filterStartTime` and `filterEndTime` to filter all events in the global event list, or set the filter to always returns `true` if both `filterStartTime` and `filterEndTime` is null (in order to show the full event list to the user)
2. Sort the filtered event list in ascending or descending order based on `sortAscending`
3. Lastly a `CommandResult` with the filtered-sorted event list in String and with `listEvent = true` to tell `MainWindow` to show the event list window.

The following activity diagram summarizes what happens when user executes `list events` from UI.

<puml src="diagrams/event/ListEventsActivityDiagram.puml"/>

##### Implementing `DeleteEventCommand`
`DeleteEventCommand` extends from the abstract class `DeleteCommand`,
inheriting `delete` as the primary command word and having `event` as its secondary command word.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ activate AddEventCommandParser
AddEventCommandParser -> AddCommandParser
deactivate AddEventCommandParser

AddCommandParser -> AddEventCommandParser : parse(commandText)
AddCommandParser -> AddEventCommandParser : parse(args)
activate AddEventCommandParser

create AddEventCommand
Expand Down
28 changes: 28 additions & 0 deletions docs/diagrams/event/ListEventsActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@startuml
skin rose
skinparam ActivityFontSize 15
skinparam ArrowFontSize 12
start
:User executes list event command;

if () then ([both exist -st and -et argument or neither exists -st nor -et argument])
if () then ([exist -st argument])
if() then([valid start time and end time])
:Filter the event based on start and end time;
else ([else])
:Throw CommandException;
endif
else ([else])
endif
if () then ([exists -descending argument])
:Sort events in descending order;
else ([else])
:Sort events in ascending order;
endif
:Returns Result message;
:Open a new window to display the event list;
else ([else])
:Throw CommandException;
endif
stop
@enduml
114 changes: 114 additions & 0 deletions docs/diagrams/event/ListEventsSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
@startuml
!include ../style.puml
skinparam ArrowFontStyle plain

box UI UI_COLOR_T1
participant ":MainWindow" as MainWindow UI_COLOR
participant ":EventListWindow" as EventListWindow UI_COLOR
end box

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":ListCommandParser" as ListCommandParser LOGIC_COLOR
participant ":ListEventCommandParser" as ListEventCommandParser LOGIC_COLOR
participant ":ListEventCommand" as ListEventCommand LOGIC_COLOR
participant "commandResult:CommandResult" as CommandResult LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
end box

-> MainWindow : executeCommand(commandText)
activate MainWindow
MainWindow -> LogicManager : execute(commandText)
activate LogicManager

LogicManager -> AddressBookParser : parseCommand(commandText)
activate AddressBookParser

create ListCommandParser
AddressBookParser -> ListCommandParser
activate ListCommandParser

ListCommandParser --> AddressBookParser
deactivate ListCommandParser

AddressBookParser -> ListCommandParser : parse(commandText)
activate ListCommandParser

create ListEventCommandParser
ListCommandParser -> ListEventCommandParser
activate ListEventCommandParser

ListEventCommandParser -> ListCommandParser
deactivate ListEventCommandParser

ListCommandParser -> ListEventCommandParser : parse(args)
activate ListEventCommandParser

create ListEventCommand
ListEventCommandParser -> ListEventCommand
activate ListEventCommand

ListEventCommand --> ListEventCommandParser
deactivate ListEventCommand

ListEventCommandParser --> ListCommandParser
deactivate ListEventCommandParser
ListEventCommandParser -[hidden]-> ListCommandParser
destroy ListEventCommandParser

ListCommandParser --> AddressBookParser
deactivate ListCommandParser
ListCommandParser -[hidden]-> AddressBookParser
destroy ListCommandParser

AddressBookParser --> LogicManager
deactivate AddressBookParser

LogicManager -> ListEventCommand : execute()
activate ListEventCommand

ListEventCommand -> Model: updateFilteredEventList(predicate)
activate Model

Model -> ListEventCommand
deactivate Model

ListEventCommand -> Model: generateSortedFilteredEventList(comparator)
activate Model
ListEventCommand <- Model : sortedFilteredEventList
deactivate Model

create CommandResult
ListEventCommand -> CommandResult
activate CommandResult

CommandResult --> ListEventCommand : commandResult
deactivate CommandResult

ListEventCommand --> LogicManager : commandResult
deactivate ListEventCommand
ListEventCommand -[hidden]-> LogicManager
destroy ListEventCommand

MainWindow <-- LogicManager : commandResult
deactivate LogicManager
MainWindow --> MainWindow : handleEventList()
activate MainWindow
MainWindow --> LogicManager : getSortedFilteredEventList()
activate LogicManager
LogicManager --> Model : getSortedFilteredEventList()
activate Model
LogicManager <-- Model : sortedFilteredEventList
deactivate Model
MainWindow <-- LogicManager : sortedFilteredEventList
deactivate LogicManager
MainWindow --> EventListWindow : show(events)
activate EventListWindow
MainWindow <-- EventListWindow
deactivate EventListWindow
deactivate MainWindow
@enduml
3 changes: 3 additions & 0 deletions docs/team/larrywang0701.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@

- Wrote the User Stories part in the DG [#10](https://github.com/AY2324S1-CS2103T-W16-1/tp/pull/10)
- Add details about secondary command parser in DG [#47](https://github.com/AY2324S1-CS2103T-W16-1/tp/pull/47/files#diff-1a95edf069a4136e9cb71bee758b0dc86996f6051f0d438ec2c424557de7160b)
- UML diagrams that I made:
<puml src="diagrams/event/AddEventSequenceDiagram.puml"/>
<puml src="diagrams/event/AddEventSequenceDiagram.puml"/>

- #### Contributions to team-based tasks

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of events */
ObservableList<Event> getFilteredEventList();

ObservableList<Event> getSortedFilteredEventList();

/**
* Returns the user prefs' address book file path.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public ObservableList<Event> getFilteredEventList() {
return model.getFilteredEventList();
}

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

Check warning on line 82 in src/main/java/seedu/address/logic/LogicManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/LogicManager.java#L82

Added line #L82 was not covered by tests
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public CommandResult execute(Model model) throws CommandException {
result = MESSAGE_FILTERED;
}
result += this.sortAscending ? MESSAGE_ASCENDING : MESSAGE_DESCENDING;
List<Event> eventList = model.getSortedFilteredEventList((o1, o2) -> {
List<Event> eventList = model.generateSortedFilteredEventList((o1, o2) -> {
LocalDateTime startTime1 = o1.getStartTime();
LocalDateTime startTime2 = o2.getStartTime();
return (startTime1.isBefore(startTime2)
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,27 @@ public interface Model {
/** Returns an unmodifiable view of the filtered event list */
ObservableList<Event> getFilteredEventList();

/**
* Generate a new list from sorting the filtered event list by the given {@code comparator}
* and return the generated list.
* @throws NullPointerException if {@code comparator} is null.
*/
List<Event> generateSortedFilteredEventList(Comparator<? super Event> comparator);

/**
* Return the sorted-filtered-list generated
* by {@code generateSortedFilteredEventList(Comparator<? super Event> comparator)}
* @throws NullPointerException if {@code sorted-filtered-list} is null
* (never called {@code generateSortedFilteredEventList(Comparator<? super Event> comparator)} before).
*/
ObservableList<Event> getSortedFilteredEventList();

/**
* Updates the filter of the filtered event list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredEventList(Predicate<Event> predicate);

/**
* Get a list from sorting the filtered event list by the given {@code comparator}.
* @throws NullPointerException if {@code comparator} is null.
*/
List<Event> getSortedFilteredEventList(Comparator<? super Event> comparator);

/**
* Find a person by index.
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import seedu.address.commons.core.GuiSettings;
Expand All @@ -31,6 +32,8 @@ public class ModelManager implements Model {
private final FilteredList<Person> filteredPersons;
private final FilteredList<Event> filteredEvents;

private ObservableList<Event> sortedFilteredEvents;

/**
* Initializes a ModelManager with the given addressBook and userPrefs.
*/
Expand Down Expand Up @@ -149,9 +152,17 @@ public void updateFilteredEventList(Predicate<Event> predicate) {
}

@Override
public List<Event> getSortedFilteredEventList(Comparator<? super Event> comparator) {
public List<Event> generateSortedFilteredEventList(Comparator<? super Event> comparator) {
requireNonNull(comparator);
return filteredEvents.stream().sorted(comparator).collect(Collectors.toUnmodifiableList());
sortedFilteredEvents = FXCollections.observableList(filteredEvents.stream()
.sorted(comparator).collect(Collectors.toUnmodifiableList()));
return sortedFilteredEvents;
}

@Override
public ObservableList<Event> getSortedFilteredEventList() {
requireNonNull(sortedFilteredEvents);
return this.sortedFilteredEvents;

Check warning on line 165 in src/main/java/seedu/address/model/ModelManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/ModelManager.java#L164-L165

Added lines #L164 - L165 were not covered by tests
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void setWindowDefaultSize(GuiSettings guiSettings) {
@FXML
public void handleEventList() {
if (!eventListWindow.isShowing()) {
eventListWindow.show(logic.getFilteredEventList());
eventListWindow.show(logic.getSortedFilteredEventList());

Check warning on line 152 in src/main/java/seedu/address/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/MainWindow.java#L152

Added line #L152 was not covered by tests
} else {
eventListWindow.focus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,19 @@ public ObservableList<Event> getFilteredEventList() {
}

@Override
public void updateFilteredEventList(Predicate<Event> predicate) {
public List<Event> generateSortedFilteredEventList(Comparator<? super Event> comparator) {
throw new AssertionError("This method should not be called.");
}

@Override
public List<Event> getSortedFilteredEventList(Comparator<? super Event> comparator) {
public ObservableList<Event> getSortedFilteredEventList() {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredEventList(Predicate<Event> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public Person findPersonByIndex(int index) {
Expand Down

0 comments on commit 5c9199a

Please sign in to comment.