Skip to content

Commit

Permalink
Merge 9bf7c69 into abdbee2
Browse files Browse the repository at this point in the history
  • Loading branch information
waynefong0401 committed Oct 23, 2019
2 parents abdbee2 + 9bf7c69 commit f48b6c9
Show file tree
Hide file tree
Showing 34 changed files with 767 additions and 15 deletions.
39 changes: 39 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,45 @@ Example: +
Shows a breakdown of all expenses in text form. +
{nbsp} +

=== Undo and Redo: `undo/redo`

. _Undo the previous action: undo_ +
Undo will restore the previous billboard state from state history. Undo will ignore all arguments. +
{nbsp} +
Usage:

undo
+
{nbsp} +
. _Redo the previous undo action: redo_ +
Redo will restore a previously undone billboard state from state history. Redo will ignore all arguments. +
{nbsp} +
Usage:

redo
+
{nbsp} +

=== Viewing History: `history`

. _View the past command history: history_ +
History will show all previous command histories. History will ignore all arguments. +
{nbsp} +
Usage:

history
+
{nbsp} +

=== Up and down key: `↑/↓`

. _Get the previous entered command: ↑_ +
Up arrow key(↑) will get the previous command entered in the command history on the text field. +
{nbsp} +
. _Get the sequential entered command: ↓_ +
Down arrow key(↓) will get the sequential command entered in the command history on the text field. +
{nbsp} +

=== Viewing help: `help`

. _Help list of complete set of commands: help_ +
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/billboard/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.billboard.model.ReadOnlyBillboard;
import seedu.billboard.model.ReadOnlyUserPrefs;
import seedu.billboard.model.UserPrefs;
import seedu.billboard.model.versionedbillboard.VersionedBillboard;
import seedu.billboard.model.util.SampleDataUtil;
import seedu.billboard.storage.BillboardStorage;
import seedu.billboard.storage.JsonBillboardStorage;
Expand Down Expand Up @@ -66,6 +67,8 @@ public void init() throws Exception {
logic = new LogicManager(model, storage);

ui = new UiManager(logic);

VersionedBillboard.commit(model.getClone());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/billboard/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class Messages {
public static final String MESSAGE_NONEXISTENT_ARCHIVE_ENTERED =
"There is no existing archive of the name provided";
public static final String MESSAGE_INVALID_ARCHIVE_NAME = "The archive name cannot be empty!";
public static final String MESSAGE_NOT_UNDOABLE = "There is no command to be undone.";
public static final String MESSAGE_NOT_REDOABLE = "There is no command to be redone.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@ private void notifyObservers() {
observer.onChanged(value);
}
}

public Set<Observer<? super T>> getObservers() {
return observers;
}

public void setObservers(Set<Observer<? super T>> observers) {
this.observers.addAll(observers);
}

}
20 changes: 20 additions & 0 deletions src/main/java/seedu/billboard/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@
import seedu.billboard.commons.core.GuiSettings;
import seedu.billboard.commons.core.LogsCenter;
import seedu.billboard.commons.core.observable.ObservableData;
import seedu.billboard.logic.commands.AddArchiveCommand;
import seedu.billboard.logic.commands.AddCommand;
import seedu.billboard.logic.commands.AddTagCommand;
import seedu.billboard.logic.commands.ClearCommand;
import seedu.billboard.logic.commands.Command;
import seedu.billboard.logic.commands.CommandResult;
import seedu.billboard.logic.commands.DeleteArchiveCommand;
import seedu.billboard.logic.commands.DeleteCommand;
import seedu.billboard.logic.commands.EditCommand;
import seedu.billboard.logic.commands.FilterTagCommand;
import seedu.billboard.logic.commands.RemoveTagCommand;
import seedu.billboard.logic.commands.RevertArchiveCommand;
import seedu.billboard.logic.commands.exceptions.CommandException;
import seedu.billboard.logic.parser.BillboardParser;
import seedu.billboard.logic.parser.exceptions.ParseException;
import seedu.billboard.model.Model;
import seedu.billboard.model.ReadOnlyArchiveWrapper;
import seedu.billboard.model.ReadOnlyBillboard;
import seedu.billboard.model.expense.Expense;
import seedu.billboard.model.versionedbillboard.VersionedBillboard;
import seedu.billboard.model.statistics.StatisticsType;
import seedu.billboard.storage.Storage;

Expand Down Expand Up @@ -45,6 +56,15 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
Command command = billboardParser.parseCommand(commandText);
commandResult = command.execute(model);

if ((command instanceof AddArchiveCommand) || (command instanceof AddCommand)
|| (command instanceof AddTagCommand) || (command instanceof ClearCommand)
|| (command instanceof DeleteArchiveCommand) || (command instanceof DeleteCommand)
|| (command instanceof RevertArchiveCommand) || (command instanceof EditCommand)
|| (command instanceof FilterTagCommand) || (command instanceof RemoveTagCommand)) {
VersionedBillboard.addCmd(commandText);
VersionedBillboard.commit(model.getClone());
}

try {
storage.saveBillboard(model.getCombinedBillboard());
} catch (IOException ioe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addArchiveExpense(archiveName, expenseToArchive);

return new CommandResult(
String.format(MESSAGE_SUCCESS_EXISTING_ARCHIVE, expenseToArchive.getName(), archiveName));
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/seedu/billboard/logic/commands/HistoryCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package seedu.billboard.logic.commands;

import seedu.billboard.model.Model;
import seedu.billboard.model.history.CommandHistory;

/**
* Displays all history command.
*/
public class HistoryCommand extends Command {
public static final String COMMAND_WORD = "history";
public static final String MESSAGE_EMPTY_HISTORY = "There is no command history.";


/**
* Executes the command and returns the result message.
*
* @param model {@code Model} which the command should operate on.
* @return feedback message of the operation result for display
*/
@Override
public CommandResult execute(Model model) {
if (!CommandHistory.hasCommand()) {
return new CommandResult(MESSAGE_EMPTY_HISTORY);
}

CommandResult cmdResult = new CommandResult(CommandHistory.getCmdHistory());
return cmdResult;
}
}
35 changes: 35 additions & 0 deletions src/main/java/seedu/billboard/logic/commands/RedoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package seedu.billboard.logic.commands;

import seedu.billboard.logic.commands.exceptions.CommandException;
import seedu.billboard.model.Model;
import seedu.billboard.model.versionedbillboard.VersionedBillboard;

/**
* Undo the previous edit action.
*/
public class RedoCommand extends Command {

public static final String COMMAND_WORD = "redo";
public static final String EMPTY_UNDO_LIST = "There is no command to be redone.";
public static final String MESSAGE_REDO_SUCCESS = COMMAND_WORD + ": %s";

/**
* Executes the command and returns the result message.
*
* @param model {@code Model} which the command should operate on.
* @return feedback message of the operation result for display
* @throws CommandException If an error occurs during command execution.
*/
@Override
public CommandResult execute(Model model) throws CommandException {
if (!VersionedBillboard.isRedoable()) {
throw new CommandException(EMPTY_UNDO_LIST);
}

String redoCmd = VersionedBillboard.getRedoCmd();
Model undoModel = VersionedBillboard.redo();
model.setModel(undoModel);
CommandResult cmdResult = new CommandResult(String.format(MESSAGE_REDO_SUCCESS, redoCmd));
return cmdResult;
}
}
35 changes: 35 additions & 0 deletions src/main/java/seedu/billboard/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package seedu.billboard.logic.commands;

import seedu.billboard.logic.commands.exceptions.CommandException;
import seedu.billboard.model.Model;
import seedu.billboard.model.versionedbillboard.VersionedBillboard;

/**
* Undo the previous edit action.
*/
public class UndoCommand extends Command {

public static final String COMMAND_WORD = "undo";
public static final String EMPTY_UNDO_LIST = "There is no command to be undone.";
public static final String MESSAGE_UNDO_SUCCESS = COMMAND_WORD + ": %s";

/**
* Executes the command and returns the result message.
*
* @param model {@code Model} which the command should operate on.
* @return feedback message of the operation result for display
* @throws CommandException If an error occurs during command execution.
*/
@Override
public CommandResult execute(Model model) throws CommandException {
if (!VersionedBillboard.isUndoable()) {
throw new CommandException(EMPTY_UNDO_LIST);
}

Model undoModel = VersionedBillboard.undo();
String undoCmd = VersionedBillboard.getUndoCmd();
model.setModel(undoModel);
CommandResult cmdResult = new CommandResult(String.format(MESSAGE_UNDO_SUCCESS, undoCmd));
return cmdResult;
}
}
12 changes: 12 additions & 0 deletions src/main/java/seedu/billboard/logic/parser/BillboardParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import seedu.billboard.logic.commands.ExitCommand;
import seedu.billboard.logic.commands.FindCommand;
import seedu.billboard.logic.commands.HelpCommand;
import seedu.billboard.logic.commands.HistoryCommand;
import seedu.billboard.logic.commands.ListCommand;
import seedu.billboard.logic.commands.RedoCommand;
import seedu.billboard.logic.commands.TagCommand;
import seedu.billboard.logic.commands.UndoCommand;
import seedu.billboard.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -76,6 +79,15 @@ public Command parseCommand(String userInput) throws ParseException {
case TagCommand.COMMAND_WORD:
return new TagCommandParser().parse(arguments);

case UndoCommand.COMMAND_WORD:
return new UndoCommand();

case RedoCommand.COMMAND_WORD:
return new RedoCommand();

case HistoryCommand.COMMAND_WORD:
return new HistoryCommand();

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/seedu/billboard/model/ArchiveWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ public ArchiveWrapper(List<Expense> unfilteredExpenses) {

}

public ArchiveWrapper(HashMap<String, Archive> archiveList) {
this.archiveList.putAll(archiveList);
}

//==================== HashMap Overwrite operations ====================

/**
* Replaces the contents of the archives with {@code newArchives}.
*/
public void setArchiveList(List<Archive> newArchiveList) {
private void setArchiveList(List<Archive> newArchiveList) {
archiveList.clear();
for (Archive archive : newArchiveList) {
archiveList.put(archive.getArchiveName(), archive);
Expand Down Expand Up @@ -83,7 +87,7 @@ public void addArchive(Archive newArchive) {
archiveList.put(newArchive.getArchiveName(), newArchive);
}

public void removeArchive(String targetArchiveName) {
void removeArchive(String targetArchiveName) {
archiveList.remove(targetArchiveName);
}

Expand Down Expand Up @@ -111,7 +115,7 @@ public void addArchiveExpense(String archiveName, Expense p) {
* Removes {@code key} from the given archive.
* The given {@code archiveName} must exist.
*/
public void removeArchiveExpense(String archiveName, Expense key) {
void removeArchiveExpense(String archiveName, Expense key) {
archiveList.get(archiveName).remove(key);
}

Expand Down Expand Up @@ -141,14 +145,21 @@ public List<Expense> getExpenseList() {
List<Archive> archives = getArchiveList();
for (Archive archive : archives) {
List<Expense> toBeCopied = archive.asUnmodifiableObservableList();
for (Expense expense : toBeCopied) {
expenses.add(expense);
}
expenses.addAll(toBeCopied);
}

return expenses;
}

@Override
public ArchiveWrapper getClone() {
return new ArchiveWrapper((HashMap<String, Archive>) archiveList.clone());
}

void setArchives(ReadOnlyArchiveWrapper archives) {
setArchiveList(archives.getArchiveList());
}

@Override
public String toString() {
return getArchiveNames().toString();
Expand All @@ -166,4 +177,6 @@ public boolean equals(Object other) {
public int hashCode() {
return archiveList.hashCode();
}


}
22 changes: 21 additions & 1 deletion src/main/java/seedu/billboard/model/Billboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public Billboard(ReadOnlyBillboard toBeCopied) {
resetData(toBeCopied);
}

public Billboard(ExpenseList expenses, UniqueTagList tags, TagCountManager count) {
setExpenses(expenses.asUnmodifiableObservableList());
this.tags.setTagList(tags.getTagList());
this.count.setCountMap(count.getCountMap());
}

//// list overwrite operations

/**
Expand All @@ -58,7 +64,7 @@ public void setExpenses(List<Expense> expense) {
}

public void setUniqueTagList(Map<String, Tag> tagList) {
this.tags.setList(tagList);
this.tags.setTagList(tagList);
}

public void setCountManager(Map<Tag, Integer> count) {
Expand Down Expand Up @@ -94,6 +100,20 @@ public ReadOnlyBillboard removeArchiveExpenses() {
return billboard;
}

public Billboard getClone() {
return new Billboard(expenses.getClone(), tags.getClone(), count.getClone());
}

public void setBillboard(Billboard billboard) {
setExpenses(billboard.getExpenses());
tags.setTagList(billboard.getTags().getTagList());
setCountManager(billboard.getCountManager());
}

public UniqueTagList getTags() {
return tags;
}

//// expense-level operations

/**
Expand Down

0 comments on commit f48b6c9

Please sign in to comment.