forked from nus-cs2103-AY1617S2/addressbook-level4
-
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 #56 from CS2103JAN2017-W15-B4/staging
Complete v0.2
- Loading branch information
Showing
80 changed files
with
1,286 additions
and
634 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
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
44 changes: 44 additions & 0 deletions
44
src/main/java/seedu/geekeep/logic/commands/DoneCommand.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,44 @@ | ||
package seedu.geekeep.logic.commands; | ||
|
||
import seedu.geekeep.commons.core.Messages; | ||
import seedu.geekeep.commons.core.UnmodifiableObservableList; | ||
import seedu.geekeep.logic.commands.exceptions.CommandException; | ||
import seedu.geekeep.model.task.ReadOnlyTask; | ||
|
||
/** | ||
* Marks 'done' for task identified using it's last displayed index from the address book. | ||
*/ | ||
public class DoneCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "done"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Marks the task identified by the index number used in the last task listing as done.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DONE_TASK_SUCCESS = "Marked as done: %1$s"; | ||
|
||
public final int targetIndex; | ||
|
||
public DoneCommand(int targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute() throws CommandException { | ||
|
||
UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList(); | ||
|
||
if (lastShownList.size() < targetIndex) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
|
||
ReadOnlyTask taskToMark = lastShownList.get(targetIndex - 1); | ||
|
||
model.markTaskDone(targetIndex - 1); | ||
|
||
return new CommandResult(String.format(MESSAGE_DONE_TASK_SUCCESS, taskToMark)); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -15,24 +15,24 @@ | |
import seedu.geekeep.model.task.UniqueTaskList; | ||
|
||
/** | ||
* Edits the details of an existing person in the address book. | ||
* Edits the details of an existing task in the address book. | ||
*/ | ||
public class EditCommand extends Command { | ||
|
||
/** | ||
* Stores the details to edit the person with. Each non-empty field value will replace the | ||
* corresponding field value of the person. | ||
* Stores the details to edit the task with. Each non-empty field value will replace the | ||
* corresponding field value of the task. | ||
*/ | ||
public static class EditPersonDescriptor { | ||
public static class EditTaskDescriptor { | ||
private Optional<Title> title = Optional.empty(); | ||
private Optional<DateTime> endDateTime = Optional.empty(); | ||
private Optional<DateTime> startDateTime = Optional.empty(); | ||
private Optional<Location> location = Optional.empty(); | ||
private Optional<UniqueTagList> tags = Optional.empty(); | ||
|
||
public EditPersonDescriptor() {} | ||
public EditTaskDescriptor() {} | ||
|
||
public EditPersonDescriptor(EditPersonDescriptor toCopy) { | ||
public EditTaskDescriptor(EditTaskDescriptor toCopy) { | ||
this.title = toCopy.getTitle(); | ||
this.endDateTime = toCopy.getEndDateTime(); | ||
this.startDateTime = toCopy.getStartDateTime(); | ||
|
@@ -96,70 +96,70 @@ public void setTitle(Optional<Title> title) { | |
|
||
public static final String COMMAND_WORD = "edit"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " | ||
+ "by the index number used in the last person listing. " | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the task identified " | ||
+ "by the index number used in the last task listing. " | ||
+ "Existing values will be overwritten by the input values.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "[NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS ] [t/TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " 1 p/91234567 e/[email protected]"; | ||
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; | ||
+ "[TITLE] [s/STARTING_TIME] [e/ENDING_TIME] [l/LOCATION] [t/TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " 1 s/2017-04-01T10:16:30 e/2017-04-01T10:16:30m"; | ||
public static final String MESSAGE_EDIT_TASK_SUCCESS = "Edited Task: %1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit 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 task manager."; | ||
/** | ||
* Creates and returns a {@code Person} with the details of {@code personToEdit} | ||
* edited with {@code editPersonDescriptor}. | ||
* Creates and returns a {@code Task} with the details of {@code taskToEdit} | ||
* edited with {@code editTaskDescriptor}. | ||
*/ | ||
private static Task createEditedTask(ReadOnlyTask personToEdit, | ||
EditPersonDescriptor editPersonDescriptor) { | ||
assert personToEdit != null; | ||
private static Task createEditedTask(ReadOnlyTask taskToEdit, | ||
EditTaskDescriptor editTaskDescriptor) { | ||
assert taskToEdit != null; | ||
|
||
Title updatedTitle = editPersonDescriptor.getTitle().orElseGet(personToEdit::getTitle); | ||
Title updatedTitle = editTaskDescriptor.getTitle().orElseGet(taskToEdit::getTitle); | ||
DateTime updatedEndDateTime | ||
= editPersonDescriptor.getEndDateTime().orElseGet(personToEdit::getEndDateTime); | ||
= editTaskDescriptor.getEndDateTime().orElseGet(taskToEdit::getEndDateTime); | ||
DateTime updatedStartDateTime | ||
= editPersonDescriptor.getStartDateTime().orElseGet(personToEdit::getStartDateTime); | ||
Location updatedLocation = editPersonDescriptor.getLocation().orElseGet(personToEdit::getLocation); | ||
UniqueTagList updatedTags = editPersonDescriptor.getTags().orElseGet(personToEdit::getTags); | ||
= editTaskDescriptor.getStartDateTime().orElseGet(taskToEdit::getStartDateTime); | ||
Location updatedLocation = editTaskDescriptor.getLocation().orElseGet(taskToEdit::getLocation); | ||
UniqueTagList updatedTags = editTaskDescriptor.getTags().orElseGet(taskToEdit::getTags); | ||
|
||
return new Task(updatedTitle, updatedStartDateTime, updatedEndDateTime, updatedLocation, updatedTags); | ||
} | ||
|
||
private final int filteredPersonListIndex; | ||
private final int filteredTaskListIndex; | ||
|
||
private final EditPersonDescriptor editPersonDescriptor; | ||
private final EditTaskDescriptor editTaskDescriptor; | ||
|
||
/** | ||
* @param filteredPersonListIndex the index of the person in the filtered person list to edit | ||
* @param editPersonDescriptor details to edit the person with | ||
* @param filteredTaskListIndex the index of the task in the filtered task list to edit | ||
* @param editTaskDescriptor details to edit the task with | ||
*/ | ||
public EditCommand(int filteredPersonListIndex, EditPersonDescriptor editPersonDescriptor) { | ||
assert filteredPersonListIndex > 0; | ||
assert editPersonDescriptor != null; | ||
public EditCommand(int filteredTaskListIndex, EditTaskDescriptor editTaskDescriptor) { | ||
assert filteredTaskListIndex > 0; | ||
assert editTaskDescriptor != null; | ||
|
||
// converts filteredPersonListIndex from one-based to zero-based. | ||
this.filteredPersonListIndex = filteredPersonListIndex - 1; | ||
// converts filteredTaskListIndex from one-based to zero-based. | ||
this.filteredTaskListIndex = filteredTaskListIndex - 1; | ||
|
||
this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor); | ||
this.editTaskDescriptor = new EditTaskDescriptor(editTaskDescriptor); | ||
} | ||
|
||
@Override | ||
public CommandResult execute() throws CommandException { | ||
List<ReadOnlyTask> lastShownList = model.getFilteredPersonList(); | ||
List<ReadOnlyTask> lastShownList = model.getFilteredTaskList(); | ||
|
||
if (filteredPersonListIndex >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
if (filteredTaskListIndex >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
|
||
ReadOnlyTask personToEdit = lastShownList.get(filteredPersonListIndex); | ||
Task editedTask = createEditedTask(personToEdit, editPersonDescriptor); | ||
ReadOnlyTask taskToEdit = lastShownList.get(filteredTaskListIndex); | ||
Task editedTask = createEditedTask(taskToEdit, editTaskDescriptor); | ||
|
||
try { | ||
model.updatePerson(filteredPersonListIndex, editedTask); | ||
model.updateTask(filteredTaskListIndex, editedTask); | ||
} catch (UniqueTaskList.DuplicateTaskException dpe) { | ||
throw new CommandException(MESSAGE_DUPLICATE_PERSON); | ||
throw new CommandException(MESSAGE_DUPLICATE_TASK); | ||
} | ||
model.updateFilteredListToShowAll(); | ||
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, personToEdit)); | ||
return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit)); | ||
} | ||
} |
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.