Skip to content

Commit

Permalink
Implement Adding, Updating, Deleting of Recurrence
Browse files Browse the repository at this point in the history
  • Loading branch information
theapeeeee committed Oct 23, 2016
1 parent 24a64d4 commit d2e259c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/todo/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public AddCommand(String name, String detail, String onDateString, String byDate
TaskDate onDate = new TaskDate(onDateString, TaskDate.TASK_DATE_ON);
TaskDate byDate = new TaskDate(byDateString, TaskDate.TASK_DATE_BY);
if (byDate.getDate() != null && !DateTimeUtil.containsDateField(byDateString)) {

byDate.setDate(LocalDate.of(onDate.getDate().getYear(),
onDate.getDate().getMonth(), onDate.getDate().getDayOfMonth()));
}
System.out.println(freq.toString());
this.toAdd = new Task(
new Name(name),
new Detail(detail),
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/seedu/todo/logic/commands/UpdateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import seedu.todo.model.task.Detail;
import seedu.todo.model.task.Name;
import seedu.todo.model.task.ReadOnlyTask;
import seedu.todo.model.task.Recurrence;
import seedu.todo.model.task.Recurrence.Frequency;
import seedu.todo.model.task.Task;
import seedu.todo.model.task.TaskDate;
import seedu.todo.model.task.UniqueTaskList.TaskNotFoundException;
Expand All @@ -34,14 +36,16 @@ public class UpdateCommand extends Command{
private final String detail;
private final String onDateTime;
private final String byDateTime;
private final String recurrence;

public UpdateCommand(int targetIndex, String name, String onDateTime, String byDateTime, String detail) {
System.out.println("HELLO" + onDateTime);
public UpdateCommand(int targetIndex, String name, String onDateTime,
String byDateTime, String detail, String recurrence) {
this.targetIndex = targetIndex;
this.name = name;
this.detail = detail;
this.onDateTime = onDateTime;
this.byDateTime = byDateTime;
this.recurrence = recurrence;
}


Expand All @@ -63,6 +67,7 @@ public CommandResult execute() {
Detail newDetail;
TaskDate newByDate;
TaskDate newOnDate;
Recurrence newRecurrence;

if (this.detail == null) {
newDetail = taskToUpdate.getDetail();
Expand All @@ -82,8 +87,14 @@ public CommandResult execute() {
newOnDate = this.onDateTime.trim().equals("-") ? new TaskDate("", TaskDate.TASK_DATE_ON) : new TaskDate(this.onDateTime, TaskDate.TASK_DATE_ON);
}

if (this.recurrence == null) {
newRecurrence = taskToUpdate.getRecurrence();
} else {
newRecurrence = this.recurrence.trim().equals("-") ? new Recurrence(Frequency.NONE) : new Recurrence(Frequency.valueOf(this.recurrence.toUpperCase().trim()));
}

Task newTask = new Task(newName, newDetail, taskToUpdate.getCompletion(),
newOnDate, newByDate, taskToUpdate.getRecurrence(), taskToUpdate.getTags());
newOnDate, newByDate, newRecurrence, taskToUpdate.getTags());
model.updateTask(taskToUpdate, newTask);
model.updateFilteredListToShowAll();

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/seedu/todo/logic/parser/ParserFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ public class ParserFormats {
public static final Pattern SEARCH_TASK_ARGS_FORMAT_FT = Pattern
.compile("from (?<fromDateTime>.+) to (?<tillDateTime>.+)", Pattern.CASE_INSENSITIVE);



public static final Pattern UPDATE_TASK_ARGS_FORMAT = Pattern
.compile("(?<name>[^/]*?)? ?((^| )((on|from) "
+ "(?<onDateTime>[^(by|;)]+)?|by (?<byDateTime>[^;]+)))*?"
+ "(?: ?;(?<detail>.+))?$", Pattern.CASE_INSENSITIVE);
.compile("(?<name>[^/]*?)? "
+ "?((^| )((on|from) (?<onDateTime>[^;]+?)?"
+"|by (?<byDateTime>[^;]+?)|"
+"every (?<rec>.+?)))*?"
+"(?: ?;(?<detail>.+))?$", Pattern.CASE_INSENSITIVE);



public static final Pattern RECURRENCE_WEEK_DAY = Pattern
.compile("every (monday|tuesday|wednesday|thursday|friday|saturday|sunday|mon|tue|wed|thurs|fri|sat|sun)");
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/todo/logic/parser/ToDoListParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,16 @@ private Command prepareAdd(String args) {

} else if (p.equals(ParserFormats.ADD_TASK_ARGS_RECUR_FORMAT_FT)) {
return new AddCommand(matcher.group("name"), matcher.group("detail"),
matcher.group("onDateTime"), null, Frequency.valueOf(matcher.group("rec").toUpperCase()));
matcher.group("onDateTime"), matcher.group("byDateTime"),
Frequency.valueOf(matcher.group("rec").toUpperCase().trim()));

} else if (p.equals(ParserFormats.ADD_TASK_ARGS_RECUR_FORMAT_BY)) {
return new AddCommand(matcher.group("name"), matcher.group("detail"), null,
matcher.group("byDateTime"), Frequency.valueOf(matcher.group("rec").toUpperCase()));
matcher.group("byDateTime"), Frequency.valueOf(matcher.group("rec").toUpperCase().trim()));

} else if (p.equals(ParserFormats.ADD_TASK_ARGS_RECUR_FORMAT_ON)) {
return new AddCommand(matcher.group("name"), matcher.group("detail"),
matcher.group("onDateTime"), null, Frequency.valueOf(matcher.group("rec").toUpperCase()));
matcher.group("onDateTime"), null, Frequency.valueOf(matcher.group("rec").toUpperCase().trim()));

} else {
return new AddCommand(matcher.group("name"), matcher.group("detail"), null, null, Frequency.NONE);
Expand Down Expand Up @@ -283,14 +284,13 @@ private Command prepareUpdate(String args) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, UpdateCommand.MESSAGE_USAGE));
}

String name = null, onDate = null, byDate = null, detail = null;
args = args.substring(1).trim();

Matcher matcher;
matcher = ParserFormats.UPDATE_TASK_ARGS_FORMAT.matcher(args.trim());
if (matcher.matches()) {
return new UpdateCommand(index.get(), matcher.group("name").trim(), matcher.group("onDateTime"),
matcher.group("byDateTime"), matcher.group("detail"));
matcher.group("byDateTime"), matcher.group("detail"), matcher.group("rec"));
} else {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, UpdateCommand.MESSAGE_USAGE));
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/todo/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public synchronized void updateTask(ReadOnlyTask oldTask, ReadOnlyTask newTask)
toDoList.getTasks().get(index).setDetail(newTask.getDetail());
toDoList.getTasks().get(index).setOnDate(newTask.getOnDate());
toDoList.getTasks().get(index).setByDate(newTask.getByDate());
toDoList.getTasks().get(index).setRecurrence(newTask.getRecurrence());
toDoList.syncTagsWithMasterList(toDoList.getTasks().get(index));
indicateToDoListChanged();
}
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/seedu/todo/model/ToDoList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import seedu.todo.model.task.Task;
import seedu.todo.model.task.UniqueTaskList;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -53,6 +54,25 @@ public ObservableList<Task> getTasks() {
return tasksHistory.peek().getInternalList();
}


public void resetData(Collection<? extends ReadOnlyTask> newTasks, Collection<Tag> newTags) {
setTasks(newTasks.stream().map(Task::new).collect(Collectors.toList()));
setTags(newTags);

for (Task t : this.getTasks()) {
if (t.isRecurring()
&& (t.getOnDate().getDate().isBefore(LocalDate.now())
|| t.getByDate().getDate().isBefore(LocalDate.now()))) {
t.getRecurrence().updateTaskDate(t);
}
}
}

public void resetData(ReadOnlyToDoList newData) {
resetData(newData.getTaskList(), newData.getTagList());
}


public void setTasks(List<Task> tasks) {
if (this.tasksHistory.isEmpty()) {
UniqueTaskList topList = this.createNewTaskList(tasks);
Expand All @@ -73,14 +93,6 @@ public void setTags(Collection<Tag> tags) {
this.tagsHistory.push(newList);
}

public void resetData(Collection<? extends ReadOnlyTask> newTasks, Collection<Tag> newTags) {
setTasks(newTasks.stream().map(Task::new).collect(Collectors.toList()));
setTags(newTags);
}

public void resetData(ReadOnlyToDoList newData) {
resetData(newData.getTaskList(), newData.getTagList());
}

//// task-level operations

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/seedu/todo/model/task/ReadOnlyTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ default boolean isSameStateAs(ReadOnlyTask other) {
*/
default String getAsText() {
final StringBuilder builder = new StringBuilder();
builder.append(getName())
.append(" Details: ")
.append(getDetail())
.append(" From: ")
.append(getOnDate())
.append(" Till: ")
.append(getByDate())
.append(" Tags: ");
builder.append(getName() + "\n")
.append("Details: ")
.append(getDetail() + "\n")
.append("From: ")
.append(getOnDate() + "\n")
.append("Till: ")
.append(getByDate() + "\n")
.append("Tags: ");
//getTags().forEach(builder::append);
return builder.toString();
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/todo/model/task/Recurrence.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public boolean isRecurring() {
public String toString() {
switch(this.freq) {
case YEAR :
return "Year";
return "YEAR";
case MONTH :
return "Month";
return "MONTH";
case WEEK:
return "Week";
return "WEEK";
case DAY :
return "Day";
return "DAY";
default :
return "NONE";
}
}

public void UpdateTaskDate(Task task){
public void updateTaskDate(Task task){
switch(this.freq) {
case YEAR :
if (task.getOnDate().getDate() != null) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/view/TaskListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<?import javafx.scene.shape.Ellipse?>
<?import javafx.scene.text.Font?>

<HBox fx:id="cardPane" minHeight="40.0" prefHeight="50.0" prefWidth="630.0" style="-fx-background-color: #FFFFFF;" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<HBox fx:id="cardPane" minHeight="40.0" prefHeight="50.0" prefWidth="630.0" style="-fx-background-color: #FFFFFF;" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane minHeight="50.0" prefHeight="50.0" translateY="5.0" HBox.hgrow="ALWAYS">

Expand Down Expand Up @@ -58,8 +58,8 @@
<Insets bottom="2.0" left="-20.0" right="2.0" top="2.0" />
</padding>
<children>
<Label fx:id="onDate" contentDisplay="RIGHT" styleClass="cell_small_label" text="\$onDate" translateY="-30.0" />
<Label fx:id="byDate" styleClass="cell_small_label" text="\$byDate" translateY="-30.0" />
<Label fx:id="onDate" contentDisplay="RIGHT" prefHeight="17.0" prefWidth="168.0" styleClass="cell_small_label" text="\$onDate" translateY="-30.0" />
<Label fx:id="byDate" prefHeight="17.0" prefWidth="174.0" styleClass="cell_small_label" text="\$byDate" translateY="-30.0" />
</children>
</VBox>
</children>
Expand Down

0 comments on commit d2e259c

Please sign in to comment.