Skip to content

Commit

Permalink
Merge pull request #82 from althea28/Add-Assignment-Command-UI
Browse files Browse the repository at this point in the history
Update details panel UI
  • Loading branch information
althea28 authored Oct 15, 2024
2 parents 5fdf8b7 + b5cd555 commit 429e68c
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public class AddAssignmentCommand extends Command {
public static final String COMMAND_WORD = "add_assignment";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an Assignment to the app. "
+ "Parameters: "
+ "\nParameters: "
+ PREFIX_STUDENT_INDEX + "STUDENT INDEX "
+ PREFIX_ASSIGNMENT_NAME + "ASSIGNMENT NAME "
+ PREFIX_ASSIGNMENT_MAX_SCORE + "MAX SCORE "
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_STUDENT_INDEX + "1"
+ PREFIX_ASSIGNMENT_NAME + "Assignment 1"
+ "\nExample: " + COMMAND_WORD + " "
+ PREFIX_STUDENT_INDEX + "1 "
+ PREFIX_ASSIGNMENT_NAME + "Assignment 1 "
+ PREFIX_ASSIGNMENT_MAX_SCORE + "100";
public static final String MESSAGE_SUCCESS = "New assignment added: %1$s";
public static final String MESSAGE_DUPLICATE_ASSIGNMENT = "This assignment already exists in the address book";
Expand Down Expand Up @@ -62,7 +62,8 @@ public CommandResult execute(Model model) throws CommandException {
}
Student editedStudent = studentToAddAssignmentTo.addAssignment(toAdd);
model.setStudent(studentToAddAssignmentTo, editedStudent);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)),
editedStudent, index.getZeroBased());
}

@Override
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.commons.util.ToStringBuilder;
Expand All @@ -32,9 +30,7 @@ public class AddCommand extends Command {
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney"
+ PREFIX_SUBJECT + "MATH"
+ PREFIX_GRADE + "P6";
+ PREFIX_TAG + "owesMoney";

public static final String MESSAGE_SUCCESS = "New student added: %1$s";
public static final String MESSAGE_DUPLICATE_STUDENT = "This student already exists in the address book";
Expand All @@ -58,7 +54,8 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addStudent(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)),
false, false, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class ClearCommand extends Command {
public CommandResult execute(Model model) {
requireNonNull(model);
model.setAddressBook(new AddressBook());
return new CommandResult(MESSAGE_SUCCESS);
return new CommandResult(MESSAGE_SUCCESS, false, false, true);
}
}
21 changes: 18 additions & 3 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CommandResult {

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

private final Student student;

Expand All @@ -27,24 +28,34 @@ public class CommandResult {
/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, Student student, int index) {
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit,
boolean clear, Student student, int index) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.clear = clear;
this.exit = exit;
this.student = student;
this.studentIndex = index;
}

public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
this(feedbackToUser, showHelp, exit, null, -1);
this(feedbackToUser, showHelp, exit, false, null, -1);
}

public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, boolean clear) {
this(feedbackToUser, showHelp, exit, clear, null, -1);
}

public CommandResult(String feedbackToUser, Student student, int index) {
this(feedbackToUser, false, false, false, student, index);
}

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

public String getFeedbackToUser() {
Expand All @@ -59,6 +70,10 @@ public boolean isExit() {
return exit;
}

public boolean isClear() {
return clear;
}

public boolean isStudent() {
return student != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public CommandResult execute(Model model) throws CommandException {

Student studentToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteStudent(studentToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_STUDENT_SUCCESS, Messages.format(studentToDelete)));
return new CommandResult(String.format(MESSAGE_DELETE_STUDENT_SUCCESS, Messages.format(studentToDelete)),
false, false, true);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public CommandResult execute(Model model) throws CommandException {

model.setStudent(studentToEdit, editedStudent);
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
return new CommandResult(String.format(MESSAGE_EDIT_STUDENT_SUCCESS, Messages.format(editedStudent)));
return new CommandResult(String.format(MESSAGE_EDIT_STUDENT_SUCCESS, Messages.format(editedStudent)),
editedStudent, index.getZeroBased());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredStudentList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_STUDENTS_LISTED_OVERVIEW, model.getFilteredStudentList().size()));
String.format(Messages.MESSAGE_STUDENTS_LISTED_OVERVIEW, model.getFilteredStudentList().size()),
false, false, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public class ListCommand extends Command {
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
return new CommandResult(MESSAGE_SUCCESS);
return new CommandResult(MESSAGE_SUCCESS, false, false, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public CommandResult execute(Model model) throws CommandException {
Student studentToDisplay = lastShownList.get(targetIndex.getZeroBased());

return new CommandResult(String.format(MESSAGE_VIEW_STUDENT_SUCCESS, targetIndex.getZeroBased() + 1),
false, false, studentToDisplay, targetIndex.getZeroBased());
studentToDisplay, targetIndex.getZeroBased());
}

@Override
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,20 @@ void fillInnerParts() {
commandBoxPlaceholder.getChildren().add(commandBox.getRoot());
}

/**
* Clears the details panel.
*/
private void clearDetailsPanel() {
studentDetailsPanelPlaceholder.getChildren().clear();
BlankDetailsPanel blankDetailsPanel = new BlankDetailsPanel();
studentDetailsPanelPlaceholder.getChildren().add(blankDetailsPanel.getRoot());
}

/**
* Updates the details panel to the selected student.
*/
private void updateDetailsPanel(Student student, int index) {
studentDetailsPanelPlaceholder.getChildren().clear();

StudentDetailsPanel studentDetailsPanel = new StudentDetailsPanel(student, index + 1);
studentDetailsPanelPlaceholder.getChildren().add(studentDetailsPanel.getRoot());
}
Expand Down Expand Up @@ -199,6 +207,10 @@ private CommandResult executeCommand(String commandText) throws CommandException
updateDetailsPanel(commandResult.getStudent(), commandResult.getStudentIndex());
}

if (commandResult.isClear()) {
clearDetailsPanel();
}

if (commandResult.isShowHelp()) {
handleHelp();
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/ui/StudentDetailsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ public StudentDetailsPanel(Student student, int displayedIndex) {
assignmentBox.setSpacing(5); // Optional: add spacing between elements

Label titleLabel = new Label(assignment.getName());
titleLabel.getStyleClass().add("assignment-name");
Label scoreLabel = new Label("Score: " + assignment.getScore() + "/" + assignment.getMaxScore());
Label statusLabel = new Label(assignment.getHasSubmitted() ? "Submitted" : "Not Submitted");
if (assignment.getHasSubmitted()) {
statusLabel.getStyleClass().add("assignment-status-submitted");
} else {
statusLabel.getStyleClass().add("assignment-status-unsubmitted");
}

// Optionally apply CSS or styling to differentiate the assignment boxes
assignmentBox.getStyleClass().add("assignment-box");
Expand Down
28 changes: 28 additions & 0 deletions src/main/resources/view/DarkTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@
-fx-border-top-width: 1px;
}

.details-pane .viewport {
-fx-background-color: #3c3e3f;
}

.stack-pane {
-fx-background-color: derive(#1d1d1d, 20%);
}
Expand Down Expand Up @@ -397,3 +401,27 @@
-fx-background-radius: 5;
-fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.2), 5, 0, 0, 0);
}

.assignment-name {
-fx-font-weight: bold;
}

.assignment-status-submitted {
-fx-hgap: 7;
-fx-vgap: 3;
-fx-text-fill: white;
-fx-background-color: #57ce55;
-fx-padding: 1 3 1 3;
-fx-border-radius: 2;
-fx-background-radius: 2;
}

.assignment-status-unsubmitted {
-fx-hgap: 7;
-fx-vgap: 3;
-fx-text-fill: white;
-fx-background-color: #e54444;
-fx-padding: 1 3 1 3;
-fx-border-radius: 2;
-fx-background-radius: 2;
}
118 changes: 65 additions & 53 deletions src/main/resources/view/StudentDetailsPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
Expand All @@ -11,59 +12,70 @@
<?import javafx.scene.layout.VBox?>

<HBox id="detailsPane" fx:id="detailsPane" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<GridPane HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<padding>
<Insets top="5" right="5" bottom="5" left="15" />
</padding>
<HBox spacing="0.5" alignment="CENTER_LEFT">
<Label fx:id="id" styleClass="details_big_label">
<minWidth>
<!-- Ensures that the label text is never truncated -->
<Region fx:constant="USE_PREF_SIZE" />
</minWidth>
</Label>
<Label fx:id="name" text="\$first" styleClass="details_big_label" />
<padding>
<Insets top="5" right="5" bottom="3" left="5" />
</padding>
</HBox>
<Separator />
<FlowPane fx:id="detailsTags">
<padding>
<Insets top="10" bottom="8" left="5"/>
</padding>
</FlowPane>
<HBox spacing="5" alignment="CENTER_LEFT">
<padding>
<Insets left="8"/>
</padding>
<Label text="Phone: " styleClass="details_field_headers" />
<Label fx:id="phone" styleClass="details_small_label" text="\$phone" />
</HBox>
<HBox spacing="5" alignment="CENTER_LEFT">
<padding>
<Insets left="8"/>
</padding>
<Label text="Email: " styleClass="details_field_headers" />
<Label fx:id="email" styleClass="details_small_label" text="\$email" />
<!-- display for Assignments !-->
</HBox>
<HBox spacing="5" alignment="CENTER_LEFT">
<padding>
<Insets left="8" top="10" bottom="5"/>
</padding>
<Label text="Assignments:" styleClass="details_field_headers" />
<!-- Use a VBox inside the FlowPane to list each assignment in its own box -->
<FlowPane fx:id="assignments" vgap="10" hgap="10" alignment="CENTER_LEFT">
<ScrollPane fitToWidth="true" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS" styleClass="details-pane">
<content >
<GridPane >
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<padding>
<Insets top="10" bottom="8" left="5"/>
<Insets top="5" right="5" bottom="5" left="15" />
</padding>
</FlowPane>
</HBox>
</VBox>
</GridPane>
<HBox spacing="0.5" alignment="CENTER_LEFT">
<Label fx:id="id" styleClass="details_big_label">
<minWidth>
<!-- Ensures that the name text is never truncated -->
<Region fx:constant="USE_PREF_SIZE" />
</minWidth>
</Label>
<Label fx:id="name" text="\$first" styleClass="details_big_label" />
<padding>
<Insets top="5" right="5" bottom="3" left="5" />
</padding>
</HBox>
<Separator />
<FlowPane fx:id="detailsTags" >
<padding>
<Insets top="10" bottom="8" left="5"/>
</padding>
</FlowPane>
<HBox spacing="5" alignment="CENTER_LEFT">
<padding>
<Insets left="8"/>
</padding>
<Label text="Phone: " styleClass="details_field_headers" />
<Label fx:id="phone" styleClass="details_small_label" text="\$phone" />
</HBox>
<HBox spacing="5" alignment="CENTER_LEFT">
<padding>
<Insets left="8"/>
</padding>
<Label text="Email: " styleClass="details_field_headers" />
<Label fx:id="email" styleClass="details_small_label" text="\$email" />
<!-- display for Assignments !-->
</HBox>
<HBox spacing="5" alignment="CENTER_LEFT">
<padding>
<Insets top="10" left="8"/>
</padding>
<Label text="Assignments:" styleClass="details_field_headers" />
</HBox>
<HBox spacing="5" alignment="CENTER_LEFT">
<padding>
<Insets left="8" bottom="5"/>
</padding>
<!--<Label text="Assignments:" styleClass="details_field_headers" /> -->

<!-- Use a VBox inside the FlowPane to list each assignment in its own box -->
<FlowPane fx:id="assignments" vgap="10" hgap="10" alignment="CENTER_LEFT" HBox.hgrow="ALWAYS">
<padding>
<Insets top="10" bottom="8" left="5"/>
</padding>
</FlowPane>
</HBox>
</VBox>
</GridPane>
</content>
</ScrollPane>
</HBox>
Loading

0 comments on commit 429e68c

Please sign in to comment.