Skip to content

Commit

Permalink
Add view command
Browse files Browse the repository at this point in the history
Added new panel as well as view command to allow full view of remark
  • Loading branch information
sk2001git committed Oct 15, 2023
1 parent ae37f7b commit 6b908de
Show file tree
Hide file tree
Showing 20 changed files with 345 additions and 20 deletions.
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -47,4 +48,10 @@ public interface Logic {
* Set the user prefs' GUI settings.
*/
void setGuiSettings(GuiSettings guiSettings);

/**
* Returns the last viewed person index.
*/
Index getLastViewedPersonIndex();

}
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
Expand All @@ -27,6 +28,7 @@ public class LogicManager implements Logic {
public static final String FILE_OPS_PERMISSION_ERROR_FORMAT =
"Could not save data to file %s due to insufficient permissions to write to the file or the folder.";


private final Logger logger = LogsCenter.getLogger(LogicManager.class);

private final Model model;
Expand Down Expand Up @@ -71,6 +73,11 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public Index getLastViewedPersonIndex() {
return model.getLastViewedPersonIndex();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand All @@ -85,4 +92,6 @@ public GuiSettings getGuiSettings() {
public void setGuiSettings(GuiSettings guiSettings) {
model.setGuiSettings(guiSettings);
}


}
31 changes: 27 additions & 4 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,36 @@ public class CommandResult {
/** The application should exit. */
private final boolean exit;

private final boolean isView;

/**
* 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 isView) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
this.isView = isView;
}

/**
* 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);
}

/**
* Constructs a {@code CommandResult} with the specified fields.
* @param feedbackToUser feedback to user
* @param isView whether to show the view
*/
public CommandResult(String feedbackToUser, boolean isView) {
this(feedbackToUser, false, false, isView);
}


public String getFeedbackToUser() {
return feedbackToUser;
}
Expand All @@ -48,6 +61,14 @@ public boolean isExit() {
return exit;
}

/**
* Returns true if the command result is to show the view.
* @return true if the command result is to show the view
*/
public boolean isView() {
return isView;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -62,12 +83,13 @@ public boolean equals(Object other) {
CommandResult otherCommandResult = (CommandResult) other;
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& showHelp == otherCommandResult.showHelp
&& exit == otherCommandResult.exit;
&& exit == otherCommandResult.exit
&& isView == otherCommandResult.isView;
}

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

@Override
Expand All @@ -76,6 +98,7 @@ public String toString() {
.add("feedbackToUser", feedbackToUser)
.add("showHelp", showHelp)
.add("exit", exit)
.add("isView", isView)
.toString();
}

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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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);
}
}
73 changes: 73 additions & 0 deletions src/main/java/seedu/address/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package seedu.address.logic.commands;

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.List;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
public class ViewCommand extends Command {
public static final String COMMAND_WORD = "view";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Views the details of the person identified "
+ "by the index number used in the last person listing. \n"
+ "Parameters: INDEX (must be a positive integer) \n"
+ "Example: " + COMMAND_WORD + " 1 ";

public static final String MESSAGE_ARGUMENTS = "Index: %1$d";
public static final String MESSAGE_SUCCESSFUL_VIEW = "Full-view shown for Person: %1$s";

private final Index index;

/**
*
* @param index of the person in the filtered person list to view
*/
public ViewCommand(Index index) {
requireAllNonNull(index);
this.index = index;
}

@Override
public CommandResult execute(Model model) throws CommandException {
List<Person> lastShownList = model.getFilteredPersonList();
model.setLastViewedPersonIndex(index);

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToView = lastShownList.get(index.getZeroBased());
return new CommandResult(generateSuccessMessage(personToView), true);
}

/**
* Generates a command execution success message for viewing {@code personToView}.
*/
private String generateSuccessMessage(Person personToView) {
return String.format(MESSAGE_SUCCESSFUL_VIEW, Messages.format(personToView));
}

private void updateUI() {

}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
// instanceof handles nulls
if (!(other instanceof ViewCommand)) {
return false;
}

ViewCommand v = (ViewCommand) other;
return index.equals(v.index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.commands.ViewCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -81,6 +82,9 @@ public Command parseCommand(String userInput) throws ParseException {
case RemarkCommand.COMMAND_WORD:
return new RemarkCommandParser().parse(arguments);

case ViewCommand.COMMAND_WORD:
return new ViewCommandParser().parse(arguments);

default:
logger.finer("This user input caused a ParseException: " + userInput);
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class CliSyntax {
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");

public static final Prefix PREFIX_REMARK = new Prefix("r/");

public static final Prefix PREFIX_VIEW = new Prefix("v/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_SORT = new Prefix("so/");
public static final Prefix PREFIX_STATUS = new Prefix("st/");
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/seedu/address/logic/parser/ViewCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_VIEW;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.commands.ViewCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new {@code ViewCommand} object
*
*/
public class ViewCommandParser implements Parser<ViewCommand> {

/**
* Parses the given {@code String} of arguments in the context of the {@code ViewCommand}
* and returns a {@code ViewCommand} object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public ViewCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_VIEW);

Index index;
try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
} catch (IllegalValueException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE), ive);
}

return new ViewCommand(index);
}
}
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.index.Index;
import seedu.address.model.person.Person;

/**
Expand Down Expand Up @@ -94,4 +95,15 @@ public interface Model {
*/
void updateFilteredPersonList(Predicate<Person> predicate1, Predicate<Person> predicate2);


/**
* Returns the Index of the last view command called.
*/
Index getLastViewedPersonIndex();

/**
* Sets the Index of the last view command called.
*/
void setLastViewedPersonIndex(Index index);

}
17 changes: 17 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javafx.collections.transformation.FilteredList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.core.index.Index;
import seedu.address.model.person.Person;

/**
Expand All @@ -26,6 +27,9 @@ public class ModelManager implements Model {
private final UserPrefs userPrefs;
private final FilteredList<Person> filteredPersons;

private Index lastViewedPersonIndex;


/**
* Initializes a ModelManager with the given addressBook and userPrefs.
*/
Expand Down Expand Up @@ -151,6 +155,19 @@ public void updateFilteredPersonList(Predicate<Person> predicate1, Predicate<Per
filteredPersons.setPredicate(person -> predicate1.test(person) && predicate2.test(person));
}

@Override
public void setLastViewedPersonIndex(Index index) {
requireNonNull(index);
lastViewedPersonIndex = index;
}

@Override
public Index getLastViewedPersonIndex() {
return lastViewedPersonIndex;
}



@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down
Loading

0 comments on commit 6b908de

Please sign in to comment.