Skip to content

Commit 47dc0f8

Browse files
authored
Merge pull request #34 from CS2103AUG2016-W13-C4/integration
Integration
2 parents c58ff51 + 03c0a8b commit 47dc0f8

File tree

17 files changed

+474
-57
lines changed

17 files changed

+474
-57
lines changed

src/main/java/seedu/address/commons/events/model/TaskManagerChangedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public TaskManagerChangedEvent(ReadOnlyTaskManager data){
1414

1515
@Override
1616
public String toString() {
17-
return "number of floating tasks " + data.getTaskList().size();
17+
return "number of tasks " + data.getTaskList().size();
1818
}
1919
}

src/main/java/seedu/address/logic/commands/AddCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public AddCommand(String taskName) {
4646
public AddCommand(String taskNameString, String startDateString, String endDateString, String recurrenceRateString,
4747
String timePeriodString, String priorityString) throws IllegalValueException {
4848
com.joestelmach.natty.Parser dateParser = new com.joestelmach.natty.Parser();
49-
Name taskName = new Name(taskNameString);
49+
Name taskName = new Name(taskNameString);
5050
Date startDate = null;
5151
Date endDate = null;
5252
RecurrenceRate recurrenceRate;
@@ -63,9 +63,9 @@ public AddCommand(String taskNameString, String startDateString, String endDateS
6363
}
6464

6565
if (recurrenceRateString == null && timePeriodString == null) {
66-
recurrenceRate = new RecurrenceRate();
66+
recurrenceRate = null;
6767
} else if (recurrenceRateString == null) {
68-
recurrenceRate = new RecurrenceRate(timePeriodString);
68+
recurrenceRate = new RecurrenceRate("1", timePeriodString);
6969
} else {
7070
recurrenceRate = new RecurrenceRate(recurrenceRateString, timePeriodString);
7171
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package seedu.address.logic.commands;
2+
3+
import java.util.Date;
4+
5+
import seedu.address.commons.core.Messages;
6+
import seedu.address.commons.core.UnmodifiableObservableList;
7+
import seedu.address.commons.exceptions.IllegalValueException;
8+
import seedu.address.logic.parser.DateParser;
9+
import seedu.address.model.item.Task;
10+
import seedu.address.model.Model;
11+
import seedu.address.model.item.Name;
12+
import seedu.address.model.item.Priority;
13+
import seedu.address.model.item.ReadOnlyTask;
14+
import seedu.address.model.item.RecurrenceRate;
15+
import seedu.address.model.item.UniqueTaskList.DuplicateTaskException;
16+
import seedu.address.model.item.UniqueTaskList.TaskNotFoundException;
17+
18+
public class EditCommand extends Command{
19+
20+
public static final String COMMAND_WORD = "edit";
21+
22+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edit an item in the To-Do List. ";
23+
24+
public static final String TOOL_TIP = "edit INDEX [NAME], [from/at START_DATE START_TIME][to/by END_DATE END_TIME][repeat every RECURRING_INTERVAL][-PRIORITY]";
25+
26+
public static final String MESSAGE_DUPLICATE_FLOATING_TASK = "This task already exists in the task manager";
27+
28+
public static final String MESSAGE_SUCCESS = "Item edited: %1$s";
29+
30+
public final int targetIndex;
31+
32+
private Task toEdit;
33+
34+
Name taskName;
35+
Date startDate ;
36+
Date endDate;
37+
RecurrenceRate recurrenceRate;
38+
Priority priority;
39+
40+
public EditCommand(int targetIndex,String taskNameString, String startDateString, String endDateString,
41+
String recurrenceRateString, String timePeriodString, String priorityString) throws IllegalValueException {
42+
43+
this.targetIndex = targetIndex;
44+
taskName = null;
45+
startDate = null;
46+
endDate = null;
47+
priority = null;
48+
49+
if ( taskNameString!=null && !taskNameString.trim().equals("")) {
50+
taskName = new Name(taskNameString);
51+
} else {
52+
System.out.println("TaskName is " + taskNameString);
53+
}
54+
/*
55+
if(taskName == null){
56+
System.out.println("TaskName = null");
57+
}
58+
*/
59+
if (startDateString != null) {
60+
DateParser dp = new DateParser(startDateString);
61+
startDate = dp.parseDate();
62+
}
63+
64+
if (endDateString != null) {
65+
DateParser dp = new DateParser(endDateString);
66+
endDate = dp.parseDate();
67+
}
68+
69+
if (recurrenceRateString == null && timePeriodString == null) {
70+
recurrenceRate = null;
71+
} else if (recurrenceRateString == null) {
72+
recurrenceRate = new RecurrenceRate("1", timePeriodString);
73+
} else {
74+
recurrenceRate = new RecurrenceRate(recurrenceRateString, timePeriodString);
75+
}
76+
77+
//TODO: Throw IllegalValueException for default cases?
78+
if(priorityString != null){
79+
switch (priorityString) {
80+
case ("low"): case ("l"): priority = Priority.LOW; break;
81+
case ("high"): case ("h"): priority = Priority.HIGH; break;
82+
case ("medium"): case ("m"): case ("med"): priority = Priority.MEDIUM; break;
83+
}
84+
}
85+
86+
this.toEdit = new Task(taskName, startDate, endDate, recurrenceRate, priority);
87+
}
88+
89+
@Override
90+
public CommandResult execute() {
91+
assert model != null;
92+
UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredFloatingTaskList();
93+
94+
if (lastShownList.size() < targetIndex) {
95+
indicateAttemptToExecuteIncorrectCommand();
96+
return new CommandResult(Messages.MESSAGE_INVALID_ITEM_DISPLAYED_INDEX);
97+
}
98+
99+
ReadOnlyTask personToEdit = lastShownList.get(targetIndex - 1);
100+
101+
if (taskName != null) {
102+
try {
103+
model.editName(personToEdit, taskName);
104+
} catch (DuplicateTaskException e) {
105+
// TODO Auto-generated catch block
106+
e.printStackTrace();
107+
}
108+
}
109+
110+
if (startDate != null) {
111+
model.editStartDate(personToEdit, startDate);
112+
}
113+
114+
if (endDate != null) {
115+
model.editEndDate(personToEdit, endDate);
116+
}
117+
118+
if (priority != null){
119+
model.editPriority(personToEdit, priority);
120+
}
121+
122+
if (recurrenceRate != null) {
123+
model.editRecurrence(personToEdit, recurrenceRate);
124+
}
125+
126+
return new CommandResult(String.format(MESSAGE_SUCCESS, toEdit));
127+
128+
}
129+
130+
}

src/main/java/seedu/address/logic/parser/Parser.java

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.regex.Pattern;
1010

1111
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
12+
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
1213

1314
/**
1415
* Parses user input.
@@ -39,6 +40,21 @@ public class Parser {
3940
+")?"
4041
+"(?: repeat every (?<recurrenceRate>.*?))?"
4142
+"(?: -(?<priority>.*?))?)");
43+
44+
private static final Pattern EDIT_ARGS_FORMAT = Pattern.compile("(?i:"
45+
+"(?<taskName>.*?)?"
46+
+"(?:"
47+
+"(?:, by (?<endDateFormatOne>.*?))"
48+
+"|(?:, from (?<startDateFormatOne>.*?))"
49+
+"|(?:, at (?<startDateFormatTwo>.*?))"
50+
+"|(?:, start (?<startDateFormatThree>.*?))"
51+
+")?"
52+
+"(?:"
53+
+"(?:, to (?<endDateFormatTwo>.*?))?"
54+
+"(?:, end (?<endDateFormatThree>.*?))?"
55+
+")?"
56+
+"(?:, repeat every (?<recurrenceRate>.*?))?"
57+
+"(?:-(?<priority>.*?))?)");
4258

4359
private static final Pattern RECURRENCE_RATE_ARGS_FORMAT = Pattern.compile("(?<rate>\\d+)?(?<timePeriod>.*?)");
4460

@@ -84,12 +100,15 @@ public Command parseCommand(String userInput) {
84100
case HelpCommand.COMMAND_WORD:
85101
return new HelpCommand();
86102

103+
case EditCommand.COMMAND_WORD:
104+
return prepareEdit(arguments);
105+
87106
default:
88107
return prepareAdd(commandWord + arguments);
89108
}
90109
}
91110

92-
/**
111+
/**
93112
* Parses arguments in the context of the add person command.
94113
*
95114
* @param args full command args string
@@ -179,6 +198,91 @@ private static Set<String> getTagsFromArgs(String tagArguments) throws IllegalVa
179198
final Collection<String> tagStrings = Arrays.asList(tagArguments.replaceFirst(" t/", "").split(" t/"));
180199
return new HashSet<>(tagStrings);
181200
}
201+
202+
/**
203+
* Parses arguments in the context of the edit task command.
204+
*
205+
* @param args full command args string
206+
* @return the prepared command
207+
*/
208+
private Command prepareEdit(String args) {
209+
210+
//TODO parse the index and args
211+
int index = 0;
212+
213+
args = args.trim();
214+
System.out.println(args);
215+
216+
String[] parts = args.split(" ");
217+
String indexNum = parts[0];
218+
219+
index = Integer.parseInt(indexNum);
220+
221+
args = args.substring(2);
222+
223+
//TODO
224+
//Update parser to make NAME field optional.
225+
final Matcher matcher = EDIT_ARGS_FORMAT.matcher(args.trim());
226+
227+
String taskName = null;
228+
String startDate = null;
229+
String endDate = null;
230+
String recurrenceRate = null;
231+
String timePeriod = null;
232+
String priority = null;
233+
234+
if (!matcher.matches()) {
235+
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
236+
}
237+
238+
try {
239+
240+
if(matcher.group("taskName") != null){
241+
taskName = matcher.group("taskName");
242+
}
243+
244+
if (matcher.group("startDateFormatOne") != null) {
245+
startDate = matcher.group("startDateFormatOne");
246+
} else if (matcher.group("startDateFormatTwo") != null) {
247+
startDate = matcher.group("startDateFormatTwo");
248+
} else if (matcher.group("startDateFormatThree") != null) {
249+
startDate = matcher.group("startDateFormatThree");
250+
}
251+
252+
if (matcher.group("endDateFormatOne") != null) {
253+
endDate = matcher.group("endDateFormatOne");
254+
} else if (matcher.group("endDateFormatTwo") != null) {
255+
endDate = matcher.group("endDateFormatTwo");
256+
} else if (matcher.group("endDateFormatThree") != null) {
257+
endDate = matcher.group("endDateFormatThree");
258+
}
259+
260+
if (matcher.group("recurrenceRate") != null) {
261+
String recurrenceString = matcher.group("recurrenceRate");
262+
final Matcher recurrenceMatcher = RECURRENCE_RATE_ARGS_FORMAT.matcher(recurrenceString);
263+
264+
//TODO: Won't reach here actually
265+
if (!recurrenceMatcher.matches()) {
266+
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
267+
}
268+
269+
if (recurrenceMatcher.group("rate") != null) {
270+
recurrenceRate = recurrenceMatcher.group("rate");
271+
}
272+
273+
timePeriod = recurrenceMatcher.group("timePeriod");
274+
}
275+
276+
if (matcher.group("priority") != null) {
277+
priority = matcher.group("priority");
278+
}
279+
280+
System.out.println(index + " " + taskName + " " + startDate + " " + endDate + " " + recurrenceRate + " " + timePeriod + " " + priority );
281+
return new EditCommand(index, taskName, startDate, endDate, recurrenceRate, timePeriod, priority);
282+
} catch (IllegalValueException ive) {
283+
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
284+
}
285+
}
182286

183287
/**
184288
* Parses arguments in the context of the delete person command.
@@ -306,6 +410,9 @@ private void updateMatchedCommands(List<String> toolTips, final String commandWo
306410
if (StringUtil.isSubstring(HelpCommand.COMMAND_WORD, commandWord)){
307411
toolTips.add(HelpCommand.TOOL_TIP);
308412
}
413+
if (StringUtil.isSubstring(EditCommand.COMMAND_WORD, commandWord)){
414+
toolTips.add(EditCommand.TOOL_TIP);
415+
}
309416
}
310417

311418
}

src/main/java/seedu/address/model/Model.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
import seedu.address.commons.core.UnmodifiableObservableList;
44
import seedu.address.model.item.Task;
5+
import seedu.address.model.item.Name;
6+
import seedu.address.model.item.Priority;
57
import seedu.address.model.item.ReadOnlyTask;
8+
import seedu.address.model.item.RecurrenceRate;
69
import seedu.address.model.item.UniqueTaskList;
10+
import seedu.address.model.item.UniqueTaskList.DuplicateTaskException;
711

12+
import java.util.Date;
813
import java.util.Set;
914

1015
/**
@@ -32,6 +37,22 @@ public interface Model {
3237
/** Updates the filter of the filtered floating task list to filter by the given keywords*/
3338
void updateFilteredFloatingTaskList(Set<String> keywords);
3439

40+
/** Edits the name of the given floating task. */
41+
void editName(ReadOnlyTask personToEdit, Name taskName) throws DuplicateTaskException;
42+
43+
/** Edits the start date of the given floating task. */
44+
void editStartDate(ReadOnlyTask personToEdit, Date startDate);
45+
46+
/** Edits the end date of the given floating task. */
47+
void editEndDate(ReadOnlyTask personToEdit, Date endDate);
48+
49+
/** Edits the priority of the given floating task. */
50+
void editPriority(ReadOnlyTask personToEdit, Priority priority);
51+
52+
/** Edits the recurrence of the given floating task. */
53+
void editRecurrence(ReadOnlyTask personToEdit, RecurrenceRate recurrenceRate);
54+
55+
3556

3657

3758
}

0 commit comments

Comments
 (0)