Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added reopen function #225

Merged
merged 3 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/Enums/TaskType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions src/main/java/Model_Classes/Leave.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
14 changes: 9 additions & 5 deletions src/main/java/Operations/TaskCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,35 +468,39 @@ 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);
} catch (RoomShareException e) {
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<Integer, TimeUnit> durationAndUnit = this.extractDuration(input);
int duration = durationAndUnit.getKey();
TimeUnit unit = durationAndUnit.getValue();
Meeting oldMeeting = (Meeting) oldTask;
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);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/Operations/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions src/main/java/Operations/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
}
}
16 changes: 16 additions & 0 deletions src/main/java/RoomShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;

/**
* Main class of the RoomShare program.
Expand Down Expand Up @@ -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> date = taskCreator.extractDate(userInput);
taskList.reopen(index,date.get(0));
} catch (RoomShareException e) {
ui.showError(e);
}
listRoutine.list();
break;

default:
Ui.clearScreen();
ui.startUp();
Expand Down