Skip to content

Commit

Permalink
Fix merge commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ZShunRen committed Oct 23, 2024
2 parents 676432b + ded5748 commit 2e19462
Show file tree
Hide file tree
Showing 36 changed files with 1,558 additions and 396 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ dependencies {
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.0'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'

implementation 'org.kordamp.ikonli:ikonli-core:12.3.0'
implementation group: 'org.kordamp.ikonli', name: 'ikonli-fontawesome5-pack', version: '12.3.1'
implementation 'org.kordamp.ikonli:ikonli-javafx:12.3.1'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
}
Expand Down
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 @@ -22,6 +22,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 @@ -60,7 +60,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,11 +1,14 @@
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 String DEFAULT_STATUS = "NONE";
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

0 comments on commit 2e19462

Please sign in to comment.