Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statistics #65

Merged
merged 10 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/webapp/app/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ h2 {
height: 30px;
}
#personal-block {
height: 10px;
height: 180px;
}
#form {
text-align: center;
Expand Down Expand Up @@ -112,4 +112,10 @@ a {
#rbtnUser {
margin-right: 100px;
}
div#metrics {
float: right;
margin-right: 40px;
font-family: "Segoe UI", Arial, sans-serif;
margin-bottom: 10px;
}

1 change: 0 additions & 1 deletion src/main/webapp/app/findgoals.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
<td>{{daysLeft}}</td>
</tr>
</table>

</div>
</body>
</html>
29 changes: 27 additions & 2 deletions src/main/webapp/app/js/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,35 @@ function switchPersonalData() {
block.classList.add("w3-hide");
}
}

function displayError(response, expected) {
if (response.status !== expected) {
alert("Something went wrong! error: " + response.status.toString());
history.go(-1);
}
}
}
function generateMetrics(goals) {
var completed = 0;
var overdue = 0;
var open = 0;
for (var i = 0; i < goals.length; i++) {
var goal = goals[i];
switch (goal.goalStatus) {
case "ACHIEVED":
completed++;
break;
case "OVERDUE":
overdue++;
break;
default:
open++;
}
}
var obj = "<table>" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a clearer name, such as statisticsTable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will do

"<tr><td><h4>Statistics</h4></td></tr>" +
"<tr><td>" + "Goals Total: " + goals.length + "</td></tr>" +
"<tr><td>" + "Goals Achieved: " + completed + "</td></tr>" +
"<tr><td>" + "Goals Overdue: " + overdue + "</td></tr>" +
"<tr><td>" + "Goals Open: " + open + "</td></tr>" +
"</table>";
document.getElementById("metrics").innerHTML = obj;
}
3 changes: 2 additions & 1 deletion src/main/webapp/app/js/start-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ function showUserGoals() {
};
}
w3DisplayData("goals-list", tabledata);
generateMetrics(goals);
});
}
}
3 changes: 2 additions & 1 deletion src/main/webapp/app/js/user-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function setDataToFields(userDto) {
if (list.length > 0) {
tabledata = {"goals": list};
w3DisplayData("goals-list", tabledata);
generateMetrics(list);
} else {
document.getElementById("hidden").classList.remove("w3-hide");
document.getElementById("goals-list").classList.add("w3-hide");
Expand All @@ -48,4 +49,4 @@ function getQueryVariable(variable) {
}
}
return (false);
}
}
1 change: 1 addition & 0 deletions src/main/webapp/app/start.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
</div>
<div id="personal-block" class="w3-hide">
<h3 id="phone_email"></h3>
<div id="metrics"></div>
</div>
<table id="goals-list" class="w3-table-all w3-hoverable">
<tr class="w3-brown">
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/user.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
</div>
<div id="personal-block" class="w3-hide">
<h3 id="email-and-phone">{{email}} | {{phone}}</h3>
<div id="metrics"></div>
</div>
<p id="hidden" class="w3-hide w3-display-middle w3-xlarge">At the moment this user has no goals.</p>
<table id="goals-list" class="w3-table-all w3-hoverable">
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/lv/ctco/javaschool/goal/boundary/GoalApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,41 @@ private GoalFormDto setupGoalFormDto() {
result.setDeadline(LocalDate.of(2918, 1, 1));
return result;
}

@Test
@DisplayName("test setStatusAchieved: changes status")
void testSetStatusAchieved() {
Long id = goal.getId();
goal.setStatus(GoalStatus.OVERDUE);
when(userStore.getCurrentUser())
.thenReturn(user1);
when(goalStore.getGoalById(id))
.thenReturn(Optional.of(goal));
goalApi.setStatusAchieved(id);
assertThat(goal.getStatus(), is(GoalStatus.ACHIEVED));
}

@Test
@DisplayName("test setStatusAchieved: throws ValidationException wrong user")
void testSetStatusAchievedThrowsExceptionIfWrongUser() {
Copy link
Contributor

@olegvm olegvm Sep 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For such long names, underscores can be used to separate parts of names:
testSetStatusAchieved_ThrowsExceptionIfWrongUser
I.e. "test" + method name that is being tested + underscore + extra part (+ underscore + more parts...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. will remember should i do it now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better do it, should be quick to do.

Long id = goal.getId();
goal.setStatus(GoalStatus.OVERDUE);
when(userStore.getCurrentUser())
.thenReturn(user2);
when(goalStore.getGoalById(id))
.thenReturn(Optional.of(goal));
assertThrows(ValidationException.class, () -> goalApi.setStatusAchieved(id));
}

@Test
@DisplayName("test setStatusAchieved: throws ValidationException no goal")
void testSetStatusAchievedThrowsExceptionIfNoGoal() {
Long id = goal.getId();
goal.setStatus(GoalStatus.OPEN);
when(userStore.getCurrentUser())
.thenReturn(user2);
when(goalStore.getGoalById(id))
.thenReturn(Optional.empty());
assertThrows(ValidationException.class, () -> goalApi.setStatusAchieved(id));
}
}