Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103T-T09-2#136 from mingyu-wan/undo-re…
Browse files Browse the repository at this point in the history
…do-function-implementation

Implement undo redo function
  • Loading branch information
emzm2023 authored Oct 31, 2023
2 parents 7681bef + f8a327b commit 30457aa
Show file tree
Hide file tree
Showing 29 changed files with 188 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class Messages {
public static final String MESSAGE_INVALID_DEVELOPER_DISPLAYED_INDEX = "The developer index provided is invalid!";
public static final String MESSAGE_INVALID_CLIENT_DISPLAYED_INDEX = "The client index provided is invalid!";
public static final String MESSAGE_INVALID_PROJECT_DISPLAYED_INDEX = "The project index provided is invalid!";
public static final String MESSAGE_INAPPLICABLE_PREFIX_USED = "You tried to edit an inapplicable field! Please check " +
"the prefixes used and try again. \n%1$s";
public static final String MESSAGE_INAPPLICABLE_PREFIX_USED = "You tried to edit an inapplicable field! "
+ "Please check the prefixes used and try again. \n%1$s";
public static final String MESSAGE_NONEXISTENT_PROJECT = "There is no existing Project with the name: %1$s!";
public static String getMessageDevelopersListedOverview(int count) {
return count == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class ClearCommand extends Command {
public CommandResult execute(Model model) {
requireNonNull(model);
model.setAddressBook(new AddressBook());
return new CommandResult(MESSAGE_SUCCESS,TabIndex.Developer);
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public CommandResult execute(Model model) throws CommandException {

Developer developerToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteDeveloper(developerToDelete);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_DELETE_DEVELOPER_SUCCESS, Messages.format(developerToDelete)),TabIndex.Developer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ExitCommand extends Command {

@Override
public CommandResult execute(Model model) {
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true,TabIndex.Developer);
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true, TabIndex.Developer);
}

}
18 changes: 18 additions & 0 deletions src/main/java/seedu/address/logic/commands/RedoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;

public class RedoCommand extends Command {
public static final String COMMAND_WORD = "redo";
public static final String MESSAGE_SUCCESS = "Redo successful!";

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.redoAddressBook(model);
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/TabIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public enum TabIndex {
Developer,
Client,
Project
developers, Project
}
18 changes: 18 additions & 0 deletions src/main/java/seedu/address/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;

public class UndoCommand extends Command {
public static final String COMMAND_WORD = "undo";
public static final String MESSAGE_SUCCESS = "Undo successful!";
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.undoAddressBook(model);
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addClient(toAdd);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)), TabIndex.Client);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addDeveloper(toAdd);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)), TabIndex.Developer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addProject(toAdd);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)), TabIndex.Project);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public CommandResult execute(Model model) throws CommandException {

model.setClient(clientToEdit, editedClient);
model.updateFilteredClientList(Model.PREDICATE_SHOW_ALL_CLIENTS);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_EDIT_CLIENT_SUCCESS, Messages.format(editedClient)), TabIndex.Client);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public CommandResult execute(Model model) throws CommandException {

model.setDeveloper(developerToEdit, editedDeveloper);
model.updateFilteredDeveloperList(Model.PREDICATE_SHOW_ALL_DEVELOPERS);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_EDIT_DEVELOPER_SUCCESS, Messages.format(editedDeveloper)), TabIndex.Developer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public CommandResult execute(Model model) throws CommandException {

model.setProject(projectToEdit, editedProject);
model.updateFilteredProjectList(Model.PREDICATE_SHOW_ALL_PROJECTS);
model.commitAddressBook(model);
return new CommandResult(String.format(MESSAGE_EDIT_PROJECT_SUCCESS, Messages.format(editedProject)), TabIndex.Project);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ public String toString() {
.add("predicate", predicate)
.toString();
}
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.commands.find;

import static java.util.Objects.requireNonNull;

import static seedu.address.logic.Messages.getMessageDevelopersListedOverview;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATEJOINED;
Expand All @@ -16,6 +17,7 @@
import java.util.function.Predicate;

import seedu.address.commons.util.ToStringBuilder;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.TabIndex;
Expand Down Expand Up @@ -76,4 +78,5 @@ public String toString() {
.add("predicate", predicate)
.toString();
}
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.commands.find;

import static java.util.Objects.requireNonNull;

import static seedu.address.logic.Messages.getMessageProjectsListedOverview;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEADLINE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.list;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CLIENTS;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.TabIndex;
import seedu.address.model.Model;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.list;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_DEVELOPERS;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.TabIndex;
import seedu.address.model.Model;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.list;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PROJECTS;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.TabIndex;
import seedu.address.model.Model;

/**
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.regex.Pattern;

import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteDeveloperCommand;
Expand All @@ -17,9 +19,9 @@
import seedu.address.logic.commands.find.FindProjectCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ImportCommand;
import seedu.address.logic.commands.ListClientCommand;
import seedu.address.logic.commands.ListDeveloperCommand;
import seedu.address.logic.commands.ListProjectCommand;
import seedu.address.logic.commands.list.ListClientCommand;
import seedu.address.logic.commands.list.ListDeveloperCommand;
import seedu.address.logic.commands.list.ListProjectCommand;
import seedu.address.logic.commands.add.AddClientCommand;
import seedu.address.logic.commands.add.AddDeveloperCommand;
import seedu.address.logic.commands.add.AddProjectCommand;
Expand All @@ -35,8 +37,10 @@
import seedu.address.logic.parser.edit.EditDeveloperCommandParser;
import seedu.address.logic.parser.edit.EditProjectCommandParser;
import seedu.address.logic.parser.exceptions.ParseException;

import seedu.address.logic.parser.imports.ImportClientCommandParser;
import seedu.address.logic.parser.imports.ImportDeveloperCommandParser;

import seedu.address.logic.parser.find.FindClientCommandParser;
import seedu.address.logic.parser.find.FindDeveloperCommandParser;
import seedu.address.logic.parser.find.FindProjectCommandParser;
Expand Down Expand Up @@ -108,7 +112,7 @@ public Command parseCommand(String userInput) throws ParseException {

case FindProjectCommand.COMMAND_WORD:
return new FindProjectCommandParser().parse(arguments);

case ListClientCommand.COMMAND_WORD:
return new ListClientCommand();

Expand All @@ -118,6 +122,12 @@ public Command parseCommand(String userInput) throws ParseException {
case ListProjectCommand.COMMAND_WORD:
return new ListProjectCommand();

case UndoCommand.COMMAND_WORD:
return new UndoCommand();

case RedoCommand.COMMAND_WORD:
return new RedoCommand();

case ExitCommand.COMMAND_WORD:
return new ExitCommand();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser.find;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOCUMENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
Expand Down Expand Up @@ -99,7 +100,6 @@ private Predicate<Client> buildPredicate(ArgumentMultimap argMultimap) {
String[] organisationKeywords = argMultimap.getValue(PREFIX_ORGANISATION).get().split("\\s+");
finalPredicate = finalPredicate.and(new OrganisationContainsKeywordsPredicate(Arrays.asList(organisationKeywords)));
}

return finalPredicate;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser.find;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATEJOINED;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
import seedu.address.logic.commands.find.FindProjectCommand;
import seedu.address.logic.parser.ArgumentMultimap;
import seedu.address.logic.parser.ArgumentTokenizer;

import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.project.DeadlineContainsKeywordsPredicate;
import seedu.address.model.project.DescriptionContainsKeywordsPredicate;

import seedu.address.model.project.Project;

import seedu.address.model.project.ProjectNameContainsKeywordsPredicate;

/**
* Parses input arguments and creates a new FindProjectCommand object
*/
public class FindProjectCommandParser implements Parser<FindProjectCommand> {

public FindProjectCommand parse(String args) throws ParseException {
String trimmedArgs = args.trim();
if (trimmedArgs.isEmpty()) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.client.Client;
import seedu.address.model.developer.Developer;

Expand Down Expand Up @@ -100,4 +101,7 @@ public interface Model {
void updateFilteredDeveloperList(Predicate<Developer> predicate);
void updateFilteredClientList(Predicate<Client> predicate);
void updateFilteredProjectList(Predicate<seedu.address.model.project.Project> predicate);
void commitAddressBook(Model model);
void undoAddressBook(Model model) throws CommandException;
void redoAddressBook(Model model) throws CommandException;
}
Loading

0 comments on commit 30457aa

Please sign in to comment.