Skip to content

Commit

Permalink
Merge pull request #185 from limweiliang/v1.3b-show-upcoming-friend-e…
Browse files Browse the repository at this point in the history
…vents

V1.3b show upcoming friend events
  • Loading branch information
AryanSarswat authored Mar 31, 2022
2 parents 98f9e10 + 80a4de1 commit e3dfd6a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/logic/commands/ShowFriendCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

import java.time.LocalDate;
import java.util.function.Predicate;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.event.Event;
import seedu.address.model.event.EventDateIsAfterPredicate;
import seedu.address.model.event.EventFriendNamesContainSubstringPredicate;
import seedu.address.model.person.FriendName;
import seedu.address.model.person.Person;

Expand Down Expand Up @@ -69,6 +75,13 @@ public CommandResult execute(Model model) throws CommandException {
//updates UI to only show a single person
model.updateFilteredPersonList(x -> x.isSamePerson(personToShow));

// updates UI to show upcoming events tied to this person
// TODO: Known bug, will show upcoming events for today that have already passed...
Predicate<Event> upcomingEventPredicate = new EventDateIsAfterPredicate(LocalDate.now());
Predicate<Event> friendPredicate = new EventFriendNamesContainSubstringPredicate(personToShow.getName().toString());

model.updateFilteredEventList(event -> upcomingEventPredicate.test(event) && friendPredicate.test(event));

return new CommandResult(String.format(MESSAGE_SUCCESS, personToShow.getName()), false,
false, false, true, false);
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/seedu/address/ui/ExpandedPersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import java.util.Comparator;
import java.util.List;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import seedu.address.model.event.Event;
import seedu.address.model.person.Log;
import seedu.address.model.person.Person;

Expand All @@ -27,6 +30,7 @@ public class ExpandedPersonCard extends UiPart<Region> {
*/

private final Person person;
private EventListPanel upcomingEventsPanel;

@FXML
private HBox cardPane;
Expand All @@ -43,12 +47,14 @@ public class ExpandedPersonCard extends UiPart<Region> {
@FXML
private FlowPane tags;
@FXML
private StackPane upcomingEventsPanelPlaceholder;
@FXML
private Label logs;

/**
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
* Creates a {@code PersonCard} with the given {@code Person} and index to display.
*/
public ExpandedPersonCard(Person person) {
public ExpandedPersonCard(Person person, ObservableList<Event> eventList) {
super(FXML);
this.person = person;
name.setText(person.getName().fullName);
Expand All @@ -63,6 +69,9 @@ public ExpandedPersonCard(Person person) {
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));

upcomingEventsPanel = new EventListPanel(eventList);
upcomingEventsPanelPlaceholder.getChildren().add(upcomingEventsPanel.getRoot());

//displaying each log
StringBuilder sb = new StringBuilder();
List<Log> logList = person.getLogs();
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/seedu/address/ui/ExpandedPersonListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.scene.control.ListView;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.event.Event;
import seedu.address.model.person.Person;

/**
Expand All @@ -16,17 +17,19 @@
public class ExpandedPersonListPanel extends UiPart<Region> {
private static final String FXML = "ExpandedPersonListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(ExpandedPersonListPanel.class);
private final ObservableList<Event> eventList;

@FXML
private ListView<Person> personListView;

/**
* Creates a {@code PersonListPanel} with the given {@code ObservableList}.
* Creates a {@code PersonListPanel} with the given {@code ObservableList} of event and person.
*/
public ExpandedPersonListPanel(ObservableList<Person> personList) {
public ExpandedPersonListPanel(ObservableList<Person> personList, ObservableList<Event> eventList) {
super(FXML);
personListView.setItems(personList);
personListView.setCellFactory(listView -> new PersonListViewCell());
this.eventList = eventList;
}

/**
Expand All @@ -40,9 +43,8 @@ protected void updateItem(Person person, boolean empty) {
setGraphic(null);
setText(null);
} else {
setGraphic(new ExpandedPersonCard(person).getRoot());
setGraphic(new ExpandedPersonCard(person, eventList).getRoot());
}
}
}

}
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
* Fills up all the placeholders of this window.
*/
void fillInnerParts() {
expandedPersonListPanel = new ExpandedPersonListPanel(logic.getFilteredPersonList());
expandedPersonListPanel =
new ExpandedPersonListPanel(logic.getFilteredPersonList(), logic.getFilteredEventList());
expandedPersonListPanelPlaceholder.getChildren();
expandedPersonListPanelPlaceholder.getChildren().add(expandedPersonListPanel.getRoot());

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/EventListPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.VBox?>

<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<VBox minHeight="10.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<ListView fx:id="eventListView" VBox.vgrow="ALWAYS" />
</VBox>
4 changes: 3 additions & 1 deletion src/main/resources/view/ExpandedPersonListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/11" xmlns:fx="http://javafx.com/fxml/1">
<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<GridPane HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
Expand Down Expand Up @@ -55,6 +56,7 @@
<Font size="30.0" />
</font>
</Label>
<StackPane fx:id="upcomingEventsPanelPlaceholder" minHeight="-Infinity" prefHeight="100.0" />
<Label styleClass="cell_header_label" text="Logs:" wrapText="true">
<VBox.margin>
<Insets top="30.0" />
Expand Down

0 comments on commit e3dfd6a

Please sign in to comment.