Skip to content

Commit

Permalink
Merge 437e272 into 486131a
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeyou committed Nov 11, 2019
2 parents 486131a + 437e272 commit 11b3a2a
Show file tree
Hide file tree
Showing 53 changed files with 1,292 additions and 72 deletions.
Empty file added Checkstyle
Empty file.
Empty file added Task
Empty file.
11 changes: 7 additions & 4 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,14 @@ image::GeneratePdfActivityDiagram.png[]


// tag::undoredo[]
=== [Proposed] Undo/Redo feature
==== Proposed Implementation
=== Undo/Redo feature
==== Implementation

The undo/redo mechanism is facilitated by `VersionedAddressBook`.
It extends `AddressBook` with an undo/redo history, stored internally as an `addressBookStateList` and `currentStatePointer`.
The undo/redo mechanism is facilitated by `VersionedCustomerManager`, `VersionedDriverManager` and
`VersionedTaskManager`.
These extend `CustomerManager`, `DriverManager` and `TaskManager` respectively, each with an undo/redo history,
stored internally as a `customerManagerStateList`, `driverManagerStateList` and `taskManagerStateList` respectively,
and a `currentStatePointer`.
Additionally, it implements the following operations:

* `VersionedAddressBook#commit()` -- Saves the current address book state in its history.
Expand Down
79 changes: 78 additions & 1 deletion docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,39 @@ Format: `list`
Exits the program. +
Format: `exit`

==== Undo a command : `undo`

Undo the most recent user command. +
Format: `undo`
****
* Only user commands that change the state of the data will be undone.
* If the last command changes the state of the stored data e.g. `addT`, then it will be undone.
* If the last command does not change the state of the stored data e.g. `list`, then a previous command that changes
the data state will be undone instead.
* Example:
** User input sequence:
*** `addD n/Uncle Alex p/888889999 e/someone@gmail.com a/1 Pine Road tt/friends`
*** `list`
*** `undo`
** Result: `undo` will undo the `addD` command, as the `list` command does not change the data state.
****

==== Redo a command : `redo`

Redo the most recently undone command. +
Format: `redo`
****
* Only user commands that change the state of the data will be redone.
* Example:
** User input sequence:
*** `addC n/Damith Bobby p/89898989 e/someoneone@gmail.com a/2 Watermelon Road`
*** `list`
*** `undo`
*** `redo`
** Result: In this case, `redo` will redo the most recently undone command i.e. `addC`. The `list` command will not be considered.
****


=== Task Management Commands

==== Add a delivery task: `addT`
Expand Down Expand Up @@ -114,7 +147,7 @@ Edits the customer and date of delivery of the task (Task ID: 5) to be `Customer
// tag::assign-command[]
==== Assign a task to a driver: `assign`

Assign an existing task a driver with a proposed time. +
Assign an existing task to a driver with a proposed time. +
Format: `assign [force] t/TASK_ID d/DRIVER_ID at/hMM - hMM`

****
Expand Down Expand Up @@ -151,6 +184,20 @@ Examples:
Remove the assigned driver and time slot from the task, and free the driver's schedule.
// end::free-command[]

==== Find a delivery task: `findT`

Finds and displays all delivery tasks that have the user input phrase in their description. +
Format: `findT [phrase] [more phrase]`
****
* This command is case-insensitive.
* Examples:
** `findT gla`
*** Finds and displays all task(s) with "gla" in their description(s).
** `findT glass`
*** Finds and displays all task(s) with "glass" in their description(s).
** `findT glass box`
*** Finds and displays all task(s) with "glass box" in their description(s).
****

==== Mark a delivery task as completed: `done`

Expand Down Expand Up @@ -232,6 +279,21 @@ Examples:

* `addC n/John Doe p/98765432 e/johnd@example.com a/311, Clementi Ave 2, #02-25 t/friends`

==== Find a customer: `findC`

Finds and displays all customers that have the user input phrase in their name. +
Format: `findC [phrase] [more phrase]`
****
* This command is case-insensitive.
* Examples:
** `findC `Johna`
*** Finds and displays all customer(s) with "Johna" in their name(s).
** `findC Bobby Rose`
*** Finds and displays all customer(s) with "Bobby Rose" in their name(s).
** `findC a`
*** Finds and displays all customer(s) with "a" in their name(s).
****


=== Driver Management Commands

Expand All @@ -249,6 +311,21 @@ Examples:

* `addD n/John Doe p/98765432 e/johnd@example.com a/311, Clementi Ave 2, #02-25 t/friends`

==== Find a driver: `findD`

Finds and displays all drivers that have the user input phrase in their name. +
Format: `findD [phrase] [more phrase]`
****
* This command is case-insensitive.
* Examples:
** `findD Uncle Sam`
*** Finds and displays all driver(s) with "Uncle Sam" in their name(s).
** `findD Ahmad`
*** Finds and displays all driver(s) with "Ahmad" in their name(s).
** `findD Tan Ah Beng`
*** Finds and displays all driver(s) with "Tan Ah Beng" in their name(s).
****

== Saving the data

Deliveria data are saved in the hard disk automatically after any command that changes the data. +
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class Messages {
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_CUSTOMERS_LISTED_OVERVIEW = "%1$d customers listed!";
public static final String MESSAGE_DRIVERS_LISTED_OVERVIEW = "%1$d drivers listed!";
public static final String MESSAGE_TASKS_LISTED_OVERVIEW = "%1$d tasks listed!";
public static final String MESSAGE_INVALID_UNDO_REQUEST = "The programme is at its initial state, no commands "
+ "available to be undone";
public static final String MESSAGE_INVALID_REDO_REQUEST = "The programme is at its latest state, no commands "
+ "available to be redone";

public static final String MESSAGE_DATA_START_NEW = "Starting with a empty manager. \n"
+ "If you had data previously, this means that your data file is corrupted";
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/seedu/address/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.io.StringWriter;
import java.util.Arrays;

import seedu.address.model.person.Driver;

/**
* Helper functions for handling strings.
*/
Expand Down Expand Up @@ -38,6 +40,37 @@ public static boolean containsWordIgnoreCase(String sentence, String word) {
.anyMatch(preppedWord::equalsIgnoreCase);
}

/**
* Returns true if the (@code sentence) contains the (@code word).
* Ignores case, but a part of the sentence must fully math the sequence of the phrase.
* <br>examples:<pre>
* containsPhraseIgnoreCase("ABc def", "abc") == true
* containsPhraseIgnoreCase("ABc def", "c def") == true
* containsPhraseIgnoreCase("ABc def", "EF") == true
* containsPhraseIgnoreCase("ABc def", "acb def") == false //not in sequence
* </pre>
*
* @param sentence cannot be null
* @param phrase cannot be null, cannot be empty
*/
public static boolean containsPhraseIgnoreCase(String sentence, String phrase) {
requireNonNull(sentence);
requireNonNull(phrase);

String preppedPhrase = phrase.trim();
checkArgument(!preppedPhrase.isEmpty(), "Phrase parameter cannot be empty");

return sentence.toLowerCase().contains(preppedPhrase);
}

/**
* Returns true if the (@code driverToCompare) is equal to (@code driverAssignedToTask).
*
*/
public static boolean isTheSameDriver(Driver driverToCompare, Driver driverAssignedToTask) {
return driverToCompare.equals(driverAssignedToTask);
}

/**
* Returns a detailed message of the t, including the stack trace.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
Command command = addressBookParser.parseCommand(commandText);
commandResult = command.execute(model);


try {
storage.saveManager(new CentralManager(model.getCustomerManager(), model.getDriverManager(),
model.getTaskManager(), model.getIdManager()));
Expand Down Expand Up @@ -78,6 +79,9 @@ public ObservableList<Task> getFilteredUnassignedTaskList() {

@Override
public ObservableList<Task> getFilteredAssignedTaskList() {
if (model.getAssignedTaskList() == null) {
model.updateAssignedTaskList();
}
return model.getAssignedTaskList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(String.format(MESSAGE_DUPLICATE_PERSON));
}

if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
model.addCustomer(customerToAdd);
model.commitManagers();

return new CommandResult(String.format(MESSAGE_SUCCESS, customerToAdd));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AddDriverCommand extends Command {

public static final String COMMAND_WORD = "addD";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a customer to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a driver to the address book. "
+ "Parameters: "
+ "[" + PREFIX_NAME + " DRIVER NAME] "
+ "[" + PREFIX_PHONE + "PHONE] "
Expand Down Expand Up @@ -73,7 +73,12 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(String.format(MESSAGE_DUPLICATE_PERSON));
}

if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
model.addDriver(driverToAdd);
model.commitManagers();

return new CommandResult(String.format(MESSAGE_SUCCESS, driverToAdd));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_INVALID_CUSTOMER_ID);
}

if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
taskToAdd.setCustomer(model.getCustomer(customerId));
model.addTask(taskToAdd);
model.commitManagers();

return new CommandResult(String.format(MESSAGE_SUCCESS, taskToAdd));
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/logic/commands/AssignCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public CommandResult execute(Model model) throws CommandException {
// saving the state of event time
Optional<EventTime> existingEventTime = task.getEventTime();

boolean isAlreadyAssigned = task.getStatus() != TaskStatus.INCOMPLETE || task.getDriver().isPresent()
|| task.getEventTime().isPresent();
boolean isAlreadyAssigned = task.getStatus() != TaskStatus.INCOMPLETE
|| task.getDriver().isPresent() || task.getEventTime().isPresent();

if (isAlreadyAssigned) {
resetTaskIfForced(task);
Expand All @@ -172,8 +172,14 @@ public CommandResult execute(Model model) throws CommandException {
}

forceAssign(driver, task, eventTime);

model.refreshAllFilteredList();

if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
model.commitManagers();

return new CommandResult(buildSuccessfulResponse(suggestion, task, driver, eventTime));
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public class ClearCommand extends Command {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
model.resetCentralManager();
model.commitManagers();
return new CommandResult(MESSAGE_SUCCESS);
}
}
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public CommandResult execute(Model model) throws CommandException {

Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);

if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
model.commitManagers();
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteIdCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public CommandResult execute(Model model) throws CommandException {
assert isDeleteSuccess;
}

if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
model.deleteTask(taskToDelete);
model.commitManagers();

return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, className, taskToDelete));
} else if (className.equals(Customer.class.getSimpleName())) {
Expand All @@ -79,7 +83,12 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(String.format(MESSAGE_CANNOT_DELETE_IF_ALLOCATED, className));
}

if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
model.deleteCustomer(customerToDelete);
model.commitManagers();

return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, className, customerToDelete));
} else {
//deletion for Driver
Expand All @@ -94,7 +103,12 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(String.format(MESSAGE_CANNOT_DELETE_IF_ALLOCATED, className));
}

if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
model.deleteDriver(driverToDelete);
model.commitManagers();

return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, className, driverToDelete));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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.DriverIsTheSamePredicate;

/**
* Display all the tasks assigned to the driver given by the input index.
* This command is a follow up search after the FindDriverCommand.
*/
public class DisplayDriverTasksCommand extends Command {

public static final String COMMAND_WORD = "driver";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all the tasks assigned to the driver given by "
+ "the specified index and displays them as a list with index numbers.\n"
+ "Parameters: [INDEX NUMBER]\n"
+ "Example: " + COMMAND_WORD + " 1";

private final DriverIsTheSamePredicate predicate;

public DisplayDriverTasksCommand(DriverIsTheSamePredicate predicate) {
this.predicate = predicate;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);

model.updateFilteredTaskList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_TASKS_LISTED_OVERVIEW, model.getFilteredTaskList().size()));
}
}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/commands/DoneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public CommandResult execute(Model model) throws CommandException {
//if task is ONGOING, it must have a driver and eventTime
freeDriverFromTask(taskToMark.getDriver().get(), taskToMark.getEventTime().get());

if (model.shouldTruncateManagers()) {
model.truncateManagers();
}
model.commitManagers();
return new CommandResult(String.format(MESSAGE_MARK_TASK_COMPLETED, taskToMark.getId()));
}

Expand Down
Loading

0 comments on commit 11b3a2a

Please sign in to comment.