Skip to content

Commit

Permalink
Merge pull request #39 from dr-arrgghh/filter-branch
Browse files Browse the repository at this point in the history
Filter branch
  • Loading branch information
dr-arrgghh authored Oct 9, 2022
2 parents 729c02e + bad2527 commit 606f688
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 111 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[![CI Status](https://github.com/AY2223S1-CS2103T-W13-1/tp/workflows/Java%20CI/badge.svg)](https://github.com/AY2223S1-CS2103T-W13-1/tp/actions)

StudMap (SM) is a desktop app for managing your students, optimized for use via a Command Line Interface (CLI)
while still having the benefits of a Graphical User Interface (GUI). If you can type fast, SM can get your
student management tasks done faster than traditional GUI apps.
while still having the benefits of a Graphical User Interface (GUI). If you can type fast, SM can get your student
management tasks done faster than traditional GUI apps.

![Ui](docs/images/Ui.png)


## Site Map

* [About Us](docs/AboutUs.md)
* [User Guide](docs/UserGuide.md)
* [Developer Guide](docs/DeveloperGuide.md)
Expand Down
211 changes: 134 additions & 77 deletions docs/DeveloperGuide.md

Large diffs are not rendered by default.

75 changes: 47 additions & 28 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
layout: page
title: User Guide
layout: page title: User Guide
---

StudMap (SM) is a desktop app for managing your students, optimized for use via a Command Line Interface (CLI) while still having the benefits of a Graphical User Interface (GUI). If you can type fast, SM can get your student management tasks done faster than traditional GUI apps.
StudMap (SM) is a desktop app for managing your students, optimized for use via a Command Line Interface (CLI) while
still having the benefits of a Graphical User Interface (GUI). If you can type fast, SM can get your student management
tasks done faster than traditional GUI apps.

* Table of Contents
{:toc}
* Table of Contents {:toc}

--------------------------------------------------------------------------------------------------------------------

Expand All @@ -18,22 +18,25 @@ StudMap (SM) is a desktop app for managing your students, optimized for use via

1. Copy the file to the folder you want to use as the _home folder_ for your StudMap.

1. Double-click the file to start the app. The GUI similar to the below should appear in a few seconds. Note how the app contains some sample data.<br>
1. Double-click the file to start the app. The GUI similar to the below should appear in a few seconds. Note how the app
contains some sample data.<br>
<!-- TODO: ![Ui](images/Ui.png) -->
[Sample UI To be added]

1. Type the command in the command box and press Enter to execute it. e.g. typing **`help`** and pressing Enter will open the help window.<br>
1. Type the command in the command box and press Enter to execute it. e.g. typing **`help`** and pressing Enter will
open the help window.<br>
Some example commands you can try:

* **`list`** : Lists all students.
* **`list`** : Lists all students.

* **`add`**`n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01` : Adds a student named `John Doe` to the StudMap.
* **`add`**`n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01` : Adds a student
named `John Doe` to the StudMap.

* **`delete`**`3` : Deletes the 3rd student shown in the current list.
* **`delete`**`3` : Deletes the 3rd student shown in the current list.

* **`clear`** : Deletes all students.
* **`clear`** : Deletes all students.

* **`exit`** : Exits the app.
* **`exit`** : Exits the app.

1. Refer to the [Features](#features) below for details of each command.

Expand All @@ -57,10 +60,12 @@ StudMap (SM) is a desktop app for managing your students, optimized for use via
* Parameters can be in any order.<br>
e.g. if the command specifies `n/NAME p/PHONE_NUMBER`, `p/PHONE_NUMBER n/NAME` is also acceptable.

* If a parameter is expected only once in the command but you specified it multiple times, only the last occurrence of the parameter will be taken.<br>
* If a parameter is expected only once in the command but you specified it multiple times, only the last occurrence of
the parameter will be taken.<br>
e.g. if you specify `p/12341234 p/56785678`, only `p/56785678` will be taken.

* Extraneous parameters for commands that do not take in parameters (such as `help`, `list`, `exit` and `clear`) will be ignored.<br>
* Extraneous parameters for commands that do not take in parameters (such as `help`, `list`, `exit` and `clear`) will be
ignored.<br>
e.g. if the command specifies `help 123`, it will be interpreted as `help`.

</div>
Expand All @@ -74,7 +79,6 @@ Shows a message explaning how to access the help page.

Format: `help`


### Adding a student: `add`

Adds a student to the StudMap.
Expand All @@ -86,6 +90,7 @@ A student can have any number of tags (including 0)
</div>

Examples:

* `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01`
* `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 t/criminal`

Expand All @@ -101,16 +106,18 @@ Edits an existing student in the StudMap.

Format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]…​`

* Edits the student at the specified `INDEX`. The index refers to the index number shown in the displayed student list. The index **must be a positive integer** 1, 2, 3, …​
* Edits the student at the specified `INDEX`. The index refers to the index number shown in the displayed student list.
The index **must be a positive integer** 1, 2, 3, …​
* At least one of the optional fields must be provided.
* Existing values will be updated to the input values.
* When editing tags, the existing tags of the student will be removed i.e adding of tags is not cumulative.
* You can remove all the student's tags by typing `t/` without
specifying any tags after it.
* You can remove all the student's tags by typing `t/` without specifying any tags after it.

Examples:
* `edit 1 p/91234567 e/johndoe@example.com` Edits the phone number and email address of the 1st student to be `91234567` and `johndoe@example.com` respectively.
* `edit 2 n/Betsy Crower t/` Edits the name of the 2nd student to be `Betsy Crower` and clears all existing tags.

* `edit 1 p/91234567 e/johndoe@example.com` Edits the phone number and email address of the 1st student to be `91234567`
and `johndoe@example.com` respectively.
* `edit 2 n/Betsy Crower t/` Edits the name of the 2nd student to be `Betsy Crower` and clears all existing tags.

### Locating students by name: `find`

Expand All @@ -122,10 +129,11 @@ Format: `find KEYWORD [MORE_KEYWORDS]`
* The order of the keywords does not matter. e.g. `Hans Bo` will match `Bo Hans`
* Only the name is searched.
* Only full words will be matched e.g. `Han` will not match `Hans`
* Students matching at least one keyword will be returned (i.e. `OR` search).
e.g. `Hans Bo` will return `Hans Gruber`, `Bo Yang`
* Students matching at least one keyword will be returned (i.e. `OR` search). e.g. `Hans Bo` will return `Hans Gruber`
, `Bo Yang`

Examples:

* `find John` returns `john` and `John Doe`
* `find alex david` returns `Alex Yeoh`, `David Li`<br>
<!-- TODO: ![result for 'find alex david'](images/findAlexDavidResult.png) -->
Expand All @@ -142,6 +150,7 @@ Format: `delete INDEX`
* The index **must be a positive integer** 1, 2, 3, …​

Examples:

* `list` followed by `delete 2` deletes the 2nd student in the StudMap.
* `find Betsy` followed by `delete 1` deletes the 1st student in the results of the `find` command.

Expand All @@ -159,29 +168,36 @@ Format: `exit`

### Saving the data

StudMap data are saved in the hard disk automatically after any command that changes the data. There is no need to save manually.
StudMap data are saved in the hard disk automatically after any command that changes the data. There is no need to save
manually.

### Editing the data file

StudMap data are saved as a JSON file `[JAR file location]/data/studmap.json`. Advanced users are welcome to update data directly by editing that data file.
StudMap data are saved as a JSON file `[JAR file location]/data/studmap.json`. Advanced users are welcome to update data
directly by editing that data file.

<div markdown="span" class="alert alert-warning">:exclamation: <b>Caution:</b>
If your changes to the data file makes its format invalid, StudMap will discard all data and start with an empty data file at the next run.
</div>

### Sorting the students: `sort`
### Sorting the students: `sort`

[Coming soon]

### Filtering the students: `filter`

[Coming soon]

### Mark student as present: `mark`

[Coming soon]

### Unmark attendance of a student: `unmark`

[Coming soon]

### Add tag to a student: `addtag`

[Coming soon]


Expand All @@ -190,18 +206,21 @@ If your changes to the data file makes its format invalid, StudMap will discard
## FAQ

**Q**: How do I transfer my data to another Computer?<br>
**A**: Install the app in the other computer and overwrite the empty data file it creates with the file that contains the data of your previous StudMap home folder.
**A**: Install the app in the other computer and overwrite the empty data file it creates with the file that contains
the data of your previous StudMap home folder.

--------------------------------------------------------------------------------------------------------------------

## Command summary

Action | Format, Examples
--------|------------------
**Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [t/TAG]…​` <br> e.g., `add n/James Ho p/22224444 e/jamesho@example.com a/123, Clementi Rd, 1234665 t/friend t/colleague`
**
Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [t/TAG]…​` <br> e.g., `add n/James Ho p/22224444 e/jamesho@example.com a/123, Clementi Rd, 1234665 t/friend t/colleague`
**Clear** | `clear`
**Delete** | `delete INDEX`<br> e.g., `delete 3`
**Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…​`<br> e.g.,`edit 2 n/James Lee e/jameslee@example.com`
**
Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…​`<br> e.g.,`edit 2 n/James Lee e/jameslee@example.com`
**Find** | `find KEYWORD [MORE_KEYWORDS]`<br> e.g., `find James Jake`
**List** | `list`
**Help** | `help`
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/seedu/address/logic/commands/FilterCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.Messages;
import seedu.address.model.Model;
import seedu.address.model.person.NameContainsKeywordsPredicate;

/**
* Filters and list all persons in the address book
*/
public class FilterCommand extends Command {

public static final String COMMAND_WORD = "filter";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Filters all persons whose names contain any of "
+ "the specified alphabets (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alex";

private final NameContainsKeywordsPredicate predicate;

public FilterCommand(NameContainsKeywordsPredicate predicate) {
this.predicate = predicate;
}


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
}
}
10 changes: 7 additions & 3 deletions src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FilterCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
Expand Down Expand Up @@ -63,15 +64,18 @@ public Command parseCommand(String userInput) throws ParseException {
case ListCommand.COMMAND_WORD:
return new ListCommand();

case AddTagCommand.COMMAND_WORD:
return new AddTagCommandParser().parse(arguments);

case ExitCommand.COMMAND_WORD:
return new ExitCommand();

case AddTagCommand.COMMAND_WORD:
return new AddTagCommandParser().parse(arguments);

case HelpCommand.COMMAND_WORD:
return new HelpCommand();

case FilterCommand.COMMAND_WORD:
return new FilterCommandParser().parse(arguments);

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/seedu/address/logic/parser/FilterCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.logic.parser;

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

import java.util.Arrays;

import seedu.address.logic.commands.FilterCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.NameContainsKeywordsPredicate;


/**
* Parses input arguments and create a new FilterCommand object
*/
public class FilterCommandParser implements Parser<FilterCommand> {

/**
* Parses the given {@code String} of arguments in the context of the FilterCommand
* and returns a FilterCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
@Override
public FilterCommand parse(String args) throws ParseException {
String trimmedArgs = args.trim();
if (trimmedArgs.isEmpty()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

String[] nameKeywords = trimmedArgs.split("\\s+");

return new FilterCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords)));
}
}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ public interface Model {
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredPersonList(Predicate<Person> predicate);


}

0 comments on commit 606f688

Please sign in to comment.