From 60f05e55947d43b4ea286f3253621144934ff782 Mon Sep 17 00:00:00 2001 From: louietyj Date: Sun, 6 Nov 2016 02:15:34 +0800 Subject: [PATCH 1/4] filterEvents by name --- .../todo/controllers/concerns/CalendarItemFilter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java b/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java index 7e5ef4e0ea41..f3aa6d4e1635 100644 --- a/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java +++ b/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java @@ -8,6 +8,7 @@ import java.util.function.Predicate; import seedu.todo.commons.exceptions.InvalidNaturalDateException; +import seedu.todo.models.Event; import seedu.todo.models.Task; /** @@ -90,5 +91,15 @@ public static List filterTasks(Map parsedResult) throws return Task.where(taskPredicates); } + + public static List filterEvents(Map parsedResult) throws InvalidNaturalDateException { + List> eventPredicates = new ArrayList>(); + + // Filter by name + if (parsedResult.get("name") != null) { + eventPredicates.add(Event.predByName(parsedResult.get("name")[1])); + } + return null; + } } From 04b4db9b0afbb54d2dbb7d104fe4dfe6b5f056e7 Mon Sep 17 00:00:00 2001 From: louietyj Date: Sun, 6 Nov 2016 02:15:47 +0800 Subject: [PATCH 2/4] filterEvents by eventStatus --- .../todo/controllers/concerns/CalendarItemFilter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java b/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java index f3aa6d4e1635..f1e75d269692 100644 --- a/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java +++ b/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java @@ -99,6 +99,17 @@ public static List filterEvents(Map parsedResult) throw if (parsedResult.get("name") != null) { eventPredicates.add(Event.predByName(parsedResult.get("name")[1])); } + + // Filter by eventStatus + if (parsedResult.get("eventStatus") != null && parsedResult.get("eventStatus")[1] != null) { + String eventStatus = parsedResult.get("eventStatus")[1]; + LocalDateTime now = LocalDateTime.now(); + if (eventStatus.equals("over") || eventStatus.equals("past")) { + eventPredicates.add(Event.predEndBefore(now)); + } else if (eventStatus.equals("future")) { + eventPredicates.add(Event.predStartBefore(now)); + } + } return null; } From c42adf3d335767f24f436229bfca03e4240f41b0 Mon Sep 17 00:00:00 2001 From: louietyj Date: Sun, 6 Nov 2016 02:15:57 +0800 Subject: [PATCH 3/4] filterEvents by time --- .../controllers/concerns/CalendarItemFilter.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java b/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java index f1e75d269692..514819bf3c20 100644 --- a/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java +++ b/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java @@ -110,7 +110,21 @@ public static List filterEvents(Map parsedResult) throw eventPredicates.add(Event.predStartBefore(now)); } } - return null; + + // Filter by time + String[] datePair = DateParser.extractDatePair(parsedResult); + String timeStartNatural = datePair[0]; + String timeEndNatural = datePair[1]; + if (timeStartNatural != null) { + LocalDateTime timeStart = DateParser.parseNatural(timeStartNatural); + eventPredicates.add(Event.predStartAfter(timeStart)); + } + if (timeEndNatural != null) { + LocalDateTime timeEnd = DateParser.parseNatural(timeEndNatural); + eventPredicates.add(Event.predEndBefore(timeEnd)); + } + + return Event.where(eventPredicates); } } From 6e708d5245446fe8a92bdf3651903b47d45636f7 Mon Sep 17 00:00:00 2001 From: louietyj Date: Sun, 6 Nov 2016 02:19:07 +0800 Subject: [PATCH 4/4] Filter by tags --- .../todo/controllers/concerns/CalendarItemFilter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java b/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java index 514819bf3c20..04f2031a1884 100644 --- a/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java +++ b/src/main/java/seedu/todo/controllers/concerns/CalendarItemFilter.java @@ -34,6 +34,7 @@ public static Map getFilterTokenDefinitions() { tokenDefinitions.put("eventStatus", new String[] { "over" , "past", "future" }); tokenDefinitions.put("timeFrom", new String[] { "from", "after" }); tokenDefinitions.put("timeTo", new String[] { "to", "before", "until", "by" }); + tokenDefinitions.put("tag", new String[] { "tag" }); return tokenDefinitions; } @@ -89,6 +90,11 @@ public static List filterTasks(Map parsedResult) throws taskPredicates.add(Task.predBeforeDueDate(timeEnd)); } + // Filter by tag + if (parsedResult.get("tag") != null && parsedResult.get("tag")[1] != null) { + taskPredicates.add(Task.predTag(parsedResult.get("tag")[1])); + } + return Task.where(taskPredicates); } @@ -124,6 +130,11 @@ public static List filterEvents(Map parsedResult) throw eventPredicates.add(Event.predEndBefore(timeEnd)); } + // Filter by tag + if (parsedResult.get("tag") != null && parsedResult.get("tag")[1] != null) { + eventPredicates.add(Event.predTag(parsedResult.get("tag")[1])); + } + return Event.where(eventPredicates); }