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

Enhance filter panel #67

Merged
merged 6 commits into from
Nov 6, 2016
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
7 changes: 0 additions & 7 deletions .checkstyle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public FilterPanelChangedEvent(Set<Types> types, Map<Types, String> qualificatio
this.tags = tags;
}

@Override
public String toString() {
return this.getClass().getSimpleName();
}

public Set<Types> getTypes() {
return types;
}
Expand All @@ -37,4 +32,10 @@ public Map<Types, String> getQualifications() {
public Set<String> getTags() {
return tags;
}

@Override
public String toString() {
return this.getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package seedu.address.commons.events.ui;

import java.util.Map;
import java.util.Set;

import seedu.address.commons.events.BaseEvent;
import seedu.address.commons.util.Types;

//@@author A0146123R
/**
* Represents a change in the filtered tasks in model that requires the Filter
* Panel to update correspondingly
*/
public class UpdateFilterPanelEvent extends BaseEvent {

private final Set<Types> types;
private final Map<Types, String> qualifications;
private final Set<String> tags;

public UpdateFilterPanelEvent(Set<Types> types, Map<Types, String> qualifications, Set<String> tags) {
this.types = types;
this.qualifications = qualifications;
this.tags = tags;
}

public Set<Types> getTypes() {
return types;
}

public Map<Types, String> getQualifications() {
return qualifications;
}

public Set<String> getTags() {
return tags;
}

@Override
public String toString() {
return this.getClass().getSimpleName();
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/util/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//@@author A0146123R
/**
* A container for Types and Qualifications variables
* A container for types and attributes variables
*/
public enum Types {
EVENTS, TASKS, DONE, UNDONE, START_DATE, END_DATE, DEADLINE, RECURRING, TAG, PRIORITY_LEVEL, INVALID
Expand Down
113 changes: 84 additions & 29 deletions src/main/java/seedu/address/logic/commands/FilterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

//@@author A0146123R
/**
* Filter the filtered task list to filter by the given attribute.
* Filter the task list by the given attributes.
*/
public class FilterCommand extends Command {

public static final String COMMAND_WORD = "filter";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Filter list for specified attributes "
+ "and displays them as a list with index numbers.\n"
+ "Parameters: [s/START_DATE] [e/END_DATE] [d/DEADLINE] [r/RECURRING] [p/PRIORITY] [t/TAG]...\n" + "Example: "
+ COMMAND_WORD + " s/23.10.2016 r/daily";
+ "Parameters: [s/START_DATE] [e/END_DATE] [d/DEADLINE] [r/RECURRING] [p/PRIORITY] [t/TAG]...\n"
+ "Example: " + COMMAND_WORD + " s/today r/daily";

private final Optional<String> deadline;
private final Optional<String> startDate;
Expand All @@ -32,6 +32,9 @@ public class FilterCommand extends Command {
private final Set<String> tags;
private final Optional<String> priority;

/**
* Convenience constructor using raw values.
*/
public FilterCommand(Optional<String> deadline, Optional<String> startDate, Optional<String> endDate,
Optional<String> recurring, Set<String> tags, Optional<String> priority) {
this.deadline = deadline;
Expand All @@ -46,31 +49,11 @@ public FilterCommand(Optional<String> deadline, Optional<String> startDate, Opti
public CommandResult execute() {
Map<Types, String> filterQualifications = new HashMap<>();
try {
if (deadline.isPresent()) {
String deadlineString = Deadline.getValidDate(deadline.get());
filterQualifications.put(Types.DEADLINE, deadlineString);
}
if (startDate.isPresent()) {
String startDateString = EventDate.getValidDate(startDate.get());
filterQualifications.put(Types.START_DATE, startDateString);
}
if (endDate.isPresent()) {
String endDateString = EventDate.getValidDate(endDate.get());
filterQualifications.put(Types.END_DATE, endDateString);
}
if (recurring.isPresent()) {
if (Recurring.isValidFrequency(recurring.get())) {
filterQualifications.put(Types.RECURRING, recurring.get());
} else {
throw new IllegalValueException(Recurring.MESSAGE_RECURRING_CONSTRAINTS);
}
}
if (priority.isPresent()) {
if (Priority.isValidPriorityLevel(Integer.parseInt(priority.get())))
filterQualifications.put(Types.PRIORITY_LEVEL, priority.get());
else
throw new IllegalValueException(Priority.MESSAGE_INVALID_PRIORITY_LEVEL);
}
prepareDeadline(filterQualifications);
prepareStartDate(filterQualifications);
prepareEndDate(filterQualifications);
prepareRecurring(filterQualifications);
preparePriority(filterQualifications);
} catch (IllegalValueException e) {
indicateAttemptToExecuteIncorrectCommand();
return new CommandResult(e.getMessage());
Expand All @@ -79,4 +62,76 @@ public CommandResult execute() {
return new CommandResult(getMessageForTaskListShownSummary(model.getFilteredTaskList().size()));
}

}
/**
* Parse the given deadline qualification
*
* @throws IllegalValueException
* if it is invalid
*/
private void prepareDeadline(Map<Types, String> qualifications) throws IllegalValueException {
if (deadline.isPresent()) {
String deadlineString = Deadline.getValidDate(deadline.get());
qualifications.put(Types.DEADLINE, deadlineString);
}
}

/**
* Parse the given start date qualification
*
* @throws IllegalValueException
* if it is invalid
*/
private void prepareStartDate(Map<Types, String> qualifications) throws IllegalValueException {
if (startDate.isPresent()) {
String startDateString = EventDate.getValidDate(startDate.get());
qualifications.put(Types.START_DATE, startDateString);
}
}

/**
* Parse the given end date qualification
*
* @throws IllegalValueException
* if it is invalid
*/
private void prepareEndDate(Map<Types, String> qualifications) throws IllegalValueException {
if (endDate.isPresent()) {
String endDateString = EventDate.getValidDate(endDate.get());
qualifications.put(Types.END_DATE, endDateString);
}
}

/**
* Parse the given priority qualification
*
* @throws IllegalValueException
* if it is invalid
*/
private void prepareRecurring(Map<Types, String> qualifications) throws IllegalValueException {
if (recurring.isPresent()) {
if (Recurring.isValidFrequency(recurring.get())) {
qualifications.put(Types.RECURRING, recurring.get());
} else {
throw new IllegalValueException(Recurring.MESSAGE_RECURRING_CONSTRAINTS);
}
}
}

// @@author A0138717X
/**
* Parse the given priority qualification
*
* @throws IllegalValueException
* if it is invalid
*/
private void preparePriority(Map<Types, String> qualifications) throws IllegalValueException {
if (priority.isPresent()) {
if (Priority.isValidPriorityLevel(Integer.parseInt(priority.get()))) {
qualifications.put(Types.PRIORITY_LEVEL, priority.get());
} else {
throw new IllegalValueException(Priority.MESSAGE_INVALID_PRIORITY_LEVEL);
}
}
}

}
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class FindCommand extends Command {
private final Set<Set<String>> keywordsGroups;
private final boolean isExactSearch;

/**
* Convenience constructor using raw values.
*/
public FindCommand(Set<Set<String>> keywordsGroups, boolean isExactSearch) {
this.keywordsGroups = keywordsGroups;
this.isExactSearch = isExactSearch;
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ public interface Model {
*/
void updateFilteredTaskList(Types type);

/**
* Updates the filter of the filtered task list to filter by the given
* keywords of the given type
*/
void updateFilteredTaskList(String keyword, Types type);

/**
* Updates the filter of the filtered task list to filter by multiple
* qualifications
Expand Down
68 changes: 37 additions & 31 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
import seedu.address.model.task.UniqueTaskList.TaskNotFoundException;
import seedu.address.commons.events.model.TaskManagerChangedEvent;
import seedu.address.commons.events.ui.FilterPanelChangedEvent;
import seedu.address.commons.events.ui.UpdateFilterPanelEvent;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.commons.exceptions.StateLimitException;
import seedu.address.commons.core.ComponentManager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -168,10 +170,13 @@ public UnmodifiableObservableList<ReadOnlyTask> getFilteredTaskList() {
return new UnmodifiableObservableList<>(filteredTasks);
}

//@@author A016123R
@Override
public void updateFilteredListToShowAll() {
filteredTasks.setPredicate(null);
raise(new UpdateFilterPanelEvent(new HashSet<Types>(), new HashMap<Types, String>(), new HashSet<String>()));
}
//@@author

@Override
public void updateFilteredTaskList(Set<String> keywords){
Expand All @@ -182,6 +187,9 @@ public void updateFilteredTaskList(Set<String> keywords){
@Override
public void updateFilteredTaskList(Types type) {
updateFilteredTaskList(getPredicateForType(type));
Set<Types> types = new HashSet<>();
types.add(type);
raise(new UpdateFilterPanelEvent(types, new HashMap<Types, String>(), new HashSet<String>()));
}

private Expression getPredicateForType(Types type) {
Expand All @@ -199,48 +207,44 @@ private Expression getPredicateForType(Types type) {
}

//@@author A0146123R
@Override
public void updateFilteredTaskList(String keyword, Types type) {
updateFilteredTaskList(getPredicateForKeywordType(type, keyword));
}

private Expression getPredicateForKeywordType(Types type, String keyword) {
switch (type) {
case START_DATE:
case DEADLINE:
case END_DATE:
return new PredicateExpression(new DateQualifier(keyword, type));
case RECURRING:
return new PredicateExpression(new RecurringQualifier(keyword));
case PRIORITY_LEVEL:
return new PredicateExpression(new PriorityQualifier(Integer.parseInt(keyword)));
default:
return null;
}
}

@Override
public void updateFilteredTaskList(Map<Types, String> qualifications, Set<String> tags) {
updateFilteredTaskListAndOperation(getPredicateForMultipleQualifications(qualifications, tags));
raise(new UpdateFilterPanelEvent(new HashSet<Types>(), qualifications, tags));
}

private ArrayList<Expression> getPredicateForMultipleQualifications(Map<Types, String> qualifications,
Set<String> tags) {
ArrayList<Expression> predicate = new ArrayList<>();
qualifications.forEach((type, keyword) -> predicate.add(getPredicateForKeywordType(type, keyword)));
qualifications.forEach((attribute, keyword) -> predicate.add(getPredicateForKeywordType(attribute, keyword)));
if (!tags.isEmpty()) {
predicate.add(getPredicateForTags(tags));
}
return predicate;
}

private Expression getPredicateForKeywordType(Types attribute, String keyword) {
switch (attribute) {
case START_DATE:
case DEADLINE:
case END_DATE:
return new PredicateExpression(new DateQualifier(keyword, attribute));
case RECURRING:
return new PredicateExpression(new RecurringQualifier(keyword));
case PRIORITY_LEVEL:
return new PredicateExpression(new PriorityQualifier(Integer.parseInt(keyword)));
default:
return null;
}
}

@Override
public void updateFilteredTaskList(Set<Types> types, Map<Types, String> qualifications, Set<String> tags) {
ArrayList<Expression> predicate = getPredicateForMultipleQualifications(qualifications, tags);
types.forEach(type -> predicate.add(getPredicateForType(type)));
updateFilteredTaskListAndOperation(predicate);
}

@Override
public void updateFilteredTaskListWithKeywords(Set<Set<String>> keywordsGroups) {
ArrayList<Expression> predicate = new ArrayList<>();
Expand Down Expand Up @@ -284,8 +288,8 @@ private void updateFilteredTaskListAndOperation(ArrayList<Expression> expression

@Subscribe
@Override
public void handleFilterPanelChangedEvent(FilterPanelChangedEvent abce) {
updateFilteredTaskList(abce.getTypes(), abce.getQualifications(), abce.getTags());
public void handleFilterPanelChangedEvent(FilterPanelChangedEvent event) {
updateFilteredTaskList(event.getTypes(), event.getQualifications(), event.getTags());
}
//@@author

Expand Down Expand Up @@ -441,19 +445,21 @@ private class DateQualifier implements Qualifier {
@Override
public boolean run(ReadOnlyTask task) {
if (task.isEvent() == isEvent) {
String date;
switch (dateType) {
case START_DATE:
return isDay ? getDay(((EventDate) task.getDate()).getStartDate()).equals(dateValue)
: ((EventDate) task.getDate()).getStartDate().equals(dateValue);
date = ((EventDate) task.getDate()).getStartDate();
break;
case END_DATE:
return isDay ? getDay(((EventDate) task.getDate()).getEndDate()).equals(dateValue)
: ((EventDate) task.getDate()).getEndDate().equals(dateValue);
date = ((EventDate) task.getDate()).getEndDate();
break;
case DEADLINE:
return isDay ? getDay(task.getDate().getValue()).equals(dateValue)
: task.getDate().getValue().equals(dateValue);
default:
date = task.getDate().getValue();
break;
default:
return false;
}
return isDay ? dateValue.equals(getDay(date)) : dateValue.equals(date);
}
return false;
}
Expand Down
Loading