Skip to content

Commit

Permalink
Contacts assigned and tasks assigned commands (#113)
Browse files Browse the repository at this point in the history
* Add predicates for assignment of tasks and persons

* Change select command to assigned command

* Add assigned command for tasks

* Refactor and change equality operator to .equals

* Fix trailing whitespaces

* Fix wrong import order

* Fix lint

* Remove contacts select from user guide

* Fix and standardise line breaks in events
  • Loading branch information
JayPeeTeeDee authored Nov 2, 2018
1 parent e4e6d81 commit d7e0330
Show file tree
Hide file tree
Showing 25 changed files with 260 additions and 78 deletions.
8 changes: 1 addition & 7 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ Format:

Format: `contacts find KEYWORD [MORE_KEYWORDS]`

==== Select a contact: `contacts select`

Format: `contacts select INDEX`

Selects the contact identified by the index number used in the displayed contact list.

==== Delete contact: `contacts delete`

Format: `contacts delete INDEX`
Expand All @@ -92,7 +86,7 @@ Format: `contacts assign c/CONTACT_INDEX k/TASK_INDEX`
Format: `contacts unassign c/CONTACT_INDEX k/TASK_INDEX`
// end::assigntasktocontact[]

==== Show tasks assigned to contact:
==== Show tasks assigned to contact: `contacts assigned`

Format: `contacts assigned CONTACT_ID`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Represents a click event in the Calendar Panel
*/
public class CalendarPanelClickEvent extends TaskPanelSelectionChangedEvent {

public CalendarPanelClickEvent(Task newSelection) {
super(newSelection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ public JumpToPersonListRequestEvent(Index targetIndex) {
public String toString() {
return getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ public JumpToTaskListRequestEvent(Index targetIndex) {
public String toString() {
return getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ public NewResultAvailableEvent(String message) {
public String toString() {
return getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.events.BaseEvent;

/**
* Represents a deselection in the Person List Panel
*/
public class PersonPanelDeselectionEvent extends BaseEvent {

@Override
public String toString() {
return getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
public class PersonPanelSelectionChangedEvent extends BaseEvent {


private final Person newSelection;

public PersonPanelSelectionChangedEvent(Person newSelection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ public class ShowHelpRequestEvent extends BaseEvent {
public String toString() {
return getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Represents a deselection in the Task List Panel
*/
public class TaskPanelDeselectionEvent extends BaseEvent {

@Override
public String toString() {
return getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
public class TaskPanelSelectionChangedEvent extends BaseEvent {


private final Task newSelection;

public TaskPanelSelectionChangedEvent(Task newSelection) {
Expand All @@ -23,5 +22,4 @@ public String toString() {
public Task getNewSelection() {
return newSelection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,28 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.IsAssignedToPersonPredicate;
import seedu.address.model.person.Person;

/**
* Selects a person identified using its displayed index from the address book.
* Selects a person identified using its displayed index,
* and the list of tasks will update to show only the tasks assigned to the person
*/
public class SelectCommand extends Command {
public class AssignedCommand extends Command {

public static final String COMMAND_WORD = "select";
public static final String COMMAND_WORD = "assigned";

public static final String MESSAGE_USAGE = getCommandFormat(COMMAND_WORD)
+ ": Selects the person identified by the index number used in the displayed person list.\n"
+ ": Selects the person identified by the index number used in the displayed person "
+ "list and shows the list of tasks assigned to the person.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + getCommandFormat(COMMAND_WORD) + " 1";

public static final String MESSAGE_SELECT_PERSON_SUCCESS = "Selected Person: %1$s";

private final Index targetIndex;

public SelectCommand(Index targetIndex) {
public AssignedCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}

Expand All @@ -44,7 +47,11 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
if (targetIndex.getZeroBased() >= filteredPersonList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
// Retrieve the desired person and update filter
Person desiredPerson = filteredPersonList.get(targetIndex.getZeroBased());
model.updateFilteredTaskList(new IsAssignedToPersonPredicate(desiredPerson));

// Update UI (purely cosmetic for now)
EventsCenter.getInstance().post(new JumpToPersonListRequestEvent(targetIndex));
return new CommandResult(String.format(MESSAGE_SELECT_PERSON_SUCCESS, targetIndex.getOneBased()));

Expand All @@ -53,7 +60,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof SelectCommand // instanceof handles nulls
&& targetIndex.equals(((SelectCommand) other).targetIndex)); // state check
|| (other instanceof AssignedCommand // instanceof handles nulls
&& targetIndex.equals(((AssignedCommand) other).targetIndex)); // state check
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package seedu.address.logic.commands.tasks;

import static java.util.Objects.requireNonNull;

import java.util.List;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.events.ui.JumpToTaskListRequestEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.task.IsAssignedToTaskPredicate;
import seedu.address.model.task.Task;

/**
* Selects a task identified using its displayed index,
* and the list of persons will update to show only the persons that are assigned to the task
*/
public class AssignedCommand extends Command {

public static final String COMMAND_WORD = "assigned";

public static final String MESSAGE_USAGE = getCommandFormat(COMMAND_WORD)
+ ": Selects the task identified by the index number used in the displayed task "
+ "list and shows the list of persons assigned to the task.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + getCommandFormat(COMMAND_WORD) + " 1";

public static final String MESSAGE_SELECT_TASK_SUCCESS = "Selected Task: %1$s";

private final Index targetIndex;

public AssignedCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);

List<Task> filteredTaskList = model.getFilteredTaskList();

if (targetIndex.getZeroBased() >= filteredTaskList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}
// Retrieve the desired task and update filter
Task desiredTask = filteredTaskList.get(targetIndex.getZeroBased());
model.updateFilteredPersonList(new IsAssignedToTaskPredicate(desiredTask));

// Update UI (purely cosmetic for now)
EventsCenter.getInstance().post(new JumpToTaskListRequestEvent(targetIndex));
return new CommandResult(String.format(MESSAGE_SELECT_TASK_SUCCESS, targetIndex.getOneBased()));

}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AssignedCommand // instanceof handles nulls
&& targetIndex.equals(((AssignedCommand) other).targetIndex)); // state check
}
}
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/parser/ContactsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.contacts.AddCommand;
import seedu.address.logic.commands.contacts.AssignCommand;
import seedu.address.logic.commands.contacts.AssignedCommand;
import seedu.address.logic.commands.contacts.ClearCommand;
import seedu.address.logic.commands.contacts.DeleteCommand;
import seedu.address.logic.commands.contacts.EditCommand;
import seedu.address.logic.commands.contacts.FindCommand;
import seedu.address.logic.commands.contacts.ListCommand;
import seedu.address.logic.commands.contacts.SelectCommand;
import seedu.address.logic.commands.contacts.UnassignCommand;
import seedu.address.logic.parser.contacts.AddCommandParser;
import seedu.address.logic.parser.contacts.AssignCommandParser;
import seedu.address.logic.parser.contacts.AssignedCommandParser;
import seedu.address.logic.parser.contacts.DeleteCommandParser;
import seedu.address.logic.parser.contacts.EditCommandParser;
import seedu.address.logic.parser.contacts.FindCommandParser;
import seedu.address.logic.parser.contacts.SelectCommandParser;
import seedu.address.logic.parser.contacts.UnassignCommandParser;
import seedu.address.logic.parser.exceptions.ParseException;

Expand Down Expand Up @@ -62,8 +62,8 @@ public Command parseCommand(String userInput) throws ParseException {
case EditCommand.COMMAND_WORD:
return new EditCommandParser().parse(arguments);

case SelectCommand.COMMAND_WORD:
return new SelectCommandParser().parse(arguments);
case AssignedCommand.COMMAND_WORD:
return new AssignedCommandParser().parse(arguments);

case DeleteCommand.COMMAND_WORD:
return new DeleteCommandParser().parse(arguments);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/parser/TasksParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.tasks.AddCommand;
import seedu.address.logic.commands.tasks.AssignCommand;
import seedu.address.logic.commands.tasks.AssignedCommand;
import seedu.address.logic.commands.tasks.DeleteCommand;
import seedu.address.logic.commands.tasks.EditCommand;
import seedu.address.logic.commands.tasks.FindCommand;
Expand All @@ -19,6 +20,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.logic.parser.tasks.AddCommandParser;
import seedu.address.logic.parser.tasks.AssignCommandParser;
import seedu.address.logic.parser.tasks.AssignedCommandParser;
import seedu.address.logic.parser.tasks.DeleteCommandParser;
import seedu.address.logic.parser.tasks.EditCommandParser;
import seedu.address.logic.parser.tasks.FindCommandParser;
Expand Down Expand Up @@ -61,6 +63,9 @@ public Command parseCommand(String userInput) throws ParseException {
case EditCommand.COMMAND_WORD:
return new EditCommandParser().parse(arguments);

case AssignedCommand.COMMAND_WORD:
return new AssignedCommandParser().parse(arguments);

case DeleteCommand.COMMAND_WORD:
return new DeleteCommandParser().parse(arguments);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.contacts.SelectCommand;
import seedu.address.logic.commands.contacts.AssignedCommand;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new SelectCommand object
* Parses input arguments and creates a new AssignedCommand object
*/
public class SelectCommandParser implements Parser<SelectCommand> {
public class AssignedCommandParser implements Parser<AssignedCommand> {

/**
* Parses the given {@code String} of arguments in the context of the SelectCommand
* and returns an SelectCommand object for execution.
* Parses the given {@code String} of arguments in the context of the AssignedCommand
* and returns an AssignedCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public SelectCommand parse(String args) throws ParseException {
public AssignedCommand parse(String args) throws ParseException {
try {
Index index = ParserUtil.parseIndex(args);
return new SelectCommand(index);
return new AssignedCommand(index);
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, SelectCommand.MESSAGE_USAGE), pe, true);
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AssignedCommand.MESSAGE_USAGE), pe, true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package seedu.address.logic.parser.tasks;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.tasks.AssignedCommand;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.contacts.ParserUtil;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new AssignedCommand object
*/
public class AssignedCommandParser implements Parser<AssignedCommand> {

/**
* Parses the given {@code String} of arguments in the context of the AssignedCommand
* and returns an AssignedCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public AssignedCommand parse(String args) throws ParseException {
try {
Index index = ParserUtil.parseIndex(args);
return new AssignedCommand(index);
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AssignedCommand.MESSAGE_USAGE), pe, true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package seedu.address.model.person;

import java.util.function.Predicate;

import seedu.address.model.task.Task;

/**
* Tests that a {@code Task} is assigned to the desired person (i.e. task contains id of {@code Person})
*/
public class IsAssignedToPersonPredicate implements Predicate<Task> {
private final Person person;

public IsAssignedToPersonPredicate(Person person) {
this.person = person;
}

@Override
public boolean test(Task task) {
return task.getPersonIds().stream()
.anyMatch(personId -> person.getId().equals(personId));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof IsAssignedToPersonPredicate // instanceof handles nulls
&& person.equals(((IsAssignedToPersonPredicate) other).person)); // state check
}

}
Loading

0 comments on commit d7e0330

Please sign in to comment.