forked from AY2425S1-CS2103T-T11-2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into branch-updateUserGuide
- Loading branch information
Showing
14 changed files
with
547 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/java/seedu/address/logic/commands/RemoveGradeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_ASSIGNMENT_NAME; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ASSIGNMENT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.ParserUtil.parseName; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.assignment.Assignment; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.Github; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.person.Telegram; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Remove assignment grades from an existing person in the address book. | ||
*/ | ||
public class RemoveGradeCommand extends Command { | ||
public static final String COMMAND_WORD = "removeGrade"; | ||
public static final String MESSAGE_USAGE = | ||
COMMAND_WORD | ||
+ ": Removes a grade of an assignment from the person.\n" | ||
+ "Parameters: " | ||
+ PREFIX_NAME | ||
+ "NAME " | ||
+ PREFIX_ASSIGNMENT | ||
+ "ASSIGNMENT\n" | ||
+ "Example: " | ||
+ COMMAND_WORD | ||
+ " " | ||
+ PREFIX_NAME | ||
+ "John Doe " | ||
+ PREFIX_ASSIGNMENT | ||
+ "Ex09"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Assignment %1$s removed from %2$s"; | ||
public static final String MESSAGE_FAILURE = "Assignment %s does not exist for %s."; | ||
private final Name personName; | ||
private final String assignmentName; | ||
|
||
/** | ||
* @param personName Name of the person. | ||
* @param assignmentName Name of assignment. | ||
*/ | ||
public RemoveGradeCommand(String personName, String assignmentName) throws ParseException { | ||
requireAllNonNull(personName, assignmentName); | ||
this.personName = parseName(personName); | ||
this.assignmentName = assignmentName; | ||
} | ||
|
||
|
||
static Person createPersonWithRemovedGrade(Person person, String assignmentName) { | ||
assert person != null; | ||
Name name = person.getName(); | ||
Phone phone = person.getPhone(); | ||
Email email = person.getEmail(); | ||
Set<Tag> tags = person.getTags(); | ||
Telegram telegram = person.getTelegram(); | ||
Github github = person.getGithub(); | ||
Set<Integer> weeksAttended = person.getWeeksPresent(); | ||
|
||
Map<String, Assignment> assignment = person.getAssignment(); | ||
assignment.remove(assignmentName); | ||
|
||
return new Person(name, phone, email, telegram, github, assignment, weeksAttended, tags); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
// check if assignment is in predefined list | ||
if (!model.hasAssignment(assignmentName)) { | ||
throw new CommandException(String.format(MESSAGE_INVALID_ASSIGNMENT_NAME, assignmentName)); | ||
} | ||
|
||
Person person = model.getPerson(personName) | ||
.orElseThrow(() -> | ||
new CommandException(MESSAGE_INVALID_PERSON_DISPLAYED_NAME)); | ||
|
||
// Check if the assignment is already missing from the person's record | ||
if (!person.getAssignment().containsKey(assignmentName)) { | ||
throw new CommandException( | ||
String.format(MESSAGE_FAILURE, assignmentName, personName)); | ||
} | ||
|
||
model.setPerson(person, createPersonWithRemovedGrade(person, model.getAssignmentName(assignmentName))); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, assignmentName, personName)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return personName + " " + assignmentName; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other instanceof RemoveGradeCommand otherCommand) { | ||
return Objects.equals(otherCommand.personName, personName) | ||
&& Objects.equals(otherCommand.assignmentName, assignmentName); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/seedu/address/logic/parser/RemoveGradeCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ASSIGNMENT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.RemoveGradeCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new RemoveGradeCommand object | ||
*/ | ||
public class RemoveGradeCommandParser implements Parser<RemoveGradeCommand> { | ||
|
||
@Override | ||
public RemoveGradeCommand parse(String args) throws ParseException { | ||
if (args.isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemoveGradeCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_ASSIGNMENT); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ASSIGNMENT) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemoveGradeCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
String name = argMultimap.getValue(PREFIX_NAME).orElse("").trim(); | ||
if (name.isEmpty()) { | ||
throw new ParseException("Name cannot be empty."); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_ASSIGNMENT); | ||
|
||
String assignmentName = argMultimap.getValue(PREFIX_ASSIGNMENT).orElse("").trim(); | ||
if (assignmentName.isEmpty()) { | ||
throw new ParseException("Assignment name cannot be empty."); | ||
} | ||
|
||
return new RemoveGradeCommand(name, assignmentName); | ||
} | ||
|
||
/** | ||
* 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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package seedu.address.ui; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.Label; | ||
|
||
/** | ||
* A UI component that displays information of a command and its use case in the {@code HelpWindow}. | ||
*/ | ||
public class CommandDetailCard extends UiPart<Node> { | ||
private static final String FXML = "CommandDetailCard.fxml"; | ||
|
||
@FXML | ||
private Label command; | ||
@FXML | ||
private Label commandDetails; | ||
|
||
/** | ||
* Creates a {@code CommandDetailCard} with the given command word and command details of the {@code Command}. | ||
* | ||
* @param commandWord command word used to call the command. | ||
* @param commandDetails details of how to use the command. | ||
*/ | ||
public CommandDetailCard(String commandWord, String commandDetails) { | ||
super(FXML); | ||
this.command.setText(commandWord); | ||
this.commandDetails.setText(commandDetails); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#commandDetailCard { | ||
-fx-background-color: derive(#1d1d1d, 25%); | ||
} | ||
|
||
#command { | ||
-fx-font-family: "Segoe UI Semibold"; | ||
-fx-text-fill: white; | ||
-fx-font-size: 16px; | ||
-fx-padding: 10 0 5 0 | ||
} | ||
|
||
#commandDetails { | ||
-fx-text-fill: white; | ||
} | ||
|
||
#separator { | ||
-fx-border-color: derive(#1d1d1d, 25%); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import java.lang.*?> | ||
<?import java.util.*?> | ||
<?import javafx.scene.*?> | ||
<?import javafx.scene.control.*?> | ||
<?import javafx.scene.layout.*?> | ||
<?import javafx.geometry.Insets?> | ||
|
||
|
||
<?import java.net.URL?> | ||
|
||
<VBox fx:id="commandDetailCard" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"> | ||
<stylesheets> | ||
<URL value="@CommandDetailCard.css" /> | ||
</stylesheets> | ||
|
||
<padding> | ||
<Insets top="5" right="5" bottom="5" left="15" /> | ||
</padding> | ||
|
||
<Label fx:id="command" styleClass="cell_small_label" text="\$command" /> | ||
<Label fx:id="commandDetails" styleClass="cell_small_label" text="\$commandDetails" /> | ||
|
||
</VBox> |
Oops, something went wrong.