diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index e4e8c2dbed9d..caab7b2dbe4b 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -48,7 +48,7 @@ The **_Architecture Diagram_** given above explains the high-level design of the App. Given below is a quick overview of each component. -`Main` has only one class called [`MainApp`](../src/main/java/seedu/address/MainApp.java). It is responsible for, +`Main` has only one class called [`MainApp`](../src/main/java/seedu/task/MainApp.java). It is responsible for, * At app launch: Initializes the components in the correct sequence, and connect them up with each other. * At shut down: Shuts down the components and invoke cleanup method where necessary. @@ -94,7 +94,7 @@ The sections below give more details of each component.
-**API** : [`Ui.java`](../src/main/java/seedu/address/ui/Ui.java) +**API** : [`Ui.java`](../src/main/java/seedu/task/ui/Ui.java) The UI consists of a `MainWindow` that is made up of parts e.g.`CommandBox`, `ResultDisplay`, `PersonListPanel`, `StatusBarFooter`, `BrowserPanel` etc. All these, including the `MainWindow`, inherit from the abstract `UiPart` class @@ -102,7 +102,7 @@ and they can be loaded using the `UiPartLoader`. The `UI` component uses JavaFx UI framework. The layout of these UI parts are defined in matching `.fxml` files that are in the `src/main/resources/view` folder.
-For example, the layout of the [`MainWindow`](../src/main/java/seedu/address/ui/MainWindow.java) is specified in +For example, the layout of the [`MainWindow`](../src/main/java/seedu/task/ui/MainWindow.java) is specified in [`MainWindow.fxml`](../src/main/resources/view/MainWindow.fxml) The `UI` component, @@ -114,7 +114,7 @@ The `UI` component,
-**API** : [`Logic.java`](../src/main/java/seedu/address/logic/Logic.java) +**API** : [`Logic.java`](../src/main/java/seedu/task/logic/Logic.java) 1. `Logic` uses the `Parser` class to parse the user command. 2. This results in a `Command` object which is executed by the `LogicManager`. @@ -129,7 +129,7 @@ API call.

-**API** : [`Model.java`](../src/main/java/seedu/address/model/Model.java) +**API** : [`Model.java`](../src/main/java/seedu/task/model/Model.java) The `Model`, * stores a `UserPref` object that represents the user's preferences. @@ -142,7 +142,7 @@ The `Model`,
-**API** : [`Storage.java`](../src/main/java/seedu/address/storage/Storage.java) +**API** : [`Storage.java`](../src/main/java/seedu/task/storage/Storage.java) The `Storage` component, * can save `UserPref` objects in json format and read it back. @@ -150,7 +150,7 @@ The `Storage` component, ### Common classes -Classes used by multiple components are in the `seedu.addressbook.commons` package. +Classes used by multiple components are in the `seedu.task.commons` package. ## Implementation @@ -200,13 +200,13 @@ We have two types of tests: These are in the `guitests` package. 2. **Non-GUI Tests** - These are tests not involving the GUI. They include, 1. _Unit tests_ targeting the lowest level methods/classes.
- e.g. `seedu.address.commons.UrlUtilTest` + e.g. `seedu.task.commons.UrlUtilTest` 2. _Integration tests_ that are checking the integration of multiple code units (those code units are assumed to be working).
- e.g. `seedu.address.storage.StorageManagerTest` + e.g. `seedu.task.storage.StorageManagerTest` 3. Hybrids of unit and integration tests. These test are checking multiple code units as well as how the are connected together.
- e.g. `seedu.address.logic.LogicManagerTest` + e.g. `seedu.task.logic.LogicManagerTest` **Headless GUI Testing** : Thanks to the [TestFX](https://github.com/TestFX/TestFX) library we use, our GUI tests can be run in the _headless_ mode. diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 5fcb1bc2ea3b..ed8cf9038baf 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -23,6 +23,7 @@ * **`add`**`meeting`: adds a task named CS2103 Tutorial * **`find`**`meeting `: searches the task named tutorial * **`delete`**`1`: delete the first task in the list + * **`complete`** `1`: mark the first task as completed * **`update`**`1 presentation c/10/10/2016:1200` : updates first task on the list to presentation having a deadline on 10/10/2016 on 12:00 while the number '1' is the index of task on the list * **`undo`** : undo previous one action * **`pin`**`1` : pin the first task in the list @@ -42,10 +43,9 @@ Adds a task to the to-do list
Format: `add TASK_NAME [s/START_DATE:START_TIME c/CLOSE_DATE:CLOSE_TIME t/TAG]` -> Date format of START_DATE and CLOSE_DATE is DD-MM-YYYY:HHMM e.g. 01/10/2016:2100 -> This is only the standard date time format. There is flexibility on the datetime format. You can use both type of date time format. +> Date format of START_DATE and CLOSE_DATE includes words like today, tomorrow, 3 days from now, day after tomorrow, noon, 12pm, 6am -* `TASK_NAME` must be unique. +* `TASK_NAME` need not be unique. * If there is no argument, the task will become floating. * `START_DATE` refer to the starting date and time of an event. For a task, the timestamp will be automatically saved as start date and time when the task is created. User can input start date and time for events. * `TAG` is for users to write tags for different tasks. Mulitple tags are available by typing `t/TAG t/TAG`. @@ -59,8 +59,7 @@ Examples: * `add quiz t/cs2102 t/easy`
Adds a flaoting task named tutorial with a tag CS2012 and easy Examples on date time flexibility: -* `add project three days from now`
Adds a project task three days later from the time you input this command -* `add meet with friends in three days`
Adds meet with friend as a task three days later from the time you input this command +* `add project c/3 days from now`
Adds a project task three days later from the time you input this command #### Deleting a task : `delete` Deletes a specific task by task name or index from the to-do list.
@@ -74,6 +73,16 @@ Examples: * `delete 1`
Deletes the first task in the to-do list. +#### Marking a task as completed: `complete` +Marks a specific task by index from the to-do list.
+FormatL `complete INDEX` + +> * INDEX refers to the number appears on the list in front the task name. + +Example: +* `complete 2`
+ Marks the second task on the list as completed. + #### Listing all persons : `list` Shows a list of tasks and events in the todo list.
Format: `list` @@ -147,7 +156,7 @@ There is no need to save manually. ## FAQ **Q**: Can I add event which have a start date and time to my to-do list ?
-**A**: Yes, you can create an event by typing command with a start and end date. For example, you have a trip from 10/10/2016 8:00 to 13/10/2016 21:00. You can type command like this: `add trip s/10/10/2016:0800 c/13/10/2016:2100`. +**A**: Yes, you can create an event by typing command with a start and end date. For example, you have a trip from 10/10/2016 8:00 to 13/10/2016 21:00. You can type command like this: `add trip s/8am 10th October c/9pm 13th October`. **Q**: If I don't know the deadline of my task yet, can I still add my task?
@@ -162,6 +171,7 @@ Command | Format -------- | :-------- Add | `add TASK_NAME [s/START_DATE:START_TIME c/CLOSE_DATE:CLOSE_TIME t/TAG]` Delete | `delete TASK_NAME` or `delete INDEX` +Complete | `complete INDEX` List | `list` Find | `find KEYWORD` or `find t/TAG` Update | `update INDEX [TASKNAME s/START_DATE:START_TIME c/CLOSE_DATE:CLOSE_TIME t/TAG rt/TO_REMOVE_TAG]` diff --git a/docs/UsingGradle.md b/docs/UsingGradle.md index 578c5f8634c2..69cb94b6e45c 100644 --- a/docs/UsingGradle.md +++ b/docs/UsingGradle.md @@ -35,7 +35,7 @@ Gradle commands look like this: ## Creating the JAR file * **`shadowJar`**
- Creates the `addressbook.jar` file in the `build/jar` folder, _if the current file is outdated_.
+ Creates the `taskmanager.jar` file in the `build/jar` folder, _if the current file is outdated_.
e.g. `./gradlew shadowJar` > To force Gradle to create the JAR file even if the current one is up-to-date, you can '`clean`' first.
@@ -56,7 +56,7 @@ If we package only our own class files into the JAR file, it will not work prope Runs all tests in the `guitests` package * **`nonGuiTests`**
- Runs all non-GUI tests in the `seedu.address` package + Runs all non-GUI tests in the `seedu.task` package * **`headless`**
Sets the test mode as _headless_. diff --git a/src/main/java/seedu/task/logic/commands/AddCommand.java b/src/main/java/seedu/task/logic/commands/AddCommand.java index f63b2146fcda..84eee9bfb29f 100644 --- a/src/main/java/seedu/task/logic/commands/AddCommand.java +++ b/src/main/java/seedu/task/logic/commands/AddCommand.java @@ -16,10 +16,10 @@ public class AddCommand extends Command { public static final String COMMAND_WORD = "add"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to the task list. " - + "Parameters: NAME [t/TAG]...\n" + + "Parameters: NAME s/start-datetime c/closedatetime [t/TAG]...\n" + "Example: " + COMMAND_WORD + " Finish CS2103"; - //TODO: o/OPENTIME c/CLOSETIME i/IMPORTANCE + //TODO: o/OPENTIME c/CLOSETIME public static final String MESSAGE_SUCCESS = "New task added: %1$s"; public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task list"; @@ -30,7 +30,7 @@ public class AddCommand extends Command { * * @throws IllegalValueException if any of the raw values are invalid */ - public AddCommand(String name, Set tags) //String openTime, String closeTime, String importance, ) + public AddCommand(String name, String openTime, String closeTime, Set tags) throws IllegalValueException { final Set tagSet = new HashSet<>(); for (String tagName : tags) { @@ -38,11 +38,11 @@ public AddCommand(String name, Set tags) //String openTime, String close } this.toAdd = new Task( new Name(name), - //new DateTime(openTime), - //new DateTime(closeTime), - //new Boolean(importance), - new UniqueTagList(tagSet), - false + new DateTime(openTime), + new DateTime(closeTime), + false, + false, + new UniqueTagList(tagSet) ); } diff --git a/src/main/java/seedu/task/logic/commands/CompleteCommand.java b/src/main/java/seedu/task/logic/commands/CompleteCommand.java new file mode 100644 index 000000000000..36bf9df6b35b --- /dev/null +++ b/src/main/java/seedu/task/logic/commands/CompleteCommand.java @@ -0,0 +1,47 @@ +package seedu.task.logic.commands; + +import seedu.task.commons.core.Messages; +import seedu.task.commons.core.UnmodifiableObservableList; +import seedu.task.commons.exceptions.IllegalValueException; +import seedu.task.model.task.Task; +import seedu.task.model.task.ReadOnlyTask; + +public class CompleteCommand extends Command { + + public static final String COMMAND_WORD = "complete"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Marks the task identified by the index number used in the last task listing as completed.\n" + + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1"; + + public static final String MESSAGE_COMPLETE_TASK_SUCCESS = "Completed Task: %1$s"; + + public final int targetIndex; + + public CompleteCommand(int targetIndex) { + this.targetIndex = targetIndex; + } + + @Override + public CommandResult execute() { + UnmodifiableObservableList lastShownList = model.getFilteredTaskList(); + + if (lastShownList.size() < targetIndex) { + indicateAttemptToExecuteIncorrectCommand(); + return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + } + + ReadOnlyTask orginialTask = lastShownList.get(targetIndex - 1); + try { + Task completedTask = new Task(orginialTask); + completedTask.setIsCompleted(true); + model.completeTask(orginialTask, completedTask); + } catch (IllegalValueException e) { + assert false : "Impossible"; + } + + + + return new CommandResult(String.format(MESSAGE_COMPLETE_TASK_SUCCESS, orginialTask)); + } +} diff --git a/src/main/java/seedu/task/logic/commands/PinCommand.java b/src/main/java/seedu/task/logic/commands/PinCommand.java index bd44e469c121..1b20eb7dbffe 100644 --- a/src/main/java/seedu/task/logic/commands/PinCommand.java +++ b/src/main/java/seedu/task/logic/commands/PinCommand.java @@ -2,6 +2,7 @@ import seedu.task.commons.core.Messages; import seedu.task.commons.core.UnmodifiableObservableList; +import seedu.task.commons.exceptions.IllegalValueException; import seedu.task.model.task.Task; import seedu.task.model.task.ReadOnlyTask; @@ -31,10 +32,13 @@ public CommandResult execute() { } ReadOnlyTask orginialTask = lastShownList.get(targetIndex - 1); - Task taskToPin = new Task(orginialTask.getName(), orginialTask.getTags(), orginialTask.getImportance()); - - taskToPin.setIsImportant(true); - model.pinTask(orginialTask, taskToPin); + try { + Task taskToPin = new Task(orginialTask); + taskToPin.setIsImportant(true); + model.pinTask(orginialTask, taskToPin); + } catch (IllegalValueException e) { + assert false : "Not possible for task on list to have illegal value"; + } return new CommandResult(String.format(MESSAGE_PIN_TASK_SUCCESS, orginialTask)); } diff --git a/src/main/java/seedu/task/logic/commands/UpdateCommand.java b/src/main/java/seedu/task/logic/commands/UpdateCommand.java index a39c90ce776b..625f7a677116 100644 --- a/src/main/java/seedu/task/logic/commands/UpdateCommand.java +++ b/src/main/java/seedu/task/logic/commands/UpdateCommand.java @@ -31,10 +31,12 @@ public class UpdateCommand extends Command { public final int targetIndex; private final Name newTaskName; + private final DateTime openTime; + private final DateTime closeTime; private final Set removedTags; private final UniqueTagList newTaskTags; - public UpdateCommand(int targetIndex, String name, Set tagsToAdd, Set tagsToRemove) throws IllegalValueException { + public UpdateCommand(int targetIndex, String name, String openTime, String closeTime, Set tagsToAdd, Set tagsToRemove) throws IllegalValueException { this.targetIndex = targetIndex; this.newTaskName = (name.isEmpty()) ? null : new Name(name); @@ -42,6 +44,8 @@ public UpdateCommand(int targetIndex, String name, Set tagsToAdd, Set\\S+(?:\\s+\\S+)*)"); // one or more keywords separated by whitespace - private static final Pattern TASK_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes + private static final Pattern ADD_TASK_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes + Pattern.compile("(?[^/]+)" + + "(s/(?[^/]+))?" + + "(c/(?[^/]+))?" + + "(?(?: t/[^/]+)*)"); // variable number of tags + + private static final Pattern UPDATE_TASK_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes Pattern.compile("(?[^/]*)" -// + " (?p?)p/(?[^/]+)" -// + " (?p?)e/(?[^/]+)" -// + " (?p?)a/(?
[^/]+)" + + "(s/(?[^/]+))?" + + "(c/(?[^/]+))?" + "(?(?: t/[^/]+)*)" // variable number of tags + "(?(?: rt/[^/]+)*)"); - + public Parser() { } /** @@ -62,6 +67,9 @@ public Command parseCommand(String userInput) { case UpdateCommand.COMMAND_WORD: return prepareUpdate(arguments); + + case CompleteCommand.COMMAND_WORD: + return prepareComplete(arguments); case PinCommand.COMMAND_WORD: return preparePin(arguments); @@ -93,16 +101,16 @@ public Command parseCommand(String userInput) { * @return the prepared command */ private Command prepareAdd(String args) { - final Matcher matcher = TASK_DATA_ARGS_FORMAT.matcher(args.trim()); + final Matcher matcher = ADD_TASK_DATA_ARGS_FORMAT.matcher(args.trim()); // Validate arg string format if (!matcher.matches()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } try { return new AddCommand(matcher.group("name"), - // matcher.group("phone"), - // matcher.group("email"), - // matcher.group("address"), + //TODO: set group somewhere + matcher.group("openTime"), + matcher.group("closeTime"), getTagsFromArgs(matcher.group("tagArguments"))); } catch (IllegalValueException ive) { return new IncorrectCommand(ive.getMessage()); @@ -198,7 +206,7 @@ private Command prepareUpdate(String args) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, UpdateCommand.MESSAGE_USAGE)); } - final Matcher argsMatcher = TASK_DATA_ARGS_FORMAT.matcher(matcher.group("arguments")); + final Matcher argsMatcher = UPDATE_TASK_DATA_ARGS_FORMAT.matcher(matcher.group("arguments")); if (!argsMatcher.matches()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, UpdateCommand.MESSAGE_USAGE)); @@ -208,6 +216,8 @@ private Command prepareUpdate(String args) { return new UpdateCommand( index.get(), argsMatcher.group("name"), + argsMatcher.group("openTime"), + argsMatcher.group("closeTime"), getTagsFromArgs(argsMatcher.group("tagArguments")), getTagsFromArgs("rt", argsMatcher.group("removeTagArguments")) ); @@ -233,6 +243,19 @@ private Command prepareFind(String args) { final Set keywordSet = new HashSet<>(Arrays.asList(keywords)); return new FindCommand(keywordSet); } + /** + * Parses arguments in the context of the complete task command. + * @param args full command args string + * @return the prepared command + */ + private Command prepareComplete(String args) { + Optional index = parseIndex(args); + if (!index.isPresent()) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, CompleteCommand.MESSAGE_USAGE)); + } + + return new CompleteCommand(index.get()); + } /** * Parses arguments in the context of the mark task command. diff --git a/src/main/java/seedu/task/model/Model.java b/src/main/java/seedu/task/model/Model.java index 93933defd2fe..40f28f547467 100644 --- a/src/main/java/seedu/task/model/Model.java +++ b/src/main/java/seedu/task/model/Model.java @@ -26,15 +26,15 @@ public interface Model { void addTask(Task task) throws UniqueTaskList.DuplicateTaskException; /** Updates the given task */ - void updateTask(ReadOnlyTask orginalTask, Task updateTask) throws UniqueTaskList.DuplicateTaskException; - + void updateTask(ReadOnlyTask orginalTask, Task updateTask) throws UniqueTaskList.DuplicateTaskException; + /** Pins the given task as important */ void pinTask(ReadOnlyTask originalTask, Task toPin); - /** - * Returns the filtered task list as an {@code UnmodifiableObservableList - * } - */ + /** Mark the given task as completed */ + void completeTask(ReadOnlyTask originalTask, Task completedTask); + + /** Returns the filtered task list as an {@code UnmodifiableObservableList} */ UnmodifiableObservableList getFilteredTaskList(); /** Updates the filter of the filtered task list to show all tasks */ diff --git a/src/main/java/seedu/task/model/ModelManager.java b/src/main/java/seedu/task/model/ModelManager.java index 6e5c0f90edc5..43a00dc07686 100644 --- a/src/main/java/seedu/task/model/ModelManager.java +++ b/src/main/java/seedu/task/model/ModelManager.java @@ -24,8 +24,8 @@ public class ModelManager extends ComponentManager implements Model { private final FilteredList filteredTasks; /** - * Initializes a ModelManager with the given AddressBook AddressBook and its - * variables should not be null + * Initializes a ModelManager with the given TaskManager + * TaskManager and its variables should not be null */ public ModelManager(TaskManager src, UserPrefs userPrefs) { super(); @@ -50,7 +50,7 @@ public ModelManager(ReadOnlyTaskManager initialData, UserPrefs userPrefs) { @Override public void resetData(ReadOnlyTaskManager newData) { taskManager.resetData(newData); - indicateAddressBookChanged(); + indicateTaskManagerChanged(); } @Override @@ -59,21 +59,21 @@ public ReadOnlyTaskManager getTaskManager() { } /** Raises an event to indicate the model has changed */ - private void indicateAddressBookChanged() { + private void indicateTaskManagerChanged() { raise(new TaskManagerChangedEvent(taskManager)); } @Override public synchronized void deleteTask(ReadOnlyTask target) throws UniqueTaskList.TaskNotFoundException { taskManager.removeTask(target); - indicateAddressBookChanged(); + indicateTaskManagerChanged(); } @Override public synchronized void addTask(Task task) throws UniqueTaskList.DuplicateTaskException { taskManager.addTask(task); updateFilteredListToShowAll(); - indicateAddressBookChanged(); + indicateTaskManagerChanged(); } @Override @@ -81,14 +81,21 @@ public synchronized void updateTask(ReadOnlyTask originalTask, Task updateTask) throws UniqueTaskList.DuplicateTaskException { taskManager.updateTask(originalTask, updateTask); updateFilteredListToShowAll(); - indicateAddressBookChanged(); + indicateTaskManagerChanged(); + } + + @Override + public synchronized void completeTask(ReadOnlyTask originalTask, Task completeTask){ + taskManager.completeTask(originalTask, completeTask); + updateFilteredListToShowAll(); + indicateTaskManagerChanged(); } @Override public synchronized void pinTask(ReadOnlyTask originalTask, Task toPin) { taskManager.pinTask(originalTask, toPin); updateFilteredListToShowAll(); - indicateAddressBookChanged(); + indicateTaskManagerChanged(); } // =========== Filtered Task List Accessors =============================================================== diff --git a/src/main/java/seedu/task/model/TaskManager.java b/src/main/java/seedu/task/model/TaskManager.java index 9fa1074c014e..2967b9d12390 100644 --- a/src/main/java/seedu/task/model/TaskManager.java +++ b/src/main/java/seedu/task/model/TaskManager.java @@ -1,6 +1,7 @@ package seedu.task.model; import javafx.collections.ObservableList; +import seedu.task.commons.exceptions.IllegalValueException; import seedu.task.model.tag.Tag; import seedu.task.model.tag.UniqueTagList; import seedu.task.model.task.ReadOnlyTask; @@ -60,7 +61,16 @@ public void setTags(Collection tags) { } public void resetData(Collection newTasks, Collection newTags) { - setTasks(newTasks.stream().map(Task::new).collect(Collectors.toList())); + setTasks(newTasks.stream().map(t -> { + try { + return new Task(t); + } catch (IllegalValueException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + + }).collect(Collectors.toList())); setTags(newTags); } @@ -102,6 +112,15 @@ public void pinTask(ReadOnlyTask originalTask, Task toPin) { tasks.pin(originalTask, toPin); } + /** + * Marks a specific task as completed to the task list. + */ + + public void completeTask(ReadOnlyTask originalTask, Task completeTask) { + syncTagsWithMasterList(completeTask); + tasks.complete(originalTask,completeTask); + } + /** * Ensures that every tag in this task: - exists in the master list * {@link #tags} - points to a Tag object in the master list diff --git a/src/main/java/seedu/task/model/task/DateTime.java b/src/main/java/seedu/task/model/task/DateTime.java index 1d69519ef149..1e901fd0b28e 100644 --- a/src/main/java/seedu/task/model/task/DateTime.java +++ b/src/main/java/seedu/task/model/task/DateTime.java @@ -1,10 +1,15 @@ package seedu.task.model.task; import java.time.Instant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Optional; +import org.ocpsoft.prettytime.PrettyTime; import org.ocpsoft.prettytime.nlp.PrettyTimeParser; import seedu.task.commons.exceptions.IllegalValueException; @@ -15,9 +20,10 @@ */ public class DateTime { - public static final String MESSAGE_DATETIME_CONSTRAINTS = "Date entered should be in a relatively standard form (e.g. in X hours, tomorrow, 20 Jan 2016, 5pm)"; + public static final String MESSAGE_DATETIME_CONSTRAINTS = "You have entered an invalid Date/Time format. For a complete list of all acceptable formats, please view our user guide."; public final Optional value; + private static PrettyTime p = new PrettyTime(); /** * Validates given Date and Time entered by the user. @@ -25,17 +31,16 @@ public class DateTime { * @throws IllegalValueException if given date/time string is invalid. */ public DateTime(String dateTime) throws IllegalValueException { - assert dateTime != null; - if (dateTime.equals("")) { + if (dateTime == null || dateTime.equals("")) { this.value = Optional.empty(); return; } - List possibleDates = new PrettyTimeParser().parse(dateTime); - if (!isValidDateTime(possibleDates)) { + if (!isValidDateTime(dateTime)) { throw new IllegalValueException(MESSAGE_DATETIME_CONSTRAINTS); } - + List possibleDates = new PrettyTimeParser().parse(dateTime); this.value = Optional.of(possibleDates.get(0).toInstant()); + } /** @@ -43,13 +48,35 @@ public DateTime(String dateTime) throws IllegalValueException { * * @param test output from date/time parser */ - public static boolean isValidDateTime(List test) { - return !test.isEmpty() && (test.size() == 1); + public static boolean isValidDateTime(String dateTime) { + List possibleDates = new PrettyTimeParser().parse(dateTime); + if(!possibleDates.isEmpty() && (possibleDates.size() == 1)) { + return true; + } else { + return false; + } } @Override public String toString() { - return (value.isPresent()) ? value.get().toString() : ""; + + if(value.isPresent()) { + DateTimeFormatter formatter = + DateTimeFormatter.ofLocalizedDateTime( FormatStyle.FULL ) + .withLocale( Locale.UK ) + .withZone( ZoneId.systemDefault() ); + return formatter.format( value.get() ); + } else { + return ""; + } + } + + public String toPrettyString() { + if(value.isPresent()) { + return p.format(Date.from(this.value.get())); + } else { + return ""; + } } @Override @@ -63,5 +90,12 @@ public boolean equals(Object other) { public int hashCode() { return value.hashCode(); } + /** + * Returns an optional corresponding to the value of the DateTime object + * @return value of DateTime object + */ + public Optional getDateTimeValue() { + return this.value; + } } diff --git a/src/main/java/seedu/task/model/task/ReadOnlyTask.java b/src/main/java/seedu/task/model/task/ReadOnlyTask.java index 2036af35f0ca..223884379d7c 100644 --- a/src/main/java/seedu/task/model/task/ReadOnlyTask.java +++ b/src/main/java/seedu/task/model/task/ReadOnlyTask.java @@ -9,9 +9,10 @@ public interface ReadOnlyTask { Name getName(); - //DateTime getOpenTime(); - //DateTime getCloseTime(); + DateTime getOpenTime(); + DateTime getCloseTime(); boolean getImportance(); + boolean getComplete(); /** * The returned TagList is a deep copy of the internal TagList, diff --git a/src/main/java/seedu/task/model/task/Task.java b/src/main/java/seedu/task/model/task/Task.java index 16cab42fc39c..0abc1b151ebc 100644 --- a/src/main/java/seedu/task/model/task/Task.java +++ b/src/main/java/seedu/task/model/task/Task.java @@ -1,42 +1,63 @@ package seedu.task.model.task; -import java.time.LocalDateTime; +import java.time.Instant; import java.util.Objects; +import seedu.task.commons.exceptions.IllegalValueException; import seedu.task.commons.util.CollectionUtil; import seedu.task.model.tag.UniqueTagList; /** - * Represents a Task in the task list. Guarantees: details are present and not - * null, field values are validated. + * Represents a Task in the task list. + * Guarantees: field values are validated. */ public class Task implements ReadOnlyTask { private Name name; - // private DateTime openTime; - // private DateTime closeTime; - private UniqueTagList tags; + private DateTime openTime; + private DateTime closeTime; + private boolean isCompleted; private boolean isImportant; + private UniqueTagList tags; + public static final String MESSAGE_DATETIME_CONSTRAINTS = "Please ensure that your start and end time combination is valid."; + /** - * Every field must be present and not null. + * Assigns instance variables + * @throws IllegalValueException if DateTime pair is invalid */ - public Task(Name name, UniqueTagList tags, boolean isImportant) { - // open time, urgent, and close time can be null + public Task(Name name, DateTime openTime, DateTime closeTime, boolean isImportant, boolean isCompleted, UniqueTagList tags) throws IllegalValueException { assert !CollectionUtil.isAnyNull(name, tags); this.name = name; - // TODO: set default values - // this.openTime = openTime; - // this.closeTime = closeTime; + this.openTime = openTime; + this.closeTime = closeTime; this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list + this.isCompleted = isCompleted; this.isImportant = isImportant; + if (!isValidDateTimePair()) { + throw new IllegalValueException(MESSAGE_DATETIME_CONSTRAINTS); + } + } + /** + * Checks if openTime is before closeTime + * @return + */ + private boolean isValidDateTimePair() { + if(openTime.getDateTimeValue().isPresent() && closeTime.getDateTimeValue().isPresent()) { + Instant openTimeValue = openTime.getDateTimeValue().get(); + Instant closeTimeValue = closeTime.getDateTimeValue().get(); + return openTimeValue.isBefore(closeTimeValue); + } else { + return true; + } } /** * Copy constructor. + * @throws IllegalValueException */ - public Task(ReadOnlyTask source) { - this(source.getName(), source.getTags(), source.getImportance()); + public Task(ReadOnlyTask source) throws IllegalValueException { + this(source.getName(), source.getOpenTime(), source.getCloseTime(), source.getImportance(), source.getComplete(), source.getTags()); } @Override @@ -44,17 +65,26 @@ public Name getName() { return name; } - /** - * @Override public DateTime getOpenTime() { return openTime; } - * - * @Override public DateTime getCloseTime() { return closeTime; } - **/ + @Override + public DateTime getOpenTime() { + return openTime; + } + @Override + public DateTime getCloseTime() { + return closeTime; + } + @Override public boolean getImportance() { return isImportant; } + @Override + public boolean getComplete() { + return isCompleted; + } + @Override public UniqueTagList getTags() { return new UniqueTagList(tags); @@ -69,9 +99,15 @@ public void setTags(UniqueTagList replacement) { public void setIsImportant(boolean isImportant) { this.isImportant = isImportant; - } + /** + * Sets the task's completion flag + */ + public void setIsCompleted(boolean isCompleted) { + this.isCompleted = isCompleted; + } + @Override public boolean equals(Object other) { return other == this // short circuit if same object @@ -91,5 +127,4 @@ public int hashCode() { public String toString() { return getAsText(); } - } diff --git a/src/main/java/seedu/task/model/task/UniqueTaskList.java b/src/main/java/seedu/task/model/task/UniqueTaskList.java index 617baaf83764..083a081f43b2 100644 --- a/src/main/java/seedu/task/model/task/UniqueTaskList.java +++ b/src/main/java/seedu/task/model/task/UniqueTaskList.java @@ -103,6 +103,19 @@ public void pin(ReadOnlyTask originalTask, Task toPin) { internalList.set(index, toPin); } + /** + * Marks a task as completed in the list. + */ + public void complete(ReadOnlyTask originalTask, Task completeTask) { + assert originalTask != null; + assert completeTask != null; + + int index = internalList.indexOf(originalTask); + assert index >= 0; + + internalList.set(index, completeTask); + } + /** * Removes the equivalent task from the list. * diff --git a/src/main/java/seedu/task/storage/XmlAdaptedTask.java b/src/main/java/seedu/task/storage/XmlAdaptedTask.java index 280018bf6f4a..7041263717ca 100644 --- a/src/main/java/seedu/task/storage/XmlAdaptedTask.java +++ b/src/main/java/seedu/task/storage/XmlAdaptedTask.java @@ -18,10 +18,16 @@ public class XmlAdaptedTask { @XmlElement(required = true) private String name; -// @XmlElement(required = false) -// private DateTime openTime; -// @XmlElement(required = false) -// private DateTime closeTime; + + @XmlElement(required = false) + private String openTime; + + @XmlElement(required = false) + private String closeTime; + + @XmlElement(required = false) + private boolean isComplete; + @XmlElement(required = false) private boolean isImportant; @@ -41,14 +47,15 @@ public XmlAdaptedTask() {} */ public XmlAdaptedTask(ReadOnlyTask source) { name = source.getName().taskName; -// openTime = source.getOpenTime(); -// closeTime = source.getCloseTime(); -// isImportant = source.getImportance(); + openTime = source.getOpenTime().toString(); + closeTime = source.getCloseTime().toString(); + isComplete = source.getComplete(); + isImportant = source.getImportance(); tagged = new ArrayList<>(); for (Tag tag : source.getTags()) { - tagged.add(new XmlAdaptedTag(tag)); + tagged.add(new XmlAdaptedTag(tag)); } - isImportant= source.getImportance(); + } /** @@ -62,11 +69,11 @@ public Task toModelType() throws IllegalValueException { taskTags.add(tag.toModelType()); } final Name name = new Name(this.name); -// final DateTime openTime = new DateTime(this.openTime); -// final DateTime closeTime = new DateTime(this.closeTime); -// final boolean isImportant = this.isImportant; + final DateTime openTime = new DateTime(this.openTime); + final DateTime closeTime = new DateTime(this.closeTime); final UniqueTagList tags = new UniqueTagList(taskTags); - final boolean isImportant= this.isImportant; - return new Task(name, tags, isImportant); //(name, openTime, closeTime, isImportant, tags) + final boolean isImportant = this.isImportant; + final boolean isComplete = this.isComplete; + return new Task(name, openTime, closeTime, isImportant, isComplete, tags); } } diff --git a/src/main/java/seedu/task/storage/XmlFileStorage.java b/src/main/java/seedu/task/storage/XmlFileStorage.java index e21139d36f1b..0fdbe51dae75 100644 --- a/src/main/java/seedu/task/storage/XmlFileStorage.java +++ b/src/main/java/seedu/task/storage/XmlFileStorage.java @@ -9,16 +9,16 @@ import java.io.FileNotFoundException; /** - * Stores addressbook data in an XML file + * Stores taskmanager data in an XML file */ public class XmlFileStorage { /** - * Saves the given addressbook data to the specified file. + * Saves the given taskmanager data to the specified file. */ - public static void saveDataToFile(File file, XmlSerializableTaskManager addressBook) + public static void saveDataToFile(File file, XmlSerializableTaskManager taskManager) throws FileNotFoundException { try { - XmlUtil.saveDataToFile(file, addressBook); + XmlUtil.saveDataToFile(file, taskManager); } catch (JAXBException e) { assert false : "Unexpected exception " + e.getMessage(); } diff --git a/src/main/java/seedu/task/ui/StatusBarFooter.java b/src/main/java/seedu/task/ui/StatusBarFooter.java index ea63cc9a8e4f..a76c39bc84b2 100644 --- a/src/main/java/seedu/task/ui/StatusBarFooter.java +++ b/src/main/java/seedu/task/ui/StatusBarFooter.java @@ -91,7 +91,7 @@ public String getFxmlPath() { } @Subscribe - public void handleAddressBookChangedEvent(TaskManagerChangedEvent abce) { + public void handleTaskManagerChangedEvent(TaskManagerChangedEvent abce) { String lastUpdated = (new Date()).toString(); logger.info(LogsCenter.getEventHandlingLogMessage(abce, "Setting last updated status to " + lastUpdated)); setSyncStatus("Last Updated: " + lastUpdated); diff --git a/src/main/java/seedu/task/ui/TaskCard.java b/src/main/java/seedu/task/ui/TaskCard.java index 277e032fd92b..85d0cc525657 100644 --- a/src/main/java/seedu/task/ui/TaskCard.java +++ b/src/main/java/seedu/task/ui/TaskCard.java @@ -7,6 +7,7 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; import javafx.scene.shape.SVGPath; +import javafx.scene.text.Text; import seedu.task.model.task.ReadOnlyTask; public class TaskCard extends UiPart{ @@ -15,12 +16,22 @@ public class TaskCard extends UiPart{ @FXML private HBox cardPane; + @FXML - private Label name; + private Text name; + @FXML private Label id; + @FXML private SVGPath star; + + @FXML + private Label openTime; + + @FXML + private Label closeTime; + @FXML private AnchorPane tagsListPlaceholder; @@ -43,14 +54,21 @@ public static TaskCard load(ReadOnlyTask task, int displayedIndex){ public void initialize() { name.setText(task.getName().taskName); id.setText(displayedIndex + ". "); + openTime.setText("Start: "+task.getOpenTime().toPrettyString()); + closeTime.setText("End: "+task.getCloseTime().toPrettyString()); tagListPanel = TagListPanel.load(getPrimaryStage(), tagsListPlaceholder, task.getTags().getInternalList()); - setImportant(); + setVisualFlags(); } - private void setImportant() { + private void setVisualFlags() { if (!task.getImportance()) { star.setOpacity(0.0); } + + if (task.getComplete()) { + cardPane.setId("cardPane-completed"); + name.setStrikethrough(true); + } } public HBox getLayout() { diff --git a/src/main/resources/view/DarkTheme.css b/src/main/resources/view/DarkTheme.css index 39b921febfa3..aba795d1cdee 100644 --- a/src/main/resources/view/DarkTheme.css +++ b/src/main/resources/view/DarkTheme.css @@ -282,6 +282,10 @@ -fx-border-width: 1 1 1 1; } +#cardPane-completed { + -fx-opacity: 0.2; +} + #commandTypeLabel { -fx-font-size: 11px; -fx-text-fill: #F70D1A; diff --git a/src/main/resources/view/TaskListCard.fxml b/src/main/resources/view/TaskListCard.fxml index 61c3879615e7..3f2b19362761 100644 --- a/src/main/resources/view/TaskListCard.fxml +++ b/src/main/resources/view/TaskListCard.fxml @@ -3,6 +3,7 @@ + @@ -27,10 +28,20 @@ - + + + + diff --git a/src/test/data/ConfigUtilTest/ExtraValuesConfig.json b/src/test/data/ConfigUtilTest/ExtraValuesConfig.json index 97f96a30c33a..74409d629958 100644 --- a/src/test/data/ConfigUtilTest/ExtraValuesConfig.json +++ b/src/test/data/ConfigUtilTest/ExtraValuesConfig.json @@ -2,7 +2,7 @@ "appTitle" : "Typical App Title", "logLevel" : "INFO", "userPrefsFilePath" : "C:\\preferences.json", - "addressBookFilePath" : "taskmanager.xml", - "addressBookName" : "TypicalAddressBookName", + "taskManagerFilePath" : "data/taskmanager.xml", + "taskManagerName" : "MESS", "extra" : "extra value" } \ No newline at end of file diff --git a/src/test/data/ConfigUtilTest/TypicalConfig.json b/src/test/data/ConfigUtilTest/TypicalConfig.json index 117791a44194..50e787694320 100644 --- a/src/test/data/ConfigUtilTest/TypicalConfig.json +++ b/src/test/data/ConfigUtilTest/TypicalConfig.json @@ -2,6 +2,6 @@ "appTitle" : "Typical App Title", "logLevel" : "INFO", "userPrefsFilePath" : "C:\\preferences.json", - "addressBookFilePath" : "taskmanager.xml", - "addressBookName" : "TypicalTaskManagerName" + "taskManagerFilePath" : "data/taskmanager.xml", + "taskManagerName" : "MESS" } \ No newline at end of file diff --git a/src/test/java/guitests/CompleteCommandTest.java b/src/test/java/guitests/CompleteCommandTest.java new file mode 100644 index 000000000000..1154daf0fb63 --- /dev/null +++ b/src/test/java/guitests/CompleteCommandTest.java @@ -0,0 +1,51 @@ +package guitests; + +import static org.junit.Assert.assertTrue; +import static seedu.task.logic.commands.CompleteCommand.MESSAGE_COMPLETE_TASK_SUCCESS; + +import org.junit.Test; + +import seedu.task.commons.core.Messages; +import seedu.task.commons.exceptions.IllegalValueException; +import seedu.task.model.task.ReadOnlyTask; +import seedu.task.testutil.TestTask; + +public class CompleteCommandTest extends TaskManagerGuiTest { + @Test + public void complete() throws IllegalValueException { + TestTask[] currentList = td.getTypicalTasks(); + int targetIndex = 1; + + // invalid index + commandBox.runCommand("complete " + (currentList.length + 1)); + assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + + // mark the first task as complete + commandBox.runCommand("complete " + targetIndex); + ReadOnlyTask newTask = taskListPanel.getTask(targetIndex - 1); + assertTrue(newTask.getComplete()); + + // confirm the result message is correct + assertResultMessage(String.format(MESSAGE_COMPLETE_TASK_SUCCESS, newTask)); + + // mark another task as complete + targetIndex = 3; + commandBox.runCommand("complete " + targetIndex); + ReadOnlyTask otherTask = taskListPanel.getTask(targetIndex - 1); + assertTrue(otherTask.getComplete()); + assertResultMessage(String.format(MESSAGE_COMPLETE_TASK_SUCCESS, otherTask)); + + // mark the last task as complete + targetIndex = currentList.length; + commandBox.runCommand("complete " + targetIndex); + newTask = taskListPanel.getTask(targetIndex - 1); + assertTrue(newTask.getComplete()); + assertResultMessage(String.format(MESSAGE_COMPLETE_TASK_SUCCESS, newTask)); + + // mark at an empty list + commandBox.runCommand("clear"); + commandBox.runCommand("complete " + (currentList.length + 1)); + assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + } + +} diff --git a/src/test/java/guitests/TaskManagerGuiTest.java b/src/test/java/guitests/TaskManagerGuiTest.java index bfa761bd0a14..814da03d3fea 100644 --- a/src/test/java/guitests/TaskManagerGuiTest.java +++ b/src/test/java/guitests/TaskManagerGuiTest.java @@ -11,6 +11,7 @@ import seedu.task.TestApp; import seedu.task.commons.core.EventsCenter; +import seedu.task.commons.exceptions.IllegalValueException; import seedu.task.model.TaskManager; import seedu.task.model.task.ReadOnlyTask; import seedu.task.testutil.TestUtil; @@ -78,7 +79,11 @@ public void setup() throws Exception { */ protected TaskManager getInitialData() { TaskManager ab = TestUtil.generateEmptyTaskManager(); - TypicalTestTasks.loadTaskManagerWithSampleData(ab); + try { + TypicalTestTasks.loadTaskManagerWithSampleData(ab); + } catch (IllegalValueException e) { + e.printStackTrace(); + } return ab; } diff --git a/src/test/java/guitests/guihandles/GuiHandle.java b/src/test/java/guitests/guihandles/GuiHandle.java index f8eecad3eaad..25b921cf0f34 100644 --- a/src/test/java/guitests/guihandles/GuiHandle.java +++ b/src/test/java/guitests/guihandles/GuiHandle.java @@ -2,9 +2,9 @@ import guitests.GuiRobot; import javafx.scene.Node; -import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.input.KeyCode; +import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.stage.Window; import seedu.task.TestApp; @@ -64,10 +64,11 @@ public void pressEnter() { } protected String getTextFromLabel(String fieldId, Node parentNode) { - return ((Label) guiRobot.from(parentNode).lookup(fieldId).tryQuery().get()).getText(); + return ((Text) guiRobot.from(parentNode).lookup(fieldId).tryQuery().get()).getText(); } public void focusOnSelf() { + if (stageTitle != null) { focusOnWindow(stageTitle); } @@ -77,6 +78,7 @@ public void focusOnMainApp() { this.focusOnWindow(TestApp.APP_TITLE); } + public void closeWindow() { java.util.Optional window = guiRobot.listTargetWindows() .stream() diff --git a/src/test/java/guitests/guihandles/TaskListPanelHandle.java b/src/test/java/guitests/guihandles/TaskListPanelHandle.java index 91d612d1094e..73ff3c18797b 100644 --- a/src/test/java/guitests/guihandles/TaskListPanelHandle.java +++ b/src/test/java/guitests/guihandles/TaskListPanelHandle.java @@ -7,6 +7,7 @@ import javafx.scene.control.ListView; import javafx.stage.Stage; import seedu.task.TestApp; +import seedu.task.commons.exceptions.IllegalValueException; import seedu.task.testutil.TestUtil; import seedu.task.model.task.ReadOnlyTask; import seedu.task.model.task.Task; @@ -153,7 +154,12 @@ public ReadOnlyTask getTask(int index) { } public TaskCardHandle getTaskCardHandle(int index) { - return getTaskCardHandle(new Task(getListView().getItems().get(index))); + try { + return getTaskCardHandle(new Task(getListView().getItems().get(index))); + } catch (IllegalValueException e) { + e.printStackTrace(); + } + return null; } public TaskCardHandle getTaskCardHandle(ReadOnlyTask task) { diff --git a/src/test/java/seedu/task/logic/LogicManagerTest.java b/src/test/java/seedu/task/logic/LogicManagerTest.java index 89d545fe1722..57ab1f031ae7 100644 --- a/src/test/java/seedu/task/logic/LogicManagerTest.java +++ b/src/test/java/seedu/task/logic/LogicManagerTest.java @@ -150,16 +150,14 @@ public void execute_clear() throws Exception { } -// @Test -// public void execute_add_invalidArgsFormat() throws Exception { -// String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); -// assertCommandBehavior( -// "add Valid Name 12345 e/valid@email.butNoPhonePrefix a/valid, address", expectedMessage); -// assertCommandBehavior( -// "add Valid Name p/12345 valid@email.butNoPrefix a/valid, address", expectedMessage); -// assertCommandBehavior( -// "add Valid Name p/12345 e/valid@email.butNoAddressPrefix valid, address", expectedMessage); -// } + @Test + public void execute_add_invalidArgsFormat() throws Exception { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); + assertCommandBehavior( + "add s/today c/tomorrow", expectedMessage); + assertCommandBehavior( + "add Valid Name a/sadsadsad", expectedMessage); + } @Test public void execute_add_invalidTaskData() throws Exception { @@ -167,6 +165,12 @@ public void execute_add_invalidTaskData() throws Exception { "add []\\[;]", Name.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( "add Do CS2103 t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS); + assertCommandBehavior("add Do CS2103 s/hello", DateTime.MESSAGE_DATETIME_CONSTRAINTS); + assertCommandBehavior("add Do CS2103 s/hello c/bbye", DateTime.MESSAGE_DATETIME_CONSTRAINTS); + assertCommandBehavior("add Do CS2103 c/bbye", DateTime.MESSAGE_DATETIME_CONSTRAINTS); + assertCommandBehavior("add Do CS2103 s/tomorrow c/today", Task.MESSAGE_DATETIME_CONSTRAINTS); + assertCommandBehavior("add Do CS2103 s/6 hours from now c/3 hours from now", Task.MESSAGE_DATETIME_CONSTRAINTS); + } @@ -382,14 +386,13 @@ class TestDataHelper{ Task adam() throws Exception { Name name = new Name("Adam Brown"); -// Phone privatePhone = new Phone("111111"); -// Email email = new Email("adam@gmail.com"); -// Address privateAddress = new Address("111, alpha street"); Tag tag1 = new Tag("tag1"); Tag tag2 = new Tag("tag2"); UniqueTagList tags = new UniqueTagList(tag1, tag2); - boolean isImportant=false; - return new Task(name, tags,isImportant); //privatePhone, email, privateAddress, + + boolean isImportant = false; + boolean isComplete = false; + return new Task(name, new DateTime(null), new DateTime(null), isImportant, isComplete, tags); } /** @@ -402,11 +405,11 @@ Task adam() throws Exception { Task generateTask(int seed) throws Exception { return new Task( new Name("Task " + seed), -// new Phone("" + Math.abs(seed)), -// new Email(seed + "@email"), -// new Address("House of " + seed), - new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))), - false + new DateTime("" + Math.abs(seed)+" days from now"), + new DateTime(""), + false, + false, + new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))) ); } @@ -417,9 +420,7 @@ String generateAddCommand(Task p) { cmd.append("add "); cmd.append(p.getName().toString()); -// cmd.append(" p/").append(p.getPhone()); -// cmd.append(" e/").append(p.getEmail()); -// cmd.append(" a/").append(p.getAddress()); + UniqueTagList tags = p.getTags(); for(Tag t: tags){ @@ -502,10 +503,11 @@ List generateTaskList(Task... Tasks) { Task generateTaskWithName(String name) throws Exception { return new Task( new Name(name), -// new Phone("1"), -// new Email("1@email"), -// new Address("House of 1"), - new UniqueTagList(new Tag("tag")),false + new DateTime("tomorrow"), + new DateTime("day after tomorrow"), + false, + false, + new UniqueTagList(new Tag("tag")) ); } } diff --git a/src/test/java/seedu/task/testutil/TaskBuilder.java b/src/test/java/seedu/task/testutil/TaskBuilder.java index aacfac2551c0..d5f505e441a8 100644 --- a/src/test/java/seedu/task/testutil/TaskBuilder.java +++ b/src/test/java/seedu/task/testutil/TaskBuilder.java @@ -27,25 +27,21 @@ public TaskBuilder withTags(String ... tags) throws IllegalValueException { return this; } -// public TaskBuilder withAddress(String address) throws IllegalValueException { -// this.task.setAddress(new Address(address)); -// return this; -// } -// -// public TaskBuilder withPhone(String phone) throws IllegalValueException { -// this.task.setPhone(new Phone(phone)); -// return this; -// } -// -// public PersonBuilder withEmail(String email) throws IllegalValueException { -// this.person.setEmail(new Email(email)); -// return this; -// } public TaskBuilder withImportance(boolean isImportant) throws IllegalValueException{ this.task.setIsImportant(isImportant); return this; } + public TaskBuilder withOpenTime(String openTime) throws IllegalValueException { + this.task.setOpenTime(new DateTime(openTime)); + return this; + } + + public TaskBuilder withCloseTime(String closeTime) throws IllegalValueException { + this.task.setCloseTime(new DateTime(closeTime)); + return this; + } + public TestTask build() { return this.task; } diff --git a/src/test/java/seedu/task/testutil/TestTask.java b/src/test/java/seedu/task/testutil/TestTask.java index 4c5e0581c181..d6fb9c11d192 100644 --- a/src/test/java/seedu/task/testutil/TestTask.java +++ b/src/test/java/seedu/task/testutil/TestTask.java @@ -9,11 +9,11 @@ public class TestTask implements ReadOnlyTask { private Name name; -// private Address address; -// private Email email; -// private Phone phone; + private DateTime openTime; + private DateTime closeTime; private UniqueTagList tags; private boolean isImportant; + private boolean isCompleted; public TestTask() { tags = new UniqueTagList(); @@ -27,37 +27,37 @@ public void setIsImportant(boolean isImportant){ this.isImportant=isImportant; } -// public void setAddress(Address address) { -// this.address = address; -// } -// -// public void setEmail(Email email) { -// this.email = email; -// } -// -// public void setPhone(Phone phone) { -// this.phone = phone; -// } + public void setOpenTime(DateTime openTime) { + this.openTime = openTime; + } + + public void setCloseTime(DateTime closeTime) { + this.closeTime = closeTime; + } + + public void setIsCompleted(boolean isCompleted){ + this.isCompleted = isCompleted; + } @Override public Name getName() { return name; } -// @Override -// public Phone getPhone() { -// return phone; -// } -// -// @Override -// public Email getEmail() { -// return email; -// } -// -// @Override -// public Address getAddress() { -// return address; -// } + @Override + public boolean getComplete() { + return isCompleted; + } + + @Override + public DateTime getOpenTime() { + return openTime; + } + + @Override + public DateTime getCloseTime() { + return closeTime; + } @Override public UniqueTagList getTags() { @@ -76,9 +76,8 @@ public String toString() { public String getAddCommand() { StringBuilder sb = new StringBuilder(); sb.append("add " + this.getName().taskName + " "); -// sb.append("p/" + this.getPhone().value + " "); -// sb.append("e/" + this.getEmail().value + " "); -// sb.append("a/" + this.getAddress().value + " "); + sb.append("s/" + this.getOpenTime().toPrettyString() + " "); + sb.append("c/" + this.getCloseTime().toPrettyString() + " "); this.getTags().getInternalList().stream().forEach(s -> sb.append("t/" + s.tagName + " ")); return sb.toString(); } @@ -86,9 +85,8 @@ public String getAddCommand() { public String getArgs() { StringBuilder sb = new StringBuilder(); sb.append(" "+this.getName().taskName + " "); -// sb.append("p/" + this.getPhone().value + " "); -// sb.append("e/" + this.getEmail().value + " "); -// sb.append("a/" + this.getAddress().value + " "); + sb.append("s/" + this.getOpenTime().toPrettyString() + " "); + sb.append("c/" + this.getCloseTime().toPrettyString() + " "); this.getTags().getInternalList().stream().forEach(s -> sb.append("t/" + s.tagName + " ")); return sb.toString(); } diff --git a/src/test/java/seedu/task/testutil/TestUtil.java b/src/test/java/seedu/task/testutil/TestUtil.java index a401485c712e..978117b15571 100644 --- a/src/test/java/seedu/task/testutil/TestUtil.java +++ b/src/test/java/seedu/task/testutil/TestUtil.java @@ -66,15 +66,15 @@ public static void assertThrows(Class expected, Runnable ex private static Task[] getSampleTaskData() { try { return new Task[]{ - new Task(new Name("Ali Muster"), new UniqueTagList(), false),//, new Phone("9482424"), new Email("hans@google.com"), new Address("4th street"), new UniqueTagList()), - new Task(new Name("Boris Mueller"), new UniqueTagList(), false),//, new Phone("87249245"), new Email("ruth@google.com"), new Address("81th street"), new UniqueTagList()), - new Task(new Name("Carl Kurz"), new UniqueTagList(), false),//, new Phone("95352563"), new Email("heinz@yahoo.com"), new Address("wall street"), new UniqueTagList()), - new Task(new Name("Daniel Meier"), new UniqueTagList(), false),// new Phone("87652533"), new Email("cornelia@google.com"), new Address("10th street"), new UniqueTagList()), - new Task(new Name("Elle Meyer"), new UniqueTagList(), false),// new Phone("9482224"), new Email("werner@gmail.com"), new Address("michegan ave"), new UniqueTagList()), - new Task(new Name("Fiona Kunz"), new UniqueTagList(), false),// new Phone("9482427"), new Email("lydia@gmail.com"), new Address("little tokyo"), new UniqueTagList()), - new Task(new Name("George Best"), new UniqueTagList(), false),// new Phone("9482442"), new Email("anna@google.com"), new Address("4th street"), new UniqueTagList()), - new Task(new Name("Hoon Meier"), new UniqueTagList(), false),// new Phone("8482424"), new Email("stefan@mail.com"), new Address("little india"), new UniqueTagList()), - new Task(new Name("Ida Mueller"), new UniqueTagList(), false),// new Phone("8482131"), new Email("hans@google.com"), new Address("chicago ave"), new UniqueTagList()) + new Task(new Name("Ali Muster"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList() ), + new Task(new Name("Boris Mueller"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()), + new Task(new Name("Carl Kurz"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()), + new Task(new Name("Daniel Meier"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()), + new Task(new Name("Elle Meyer"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()), + new Task(new Name("Fiona Kunz"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()), + new Task(new Name("George Best"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()), + new Task(new Name("Hoon Meier"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()), + new Task(new Name("Ida Mueller"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()), }; } catch (IllegalValueException e) { assert false; diff --git a/src/test/java/seedu/task/testutil/TypicalTestTasks.java b/src/test/java/seedu/task/testutil/TypicalTestTasks.java index 1d93715a8b0b..b20b4d243cbc 100644 --- a/src/test/java/seedu/task/testutil/TypicalTestTasks.java +++ b/src/test/java/seedu/task/testutil/TypicalTestTasks.java @@ -13,28 +13,33 @@ public class TypicalTestTasks { public TypicalTestTasks() { try { - cs2103 = new TaskBuilder().withName("Do CS 2103").//withAddress("123, Jurong West Ave 6, #08-111") - //.withEmail("alice@gmail.com").withPhone("85355255") - withTags("friends").withImportance(false).build(); - laundry = new TaskBuilder().withName("Meier").//withAddress("311, Clementi Ave 2, #02-25") - //.withEmail("johnd@gmail.com").withPhone("98765432") - withTags("urgent", "important").withImportance(false).build(); - carl = new TaskBuilder().withName("Meet Carl").build();//withPhone("95352563").withEmail("heinz@yahoo.com").withAddress("wall street").build(); - daniel = new TaskBuilder().withName("Have lunch with Meier").build();//.withPhone("87652533").withEmail("cornelia@google.com").withAddress("10th street").build(); - elle = new TaskBuilder().withName("Take Ellie out on a date").build();//.withPhone("9482224").withEmail("werner@gmail.com").withAddress("michegan ave").build(); - fiona = new TaskBuilder().withName("Buy a Shrek and Fiona Toy").build();//withPhone("9482427").withEmail("lydia@gmail.com").withAddress("little tokyo").build(); - george = new TaskBuilder().withName("Watch George Best Videos").build();//withPhone("9482442").withEmail("anna@google.com").withAddress("4th street").build(); + cs2103 = new TaskBuilder().withName("Do CS 2103").withOpenTime("next thursday") + .withCloseTime("next friday").withTags("friends").withImportance(false).build(); + laundry = new TaskBuilder().withName("Meier").withOpenTime("tomorrow") + .withCloseTime("day after tomorrow").withImportance(false).withTags("urgent", "important").build(); + carl = new TaskBuilder().withName("Meet Carl").withOpenTime("next thursday") + .withCloseTime("next friday").build(); + daniel = new TaskBuilder().withName("Have lunch with Meier").withOpenTime("6 hours from now") + .withCloseTime("8 hours from now").build(); + elle = new TaskBuilder().withName("Take Ellie out on a date").withOpenTime("6 hours from now") + .withCloseTime("12 hours from now").build(); + fiona = new TaskBuilder().withName("Buy a Shrek and Fiona Toy").withOpenTime("tomorrow") + .withCloseTime("day after tomorrow").build(); + george = new TaskBuilder().withName("Watch George Best Videos").withOpenTime("tomorrow") + .withCloseTime("day after tomorrow").build(); //Manually added - hoon = new TaskBuilder().withName("Hoon Meier").withTags("omg").withImportance(false).build();//withPhone("8482424").withEmail("stefan@mail.com").withAddress("little india").build(); - ida = new TaskBuilder().withName("Ida Mueller").build();//withPhone("8482131").withEmail("hans@google.com").withAddress("chicago ave").build(); + hoon = new TaskBuilder().withName("Hoon Meier").withOpenTime("tomorrow") + .withCloseTime("day after tomorrow").withTags("omg").withImportance(false).build(); + ida = new TaskBuilder().withName("Ida Mueller").withOpenTime("tomorrow") + .withCloseTime("day after tomorrow").build(); } catch (IllegalValueException e) { e.printStackTrace(); assert false : "not possible"; } } - public static void loadTaskManagerWithSampleData(TaskManager ab) { + public static void loadTaskManagerWithSampleData(TaskManager ab) throws IllegalValueException { try { ab.addTask(new Task(cs2103)); @@ -55,7 +60,12 @@ public TestTask[] getTypicalTasks() { public TaskManager getTypicalTaskManager(){ TaskManager ab = new TaskManager(); - loadTaskManagerWithSampleData(ab); + try { + loadTaskManagerWithSampleData(ab); + } catch (IllegalValueException e) { + e.printStackTrace(); + assert false: "Invalid sample task data"; + } return ab; } }