forked from nus-cs2103-AY2223S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY2223S1#86 from ShenyiCui/Shenyi/67-cr…
…eate-select-contact-and-ui Feat: Add select contact command and UI
- Loading branch information
Showing
39 changed files
with
690 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
coverage: | ||
status: | ||
patch: | ||
default: | ||
target: auto | ||
threshold: 50% | ||
project: | ||
default: | ||
target: auto | ||
threshold: 75% |
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
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
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
73 changes: 73 additions & 0 deletions
73
src/main/java/swift/logic/commands/SelectContactCommand.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,73 @@ | ||
package swift.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static swift.model.Model.PREDICATE_SHOW_ALL_BRIDGE; | ||
import static swift.model.Model.PREDICATE_SHOW_ALL_TASKS; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
import swift.commons.core.Messages; | ||
import swift.commons.core.index.Index; | ||
import swift.logic.commands.exceptions.CommandException; | ||
import swift.model.Model; | ||
import swift.model.bridge.PersonTaskBridge; | ||
import swift.model.person.Person; | ||
import swift.model.task.Task; | ||
|
||
/** | ||
* Deletes a task identified using it's displayed index from the address book. | ||
*/ | ||
public class SelectContactCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "select_contact"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Selects the contact identified by the index number used in the displayed contact list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_SELECT_CONTACT_SUCCESS = "Person Selected!"; | ||
|
||
private final Index targetIndex; | ||
|
||
public SelectContactCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownPersonList = model.getFilteredPersonList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownPersonList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person selectedPerson = lastShownPersonList.get(targetIndex.getZeroBased()); | ||
model.updateFilteredPersonList((person) -> person.equals(selectedPerson)); | ||
|
||
model.updateFilteredBridgeList(PREDICATE_SHOW_ALL_BRIDGE); | ||
model.updateFilteredBridgeList((bridge) -> bridge.getPersonId().equals(selectedPerson.getId())); | ||
List<PersonTaskBridge> bridgeList = model.getFilteredBridgeList(); | ||
|
||
// Predicate to check whether task exists within a bridgeList | ||
Predicate<Task> isTaskExist = (task) -> bridgeList.stream() | ||
.filter((bridge) -> bridge.getTaskId().equals(task.getId())) | ||
.collect(Collectors.toList()) | ||
.size() != 0; | ||
|
||
model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS); | ||
model.updateFilteredTaskList(isTaskExist); | ||
|
||
return new CommandResult(Messages.MESSAGE_PERSONS_SELECTED_OVERVIEW); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof SelectContactCommand // instanceof handles nulls | ||
&& targetIndex.equals(((SelectContactCommand) 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
29 changes: 29 additions & 0 deletions
29
src/main/java/swift/logic/parser/SelectContactCommandParser.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,29 @@ | ||
package swift.logic.parser; | ||
|
||
import static swift.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import swift.commons.core.index.Index; | ||
import swift.logic.commands.SelectContactCommand; | ||
import swift.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteCommand object | ||
*/ | ||
public class SelectContactCommandParser implements Parser<SelectContactCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteCommand | ||
* and returns a DeleteCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public SelectContactCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new SelectContactCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, SelectContactCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.