Skip to content

Commit

Permalink
Merge pull request #83 from AY2021S1-CS2103T-T10-1/feature-issue-82
Browse files Browse the repository at this point in the history
Add task to project
  • Loading branch information
pr4aveen authored Oct 24, 2020
2 parents f87fe60 + bef220e commit 09a99f0
Show file tree
Hide file tree
Showing 96 changed files with 2,176 additions and 1,213 deletions.
2 changes: 1 addition & 1 deletion docs/diagrams/tracing/LogicSequenceDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ create ecp
abp -> ecp
abp -> ecp ++: parse(arguments)
create ec
ecp -> ec ++: index, editProjectDescriptor
ecp -> ec ++: index, editTrackedItemDescriptor
ec --> ecp --
ecp --> abp --: command
abp --> logic --: command
Expand Down
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Momentum
---

[![CI Status](https://github.com/se-edu/addressbook-level3/workflows/Java%20CI/badge.svg)](https://github.com/se-edu/addressbook-level3/actions)
[![codecov](https://codecov.io/gh/se-edu/addressbook-level3/branch/master/graph/badge.svg)](https://codecov.io/gh/se-edu/addressbook-level3)
[![codecov](https://codecov.io/gh/AY2021S1-CS2103T-T10-1/tp/branch/master/graph/badge.svg)](https://codecov.io/gh/AY2021S1-CS2103T-T10-1/tp)

![Ui](images/Ui.png)

Expand All @@ -18,3 +18,4 @@ title: Momentum

* Libraries used: [JavaFX](https://openjfx.io/), [Jackson](https://github.com/FasterXML/jackson), [JUnit5](https://github.com/junit-team/junit5)
* This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org).

2 changes: 1 addition & 1 deletion docs/tutorials/TracingCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
public CommandResult execute(Model model) throws CommandException {
...
Person projectToEdit = lastShownList.get(index.getZeroBased());
Person editedProject = createEditedPerson(projectToEdit, editProjectDescriptor);
Person editedProject = createEditedPerson(projectToEdit, editTrackedItemDescriptor);
if (!projectToEdit.isSamePerson(editedProject) && model.hasPerson(editedProject)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/momentum/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import seedu.momentum.logic.parser.exceptions.ParseException;
import seedu.momentum.logic.statistic.StatisticGenerator;
import seedu.momentum.model.ReadOnlyProjectBook;
import seedu.momentum.model.project.Project;
import seedu.momentum.model.project.TrackedItem;

/**
* API of the Logic component
Expand All @@ -33,14 +33,14 @@ public interface Logic {
ReadOnlyProjectBook getProjectBook();

/**
* Returns an unmodifiable view of the filtered list of projects
* Returns an unmodifiable view of the filtered list of tracked items.
*/
ObservableList<Project> getFilteredProjectList();
ObservableList<TrackedItem> getFilteredTrackedItemList();

/**
* Returns a list of projects whose timers are running
* Returns a list of projects whose timers are running.
*/
ObservableList<Project> getRunningTimers();
ObservableList<TrackedItem> getRunningTimers();

/**
* Returns the user prefs' project book file path.
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/seedu/momentum/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import seedu.momentum.logic.statistic.StatisticManager;
import seedu.momentum.model.Model;
import seedu.momentum.model.ReadOnlyProjectBook;
import seedu.momentum.model.project.Project;
import seedu.momentum.model.project.TrackedItem;
import seedu.momentum.storage.Storage;

/**
Expand Down Expand Up @@ -45,8 +45,10 @@ public LogicManager(Model model, Storage storage) {
public CommandResult execute(String commandText) throws CommandException, ParseException {
logger.info("----------------[USER COMMAND][" + commandText + "]");

model.resetView();

CommandResult commandResult;
Command command = projectBookParser.parseCommand(commandText);
Command command = projectBookParser.parseCommand(commandText, model);
commandResult = command.execute(model);

try {
Expand All @@ -70,12 +72,12 @@ public ReadOnlyProjectBook getProjectBook() {
}

@Override
public ObservableList<Project> getFilteredProjectList() {
return model.getFilteredProjectList();
public ObservableList<TrackedItem> getFilteredTrackedItemList() {
return model.getFilteredTrackedItemList();
}

@Override
public ObservableList<Project> getRunningTimers() {
public ObservableList<TrackedItem> getRunningTimers() {
return model.getRunningTimers();
}

Expand Down
44 changes: 35 additions & 9 deletions src/main/java/seedu/momentum/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.momentum.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.momentum.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.momentum.logic.parser.CliSyntax.PREFIX_DEADLINE_DATE;
import static seedu.momentum.logic.parser.CliSyntax.PREFIX_DEADLINE_TIME;
import static seedu.momentum.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
Expand All @@ -9,7 +10,10 @@

import seedu.momentum.logic.commands.exceptions.CommandException;
import seedu.momentum.model.Model;
import seedu.momentum.model.ViewMode;
import seedu.momentum.model.project.Project;
import seedu.momentum.model.project.Task;
import seedu.momentum.model.project.TrackedItem;

/**
* Adds a project to the project book.
Expand All @@ -33,26 +37,48 @@ public class AddCommand extends Command {
public static final String MESSAGE_SUCCESS = "New project added: %1$s";
public static final String MESSAGE_DUPLICATE_PROJECT = "This project already exists in the project book";

private final Project toAdd;
private TrackedItem toAdd;

private Project projectToAddTask;
private Task taskToAdd;

/**
* Creates an AddCommand to add the specified {@code Project}
*/
public AddCommand(Project project) {
requireNonNull(project);
toAdd = project;
public AddCommand(TrackedItem trackedItem) {
requireNonNull(trackedItem);
toAdd = trackedItem;
}

/**
* Creates an AddCommand to add the specified {@code Task} to the specificed {@code Project}
*/
public AddCommand(Task task, Project project) {
requireAllNonNull(task, project);
taskToAdd = task;
projectToAddTask = project;
}

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

if (model.hasProject(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PROJECT);
}
ViewMode viewMode = model.getViewMode();

model.addProject(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
if (viewMode == ViewMode.PROJECTS) {
if (model.hasTrackedItem(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PROJECT);
}

model.addTrackedItem(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
} else {
if (projectToAddTask.hasTask(taskToAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PROJECT);
}
projectToAddTask.addTask(taskToAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, taskToAdd));
}
}

@Override
Expand Down
38 changes: 34 additions & 4 deletions src/main/java/seedu/momentum/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import seedu.momentum.commons.core.index.Index;
import seedu.momentum.logic.commands.exceptions.CommandException;
import seedu.momentum.model.Model;
import seedu.momentum.model.ViewMode;
import seedu.momentum.model.project.Project;
import seedu.momentum.model.project.TrackedItem;

/**
* Deletes a project identified using it's displayed index from the project book.
Expand All @@ -25,23 +27,51 @@ public class DeleteCommand extends Command {
public static final String MESSAGE_DELETE_PROJECT_SUCCESS = "Deleted Project: %1$s";

private final Index targetIndex;
private Project projectToDeleteTaskFrom;

/**
* Deletes a project at a given index from the project book.
*
* @param targetIndex index of the project to be deleted.
*/
public DeleteCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}

/**
* Deletes a task at a given index from a certain project.
*
* @param targetIndex index of the task to be deleted.
* @param project project to delete the task from.
*/
public DeleteCommand(Index targetIndex, Project project) {
this.targetIndex = targetIndex;
this.projectToDeleteTaskFrom = project;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Project> lastShownList = model.getFilteredProjectList();

ViewMode viewMode = model.getViewMode();

List<TrackedItem> lastShownList = viewMode == ViewMode.PROJECTS
? model.getFilteredTrackedItemList()
: projectToDeleteTaskFrom.getTaskList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PROJECT_DISPLAYED_INDEX);
}

Project projectToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteProject(projectToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PROJECT_SUCCESS, projectToDelete));
TrackedItem trackedItemToDelete = lastShownList.get(targetIndex.getZeroBased());

if (viewMode == ViewMode.PROJECTS) {
model.deleteTrackedItem(trackedItemToDelete);
} else {
projectToDeleteTaskFrom.deleteTask(trackedItemToDelete);
}

return new CommandResult(String.format(MESSAGE_DELETE_PROJECT_SUCCESS, trackedItemToDelete));
}

@Override
Expand Down
Loading

0 comments on commit 09a99f0

Please sign in to comment.