Skip to content

Commit

Permalink
Merge pull request #88 from CS2103AUG2016-W10-C1/feat/track/separate-…
Browse files Browse the repository at this point in the history
…panels

Improve tracking of deadlines
  • Loading branch information
alexfjw committed Oct 25, 2016
2 parents 34d4f62 + 61d3d5b commit 0c24c9e
Show file tree
Hide file tree
Showing 47 changed files with 1,092 additions and 402 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package seedu.taskman.commons.events.ui;

import seedu.taskman.commons.events.BaseEvent;
import seedu.taskman.model.event.Activity;

/**
* Indicates a request to jump to the list of tasks
*/
public class JumpToListRequestEvent extends BaseEvent {

public final int targetIndex;
public final Activity.PanelType panelType;

public JumpToListRequestEvent(int targetIndex) {
public JumpToListRequestEvent(Activity.PanelType panelType, int targetIndex) {
this.panelType = panelType;
this.targetIndex = targetIndex;
}

Expand Down
20 changes: 18 additions & 2 deletions src/main/java/seedu/taskman/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@ public interface Logic {
*/
CommandResult execute(String commandText);

//TODO Remove
/**
* Returns the filtered list of tasks
* Returns the filtered list of activities
*/
ObservableList<Activity> getFilteredActivityList();
//ObservableList<Activity> getFilteredActivityList();

/**
* Returns the filtered list of activities with schedules
*/
ObservableList<Activity> getSortedScheduleList();

/**
* Returns the filtered list of tasks with deadlines
*/
ObservableList<Activity> getSortedDeadlineList();

/**
* Returns the filtered list of tasks without deadlines
*/
ObservableList<Activity> getSortedFloatingList();

}
18 changes: 18 additions & 0 deletions src/main/java/seedu/taskman/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,26 @@ public CommandResult execute(String commandText) {
return result;
}

//TODO Remove
/*
@Override
public ObservableList<Activity> getFilteredActivityList() {
return model.getFilteredActivityList();
}
*/

@Override
public ObservableList<Activity> getSortedScheduleList() {
return model.getSortedScheduleList();
}

@Override
public ObservableList<Activity> getSortedDeadlineList() {
return model.getSortedDeadlineList();
}

@Override
public ObservableList<Activity> getSortedFloatingList() {
return model.getSortedFloatingList();
}
}
36 changes: 31 additions & 5 deletions src/main/java/seedu/taskman/logic/commands/Command.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package seedu.taskman.logic.commands;

import javafx.util.Pair;
import seedu.taskman.commons.core.EventsCenter;
import seedu.taskman.commons.core.Messages;
import seedu.taskman.commons.events.ui.IncorrectCommandAttemptedEvent;
import seedu.taskman.commons.util.StringUtil;
import seedu.taskman.logic.parser.CommandParser;
import seedu.taskman.model.Model;
import seedu.taskman.model.event.Activity;
import seedu.taskman.storage.Storage;

import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Represents a command with hidden internal logic and the ability to be executed.
*/
public abstract class Command {
private static final Pattern TASK_INDEX_ARGS_FORMAT = Pattern.compile(CommandParser.ArgumentPattern.TARGET_INDEX.pattern);
private static final Pattern PANEL_TYPE_WITH_INDEX_ARGS_FORMAT =
Pattern.compile("" + CommandParser.ArgumentPattern.PANEL + CommandParser.ArgumentPattern.TARGET_INDEX);
private static final Pattern TASK_INDEX_ARGS_FORMAT =
Pattern.compile(CommandParser.ArgumentPattern.TARGET_INDEX.pattern);
public final boolean storeHistory;
protected Model model;
protected Storage storage;
Expand Down Expand Up @@ -59,15 +70,30 @@ protected static Optional<Integer> parseIndex(String command) {
if (!matcher.matches()) {
return Optional.empty();
}

String index = matcher.group("targetIndex");
if(!StringUtil.isUnsignedInteger(index)){
return Optional.empty();
}
return Optional.of(Integer.parseInt(index));

return Optional.of(Integer.valueOf(index));
}

/**
* Returns the specified panel type and index in the {@code command}IF a positive unsigned integer is given as the
* index and a panel type is specified
*/
protected static Optional<Pair<Activity.PanelType, Integer>> parsePanelTypeWithIndexOnly(String command) {
final Matcher matcher = PANEL_TYPE_WITH_INDEX_ARGS_FORMAT.matcher(command.trim());
if (!matcher.matches()) {
return Optional.empty();
}
String rawPanelType = matcher.group("panel");
Activity.PanelType panelType = Activity.PanelType.fromString(rawPanelType);
String index = matcher.group("targetIndex");
if(!StringUtil.isUnsignedInteger(index)){
return Optional.empty();
}
return Optional.of(new Pair<>(panelType, Integer.parseInt(index)));
}

/**
* Executes the command and returns the result message.
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/seedu/taskman/logic/commands/CompleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.taskman.logic.commands;

import javafx.util.Pair;
import seedu.taskman.commons.core.Messages;
import seedu.taskman.commons.core.UnmodifiableObservableList;
import seedu.taskman.commons.exceptions.IllegalValueException;
Expand All @@ -23,6 +24,7 @@ public class CompleteCommand extends Command {
public static final String COMMAND_WORD = "complete";
private static final String STATUS_COMPLETE = "complete";

// todo: change me
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Marks an existing task as complete./n"
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD
Expand All @@ -35,20 +37,25 @@ public class CompleteCommand extends Command {
private Activity activityToComplete;
private Activity afterComplete;
private int targetIndex;
private Activity.PanelType panelType;

private CompleteCommand(int targetIndex) {
private CompleteCommand(Activity.PanelType panelType, int targetIndex) {
super(true);
this.panelType = panelType;
this.targetIndex = targetIndex;
}

public static Command prepareComplete(String arguments) {
Optional<Integer> index = parseIndex(arguments);
if(!index.isPresent()){
Optional<Pair<Activity.PanelType, Integer>> panelIndexPair = parsePanelTypeWithIndexOnly(arguments);
if(!panelIndexPair.isPresent()){
return new IncorrectCommand(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE));
}

return new CompleteCommand(index.get());

return new CompleteCommand(
panelIndexPair.get().getKey(),
panelIndexPair.get().getValue());
}

@Override
Expand All @@ -74,7 +81,7 @@ public CommandResult execute() {
}

private void initMembers() throws IllegalValueException {
UnmodifiableObservableList<Activity> lastShownList = model.getFilteredActivityList();
UnmodifiableObservableList<Activity> lastShownList = model.getActivityListForPanelType(panelType);

if (lastShownList.size() < targetIndex) {
indicateAttemptToExecuteIncorrectCommand();
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/seedu/taskman/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package seedu.taskman.logic.commands;

import javafx.util.Pair;
import seedu.taskman.commons.core.Messages;
import seedu.taskman.commons.core.UnmodifiableObservableList;
import seedu.taskman.model.event.Activity;
import seedu.taskman.model.event.UniqueActivityList.ActivityNotFoundException;


import java.util.Optional;

import static seedu.taskman.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
Expand All @@ -14,37 +14,39 @@
* Deletes a task identified using it's last displayed index from the task man.
*/
public class DeleteCommand extends Command {

public static final String COMMAND_WORD = "delete";

//todo: update me
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the task or event identified by the index number used in the last activity listing.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_EVENT_SUCCESS = "Deleted Task: %1$s";

public final int targetIndex;
private final int targetIndex;
private final Activity.PanelType panelType;

public DeleteCommand(int targetIndex) {
private DeleteCommand(Activity.PanelType panelType, int targetIndex) {
super(true);
this.targetIndex = targetIndex;
this.panelType = panelType;
}

public static Command prepareDelete(String arguments) {
Optional<Integer> index = parseIndex(arguments);
if(!index.isPresent()){
Optional<Pair<Activity.PanelType, Integer>> panelWithIndex = parsePanelTypeWithIndexOnly(arguments);
if(!panelWithIndex.isPresent()){
return new IncorrectCommand(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE));
}

return new DeleteCommand(index.get());
Pair<Activity.PanelType, Integer> pair = panelWithIndex.get();
return new DeleteCommand(pair.getKey(), pair.getValue());
}

@Override
public CommandResult execute() {

UnmodifiableObservableList<Activity> lastShownList = model.getFilteredActivityList();
UnmodifiableObservableList<Activity> lastShownList = model.getActivityListForPanelType(panelType);

if (lastShownList.size() < targetIndex) {
indicateAttemptToExecuteIncorrectCommand();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/taskman/logic/commands/DoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ public class DoCommand extends Command {

// todo, differed: let parameters be objects. we can easily generate the usage in that case
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to TaskMan.\n"
+ "Parameters: TITLE d/DEADLINE s/SCHEDULE [t/TAG]...\n"
+ "Parameters: TITLE d/OPTIONAL_DEADLINE s/OPTIONAL_SCHEDULE [t/OPTIONAL_TAGS]...\n"
+ "Example: " + COMMAND_WORD
+ " pay utility bills d/next fri 1800 s/tdy 1800, tdy 1830 t/bills";

public static final String MESSAGE_SUCCESS = "New task added: %1$s";
public static final String MESSAGE_DUPLICATE_EVENT = "This task already exists in TaskMan";
private static final Pattern TASK_DO_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes
Pattern.compile("" + CommandParser.ArgumentPattern.TITLE
+ CommandParser.ArgumentPattern.DEADLINE
+ CommandParser.ArgumentPattern.SCHEDULE
+ CommandParser.ArgumentPattern.FREQUENCY
+ CommandParser.ArgumentPattern.TAG); // variable number of tags
+ CommandParser.ArgumentPattern.OPTIONAL_DEADLINE
+ CommandParser.ArgumentPattern.OPTIONAL_SCHEDULE
+ CommandParser.ArgumentPattern.OPTIONAL_FREQUENCY
+ CommandParser.ArgumentPattern.OPTIONAL_TAGS); // variable number of tags

private final Task toAdd;

Expand Down
Loading

0 comments on commit 0c24c9e

Please sign in to comment.