diff --git a/README.adoc b/README.adoc index 8df95e059513..bc6c524c683b 100644 --- a/README.adoc +++ b/README.adoc @@ -2,9 +2,7 @@ ifdef::env-github,env-browser[:relfileprefix: docs/] https://travis-ci.org/CS2113-AY1819S1-T16-2/main[image:https://travis-ci.org/CS2113-AY1819S1-T16-2/main.svg?branch=master[Build Status]] -https://ci.appveyor.com/project/damithc/addressbook-level4[image:https://ci.appveyor.com/api/projects/status/3boko2x2vr5cc3w2?svg=true[Build status]] https://coveralls.io/github/CS2113-AY1819S1-T16-2/main[image:https://coveralls.io/repos/github/CS2113-AY1819S1-T16-2/main/badge.svg?branch=master[Coverage Status]] -https://www.codacy.com/app/damith/addressbook-level4?utm_source=github.com&utm_medium=referral&utm_content=se-edu/addressbook-level4&utm_campaign=Badge_Grade[image:https://api.codacy.com/project/badge/Grade/fc0b7775cf7f4fdeaf08776f3d8e364a[Codacy Badge]] ifdef::env-github[] diff --git a/_reposense/config.json b/_reposense/config.json index cf04084dcea4..851ca3add068 100644 --- a/_reposense/config.json +++ b/_reposense/config.json @@ -4,7 +4,7 @@ { "githubId": "jieliangang", "displayName": "ANG...ANG", - "authorNames": ["jieliangang", "jlang"] + "authorNames": ["jieliangang", "jlang", "Jie Liang Ang"] }, { "githubId": "fr3ddy4", diff --git a/build.gradle b/build.gradle index f8e614f8b49b..eec4cb76fe8b 100644 --- a/build.gradle +++ b/build.gradle @@ -82,7 +82,7 @@ dependencies { } shadowJar { - archiveName = 'addressbook.jar' + archiveName = 'proManage.jar' destinationDir = file("${buildDir}/jar/") } diff --git a/docs/DeveloperGuide.adoc b/docs/DeveloperGuide.adoc index 0ee226a3300a..ceb38cde5668 100644 --- a/docs/DeveloperGuide.adoc +++ b/docs/DeveloperGuide.adoc @@ -254,7 +254,15 @@ image::SortNewCommand1StateListDiagram.png[width="650"] image::SortSequenceDiagram.png[width="650"] +==== Design Considerations +===== Committing Event List after sorting + * **Alternative 1 (current choice):** Commits and saves the entire event list. +** Pros: Easy to implement and able to use undo to the previous state. +** Cons: May have performance issues in terms of memory usage. +* **Alternative 2:** Does not commit the event list. +** Pros: Will use less memory. +** Cons: Unable to use undo function to revert back to the previous view. // end::Sorting[] @@ -281,11 +289,13 @@ Storing only the *name* of `Person` in the `Attendees` object of `Event` saves m We can also have a summarized content of persons (their names) involved in an event. Obtaining the full information of the list of persons in a particular event is not required in the current version of project, but can still be implemented easily with the current `Attendee` structure. This can be done by filtering through the address book based on the person names present in `Attendees`. Thus, there is no need to store any event information in the `Person` object. +Implementation of RemoveCommand is similar to InviteCommand, but removes persons from attendees of events instead. + ==== Execution of Command Given below is an example usage scenario and how the invite mechanism works. -Step 1. The user executes `invite 1 to/1` to invite the 1st person in the address book to the 1st event in the event list. The command text is passed to an instance of the `LogicManager` class. +Step 1. The user inputs `invite 1 to/1` to invite the 1st person in the address book to the 1st event in the event list. The command text is passed to an instance of the `LogicManager` class. Step 2. The `LogicManager` instance calls `AddressBookParser#parsecommand`, which parses the `invite` command phrase. @@ -347,38 +357,6 @@ The same concept can also be applied to events, being able to invite one person Implementation of this additional feature would require changes to both `InviteCommandParser` and `InviteCommand#execute`. // end::Invite[] -// tag:: Sorting[] - -=== Event Sorting - -==== Current Implementation - -The sort mechanism is facilitated by Comparator. -When the sort method for FXObservableList is called, it will take a Comparator object to be used for sorting the list. -The comparator is able to take in two Event class objects and compare the relative parameter values. -The parameter can be `EventName`, `Date` & `StartTime`. -To allow sorting of these parameters, there are three types of comparators. - - -image::SortNewCommand1StateListDiagram.png[width="650"] - -The following sequence diagram shows how the sort operation works: - -image::SortSequenceDiagram.png[width="650"] - - -==== Design Considerations - -===== Committing Event List after sorting - -* **Alternative 1 (current choice):** Commits and saves the entire event list. -** Pros: Easy to implement and able to use undo to the previous state. -** Cons: May have performance issues in terms of memory usage. -* **Alternative 2:** Does not commit the event list. -** Pros: Will use less memory. -** Cons: Unable to use undo function to revert back to the previous view. - -// end::Sorting[] // tag::dataencryption[] diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4d382bebb522..42308e25abcf 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -87,20 +87,29 @@ Example: + ==== Listing all personnel of the company : 'list' -Shows a list of personnel in the company + +Shows a list of all the personnel, , all the events, or those people in the specific department in the project team + Format/Prompts: + -Enter a command: `list` + +Enter command to list all people: `list all people` + +Enter a command to list all the events: `list all events` + +Enter a command to list people in the specific `DEPARTMENT`: `list dep DEPARTMENT` + +Example: + +`list dep Admin` + +`list dep Admin Finance` + ==== Editing an employee : 'edit' Edits the details of the employee: + Format/Prompts: + -Enter a command: `edit LIST_INDEX n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS dep/DEPARTMENT t/TAG…​` +Enter a command: `edit LIST_INDEX p/PHONE_NUMBER e/EMAIL a/ADDRESS dep/DEPARTMENT t/TAG…​` **** * Edits the event at the specified `INDEX`. The index refers to the index number shown in the displayed event list. The index *must be a positive integer* 1, 2, 3, ... + * At least one of the optional fields must be provided. +* Name is not editable * Existing values will be updated to the input values. * When editing tags, the existing tags of the person will be removed i.e adding of tags is not cumulative. * You can remove all the person’s tags by typing t/ without specifying any tags after it. @@ -133,14 +142,14 @@ Format: `schedule` Add employees to the project event at the respective specified INDEX. The index refers to the index number shown in the displayed person and event list. The index must be a positive integer 1, 2, 3... + -Format: `invite LIST_INDEX to/SCHEDULE_INDEX` + +Format: `invite PERSON_INDEX to/EVENT_INDEX` + Example: invite 1 to/2 ==== Remove employee: `remove` Removes an employee from the project event. + -Format/Prompts: `remove SCHEDULE_INDEX n/NAME` + -Example: remove 10 n/John Doe +Format/Prompts: `remove PERSON_INDEX from/EVENT_INDEX` + +Example: remove 1 from/2 ==== Modifying an event: `editEvent` @@ -330,6 +339,19 @@ Example: + `n/Board Meeting d/Weekly Meeting l/Conference Room 1 date/2018-09-28 s/12:00 e/23:59 ` + Creates an event named Board Meeting. +==== Listing all personnel of the company : 'list' + +Shows a list of all the personnel, , all the events, or those people in the specific department in the project team + +Format/Prompts: + + +Enter command to list all people: `list all people` + +Enter a command to list all the events: `list all events` + +Enter a command to list people in the specific `DEPARTMENT`: `list dep DEPARTMENT` + +Example: + +`list dep Admin` + +`list dep Admin Finance` + ==== Listing all events: `schedule` Display the full list of events in the project. + @@ -345,8 +367,8 @@ Example: invite 1 to/2 ==== Remove employee: `remove` Removes an employee from the project event. + -Format/Prompts: `remove SCHEDULE_INDEX n/NAME` + -Example: remove 10 n/John Doe +Format/Prompts: `remove EVENT_INDEX from/PERSON_INDEX` + +Example: remove 1 from/2 ==== Modifying an event: `editEvent` @@ -356,7 +378,7 @@ index must be a positive integer 1, 2, 3... + Input nil if it is not the field to be changed. + Format/Prompts: + Enter a command: `editEvent SCHEDULE_INDEX` + -Enter event details: `n/NAME d/DESCRIPTION l/LOCATION date/DATE(DDMMYY) s/START TIME e/END TIME` + +Enter event details: `d/DESCRIPTION l/LOCATION date/DATE(DDMMYY) s/START TIME e/END TIME` + **** * Edits the event at the specified `INDEX`. The index refers to the index number shown in the displayed event list. The @@ -520,6 +542,19 @@ This section is meant for Employees. Employees can only access his/her own departments' events. ==== +==== Listing all personnel of the company : 'list' + +Shows a list of all the personnel, , all the events, or those people in the specific department in the project team + +Format/Prompts: + + +Enter command to list all people: `list all people` + +Enter a command to list all the events: `list all events` + +Enter a command to list people in the specific `DEPARTMENT`: `list dep DEPARTMENT` + +Example: + +`list dep Admin` + +`list dep Admin Finance` + ==== Listing all events: `schedule` Display the full list of events in the project. + @@ -558,7 +593,7 @@ Task with id 1 is submitted as complete. * *List* : `list` -* *Edit* : `edit LIST_INDEX n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS dep/DEPARTMENT t/TAG…​` +* *Edit* : `edit LIST_INDEX p/PHONE_NUMBER e/EMAIL a/ADDRESS dep/DEPARTMENT t/TAG…​` * *Delete* : `delete LIST_INDEX` @@ -567,9 +602,9 @@ Task with id 1 is submitted as complete. * *Schedule* : `schedule` -* *Invite* : `invite LIST_INDEX to/SCHEDULE_INDEX` +* *Invite* : `invite PERSON_INDEX to/EVENT_INDEX` -* *Remove* : `remove SCHEDULE_INDEX n/NAME` +* *Remove* : `remove PERSON_INDEX n/EVENT_INDEX` * *editEvent* : `n/NAME d/DESCRIPTION l/LOCATION date/DATE s/START TIME e/END TIME ` diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index b4bfd19ae21b..9d4df1494d16 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -10,7 +10,6 @@ import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; - import seedu.address.commons.core.Config; import seedu.address.commons.core.EventsCenter; import seedu.address.commons.core.LogsCenter; @@ -47,7 +46,7 @@ */ public class MainApp extends Application { - public static final Version VERSION = new Version(1, 1, 0, true); + public static final Version VERSION = new Version(1, 2, 1, true); private static final Logger logger = LogsCenter.getLogger(MainApp.class); @@ -69,7 +68,6 @@ public void init() throws Exception { UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath()); userPrefs = initPrefs(userPrefsStorage); - //TODO: Convert addressbookstorage to person storage AddressBookStorage addressBookStorage = new XmlAddressBookStorage(userPrefs.getAddressBookFilePath()); EventStorage eventStorage = new XmlEventStorage(userPrefs.getEventlistPath()); storage = new StorageManager(addressBookStorage, eventStorage, userPrefsStorage); @@ -83,8 +81,10 @@ public void init() throws Exception { ui = new UiManager(logic, config, userPrefs); initEventsCenter(); + } + /** * Returns a {@code ModelManager} with the data from {@code storage}'s address book and {@code userPrefs}.
* The data from the sample address book will be used instead if {@code storage}'s address book is not found, diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index ac45200865f0..9e2beba79479 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -8,7 +8,7 @@ import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.logic.parser.AddressBookParser; +import seedu.address.logic.parser.ProManageParser; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.Model; import seedu.address.model.event.Event; @@ -22,19 +22,20 @@ public class LogicManager extends ComponentManager implements Logic { private final Model model; private final CommandHistory history; - private final AddressBookParser addressBookParser; + private ProManageParser proManageParser; public LogicManager(Model model) { this.model = model; history = new CommandHistory(); - addressBookParser = new AddressBookParser(); + this.proManageParser = new ProManageParser(); } + @Override public CommandResult execute(String commandText) throws CommandException, ParseException { logger.info("----------------[USER COMMAND][" + commandText + "]"); try { - Command command = addressBookParser.parseCommand(commandText); + Command command = proManageParser.parseCommand(commandText); return command.execute(model, history); } finally { history.add(commandText); diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 0bc770332a66..d51daaba087e 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -40,10 +40,10 @@ public CommandResult execute(Model model, CommandHistory history) throws Command throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } - // TODO: DELETE EMPLOYEE FROM EVENT ATTENDEE LIST TOO Person personToDelete = lastShownList.get(targetIndex.getZeroBased()); model.deletePerson(personToDelete); + model.removePersonFromAllEvents(personToDelete); model.commitAddressBook(); return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete)); } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 542a462c3064..25d92658e97d 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -4,7 +4,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -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; @@ -38,9 +37,8 @@ public class EditCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " + "by the index number used in the displayed person list. " - + "Existing values will be overwritten by the input values.\n" + + "Existing values will be overwritten by the input values. Name is NOT editable\n" + "Parameters: INDEX (must be a positive integer) " - + "[" + PREFIX_NAME + "NAME] " + "[" + PREFIX_PHONE + "PHONE] " + "[" + PREFIX_EMAIL + "EMAIL] " + "[" + PREFIX_ADDRESS + "ADDRESS] " @@ -99,7 +97,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command private static Person createEditedPerson(Person personToEdit, EditPersonDescriptor editPersonDescriptor) { assert personToEdit != null; - Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName()); + Name name = personToEdit.getName(); Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); @@ -107,7 +105,7 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedDepartment, updatedTags); + return new Person(name, updatedPhone, updatedEmail, updatedAddress, updatedDepartment, updatedTags); } @Override @@ -133,7 +131,6 @@ public boolean equals(Object other) { * corresponding field value of the person. */ public static class EditPersonDescriptor { - private Name name; private Phone phone; private Email email; private Address address; @@ -148,7 +145,6 @@ public EditPersonDescriptor() {} * A defensive copy of {@code tags} is used internally. */ public EditPersonDescriptor(EditPersonDescriptor toCopy) { - setName(toCopy.name); setPhone(toCopy.phone); setEmail(toCopy.email); setAddress(toCopy.address); @@ -161,15 +157,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(name, phone, email, address, department, tags); - } - - public void setName(Name name) { - this.name = name; - } - - public Optional getName() { - return Optional.ofNullable(name); + return CollectionUtil.isAnyNonNull(phone, email, address, department, tags); } public void setPhone(Phone phone) { @@ -236,8 +224,7 @@ public boolean equals(Object other) { // state check EditPersonDescriptor e = (EditPersonDescriptor) other; - return getName().equals(e.getName()) - && getPhone().equals(e.getPhone()) + return getPhone().equals(e.getPhone()) && getEmail().equals(e.getEmail()) && getAddress().equals(e.getAddress()) && getDepartment().equals(e.getDepartment()) diff --git a/src/main/java/seedu/address/logic/commands/InviteCommand.java b/src/main/java/seedu/address/logic/commands/InviteCommand.java index 755fff3fe7d8..f177ea3370e1 100644 --- a/src/main/java/seedu/address/logic/commands/InviteCommand.java +++ b/src/main/java/seedu/address/logic/commands/InviteCommand.java @@ -3,7 +3,6 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_TO; -import java.time.LocalDate; import java.util.List; import seedu.address.commons.core.Messages; @@ -12,12 +11,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.event.Attendees; -import seedu.address.model.event.Description; -import seedu.address.model.event.EndTime; import seedu.address.model.event.Event; -import seedu.address.model.event.EventName; -import seedu.address.model.event.Location; -import seedu.address.model.event.StartTime; import seedu.address.model.person.Person; //@@author jieliangang @@ -68,7 +62,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command throw new CommandException(MESSAGE_DUPLICATE_PERSON); } - Event updatedEvent = updateList(event, personName); + Event updatedEvent = event.addPersonToAttendee(personName); model.updateEvent(event, updatedEvent); model.commitAddressBook(); @@ -76,25 +70,6 @@ public CommandResult execute(Model model, CommandHistory history) throws Command return new CommandResult(String.format(MESSAGE_INVITE_PERSON_SUCCESS, personName, event.getEventName())); } - /** - * Add new name to an event attendees list. - * - * @param event The event to be updated. - * @param personName The person's name to be added to the attendees list. - * @return An updated event with the person's name in the attendees list. - */ - private static Event updateList(Event event, String personName) { - assert event != null; - Attendees updatedAttendee = event.getAttendees().addName(personName); - EventName eventName = event.getEventName(); - Description description = event.getDescription(); - Location location = event.getLocation(); - StartTime startTime = event.getStartTime(); - EndTime endTime = event.getEndTime(); - LocalDate date = event.getDate(); - - return new Event(eventName, description, date, startTime, endTime, location, updatedAttendee); - } @Override public boolean equals(Object other) { diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index f37070351ddc..704c4beec812 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -1,8 +1,9 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ALL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ALL_PEOPLE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_LIST_DEPARTMENT; +import static seedu.address.model.EventModel.PREDICATE_SHOW_ALL_EVENTS; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import seedu.address.commons.core.Messages; @@ -19,14 +20,16 @@ public class ListCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Lists all persons by the given parameter\n" + "Parameters: " - + PREFIX_DEPARTMENT + " DEPARTMENT " - + "or " + PREFIX_ALL + "\n" - + "Example: " + COMMAND_WORD + " " + PREFIX_DEPARTMENT + " Admin"; + + PREFIX_LIST_DEPARTMENT + " DEPARTMENT " + + "or " + PREFIX_ALL_PEOPLE + "\n" + + "Example: " + COMMAND_WORD + " " + PREFIX_LIST_DEPARTMENT + " Admin"; - public static final String MESSAGE_SUCCESS = "All persons listed!"; + public static final String MESSAGE_SUCCESS_PEOPLE = "All people listed!"; + public static final String MESSAGE_SUCCESS_EVENT = "All events listed!"; public static final String LIST_KEY_DEPARTMENT = "dep"; - public static final String LIST_KEY_ALL = "all"; + public static final String LIST_KEY_ALL = "all people"; + public static final String LIST_KEY_EVENT = "all events"; private final String listKey; private final DepartmentContainsKeywordsPredicate predicate; @@ -42,16 +45,24 @@ public ListCommand(String sortByParam, DepartmentContainsKeywordsPredicate predi public CommandResult execute(Model model, CommandHistory history) { requireNonNull(model); + String message = null; + switch (listKey) { case (LIST_KEY_DEPARTMENT): model.updateFilteredPersonList(predicate); return new CommandResult( String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); + + case (LIST_KEY_EVENT): model.updateFilteredEventList(PREDICATE_SHOW_ALL_EVENTS); + message = MESSAGE_SUCCESS_EVENT; + break; case (LIST_KEY_ALL): model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + message = MESSAGE_SUCCESS_PEOPLE; break; default: } + return new CommandResult(message); + - return new CommandResult(MESSAGE_SUCCESS); } @Override diff --git a/src/main/java/seedu/address/logic/commands/LoginCommand.java b/src/main/java/seedu/address/logic/commands/LoginCommand.java new file mode 100644 index 000000000000..37d9788c79e7 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/LoginCommand.java @@ -0,0 +1,42 @@ +package seedu.address.logic.commands; + +import seedu.address.logic.CommandHistory; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.parser.CommandsParser; +import seedu.address.logic.parser.EmployeeParser; +import seedu.address.logic.parser.ManagerParser; +import seedu.address.model.Model; + +/** + * Login the person into ProManage + */ +public class LoginCommand extends Command { + public static final String COMMAND_WORD = "login"; + private static final String KEY_MANAGER = "manager"; + private static final String KEY_EMPLOYEE = "employee"; + private static final String MESSAGE_INVALID_LOGIN = "Login identity should be either the following:" + + "\nmanager\nempolyee"; + private static final String MESSAGE_SUCCESS = "Successfully login as %s"; + + private final String loginIdentity; + + public LoginCommand(String arguments) { + this.loginIdentity = arguments; + } + + public CommandsParser getParser() throws CommandException { + switch (loginIdentity) { + case KEY_MANAGER: + return new ManagerParser(); + case KEY_EMPLOYEE: + return new EmployeeParser(); + default: + throw new CommandException(MESSAGE_INVALID_LOGIN); + } + } + + @Override + public CommandResult execute(Model model, CommandHistory history) { + return new CommandResult(String.format(MESSAGE_SUCCESS, loginIdentity)); + } +} diff --git a/src/main/java/seedu/address/logic/commands/RemoveCommand.java b/src/main/java/seedu/address/logic/commands/RemoveCommand.java new file mode 100644 index 000000000000..e662769ff31a --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/RemoveCommand.java @@ -0,0 +1,85 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_FROM; + +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.event.Attendees; +import seedu.address.model.event.Event; +import seedu.address.model.person.Person; + + +//@@author jieliangang +/** + * Removes an existing person from an existing event. + */ +public class RemoveCommand extends Command { + + public static final String COMMAND_WORD = "remove"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Removes an existing person from an existing event " + + "by the index number used in the displayed person list and displayed event list.\n" + + "Parameters: INDEX (must be a positive integer) " + + PREFIX_FROM + "INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 1 " + PREFIX_FROM + "1"; + + public static final String MESSAGE_REMOVE_PERSON_SUCCESS = "Removed Person: %1$s from %2$s"; + public static final String MESSAGE_ABSENT_PERSON = "This person is not originally in the event's attendee list."; + public static final String MESSAGE_ATTENDEE_EMPTY = "The event selected has no invited persons."; + + private final Index indexEvent; + private final Index indexPerson; + + public RemoveCommand(Index indexPerson, Index indexEvent) { + this.indexPerson = indexPerson; + this.indexEvent = indexEvent; + } + + @Override + public CommandResult execute(Model model, CommandHistory history) throws CommandException { + requireNonNull(model); + List lastShownPersonList = model.getFilteredPersonList(); + List lastShownEventList = model.getFilteredEventList(); + + if (indexPerson.getZeroBased() >= lastShownPersonList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + if (indexEvent.getZeroBased() >= lastShownEventList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_EVENT_DISPLAYED_INDEX); + } + Person person = lastShownPersonList.get(indexPerson.getZeroBased()); + Event event = lastShownEventList.get(indexEvent.getZeroBased()); + + String personName = person.getName().toString(); + Attendees attendeesList = event.getAttendees(); + + if (attendeesList.isSetEmpty()) { + throw new CommandException(MESSAGE_ATTENDEE_EMPTY); + } else if (!attendeesList.hasName(personName)) { + throw new CommandException(MESSAGE_ABSENT_PERSON); + } + + Event updatedEvent = event.removePersonFromAttendee(personName); + + model.updateEvent(event, updatedEvent); + model.commitAddressBook(); + + return new CommandResult(String.format(MESSAGE_REMOVE_PERSON_SUCCESS, personName, event.getEventName())); + } + + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof RemoveCommand // instanceof handles nulls + && indexEvent.equals(((RemoveCommand) other).indexEvent)) + && indexPerson.equals(((RemoveCommand) other).indexPerson); // state check + } +} diff --git a/src/main/java/seedu/address/logic/commands/SelectCommand.java b/src/main/java/seedu/address/logic/commands/SelectCommand.java index f5e8c1a8722e..d35402458a2e 100644 --- a/src/main/java/seedu/address/logic/commands/SelectCommand.java +++ b/src/main/java/seedu/address/logic/commands/SelectCommand.java @@ -11,8 +11,10 @@ import seedu.address.logic.CommandHistory; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.event.EventContainsAttendeePredicate; import seedu.address.model.person.Person; +//@@author jieliangang /** * Selects a person identified using it's displayed index from the address book. */ @@ -21,7 +23,8 @@ public class SelectCommand extends Command { public static final String COMMAND_WORD = "select"; public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Selects the person identified by the index number used in the displayed person list.\n" + + ": Selects the person identified by the index number used in the displayed person list " + + "and display events the person is attending\n" + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1"; @@ -43,6 +46,12 @@ public CommandResult execute(Model model, CommandHistory history) throws Command throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } + Person person = filteredPersonList.get(targetIndex.getZeroBased()); + String personName = person.getName().toString(); + EventContainsAttendeePredicate predicate = new EventContainsAttendeePredicate(personName); + model.updateFilteredEventList(predicate); + model.sortByDate(); + EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex)); return new CommandResult(String.format(MESSAGE_SELECT_PERSON_SUCCESS, targetIndex.getOneBased())); diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 684c106a70cf..fd9ab0ec1595 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -21,6 +21,7 @@ import seedu.address.logic.commands.InviteCommand; import seedu.address.logic.commands.ListCommand; import seedu.address.logic.commands.RedoCommand; +import seedu.address.logic.commands.RemoveCommand; import seedu.address.logic.commands.SelectCommand; import seedu.address.logic.commands.SortCommand; import seedu.address.logic.commands.UndoCommand; @@ -89,6 +90,9 @@ public Command parseCommand(String userInput) throws ParseException { case InviteCommand.COMMAND_WORD: return new InviteCommandParser().parse(arguments); + case RemoveCommand.COMMAND_WORD: + return new RemoveCommandParser().parse(arguments); + case HistoryCommand.COMMAND_WORD: return new HistoryCommand(); diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 41a6fb856d27..a7db03b84eea 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -15,9 +15,13 @@ public class CliSyntax { public static final Prefix PREFIX_START_DATE = new Prefix("s/"); public static final Prefix PREFIX_END_DATE = new Prefix("e/"); public static final Prefix PREFIX_DESCRIPTION = new Prefix("d/"); - public static final Prefix PREFIX_DEPARTMENT = new Prefix("dep"); + public static final Prefix PREFIX_DEPARTMENT = new Prefix("dep/"); + public static final Prefix PREFIX_LIST_DEPARTMENT= new Prefix("dep"); public static final Prefix PREFIX_LOCATION = new Prefix("l/"); public static final Prefix PREFIX_TO = new Prefix("to/"); - public static final Prefix PREFIX_ALL = new Prefix("all"); + public static final Prefix PREFIX_ALL_PEOPLE = new Prefix("all people"); + public static final Prefix PREFIX_ALL_EVENTS = new Prefix("all events"); + public static final Prefix PREFIX_FROM = new Prefix("from/"); + } diff --git a/src/main/java/seedu/address/logic/parser/CommandsParser.java b/src/main/java/seedu/address/logic/parser/CommandsParser.java new file mode 100644 index 000000000000..89fcf96af7e1 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/CommandsParser.java @@ -0,0 +1,33 @@ +package seedu.address.logic.parser; + +import java.util.regex.Pattern; + +import seedu.address.logic.commands.Command; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses user input. + */ +public abstract class CommandsParser { + + /** + * Used for initial separation of command word and args. + */ + protected static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?\\S+)(?.*)"); + + + /** + * Parses user input into command for execution. + * + * @param userInput full user input string + * @return the command based on the user input + * @throws ParseException if the user input does not conform the expected format + */ + public abstract Command parseCommand(String userInput) throws ParseException; + + /** + * Returns identity of the parser type + */ + public abstract String getIdentity(); + +} diff --git a/src/main/java/seedu/address/logic/parser/DefaultParser.java b/src/main/java/seedu/address/logic/parser/DefaultParser.java new file mode 100644 index 000000000000..b9a594be2eb7 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/DefaultParser.java @@ -0,0 +1,120 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; + +import java.util.regex.Matcher; + +import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.AddEventCommand; +import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.DeleteEventCommand; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.commands.EditEventCommand; +import seedu.address.logic.commands.ExitCommand; +import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.HelpCommand; +import seedu.address.logic.commands.HistoryCommand; +import seedu.address.logic.commands.InviteCommand; +import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.LoginCommand; +import seedu.address.logic.commands.RedoCommand; +import seedu.address.logic.commands.RemoveCommand; +import seedu.address.logic.commands.SelectCommand; +import seedu.address.logic.commands.SortCommand; +import seedu.address.logic.commands.UndoCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses user input. + */ +public class DefaultParser extends CommandsParser { + + public static final String IDENTITY = "Default"; + + /** + * Parses user input into command for execution. + * + * @param userInput full user input string + * @return the command based on the user input + * @throws ParseException if the user input does not conform the expected format + */ + public Command parseCommand(String userInput) throws ParseException { + final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim()); + if (!matcher.matches()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE)); + } + + final String commandWord = matcher.group("commandWord"); + final String arguments = matcher.group("arguments"); + switch (commandWord) { + + case AddCommand.COMMAND_WORD: + return new AddCommandParser().parse(arguments); + + case AddEventCommand.COMMAND_WORD: + return new AddEventCommandParser().parse(arguments); + + case EditCommand.COMMAND_WORD: + return new EditCommandParser().parse(arguments); + + case EditEventCommand.COMMAND_WORD: + return new EditEventCommandParser().parse(arguments); + + case SelectCommand.COMMAND_WORD: + return new SelectCommandParser().parse(arguments); + + case DeleteCommand.COMMAND_WORD: + return new DeleteCommandParser().parse(arguments); + + case DeleteEventCommand.COMMAND_WORD: + return new DeleteEventCommandParser().parse(arguments); + + case ClearCommand.COMMAND_WORD: + return new ClearCommand(); + + case FindCommand.COMMAND_WORD: + return new FindCommandParser().parse(arguments); + + case ListCommand.COMMAND_WORD: + return new ListCommandParser().parse(arguments); + + case SortCommand.COMMAND_WORD: + return new SortCommandParser().parse(arguments); + + case InviteCommand.COMMAND_WORD: + return new InviteCommandParser().parse(arguments); + + case RemoveCommand.COMMAND_WORD: + return new RemoveCommandParser().parse(arguments); + + case HistoryCommand.COMMAND_WORD: + return new HistoryCommand(); + + case ExitCommand.COMMAND_WORD: + return new ExitCommand(); + + case HelpCommand.COMMAND_WORD: + return new HelpCommand(); + + case UndoCommand.COMMAND_WORD: + return new UndoCommand(); + + case RedoCommand.COMMAND_WORD: + return new RedoCommand(); + + case LoginCommand.COMMAND_WORD : + return new LoginCommandParser().parse(arguments); + + default: + throw new ParseException(MESSAGE_UNKNOWN_COMMAND); + } + } + + public String getIdentity() { + return this.IDENTITY; + } + +} diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index e8aa84b22123..2125d866195f 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -5,7 +5,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -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; @@ -34,7 +33,7 @@ public class EditCommandParser implements Parser { public EditCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, + ArgumentTokenizer.tokenize(args, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_DEPARTMENT, PREFIX_TAG); Index index; @@ -46,9 +45,6 @@ public EditCommand parse(String args) throws ParseException { } EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor(); - if (argMultimap.getValue(PREFIX_NAME).isPresent()) { - editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get())); - } if (argMultimap.getValue(PREFIX_PHONE).isPresent()) { editPersonDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get())); } diff --git a/src/main/java/seedu/address/logic/parser/EmployeeParser.java b/src/main/java/seedu/address/logic/parser/EmployeeParser.java new file mode 100644 index 000000000000..d99ee99f20e2 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/EmployeeParser.java @@ -0,0 +1,88 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; + +import java.util.regex.Matcher; + +import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.ExitCommand; +import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.HelpCommand; +import seedu.address.logic.commands.HistoryCommand; +import seedu.address.logic.commands.InviteCommand; +import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.RedoCommand; +import seedu.address.logic.commands.SelectCommand; +import seedu.address.logic.commands.SortCommand; +import seedu.address.logic.commands.UndoCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses user input. + */ +public class EmployeeParser extends CommandsParser { + + public static final String IDENTITY = "Employee"; + + /** + * Parses user input into command for execution. + * + * @param userInput full user input string + * @return the command based on the user input + * @throws ParseException if the user input does not conform the expected format + */ + public Command parseCommand(String userInput) throws ParseException { + final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim()); + if (!matcher.matches()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE)); + } + + final String commandWord = matcher.group("commandWord"); + final String arguments = matcher.group("arguments"); + switch (commandWord) { + + case SelectCommand.COMMAND_WORD: + return new SelectCommandParser().parse(arguments); + + case ClearCommand.COMMAND_WORD: + return new ClearCommand(); + + case FindCommand.COMMAND_WORD: + return new FindCommandParser().parse(arguments); + + case ListCommand.COMMAND_WORD: + return new ListCommandParser().parse(arguments); + + case SortCommand.COMMAND_WORD: + return new SortCommandParser().parse(arguments); + + case InviteCommand.COMMAND_WORD: + return new InviteCommandParser().parse(arguments); + + case HistoryCommand.COMMAND_WORD: + return new HistoryCommand(); + + case ExitCommand.COMMAND_WORD: + return new ExitCommand(); + + case HelpCommand.COMMAND_WORD: + return new HelpCommand(); + + case UndoCommand.COMMAND_WORD: + return new UndoCommand(); + + case RedoCommand.COMMAND_WORD: + return new RedoCommand(); + + default: + throw new ParseException(MESSAGE_UNKNOWN_COMMAND); + } + } + + public String getIdentity() { + return this.IDENTITY; + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ListCommandParser.java b/src/main/java/seedu/address/logic/parser/ListCommandParser.java index fa4840c0df32..7dd40696539d 100644 --- a/src/main/java/seedu/address/logic/parser/ListCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ListCommandParser.java @@ -2,7 +2,9 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import seedu.address.logic.commands.ListCommand; import seedu.address.logic.parser.exceptions.ParseException; @@ -21,9 +23,11 @@ public class ListCommandParser implements Parser { */ @Override public ListCommand parse(String userInput) throws ParseException { - + List showAll = new ArrayList<>(); if (parseAll(userInput)) { - return new ListCommand(ListCommand.LIST_KEY_ALL, null); + return new ListCommand(ListCommand.LIST_KEY_ALL, new DepartmentContainsKeywordsPredicate(showAll)); + } else if (parseEvent(userInput)) { + return new ListCommand(ListCommand.LIST_KEY_EVENT, new DepartmentContainsKeywordsPredicate(showAll)); } else if (parseDep(userInput)) { String relevantInfo = userInput.replaceAll("(?i)dep", ""); @@ -42,7 +46,7 @@ public ListCommand parse(String userInput) throws ParseException { * @return boolean true if it is equal, if not, false */ private boolean parseAll(String userInput) { - return userInput.trim().equalsIgnoreCase("all"); + return userInput.trim().equalsIgnoreCase("all people"); } /** @@ -50,9 +54,17 @@ private boolean parseAll(String userInput) { * @return boolean true if it is equal, if not, false */ private boolean parseDep(String userInput) { - return userInput.trim().split("\\s+")[0].equalsIgnoreCase("dep"); + return userInput.trim().split("\\s+")[0] + .equalsIgnoreCase("dep"); } + /** + * Checks if first word of the userInput is equals to "dep" + * @return boolean true if it is equal, if not, false + */ + private boolean parseEvent(String userInput) { + return userInput.trim().equalsIgnoreCase("all events"); + } /** * Splits the userInput by whitespace and places it into a DepartmentContainsKeywordPredicate * @return a new predicate diff --git a/src/main/java/seedu/address/logic/parser/LoginCommandParser.java b/src/main/java/seedu/address/logic/parser/LoginCommandParser.java new file mode 100644 index 000000000000..8dfa58dba656 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/LoginCommandParser.java @@ -0,0 +1,40 @@ +package seedu.address.logic.parser; + +import seedu.address.logic.commands.LoginCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses user input. + */ +public class LoginCommandParser { + public static final String KEY_MANAGER = "manager"; + public static final String KEY_EMPLOYEE = "employee"; + + private static final String MESSAGE_INVALID_LOGIN = "Login identity should be either the following:" + + "\nmanager\nemployee" + + "\nExample: login manager"; + + + /** + * Parses user input into command for execution. + * + * @param args full user input string + * @return the command based on the user input + * @throws ParseException if the user input does not conform the expected format + */ + public LoginCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + switch (trimmedArgs) { + + case KEY_MANAGER: + return new LoginCommand(KEY_MANAGER); + + case KEY_EMPLOYEE: + return new LoginCommand(KEY_EMPLOYEE); + + default: + throw new ParseException(MESSAGE_INVALID_LOGIN); + } + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ManagerParser.java b/src/main/java/seedu/address/logic/parser/ManagerParser.java new file mode 100644 index 000000000000..814e02a5fe29 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ManagerParser.java @@ -0,0 +1,116 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; + +import java.util.regex.Matcher; + +import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.AddEventCommand; +import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.DeleteEventCommand; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.commands.EditEventCommand; +import seedu.address.logic.commands.ExitCommand; +import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.HelpCommand; +import seedu.address.logic.commands.HistoryCommand; +import seedu.address.logic.commands.InviteCommand; +import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.RedoCommand; +import seedu.address.logic.commands.RemoveCommand; +import seedu.address.logic.commands.SelectCommand; +import seedu.address.logic.commands.SortCommand; +import seedu.address.logic.commands.UndoCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses user input. + */ +public class ManagerParser extends CommandsParser { + + public static final String IDENTITY = "Manager"; + + /** + * Parses user input into command for execution. + * + * @param userInput full user input string + * @return the command based on the user input + * @throws ParseException if the user input does not conform the expected format + */ + public Command parseCommand(String userInput) throws ParseException { + final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim()); + if (!matcher.matches()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE)); + } + + final String commandWord = matcher.group("commandWord"); + final String arguments = matcher.group("arguments"); + switch (commandWord) { + + case AddCommand.COMMAND_WORD: + return new AddCommandParser().parse(arguments); + + case AddEventCommand.COMMAND_WORD: + return new AddEventCommandParser().parse(arguments); + + case EditCommand.COMMAND_WORD: + return new EditCommandParser().parse(arguments); + + case EditEventCommand.COMMAND_WORD: + return new EditEventCommandParser().parse(arguments); + + case SelectCommand.COMMAND_WORD: + return new SelectCommandParser().parse(arguments); + + case DeleteCommand.COMMAND_WORD: + return new DeleteCommandParser().parse(arguments); + + case DeleteEventCommand.COMMAND_WORD: + return new DeleteEventCommandParser().parse(arguments); + + case ClearCommand.COMMAND_WORD: + return new ClearCommand(); + + case FindCommand.COMMAND_WORD: + return new FindCommandParser().parse(arguments); + + case ListCommand.COMMAND_WORD: + return new ListCommandParser().parse(arguments); + + case SortCommand.COMMAND_WORD: + return new SortCommandParser().parse(arguments); + + case InviteCommand.COMMAND_WORD: + return new InviteCommandParser().parse(arguments); + + case RemoveCommand.COMMAND_WORD: + return new RemoveCommandParser().parse(arguments); + + case HistoryCommand.COMMAND_WORD: + return new HistoryCommand(); + + case ExitCommand.COMMAND_WORD: + return new ExitCommand(); + + case HelpCommand.COMMAND_WORD: + return new HelpCommand(); + + case UndoCommand.COMMAND_WORD: + return new UndoCommand(); + + case RedoCommand.COMMAND_WORD: + return new RedoCommand(); + + default: + throw new ParseException(MESSAGE_UNKNOWN_COMMAND); + } + } + + public String getIdentity() { + return this.IDENTITY; + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ProManageParser.java b/src/main/java/seedu/address/logic/parser/ProManageParser.java new file mode 100644 index 000000000000..2dd4475a87f5 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ProManageParser.java @@ -0,0 +1,35 @@ +package seedu.address.logic.parser; + +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.LoginCommand; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses user input. + */ +public class ProManageParser { + /** + * Used for initial separation of command word and args. + */ + + private CommandsParser commandsParser; + + public ProManageParser() { + this.commandsParser = new DefaultParser(); + } + + /** + * @param userInput + * @return Command + * @throws ParseException + */ + + public Command parseCommand(String userInput) throws CommandException, ParseException { + Command command = commandsParser.parseCommand(userInput); + if (command instanceof LoginCommand) { + this.commandsParser = ((LoginCommand) command).getParser(); + } + return command; + } +} diff --git a/src/main/java/seedu/address/logic/parser/RemoveCommandParser.java b/src/main/java/seedu/address/logic/parser/RemoveCommandParser.java new file mode 100644 index 000000000000..7cb709710007 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/RemoveCommandParser.java @@ -0,0 +1,52 @@ +package seedu.address.logic.parser; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_FROM; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.RemoveCommand; +import seedu.address.logic.parser.exceptions.ParseException; + + +//@@author jieliangang +/** + * Parses input arguments and creates a new RemoveCommand object + */ +public class RemoveCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the RemoveCommandParser + * and returns a RemoveCommand object for execution. + * + * @throws ParseException if the user input does not conform to the expected format + */ + public RemoveCommand parse(String args) throws ParseException { + requireNonNull(args); + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_FROM); + + Index indexPerson; + Index indexEvent; + + try { + indexPerson = ParserUtil.parseIndex(argMultimap.getPreamble()); + } catch (ParseException pe) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemoveCommand.MESSAGE_USAGE), pe); + } + + if (argMultimap.getValue(PREFIX_FROM).isPresent()) { + try { + indexEvent = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_FROM).get()); + } catch (ParseException pe) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + RemoveCommand.MESSAGE_USAGE), pe); + } + } else { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemoveCommand.MESSAGE_USAGE)); + } + + return new RemoveCommand(indexPerson, indexEvent); + + } +} diff --git a/src/main/java/seedu/address/model/EventList.java b/src/main/java/seedu/address/model/EventList.java index 80fda1eccc6a..3b2b56da1485 100644 --- a/src/main/java/seedu/address/model/EventList.java +++ b/src/main/java/seedu/address/model/EventList.java @@ -7,6 +7,7 @@ import javafx.collections.ObservableList; import seedu.address.model.event.Event; import seedu.address.model.event.UniqueEventList; +import seedu.address.model.person.Person; /** * Wraps all data at the event-list level @@ -83,6 +84,14 @@ public void removeEvent(Event key) { events.remove(key); } + /** + * Removes {@code Person} from the Attendee of {@code EventList}. + */ + public void removePersonFromAllEvents(Person person) { + String personName = person.getName().toString(); + events.removeAttendee(personName); + } + public List getSortedEventList() { return events.getSortedEventList(); } diff --git a/src/main/java/seedu/address/model/EventModel.java b/src/main/java/seedu/address/model/EventModel.java index 644b4004679c..20a99805bbee 100644 --- a/src/main/java/seedu/address/model/EventModel.java +++ b/src/main/java/seedu/address/model/EventModel.java @@ -4,6 +4,7 @@ import javafx.collections.ObservableList; import seedu.address.model.event.Event; +import seedu.address.model.person.Person; /** @@ -56,6 +57,12 @@ public interface EventModel { */ void updateFilteredEventList(Predicate predicate); + /** + * Remove person's name from all event's attendee if present + * This is called when a person is deleted from addressbook + */ + void removePersonFromAllEvents(Person person); + /** * Returns true if the model has previous event list states to restore. */ diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 8cc4de93ea73..de2b3894ac73 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -1,15 +1,9 @@ package seedu.address.model; -import java.util.function.Predicate; - -import seedu.address.model.person.Person; - /** * The API of the Model component. */ public interface Model extends PersonModel, EventModel { - /** {@code Predicate} that always evaluate to true */ - Predicate PREDICATE_SHOW_ALL_PERSONS = unused -> true; /** Clears existing backing model and replaces with the provided new data. */ void resetData(ReadOnlyAddressBook newData, ReadOnlyEventList newEventList); diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index c71a7630d0e2..83f5af737507 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -183,6 +183,14 @@ public void updateEvent(Event target, Event editedEvent) { indicateEventListChanged(); } + @Override + public void removePersonFromAllEvents(Person person) { + requireNonNull(person); + + versionedEventList.removePersonFromAllEvents(person); + indicateEventListChanged(); + } + @Override public ObservableList getFilteredEventList() { return FXCollections.unmodifiableObservableList(filteredEvents); diff --git a/src/main/java/seedu/address/model/event/Attendees.java b/src/main/java/seedu/address/model/event/Attendees.java index 7cc1f03b10c1..39a329cffcb9 100644 --- a/src/main/java/seedu/address/model/event/Attendees.java +++ b/src/main/java/seedu/address/model/event/Attendees.java @@ -28,18 +28,6 @@ public Attendees(Set... attendeesSet) { } } - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - int i = 1; - for (String name : attendeesSet) { - builder.append(String.format("%i: ", i++)); - builder.append(name); - builder.append("\n"); - } - return builder.toString(); - } - /** * Add names to attendees list * @param name The new name to be added. @@ -51,6 +39,17 @@ public Attendees addName(String name) { return new Attendees(updatedAttendees); } + /** + * Remove names to attendees list + * @param name The name to be removed. + * @return A new copy of updated Attendees. + */ + public Attendees removeName(String name) { + Set updatedAttendees = new HashSet<>(this.attendeesSet); + updatedAttendees.remove(name); + return new Attendees(updatedAttendees); + } + /** * Returns whether set contains name. * @param name The name to be checked. diff --git a/src/main/java/seedu/address/model/event/Event.java b/src/main/java/seedu/address/model/event/Event.java index 82fd9c41384e..cc302ebec7ce 100644 --- a/src/main/java/seedu/address/model/event/Event.java +++ b/src/main/java/seedu/address/model/event/Event.java @@ -27,7 +27,7 @@ public class Event implements Comparable { private final StartTime startTime; private final EndTime endTime; private final Location location; - private final Attendees attendees; + private Attendees attendees; /** * Every field must be present not null @@ -130,7 +130,8 @@ public boolean equals(Object other) { && otherEvent.getDescription().equals(getDescription()) && otherEvent.getLocation().equals(getLocation()) && otherEvent.getStartTime().equals(getStartTime()) - && otherEvent.getEndTime().equals(getEndTime()); + && otherEvent.getEndTime().equals(getEndTime()) + && otherEvent.getDate().equals(getDate()); } @Override @@ -163,6 +164,34 @@ public String toString() { return builder.toString(); } + /** + * Add new name to an event attendees list. + * + * @param personName The person's name to be removed from the attendees list. + * @return An updated event with the person's name in the attendees list. + */ + public Event addPersonToAttendee(String personName) { + assert personName != null; + assert !attendees.hasName(personName); + Attendees updatedAttendee = attendees.addName(personName); + return new Event(eventName, description, date, startTime, endTime, location, updatedAttendee); + } + + + /** + * Remove existing name from an event attendees list. + * + * @param personName The person's name to be removed from the attendees list. + * @return An updated event with the person's name removed in the attendees list. + */ + public Event removePersonFromAttendee(String personName) { + assert personName != null; + assert attendees.hasName(personName); + Attendees updatedAttendee = attendees.removeName(personName); + return new Event(eventName, description, date, startTime, endTime, location, updatedAttendee); + } + + @Override public int compareTo(Event other) { return this.getEventName().fullName.compareTo(other.getEventName().fullName); diff --git a/src/main/java/seedu/address/model/event/EventContainsAttendeePredicate.java b/src/main/java/seedu/address/model/event/EventContainsAttendeePredicate.java new file mode 100644 index 000000000000..4652db6d9b75 --- /dev/null +++ b/src/main/java/seedu/address/model/event/EventContainsAttendeePredicate.java @@ -0,0 +1,27 @@ +package seedu.address.model.event; + +import java.util.function.Predicate; + +//@@author jieliangang +/** + * Tests that a {@code Event}'s {@code Attendee} contains the person name given. + */ +public class EventContainsAttendeePredicate implements Predicate { + private final String personName; + + public EventContainsAttendeePredicate(String personName) { + this.personName = personName; + } + + @Override + public boolean test(Event event) { + return event.getAttendees().hasName(personName); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof EventContainsAttendeePredicate // instanceof handles nulls + && personName.equals(((EventContainsAttendeePredicate) other).personName)); // state check + } +} diff --git a/src/main/java/seedu/address/model/event/UniqueEventList.java b/src/main/java/seedu/address/model/event/UniqueEventList.java index 96722a3e71c3..b3ada2d24121 100644 --- a/src/main/java/seedu/address/model/event/UniqueEventList.java +++ b/src/main/java/seedu/address/model/event/UniqueEventList.java @@ -50,7 +50,7 @@ public void add(Event toAdd) { } /** - * Replaces the event {@code target} in the list with {@code editedPerson}. + * Replaces the event {@code target} in the list with {@code editedEvent}. * {@code target} must exist in the list. * The person identity of {@code editedPerson} must not be the same as another existing person in the list. */ @@ -69,8 +69,8 @@ public void setEvent(Event target, Event editedEvent) { } /** - * Removes the equivalent person from the list. - * The person must exist in the list. + * Removes the equivalent event from the list. + * The event must exist in the list. */ public void remove(Event toRemove) { requireNonNull(toRemove); @@ -97,6 +97,21 @@ public void setEvents(List events) { internalList.setAll(events); } + /** + * Update events which Attendee contains personName + */ + public void removeAttendee(String personName) { + requireNonNull(personName); + for (Event event: internalList) { + if (event.getAttendees().hasName(personName)) { + int index = internalList.indexOf(event); + Event updatedEvent = event.removePersonFromAttendee(personName); + internalList.set(index, updatedEvent); + } + } + } + + public List getSortedEventList() { List result = this.internalList; Collections.sort(result); diff --git a/src/main/java/seedu/address/model/person/DepartmentContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/person/DepartmentContainsKeywordsPredicate.java index 7b8123763e47..13260e215b6b 100644 --- a/src/main/java/seedu/address/model/person/DepartmentContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/person/DepartmentContainsKeywordsPredicate.java @@ -16,6 +16,9 @@ public DepartmentContainsKeywordsPredicate(List keywords) { @Override public boolean test(Person person) { + if (keywords.size() == 0) { + return true; + } return keywords.stream() .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getDepartment().value, keyword)); } diff --git a/src/main/java/seedu/address/ui/CommandBox.java b/src/main/java/seedu/address/ui/CommandBox.java index 3d7aaded5640..7d3ed2d0b61b 100644 --- a/src/main/java/seedu/address/ui/CommandBox.java +++ b/src/main/java/seedu/address/ui/CommandBox.java @@ -148,4 +148,5 @@ private void setStyleToIndicateCommandFailure() { styleClass.add(ERROR_STYLE_CLASS); } + } diff --git a/src/main/java/seedu/address/ui/EventCard.java b/src/main/java/seedu/address/ui/EventCard.java index dd312f90bf87..6cbbd0385d75 100644 --- a/src/main/java/seedu/address/ui/EventCard.java +++ b/src/main/java/seedu/address/ui/EventCard.java @@ -52,9 +52,9 @@ public EventCard(Event event, int displayedIndex) { eventName.setText(event.getEventName().fullName); description.setText(event.getDescription().value); eventLocation.setText(String.format("Location: %s", event.getLocation().value)); - //eventDate.setText(String.format("Date: %s", formatDate(event.getDate()))); - startTime.setText(String.format("Start date: %s", event.getStartTime().startTime)); - endTime.setText(String.format("End Date: %s", event.getEndTime().endTime)); + eventDate.setText(String.format("Date: %s", formatDate(event.getDate()))); + startTime.setText(String.format("Start time: %s", event.getStartTime().startTime)); + endTime.setText(String.format("End time: %s", event.getEndTime().endTime)); } @Override diff --git a/src/main/java/seedu/address/ui/EventListPanel.java b/src/main/java/seedu/address/ui/EventListPanel.java index daf0eace18ca..f1d6c90566c5 100644 --- a/src/main/java/seedu/address/ui/EventListPanel.java +++ b/src/main/java/seedu/address/ui/EventListPanel.java @@ -2,8 +2,6 @@ import java.util.logging.Logger; -import com.google.common.eventbus.Subscribe; - import javafx.application.Platform; import javafx.collections.ObservableList; import javafx.fxml.FXML; @@ -11,8 +9,6 @@ import javafx.scene.control.ListView; import javafx.scene.layout.Region; import seedu.address.commons.core.LogsCenter; -import seedu.address.commons.events.ui.EventPanelSelectionChangedEvent; -import seedu.address.commons.events.ui.JumpToListRequestEvent; import seedu.address.model.event.Event; @@ -36,7 +32,7 @@ public EventListPanel(ObservableList eventList) { private void setConnections(ObservableList eventList) { eventListView.setItems(eventList); eventListView.setCellFactory(listView -> new EventListViewCell()); - setEventHandlerForSelectionChangeEvent(); + //setEventHandlerForSelectionChangeEvent(); } private void setEventHandlerForSelectionChangeEvent() { @@ -44,8 +40,7 @@ private void setEventHandlerForSelectionChangeEvent() { .addListener((observable, oldValue, newValue) -> { if (newValue != null) { logger.fine("Selection in event list panel changed to : '" + newValue + "'"); - raise(new EventPanelSelectionChangedEvent(newValue)); - //raise(new NewResultAvailableEvent(newValue.toString())); + //raise(new EventPanelSelectionChangedEvent(newValue)); } }); } @@ -60,12 +55,6 @@ private void scrollTo(int index) { }); } - @Subscribe - private void handleJumpToListRequestEvent(JumpToListRequestEvent event) { - logger.info(LogsCenter.getEventHandlingLogMessage(event)); - scrollTo(event.targetIndex); - } - /** * Custom {@code ListCell} that displays the graphics of a {@code Event} using a {@code EventCard}. */ diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index f9b8ba254039..e913d4ae6586 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -128,9 +128,9 @@ void fillInnerParts() { personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); browserPanel = new BrowserPanel(); - browserPlaceholder.getChildren().add(browserPanel.getRoot()); + //browserPlaceholder.getChildren().add(browserPanel.getRoot()); // TODO: Update gui tests before using eventListPanel - //browserPlaceholder.getChildren().add(eventListPanel.getRoot()); + browserPlaceholder.getChildren().add(eventListPanel.getRoot()); ResultDisplay resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); diff --git a/src/main/java/seedu/address/ui/PersonListPanel.java b/src/main/java/seedu/address/ui/PersonListPanel.java index 80080adb4305..dd1e61a99095 100644 --- a/src/main/java/seedu/address/ui/PersonListPanel.java +++ b/src/main/java/seedu/address/ui/PersonListPanel.java @@ -12,7 +12,6 @@ import javafx.scene.layout.Region; import seedu.address.commons.core.LogsCenter; import seedu.address.commons.events.ui.JumpToListRequestEvent; -import seedu.address.commons.events.ui.PersonPanelSelectionChangedEvent; import seedu.address.model.person.Person; /** @@ -42,7 +41,7 @@ private void setEventHandlerForSelectionChangeEvent() { .addListener((observable, oldValue, newValue) -> { if (newValue != null) { logger.fine("Selection in person list panel changed to : '" + newValue + "'"); - raise(new PersonPanelSelectionChangedEvent(newValue)); + //raise(new PersonPanelSelectionChangedEvent(newValue)); } }); } diff --git a/src/main/resources/view/EventListCard.fxml b/src/main/resources/view/EventListCard.fxml index db2f7812d614..18b1beb5f4a7 100644 --- a/src/main/resources/view/EventListCard.fxml +++ b/src/main/resources/view/EventListCard.fxml @@ -29,6 +29,7 @@