Skip to content

Commit

Permalink
Merge pull request #4 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 11, 2019
2 parents 6881ba8 + 5c489d2 commit 3f43fff
Show file tree
Hide file tree
Showing 21 changed files with 503 additions and 24 deletions.
Binary file modified docs/images/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public LogicManager(Model model, Storage storage) {
public CommandResult execute(String commandText) throws CommandException, ParseException {
logger.info("----------------[USER COMMAND][" + commandText + "]");

String aliasedCommandText = model.getUserPrefs().getAliasTable().applyAlias(commandText);

CommandResult commandResult;
Command command = addressBookParser.parseCommand(commandText);
Command command = addressBookParser.parseCommand(aliasedCommandText);
commandResult = command.execute(model);

try {
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/seedu/address/logic/commands/AliasCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ALIAS_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ALIAS_VALUE;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;

/**
* Defines an alias.
*/
public class AliasCommand extends Command {

public static final String COMMAND_WORD = "alias";

public static final String MESSAGE_SUCCESS = "Alias added: %1$s -> %2$s";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": defines an alias. "
+ "Parameters: "
+ PREFIX_ALIAS_NAME + "ALIAS_NAME "
+ PREFIX_ALIAS_VALUE + "ALIAS_VALUE "
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_ALIAS_NAME + "h "
+ PREFIX_ALIAS_VALUE + "help";

private final String alias;
private final String aliasTo;

/**
* Creates an AliasCommand to define an alias.
*/
public AliasCommand(String alias, String aliasTo) {
requireNonNull(alias);
requireNonNull(aliasTo);
this.alias = alias.trim();
this.aliasTo = aliasTo.trim();
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

model.getUserPrefs().getAliasTable().addAlias(alias, aliasTo);
return new CommandResult(String.format(MESSAGE_SUCCESS, alias, aliasTo));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public CommandResult(String feedbackToUser, boolean showHelp, boolean addVisit,
this.addVisit = addVisit;
this.deleteVisit = deleteVisit;
this.exit = exit;
}

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

public CommandResult(String feedbackToUser, int idx, String date) {
Expand All @@ -62,7 +66,8 @@ 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);
}

public String getFeedbackToUser() {
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/seedu/address/logic/commands/ProfileCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* Changes the visitList of an existing person in the address book.
*/
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"
+ "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";

private final Index index;

/**
* @param index of the person in the last listing whose profile is to be viewed
*/
public ProfileCommand(Index index) {
requireAllNonNull(index);

this.index = index;
}

@Override
public CommandResult execute(Model model) throws CommandException {
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);

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


@Override
public boolean equals(Object other) {
// short circuit if same object
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof ProfileCommand)) {
return false;
}

// state check
ProfileCommand e = (ProfileCommand) other;
return index.equals(e.index);
}
}
51 changes: 51 additions & 0 deletions src/main/java/seedu/address/logic/commands/ReminderCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAYS;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.Reminder;

/**
* Adds a reminder to VISIT.
*/
public class ReminderCommand extends Command {

public static final String COMMAND_WORD = "reminder";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Creates a new reminder to show up when the program is launched. "
+ "Parameters: "
+ "[" + PREFIX_DAYS + "EXPIRY IN DAYS]...\n"
+ "Example: " + COMMAND_WORD + " "
+ "Two Point Hospital closed "
+ PREFIX_DAYS + "7";

public static final String MESSAGE_SUCCESS = "New reminder added: %s";

private final Reminder toAdd;

/**
* Creates an ReminderCommand to add the specified {@code Reminder}
*/
public ReminderCommand(Reminder reminder) {
requireNonNull(reminder);
toAdd = reminder;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

model.addReminder(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd.getDescription()));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof ReminderCommand // instanceof handles nulls
&& toAdd.equals(((ReminderCommand) other).toAdd));
}
}
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddVisitCommand;
import seedu.address.logic.commands.AliasCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteCommand;
Expand All @@ -17,6 +18,8 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.ProfileCommand;
import seedu.address.logic.commands.ReminderCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -47,6 +50,9 @@ public Command parseCommand(String userInput) throws ParseException {

switch (commandWord) {

case AliasCommand.COMMAND_WORD:
return new AliasCommandParser().parse(arguments);

case AddCommand.COMMAND_WORD:
return new AddCommandParser().parse(arguments);

Expand All @@ -72,6 +78,12 @@ public Command parseCommand(String userInput) throws ParseException {
System.out.println(commandWord);
return new DeleteVisitCommandParser().parse(arguments);

case ProfileCommand.COMMAND_WORD:
return new ProfileCommandParser().parse(arguments);

case ReminderCommand.COMMAND_WORD:
return new ReminderCommandParser().parse(arguments);

case ExitCommand.COMMAND_WORD:
return new ExitCommand();

Expand Down
44 changes: 44 additions & 0 deletions src/main/java/seedu/address/logic/parser/AliasCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ALIAS_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ALIAS_VALUE;

import java.util.stream.Stream;

import seedu.address.logic.commands.AliasCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new AliasCommand object
*/
public class AliasCommandParser implements Parser<AliasCommand> {

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

if (!arePrefixesPresent(argMultimap, PREFIX_ALIAS_NAME, PREFIX_ALIAS_VALUE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AliasCommand.MESSAGE_USAGE));
}

String name = argMultimap.getValue(PREFIX_ALIAS_NAME).get();
String value = argMultimap.getValue(PREFIX_ALIAS_VALUE).get();

return new AliasCommand(name, value);
}

/**
* Returns true if none of the prefixes contains empty {@code Optional} values in the given
* {@code ArgumentMultimap}.
*/
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}
}
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

public static final Prefix PREFIX_ALIAS_NAME = new Prefix("l/");
public static final Prefix PREFIX_ALIAS_VALUE = new Prefix("v/");

public static final Prefix PREFIX_VISIT = new Prefix("v/");
public static final Prefix PREFIX_DELETE_VISIT = new Prefix("d/");
public static final Prefix PREFIX_DAYS = new Prefix("d/");


}
33 changes: 33 additions & 0 deletions src/main/java/seedu/address/logic/parser/ProfileCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

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

/**
* Parses input arguments and creates a new {@code RemarkCommand} object
*/
public class ProfileCommandParser implements Parser<ProfileCommand> {
/**
* Parses the given {@code String} of arguments in the context of the {@code RemarkCommand}
* and returns a {@code RemarkCommand} object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public ProfileCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args);

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

return new ProfileCommand(index);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAYS;

import seedu.address.logic.commands.ReminderCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Reminder;

/**
* Parses input arguments and creates a new {@code RemindCommand} object
*/
public class ReminderCommandParser implements Parser<ReminderCommand> {
/**
* Parses the given {@code String} of arguments in the context of the {@code RemindCommand}
* and returns a {@code RemindCommand} object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public ReminderCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DAYS);

String description;
int days;
try {
description = argMultimap.getPreamble();
days = Integer.parseInt(argMultimap.getValue(PREFIX_DAYS).orElse("1"));
} catch (Exception ex) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReminderCommand.MESSAGE_USAGE), ex);
}

return new ReminderCommand(new Reminder(description, days));
}
}
Loading

0 comments on commit 3f43fff

Please sign in to comment.