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

Create pop-up window for View command #55

Merged
merged 11 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Messages {
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";

public static final String MESSAGE_VIEW = "Viewing %1$s:";
public static final String MESSAGE_NO_PERSON_FOUND = "No patient with specified NRIC.";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ public class CommandResult {
/** Help information should be shown to the user. */
private final boolean showHelp;

/** View information should be shown to the user. */
private final boolean showView;

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

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

Expand All @@ -33,7 +37,7 @@ public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
* and other fields set to their default value.
*/
public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false);
this(feedbackToUser, false, false, false);
}

public String getFeedbackToUser() {
Expand All @@ -44,6 +48,10 @@ public boolean isShowHelp() {
return showHelp;
}

public boolean isShowView() {
return showView;
}

public boolean isExit() {
return exit;
}
Expand All @@ -62,19 +70,21 @@ public boolean equals(Object other) {
CommandResult otherCommandResult = (CommandResult) other;
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& showHelp == otherCommandResult.showHelp
&& showView == otherCommandResult.showView
&& exit == otherCommandResult.exit;
}

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

@Override
public String toString() {
return new ToStringBuilder(this)
.add("feedbackToUser", feedbackToUser)
.add("showHelp", showHelp)
.add("showView", showView)
.add("exit", exit)
.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, 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, true, false);
return new CommandResult(SHOWING_HELP_MESSAGE, true, false, false);
}
}
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Nric;
import seedu.address.model.person.NricMatchesPredicate;

/**
Expand Down Expand Up @@ -38,8 +39,8 @@
if (model.getFilteredPersonList().isEmpty()) {
throw new CommandException(Messages.MESSAGE_NO_PERSON_FOUND);
} else {
return new CommandResult(String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW,
model.getFilteredPersonList().size()));
Nric nric = model.getFilteredPersonList().get(0).getNric();
return new CommandResult(String.format(Messages.MESSAGE_VIEW, nric), false, true, false);

Check warning on line 43 in src/main/java/seedu/address/logic/commands/ViewCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/ViewCommand.java#L42-L43

Added lines #L42 - L43 were not covered by tests
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
private PersonListPanel personListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
private ViewWindow viewWindow;

@FXML
private StackPane commandBoxPlaceholder;
Expand Down Expand Up @@ -66,6 +67,7 @@
setAccelerators();

helpWindow = new HelpWindow();
viewWindow = null;

Check warning on line 70 in src/main/java/seedu/address/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/MainWindow.java#L70

Added line #L70 was not covered by tests
}

public Stage getPrimaryStage() {
Expand Down Expand Up @@ -151,6 +153,19 @@
primaryStage.show();
}

/**
* Opens the view window to display patient details.
*/
@FXML
public void handleView(String feedback) {
if (viewWindow != null && viewWindow.isShowing()) {
viewWindow.hide();

Check warning on line 162 in src/main/java/seedu/address/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/MainWindow.java#L162

Added line #L162 was not covered by tests
}

this.viewWindow = new ViewWindow(feedback, logic.getFilteredPersonList().get(0));
viewWindow.show();
}

Check warning on line 167 in src/main/java/seedu/address/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/MainWindow.java#L165-L167

Added lines #L165 - L167 were not covered by tests

/**
* Closes the application.
*/
Expand All @@ -159,6 +174,11 @@
GuiSettings guiSettings = new GuiSettings(primaryStage.getWidth(), primaryStage.getHeight(),
(int) primaryStage.getX(), (int) primaryStage.getY());
logic.setGuiSettings(guiSettings);

if (viewWindow != null && viewWindow.isShowing()) {
viewWindow.hide();

Check warning on line 179 in src/main/java/seedu/address/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/MainWindow.java#L179

Added line #L179 was not covered by tests
}

helpWindow.hide();
primaryStage.hide();
}
Expand All @@ -182,6 +202,10 @@
handleHelp();
}

if (commandResult.isShowView()) {
handleView(commandResult.getFeedbackToUser());

Check warning on line 206 in src/main/java/seedu/address/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/MainWindow.java#L206

Added line #L206 was not covered by tests
}

if (commandResult.isExit()) {
handleExit();
}
Expand Down
87 changes: 87 additions & 0 deletions src/main/java/seedu/address/ui/ViewWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package seedu.address.ui;

import java.util.Comparator;
import java.util.logging.Logger;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.person.Person;

/**
* Represents a view window in the user interface.
* This window is used to display detailed information about a person.
*/
public class ViewWindow extends UiPart<Stage> {
private static final String FXML = "ViewWindow.fxml";
private final Logger logger = LogsCenter.getLogger(getClass());

Check warning on line 20 in src/main/java/seedu/address/ui/ViewWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/ViewWindow.java#L20

Added line #L20 was not covered by tests

@FXML
private StackPane feedbackDisplayPlaceholder;
@FXML
private Label feedback;
@FXML
private Label name;
@FXML
private Label phone;
@FXML
private Label address;
@FXML
private Label email;
@FXML
private Label remark;
@FXML
private Label nric;
@FXML
private FlowPane tags;

private ViewWindow(Stage root, String feedbackDisplayText, Person person) {
super(FXML, root);

Check warning on line 42 in src/main/java/seedu/address/ui/ViewWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/ViewWindow.java#L42

Added line #L42 was not covered by tests

feedback.setText(feedbackDisplayText);
name.setText(person.getName().fullName);
phone.setText(person.getPhone().value);
address.setText(person.getAddress().value);
email.setText(person.getEmail().value);
remark.setText(person.getRemark().value);
nric.setText(person.getNric().value);
person.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
}

Check warning on line 54 in src/main/java/seedu/address/ui/ViewWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/ViewWindow.java#L44-L54

Added lines #L44 - L54 were not covered by tests

/**
* Creates a new ViewWindow with the given feedback display text and person.
* @param feedbackDisplayText The text to display in the feedback label.
* @param person The person whose details to display.
*/
public ViewWindow(String feedbackDisplayText, Person person) {
this(new Stage(), feedbackDisplayText, person);
}

Check warning on line 63 in src/main/java/seedu/address/ui/ViewWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/ViewWindow.java#L62-L63

Added lines #L62 - L63 were not covered by tests

/**
* Shows the view window.
*/
public void show() {
logger.fine("Showing view page on a patient.");
getRoot().show();
getRoot().centerOnScreen();
}

Check warning on line 72 in src/main/java/seedu/address/ui/ViewWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/ViewWindow.java#L69-L72

Added lines #L69 - L72 were not covered by tests

/**
* Returns true if the view window is currently being shown.
*/
public boolean isShowing() {
return getRoot().isShowing();

Check warning on line 78 in src/main/java/seedu/address/ui/ViewWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/ViewWindow.java#L78

Added line #L78 was not covered by tests
}

/**
* Hides the view window.
*/
public void hide() {
getRoot().hide();
}

Check warning on line 86 in src/main/java/seedu/address/ui/ViewWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/ViewWindow.java#L85-L86

Added lines #L85 - L86 were not covered by tests
}
47 changes: 47 additions & 0 deletions src/main/resources/view/ViewWindow.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.Scene?>
<?import javafx.stage.Stage?>
<fx:root resizable="false" title="View" type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<icons>
<Image url="@/images/address_book_32.png" />
</icons>
<scene>
<Scene>
<stylesheets>
<URL value="@DarkTheme.css" />
</stylesheets>

<VBox>
<StackPane VBox.vgrow="NEVER" styleClass="pane-with-border" fx:id="feedbackDisplayPlaceholder" alignment="CENTER_LEFT">
<padding>
<Insets top="5" right="10" bottom="5" left="10" />
</padding>
<Label fx:id="feedback" text="\$feedback" styleClass="label-header" />
</StackPane>

<VBox fx:id="personDisplay" styleClass="pane-with-border" minWidth="340" prefWidth="340" VBox.vgrow="ALWAYS">
<padding>
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<VBox>
<Label fx:id="name" styleClass="label-bright" text="\$first"/>
<FlowPane fx:id="tags" />
<Label fx:id="phone" styleClass="label-bright" text="\$phone" />
<Label fx:id="address" styleClass="label-bright" text="\$address" />
<Label fx:id="email" styleClass="label-bright" text="\$email" />
<Label fx:id="remark" styleClass="label-bright" text="\$remark" />
<Label fx:id="nric" styleClass="label-bright" text="\$nric" />
</VBox>
</VBox>
</VBox>
</Scene>
</scene>
</fx:root>
18 changes: 12 additions & 6 deletions src/test/java/seedu/address/logic/commands/CommandResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void equals() {

// same values -> returns true
assertTrue(commandResult.equals(new CommandResult("feedback")));
assertTrue(commandResult.equals(new CommandResult("feedback", false, false)));
assertTrue(commandResult.equals(new CommandResult("feedback", false, false, false)));

// same object -> returns true
assertTrue(commandResult.equals(commandResult));
Expand All @@ -29,10 +29,13 @@ public void equals() {
assertFalse(commandResult.equals(new CommandResult("different")));

// different showHelp value -> returns false
assertFalse(commandResult.equals(new CommandResult("feedback", true, false)));
assertFalse(commandResult.equals(new CommandResult("feedback", true, false, false)));

// different showView value -> returns false
assertFalse(commandResult.equals(new CommandResult("feedback", false, true, false)));

// different exit value -> returns false
assertFalse(commandResult.equals(new CommandResult("feedback", false, true)));
assertFalse(commandResult.equals(new CommandResult("feedback", false, false, true)));
}

@Test
Expand All @@ -46,18 +49,21 @@ public void hashcode() {
assertNotEquals(commandResult.hashCode(), new CommandResult("different").hashCode());

// different showHelp value -> returns different hashcode
assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", true, false).hashCode());
assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", true, false, false).hashCode());

// different showView value -> returns different hashcode
assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", false, true, false).hashCode());

// different exit value -> returns different hashcode
assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", false, true).hashCode());
assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", false, false, true).hashCode());
}

@Test
public void toStringMethod() {
CommandResult commandResult = new CommandResult("feedback");
String expected = CommandResult.class.getCanonicalName() + "{feedbackToUser="
+ commandResult.getFeedbackToUser() + ", showHelp=" + commandResult.isShowHelp()
+ ", exit=" + commandResult.isExit() + "}";
+ ", showView=" + commandResult.isShowView() + ", exit=" + commandResult.isExit() + "}";
assertEquals(expected, commandResult.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ExitCommandTest {

@Test
public void execute_exit_success() {
CommandResult expectedCommandResult = new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true);
CommandResult expectedCommandResult = new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, false, true);
assertCommandSuccess(new ExitCommand(), model, expectedCommandResult, expectedModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class HelpCommandTest {

@Test
public void execute_help_success() {
CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE, true, false);
CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE, true, false, false);
assertCommandSuccess(new HelpCommand(), model, expectedCommandResult, expectedModel);
}
}
13 changes: 0 additions & 13 deletions src/test/java/seedu/address/logic/commands/ViewCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.Messages.MESSAGE_NO_PERSON_FOUND;
import static seedu.address.logic.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -50,16 +47,6 @@ public void equals() {
assertFalse(viewFirstCommand.equals(viewSecondCommand));
}

@Test
public void execute_validNric_personFound() {
NricMatchesPredicate predicate = new NricMatchesPredicate(ALICE.getNric().value);
ViewCommand viewCommand = new ViewCommand(ALICE.getNric().value);
expectedModel.updateFilteredPersonList(predicate);

String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 1);
assertCommandSuccess(viewCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_invalidNric_noPersonFound() {
NricMatchesPredicate predicate = new NricMatchesPredicate("S0000000X");
Expand Down