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

Merge V0.5 #128

Merged
merged 20 commits into from
Nov 7, 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
2 changes: 1 addition & 1 deletion docs/AboutUs.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Component SME: UI
* Other major contributions:
* Initial gradle natty dependency configuration [[8360c0d](https://github.com/CS2103AUG2016-T14-C2/main/commit/8360c0d66fc55f36bed0d0e9d4c6b63186aeb590)]
* Set up initial interface for undo/redo in Command classes and implement Logic-level undo/redo [[4dfafa0](https://github.com/CS2103AUG2016-T14-C2/main/commit/4dfafa07337f731959bcd7e267e0de9a093ae285)]
* All parsing related code for all commands [[Parser](../src/main/java/seedu/savvytasker/logic/parser)]
* Almost all parsing related code for all commands [[Parser](../src/main/java/seedu/savvytasker/logic/parser)]

-----

Expand Down
4 changes: 2 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ Format: `alias k/KEYWORD r/REPRESENTATION`

> Parameters | Description
> -------- | :--------
> KEYWORD | Specifies the keyword that will be replaced when met in a command, must be a single word
> REPRESENTATION | Specifies the text that will replace the keyword
> KEYWORD | Specifies the keyword that will be replaced when met in a command, must be a single word.
> REPRESENTATION | Specifies the text that will replace the keyword. Cannot contain slashes.

Examples:
* `alias k/pjm r/Project Meeting`<br>
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/savvytasker/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public class MainApp extends Application {
protected Config config;
protected UserPrefs userPrefs;
protected static MainApp instance;

public MainApp() {}

@Override
public void init() throws Exception {
logger.info("=============================[ Initializing Savvy Tasker ]===========================");
super.init();
instance = this;

config = initConfig(getApplicationParameter("config"));
storage = new StorageManager(config.getSavvyTaskerFilePath(), config.getUserPrefsFilePath());

Expand All @@ -69,8 +69,9 @@ public void init() throws Exception {
ui = new UiManager(logic, config, userPrefs);

initEventsCenter();

}

private String getApplicationParameter(String parameterName){
Map<String, String> applicationParameters = getParameters().getNamed();
return applicationParameters.get(parameterName);
Expand Down Expand Up @@ -183,7 +184,7 @@ public void stop() {
System.exit(0);
}

//@@author A0139915W
//@@author A0138431L
@Subscribe
public void handleSavvyTaskerSaveLocationChangedEvent(DataSavingLocationChangedEvent dslce) {
try {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/savvytasker/commons/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class Config {
private String savvyTaskerFilePath = "data/savvytasker.xml";
private String savvyTaskerListName = "MyTaskList";


public Config() {
}

Expand Down Expand Up @@ -61,7 +60,6 @@ public void setSavvyTaskerName(String savvyTaskerName) {
this.savvyTaskerListName = savvyTaskerName;
}


@Override
public boolean equals(Object other) {
if (other == this){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import seedu.savvytasker.commons.events.BaseEvent;
import seedu.savvytasker.model.ReadOnlySavvyTasker;

//@@author A0139915W
//@@author A0138431L
/**
* Indicates a change in location of the storage
*/
Expand Down
35 changes: 17 additions & 18 deletions src/main/java/seedu/savvytasker/commons/util/SmartDefaultDates.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//@@author A0139915W
/**
* Helper functions for handling dates.
* @author A0139915W
*/

public class SmartDefaultDates {
Expand All @@ -28,41 +27,37 @@ public SmartDefaultDates(InferredDate startDateTime, InferredDate endDateTime) {
calendar = Calendar.getInstance();
today = Calendar.getInstance();
today.setTime(new Date());
if (startDateTime == null && endDateTime == null) {
// dates not being supplied, nothing to parse
} else if (startDateTime == null && endDateTime != null) {
if (startDateTime == null && endDateTime != null) {
// apply smart default for endDateTime only
parseEnd(endDateTime);
} else if (startDateTime != null && endDateTime == null) {
// apply smart default for startDateTime only
parseStart(startDateTime);
} else {
} else if (startDateTime != null && endDateTime != null) {
parseStartAndEnd(startDateTime, endDateTime);
}
}

/**
* Gets the smart default for end date
* Gets the smart defaults for end date.
*
* If the date is not supplied, the date will default to today.
* If the time is not supplied, the time will default to 2359:59 on the specified date.
* If both date and time are not supplied, the date returned will be null.
* @param today the time now
* @param endDateTime the end time to parse
* @return
*/
public Date getEnd(InferredDate endDateTime) {
if (endDateTime == null) return null;
calendar.setTime(endDateTime.getInferredDateTime());
if (endDateTime.isDateInferred() && endDateTime.isTimeInferred()) {
// user didn't specify anything
// remove date field
return null;
} else if (endDateTime.isDateInferred()) {
// date not supplied
// defaults to today
calendar.set(Calendar.DATE, today.get(Calendar.DATE));
calendar.set(Calendar.MONTH, today.get(Calendar.MONTH));
calendar.set(Calendar.YEAR, today.get(Calendar.YEAR));
} else if (endDateTime.isTimeInferred()) {
// time not supplied
// defaults to 2359
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
Expand Down Expand Up @@ -97,7 +92,11 @@ private void parseEnd(InferredDate endDateTime) {


/**
* Gets the smart default for start date
* Gets the smart default for start date.
*
* If the date is not supplied, the date will default to today.
* If the time is not supplied, the time will default to 0000:00 on the specified date.
* If both date and time are not supplied, the date returned will be null.
* @param today the time now
* @param startDateTime the start time to parse
* @return
Expand All @@ -110,14 +109,10 @@ public Date getStart(InferredDate startDateTime) {
// remove date field
return null;
} else if (startDateTime.isDateInferred()) {
// date not supplied
// defaults to today
calendar.set(Calendar.DATE, today.get(Calendar.DATE));
calendar.set(Calendar.MONTH, today.get(Calendar.MONTH));
calendar.set(Calendar.YEAR, today.get(Calendar.YEAR));
} else if (startDateTime.isTimeInferred()) {
// time not supplied
// defaults to 0000
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Expand Down Expand Up @@ -148,8 +143,12 @@ private void parseStart(InferredDate startDateTime) {

/**
* Sets the starting and ending date/time based on defaults for providing both
* start and end times
* start and end times.
*
* Note that this method has no restrictions on the starting and ending date/time.
* i.e. the starting time is later than the ending time.
* @param startDateTime start time supplied
* @param endDateTime end time supplied
*/
private void parseStartAndEnd(InferredDate startDateTime, InferredDate endDateTime) {
assert endDateTime.getInferredDateTime() != null;
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/seedu/savvytasker/logic/Logic.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package seedu.savvytasker.logic;

import java.util.Date;

import javafx.collections.ObservableList;
import seedu.savvytasker.logic.commands.CommandResult;
import seedu.savvytasker.model.alias.AliasSymbol;
import seedu.savvytasker.logic.commands.CommandResult;
import seedu.savvytasker.model.task.ReadOnlyTask;

/**
Expand All @@ -18,10 +20,23 @@ public interface Logic {

/** Returns the filtered list of tasks */
ObservableList<ReadOnlyTask> getFilteredTaskList();

/** Returns the filtered list of alias symbol */
ObservableList<AliasSymbol> getAliasSymbolList();

/** */
boolean canParseHeader(String keyword);

/** Returns the list of tasks that are overdue */
ObservableList<ReadOnlyTask> getFilteredOverdueTasks();

/** Returns the list of floating tasks */
ObservableList<ReadOnlyTask> getFilteredFloatingTasks();

/** Returns the list of tasks on a specific day */
ObservableList<ReadOnlyTask> getFilteredDailyTasks(int i, Date date);

/** Returns the list of tasks that occur after the selected week */
ObservableList<ReadOnlyTask> getFilteredUpcomingTasks(Date date);

}
70 changes: 52 additions & 18 deletions src/main/java/seedu/savvytasker/logic/LogicManager.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package seedu.savvytasker.logic;

import java.util.Date;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.logging.Logger;

import com.google.common.eventbus.Subscribe;

import javafx.collections.ObservableList;
import seedu.savvytasker.MainApp;
import seedu.savvytasker.commons.core.ComponentManager;
import seedu.savvytasker.commons.core.EventsCenter;
import seedu.savvytasker.commons.core.LogsCenter;
Expand Down Expand Up @@ -37,26 +38,26 @@
import seedu.savvytasker.model.alias.AliasSymbol;
import seedu.savvytasker.model.task.ReadOnlyTask;
import seedu.savvytasker.storage.Storage;
import seedu.savvytasker.ui.Ui;

/**
* The main LogicManager of the app.
*/
public class LogicManager extends ComponentManager implements Logic {
private final Logger logger = LogsCenter.getLogger(LogicManager.class);

private final int MAX_UNDO_REDO_QUEUE_SIZE = 50;

private final Model model;
private final Storage storage;
private final MasterParser parser;
private final Stack<Command> undoStack;
private final Stack<Command> redoStack;
private final Deque<Command> undoDeque;
private final Deque<Command> redoDeque;

public LogicManager(Model model, Storage storage) {
this.model = model;
this.storage = storage;
this.parser = new MasterParser();
this.undoStack = new Stack<Command>();
this.redoStack = new Stack<Command>();
this.undoDeque = new LinkedList<Command>();
this.redoDeque = new LinkedList<Command>();

registerAllDefaultCommandParsers();
loadAllAliasSymbols();
Expand Down Expand Up @@ -89,23 +90,48 @@ else if (command.isRedo()){
}
}
else if (command.canUndo()){
undoStack.push(command);
redoStack.clear();
//@@author A0139916U
undoDeque.addLast(command);
if (undoDeque.size() > MAX_UNDO_REDO_QUEUE_SIZE) {
undoDeque.removeFirst();
}
redoDeque.clear();
}
//@@author

return result;
}

//@@author A0139915W
@Override
public ObservableList<ReadOnlyTask> getFilteredTaskList() {
return model.getFilteredTaskList();
}

@Override
public ObservableList<AliasSymbol> getAliasSymbolList() {
return parser.getAliasSymbolList();
}
//@@author

//@@author A0138431L
@Override
public ObservableList<ReadOnlyTask> getFilteredOverdueTasks() {
return model.getFilteredOverdueTasks();
}

@Override
public ObservableList<ReadOnlyTask> getFilteredFloatingTasks() {
return model.getFilteredFloatingTasks();
}

@Override
public ObservableList<ReadOnlyTask> getFilteredDailyTasks(int i, Date date) {
return model.getFilteredDailyTasks(i, date);
}

@Override
public ObservableList<ReadOnlyTask> getFilteredUpcomingTasks(Date date) {
return model.getFilteredUpcomingTasks(date);
}
//@@author

Expand Down Expand Up @@ -135,26 +161,34 @@ private void loadAllAliasSymbols() {
}
}

/**
* Undo last command and add it to the redo deque.
* @return true if undone successfully, false otherwise
*/
private boolean undo() {
boolean undone = false;

if (!undoStack.isEmpty()) {
Command command = undoStack.pop();
if (!undoDeque.isEmpty()) {
Command command = undoDeque.removeLast();
command.undo();
redoStack.push(command);
redoDeque.addLast(command);
undone = true;
}

return undone;
}

/**
* Redo last command and add it to undone deque.
* @return true if redone successfully, false otherwise
*/
private boolean redo() {
boolean redone = false;

if (!redoStack.isEmpty()) {
Command command = redoStack.pop();
if (!redoDeque.isEmpty()) {
Command command = redoDeque.removeLast();
command.redo();
undoStack.push(command);
undoDeque.addLast(command);
redone = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ public CommandResult execute() {
addToListOfTasksAdded(tasksAdded.toArray(new Task[tasksAdded.size()]));
}

// always >= 0 unless this is being run without UI.
int targetIndex = getIndexOfTask(taskAdded);
if (targetIndex >= 0) {
EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex));
} else {
// GUI should never ever get here
}
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
} catch (InvalidDateException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ public class ClearCommand extends ModelRequiringCommand {
public static final String MESSAGE_SUCCESS = "Savvy Tasker has been cleared!";

private ReadOnlySavvyTasker original;

public ClearCommand() {}


@Override
public CommandResult execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class ExitCommand extends Command {

public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Savvy Tasker as requested ...";

public ExitCommand() {}

@Override
public CommandResult execute() {
EventsCenter.getInstance().post(new ExitAppRequestEvent());
Expand Down
Loading