Skip to content

Commit

Permalink
Merge pull request #100 from Gibson0918/Remove-Contact-Details
Browse files Browse the repository at this point in the history
Modified code to hide the visibility of contact details of all command except view command.
  • Loading branch information
Statspadders authored Mar 30, 2023
2 parents b2ba4af + 6c2b232 commit 2b95711
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public CommandResult execute(Model model) throws CommandException {
}
model.resetPersonHiddenStatus();
model.deleteMultiplePersons(listOfPeople);
model.resetPersonHiddenStatus();
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ public DeleteSingleIndexCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.resetPersonHiddenStatus();
List<Person> lastShownList = model.getFilteredPersonList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.resetPersonHiddenStatus();
model.deletePerson(personToDelete);

return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public CommandResult execute(Model model) throws CommandException {

List<Name> nameList = index.stream().filter(x -> validateIndex(x, lastShownList))
.map(x -> lastShownList.get(x.getZeroBased()).getName()).collect(Collectors.toList());
List<Person> updatedPersonList = lastShownList.stream()
.filter(x -> nameList.contains(x.getName())).collect(Collectors.toList());
model.showPersonContact(updatedPersonList);
MatchNamePredicate predicate = new MatchNamePredicate(nameList);
model.updateFilteredPersonList(predicate);
StringBuilder sb = new StringBuilder();
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

import javafx.collections.ObservableList;
Expand All @@ -12,7 +13,9 @@
* The API of the Model component.
*/
public interface Model {
/** {@code Predicate} that always evaluate to true */
/**
* {@code Predicate} that always evaluate to true
*/
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;

/**
Expand Down Expand Up @@ -60,7 +63,9 @@ public interface Model {
*/
void setAddressBook(ReadOnlyAddressBook addressBook);

/** Returns the AddressBook */
/**
* Returns the AddressBook
*/
ReadOnlyAddressBook getAddressBook();

/**
Expand All @@ -77,6 +82,7 @@ public interface Model {
/**
* Deletes all the people in the list.
* All the people in the list must exist in the address book.
*
* @param listOfPeople ArrayList of Person.
*/
void deleteMultiplePersons(ArrayList<Person> listOfPeople);
Expand All @@ -94,17 +100,28 @@ public interface Model {
*/
void setPerson(Person target, Person editedPerson);

/** Returns an unmodifiable view of the filtered person list */
/**
* Returns an unmodifiable view of the filtered person list
*/
ObservableList<Person> getFilteredPersonList();

/**
* Updates the filter of the filtered person list to filter by the given {@code predicate}.
*
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredPersonList(Predicate<Person> predicate);

/**
* resets each person contact status to be hidden.
*/
void resetPersonHiddenStatus();

/**
* Sets each person's contact in the person list to be visible.
* @param personList list of person.
*/
void showPersonContact(List<Person> personList);

/**
* Adds all contacts not already in the address book into the address book.
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ public void updateFilteredPersonList(Predicate<Person> predicate) {
filteredPersons.setPredicate(predicate);
}

/**
* resets each person contact status to be hidden.
*/
@Override
public void resetPersonHiddenStatus() {
List<Person> personlist = getFilteredPersonList();
Expand All @@ -183,6 +186,15 @@ public void resetPersonHiddenStatus() {
});
}

/**
* Sets each person's contact in the person list to be visible.
* @param personList list of person.
*/
@Override
public void showPersonContact(List<Person> personList) {
personList.stream().forEach(x -> x.toggleHidden());
}

//=========== Undo management =============================================================================
public boolean hasUndoableCommand() {
return undoManager.hasUndoableCommand();
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/seedu/address/logic/commands/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -172,6 +173,11 @@ public void resetPersonHiddenStatus() {
throw new AssertionError("This method should not be called.");
}

@Override
public void showPersonContact(List<Person> personList) {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean hasUndoableCommand() {
throw new AssertionError("This method should not be called.");
Expand All @@ -188,6 +194,7 @@ public boolean hasRedoableCommand() {
public String executeRedo() {
throw new AssertionError("This method should not be called.");
}

}

/**
Expand Down Expand Up @@ -235,11 +242,14 @@ public void resetPersonHiddenStatus() {
});
}

@Override
public void showPersonContact(List<Person> personList) {
personList.stream().forEach(x -> x.toggleHidden());
}

@Override
public ReadOnlyAddressBook getAddressBook() {
return new AddressBook();
}
}

}

0 comments on commit 2b95711

Please sign in to comment.