Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1718S1#70 from Procrastinatus/master
Browse files Browse the repository at this point in the history
Implemented multi-delete for persons, added schedule list panel, added some tests
  • Loading branch information
cjianhui authored Oct 27, 2017
2 parents c07e7ef + 0300310 commit 417feec
Show file tree
Hide file tree
Showing 48 changed files with 1,491 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/**
* Indicates a request to jump to the list of persons
*/
public class JumpToListRequestEvent extends BaseEvent {
public class JumpToPersonListRequestEvent extends BaseEvent {

public final int targetIndex;

public JumpToListRequestEvent(Index targetIndex) {
public JumpToPersonListRequestEvent(Index targetIndex) {
this.targetIndex = targetIndex.getZeroBased();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.events.BaseEvent;

/**
* Indicates a request to jump to the list of persons
*/
public class JumpToScheduleListRequestEvent extends BaseEvent {

public final int targetIndex;

public JumpToScheduleListRequestEvent(Index targetIndex) {
this.targetIndex = targetIndex.getZeroBased();
}

@Override
public String toString() {
return this.getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.events.BaseEvent;
import seedu.address.ui.ScheduleCard;

/**
* Represents a selection change in the Person List Panel
*/
public class SchedulePanelSelectionChangedEvent extends BaseEvent {

private final ScheduleCard newSelection;

public SchedulePanelSelectionChangedEvent(ScheduleCard newSelection) {
this.newSelection = newSelection;
}

@Override
public String toString() {
return this.getClass().getSimpleName();
}

public ScheduleCard getNewSelection() {
return newSelection;
}
}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.group.ReadOnlyGroup;
import seedu.address.model.person.ReadOnlyPerson;
import seedu.address.model.schedule.ReadOnlySchedule;

/**
* API of the Logic component
Expand All @@ -26,6 +27,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of groups */
ObservableList<ReadOnlyGroup> getFilteredGroupList();

/** Returns an unmodifiable view of the filtered list of schedules */
ObservableList<ReadOnlySchedule> getFilteredScheduleList();

/** Returns the list of input entered by the user, encapsulated in a {@code ListElementPointer} object */
ListElementPointer getHistorySnapshot();
}
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import seedu.address.model.Model;
import seedu.address.model.group.ReadOnlyGroup;
import seedu.address.model.person.ReadOnlyPerson;
import seedu.address.model.schedule.ReadOnlySchedule;

/**
* The main LogicManager of the app.
Expand Down Expand Up @@ -56,6 +57,11 @@ public ObservableList<ReadOnlyGroup> getFilteredGroupList() {
return model.getFilteredGroupList();
}

@Override
public ObservableList<ReadOnlySchedule> getFilteredScheduleList() {
return model.getFilteredScheduleList();
}

@Override
public ListElementPointer getHistorySnapshot() {
return new ListElementPointer(history.getHistory());
Expand Down
34 changes: 27 additions & 7 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,52 @@ public class DeleteCommand extends UndoableCommand {
public static final String COMMAND_ALT = "d";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the last person listing.\n"
+ ": Deletes the person identified by the index number(s) used in the last person listing.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";
+ "Example: " + COMMAND_WORD + " 1 2 3";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";

private final Index targetIndex;
private Index targetIndex;

private Index[] targetIndexes;

public DeleteCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}

public DeleteCommand(Index[] targetIndexes) {
this.targetIndexes = targetIndexes;
}

@Override
public CommandResult executeUndoableCommand() throws CommandException {

List<ReadOnlyPerson> lastShownList = model.getFilteredPersonList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
ReadOnlyPerson personToDelete = null;
ReadOnlyPerson[] personsToDelete = null;

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

ReadOnlyPerson personToDelete = lastShownList.get(targetIndex.getZeroBased());
if (targetIndexes != null) {
personsToDelete = new ReadOnlyPerson[targetIndexes.length];
for (int i = 0; i < personsToDelete.length; i++) {
personsToDelete[i] = lastShownList.get(targetIndexes[i].getZeroBased());
}
}

try {
model.deletePerson(personToDelete);
if (personsToDelete == null) {
model.deletePerson(personToDelete);
} else {
model.deletePersons(personsToDelete);
}
} catch (PersonNotFoundException pnfe) {
assert false : "The target person cannot be missing";
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/SelectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.events.ui.JumpToGroupListRequestEvent;
import seedu.address.commons.events.ui.JumpToListRequestEvent;
import seedu.address.commons.events.ui.JumpToPersonListRequestEvent;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.group.ReadOnlyGroup;
import seedu.address.model.person.ReadOnlyPerson;
Expand Down Expand Up @@ -52,7 +52,7 @@ public CommandResult execute() throws CommandException {
if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex));
EventsCenter.getInstance().post(new JumpToPersonListRequestEvent(targetIndex));
return new CommandResult(String.format(MESSAGE_SELECT_PERSON_SUCCESS, targetIndex.getOneBased()));
}

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/seedu/address/logic/parser/DeleteCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ public class DeleteCommandParser implements Parser<DeleteCommand> {
*/
public DeleteCommand parse(String args) throws ParseException {
try {
Index index = ParserUtil.parseIndex(args);
return new DeleteCommand(index);
String[] arguments = args.trim().split(" ");
if (arguments.length == 1) {
Index index = ParserUtil.parseIndex(args);
return new DeleteCommand(index);
} else {
Index[] indexes = new Index[arguments.length];
for (int i = 0; i < indexes.length; i++) {
indexes[i] = ParserUtil.parseIndex(arguments[i]);
}
return new DeleteCommand(indexes);
}
} catch (IllegalValueException ive) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE));
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
import seedu.address.model.person.exceptions.DuplicatePersonException;
import seedu.address.model.person.exceptions.NoPersonsException;
import seedu.address.model.person.exceptions.PersonNotFoundException;
import seedu.address.model.schedule.ReadOnlySchedule;
import seedu.address.model.schedule.Schedule;
import seedu.address.model.schedule.UniqueScheduleList;
import seedu.address.model.schedule.exceptions.DuplicateScheduleException;
import seedu.address.model.schedule.exceptions.ScheduleNotFoundException;
import seedu.address.model.tag.Tag;
import seedu.address.model.tag.UniqueTagList;

Expand All @@ -36,6 +41,7 @@ public class AddressBook implements ReadOnlyAddressBook {
private final UniquePersonList persons;
private final UniqueTagList tags;
private final UniqueGroupList groups;
private final UniqueScheduleList schedules;

/*
* The 'unusual' code block below is an non-static initialization block, sometimes used to avoid duplication
Expand All @@ -48,6 +54,7 @@ public class AddressBook implements ReadOnlyAddressBook {
persons = new UniquePersonList();
tags = new UniqueTagList();
groups = new UniqueGroupList();
schedules = new UniqueScheduleList();
}

public AddressBook() {}
Expand Down Expand Up @@ -278,6 +285,32 @@ public boolean removeGroup(ReadOnlyGroup key) throws GroupNotFoundException {
throw new GroupNotFoundException();
}
}

//// schedule-level operations

/**
* Adds a schedule to the address book.
*
* @throws DuplicateScheduleException if an equivalent schedule already exists.
*/

public void addSchedule(ReadOnlySchedule s) throws DuplicateScheduleException {
Schedule newSchedule = new Schedule(s);
schedules.add(newSchedule);
}

/**
* Removes {@code key} from this {@code AddressBook}.
* @throws ScheduleNotFoundException if the {@code key} is not in this {@code AddressBook}.
*/
public boolean removeSchedule(ReadOnlySchedule key) throws ScheduleNotFoundException {
if (schedules.remove(key)) {
return true;
} else {
throw new ScheduleNotFoundException();
}
}

//// util methods

@Override
Expand All @@ -304,6 +337,11 @@ public ObservableList<ReadOnlyGroup> getGroupList() {
return groups.asObservableList();
}

@Override
public ObservableList<ReadOnlySchedule> getScheduleList() {
return schedules.asObservableList();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import seedu.address.model.person.exceptions.DuplicatePersonException;
import seedu.address.model.person.exceptions.NoPersonsException;
import seedu.address.model.person.exceptions.PersonNotFoundException;
import seedu.address.model.schedule.ReadOnlySchedule;
import seedu.address.model.schedule.exceptions.DuplicateScheduleException;
import seedu.address.model.schedule.exceptions.ScheduleNotFoundException;

/**
* The API of the Model component.
Expand All @@ -23,6 +26,9 @@ public interface Model {
/** {@code Predicate} that always evaluate to true */
Predicate<ReadOnlyGroup> PREDICATE_SHOW_ALL_GROUPS = unused -> true;

/** {@code Predicate} that always evaluate to true */
Predicate<ReadOnlySchedule> PREDICATE_SHOW_ALL_SCHEDULES = unused -> true;

/** Clears existing backing model and replaces with the provided new data. */
void resetData(ReadOnlyAddressBook newData);

Expand All @@ -32,6 +38,9 @@ public interface Model {
/** Deletes the given person. */
void deletePerson(ReadOnlyPerson target) throws PersonNotFoundException;

/** Deletes the given persons. */
void deletePersons(ReadOnlyPerson[] targets) throws PersonNotFoundException;

/** Adds the given person */
void addPerson(ReadOnlyPerson person) throws DuplicatePersonException;

Expand All @@ -44,6 +53,12 @@ public interface Model {
/** Deletes the given group */
void deleteGroup(ReadOnlyGroup group) throws GroupNotFoundException;

/** Adds the given schedule */
void addSchedule(ReadOnlySchedule schedule) throws DuplicateScheduleException;

/** Deletes the given schedule */
void deleteSchedule(ReadOnlySchedule schedule) throws ScheduleNotFoundException;

/** Adds given person to given group */
void addPersonToGroup(Index targetGroup, ReadOnlyPerson toAdd) throws
GroupNotFoundException, PersonNotFoundException, DuplicatePersonException;
Expand All @@ -69,6 +84,11 @@ void updatePerson(ReadOnlyPerson target, ReadOnlyPerson editedPerson)
/** Returns an unmodifiable view of the filtered group list */
ObservableList<ReadOnlyGroup> getFilteredGroupList();

/** Returns an unmodifiable view of the filtered schedule list */
ObservableList<ReadOnlySchedule> getFilteredScheduleList();

void showUnfilteredPersonList();

/**
* Updates the filter of the filtered person list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
Expand All @@ -81,4 +101,9 @@ void updatePerson(ReadOnlyPerson target, ReadOnlyPerson editedPerson)
*/
void updateFilteredGroupList(Predicate<ReadOnlyGroup> predicate);

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

0 comments on commit 417feec

Please sign in to comment.