Skip to content

Commit

Permalink
Merge pull request #167 from Andrew22Teoh/ImproveViewCommand
Browse files Browse the repository at this point in the history
Improved view command
  • Loading branch information
Rachael-Chan authored Nov 1, 2024
2 parents 4de1c6c + 11990be commit d647a11
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 149 deletions.
13 changes: 8 additions & 5 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SocialBook is a **desktop app for managing contacts, optimized for use via a Li

* `list` : Lists all contacts.

* `view 2` : Displays all the information on the 2nd contact shown in the current list.
* `view 2` : Toggles the view on the 2nd contact shown in the current list with more/less information.

* `add n/John Doe p/98765432 e/[email protected] a/John street, block 123, #01-01 d/06-01-2024` : Adds a contact named `John Doe` to the SocialBook.

Expand Down Expand Up @@ -109,16 +109,19 @@ Format: `list`

### Viewing a person : `view`

Pops up a window containing all the information that has been saved on this person. Also filters the current listed persons to just this specific person.
Toggles the contact card on the specified person, switching between more and less information. <br>
The default view for all contact cards will display less information to avoid visually overwhelming users, but users may decide to toggle the `view` for all information on one or more persons.

Format: `view INDEX`

* This command only allows the user to `view` one person at a time. Trying to key in more than 1 index will result in an error message.
* This command permits the user to `view` multiple contacts at once. Using the `view` command on a contact that's already expanded will collapse it back to its default view.
* Viewing is done by index, and **not** the person's name or any other field. Attempting to `view` by name, address, or any other fields will result in an error.

Examples:
* `view 1` will bring up the view window for the first person in the displayed list. <br>
![result of `view 1`](images/viewOneResult.png)
* `view 2` will expand the contact card for the second person in the contact list. <br>
![result of `view 2`](images/viewTwoResult.png)
* Using `view 2` again will collapse the contact card back down to its default view. <br>
![result of second `view 2`](images/secondViewTwoResult.png)


### Editing a person : `edit`
Expand Down
13 changes: 7 additions & 6 deletions docs/diagrams/UiClassDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Class "<<interface>>\nUi" as Ui
Class "{abstract}\nUiPart" as UiPart
Class UiManager
Class MainWindow
Class ViewWindow
Class HelpWindow
Class ResultDisplay
Class PersonListPanel
Class PersonCard
Class PersonCardFull
Class StatusBarFooter
Class CommandBox
}
Expand All @@ -36,29 +36,30 @@ MainWindow *-down-> "1" ResultDisplay
MainWindow *-down-> "1" PersonListPanel
MainWindow *-down-> "1" StatusBarFooter
MainWindow --> "0..1" HelpWindow
MainWindow --> "0..1" ViewWindow

PersonListPanel -down-> "*" PersonCard
PersonListPanel -right-> "*" PersonCard
PersonListPanel -right-> "*" PersonCardFull

MainWindow -left-|> UiPart

ResultDisplay --|> UiPart
CommandBox --|> UiPart
PersonListPanel --|> UiPart
PersonCard --|> UiPart
PersonCardFull --|> UiPart
StatusBarFooter --|> UiPart
HelpWindow --|> UiPart
ViewWindow --|> UiPart

PersonCard ..> Model
PersonCardFull ..> Model
UiManager -right-> Logic
MainWindow -left-> Logic

PersonListPanel -[hidden]left- HelpWindow
HelpWindow -[hidden]left- ViewWindow
ViewWindow -[hidden]left- CommandBox
HelpWindow -[hidden]left- CommandBox
CommandBox -[hidden]left- ResultDisplay
ResultDisplay -[hidden]left- StatusBarFooter
PersonCardFull -[hidden]down- PersonCard

MainWindow -[hidden]-|> UiPart
@enduml
Binary file added docs/images/secondViewTwoResult.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/viewOneResult.png
Binary file not shown.
Binary file added docs/images/viewTwoResult.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 31 additions & 15 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
@@ -1,59 +1,75 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Objects;
import java.util.Optional;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.ToStringBuilder;

/**
* Represents the result of a command execution.
*/
public class CommandResult {
/**
* Represents the lack of an index returned in a {@code CommandResult}.
* Declared as public so that {@code HelpCommand} and {@code ExitCommand} are able to use it.
*/
public static final Index NO_INDEX_TO_VIEW = null;

private final String feedbackToUser;

/** User wants to view all information about a contact. */
private final boolean shouldOpenView;
/**
* User wants to view all information about a particular contact.
* May or may not hold an {@code Index}, depending on whether the user has requested to view a contact.
*/
private final Optional<Index> indexToView;

/** Help information should be shown to the user. */
private final boolean showHelp;

/** The application should exit. */
private final boolean exit;
private final boolean shouldExit;

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean shouldOpenView, boolean showHelp, boolean exit) {
public CommandResult(String feedbackToUser, Index indexToView, boolean showHelp, boolean shouldExit) {
requireAllNonNull(feedbackToUser, showHelp, shouldExit);
this.feedbackToUser = requireNonNull(feedbackToUser);
this.shouldOpenView = shouldOpenView;
this.indexToView = Optional.ofNullable(indexToView);
this.showHelp = showHelp;
this.exit = exit;
this.shouldExit = shouldExit;
}

/**
* 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, false);
this(feedbackToUser, NO_INDEX_TO_VIEW, false, false);
}

public String getFeedbackToUser() {
return feedbackToUser;
}

public boolean isView() {
return shouldOpenView;
public Optional<Index> getIndexToView() {
return indexToView;
}

public boolean isViewCommand() {
return indexToView.isPresent();
}

public boolean isShowHelp() {
return showHelp;
}

public boolean isExit() {
return exit;
return shouldExit;
}

@Override
Expand All @@ -69,23 +85,23 @@ public boolean equals(Object other) {

CommandResult otherCommandResult = (CommandResult) other;
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& shouldOpenView == otherCommandResult.shouldOpenView
&& indexToView.equals(otherCommandResult.indexToView)
&& showHelp == otherCommandResult.showHelp
&& exit == otherCommandResult.exit;
&& shouldExit == otherCommandResult.shouldExit;
}

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

@Override
public String toString() {
return new ToStringBuilder(this)
.add("feedbackToUser", feedbackToUser)
.add("shouldView", shouldOpenView)
.add("indexToView", indexToView)
.add("showHelp", showHelp)
.add("exit", exit)
.add("shouldExit", shouldExit)
.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, false, true);
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, CommandResult.NO_INDEX_TO_VIEW, false, true);
}

}
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, false, true, false);
return new CommandResult(SHOWING_HELP_MESSAGE, CommandResult.NO_INDEX_TO_VIEW, true, false);
}
}
20 changes: 11 additions & 9 deletions src/main/java/seedu/address/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@
import seedu.address.model.person.Person;

/**
* Shows the full view for a person with all of their information.
* Toggles the card status of a person to either show all of their information,
* or only an abridged version of it.
*/
public class ViewCommand extends Command {

public static final String COMMAND_WORD = "view";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Shows all information about the person identified by the index number in the displayed person list.\n"
+ ": Toggles the amount of information shown about the person "
+ "identified by the index number in the displayed person list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_VIEW_SUCCESS = "Showing information for %1$s.";
public static final String MESSAGE_VIEW_SUCCESS = "Toggling the view of %1$s.";

private final Index index;

/**
* Creates a ViewCommand to view all information on a specified {@code Person}.
* Creates a ViewCommand to toggle the view on a specified {@code Person}.
*/
public ViewCommand(Index index) {
requireAllNonNull(index);
Expand All @@ -37,8 +39,10 @@ public ViewCommand(Index index) {
}

/**
* Filters the displayed {@code ObservableList} in the {@code Model} to just the selected index.
* Returns a {@code CommandResult} that indicates the user has requested to View a person.
* Checks that the selected index is valid and within
* the range of the {@code ObservableList} in the {@code Model}.
* Returns a {@code CommandResult} that indicates the user
* has requested to toggle the view of a person at the given {@code Index}.
*/
@Override
public CommandResult execute(Model model) throws CommandException {
Expand All @@ -50,11 +54,9 @@ public CommandResult execute(Model model) throws CommandException {
}

Person personToView = lastShownList.get(index.getZeroBased());
model.updateFilteredPersonList(person -> person.isSamePerson(personToView));

String commandResultMessage = String.format(MESSAGE_VIEW_SUCCESS, Messages.format(personToView));

return new CommandResult(commandResultMessage, true, false, false);
return new CommandResult(commandResultMessage, index, false, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new ViewCommand object
* Parses input arguments and creates a new ViewCommand object.
*/
public class ViewCommandParser implements Parser<ViewCommand> {
private static final String WHITESPACE_SPLIT = "\\s+";
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.ui;

import java.util.Optional;
import java.util.logging.Logger;

import javafx.event.ActionEvent;
Expand All @@ -12,6 +13,7 @@
import javafx.stage.Stage;
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.Logic;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
Expand All @@ -34,7 +36,6 @@ public class MainWindow extends UiPart<Stage> {
private PersonListPanel personListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
private ViewWindow viewWindow;

@FXML
private StackPane commandBoxPlaceholder;
Expand Down Expand Up @@ -67,7 +68,6 @@ public MainWindow(Stage primaryStage, Logic logic) {
setAccelerators();

helpWindow = new HelpWindow();
viewWindow = new ViewWindow();
}

public Stage getPrimaryStage() {
Expand Down Expand Up @@ -138,16 +138,15 @@ private void setWindowDefaultSize(GuiSettings guiSettings) {
}

/**
* Opens the view window or focuses on it if it's already opened.
* Updates the displayed person list for the user.
*/
@FXML
public void handleView() {
viewWindow.view(logic.getFilteredPersonList());
if (!viewWindow.isShowing()) {
viewWindow.show();
} else {
viewWindow.focus();
}
public void handleView(Optional<Index> indexToView) {
assert indexToView.isPresent() : "This method should not be called if indexToView is empty";

personListPanelPlaceholder.getChildren().clear();
personListPanel.updateViewedPersons(indexToView);
personListPanelPlaceholder.getChildren().add(personListPanel.getRoot());
}

/**
Expand All @@ -174,7 +173,6 @@ private void handleExit() {
GuiSettings guiSettings = new GuiSettings(primaryStage.getWidth(), primaryStage.getHeight(),
(int) primaryStage.getX(), (int) primaryStage.getY());
logic.setGuiSettings(guiSettings);
viewWindow.hide();
helpWindow.hide();
primaryStage.hide();
}
Expand All @@ -194,8 +192,8 @@ private CommandResult executeCommand(String commandText) throws CommandException
logger.info("Result: " + commandResult.getFeedbackToUser());
resultDisplay.setSuccessFeedbackToUser(commandResult.getFeedbackToUser());

if (commandResult.isView()) {
handleView();
if (commandResult.isViewCommand()) {
handleView(commandResult.getIndexToView());
}

if (commandResult.isShowHelp()) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import seedu.address.model.person.Person;

/**
* An UI component that displays information of a {@code Person}.
* A UI component that displays some information about a {@code Person}.
*/
public class PersonCard extends UiPart<Region> {

Expand Down Expand Up @@ -41,7 +41,7 @@ public class PersonCard extends UiPart<Region> {
private Label dateOfLastVisit;

/**
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
* Creates a {@code PersonCard} with the given {@code Person} and index to display.
*/
public PersonCard(Person person, int displayedIndex) {
super(FXML);
Expand Down Expand Up @@ -75,7 +75,7 @@ private void setTagsFlowpane(Person personToView) {
}

private void setPhoneLabel(Person personToView) {
phone.setText("Phone number: " + personToView.getPhone().value);
phone.setText("Phone Number: " + personToView.getPhone().value);
}

private void setNameLabel(Person personToView) {
Expand Down
Loading

0 comments on commit d647a11

Please sign in to comment.