Skip to content

Commit

Permalink
Merge pull request #6 from AY1920S1-CS2103T-F12-2/master
Browse files Browse the repository at this point in the history
chore: sync with team repo
  • Loading branch information
Q-gabe authored Oct 16, 2019
2 parents cb9c0ea + 0d2c483 commit b906a10
Show file tree
Hide file tree
Showing 21 changed files with 598 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class GuiSettings implements Serializable {

private static final double DEFAULT_HEIGHT = 600;
private static final double DEFAULT_WIDTH = 740;
private static final double DEFAULT_WIDTH = 700;

private final double windowWidth;
private final double windowHeight;
Expand Down
37 changes: 28 additions & 9 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 javafx.collections.ObservableList;
import seedu.address.model.person.Person;
import seedu.address.model.person.VisitReport;

/**
Expand All @@ -20,6 +21,8 @@ public class CommandResult {

private ObservableList<VisitReport> reports;

private Person profilePerson;

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

Expand All @@ -29,35 +32,43 @@ public class CommandResult {
/** The application should addVisit. */
private final boolean deleteVisit;

/** The application should show the Profile */
private final boolean profile;

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



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

public CommandResult(String feedbackToUser, int idx) {
this(feedbackToUser, false, false, false, false);
this(feedbackToUser, false, false, false, false, false);
this.index = idx;
}

public CommandResult(String feedbackToUser, Person profilePerson) {
this(feedbackToUser, false, false, false, true, false);
this.profilePerson = profilePerson;
}

public CommandResult(String feedbackToUser, int idx, String date) {
this(feedbackToUser, false, true, false, false);
this(feedbackToUser, false, true, false, false, false);
this.index = idx;
this.date = date;
}

public CommandResult(String feedbackToUser, ObservableList<VisitReport> lst) {
this(feedbackToUser, false, false, true, false);
this(feedbackToUser, false, false, true, false, false);
this.reports = lst;
}

Expand All @@ -66,8 +77,7 @@ public CommandResult(String feedbackToUser, ObservableList<VisitReport> lst) {
* and other fields set to their default value.
*/
public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false, false,
false);
this(feedbackToUser, false, false, false, false, false);
}

public String getFeedbackToUser() {
Expand Down Expand Up @@ -102,6 +112,14 @@ public boolean isDeleteVisit() {
return deleteVisit;
}

public boolean isShowProfile() {
return profile;
}

public Person getProfilePerson() {
return profilePerson;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -117,12 +135,13 @@ public boolean equals(Object other) {
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& showHelp == otherCommandResult.showHelp
&& addVisit == otherCommandResult.addVisit
&& profile == otherCommandResult.profile
&& exit == otherCommandResult.exit;
}

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


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, false, true);
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, false, 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, false, false);
return new CommandResult(SHOWING_HELP_MESSAGE, true, false, false, false, false);
}
}
16 changes: 7 additions & 9 deletions src/main/java/seedu/address/logic/commands/ProfileCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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;

Expand All @@ -17,14 +16,12 @@
public class ProfileCommand extends Command {
public static final String COMMAND_WORD = "profile";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Opens the detailed profile of the patient identified"
+ "by the index number used in the last person listing. "
+ "The profile can be generated into a log file subsequently.\n"
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Opens the detailed profile of the patient identified "
+ "by the index number used in the last person listing.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "Example: " + COMMAND_WORD + " 1 ";

// public static final String MESSAGE_VIEW_PROFILE_SUCCESS = "Generated profile view of : %1$s";
public static final String MESSAGE_VIEW_PROFILE_SUCCESS = "Profile Command Recognized! Target: %1$s";
public static final String MESSAGE_VIEW_PROFILE_SUCCESS = "Generated profile view of : %1$s";

private final Index index;

Expand All @@ -39,16 +36,17 @@ public ProfileCommand(Index index) {

@Override
public CommandResult execute(Model model) throws CommandException {
// Get person list based on existing filter
List<Person> lastShownList = model.getFilteredPersonList();

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

Person personToEdit = lastShownList.get(index.getZeroBased());
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
// Extract the person from list
Person personProfileToShow = lastShownList.get(index.getZeroBased());

return new CommandResult(String.format(MESSAGE_VIEW_PROFILE_SUCCESS, personToEdit), index.getOneBased());
return new CommandResult(String.format(MESSAGE_VIEW_PROFILE_SUCCESS, personProfileToShow), personProfileToShow);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_VISIT;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.commands.AddVisitCommand;
Expand All @@ -23,16 +26,16 @@ public AddVisitCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_VISIT);

Index index;
String report;
String date;
try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
report = argMultimap.getValue(PREFIX_VISIT).orElse("");
// Take date from '/v' prefix or use current timing for report date.
date = ParserUtil.parseVisitReport(argMultimap.getValue(PREFIX_VISIT)
.orElse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))));
} catch (IllegalValueException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddVisitCommand.MESSAGE_USAGE), ive);
}

//String date = argMultimap.getValue(PREFIX_VISIT).orElse("");

return new AddVisitCommand(index, report);
return new AddVisitCommand(index, date);
}
}
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.VisitReport;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -122,4 +123,15 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
return tagSet;
}

/**
* @throws ParseException if the given {@code date} is invalid.
*/
public static String parseVisitReport(String date) throws ParseException {
requireNonNull(date);
String trimmedDate = date.trim();
if (!VisitReport.isValidVisitDate(trimmedDate)) {
throw new ParseException(VisitReport.MESSAGE_CONSTRAINTS);
}
return trimmedDate;
}
}
18 changes: 15 additions & 3 deletions src/main/java/seedu/address/model/person/VisitReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import static java.util.Objects.requireNonNull;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
import java.util.Objects;


Expand All @@ -11,7 +15,6 @@
public class VisitReport {

public static final String MESSAGE_CONSTRAINTS = "Visit date should follow dd/mm/yyyy format";
public static final String VALIDATION_REGEX = "^(3[01]|[12][0-9]|0[1-9])/(1[0-2]|0[1-9])/[0-9]{4}$";

public final String date;

Expand Down Expand Up @@ -48,10 +51,19 @@ public String toString() {
}

/**
* Returns true if a given string is a valid tag name.
* Returns true if a given string is a valid date.
*/
public static boolean isValidVisitDate(String test) {
return test.matches(VALIDATION_REGEX);

//make sure month and day are valid and year is 2xxx
DateTimeFormatter dateFormatter =
DateTimeFormatter.ofPattern("dd/MM/2uuu").withResolverStyle(ResolverStyle.STRICT);
try {
LocalDate.parse(test, dateFormatter);
} catch (DateTimeParseException e) {
return false;
}
return true;
}

@Override
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class MainWindow extends UiPart<Stage> {
private HelpWindow helpWindow;
private VisitRecordWindow visitWindow;
private VisitListPanel visitListPanel;
private ProfilePanel profilePanel;

@FXML
private StackPane commandBoxPlaceholder;
Expand Down Expand Up @@ -67,6 +68,7 @@ public MainWindow(Stage primaryStage, Logic logic) {
helpWindow = new HelpWindow();
visitWindow = new VisitRecordWindow();
visitListPanel = new VisitListPanel();
profilePanel = new ProfilePanel();
}

public Stage getPrimaryStage() {
Expand Down Expand Up @@ -160,9 +162,23 @@ private void handleExit() {
helpWindow.hide();
visitWindow.hide();
visitListPanel.hide();
profilePanel.hide();
primaryStage.hide();
}


/**
* Opens the profile panel or focuses on it if it's already opened.
*/
@FXML
public void handleProfilePanel() {
if (!profilePanel.isShowing()) {
profilePanel.show();
} else {
profilePanel.focus();
}
}

/**
* Opens the visit form or focuses on it if it's already opened.
*/
Expand Down Expand Up @@ -216,6 +232,11 @@ private CommandResult executeCommand(String commandText) throws CommandException
handleDeleteVisit();
}

if (commandResult.isShowProfile()) {
profilePanel.setup(commandResult.getProfilePerson());
handleProfilePanel();
}

if (commandResult.isExit()) {
handleExit();
}
Expand Down
Loading

0 comments on commit b906a10

Please sign in to comment.