Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2425S1#123 from potaotototo/fix-displ…
Browse files Browse the repository at this point in the history
…ay-bug

Fix display bug
  • Loading branch information
weijianwong authored Oct 28, 2024
2 parents 4414c8b + 6a81a9a commit c877db9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/tuteez/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ public CommandResult execute(Model model) throws CommandException {
}

model.setPerson(personToEdit, editedPerson);

if (model.getLastViewedPerson().get().isPresent()) {
if (personToEdit.equals(model.getLastViewedPerson().get().get())) {
model.updateLastViewedPerson(editedPerson);
String logMessageForPerson =
String.format("Student on display is edited, After Edit - Student: %s", editedPerson);
logger.info(logMessageForPerson);
}
}

model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
String logMessage = String.format("Before Edit - Student: %s%nAfter Edit - Student: %s",
personToEdit, editedPerson);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/tuteez/ui/DisplayCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ public DisplayCard(Optional<Person> lastViewedPerson) {
telegram.setText(person.getTelegramUsername().telegramUsername);
address.setText(person.getAddress().value);
email.setText(person.getEmail().value);

tags.getChildren().clear();
person.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));

remarks.getChildren().clear();
person.getRemarkList().getRemarks().stream()
.sorted(Comparator.comparing(remark -> remark.toString()))
.forEach(remark -> remarks.getChildren().add(new Label(remark.toString())));

lessons.getChildren().clear();
person.getLessons().stream()
.forEach(lesson -> lessons.getChildren().add(new Label(lesson.getDayAndTime())));
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/tuteez/ui/DisplayCardPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ public class DisplayCardPanel extends UiPart<Region> {
public DisplayCardPanel(ObjectProperty<Optional<Person>> lastViewedPerson) {
super(FXML);
this.lastViewedPerson = lastViewedPerson;

displayCardListView.setMouseTransparent(true);
displayCardListView.setFocusTraversable(false);

displayCardListView.setItems(FXCollections.observableArrayList());

lastViewedPerson.addListener((observable, oldPerson, newPerson) -> updateDisplayCard(newPerson));
lastViewedPerson.addListener((observable, oldValue, newValue) -> {
logger.fine("Last viewed person changed to: " + newValue);
updateDisplayCard(newValue);
});

displayCardListView.setCellFactory(listView -> new DisplayCardListViewCell());

updateDisplayCard(lastViewedPerson.get());
}

/**
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/tuteez/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,41 @@ public void execute_invalidPersonIndexFilteredList_failure() {
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

@Test
public void execute_editLastViewedPerson_success() {
Person originalPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person editedPerson = new PersonBuilder(originalPerson).withName(VALID_NAME_BOB).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build();
EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, descriptor);

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(originalPerson, editedPerson);
expectedModel.updateLastViewedPerson(editedPerson);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_editNonLastViewedPerson_noUpdateLastViewed() {
Person lastViewedPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
model.updateLastViewedPerson(lastViewedPerson);

Person personToEdit = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased());
Person editedPerson = new PersonBuilder(personToEdit).withName(VALID_NAME_BOB).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build();
EditCommand editCommand = new EditCommand(INDEX_SECOND_PERSON, descriptor);

Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());
expectedModel.setPerson(personToEdit, editedPerson);
expectedModel.updateLastViewedPerson(lastViewedPerson);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson));

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
}

@Test
public void equals() {
final EditCommand standardCommand = new EditCommand(INDEX_FIRST_PERSON, DESC_AMY);
Expand Down

0 comments on commit c877db9

Please sign in to comment.