Skip to content

Commit

Permalink
Merge pull request #174 from jroberts91/1.4Features
Browse files Browse the repository at this point in the history
Archive, Restore features
  • Loading branch information
jroberts91 committed Nov 8, 2018
2 parents b486ebf + c1c83d9 commit fa4ac22
Show file tree
Hide file tree
Showing 23 changed files with 283 additions and 20 deletions.
3 changes: 3 additions & 0 deletions docs/team/joshuarobert.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Lastly, if there is a need to restore the employee back to the `activelist` a us

=== Minor enhancement:

==== Features:


==== Code contributed:
** [https://github.com[Functional code]]
** [https://github.com[Test code]]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.events.BaseEvent;

/**
* Indicates that the leave list command has been run
*/
public class ArchiveListEvent extends BaseEvent {
public ArchiveListEvent() {
}

@Override
public String toString() {
return "archivelist";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ public class JumpToListRequestEvent extends BaseEvent {

public final int targetIndex;

public JumpToListRequestEvent(Index targetIndex) {
public final int listPicker;

public JumpToListRequestEvent(Index targetIndex, int listPicker) {
this.targetIndex = targetIndex.getZeroBased();
this.listPicker = listPicker;
}

@Override
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/seedu/address/logic/commands/ArchiveCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.events.ui.ArchiveListEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;

/**
* Lists archived Persons in the address book to the user.
*/
public class ArchiveCommand extends Command {

public static final String COMMAND_WORD = "archive";

public static final String MESSAGE_SUCCESS = "Listed all archived Persons";


@Override
public CommandResult runBody(Model model, CommandHistory history) {
requireNonNull(model);
model.updateArchivedPersonList(PREDICATE_SHOW_ALL_PERSONS);
EventsCenter.getInstance().post(new ArchiveListEvent());
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class AutoCompleteCommandHelper {
private static String[] commandWordList = {
AddCommand.COMMAND_WORD,
ArchiveCommand.COMMAND_WORD,
ClearCommand.COMMAND_WORD,
DeleteCommand.COMMAND_WORD,
EditCommand.COMMAND_WORD,
Expand All @@ -22,6 +23,7 @@ public class AutoCompleteCommandHelper {
ModifyPermissionCommand.COMMAND_WORD,
PasswordCommand.COMMAND_WORD,
RedoCommand.COMMAND_WORD,
RestoreCommand.COMMAND_WORD,
SelectCommand.COMMAND_WORD,
SelfEditCommand.COMMAND_WORD,
UndoCommand.COMMAND_WORD,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import seedu.address.logic.CommandHistory;
import seedu.address.model.AddressBook;
import seedu.address.model.ArchiveList;
import seedu.address.model.Model;
import seedu.address.model.person.User;

Expand All @@ -19,6 +20,7 @@ public class ClearCommand extends Command {
public CommandResult runBody(Model model, CommandHistory history) {
requireNonNull(model);
model.resetData(new AddressBook());
model.resetArchive(new ArchiveList());
model.commitAddressBook();
return new CommandResult(MESSAGE_SUCCESS);
}
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/seedu/address/logic/commands/RestoreCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import java.util.List;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.permission.Permission;
import seedu.address.model.person.Person;

/**
* Deletes a person identified using it's displayed index from the address book.
*/
public class RestoreCommand extends Command {

public static final String COMMAND_WORD = "restore";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the archived person list.\n"
+ "Adds the selected person to the active person list. \n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Restored Person: %1$s";
//public static final String MESSAGE_DELETE_SELF_FAILURE = "You cannot delete yourself";

private final Index targetIndex;

public RestoreCommand(Index targetIndex) {
requiredPermission.addPermissions(Permission.RESTORE_EMPLOYEE);
this.targetIndex = targetIndex;
}

@Override
public CommandResult runBody(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getArchivedPersonList();

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

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

model.restorePerson(personToRestore);
model.commitAddressBook();
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToRestore));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof RestoreCommand // instanceof handles nulls
&& targetIndex.equals(((RestoreCommand) other).targetIndex)); // state check
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CommandResult runBody(Model model, CommandHistory history) throws Command
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex));
EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex, 1));
return new CommandResult(String.format(MESSAGE_SELECT_PERSON_SUCCESS, targetIndex.getOneBased()));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import seedu.address.logic.commands.AddAssignmentCommand;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ArchiveCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteAssignmentCommand;
Expand All @@ -28,6 +29,7 @@
import seedu.address.logic.commands.ModifyPermissionCommand;
import seedu.address.logic.commands.PasswordCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.RestoreCommand;
import seedu.address.logic.commands.SelectCommand;
import seedu.address.logic.commands.SelfEditCommand;
import seedu.address.logic.commands.UndoCommand;
Expand Down Expand Up @@ -64,6 +66,9 @@ public Command parseCommand(String userInput) throws ParseException {
case AddCommand.COMMAND_WORD:
return new AddCommandParser().parse(arguments);

case ArchiveCommand.COMMAND_WORD:
return new ArchiveCommand();

case EditCommand.COMMAND_WORD:
return new EditCommandParser().parse(arguments);

Expand Down Expand Up @@ -97,6 +102,9 @@ public Command parseCommand(String userInput) throws ParseException {
case RedoCommand.COMMAND_WORD:
return new RedoCommand();

case RestoreCommand.COMMAND_WORD:
return new RestoreCommandParser().parse(arguments);

case ModifyPermissionCommand.COMMAND_WORD:
return new ModifyPermissionCommandParser().parse(arguments);

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/logic/parser/RestoreCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.RestoreCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new DeleteCommand object
*/
public class RestoreCommandParser implements Parser<RestoreCommand> {

/**
* Parses the given {@code String} of arguments in the context of the RestoreCommand
* and returns an RestoreCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public RestoreCommand parse(String args) throws ParseException {
try {
Index index = ParserUtil.parseIndex(args);
return new RestoreCommand(index);
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, RestoreCommand.MESSAGE_USAGE), pe);
}
}

}
15 changes: 15 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public interface Model {
/** Clears existing backing model and replaces with the provided new data. */
void resetData(ReadOnlyAddressBook newData);

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

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

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

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

/**
* Adds the given person.
* {@code person} must not already exist in the address book.
Expand Down Expand Up @@ -89,6 +98,12 @@ public interface Model {
*/
void updateFilteredPersonList(Predicate<Person> predicate);

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

/** Returns an unmodifiable view of the filtered leave application list */
ObservableList<LeaveApplicationWithEmployee> getFilteredLeaveApplicationList();

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public void resetData(ReadOnlyAddressBook newData) {
indicateArchivedListChanged();
}

@Override
public void resetArchive(ReadOnlyArchiveList newData) {
versionedArchiveList.resetData(newData);
indicateAddressBookChanged();
indicateAssignmentListChanged();
indicateArchivedListChanged();
}

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

@Override
public void restorePerson(Person target) {
versionedArchiveList.removePerson(target);
versionedAddressBook.addPerson(target);
indicateAddressBookChanged();
indicateArchivedListChanged();
}

@Override
public void addPerson(Person person) {
if (alreadyContainsUsername(person.getUsername().username, null)) {
Expand Down Expand Up @@ -177,6 +193,12 @@ public void updateFilteredPersonList(Predicate<Person> predicate) {
filteredPersons.setPredicate(predicate);
}

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

//=========== Filtered Leave Application List Accessors ============================================================

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum Permission {
ADD_EMPLOYEE,
REMOVE_EMPLOYEE,
EDIT_EMPLOYEE,
RESTORE_EMPLOYEE,

VIEW_EMPLOYEE_LEAVE,
APPROVE_LEAVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public Set<Permission> getPreset() {
preset.add(Permission.VIEW_PROJECT);
preset.add(Permission.ASSIGN_PROJECT);
preset.add(Permission.ASSIGN_PERMISSION);
preset.add(Permission.RESTORE_EMPLOYEE);
return preset;
}
},
Expand All @@ -49,6 +50,7 @@ public Set<Permission> getPreset() {
preset.add(Permission.CREATE_PROJECT);
preset.add(Permission.VIEW_PROJECT);
preset.add(Permission.ASSIGN_PROJECT);
preset.add(Permission.RESTORE_EMPLOYEE);
return preset;
}
},
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/ui/ListPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,16 @@ public void handle(ActionEvent e) {
});
registerAsAnEventHandler(this);
}

public void setArchiveList() {
archiveList.setStyle("-fx-background-color: #28B463; -fx-border-color: #28B463;");
activeList.setStyle("-fx-background-color: #95A5A6; -fx-border-color: #95A5A6;");
assignmentList.setStyle("-fx-background-color: #95A5A6; -fx-border-color: #95A5A6;");
}

public void setActiveList() {
activeList.setStyle("-fx-border-color: #28B463; -fx-background-color: #28B463;");
archiveList.setStyle("-fx-background-color: #95A5A6; -fx-border-color: #95A5A6;");
assignmentList.setStyle("-fx-background-color: #95A5A6; -fx-border-color: #95A5A6;");
}
}
Loading

0 comments on commit fa4ac22

Please sign in to comment.