forked from nus-cs2103-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contacts assigned and tasks assigned commands (#113)
* 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
1 parent
e4e6d81
commit d7e0330
Showing
25 changed files
with
260 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/seedu/address/commons/events/ui/PersonPanelDeselectionEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/seedu/address/logic/commands/tasks/AssignedCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/logic/parser/tasks/AssignedCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/model/person/IsAssignedToPersonPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
Oops, something went wrong.