Skip to content

Commit

Permalink
Merge branch 'master' into branch-Refactor-Undoable
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/seedu/address/logic/commands/task/DoneTaskCommand.java
  • Loading branch information
jeffsieu committed Nov 1, 2021
2 parents a20fc31 + d160539 commit 38db102
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 48 deletions.
14 changes: 8 additions & 6 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ Lists all tasks in the task list. Clears any existing filters.

Tasks can be filtered by completion status and/or tags. Show only completed tasks with `done/`, pending tasks with `undone/` and tasks with a certain tag `TAG` with `tag/TAG`.

> Note: `undone/` and `done/` flags cannot be specified at the same time.
**Format:**

`task list [done/] [undone/] [t/TAG]`
`task list [done/ OR undone/] [t/TAG]`

### Editing a task: `task edit`

Expand Down Expand Up @@ -347,16 +349,16 @@ If your changes to the data file makes its format invalid, TaskMaster will disca
| Action | Format, Examples |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|***Address Book Commands*** |
| **Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [t/TAG]…` <br> e.g., `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 1234665 t/friend t/colleague` |
| **Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [t/TAG]…` <br> e.g., `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 1234665 t/friend t/colleague` |
| **List** | `list` |
| **Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…`<br> e.g.,`edit 2 n/James Lee e/[email protected]` |
| **Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…`<br> e.g.,`edit 2 n/James Lee e/[email protected]` |
| **Find** | `find KEYWORD [MORE_KEYWORDS]`<br> e.g., `find James Jake` |
| **Delete** | `delete INDEX`<br> e.g., `delete 3` |
| **Clear** | `clear` |
|***Task List Commands*** |
| **Task Add** | `task add TITLE [d/DESCRIPTION] [ts/TIMESTAMP] [tag/TAG}` |
| **Task List** | `task list [done/] [undone/] [t/TAG]` |
| **Task Edit** | `task edit INDEX [t/TITLE] [d/DESCRIPTION] [ts/TIMESTAMP] [tag/TAG]…` <br> e.g.,`task edit 1 t/CS2103 Week 6 Quiz` |
| **Task Add** | `task add TITLE [d/DESCRIPTION] [ts/TIMESTAMP] [t/TAG]` |
| **Task List** | `task list [done/ OR undone/] [t/TAG]` |
| **Task Edit** | `task edit INDEX [ti/TITLE] [d/DESCRIPTION] [ts/TIMESTAMP] [t/TAG]…` <br> e.g.,`task edit 1 t/CS2103 Week 6 Quiz` |
| **Task Find** | `task find KEYWORD [MORE_KEYWORDS]`|
| **Task Delete** | `task delete INDEX`<br> e.g., `task delete 3` |
| **Task Purge** | `task purge` |
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface Logic {
* Returns a list of available task filters.
* @return The list of available task filters
*/
ObservableList<TaskFilter> getAvailableTaskFilters();
ObservableList<TaskFilter> getSelectableTaskFilters();

/**
* Returns the list of selected filters to filter tasks by.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void setTaskFilters(List<TaskFilter> taskFilters) {
}

@Override
public ObservableList<TaskFilter> getAvailableTaskFilters() {
return model.getAvailableTaskFilters();
public ObservableList<TaskFilter> getSelectableTaskFilters() {
return model.getSelectableTaskFilters();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,43 @@ public DoneTaskCommand(Index index) {
@Override
protected CommandResult executeDo(Model model) throws CommandException {
requireNonNull(model);
List<Task> taskList = model.getFilteredTaskList();
boolean isDone = changeTaskIsDone(model);
displayedString = isDone
? MESSAGE_SUCCESS
: MESSAGE_UNDONE;

return new CommandResult(String.format(displayedString, completedTask));
}

@Override
protected CommandResult executeUndo(Model model) throws CommandException {
requireNonNull(model);
changeTaskIsDone(model);
return new CommandResult(String.format(displayedString, this.completedTask));
}

private boolean changeTaskIsDone(Model model) throws CommandException {
List<Task> taskList = model.getFilteredTaskList();
if (index.getZeroBased() >= taskList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}

Task task = taskList.get(index.getZeroBased());
boolean isDone = task.isDone();
Task completedTask = new Task(task.getTitle(),
task.getDescription().orElse(null),
task.getTimestamp().orElse(null),
task.getTags(),
!task.isDone(),
task.getContacts());

this.completedTask = completedTask;
model.setTask(task, completedTask);

displayedString = isDone
? MESSAGE_UNDONE
: MESSAGE_SUCCESS;

return new CommandResult(String.format(displayedString, completedTask));
}

@Override
protected CommandResult executeUndo(Model model) throws CommandException {
this.execute(model);
return new CommandResult(String.format(MESSAGE_SUCCESS,
this.completedTask));
return completedTask.isDone();
}

@Override
public boolean equals(Object o) {
return this == o || (o instanceof DoneTaskCommand && index.equals(((DoneTaskCommand) o).index));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ListTaskCommand extends TaskCommand {
public static final String COMMAND_WORD = "list";
public static final String FULL_COMMAND_WORD = TaskCommand.COMMAND_WORD + " " + COMMAND_WORD;
public static final String MESSAGE_SUCCESS = "Task list updated";
public static final String MESSAGE_ONE_DONE_FILTER = "Tasks can only be filtered by done or undone at one time.";
public static final String MESSAGE_USAGE = FULL_COMMAND_WORD
+ ": Lists tasks matching the given search conditions.\n"
+ "Parameters: "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser.task;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.task.ListTaskCommand.MESSAGE_ONE_DONE_FILTER;
import static seedu.address.logic.commands.task.ListTaskCommand.MESSAGE_USAGE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -45,6 +46,12 @@ public ListTaskCommand parse(String args) throws ParseException {
Set<Tag> tags = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
List<TaskFilter> taskFilters = tags.stream().map(TaskFilters.FILTER_TAG).collect(Collectors.toList());

// Both done and undone flags are present
if (argMultimap.getValue(PREFIX_DONE).isPresent()
&& argMultimap.getValue(PREFIX_UNDONE).isPresent()) {
throw new ParseException(MESSAGE_ONE_DONE_FILTER + "\n" + MESSAGE_USAGE);
}

if (argMultimap.getValue(PREFIX_DONE).isPresent()) {
taskFilters.add(TaskFilters.FILTER_DONE);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ public interface Model {


/**
* Returns a list of available task filters.
* @return The list of available task filters.
* Returns a list of selectable task filters.
* @return The list of selectable task filters.
*/
ObservableList<TaskFilter> getAvailableTaskFilters();
ObservableList<TaskFilter> getSelectableTaskFilters();

/**
* Returns the list of selected filters to filter tasks by.
Expand Down
36 changes: 22 additions & 14 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class ModelManager implements Model {
private final FilteredList<Person> filteredPersons;
private final FilteredList<Task> filteredTasks;
private final ObservableList<TaskFilter> availableTaskFilters;
private final FilteredList<TaskFilter> selectableTaskFilters;
private final ObservableList<TaskFilter> selectedTaskFilters;

/**
Expand All @@ -62,9 +63,9 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyTaskList taskList,
filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
filteredTasks = new FilteredList<>(this.taskList.getTasks());
availableTaskFilters = FXCollections.observableArrayList();
selectableTaskFilters = new FilteredList<>(availableTaskFilters,
filter -> getSelectedTaskFilters().stream().noneMatch(filter::hasConflictWith));
selectedTaskFilters = FXCollections.observableArrayList();


}

public ModelManager() {
Expand All @@ -73,12 +74,13 @@ public ModelManager() {

/**
* Returns a new ModelManager initialize from the given {@link Model}.
*
* @param model The model to initialize the {@link ModelManager} from
* @return The initialized ModelManager
*/
public static ModelManager from(Model model) {
return new ModelManager(
new AddressBook(model.getAddressBook()), new TaskList(model.getTaskList()) , new UserPrefs());
new AddressBook(model.getAddressBook()), new TaskList(model.getTaskList()), new UserPrefs());
}

//=========== UserPrefs ==================================================================================
Expand Down Expand Up @@ -160,7 +162,6 @@ public void setPerson(Person target, Person editedPerson) {
}



//=========== Filtered Person List Accessors =============================================================

/**
Expand Down Expand Up @@ -229,10 +230,15 @@ private void recomputeAvailableTaskFilters() {
availableTaskFilters.addAll(tagFilters);
}

private void refreshSelectableTaskFiltersPredicate() {
selectableTaskFilters.setPredicate(
filter -> getSelectedTaskFilters().stream().noneMatch(filter::hasConflictWith));
}

@Override
public ObservableList<TaskFilter> getAvailableTaskFilters() {
public ObservableList<TaskFilter> getSelectableTaskFilters() {
recomputeAvailableTaskFilters();
return availableTaskFilters;
return selectableTaskFilters;
}

@Override
Expand All @@ -244,19 +250,22 @@ public ObservableList<TaskFilter> getSelectedTaskFilters() {
public void addTaskFilter(TaskFilter taskFilter) {
selectedTaskFilters.add(taskFilter);
recalculateFilteredTaskList();
refreshSelectableTaskFiltersPredicate();
}

@Override
public void removeTaskFilter(TaskFilter taskFilter) {
selectedTaskFilters.remove(taskFilter);
recalculateFilteredTaskList();
refreshSelectableTaskFiltersPredicate();
}

@Override
public void setTaskFilters(List<TaskFilter> taskFilters) {
selectedTaskFilters.clear();
selectedTaskFilters.addAll(taskFilters);
recalculateFilteredTaskList();
refreshSelectableTaskFiltersPredicate();
}

@Override
Expand Down Expand Up @@ -315,7 +324,6 @@ public void setTask(Task target, Task editedTask) {
Task updatedEditedTask = updateTaskContacts(editedTask);
taskList.setTask(target, updatedEditedTask);
updateTaskFilters();

}

/**
Expand Down Expand Up @@ -382,7 +390,7 @@ private Task updateTaskContacts(Task task) {
/**
* Determines if a name exists within a given a list of {@code Person}s.
*
* @param personList List of Persons to check through
* @param personList List of Persons to check through
* @param nameToCheck Name to check the list with
* @return Boolean indicating whether the personList contains nameToCheck.
*/
Expand All @@ -408,7 +416,7 @@ private void updateAllTasksContacts() {
* Changes the {@code oldName} in the given {@code Task} to the new name.
* Used when a {@code Person}'s {@code Name} is edited.
*
* @param task Given task to update
* @param task Given task to update
* @param oldName Old name to change
* @param newName New name to change to
* @return A new copy of the changed task. If there is no change, the task itself is returned.
Expand All @@ -425,11 +433,11 @@ private Task changeTaskContactName(Task task, Name oldName, Name newName) {
return updatedContacts.equals(currentContactList)
? task
: new Task(task.getTitle(),
task.getDescription().orElse(null),
task.getTimestamp().orElse(null),
task.getTags(),
task.isDone(),
updatedContacts);
task.getDescription().orElse(null),
task.getTimestamp().orElse(null),
task.getTags(),
task.isDone(),
updatedContacts);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public String toDisplayString() {
return isInverted ? "Undone" : "Done";
}

@Override
public boolean hasConflictWith(TaskFilter other) {
return other instanceof DoneTaskFilter;
}

@Override
public DoneTaskFilter invert() {
return new DoneTaskFilter(!isInverted);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.model.task.filters;

import java.util.Objects;
import java.util.function.Predicate;

import seedu.address.commons.util.StringUtil;
Expand Down Expand Up @@ -33,4 +34,26 @@ public String toDisplayString() {
return (this.isInverted ? "Without " : "Contains ")
+ StringUtil.limitString(keywords, "...", KeywordTaskFilter.MAX_KEYWORDS_LENGTH);
}

@Override
public boolean hasConflictWith(TaskFilter other) {
return other instanceof KeywordTaskFilter;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
KeywordTaskFilter that = (KeywordTaskFilter) o;
return keywords.equals(that.keywords) && isInverted == that.isInverted;
}

@Override
public int hashCode() {
return Objects.hash(keywords, isInverted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public String toDisplayString() {
return (isInverted ? "Not tagged " : "Tagged ") + tag;
}

@Override
public boolean hasConflictWith(TaskFilter other) {
if (!(other instanceof TagTaskFilter)) {
return false;
}
TagTaskFilter otherTagTaskFilter = (TagTaskFilter) other;
return tag.equals(otherTagTaskFilter.tag);
}

@Override
public TagTaskFilter invert() {
return new TagTaskFilter(tag, !isInverted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public Predicate<Task> getPredicate() {
* @return the string used to describe the filter in the UI
*/
public abstract String toDisplayString();

public abstract boolean hasConflictWith(TaskFilter other);
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void fillInnerParts() {

TaskListPanel taskListPanel = new TaskListPanel(
logic.getFilteredTaskList(),
logic.getAvailableTaskFilters(),
logic.getSelectableTaskFilters(),
logic.getSelectedTaskFilters(),
logic::addTaskFilter,
logic::removeTaskFilter,
Expand Down
Loading

0 comments on commit 38db102

Please sign in to comment.