Skip to content

Commit

Permalink
Fix list items not displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
tohlh committed Apr 14, 2024
1 parent 564f5c5 commit c68b455
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 deletions.
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ public boolean equals(Object other) {
&& year.equals(otherPerson.year)
&& telegram.equals(otherPerson.telegram)
&& major.equals(otherPerson.major)
&& remark.equals(otherPerson.remark)
&& groups.equals(otherPerson.groups);
&& remark.equals(otherPerson.remark);
}

@Override
Expand Down
36 changes: 12 additions & 24 deletions src/main/java/seedu/address/ui/PersonAttendanceList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package seedu.address.ui;

import java.util.ArrayList;
import java.util.List;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.SimpleStringProperty;
Expand Down Expand Up @@ -45,15 +48,15 @@ public class PersonAttendanceList extends UiPart<Region> {
/**
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
*/
public PersonAttendanceList(Person person, int displayedIndex, String groupName) {
public PersonAttendanceList(Person person, int displayedIndex) {
super(FXML);
this.person = person;
id.setText(displayedIndex + ". ");
name.setText(person.getName().fullName);

populateGroupNameCol();
createAttendanceCols();
populateAttendanceCols(groupName);
populateAttendanceCols();
groups.getChildren().add(attendanceTable);
setTableHt();
}
Expand Down Expand Up @@ -85,28 +88,13 @@ public void createAttendanceCols() {
/**
* Populates columns with weekly attendance data.
*/
public void populateAttendanceCols(String groupName) {
// for (Group group : person.getGroups()) {
// if (group.groupName.equals(groupName)) {
// String[] attendanceArray = group.attendance.toArray(new String[0]);
// AttendanceRow row = new AttendanceRow(group.groupName, attendanceArray);
// attendanceTable.getItems().add(row);
// break;
// }
// }
person.getGroups().stream()
.filter(group -> group.groupName.equals(groupName))
.findFirst()
.ifPresent(group -> {
String[] attendanceArray = group.attendance.toArray(new String[0]);
attendanceTable.getItems().add(new AttendanceRow(group.groupName, attendanceArray));
});
// List<AttendanceRow> attendanceRows = new ArrayList<>();
// person.getGroups().forEach(group -> {
// String[] attendanceArray = group.attendance.toArray(new String[0]);
// attendanceRows.add(new AttendanceRow(group.groupName, attendanceArray));
// });
// attendanceTable.getItems().addAll(attendanceRows);
public void populateAttendanceCols() {
List<AttendanceRow> attendanceRows = new ArrayList<>();
person.getGroups().forEach(group -> {
String[] attendanceArray = group.attendance.toArray(new String[0]);
attendanceRows.add(new AttendanceRow(group.groupName, attendanceArray));
});
attendanceTable.getItems().addAll(attendanceRows);
}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/seedu/address/ui/PersonListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -89,7 +91,7 @@ protected void updateItem(Person person, boolean empty) {
int absoluteIndex = personList.indexOf(person) + 1;
String selectedTabName = (tabPane.getSelectionModel().getSelectedItem() != null)
? tabPane.getSelectionModel().getSelectedItem().getText() : "Results";
setGraphic(new PersonAttendanceList(person, absoluteIndex, selectedTabName).getRoot());
setGraphic(new PersonAttendanceList(person, absoluteIndex).getRoot());
}
}
}
Expand Down Expand Up @@ -117,7 +119,18 @@ private void createEachGroupTab(Set<Group> groups) {
tab.setContent(groupListView);

// Filter persons based on the group and set them in the ListView
groupListView.setItems(personList.filtered(person -> person.getGroups().contains(group)));
ObservableList<Person> filteredPersons = personList.filtered(person -> person.getGroups().contains(group));
ObservableList<Person> personsWithFilteredGroups = FXCollections.observableArrayList();

for (Person person : filteredPersons) {
Set<Group> filteredGroups = person.getGroups().stream()
.filter(g -> g.equals(group)).collect(Collectors.toSet());
Person newPerson = new Person(person.getName(), person.getPhone(), person.getEmail(), person.getYear(),
person.getTelegram(), person.getMajor(), person.getRemark(), filteredGroups);
personsWithFilteredGroups.add(newPerson);
}

groupListView.setItems(personsWithFilteredGroups);
groupListView.setCellFactory(listView -> new PersonAttendanceViewCell());
tabPane.getTabs().add(tab);
}
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ public void equals() {
// different remark -> returns false
editedAlice = new PersonBuilder(ALICE).withRemark(VALID_REMARK_OUTSPOKEN).build();
assertFalse(ALICE.equals(editedAlice));

// different groups -> returns false
editedAlice = new PersonBuilder(ALICE).withGroups(VALID_GROUP_LAB).build();
assertFalse(ALICE.equals(editedAlice));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,4 @@ public void toModelType_nullMajor_throwsIllegalValueException() {
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullGroups_personNotEquals() throws Exception {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_YEAR,
VALID_TELEGRAM, VALID_MAJOR, VALID_REMARK, null);
assertNotEquals(BENSON, person.toModelType());
}

}

0 comments on commit c68b455

Please sign in to comment.