Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2223S2#65 from hongshenggg/master
Browse files Browse the repository at this point in the history
Add delete-image feature to DeveloperGuide
  • Loading branch information
weekiat-douze authored Mar 23, 2023
2 parents 2811d22 + 8c1ea2b commit 39a62fc
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![codecov](https://codecov.io/gh/nus-cs2103-AY2223S2/tp/branch/master/graph/badge.svg?token=SNV76O467D)](https://codecov.io/gh/nus-cs2103-AY2223S2/tp)
![Ui](docs/images/Ui.png)

* This is BookFace, a university-centered address book application.
* This is BookFace, an NUS-centered address book application.
Example usages:
* Add contacts along with the image of the person
* Quickly import university related contacts
Expand Down
74 changes: 66 additions & 8 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
**Target user profile**:

University students who need to keep track of their contacts from different classes/ccas/clubs etc.
Students from the National University of Singapore (NUS) who need to keep track of their contacts from different classes/ccas/clubs etc.

**Value proposition**:

Students often take many classes and meet different people. This application helps them to organise their
NUS Students often take many classes and meet different people. This application helps them to organise their
contacts list for an easier way to set up proper communication channels. This makes it easier for students to form
connections with their peers during their time in University.

Expand Down Expand Up @@ -168,21 +168,21 @@ The add-image mechanism is facilitated by `AddImageCommand`, `AddImageCommandPar
- `AddImageCommand` extends `Command`
- `AddImageCommandParser` extends `Parser`

The `AddImageCommandParser` parses the user input into index of contact and path to an image.
It returns a `AddImageCommand` with the 2 information retrieved.
`AddImageCommand#execute` copies the image provided by the user via a path and replaces the current image with the new one.
The `AddImageCommandParser` parses the user input into index of contact and path to an image.
It returns a `AddImageCommand` with the 2 information retrieved.
`AddImageCommand#execute` copies the image provided by the user via a path and replaces the current image with the new one.
It also saves the file name of the new image to the `model`.

Given below is an example usage scenario and how the add-image mechanism behaves at each step.

Step 1. When user wants to add an image to a contact, they use the `add-image` command.

Step 2. The `LogicManger` receives the command text from the user input and gives it to `AddressBookParser`. `AddressBookParser` calls `AddImageCommandParser` to parse the user input.
Step 2. The `LogicManager` receives the command text from the user input and gives it to `AddressBookParser`. `AddressBookParser` calls `AddImageCommandParser` to parse the user input.

Step 3. The `AddImageCommandParser` retrieves the contact index as well as the image path and creates a `AddImageCommand`

Step 4. `AddImageCommand#execute` is called. The method calls `ImageUtil#importImage` to copy the image into the "profile_pictures/" directory.
Once that is successful, `AddImageCommand#execute` proceeds to call `ImageUtil#deleteImage` to remove the current image.
Step 4. `AddImageCommand#execute` is called. The method calls `ImageUtil#importImage` to copy the image into the "profile_pictures/" directory.
Once that is successful, `AddImageCommand#execute` proceeds to call `ImageUtil#deleteImage` to remove the current image.
Finally `AddImageCommand#execute` updates the model provided in the arguments.

> **Note**: If the path given is invalid or if the file at the given path is not a png/jpeg image, the command will not be completed.
Expand All @@ -207,3 +207,61 @@ The following activity diagram summarizes what happens when a user executes add-
- Easy to save as only the Path as a string
- Cons:
- Path is easily invalidated (e.g. user moves/deletes/renames the image)
## Delete Image Feature
### Delete Image Implementation
The delete-image feature is facilitated by the classes `DeleteImageCommand`,
`DeleteImageCommandParser`, `ImageUtil`, and `ParserUtil`.
The `DeleteImageCommandParser` first parses through the user command to obtain
the desired index through using `ParserUtil#parseIndex`. Following which an
instance of a `DeleteImageCommand` containing the desired index is returned.
`DeleteImageCommand#execute` is then called, which sets the image of the contact
at the desired index to a default image, and deletes the existing image through
`ImageUtil#deleteImage`.

Given below is an example usage scenario for how the delete-image mechanism behaves.

Step 1: User starts up the application and sees their list of contacts. Some of
which have already had an image added.

Step 2: The user decides that the image given to the contact at index 4 is not
suitable, and wants to delete it. The user inputs `delete-image 4`.
`DeleteImageCommandParser#parse` is then called to parse this input for the
desired index.

> **Note**: If the user inputs an index of a contact which currently does not have
an image, or if the user inputs an invalid index, an error will be returned to
the user

Step 3: If the instruction was valid, `Model#deleteImage` is called to set the
image of the contact to the default image.

Step 4: `ImageUtil#deleteImage` is then called to delete the existing image
from the program directory.

The following sequence diagram shows how the delete-image operation works.

![DeleteImageSequenceDiagram](images/DeleteImageSequenceDiagram.png)

> **Note**: The lifeline of the `DeleteImageCommandParser` and `DeleteImageCommand`
> should end at the destroy marker (X) but due to the limitations of PlantUML, the
> lifeline reaches the end of the diagram.
The following activity diagram summarizes what happens when a user executes a
delete-image command:

![DeleteImageActivityDiagram](images/DeleteImageActivityDiagram.png)

### Design Considerations:
- **Alternative 1 (current choice):** Delete the existing image file from program
directory.
- Pros:
- Ensures application does not consume excess storage
- Cons:
- Extra complexity in requiring file i/o operations

- **Alternative 2:** Disregard deleting the image file from program directory.
- Pros:
- Easier to implement
- Cons:
- Application will take up increasingly more unnecessary storage during
its lifetime of usage
10 changes: 5 additions & 5 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ Examples:

## Delete Image for contacts

Delete image of a contact.
Delete the image of a contact.
Format: `delete-image INDEX`

* Delete image of contact specified by `INDEX`
* Deletes the image of contact specified by `INDEX`
* The index refers to the index number shown in the displayed person list.
* The index *must* be a positive integer 1, 2, 3, …
* The image must be placed in a specific folder for BookFace to locate
* A default image will be used after it is deleted
Example:
* `delete-image` 2 deletes the image of the 2nd person in the address book.

Example:
* `delete-image 2` deletes the image of the 2nd person in the address book.

## Quick Import for admin contacts: `import`

Expand Down
18 changes: 18 additions & 0 deletions docs/diagrams/DeleteImageActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@startuml
start
:User executes delete-image command;
'Since the beta syntax does not support placing the condition outside the
'diamond we place it as the true branch instead.

if () then ([index provided is valid])
if () then ([person at index does not have default image])
:Person's image is set to default image;
:Image is deleted from program directory;
else ([else])
:Display error message;
endif
else ([else])
: Display error message;
endif
stop
@enduml
79 changes: 79 additions & 0 deletions docs/diagrams/DeleteImageSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@startuml
!include style.puml

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":DeleteImageCommandParser" as DeleteImageCommandParser LOGIC_COLOR
participant "d:DeleteImageCommand" as DeleteImageCommand LOGIC_COLOR
participant "result:CommandResult" as CommandResult LOGIC_COLOR
participant "<<class>>\nImageUtil" as ImageUtil LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
end box

[-> LogicManager : execute("delete-image 1")
activate LogicManager

LogicManager -> AddressBookParser : parseCommand("delete-image 1")
activate AddressBookParser

create DeleteImageCommandParser
AddressBookParser -> DeleteImageCommandParser
activate DeleteImageCommandParser

DeleteImageCommandParser --> AddressBookParser
deactivate DeleteImageCommandParser

AddressBookParser -> DeleteImageCommandParser : parse("1")
activate DeleteImageCommandParser

create DeleteImageCommand
DeleteImageCommandParser -> DeleteImageCommand
activate DeleteImageCommand

DeleteImageCommand --> DeleteImageCommandParser : d
deactivate DeleteImageCommand

DeleteImageCommandParser --> AddressBookParser : d
deactivate DeleteImageCommandParser
'Hidden arrow to position the destroy marker below the end of the activation bar.
DeleteImageCommandParser -[hidden]-> AddressBookParser
destroy DeleteImageCommandParser

AddressBookParser --> LogicManager : d
deactivate AddressBookParser

LogicManager -> DeleteImageCommand : execute()
activate DeleteImageCommand

DeleteImageCommand -> Model : deleteImage(personaAtIndex)
activate Model

Model --> DeleteImageCommand
deactivate Model

DeleteImageCommand -> ImageUtil : deleteImage(imageName)
activate ImageUtil

ImageUtil --> DeleteImageCommand
deactivate ImageUtil

create CommandResult
DeleteImageCommand -> CommandResult
activate CommandResult

CommandResult --> DeleteImageCommand : result
deactivate CommandResult

DeleteImageCommand --> LogicManager : result
deactivate DeleteImageCommand
'Hidden arrow to position the destroy marker below the end of the activation bar.
DeleteImageCommandParser -[hidden]-> LogicManager
destroy DeleteImageCommand

[<--LogicManager : result
deactivate LogicManager
@enduml
Binary file added docs/images/DeleteImageActivityDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/DeleteImageSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 39a62fc

Please sign in to comment.