[Proposed] Undo/redo feature
section in the
original AB3 Developer Guide.
During the development process of these two features, the codes are written by our own developers, based on the suggested
architectural design and APIs mentioned in the above documentation.Overview of GUI
section under UserGuide is adpated from CS2103T-F12-3's MediBase3.Refer to the guide Setting up and getting started.
The Architecture Diagram given above explains the high-level design of the App.
Given below is a quick overview of main components and how they interact with each other.
Main components of the architecture
Main
(consisting of classes Main
and MainApp
) is in charge of the app launch and shut down.
The bulk of the app's work is done by the following four components:
UI
: The UI of the App.Logic
: The command executor.Model
: Holds the data of the App in memory.Storage
: Reads data from, and writes data to, the hard disk.Commons
represents a collection of classes used by multiple other components.
How the architecture components interact with each other
The Sequence Diagram below shows how the components interact with each other for the scenario where the user issues the command delete 1
.
Each of the four main components (also shown in the diagram above),
interface
with the same name as the Component.{Component Name}Manager
class (which follows the corresponding API interface
mentioned in the previous point.For example, the Logic
component defines its API in the Logic.java
interface and implements its functionality using the LogicManager.java
class which follows the Logic
interface. Other components interact with a given component through its interface rather than the concrete class (reason: to prevent outside component's being coupled to the implementation of a component), as illustrated in the (partial) class diagram below.
The sections below give more details of each component.
The API of this component is specified in Ui.java
The UI consists of a MainWindow
that is made up of parts e.g.CommandBox
, ResultDisplay
, PersonListPanel
, HistoryCommandListPanel
, StatusBarFooter
etc. All these, including the MainWindow
, inherit from the abstract UiPart
class which captures the commonalities between classes that represent parts of the visible GUI.
The UI
component uses the JavaFx UI framework. The layout of these UI parts are defined in matching .fxml
files that are in the src/main/resources/view
folder. For example, the layout of the MainWindow
is specified in MainWindow.fxml
The UI
component,
Logic
component.Model
data so that the UI can be updated with the modified data.Logic
component, because the UI
relies on the Logic
to execute commands.Model
component, as it displays Person
object residing in the Model
.API : Logic.java
Here's a (partial) class diagram of the Logic
component:
The sequence diagram below illustrates the interactions within the Logic
component, taking execute("delete 1")
API call as an example.
Note: The lifeline for DeleteCommandParser
should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline continues till the end of diagram.
How the Logic
component works:
Logic
is called upon to execute a command, it is passed to an AddressBookParser
object which in turn creates a parser that matches the command (e.g., DeleteCommandParser
) and uses it to parse the command.Command
object (more precisely, an object of one of its subclasses e.g., DeleteCommand
) which is executed by the LogicManager
.Model
when it is executed (e.g. to delete a person).Model
) to achieve.CommandResult
object which is returned back from Logic
.Here are the other classes in Logic
(omitted from the class diagram above) that are used for parsing a user command:
How the parsing works:
AddressBookParser
class creates an XYZCommandParser
(XYZ
is a placeholder for the specific command name e.g., AddCommandParser
) which uses the other classes shown above to parse the user command and create a XYZCommand
object (e.g., AddCommand
) which the AddressBookParser
returns back as a Command
object.XYZCommandParser
classes (e.g., AddCommandParser
, DeleteCommandParser
, ...) inherit from the Parser
interface so that they can be treated similarly where possible e.g, during testing.API : Model.java
The Model
component,
Person
objects (which are contained in a UniquePersonList
object).Person
objects (e.g., results of a search query) as a separate filtered list which is exposed to outsiders as an unmodifiable ObservableList<Person>
that can be 'observed' e.g. the UI can be bound to this list so that the UI automatically updates when the data in the list change.UserPref
object that represents the user’s preferences. This is exposed to the outside as a ReadOnlyUserPref
objects.Model
represents data entities of the domain, they should make sense on their own without depending on other components)Note: An alternative (arguably, a more OOP) model is given below. It has a Tag
list in the AddressBook
, which Person
references. This allows AddressBook
to only require one Tag
object per unique tag, instead of each Person
needing their own Tag
objects.
API : Storage.java
The Storage
component,
AddressBookStorage
and UserPrefStorage
, which means it can be treated as either one (if only the functionality of only one is needed).Model
component (because the Storage
component's job is to save/retrieve objects that belong to the Model
)Classes used by multiple components are in the seedu.address.commons
package.
This section describes some noteworthy details on how certain features are implemented.
The undo/redo mechanism is facilitated by VersionedAddressBook
.
It extends AddressBook
with an undo/redo history, stored internally as an addressBookStateList
and currentStatePointer
.
Additionally, it implements the following operations:
VersionedAddressBook#commitAddressBook()
— Saves the current address book state in its history.VersionedAddressBook#undoAddressBook()
— Restores the previous address book state from its history.VersionedAddressBook#redoAddressBook()
— Restores a previously undone address book state from its history.These operations are exposed in the Model
interface as Model#commitAddressBook()
, Model#undoAddressBook()
and Model#redoAddressBook()
respectively.
Given below is an example usage scenario and how the undo/redo mechanism behaves at each step.
Step 1. The user launches the application for the first time. The VersionedAddressBook
will be initialized with the initial address book state, and the currentStatePointer
pointing to that single address book state.
Step 2. The user executes delete 5
command to delete the 5th person in the address book. The delete
command calls Model#commitAddressBook()
, causing the modified state of the address book after the delete 5
command executes to be saved in the addressBookStateList
, and the currentStatePointer
is shifted to the newly inserted address book state.
Step 3. The user executes add n/David …
to add a new person. The add
command also calls Model#commitAddressBook()
, causing another modified address book state to be saved into the addressBookStateList
.
Note: If a command fails its execution, it will not call Model#commitAddressBook()
, so the address book state will not be saved into the addressBookStateList
.
Step 4. The user now decides that adding the person was a mistake, and decides to undo that action by executing the undo
command. The undo
command will call Model#undoAddressBook()
, which will shift the currentStatePointer
once to the left, pointing it to the previous address book state, and restores the address book to that state.
Note: If the currentStatePointer
is at index 0, pointing to the initial AddressBook state, then there are no previous AddressBook states to restore. The Model#undoAddressBook()
throws a CommandException
in this case. Then, it will return an error to the user rather
than attempting to perform the undo.
The following sequence diagram shows how an undo operation goes through the Logic
component:
Note: The lifeline for UndoCommand
should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline reaches the end of diagram.
Similarly, how an undo operation goes through the Model
component is shown below:
The redo
command does the opposite — it calls Model#redoAddressBook()
, which shifts the currentStatePointer
once to the right, pointing to the previously undone state, and restores the address book to that state.
Note: If the currentStatePointer
is at index addressBookStateList.size() - 1
, pointing to the latest address book state, then there are no undone AddressBook states to restore. The Model#redoAddressBook()
will throw a CommandException
in this case. Then, it will return an error to the user rather than attempting to perform the redo.
Step 5. The user then decides to execute the command list
. Commands that do not modify the address book, such as list
, will not call Model#commitAddressBook()
, Model#undoAddressBook()
or Model#redoAddressBook()
. Thus, the addressBookStateList
remains unchanged.
Step 6. The user executes clear
, which calls Model#commitAddressBook()
. Since the currentStatePointer
is not pointing at the end of the addressBookStateList
, all address book states after the currentStatePointer
will be purged. Reason: It no longer makes sense to redo the add n/David …
command. This is the behavior that most modern desktop applications follow.
The following activity diagram summarizes what happens when a user executes a new command:
Note: Model#undoAddressBook()
and Model#redoAddressBook()
will also throw a CommandException
in the unlikely case that there are uncommitted changes when an undo or a redo is attempted. This may happen if a data changing command did not call Model#commitAddressBook()
.
Aspect: How undo & redo executes:
Alternative 1 (current choice): Saves the entire address book.
Alternative 2: Individual command knows how to undo/redo by itself.
delete
, just save the person being deleted).Target user profile:
Value proposition:
Allows NUS CS freshmen to easily locate the admin contact details when needed,
which helps them better manage contact details of their professors, teaching assistants, classmates, CCA mates, offices, emergency helplines, etc.
so that they can focus more on their study.
Priorities: High (must have) - * * *
, Medium (nice to have) - * *
, Low (unlikely to have) - *
Priority | As a … | I want to … | So that I can… |
---|---|---|---|
* * * | Y1 CS Student | add a contact | start tracking my contacts on this app |
* * * | Y1 CS student who prefers a clean address book with useful contacts only | delete contacts | remove contacts that I no longer need to keep track of |
* * * | Y1 CS student who hates using a mouse or touchpad | access to all functionalities of the app with keyboard | manage the contacts in the most efficient way |
* * * | Y1 CS student | search for contact info from my address book using name, module code (with role), or tag | find their contact immediately and reach out to them to settle any issues |
* * | Y1 CS student | navigate to view the full contact list | perform an action (like editing or deleting contacts) |
* * | Y1 CS student who struggles to remember who to reach out to for certain issues | find the correct contact info by searching the category of the issue that I am trying to settle | seek help immediately even when I forget who to reach out to |
* * | Y1 CS student who wants to seek clarifications/actions from a professor regarding certain issues | find contact details of the professor(s) for a course | seek help/assistance with ease |
* * | Y1 CS student who is sick before a tutorial/lab/exam | find contact details of my TA | easily inform them about my absence on time |
* * | Y1 CS student who is involved in any accident or emergency | find contact details of campus security | protect me and my friends' safety immediately |
* * | Y1 CS student who has financial concerns for school | find contact details of nus financial office | settle any financial related issues |
* * | Y1 CS student who needs to update contact info | update contact info for courses in this semester with that in the next semester | keep info updated in more efficient ways |
* * | Y1 CS student who frequently access some of the contact details but lazy to repeat same commands everytime | classify frequently accessed contacts and query them using shorter commands | access those frequent contact without wasting too much time |
* * | New user | see usage instructions | refer to instructions when I forget how to use the App |
* * | Y1 CS student who is a fresh man in a cca | find contact details of my cca leader/friends | settle any cca-related issues with them |
* * | Y1 CS student who are unsure about the procedure of making an appointment with a doctor | find contact details for UHC and NUH easily | make appointment with doctor as early as possible |
* * | Y1 CS student who are facing an academic challenges and mental issue | find contact details of counselling service | seek help and support from others before it is too late |
* * | Y1 CS student who lives in campus and don't know where to contact with if I need to enquire some information | find contact details of campus hostels easily | |
* * | Y1 CS student who is keen to study together with friends/wants to manage friends know from class | find out contact of friends who attend a specific module/course during the semester | |
* * | Potential user exploring the app | see the app populated with sample data | see how the app will look like when it is in use. |
* | Y1 CS student who wants to share my contact list with friends who need them | transfer useful data to help others efficiently | |
* | Y1 CS student who are unsure about the modules planning but don't know who to reach out for | find the respective contact of academic advisors | |
* | Y1 CS student who is unaware of the various opportunities provided by nus and soc | find the contact emails and main pages for the opportunities such as SEP, NOC, UROP + ReX, summer school, winter school etc | |
* | User who performed action wrongly when using the app | redo/undo current actions | perform multiple actions efficiently without wasting time on correcting the mistakes |
(For all use cases below, the System is the ContactCS
and the Actor is the CS freshman
, unless specified otherwise)
Use case: UC01 Add a contact
MSS
User requests to add a new contact by providing the relevant contact details.
ContactCS adds the contact to the contact list.
Use case ends.
Extensions
1a. Necessary input is missing.
1a1. ContactCS requests the user to provide the required information
1a2. User enters new data
Steps 1a1 - 1a2 are repeated until the data entered contain all the necessary fields
Use case resumes from step 2.
1b. The given format is invalid.
1b1. ContactCS requests the user to provide the correct format and shows the valid command format
1b2. User enters new input
Steps 1b1 - 1b2 are repeated until the format for the entered input is correct
Use case resumes from step 2.
1c. The given contact is a duplicate.
1c1. ContactCS shows an error message telling the user that the contact already exists in ContactCS
Use case ends.
Use case: UC02 Search contact(s)
MSS
User requests to search for contact(s) by providing one or more of the following:
ContactCS shows a list of matching contacts
Use case ends.
Extensions
1a. Necessary input of at least one keyword is missing.
1a1. ContactCS requests the user to provide keyword
1a2. User enters new input
Steps 1a1 - 1a2 are repeated until all required fields in the input are complete
Use case resumes from step 2.
1b. The input format is invalid.
1b1. ContactCS requests the user to provide the correct format and shows correct syntax, example
1b2. User enters new input
Steps 1b1 - 1b2 are repeated until the format for the entered input is correct
Use case resumes from step 2.
1c. No matching contacts found.
1c1. ContactCS displays a message to the user saying that there is no matching contacts found
Use case ends.
Use case: UC03 List contacts
MSS
User requests to list the contacts
ContactCS shows a list of contacts
Use case ends.
Use case: UC04 Delete a person
MSS
User requests to list (UC03) the contacts or search (UC02) for contact(s)
User requests to delete a person or multiple persons in the list
ContactCS deletes the person(s)
Use case ends.
Extensions
2a. The given index/indices is/are invalid.
2a1. ContactCS requests the user to provide the correct index/indices
2a2. User enters new index/indices
Steps 2a1 - 2a2 are repeated until the index/indices entered is/are valid
Use case resumes from step 3.
Use case: UC05 Edit contact information
MSS
User requests to list (UC03) the contacts or search (UC02) for contact(s)
User requests to edit contact information for a specific person in the list, providing the new contact details
ContactCS updates the contact details based on the information provided by the user
Use case ends.
Extensions
2a. The given index is invalid.
2a1. ContactCS requests the user to provide the correct index
2a2. User enters new index
Steps 2a1 - 2a2 are repeated until the index entered is correct
Use case resumes from step 3.
2b. The given format is invalid.
2b1. ContactCS requests the user to provide the correct format and shows the valid command format
2b2. User enters new input
Steps 2b1 - 2b2 are repeated until the format for the entered input is valid
Use case resumes from step 3.
Use case: UC06 View usage instructions
MSS
User requests to view usage instructions for the app
ContactCS displays the usage instructions and commands available for the user
Use case ends.
Extensions
1a. The given format is invalid.
1a1. ContactCS requests the user to provide the correct format and shows the valid command format
1a2. User enters new input
Steps 1a1 - 1a2 are repeated until the format for the entered input is correct
Use case resumes from step 2.
Use case: UC07 Undo actions
MSS
User requests to undo the last action that modified contact list data
ContactCS reverts to the previous state
Use case ends.
Extensions
1a. No modification of contact list data has been performed yet.
1a1. ContactCS shows an error message indicating that there is no action to undo
Use case ends.
1b. The given format is invalid.
1b1. ContactCS requests the user to provide the correct format and shows the valid command format
1b2. User enters new input
Steps 1b1 - 1b2 are repeated until the format of the entered input is correct
Use case resumes from step 2.
Use case: UC08 Redo actions
MSS
User requests a redo
ContactCS reapplies the last undone action
Use case ends.
Extensions
1a. User tries to redo an action without having undone one first.
1a1. ContactCS shows an error message indicating that there is no action to redo
Use case ends.
1b. The given format is invalid.
1b1. ContactCS requests the user to provide the correct format and shows the valid command format
1b2. User enters new input
Steps 1b1 - 1b2 are repeated until the format of the entered input is correct
Use case resumes from step 2.
17
installed.Given below are instructions to test the app manually.
Note: These instructions only provide a starting point for testers to work on; testers are expected to do more exploratory testing.
Initial launch
Download the jar file and copy into an empty folder
Open a terminal and cd
into the folder with the jar file.
Run java -jar contactcs.jar
.
Expected: Shows the GUI with a set of sample contacts. The window size may not be optimum.
Saving window preferences
Resize the window to an optimum size. Move the window to a different location. Close the window.
Re-launch the app by rerunning java -jar contactcs.jar
in the terminal.
Expected: The most recent window size and location is retained.
Deleting person(s) while all persons are being shown
Prerequisites: List all persons using the list
command. Multiple persons in the list.
Test case: delete 1
Expected: First contact is deleted from the list. Details of the deleted contact shown in the status message.
Test case: delete 1 3
Expected: First and third contacts are deleted from the list. Details of the deleted contacts shown in the status message.
Test case: delete 0
Expected: No person is deleted. Error details shown in the status message. Status bar remains the same.
Other incorrect delete commands to try: delete
, delete x
(where x is larger than the list size), delete abc
Expected: Similar to previous.
Testing data persistence across sessions
Add a new person using the add
command.
Close the app.
Re-launch the app.
Expected: The newly added person should still be present in the list.
You can try out other data changing commands such as delete
, edit
, clear
.
Dealing with missing data file
contactcs.json
file inside the folder named data
. It is located in the same folder as the jar file.contactcs.json
file filled with sample data.add n/Alice p/11111111
command.add n/Bob p/22222222
command.add n/Catherine p/33333333
command.find
clear
command.add n/Alice p/11111111 r/CS1101S t/tag1
add n/Bob p/22222222 r/MA1521 t/tag2
add n/Catherine p/33333333 r/CS2103T t/tag3
find n/Alice n/Bob r/CS1101S
. find
command finds all persons with (name Alice or Bob) and role CS1101S.find r/CS1101S r/MA1521 t/tag1 t/tag3
find
command finds all persons with (module role CS1101S or MA1521) and (tag1 or tag 3).clear
command.add n/Alice p/11111111 r/CS1101S t/tag1
edit 1 r/CS2103T
Using role acronyms
add n/Alice p/11111111 r/CS1101S-Prof r/CS2103T-TA
TA
is short for Tutor
and Prof
is short for Professor
. You can also specify the full role name.Not specifying the role
add n/Alice p/11111111 r/MA1521
Team size: 5
Make find command shorter by allowing fuzzy search of module-role, such that user can find all contacts with roles related to a specified module, just by inputting module code or even fraction of it.
(For example:find r/CS2103T
finds all contacts related to CS2103T, find r/CS
finds all contacts related to modules whose module codes start with CS).
The current find command automatically assumes that user wants to search student role if only a module code is supplied to the find command, which may be counter-intuitive to some users.
Sometimes, user cannot remember the full module code, or wants to search over a wider range of modules, but the current implementation does not support that either,
hence reducing the usefulness of this command.
(As shown in the screenshot, find r/CS1101S
only matches contacts with role CS1101S Student, despite that there are 2 CS1101S professors in the sample data.)
(As shown in the screenshot, find r/CS
results in error messages because construction of search query requires exact module code to work.)
This limitation is due to our current system design which forces a role type to be assigned to an exact module code into the search query for the find command to execute,
we plan to adopt other ways of constructing the query to allow for more general search of module-role in the future.
Allow deletion of other optional data fields of a contact, using the current edit command approach. Currently, only the description and tag fields can be deleted, by specifying the corresponding prefix followed by an empty string (For Example: edit 9 t/
removes all tags, while edit 9 d/
removes the description of the ninth contact in the current list). However, other optional fields such as the phone, email and address cannot be removed as of v1.6.
(As shown in the screenshot, edit 9 d/
successfully removes description field from the ninth person in the current list.)
(As shown in the screenshot, edit 9 e/
as an attempt to remove email from ninth person in the current list fails, because empty email field for edit command is not allowed.
Similar issues happen when removing phone using edit 9 p/
and removing address using edit 9 a/
.)
This can be very troublesome to user if he/she accidentally adds these fields to a contact and realized that these wrong fields cannot be removed.
If these fields are left unchanged over a long period of time, user may forget that these fields are wrong and hence use the wrong information in the program, which is definitely
not desired. We plan to allow edit command to accept empty input for phone, email and address and change the parser such that the empty inputs for these fields can be considered as
deleting them from the selected contact.
Allow the user to delimit special prefixes appearing in the contact details.
Currently, if any of the input fields contain the special prefixes, the string will be split into multiple fields, which may not be the user's intention.
For example, if the user attempts to execute edit 1 d/For a/b testing
, the command will be wrongly interpreted as
For
, andb testing
. (refer to the screenshot below)
The current workaround is to add a non-whitespace character in front of the prefix (i.e. edit 1 d/For 'a/b testing
), but this is not intuitive to the user.
We plan to follow a more standard approach of using a backslash to escape the special prefixes.
More importantly, the parser will remove the backslash at the end of parsing, so that the user does not see the backslash in the final output.
Enforce realistic role assignment for contacts. Currently, a contact can have multiple roles, such as both "Professor" and "Student".
This is unrealistic, as an individual is typically either a student or a professor, but not both.
(As shown in the screenshot, Royston is both a CS1101S professor and CS2100 student.)
We plan to enforce stricter role assignment, ensuring that:
Allow command navigation using up and down arrows. Currently, the user has to type the command from scratch if he/she wants to execute a previous command again.
This can be very troublesome if the user wants to execute the same command multiple times, or if the user wants to execute a similar command to the previous one.
We plan to allow the user to navigate through the command history using the up and down arrows.
Allows sorting of contacts based on different fields. Currently, the contacts are displayed in the order they are added to the address book.
This can make it challenging for users to locate a contact if they are unsure of specific search criteria.
We plan to allow the user to view the contacts in a sorted order to find the contact he/she is looking for more easily.
Allow multi-word tags for contacts. Currently, tag field only allows alphanumeric inputs for tag creation, which means spaces, underscores(_) and dashes(-) are not
allowed in the input, and as a result prevents user from creating multi-word tags for contacts.
(As shown in the screenshot, edit 9 t/team leader
as an attempt to replace existing tags of ninth person in the current list shows an error message,
because tag input team leader
contains space which is not allowed, same issue happens with the add command)
This is not very suitable design because user may want to create multi-word tags
such as team leader
, best friend
, financial office
etc, and the current validation method does not offer this level of flexibility. Therefore, we plan to loosen the restriction
on tag creation input to allow space for word separation, so that user can create multi-word tag to contacts for easier management.
Reflect the true redo/undo states of the address book in the history command list. Currently, the history command list only shows all data changing commands executed by the user and does not precisely reflect the current and history states of the address book.
For example, if the user executes delete 1
, then delete 2
, then undo
, then delete 3
, the true history states are [delete 1, delete 3]
since delete 2
has been purged.
However, the history command list will only show all data changing commands executed so far, (refer to the screenshot below) which is not accurate.
Moreover, we plan to highlight the current state of the address book in the history command list, so that the user can easily identify the current state of the address book.
Standardize Phone Number Format for Duplicate Detection. Currently, the application allows adding multiple contacts with phone numbers that may look different but essentially represent the same number.
For example, +65 12345678 (24 hr)
and 12345678
are treated as distinct, leading to potential duplicates and inconsistencies.
We plan to implement a standardization process to recognize and handle variations in phone number formatting. Specifically:
edit
command.
Currently, it requires 2 separate edit
commands if the user wants to replace existing module roles for a contact.
We plan to allow the user to add and delete multiple module roles in a single edit
command at the same time.
For example, the user can execute edit 1 r/-CS1101S-Student r/+CS2103T-TA
to replace the existing module role CS1101S-Student with CS2103T-TA for the first contact in the list.