Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ryanguai/tp
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanguai committed Oct 16, 2022
2 parents 3c323fa + 7596e38 commit 2f16299
Show file tree
Hide file tree
Showing 37 changed files with 617 additions and 103 deletions.
25 changes: 13 additions & 12 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ Format: `listT`
### Adding Tasks: `addT`

Adds a task to the task list.
The deadline of the task is allowed to be empty. Newly added tasks are marked as not done.
Throws an exception if the description of the task is empty.
The description and deadline of the task are not allowed to be empty. Newly added tasks are marked as not done.
Throws an exception if the description of the task is empty.
Throws an exception if the deadline of the task is empty.
Throws an exception if the deadline of the task is not in dd-mm-yyyy format.

Format: `addT d/DESCRIPTION D/DEADLINE`
Expand All @@ -186,11 +187,11 @@ Example:

Removes the specified task from the task list. Throws an exception if task does not exist.

Format: `deleteT i/INDEX`
Format: `deleteT INDEX`

Example:

* `deleteT i/12` will delete the 12th task in the task list.
* `deleteT 12` will delete the 12th task in the task list.

### Marking task as done: `markT`

Expand Down Expand Up @@ -279,41 +280,41 @@ Format: `listL`

Adds a label to an existing contact in the address book. Each contact can have multiple labels. If there is no existing label with the same name, label is added to the label list. Throws an exception if contact does not exist.

Format: `addL c/INDEX n/label_NAME`
Format: `addL c/INDEX l/label_NAME`

Example:

* `addL c/12 n/CS2103T` will add the label "CS2103T" to the 12th contact on the contact list.
* `addL c/12 l/CS2103T` will add the label "CS2103T" to the 12th contact on the contact list.

### Removing a label from a contact: `deleteL`

Removes a label from an existing contact in the address book. If contact is last remaining person with said label, label is removed from the label list. Throws an exception if contact or label does not exist.

Format: `deleteL c/INDEX n/label_NAME`
Format: `deleteL c/INDEX l/label_NAME`

Example:

* `deleteL c/14 n/CS2101` will remove the label "CS2101" from the 14th contact on the contact list.
* `deleteL c/14 l/CS2101` will remove the label "CS2101" from the 14th contact on the contact list.

### Adding a label to a task: `addL`

Adds a label to an existing task in the address book. Each task can have multiple labels. If there is no existing label with the same name, label is added to the label list. Throws an exception if task does not exist.

Format: `addL t/INDEX n/label_NAME`
Format: `addL t/INDEX l/label_NAME`

Example:

* `addL t/12 n/CS2103T` will add the label "CS2103T" to the 12th task on the task list.
* `addL t/12 l/CS2103T` will add the label "CS2103T" to the 12th task on the task list.

### Removing a label from a task: `deleteL`

Removes a label from an existing task in the address book. If contact is last remaining person with said label, label is removed from the label list. Throws an exception if task or label does not exist.

Format: `deleteL t/INDEX n/label_NAME`
Format: `deleteL t/INDEX l/label_NAME`

Example:

* `deleteL t/14 n/CS2101` will remove the label "CS2101" from the 14th task on the task list.
* `deleteL t/14 l/CS2101` will remove the label "CS2101" from the 14th task on the task list.

## Automatic tab switching

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package seedu.address.logic.commands.contact;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;
import seedu.address.model.person.PersonContainsKeywordsPredicate;

/**
* Finds and lists all persons whose tags contain any of the argument keywords.
* Keyword matching is case-insensitive.
*/
public class FilterContactCommand extends Command {

public static final String COMMAND_WORD = "filterC";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose tag(s) contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " grocery shopping friends";

private final PersonContainsKeywordsPredicate predicate;

public FilterContactCommand(PersonContainsKeywordsPredicate predicate) {
this.predicate = predicate;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof FilterContactCommand // instanceof handles nulls
&& predicate.equals(((FilterContactCommand) other).predicate)); // state check
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import seedu.address.model.person.PersonContainsKeywordsPredicate;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
* Keyword matching is case insensitive.
* Finds and lists all persons in address book whose fields contain any of the argument keywords.
* Keyword matching is case-insensitive.
*/
public class FindContactCommand extends Command {

Expand Down
35 changes: 20 additions & 15 deletions src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,29 @@ public class AddTagCommand extends Command {
public static final String MESSAGE_ADD_TAG_SUCCESS = "Added tag: %1$s";
public static final String MESSAGE_TAG_NOT_ADDED = "At least 1 tag to add must be provided.";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";
public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the address book.";
public static final String MESSAGE_MISSING_INDEX = "At least 1 contact or task index must be provided.";

private final Index index;
private final Index contactIndex;
private final Index taskIndex;
private final EditPersonDescriptor editPersonDescriptor;
private final EditTaskDescriptor editTaskDescriptor;
private final boolean addTagToContact;
private final boolean addTagToTask;

/**
* @param index of the person in the filtered person list to edit
* @param contactIndex of the person in the filtered person list to edit
* @param editPersonDescriptor details to edit the person with
*/
public AddTagCommand(Index index, EditPersonDescriptor editPersonDescriptor, EditTaskDescriptor editTaskDescriptor,
boolean addTagToContact, boolean addTagToTask) {
requireNonNull(index);
public AddTagCommand(Index contactIndex, Index taskIndex, EditPersonDescriptor editPersonDescriptor,
EditTaskDescriptor editTaskDescriptor, boolean addTagToContact, boolean addTagToTask) {
requireNonNull(contactIndex);
requireNonNull(taskIndex);
requireNonNull(editPersonDescriptor);
requireNonNull(editTaskDescriptor);

this.index = index;
this.contactIndex = contactIndex;
this.taskIndex = taskIndex;
this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor);
this.addTagToContact = addTagToContact;
this.addTagToTask = addTagToTask;
Expand All @@ -78,11 +82,11 @@ public CommandResult execute(Model model) throws CommandException {
if (addTagToContact) {
List<Person> lastShownPersonList = model.getFilteredPersonList();

if (index.getZeroBased() >= lastShownPersonList.size()) {
if (contactIndex.getZeroBased() >= lastShownPersonList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToEdit = lastShownPersonList.get(index.getZeroBased());
Person personToEdit = lastShownPersonList.get(contactIndex.getZeroBased());
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor);

if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
Expand All @@ -97,15 +101,15 @@ public CommandResult execute(Model model) throws CommandException {
if (addTagToTask) {
List<Task> lastShownTaskList = model.getFilteredTaskList();

if (index.getZeroBased() >= lastShownTaskList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
if (taskIndex.getZeroBased() >= lastShownTaskList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}

Task taskToEdit = lastShownTaskList.get(index.getZeroBased());
Task taskToEdit = lastShownTaskList.get(taskIndex.getZeroBased());
Task editedTask = createEditedTask(taskToEdit, editTaskDescriptor);

if (!taskToEdit.isSameTask(editedTask) && model.hasTask(editedTask)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
throw new CommandException(MESSAGE_DUPLICATE_TASK);
}

model.setTask(taskToEdit, editedTask);
Expand Down Expand Up @@ -146,8 +150,7 @@ private static Task createEditedTask(Task taskToEdit, EditTaskDescriptor editTas
assert taskToEdit != null;

Description updatedDescription = editTaskDescriptor.getDescription().orElse(taskToEdit.getDescription());
// TODO: Implement
Deadline updatedDeadline = new Deadline("");
Deadline updatedDeadline = editTaskDescriptor.getDeadline().orElse(taskToEdit.getDeadline());
Boolean updatedIsDone = editTaskDescriptor.getIsDone().orElse(taskToEdit.getStatus());
Set<Tag> newTags = editTaskDescriptor.getTags().orElse(new HashSet<>());
Set<Tag> updatedTags = new HashSet<>();
Expand All @@ -173,7 +176,9 @@ public boolean equals(Object other) {

// state check
AddTagCommand e = (AddTagCommand) other;
return index.equals(e.index)
return contactIndex.equals(e.contactIndex)
&& taskIndex.equals(e.taskIndex)
&& editTaskDescriptor.equals(e.editTaskDescriptor)
&& editPersonDescriptor.equals(e.editPersonDescriptor);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,37 @@ public class DeleteTagCommand extends Command {
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_TAG + "CS2103T";

public static final String MESSAGE_ADD_TAG_SUCCESS = "Deleted tag: %1$s";
public static final String MESSAGE_TAG_NOT_ADDED = "At least 1 tag to add must be provided.";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";
public static final String MESSAGE_DELETE_TAG_SUCCESS = "Deleted tag: %1$s";
public static final String MESSAGE_TAG_NOT_DELETED = "At least 1 tag to delete must be provided.";
public static final String MESSAGE_TAGS_DO_NOT_EXIST = "The tag(s) you want to remove are not found "
+ "on the selected contact/task.";
public static final String MESSAGE_MISSING_INDEX = "At least 1 contact or task index must be provided.";

private final Index index;
private final Index contactIndex;
private final Index taskIndex;
private final EditPersonDescriptor editPersonDescriptor;
private final EditTaskDescriptor editTaskDescriptor;
private final boolean deleteTagFromContact;
private final boolean deleteTagFromTask;

/**
* @param index of the person in the filtered person list to edit
* @param contactIndex of the person in the filtered person list to edit
* @param taskIndex of the task in the filtered task list to edit
* @param editPersonDescriptor details to edit the person with
* @param editTaskDescriptor details to edit the task with
* @param deleteTagFromContact true if contactIndex was provided
* @param deleteTagFromTask true if taskIndex was provided
*/
public DeleteTagCommand(Index index, EditPersonDescriptor editPersonDescriptor,
public DeleteTagCommand(Index contactIndex, Index taskIndex, EditPersonDescriptor editPersonDescriptor,
EditTaskDescriptor editTaskDescriptor, boolean deleteTagFromContact,
boolean deleteTagFromTask) {
requireNonNull(index);
requireNonNull(contactIndex);
requireNonNull(taskIndex);
requireNonNull(editPersonDescriptor);
requireNonNull(editTaskDescriptor);

this.index = index;
this.contactIndex = contactIndex;
this.taskIndex = taskIndex;
this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor);
this.deleteTagFromContact = deleteTagFromContact;
this.deleteTagFromTask = deleteTagFromTask;
Expand All @@ -79,39 +87,39 @@ public CommandResult execute(Model model) throws CommandException {
if (deleteTagFromContact) {
List<Person> lastShownList = model.getFilteredPersonList();

if (index.getZeroBased() >= lastShownList.size()) {
if (contactIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToEdit = lastShownList.get(index.getZeroBased());
Person personToEdit = lastShownList.get(contactIndex.getZeroBased());
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor);

if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
if (personToEdit.getTags().equals(editedPerson.getTags())) {
throw new CommandException(MESSAGE_TAGS_DO_NOT_EXIST);
}

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_ADD_TAG_SUCCESS,
return new CommandResult(String.format(MESSAGE_DELETE_TAG_SUCCESS,
editPersonDescriptor.getTags().orElse(new HashSet<>())));
}
if (deleteTagFromTask) {
List<Task> lastShownTaskList = model.getFilteredTaskList();

if (index.getZeroBased() >= lastShownTaskList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
if (taskIndex.getZeroBased() >= lastShownTaskList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}

Task taskToEdit = lastShownTaskList.get(index.getZeroBased());
Task taskToEdit = lastShownTaskList.get(taskIndex.getZeroBased());
Task editedTask = createEditedTask(taskToEdit, editTaskDescriptor);

if (!taskToEdit.isSameTask(editedTask) && model.hasTask(editedTask)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
if (taskToEdit.getTags().equals(editedTask.getTags())) {
throw new CommandException(MESSAGE_TAGS_DO_NOT_EXIST);
}

model.setTask(taskToEdit, editedTask);
model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS);
return new CommandResult(String.format(MESSAGE_ADD_TAG_SUCCESS,
return new CommandResult(String.format(MESSAGE_DELETE_TAG_SUCCESS,
editTaskDescriptor.getTags().orElse(new HashSet<>())));
}
throw new CommandException(MESSAGE_MISSING_INDEX);
Expand Down Expand Up @@ -147,8 +155,7 @@ private static Task createEditedTask(Task taskToEdit, EditTaskDescriptor editTas
assert taskToEdit != null;

Description updatedDescription = editTaskDescriptor.getDescription().orElse(taskToEdit.getDescription());
// TODO: Implement
Deadline updatedDeadline = new Deadline("");
Deadline updatedDeadline = editTaskDescriptor.getDeadline().orElse(taskToEdit.getDeadline());
Boolean updatedIsDone = editTaskDescriptor.getIsDone().orElse(taskToEdit.getStatus());
Set<Tag> newTags = editTaskDescriptor.getTags().orElse(new HashSet<>());
Set<Tag> updatedTags = new HashSet<>();
Expand All @@ -174,7 +181,9 @@ public boolean equals(Object other) {

// state check
DeleteTagCommand e = (DeleteTagCommand) other;
return index.equals(e.index)
return contactIndex.equals(e.contactIndex)
&& taskIndex.equals(e.taskIndex)
&& editTaskDescriptor.equals(e.editTaskDescriptor)
&& editPersonDescriptor.equals(e.editPersonDescriptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ public class AddTaskCommand extends Command {

public static final String MESSAGE_ADD_TASK_SUCCESS = "New task added: %1$s";
// public static final String MESSAGE_MISSING_DESCRIPTION = "A task must have a description";
// To be implemented later.

private final Task newTask;

/**
* Creates an AddTCommand to add the specified {@code Task}
* Creates an AddTaskCommand to add the specified {@code Task}
*/
public AddTaskCommand(Task task) {
requireNonNull(task);
Expand All @@ -42,7 +43,7 @@ public AddTaskCommand(Task task) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

model.addT(newTask);
model.addTask(newTask);
return new CommandResult(String.format(MESSAGE_ADD_TASK_SUCCESS, newTask));
}

Expand Down
Loading

0 comments on commit 2f16299

Please sign in to comment.