Skip to content

Commit 91b658d

Browse files
authored
Merge pull request #256 from BryanYap972/branch-v1.3
Added add, delete and done commands for IP project Progress tracker.
2 parents 476cff2 + 07f0182 commit 91b658d

File tree

17 files changed

+557
-6
lines changed

17 files changed

+557
-6
lines changed

src/main/java/seedu/nova/logic/commands/commoncommands/NavCommand.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import seedu.nova.logic.parser.ModeEnum;
88
import seedu.nova.model.Mode;
99
import seedu.nova.model.Model;
10+
import seedu.nova.model.progresstracker.Ip;
11+
import seedu.nova.model.progresstracker.ProgressTracker;
1012

1113
/**
1214
* Class for navigation command
@@ -31,6 +33,15 @@ public CommandResult execute(Model model) {
3133

3234
if (mode.getModeEnum().equals(this.modeEnum)) {
3335
return new CommandResult(String.format(MESSAGE_SAME_MODE, modeEnum.name().toLowerCase()), false, false);
36+
} else if (this.modeEnum.equals(ModeEnum.PROGRESSTRACKER)) {
37+
ProgressTracker pt = model.getProgressTracker();
38+
Ip ip = pt.getIp();
39+
double ipProgress = ip.getProgress();
40+
41+
String messageProgresstracker = "Projects: \n"
42+
+ " IP Project: " + ipProgress + "%\n"
43+
+ " TP Project: 0%";
44+
return new CommandResult(messageProgresstracker, false, false);
3445
} else {
3546
mode.setModeEnum(this.modeEnum);
3647
return new CommandResult(MESSAGE_SUCCESS + mode.getModeEnum().name(), true, false);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package seedu.nova.logic.commands.ptcommands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_DESC;
5+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_PROJECT;
6+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_WEEK;
7+
8+
import seedu.nova.logic.commands.Command;
9+
import seedu.nova.logic.commands.CommandResult;
10+
import seedu.nova.logic.commands.exceptions.CommandException;
11+
import seedu.nova.model.Model;
12+
import seedu.nova.model.progresstracker.Ip;
13+
import seedu.nova.model.progresstracker.ProgressTracker;
14+
import seedu.nova.model.progresstracker.PtTask;
15+
import seedu.nova.model.progresstracker.PtTaskList;
16+
import seedu.nova.model.progresstracker.PtWeek;
17+
import seedu.nova.model.progresstracker.PtWeekList;
18+
import seedu.nova.model.progresstracker.TaskDesc;
19+
20+
/**
21+
* Adds task to specified week
22+
*/
23+
public class PtAddCommand extends Command {
24+
public static final String COMMAND_WORD = "add";
25+
26+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds task in the "
27+
+ "project in the specified week. "
28+
+ "Parameters: "
29+
+ PREFIX_PROJECT + "PROJECT "
30+
+ PREFIX_WEEK + "WEEK "
31+
+ PREFIX_DESC + "TASK DESCRIPTION \n"
32+
+ "Example: " + COMMAND_WORD + " "
33+
+ PREFIX_PROJECT + "Ip "
34+
+ PREFIX_WEEK + "2"
35+
+ PREFIX_DESC + "Implement javafx";
36+
37+
private int weekNum;
38+
private String project;
39+
private String taskDesc;
40+
41+
public PtAddCommand(int weekNum, String project, String taskDesc) {
42+
this.weekNum = weekNum;
43+
this.project = project.trim().toLowerCase();
44+
this.taskDesc = taskDesc;
45+
}
46+
47+
@Override
48+
public CommandResult execute(Model model) throws CommandException {
49+
requireNonNull(model);
50+
ProgressTracker pt = model.getProgressTracker();
51+
PtWeek week = null;
52+
53+
//Create new task
54+
TaskDesc taskDesc = new TaskDesc(this.taskDesc);
55+
PtTask newTask = new PtTask(taskDesc, this.weekNum);
56+
57+
if (project.equals("ip")) {
58+
Ip ip = pt.getIp();
59+
PtWeekList weekList = ip.getWeekList();
60+
week = weekList.getWeek(weekNum);
61+
62+
//if week not created, create week
63+
if (week == null) {
64+
PtWeek newWeek = new PtWeek(weekNum);
65+
weekList.addWeek(newWeek);
66+
67+
week = newWeek;
68+
}
69+
70+
PtTaskList taskList = week.getTaskList();
71+
taskList.addTask(newTask);
72+
73+
} else {
74+
//do nothing
75+
}
76+
77+
String result = "Added task to week " + weekNum + " of " + project;
78+
79+
return new CommandResult(result, false, false);
80+
}
81+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package seedu.nova.logic.commands.ptcommands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_DESC;
5+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_PROJECT;
6+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_TASK;
7+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_WEEK;
8+
9+
import seedu.nova.logic.commands.Command;
10+
import seedu.nova.logic.commands.CommandResult;
11+
import seedu.nova.logic.commands.exceptions.CommandException;
12+
import seedu.nova.model.Model;
13+
import seedu.nova.model.progresstracker.Ip;
14+
import seedu.nova.model.progresstracker.ProgressTracker;
15+
import seedu.nova.model.progresstracker.PtTask;
16+
import seedu.nova.model.progresstracker.PtTaskList;
17+
import seedu.nova.model.progresstracker.PtWeek;
18+
import seedu.nova.model.progresstracker.PtWeekList;
19+
20+
/**
21+
* Adds task to specified week
22+
*/
23+
public class PtDeleteCommand extends Command {
24+
public static final String COMMAND_WORD = "delete";
25+
26+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes task in the specified "
27+
+ "project in the specified week. "
28+
+ "Parameters: "
29+
+ PREFIX_PROJECT + "PROJECT "
30+
+ PREFIX_WEEK + "WEEK "
31+
+ PREFIX_DESC + "TASK DESCRIPTION \n"
32+
+ "Example: " + COMMAND_WORD + " "
33+
+ PREFIX_PROJECT + "Ip "
34+
+ PREFIX_WEEK + "2"
35+
+ PREFIX_TASK + "1";
36+
37+
public static final String MESSAGE_NULLWEEK = "Week not added yet";
38+
39+
public static final String MESSAGE_NULLTASK = "No task with that index";
40+
41+
private int weekNum;
42+
private String project;
43+
private int taskNum;
44+
45+
public PtDeleteCommand(int weekNum, String project, int taskNum) {
46+
this.weekNum = weekNum;
47+
this.project = project.trim().toLowerCase();
48+
this.taskNum = taskNum;
49+
}
50+
51+
@Override
52+
public CommandResult execute(Model model) throws CommandException {
53+
requireNonNull(model);
54+
ProgressTracker pt = model.getProgressTracker();
55+
PtWeek week = null;
56+
57+
if (project.equals("ip")) {
58+
Ip ip = pt.getIp();
59+
PtWeekList weekList = ip.getWeekList();
60+
week = weekList.getWeek(weekNum);
61+
62+
//if week not created, create week
63+
if (week == null) {
64+
throw new CommandException(MESSAGE_NULLWEEK);
65+
}
66+
67+
PtTaskList taskList = week.getTaskList();
68+
PtTask taskDelete = taskList.getTask(taskNum);
69+
70+
if (taskDelete == null) {
71+
throw new CommandException(MESSAGE_NULLTASK);
72+
}
73+
74+
taskList.deleteTask(taskNum);
75+
76+
if (taskList.getNumTask() == 0) {
77+
weekList.removeWeek(weekNum);
78+
}
79+
} else {
80+
//do nothing
81+
}
82+
83+
String result = "Deleted task " + taskNum + " in week " + weekNum + " of " + project;
84+
85+
return new CommandResult(result, false, false);
86+
}
87+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package seedu.nova.logic.commands.ptcommands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_DESC;
5+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_PROJECT;
6+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_TASK;
7+
import static seedu.nova.logic.parser.CliSyntax.PREFIX_WEEK;
8+
9+
import seedu.nova.logic.commands.Command;
10+
import seedu.nova.logic.commands.CommandResult;
11+
import seedu.nova.logic.commands.exceptions.CommandException;
12+
import seedu.nova.model.Model;
13+
import seedu.nova.model.progresstracker.Ip;
14+
import seedu.nova.model.progresstracker.ProgressTracker;
15+
import seedu.nova.model.progresstracker.PtTask;
16+
import seedu.nova.model.progresstracker.PtTaskList;
17+
import seedu.nova.model.progresstracker.PtWeek;
18+
import seedu.nova.model.progresstracker.PtWeekList;
19+
20+
/**
21+
* Adds task to specified week
22+
*/
23+
public class PtDoneCommand extends Command {
24+
public static final String COMMAND_WORD = "done";
25+
26+
public static final String MESSAGE_NULLTASK = "No task with that index";
27+
28+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Sets specified task as done "
29+
+ "Parameters: "
30+
+ PREFIX_PROJECT + "PROJECT "
31+
+ PREFIX_WEEK + "WEEK "
32+
+ PREFIX_DESC + "TASK DESCRIPTION \n"
33+
+ "Example: " + COMMAND_WORD + " "
34+
+ PREFIX_PROJECT + "Ip "
35+
+ PREFIX_WEEK + "2"
36+
+ PREFIX_TASK + "1";
37+
38+
private int weekNum;
39+
private String project;
40+
private int taskNum;
41+
42+
public PtDoneCommand(int weekNum, String project, int taskNum) {
43+
this.weekNum = weekNum;
44+
this.project = project.trim().toLowerCase();
45+
this.taskNum = taskNum;
46+
}
47+
48+
@Override
49+
public CommandResult execute(Model model) throws CommandException {
50+
requireNonNull(model);
51+
ProgressTracker pt = model.getProgressTracker();
52+
PtWeek week = null;
53+
54+
if (project.equals("ip")) {
55+
Ip ip = pt.getIp();
56+
PtWeekList weekList = ip.getWeekList();
57+
week = weekList.getWeek(weekNum);
58+
59+
//if week not created, create week
60+
if (week == null) {
61+
throw new CommandException(MESSAGE_NULLTASK);
62+
}
63+
64+
PtTaskList taskList = week.getTaskList();
65+
PtTask task = taskList.getTask(taskNum);
66+
task.setDone();
67+
68+
} else {
69+
//do nothing
70+
}
71+
72+
String result = "Changed done status of task " + taskNum + " in week " + weekNum + " of " + project;
73+
74+
return new CommandResult(result, false, false);
75+
}
76+
}
77+

src/main/java/seedu/nova/logic/commands/ptcommands/PtListCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class PtListCommand extends Command {
2727
+ PREFIX_PROJECT + "Ip "
2828
+ PREFIX_WEEK + "2";
2929

30-
public static final String MESSAGE_NULLWEEK = "Week not added yet";
30+
public static final String MESSAGE_NULLWEEK = "No task in specified week";
3131

3232
private int weekNum;
3333
private String project;
@@ -53,8 +53,8 @@ public CommandResult execute(Model model) throws CommandException {
5353
if (week == null) {
5454
throw new CommandException(MESSAGE_NULLWEEK);
5555
}
56-
57-
String result = week.getTaskList().listTasks();
56+
String header = "IP Project " + "(Week " + weekNum + "):" + "\n";
57+
String result = header + " " + week.getTaskList().listTasks();
5858

5959
return new CommandResult(result, false, false);
6060
}

src/main/java/seedu/nova/logic/parser/CliSyntax.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class CliSyntax {
1515
public static final Prefix PREFIX_DESC = new Prefix("d\\");
1616
public static final Prefix PREFIX_VENUE = new Prefix("v\\");
1717
public static final Prefix PREFIX_TIME = new Prefix("t\\");
18+
public static final Prefix PREFIX_TASK = new Prefix("t\\");
19+
public static final Prefix PREFIX_KEYWORD = new Prefix("k\\");
1820
public static final Prefix PREFIX_INDEX = new Prefix("i\\");
1921
public static final Prefix PREFIX_PROJECT = new Prefix("p\\");
2022
public static final Prefix PREFIX_WEEK = new Prefix("w\\");

src/main/java/seedu/nova/logic/parser/ParserUtil.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import seedu.nova.model.person.Name;
1818
import seedu.nova.model.person.Phone;
1919
import seedu.nova.model.progresstracker.Project;
20+
import seedu.nova.model.progresstracker.TaskDesc;
2021

2122
/**
2223
* Contains utility methods used for parsing strings in the various *Parser classes.
@@ -28,6 +29,7 @@ public class ParserUtil {
2829
*/
2930
public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer.";
3031
public static final String MESSAGE_INVALID_WEEK = "Week is not a non-zero unsigned integer.";
32+
public static final String MESSAGE_INVALID_TASK = "Task number is not a non-zero unsigned integer.";
3133

3234
/**
3335
* Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be
@@ -158,6 +160,21 @@ public static int parseWeek(String week) throws ParseException {
158160
return Integer.parseInt(trimmedWeek);
159161
}
160162

163+
/**
164+
* Parsers task number into an int
165+
* @param taskNum string containing number to specify the task
166+
* @return int of the task input
167+
* @throws ParseException if is non-zero throw exception
168+
*/
169+
public static int parseTask(String taskNum) throws ParseException {
170+
requireNonNull(taskNum);
171+
String trimmedNum = taskNum.trim();
172+
if (!StringUtil.isNonZeroUnsignedInteger(trimmedNum)) {
173+
throw new ParseException(MESSAGE_INVALID_TASK);
174+
}
175+
return Integer.parseInt(trimmedNum);
176+
}
177+
161178
/**
162179
* Checks if project name is correct
163180
* @param project project name
@@ -175,6 +192,23 @@ public static String parseProject(String project) throws ParseException {
175192
return trimmedProject;
176193
}
177194

195+
/**
196+
* Checks if taskDesc is blank
197+
* @param taskDesc task description
198+
* @return task description
199+
* @throws ParseException if task description is blank
200+
*/
201+
public static String parseTaskDesc(String taskDesc) throws ParseException {
202+
requireNonNull(taskDesc);
203+
String trimmedTaskDesc = taskDesc.trim();
204+
205+
if (!TaskDesc.isValidTaskDesc(trimmedTaskDesc)) {
206+
throw new ParseException(TaskDesc.MESSAGE_CONSTRAINTS);
207+
}
208+
209+
return trimmedTaskDesc;
210+
}
211+
178212
/**
179213
* Parse date local date.
180214
*

src/main/java/seedu/nova/logic/parser/ptparsers/ProgresstrackerParser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import java.util.regex.Pattern;
66

77
import seedu.nova.logic.commands.Command;
8+
import seedu.nova.logic.commands.ptcommands.PtAddCommand;
9+
import seedu.nova.logic.commands.ptcommands.PtDeleteCommand;
10+
import seedu.nova.logic.commands.ptcommands.PtDoneCommand;
811
import seedu.nova.logic.commands.ptcommands.PtListCommand;
912
import seedu.nova.logic.parser.exceptions.ParseException;
1013

@@ -29,6 +32,15 @@ public Command parseCommand(String commandWord, String arguments) throws ParseEx
2932
case PtListCommand.COMMAND_WORD:
3033
return new PtListCommandParser().parse(arguments);
3134

35+
case PtAddCommand.COMMAND_WORD:
36+
return new PtAddCommandParser().parse(arguments);
37+
38+
case PtDeleteCommand.COMMAND_WORD:
39+
return new PtDeleteCommandParser().parse(arguments);
40+
41+
case PtDoneCommand.COMMAND_WORD:
42+
return new PtDoneCommandParser().parse(arguments);
43+
3244
default:
3345
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
3446
}

0 commit comments

Comments
 (0)