Skip to content

Commit

Permalink
Merge pull request #95 from samuelchristopher/ui-project-view
Browse files Browse the repository at this point in the history
Project View
  • Loading branch information
riazaham authored Oct 28, 2020
2 parents 3c5223a + 28c707d commit c8148e9
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public String executeCommand(ArrayList<Project> projects, ArrayList<TeamMember>
}
try {
Project selectedProject = projects.get(projectIndex);
System.out.println("Switched to Project \"" + selectedProject.getProjectName() + "\"");
//For small sam => help me implement this
return selectedProject.toString();
String projectView = Ui.projectViewMessage(selectedProject);
return projectView;
} catch (IndexOutOfBoundsException e) {
throw new DukeExceptions("invalidProjectID");
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/duke/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public boolean isDone() {
protected LocalDate date;
protected TeamMember member;
protected int estimateInMinutes = 0;
protected int actualInMinutes;
protected int actualInMinutes = 0;
protected String priority;

public String getPriority() {
return priority;
return (priority != null) ? priority : "—";
}

public void setPriority(String priority) {
Expand Down Expand Up @@ -65,7 +65,7 @@ public String getTaskDescription() {
}

public String getDateString() {
return date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
return (date != null) ? date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) : "—";
}

public TeamMember getMember() {
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/seedu/duke/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,109 @@ public static String printSwitchedToHomeViewMessage() {
return "Switched to Home View";
}

public static String projectViewMessage(Project project) {
try {
String projectTitle = "Project \"" + project.getProjectName() + "\"";
String taskListTitle = "\n ---------------------\n| TASK LIST |\n ---------------------";
String membersListTitle = "\n ---------------------\n| MEMBERS LIST |\n ---------------------";
String statusSpaces = " "; // 6
String descriptionSpaces = " "; // 19
String deadlineSpaces = " "; // 16
String prioritySpaces = " "; // 14
String expectedSpaces = " "; // 17
String actualSpaces = " "; // 13
String membersSpaces = " "; // 16
String tableLabel = "Status Description "
+ "Deadline Priority Expected Hrs Actual Hrs | Members Involved\n"
+ "------------------------------------------------"
+ "----------------------------------------|------------------";
Integer extra = 0;
Integer i = 0;
String currentTaskLine = "";
String taskLines = "\n";
if (project.getTaskList().size() > 0) {
for (; i < project.getTaskList().size(); i++) {
Task currentTask = project.getTaskList().get(i);
String status = currentTask.isDone() ? "(Y)" : "(N)";
String description = currentTask.getTaskDescription();
String deadline = currentTask.getDateString();
String memberName;

currentTaskLine = status + statusSpaces + description
+ (descriptionSpaces.substring(0, descriptionSpaces.length() - description.length()));
if (deadline.length() > 0) {
currentTaskLine += (deadline);
} else {
currentTaskLine += "—";
}

currentTaskLine += (deadlineSpaces.substring(0, deadlineSpaces.length() - deadline.length()));

String priority = currentTask.getPriority();
if (priority.length() > 0) {
currentTaskLine += (priority);
} else {
currentTaskLine += "—";
}
currentTaskLine += (prioritySpaces.substring(0, prioritySpaces.length() - priority.length()));

Integer estimate = currentTask.getEstimate();
if (estimate > 1) {
currentTaskLine += (estimate / 60);
extra = estimate.toString().length() - 1;
} else {
currentTaskLine += "—";
extra = 0;
}
currentTaskLine += (expectedSpaces.substring(0, expectedSpaces.length()
- estimate.toString().length() + extra));

Integer actual = currentTask.getActual();
if (actual > 1) {
currentTaskLine += (actual / 60);
} else {
currentTaskLine += "—";
}

extra = actual.toString().length() - 1;
currentTaskLine += (actualSpaces.substring(0, actualSpaces.length()
- actual.toString().length() + extra));

TeamMember member = currentTask.getMember();
if (member != null) {
currentTaskLine += "| " + member.getName();
memberName = member.getName();
} else {
currentTaskLine += "| —";
memberName = "| —";
}
currentTaskLine += (membersSpaces.substring(0, membersSpaces.length() - memberName.length()));

taskLines += (currentTaskLine + "\n");
}
} else {
taskLines += "No tasks have been added to this project.";
}

ArrayList<TeamMember> members = project.getTeamMembers();
String membersListLines = "";
if (members.size() > 0) {
for (int j = 0; j < members.size(); j++) {
membersListLines += (j + 1) + ". " + members.get(j).getName() + "\n";
}
} else {
membersListLines += "No team members have been assigned to this project.";
}

return projectTitle + "\n" + taskListTitle + "\n"
+ (project.getTaskList().size() > 0 ? tableLabel : "") + taskLines
+ "\n \n" + membersListTitle + "\n" + membersListLines;
} catch (Error e) {
System.out.println(e.getMessage());
}
return "hi";
}

public static String printMemberAssignedToTaskMessage(String memberName, String taskName) {
return "Member \"" + memberName + "\" has been assigned to \"" + taskName + "\"";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static void testSetup() {
projects.add(projectOne);
projects.add(projectTwo);
projects.add(projectThree);
projectTwo.addDescription("Do CS2113 Tutorial by today");
projectTwo.addProjectDeadline(LocalDate.parse("2020-12-31"));
}

Expand All @@ -40,7 +39,19 @@ void executeCommand_validProjectIdWithDescription_additionalInformation() throws
HashMap<String, String> params = new HashMap<>();
params.put("p","2");
ProjectSelectCommand selectProject = new ProjectSelectCommand(params);
String expectedOutput = "Description: Do CS2113 Tutorial by today | Deadline: 2020-12-31";
String expectedOutput = "Project \"Project Two\"\n"
+ "\n"
+ " ---------------------\n"
+ "| TASK LIST |\n"
+ " ---------------------\n"
+ "\n"
+ "No tasks have been added to this project.\n"
+ " \n"
+ "\n"
+ " ---------------------\n"
+ "| MEMBERS LIST |\n"
+ " ---------------------\n"
+ "No team members have been assigned to this project.";
String actualOutput = selectProject.executeCommand(projects, teamMembers);
assertEquals(expectedOutput, actualOutput);
}
Expand Down

0 comments on commit c8148e9

Please sign in to comment.