Skip to content

Commit

Permalink
Merge pull request AY2425S1-CS2103T-F15-2#48 from JYL27/branch-Ui
Browse files Browse the repository at this point in the history
Update Ui component
  • Loading branch information
btbrandon authored Oct 9, 2024
2 parents 36e1327 + 22e2777 commit 04b5cfa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/main/java/seedu/address/model/person/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Module {
public static final String VALIDATION_REGEX = "^[a-zA-Z0-9]+$";

public final String module;
private Grade grade;

/**
* Constructs an {@code Module}.
Expand All @@ -38,9 +39,13 @@ public static boolean isValidModule(String test) {
return test.matches(VALIDATION_REGEX);
}

public void setGrade(Grade grade) {
this.grade = grade;
}

@Override
public String toString() {
return module;
return module + ": " + (grade == null ? "Grade not assigned" : grade.toString());
}

@Override
Expand All @@ -62,5 +67,4 @@ public boolean equals(Object other) {
public int hashCode() {
return module.hashCode();
}

}
16 changes: 8 additions & 8 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Collections;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Objects;

import seedu.address.commons.util.ToStringBuilder;
Expand All @@ -26,7 +25,7 @@ public class Person {
private final Address address;
private final Course course;
private final Tag tag;
private final HashMap<Module, Grade> moduleGrades = new HashMap<>();
private final ArrayList<Module> moduleGrades = new ArrayList<>();

/**
* Every field must be present and not null.
Expand Down Expand Up @@ -72,9 +71,9 @@ public Course getCourse() {
*
* @param newModuleGrades A map of Module and Grade pairs to set.
*/
public void setModuleGrades(HashMap<Module, Grade> newModuleGrades) {
public void setModuleGrades(ArrayList<Module> newModuleGrades) {
moduleGrades.clear();
moduleGrades.putAll(newModuleGrades);
moduleGrades.addAll(newModuleGrades);
}

/**
Expand All @@ -86,15 +85,16 @@ public void setModuleGrades(HashMap<Module, Grade> newModuleGrades) {
public void addModuleGrade(Module module, Grade grade) {
requireNonNull(module, "Module cannot be null");
requireNonNull(grade, "Grade cannot be null");
moduleGrades.put(module, grade);
module.setGrade(grade);
moduleGrades.add(module);
}

/**
* Returns an immutable course grades map, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public HashMap<Module, Grade> getModuleGrades() {
return (HashMap<Module, Grade>) Collections.unmodifiableMap(moduleGrades);
public ArrayList<Module> getModuleGrades() {
return moduleGrades;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class PersonCard extends UiPart<Region> {
private Label email;
@FXML
private FlowPane tags;
@FXML
private Label course;

/**
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
Expand All @@ -50,10 +52,17 @@ public PersonCard(Person person, int displayedIndex) {
phone.setText(person.getPhone().value);
address.setText(person.getAddress().value);
email.setText(person.getEmail().value);

FlowPane singleTagFlowPane = new FlowPane();
Label tagLabel = new Label(person.getTag().toString());
singleTagFlowPane.getChildren().add(tagLabel);
tags.getChildren().add(singleTagFlowPane);

String modulesAsString = person.getModuleGrades().stream()
.map(m -> m.toString() + "\n")
.reduce("", (x, y) -> x + y);

course.setText(modulesAsString.isEmpty() ? "No enrolled modules" : modulesAsString);
/*person.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));*/
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/view/PersonListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" />
<Label fx:id="address" styleClass="cell_small_label" text="\$address" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
<Label fx:id="course" styleClass="cell_small_label" text="\$course" />
</VBox>
</GridPane>
</HBox>

0 comments on commit 04b5cfa

Please sign in to comment.