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

Update features #178

Merged
merged 3 commits into from Nov 8, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,23 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.events.BaseEvent;

/**
* Represents a selection change in the Person List Panel and indicates white state is it currently on
*/
public class ChangeOnListPickerClickEvent extends BaseEvent {
private final int newSelection;

public ChangeOnListPickerClickEvent (int newSelection) {
this.newSelection = newSelection;
}

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

public int getNewSelection() {
return newSelection;
}
}
44 changes: 33 additions & 11 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Expand Up @@ -37,21 +37,43 @@ public DeleteCommand(Index targetIndex) {
@Override
public CommandResult runBody(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
int state = model.getState();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
if (state == 1) {
List<Person> lastShownList = model.getFilteredPersonList();

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

if (personToDelete.equals(model.getLoggedInUser().getPerson())) {
throw new CommandException(MESSAGE_DELETE_SELF_FAILURE);
}
Person personToDelete = lastShownList.get(targetIndex.getZeroBased());

if (personToDelete.equals(model.getLoggedInUser().getPerson())) {
throw new CommandException(MESSAGE_DELETE_SELF_FAILURE);
}

model.deletePerson(personToDelete);
model.commitAddressBook();
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
} else if (state == 2) {
List<Person> lastShownList = model.getArchivedPersonList();

model.deletePerson(personToDelete);
model.commitAddressBook();
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToDelete = lastShownList.get(targetIndex.getZeroBased());

if (personToDelete.equals(model.getLoggedInUser().getPerson())) {
throw new CommandException(MESSAGE_DELETE_SELF_FAILURE);
}

model.deleteFromArchive(personToDelete);
model.commitAddressBook();
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
} else {
return null;
}
}

@Override
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Expand Up @@ -26,6 +26,9 @@ public interface Model {
/** Clears existing backing model and replaces with the provided new data. */
void resetArchive(ReadOnlyArchiveList newData);

/** Returns the current state of the person panel list */
int getState();

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

Expand All @@ -46,6 +49,12 @@ public interface Model {
*/
void deletePerson(Person target);

/**
* Deletes the given person in the archive list.
* The person must exist in the archive list.
*/
void deleteFromArchive(Person target);

/**
* Restores the given person in the archive list.
* The person must exist in the archive list.
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Expand Up @@ -7,6 +7,8 @@
import java.util.function.Predicate;
import java.util.logging.Logger;

import com.google.common.eventbus.Subscribe;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
Expand All @@ -15,6 +17,7 @@
import seedu.address.commons.events.model.AddressBookChangedEvent;
import seedu.address.commons.events.model.ArchivedListChangedEvent;
import seedu.address.commons.events.model.AssignmentListChangedEvent;
import seedu.address.commons.events.ui.ChangeOnListPickerClickEvent;
import seedu.address.commons.exceptions.IllegalUsernameException;
import seedu.address.model.leaveapplication.LeaveApplicationWithEmployee;
import seedu.address.model.person.Person;
Expand All @@ -28,6 +31,8 @@
public class ModelManager extends ComponentManager implements Model {
private static final Logger logger = LogsCenter.getLogger(ModelManager.class);

//1 is for active list, 2 is for archive list
private int state;
private final VersionedAddressBook versionedAddressBook;
private final VersionedAssignmentList versionedAssignmentList;
private final VersionedArchiveList versionedArchiveList;
Expand Down Expand Up @@ -55,6 +60,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyAssignmentList assi
versionedArchiveList = new VersionedArchiveList(archiveList);
filteredLeaveApplications = new FilteredList<>(versionedAddressBook.getLeaveApplicationList());
archivedPersons = new FilteredList<>(versionedArchiveList.getPersonList());
state = 1;
}

public ModelManager() {
Expand All @@ -77,6 +83,11 @@ public void resetArchive(ReadOnlyArchiveList newData) {
indicateArchivedListChanged();
}

@Override
public int getState() {
return this.state;
}

@Override
public ReadOnlyAddressBook getAddressBook() {
return versionedAddressBook;
Expand Down Expand Up @@ -116,6 +127,12 @@ public void deletePerson(Person target) {
indicateArchivedListChanged();
}

@Override
public void deleteFromArchive(Person target) {
versionedArchiveList.removePerson(target);
indicateArchivedListChanged();
}

@Override
public void restorePerson(Person target) {
versionedArchiveList.removePerson(target);
Expand Down Expand Up @@ -191,12 +208,14 @@ public ObservableList<Person> getArchivedPersonList() {
public void updateFilteredPersonList(Predicate<Person> predicate) {
requireNonNull(predicate);
filteredPersons.setPredicate(predicate);
state = 1;
}

@Override
public void updateArchivedPersonList(Predicate<Person> predicate) {
requireNonNull(predicate);
archivedPersons.setPredicate(predicate);
state = 2;
}

//=========== Filtered Leave Application List Accessors ============================================================
Expand Down Expand Up @@ -250,6 +269,7 @@ public void redoAddressBook() {
@Override
public void commitAddressBook() {
versionedAddressBook.commit();
versionedArchiveList.commit();
}

@Override
Expand Down Expand Up @@ -346,4 +366,8 @@ public boolean containsAssignment(String newAssignment, Assignment ignore) {
return true;
}

@Subscribe
private void handleShowHelpEvent(ChangeOnListPickerClickEvent event) {
state = event.getNewSelection();
}
}
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/ui/ListPicker.java
Expand Up @@ -8,6 +8,7 @@
import javafx.scene.control.Button;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.ui.ChangeOnListPickerClickEvent;
import seedu.address.commons.events.ui.ListPickerSelectionChangedEvent;

/**
Expand Down Expand Up @@ -39,6 +40,7 @@ public void handle(ActionEvent e) {
assignmentList.setStyle("-fx-background-color: #95A5A6; -fx-border-color: #95A5A6;");
assignmentList.setDisable(false);
raise(new ListPickerSelectionChangedEvent(2));
raise(new ChangeOnListPickerClickEvent(2));
}
});
// Active button is selected
Expand All @@ -52,6 +54,7 @@ public void handle(ActionEvent e) {
assignmentList.setStyle("-fx-background-color: #95A5A6; -fx-border-color: #95A5A6;");
assignmentList.setDisable(false);
raise(new ListPickerSelectionChangedEvent(1));
raise(new ChangeOnListPickerClickEvent(1));
}
});
// Assignment button is selected
Expand Down
Expand Up @@ -100,6 +100,11 @@ public void addPerson(Person person) {
throw new AssertionError("This method should not be called.");
}

@Override
public int getState() {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean alreadyContainsUsername(String username, Person ignore) {
throw new AssertionError("This method should not be called.");
Expand Down Expand Up @@ -141,6 +146,11 @@ public void deletePerson(Person target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteFromArchive(Person target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void restorePerson(Person target) {
throw new AssertionError("This method should not be called.");
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/seedu/address/logic/commands/AddCommandTest.java
Expand Up @@ -118,6 +118,11 @@ public void addPerson(Person person) {
throw new AssertionError("This method should not be called.");
}

@Override
public int getState() {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean alreadyContainsUsername(String username, Person ignore) {
return false;
Expand Down Expand Up @@ -158,6 +163,11 @@ public void deletePerson(Person target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteFromArchive(Person target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void restorePerson(Person target) {
throw new AssertionError("This method should not be called.");
Expand Down