diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 8950343f086..a2cf7e72377 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -6,7 +6,6 @@ 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_TAG; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.util.Collections; import java.util.HashSet; @@ -84,7 +83,10 @@ public CommandResult execute(Model model) throws CommandException { } model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + if (model.getIsLoansTab().get()) { + model.updateFilteredPersonList(person -> person.isSamePerson(editedPerson)); + model.updateFilteredLoanList(loan -> loan.isAssignedTo(editedPerson)); + } return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); } diff --git a/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java b/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java index 218121faf26..40eb1c7a360 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java @@ -45,11 +45,7 @@ public CommandResult execute(Model model) throws CommandException { Person personToShowLoan = lastShownList.get(targetIndex.getZeroBased()); model.updateFilteredPersonList(person -> person.equals(personToShowLoan)); - if (isShowAllLoans) { - model.updateFilteredLoanList(loan -> loan.isAssignedTo(personToShowLoan)); - } else { - model.updateFilteredLoanList(loan -> loan.isAssignedTo(personToShowLoan) && loan.isActive()); - } + model.updateFilteredLoanList(loan -> loan.isAssignedTo(personToShowLoan), isShowAllLoans); model.setDualPanel(); return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(personToShowLoan)), false, false, true); diff --git a/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java b/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java index eedc05b349c..7982f62c76a 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java @@ -1,8 +1,6 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_ACTIVE_LOANS; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_LOANS; import static seedu.address.model.Model.PREDICATE_SHOW_NO_PERSONS; import seedu.address.model.Model; @@ -23,11 +21,7 @@ public ViewLoansCommand(boolean isShowAllLoans) { public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredPersonList(PREDICATE_SHOW_NO_PERSONS); - if (isShowAllLoans) { - model.updateFilteredLoanList(PREDICATE_SHOW_ALL_LOANS); - } else { - model.updateFilteredLoanList(PREDICATE_SHOW_ALL_ACTIVE_LOANS); - } + model.updateFilteredLoanList(unused -> true, isShowAllLoans); model.setIsLoansTab(true); return new CommandResult(MESSAGE_SUCCESS, false, false, true); } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index b979c778387..ce4b052c118 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -138,10 +138,27 @@ public interface Model { */ void updateFilteredPersonList(Predicate predicate); + /** + * Returns an unmodifiable view of the sorted loan list + */ ObservableList getSortedLoanList(); + /** + * Updates the filter of the filtered loan list to filter by the given {@code predicate}. + * + * @param predicate + */ void updateFilteredLoanList(Predicate predicate); + /** + * Updates the filter of the filtered loan list to filter by the given {@code predicate}. + * Also updates the preference of whether to show all loans or only active loans. + * + * @param predicate + * @param isShowAllLoans + */ + void updateFilteredLoanList(Predicate predicate, boolean isShowAllLoans); + void setLoanList(List loanList); BooleanProperty getIsLoansTab(); diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 8882b430ee7..43abd8fa137 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -38,6 +38,7 @@ public class ModelManager implements Model { private final BooleanProperty isLoansTab = new SimpleBooleanProperty(false); private final BooleanProperty isAnalyticsTab = new SimpleBooleanProperty(false); private final BooleanProperty isPersonTab = new SimpleBooleanProperty(false); + private final BooleanProperty isShowAllLoans = new SimpleBooleanProperty(false); private final ObjectProperty dashboardData = new SimpleObjectProperty<>(); /** @@ -187,7 +188,16 @@ public ObservableList getSortedLoanList() { @Override public void updateFilteredLoanList(Predicate predicate) { requireNonNull(predicate); - filteredLoans.setPredicate(predicate); + Predicate second_predicate = + isShowAllLoans.get() ? PREDICATE_SHOW_ALL_LOANS : PREDICATE_SHOW_ALL_ACTIVE_LOANS; + filteredLoans.setPredicate(predicate.and(second_predicate)); + } + + @Override + public void updateFilteredLoanList(Predicate predicate, boolean isShowAllLoans) { + requireNonNull(predicate); + this.isShowAllLoans.setValue(isShowAllLoans); + updateFilteredLoanList(predicate); } @Override diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index fedd16dd75e..4597881de65 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -169,6 +169,8 @@ public void updateFilteredPersonList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + + @Override public void setLoanList(List loanList) { throw new AssertionError("This method should not be called."); @@ -184,6 +186,11 @@ public void updateFilteredLoanList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + @Override + public void updateFilteredLoanList(Predicate predicate, boolean isShowAllLoans) { + throw new AssertionError("This method should not be called."); + } + @Override public BooleanProperty getIsLoansTab() { throw new AssertionError("This method should not be called."); diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 469dd97daa7..5d41344d94a 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -84,8 +84,6 @@ public void execute_noFieldSpecifiedUnfilteredList_success() { @Test public void execute_filteredList_success() { - showPersonAtIndex(model, INDEX_FIRST_PERSON); - Person personInFilteredList = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); Person editedPerson = new PersonBuilder(personInFilteredList).withName(VALID_NAME_BOB).build(); EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON,