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

Add close command #115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
cf66436
Move saving data section to the last feature
itsme-zeix Oct 20, 2024
d03c915
Update fork
iamdiluxedbutcooler Oct 21, 2024
c0cd395
Update fork 2
iamdiluxedbutcooler Oct 21, 2024
e38f1f5
Implement confirmation check
FionaQY Oct 21, 2024
1876f0d
Refactor command logic
FionaQY Oct 21, 2024
c9bf45f
Fix saving bug
FionaQY Oct 21, 2024
3eec0ea
Fix checkstyle violation
FionaQY Oct 21, 2024
7d77a32
Add test for delete command
FionaQY Oct 21, 2024
97c0dcf
Fix import order
FionaQY Oct 21, 2024
8044291
Rewrite of User Guide
itsme-zeix Oct 21, 2024
7430457
Add Prerequisite section and setup congrats message
itsme-zeix Oct 21, 2024
c3aac31
Add view command
iamdiluxedbutcooler Oct 21, 2024
2bb50ac
Add view command parser
iamdiluxedbutcooler Oct 21, 2024
b414167
Update parser related file
iamdiluxedbutcooler Oct 21, 2024
0e84a17
Refactor command classes as we going to define which person we are vi…
iamdiluxedbutcooler Oct 21, 2024
e4c4ea3
Update command result to include view command
iamdiluxedbutcooler Oct 21, 2024
0e89fdd
Update model classes
iamdiluxedbutcooler Oct 21, 2024
9cb5b26
Add split screen panel
iamdiluxedbutcooler Oct 21, 2024
86e9eeb
Link new panel with main window
iamdiluxedbutcooler Oct 21, 2024
0995698
Update styling files
iamdiluxedbutcooler Oct 21, 2024
9c504ce
Update arguments for view person in related tests
iamdiluxedbutcooler Oct 21, 2024
294b216
Add tests for view command
iamdiluxedbutcooler Oct 21, 2024
2ff0865
Formatting main
iamdiluxedbutcooler Oct 21, 2024
b94e5d0
Formatting test
iamdiluxedbutcooler Oct 21, 2024
75ada68
Fix EOF errors
iamdiluxedbutcooler Oct 21, 2024
3437adf
Fix EOF 2
iamdiluxedbutcooler Oct 21, 2024
f674e9a
Add close command
iamdiluxedbutcooler Oct 21, 2024
26c58ee
Update parser
iamdiluxedbutcooler Oct 21, 2024
9623c34
Update UI
iamdiluxedbutcooler Oct 21, 2024
b5db425
Add test for close command
iamdiluxedbutcooler Oct 21, 2024
cd4f994
Add suggested changes
itsme-zeix Oct 22, 2024
bc994c2
Merge pull request #111 from itsme-zeix/update-user-guide
itsme-zeix Oct 22, 2024
055ee03
Merge pull request #107 from FionaQY/command-confirmation
ZShunRen Oct 22, 2024
63e59c8
Update src/main/java/seedu/address/model/ModelManager.java
iamdiluxedbutcooler Oct 22, 2024
261223e
Update src/main/java/seedu/address/model/ModelManager.java
iamdiluxedbutcooler Oct 22, 2024
658be23
Change checking protocol to match other module
iamdiluxedbutcooler Oct 22, 2024
1fb90af
Standardize conditions
iamdiluxedbutcooler Oct 22, 2024
d641c02
Resolve merge conflicts
iamdiluxedbutcooler Oct 22, 2024
6a3dcca
Solve test fail
iamdiluxedbutcooler Oct 22, 2024
922f676
Add enums for empty person
iamdiluxedbutcooler Oct 22, 2024
8ca6273
Merge pull request #114 from iamdiluxedbutcooler/add-view-and-close-c…
iamdiluxedbutcooler Oct 22, 2024
3dcac3e
Add close command
iamdiluxedbutcooler Oct 21, 2024
6b6523b
Update parser
iamdiluxedbutcooler Oct 21, 2024
483fd7e
Update UI
iamdiluxedbutcooler Oct 21, 2024
7c2b2d0
Add test for close command
iamdiluxedbutcooler Oct 21, 2024
0a0167c
Resolve merge conflict
iamdiluxedbutcooler Oct 22, 2024
91b5ded
Fix same level of abstraction
iamdiluxedbutcooler Oct 22, 2024
62fb739
Merge remote-tracking branch 'origin/add-close-split-command' into ad…
iamdiluxedbutcooler Oct 22, 2024
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
886 changes: 581 additions & 305 deletions docs/UserGuide.md

Large diffs are not rendered by default.

38 changes: 36 additions & 2 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic;

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

import java.io.IOException;
import java.nio.file.AccessDeniedException;
import java.nio.file.Path;
Expand Down Expand Up @@ -33,6 +35,10 @@ public class LogicManager implements Logic {
private final Storage storage;
private final AddressBookParser addressBookParser;

// Boolean to determine if user has confirmed they want to delete command
private boolean awaitingConfirmation = false;
private Command delayedCommand = null;

/**
* Constructs a {@code LogicManager} with the given {@code Model} and {@code Storage}.
*/
Expand All @@ -47,8 +53,17 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
logger.info("----------------[USER COMMAND][" + commandText + "]");

CommandResult commandResult;
Command command = addressBookParser.parseCommand(commandText);
commandResult = command.execute(model);
if (this.awaitingConfirmation) {
commandResult = handleConfirmation(commandText);
} else {
Command command = addressBookParser.parseCommand(commandText);
commandResult = command.execute(model, this.awaitingConfirmation);

if (commandResult.isShowConfirmation() && !this.awaitingConfirmation) {
this.awaitingConfirmation = true;
this.delayedCommand = command;
}
}

try {
storage.saveAddressBook(model.getAddressBook());
Expand All @@ -61,6 +76,25 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
return commandResult;
}

/**
* Processes user input for command confirmation.
* Executes the delayed command if confirmed, or cancels it and returns a cancellation message.
*
* @param commandText The user's confirmation input.
* @return The result of the command if confirmed, or a cancellation message.
* @throws CommandException If an error occurs during command execution.
*/
private CommandResult handleConfirmation(String commandText) throws CommandException {
CommandResult commandResult;
if (addressBookParser.parseConfirmation(commandText)) {
commandResult = this.delayedCommand.execute(model, this.awaitingConfirmation);
} else {
commandResult = new CommandResult(MESSAGE_COMMAND_CANCELLED);
}
this.awaitingConfirmation = false;
return commandResult;
}

@Override
public ReadOnlyAddressBook getAddressBook() {
return model.getAddressBook();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class Messages {

public static final String MESSAGE_CONCURRENT_RN_RA_FIELDS = "Both remark new and remark append fields are "
+ "specified, please only use one.";

public static final String MESSAGE_COMMAND_CANCELLED = "Command has been cancelled.";

/**
* Returns an error message indicating the duplicate prefixes.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public AddCommand(Person person) {
}

@Override
public CommandResult execute(Model model) throws CommandException {
protected CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_CLEAR_CONFIRMATION = "This will permanently clear all contacts. "
+ "Are you sure you want to execute this command? (y/n)";

private static final boolean requiresConfirmation = true;

@Override
public CommandResult execute(Model model) {
protected CommandResult execute(Model model) {
requireNonNull(model);
model.setAddressBook(new AddressBook());
return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public CommandResult execute(Model model, Boolean confirmationReceived) {
if (confirmationReceived.equals(requiresConfirmation)) {
return this.execute(model);
}
return new CommandResult(MESSAGE_CLEAR_CONFIRMATION, false, false, true, null, false);
}

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

import static seedu.address.logic.commands.CommandCommons.EMPTY_PERSON;

import seedu.address.model.Model;

/**
* Closes the detail view in the address book.
*/
public class CloseCommand extends Command {

public static final String COMMAND_WORD = "close";

public static final String MESSAGE_SUCCESS = "Detailed view closed.";

@Override
public CommandResult execute(Model model) {
return new CommandResult(
MESSAGE_SUCCESS,
false,
false,
false,
EMPTY_PERSON,
false
);
}
@Override
public boolean equals(Object obj) {
return obj == this || obj instanceof CloseCommand;
}

@Override
public String toString() {
return COMMAND_WORD;
}
}
21 changes: 19 additions & 2 deletions src/main/java/seedu/address/logic/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,30 @@
*/
public abstract class Command {

private static final boolean requiresConfirmation = false;

/**
* Executes the command and returns the result message.
*
* @param model {@code Model} which the command should operate on.
* @param model {@code Model} which the command should operate on and m
* @param confirmationReceived A {@code Boolean} indicating whether user confirmation has been provided,
* if required for executing the command.
* @return feedback message of the operation result for display
* @throws CommandException If an error occurs during command execution.
*/
public abstract CommandResult execute(Model model) throws CommandException;
public CommandResult execute(Model model, Boolean confirmationReceived) throws CommandException {
if (confirmationReceived.equals(requiresConfirmation)) {
return this.execute(model);
}
return null;
}

/**
* 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.
*/
protected abstract CommandResult execute(Model model) throws CommandException;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package seedu.address.logic.commands;

import seedu.address.model.person.Person;

/**
* Contains common values used in different command classes, including default command values.
*/
public final class CommandCommons {
public static final String DEFAULT_TIER = "";
public static final String DEFAULT_REMARK = "NA";
public static final Person EMPTY_PERSON = null;

}
35 changes: 30 additions & 5 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Objects;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.person.Person;

/**
* Represents the result of a command execution.
Expand All @@ -19,21 +20,31 @@ public class CommandResult {
/** The application should exit. */
private final boolean exit;

/** The application should show a confirmation button */
private final boolean showConfirmation;

private final boolean showPerson;
private final Person viewedPerson;

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit,
boolean showPerson, Person viewedPerson, boolean showConfirmation) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
this.showPerson = showPerson;
this.viewedPerson = viewedPerson;
this.showConfirmation = showConfirmation;
}

/**
* Constructs a {@code CommandResult} with the specified {@code feedbackToUser},
* and other fields set to their default value.
*/
public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false);
this(feedbackToUser, false, false, false, null, false);
}

public String getFeedbackToUser() {
Expand All @@ -48,26 +59,40 @@ public boolean isExit() {
return exit;
}

public boolean isShowPerson() {
return showPerson;
}

public Person getViewedPerson() {
return viewedPerson;
}

public boolean isShowConfirmation() {
return showConfirmation;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof CommandResult)) {
return false;
}

CommandResult otherCommandResult = (CommandResult) other;
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& showHelp == otherCommandResult.showHelp
&& exit == otherCommandResult.exit;
&& exit == otherCommandResult.exit
&& showConfirmation == otherCommandResult.showConfirmation
&& showPerson == otherCommandResult.showPerson
&& Objects.equals(viewedPerson, otherCommandResult.viewedPerson);
}

@Override
public int hashCode() {
return Objects.hash(feedbackToUser, showHelp, exit);
return Objects.hash(feedbackToUser, showHelp, exit, showConfirmation, showPerson, viewedPerson);
}

@Override
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class DeleteCommand extends Command {
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";
public static final String MESSAGE_DELETE_CONFIRMATION = "This will permanently delete this contact. "
+ "Are you sure you want to execute this command? (y/n)";

private static final boolean requiresConfirmation = true;


private final Index targetIndex;

Expand All @@ -45,6 +50,14 @@ public CommandResult execute(Model model) throws CommandException {
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)));
}

@Override
public CommandResult execute(Model model, Boolean confirmationReceived) throws CommandException {
if (confirmationReceived.equals(requiresConfirmation)) {
return this.execute(model);
}
return new CommandResult(MESSAGE_DELETE_CONFIRMATION, false, false, true, null, false);
}

@Override
public boolean equals(Object other) {
if (other == this) {
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);
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true, false, null, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public FilterCommand(Predicate<Person> predicate) {
}

@Override
public CommandResult execute(Model model) {
protected CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
return new CommandResult(
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandCommons.EMPTY_PERSON;

import seedu.address.model.Model;

/**
Expand All @@ -16,6 +18,6 @@ public class HelpCommand extends Command {

@Override
public CommandResult execute(Model model) {
return new CommandResult(SHOWING_HELP_MESSAGE, true, false);
return new CommandResult(SHOWING_HELP_MESSAGE, true, false, false, EMPTY_PERSON, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ListCommand extends Command {


@Override
public CommandResult execute(Model model) {
protected CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(MESSAGE_SUCCESS);
Expand Down
Loading