Skip to content

Commit

Permalink
Merge pull request #65 from ananya21/assign-team
Browse files Browse the repository at this point in the history
Add AssignTeamCommand and AssignTeamCommandParser
  • Loading branch information
ananya21 authored Apr 3, 2024
2 parents 21a7a23 + 1537cac commit feec0a0
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class AssignPersonCommand extends Command {

public static final String COMMAND_WORD = "add person";
public static final String COMMAND_WORD = "assign person";

public static final String MESSAGE_USAGE = COMMAND_WORD + "PERSON_NAME"
+ "/to TASK_NAME"
Expand All @@ -27,6 +27,9 @@ public class AssignPersonCommand extends Command {
public static final String MESSAGE_TASK_NOT_FOUND = "Task %1s not found: "
+ "Please make sure the task exists.";

public static final String MESSAGE_MEMBER_NOT_FOUND = "Team member %1s not found: "
+ "Please make sure the person exists.";

public static final String MESSAGE_SUCCESS = "The person %1$s has been assigned to the following task %2$s.";

private final Task task;
Expand Down Expand Up @@ -55,6 +58,10 @@ public CommandResult execute(Model model) throws CommandException {
Messages.format(project)));
}

if (!projectAssign.hasMember(member)) {
throw new CommandException(String.format(MESSAGE_MEMBER_NOT_FOUND, member));
}

Task assignTask = projectAssign.findTask(task.getName());

if (assignTask.equals(null)) {
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/seedu/address/logic/commands/AssignTeamCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import java.util.ArrayList;
import java.util.List;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.project.Member;

/**
* Adds a task to a project.
*/
public class AssignTeamCommand extends Command {

public static final String COMMAND_WORD = "assign team";

public static final String MESSAGE_USAGE = COMMAND_WORD + "PERSON_NAME, PERSON_NAME, PERSON_NAME"
+ "/to PROJECT_NAME";

public static final String MESSAGE_PROJECT_NOT_FOUND = "Project %1$s not found: "
+ "Please make sure the project exists.";

public static final String MESSAGE_SUCCESS = "The team %1$s has been assigned to the following project %2$s.";
private final Person project;

private final List<Member> team;

/**
* Creates an AddCommand to add the specified {@code Person}
*/
public AssignTeamCommand(List<String> team, Person project) {
this.project = project;
this.team = new ArrayList<>();
for (String name : team) {
this.team.add(new Member(name));
}
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
Person projectAssign = model.findPerson(project.getName());

if (projectAssign.equals(null)) {
throw new CommandException(String.format(
MESSAGE_PROJECT_NOT_FOUND,
Messages.format(project)));
}

projectAssign.assignTeam(this.team);

return new CommandResult(String.format(MESSAGE_SUCCESS, team, Messages.format(projectAssign)));
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("set Team", team)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import seedu.address.logic.commands.AddProjectCommand;
import seedu.address.logic.commands.AddTaskCommand;
import seedu.address.logic.commands.AssignPersonCommand;
import seedu.address.logic.commands.AssignTeamCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteProjectCommand;
Expand Down Expand Up @@ -71,6 +72,9 @@ public Command parseCommand(String userInput) throws ParseException {
case AssignPersonCommand.COMMAND_WORD:
return new AssignPersonCommandParser().parse(arguments);

case AssignTeamCommand.COMMAND_WORD:
return new AssignTeamCommandParser().parse(arguments);

case SetStatusCommand.COMMAND_WORD:
return new SetStatusCommandParser().parse(arguments);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import seedu.address.logic.commands.AssignTeamCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Person;


/**
* Parses input arguments and creates a new AddCommand object
*/
public class AssignTeamCommandParser implements Parser<AssignTeamCommand> {

/**
* Parses the given {@code String} of arguments in the context of the AddCommand
* and returns an AddCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public AssignTeamCommand parse(String args) throws ParseException {
try {
if (!args.contains(" /to ")) {
throw new ParseException("Whoops! When referring to another field like a project,"
+ " always remember to put /to instead of just to.");
}
String members = args.split(" /to")[0].trim();
String projectName = args.split(" /to")[1].trim();
List<String> team = Arrays.stream(members.split(","))
.map(String::trim)
.collect(Collectors.toList());
if ((team.size() == 0) || (projectName.length() == 0)) {
throw new ParseException("Please enter the project and team fields");
}
Person project = new Person(ParserUtil.parseName(projectName));
return new AssignTeamCommand(team, project);
} catch (IndexOutOfBoundsException e) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
AssignTeamCommand.MESSAGE_USAGE));
}
}
}
28 changes: 27 additions & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.project.Member;
import seedu.address.model.project.Task;

/**
Expand All @@ -26,7 +28,8 @@ public class Person {

private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy");

private String status;
private List<Member> team = new ArrayList<>();
private String status = "None";
private String category;

/**
Expand Down Expand Up @@ -55,6 +58,10 @@ public void addTask(Task task) {
taskList.add(task);
}

public void assignTeam(List<Member> team) {
this.team = team;
}

/**
* Removes task from the Person object
*/
Expand Down Expand Up @@ -197,6 +204,12 @@ public String toString() {
.add("name", name).toString();
}

public String getTeam() {
return team.stream()
.map(Member::toString) // Assuming Member class has getName() method returning String
.collect(Collectors.joining(", "));
}

/**
* Returns true if the Person has a task that is equal to the specified task
*/
Expand All @@ -209,6 +222,19 @@ public boolean hasTask(Task task) {
return false;
}

/**
* @param member member to be found inside the team member list
* @return boolean value (true/false) depending on whether the member is in the team
*/
public boolean hasMember(Member member) {
for (Member m : team) {
if (m.equals(member)) {
return true;
}
}
return false;
}

/**
* Returns a new person with new name but the same task (for edit person command)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/project/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Task)) {
if (!(obj instanceof Member)) {
return false;
}
Member other = (Member) obj;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/ui/TaskListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ public class TaskListPanel extends UiPart<Region> {
@FXML
private ListView<Task> doneTaskListView;

@FXML
private Label team;

/**
* Creates a {@code PersonListPanel} with the given {@code ObservableList}.
*/
public TaskListPanel(Person currentProject) {
super(FXML);
this.currentProject = currentProject;
showingProjectName.setText("Showing Project: " + currentProject.getName().fullName);
team.setText("Team Members: " + currentProject.getTeam());

undoneTaskListView.getItems().clear();
undoneTaskListView.getItems().addAll(currentProject.getUndoneTasks());
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/view/TaskListPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
<Insets top="20" right="8" bottom="20" left="8" />
</padding>
<Label fx:id="showingProjectName" styleClass="cell_big_label" />
</StackPane>
<StackPane VBox.vgrow="NEVER" styleClass="pane-with-border"
minWidth="280" prefWidth="280" minHeight="54" prefHeight="54">
<padding>
<Insets top="120" right="8" bottom="120" left="8" />
</padding>
<Label fx:id="team" styleClass="cell_big_label" />

</StackPane>
<HBox fx:id="taskList" styleClass="pane-with-border"
Expand Down

0 comments on commit feec0a0

Please sign in to comment.