Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behaviour of edit person in loan view #124

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,7 +83,10 @@
}

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));

Check warning on line 88 in src/main/java/seedu/address/logic/commands/EditCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/EditCommand.java#L87-L88

Added lines #L87 - L88 were not covered by tests
}
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@

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);

Check warning on line 48 in src/main/java/seedu/address/logic/commands/ViewLoanCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/ViewLoanCommand.java#L48

Added line #L48 was not covered by tests
model.setDualPanel();
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(personToShowLoan)),
false, false, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,11 +21,7 @@
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);

Check warning on line 24 in src/main/java/seedu/address/logic/commands/ViewLoansCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/ViewLoansCommand.java#L24

Added line #L24 was not covered by tests
model.setIsLoansTab(true);
return new CommandResult(MESSAGE_SUCCESS, false, false, true);
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,27 @@ public interface Model {
*/
void updateFilteredPersonList(Predicate<Person> predicate);

/**
* Returns an unmodifiable view of the sorted loan list
*/
ObservableList<Loan> getSortedLoanList();

/**
* Updates the filter of the filtered loan list to filter by the given {@code predicate}.
*
* @param predicate
*/
void updateFilteredLoanList(Predicate<Loan> 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<Loan> predicate, boolean isShowAllLoans);

void setLoanList(List<Loan> loanList);

BooleanProperty getIsLoansTab();
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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> dashboardData = new SimpleObjectProperty<>();

/**
Expand Down Expand Up @@ -187,7 +188,16 @@
@Override
public void updateFilteredLoanList(Predicate<Loan> predicate) {
requireNonNull(predicate);
filteredLoans.setPredicate(predicate);
Predicate<Loan> second_predicate =
isShowAllLoans.get() ? PREDICATE_SHOW_ALL_LOANS : PREDICATE_SHOW_ALL_ACTIVE_LOANS;
filteredLoans.setPredicate(predicate.and(second_predicate));
}

@Override
public void updateFilteredLoanList(Predicate<Loan> predicate, boolean isShowAllLoans) {
requireNonNull(predicate);
this.isShowAllLoans.setValue(isShowAllLoans);
updateFilteredLoanList(predicate);

Check warning on line 200 in src/main/java/seedu/address/model/ModelManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/ModelManager.java#L198-L200

Added lines #L198 - L200 were not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public void updateFilteredPersonList(Predicate<Person> predicate) {
throw new AssertionError("This method should not be called.");
}



@Override
public void setLoanList(List<Loan> loanList) {
throw new AssertionError("This method should not be called.");
Expand All @@ -184,6 +186,11 @@ public void updateFilteredLoanList(Predicate<Loan> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredLoanList(Predicate<Loan> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading