diff --git a/src/main/java/Enums/TaskType.java b/src/main/java/Enums/TaskType.java index ff1122c311..59280dd321 100644 --- a/src/main/java/Enums/TaskType.java +++ b/src/main/java/Enums/TaskType.java @@ -2,5 +2,5 @@ public enum TaskType { list, bye, find, done , delete, time, snooze, others, help, priority, reorder, - restore, add, subtask, update, sort, log, overdue, reschedule, completed, show, removeoverdue + restore, add, subtask, update, sort, log, overdue, reschedule, completed, show, removeoverdue, reopen } diff --git a/src/main/java/Model_Classes/Leave.java b/src/main/java/Model_Classes/Leave.java index d5b9825c60..a1a282ee4c 100644 --- a/src/main/java/Model_Classes/Leave.java +++ b/src/main/java/Model_Classes/Leave.java @@ -75,4 +75,12 @@ public String getAssignee() { public String toString() { return "[L] " + super.getDescription() + " (" + user + ")" + " (From: " + from + " To: " + to + ")"; } + + /** + * setter for user + * @param user name of user for the leave + */ + public void setUser(String user) { + this.user = user; + } } \ No newline at end of file diff --git a/src/main/java/Operations/TaskCreator.java b/src/main/java/Operations/TaskCreator.java index 55a852a013..37156402b1 100644 --- a/src/main/java/Operations/TaskCreator.java +++ b/src/main/java/Operations/TaskCreator.java @@ -468,12 +468,12 @@ public void updateTask(String input, Task oldTask) throws RoomShareException { } } - else if (input.contains("*")) { + if (input.contains("*")) { Priority priority = this.extractPriority(input); oldTask.setPriority(priority); } - else if (input.contains("@")) { + if (input.contains("@")) { String assignee = null; try { assignee = this.extractAssignee(input); @@ -481,9 +481,13 @@ else if (input.contains("@")) { assignee = "everyone"; } oldTask.setAssignee(assignee); + if (oldTask instanceof Leave) { + Leave oldLeave = (Leave) oldTask; + oldLeave.setUser(assignee); + } } - else if (input.contains("^") && oldTask instanceof Meeting) { + if (input.contains("^") && oldTask instanceof Meeting) { Pair durationAndUnit = this.extractDuration(input); int duration = durationAndUnit.getKey(); TimeUnit unit = durationAndUnit.getValue(); @@ -491,12 +495,12 @@ else if (input.contains("^") && oldTask instanceof Meeting) { oldMeeting.setDuration(duration,unit); } - else if (input.contains("%")) { + if (input.contains("%")) { RecurrenceScheduleType recurrence = this.extractRecurrence(input); oldTask.setRecurrenceSchedule(recurrence); } - else if(input.contains("uncheck") && !(oldTask instanceof Leave)) { + if(input.contains("uncheck") && !(oldTask instanceof Leave)) { boolean checked = oldTask.getDone(); oldTask.setDone(!checked); } diff --git a/src/main/java/Operations/TaskList.java b/src/main/java/Operations/TaskList.java index a3d2c6164f..11c3d69ef3 100644 --- a/src/main/java/Operations/TaskList.java +++ b/src/main/java/Operations/TaskList.java @@ -492,4 +492,19 @@ public int[] listTagged(String user) throws RoomShareException{ int[] done = {belongCount, doneCount}; return done; } + + /** + * sets the tasks which are done to an undone state. + * @param index index of task + * @param date date the new deadline of the task + * @throws RoomShareException when the task selected is a Leave + */ + public void reopen(int index, Date date) throws RoomShareException { + tasks.get(index).setDate(date); + CheckAnomaly.checkDuplicate(tasks.get(index)); + if (tasks.get(index) instanceof Meeting) { + CheckAnomaly.checkTimeClash(tasks.get(index)); + } + tasks.get(index).setDone(false); + } } diff --git a/src/main/java/Operations/Ui.java b/src/main/java/Operations/Ui.java index eb934adcb9..fb35aace24 100644 --- a/src/main/java/Operations/Ui.java +++ b/src/main/java/Operations/Ui.java @@ -337,4 +337,8 @@ public void showTaggedPercentage(String user) { public void showDeletedList() { System.out.println("Here are the tasks that you have deleted and are in temporary storage"); } + + public void showDoneList() { + System.out.println("These are the tasks that you have already done:"); + } } diff --git a/src/main/java/RoomShare.java b/src/main/java/RoomShare.java index 70ad79a538..d53a75b10b 100644 --- a/src/main/java/RoomShare.java +++ b/src/main/java/RoomShare.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Date; /** * Main class of the RoomShare program. @@ -430,6 +431,21 @@ public void run() throws RoomShareException, IOException, InterruptedException { } break; + case reopen: + Ui.clearScreen(); + String userInput = parser.getCommandLine(); + ui.showDoneList(); + taskList.showCompleted(); + try { + int index = parser.getIndex(userInput); + ArrayList date = taskCreator.extractDate(userInput); + taskList.reopen(index,date.get(0)); + } catch (RoomShareException e) { + ui.showError(e); + } + listRoutine.list(); + break; + default: Ui.clearScreen(); ui.startUp();