Skip to content

Commit c68b455

Browse files
committed
Fix list items not displaying
1 parent 564f5c5 commit c68b455

File tree

5 files changed

+28
-39
lines changed

5 files changed

+28
-39
lines changed

src/main/java/seedu/address/model/person/Person.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ public boolean equals(Object other) {
139139
&& year.equals(otherPerson.year)
140140
&& telegram.equals(otherPerson.telegram)
141141
&& major.equals(otherPerson.major)
142-
&& remark.equals(otherPerson.remark)
143-
&& groups.equals(otherPerson.groups);
142+
&& remark.equals(otherPerson.remark);
144143
}
145144

146145
@Override

src/main/java/seedu/address/ui/PersonAttendanceList.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package seedu.address.ui;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
import javafx.beans.binding.Bindings;
47
import javafx.beans.binding.DoubleBinding;
58
import javafx.beans.property.SimpleStringProperty;
@@ -45,15 +48,15 @@ public class PersonAttendanceList extends UiPart<Region> {
4548
/**
4649
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
4750
*/
48-
public PersonAttendanceList(Person person, int displayedIndex, String groupName) {
51+
public PersonAttendanceList(Person person, int displayedIndex) {
4952
super(FXML);
5053
this.person = person;
5154
id.setText(displayedIndex + ". ");
5255
name.setText(person.getName().fullName);
5356

5457
populateGroupNameCol();
5558
createAttendanceCols();
56-
populateAttendanceCols(groupName);
59+
populateAttendanceCols();
5760
groups.getChildren().add(attendanceTable);
5861
setTableHt();
5962
}
@@ -85,28 +88,13 @@ public void createAttendanceCols() {
8588
/**
8689
* Populates columns with weekly attendance data.
8790
*/
88-
public void populateAttendanceCols(String groupName) {
89-
// for (Group group : person.getGroups()) {
90-
// if (group.groupName.equals(groupName)) {
91-
// String[] attendanceArray = group.attendance.toArray(new String[0]);
92-
// AttendanceRow row = new AttendanceRow(group.groupName, attendanceArray);
93-
// attendanceTable.getItems().add(row);
94-
// break;
95-
// }
96-
// }
97-
person.getGroups().stream()
98-
.filter(group -> group.groupName.equals(groupName))
99-
.findFirst()
100-
.ifPresent(group -> {
101-
String[] attendanceArray = group.attendance.toArray(new String[0]);
102-
attendanceTable.getItems().add(new AttendanceRow(group.groupName, attendanceArray));
103-
});
104-
// List<AttendanceRow> attendanceRows = new ArrayList<>();
105-
// person.getGroups().forEach(group -> {
106-
// String[] attendanceArray = group.attendance.toArray(new String[0]);
107-
// attendanceRows.add(new AttendanceRow(group.groupName, attendanceArray));
108-
// });
109-
// attendanceTable.getItems().addAll(attendanceRows);
91+
public void populateAttendanceCols() {
92+
List<AttendanceRow> attendanceRows = new ArrayList<>();
93+
person.getGroups().forEach(group -> {
94+
String[] attendanceArray = group.attendance.toArray(new String[0]);
95+
attendanceRows.add(new AttendanceRow(group.groupName, attendanceArray));
96+
});
97+
attendanceTable.getItems().addAll(attendanceRows);
11098
}
11199

112100
/**

src/main/java/seedu/address/ui/PersonListPanel.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import java.util.HashSet;
44
import java.util.Set;
55
import java.util.logging.Logger;
6+
import java.util.stream.Collectors;
67

8+
import javafx.collections.FXCollections;
79
import javafx.collections.ListChangeListener;
810
import javafx.collections.ObservableList;
911
import javafx.fxml.FXML;
@@ -89,7 +91,7 @@ protected void updateItem(Person person, boolean empty) {
8991
int absoluteIndex = personList.indexOf(person) + 1;
9092
String selectedTabName = (tabPane.getSelectionModel().getSelectedItem() != null)
9193
? tabPane.getSelectionModel().getSelectedItem().getText() : "Results";
92-
setGraphic(new PersonAttendanceList(person, absoluteIndex, selectedTabName).getRoot());
94+
setGraphic(new PersonAttendanceList(person, absoluteIndex).getRoot());
9395
}
9496
}
9597
}
@@ -117,7 +119,18 @@ private void createEachGroupTab(Set<Group> groups) {
117119
tab.setContent(groupListView);
118120

119121
// Filter persons based on the group and set them in the ListView
120-
groupListView.setItems(personList.filtered(person -> person.getGroups().contains(group)));
122+
ObservableList<Person> filteredPersons = personList.filtered(person -> person.getGroups().contains(group));
123+
ObservableList<Person> personsWithFilteredGroups = FXCollections.observableArrayList();
124+
125+
for (Person person : filteredPersons) {
126+
Set<Group> filteredGroups = person.getGroups().stream()
127+
.filter(g -> g.equals(group)).collect(Collectors.toSet());
128+
Person newPerson = new Person(person.getName(), person.getPhone(), person.getEmail(), person.getYear(),
129+
person.getTelegram(), person.getMajor(), person.getRemark(), filteredGroups);
130+
personsWithFilteredGroups.add(newPerson);
131+
}
132+
133+
groupListView.setItems(personsWithFilteredGroups);
121134
groupListView.setCellFactory(listView -> new PersonAttendanceViewCell());
122135
tabPane.getTabs().add(tab);
123136
}

src/test/java/seedu/address/model/person/PersonTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ public void equals() {
8989
// different remark -> returns false
9090
editedAlice = new PersonBuilder(ALICE).withRemark(VALID_REMARK_OUTSPOKEN).build();
9191
assertFalse(ALICE.equals(editedAlice));
92-
93-
// different groups -> returns false
94-
editedAlice = new PersonBuilder(ALICE).withGroups(VALID_GROUP_LAB).build();
95-
assertFalse(ALICE.equals(editedAlice));
9692
}
9793

9894
@Test

src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,4 @@ public void toModelType_nullMajor_throwsIllegalValueException() {
149149
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
150150
}
151151

152-
@Test
153-
public void toModelType_nullGroups_personNotEquals() throws Exception {
154-
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_YEAR,
155-
VALID_TELEGRAM, VALID_MAJOR, VALID_REMARK, null);
156-
assertNotEquals(BENSON, person.toModelType());
157-
}
158-
159152
}

0 commit comments

Comments
 (0)