Skip to content

Commit b1cdc37

Browse files
committed
Improving the UI
1 parent fc276a6 commit b1cdc37

File tree

4 files changed

+73
-23
lines changed

4 files changed

+73
-23
lines changed

tests_e2e/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>microservices.book</groupId>
5-
<artifactId>tests-e2e-v9</artifactId>
5+
<artifactId>tests-e2e-v10</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.9.0-SNAPSHOT</version>
7+
<version>0.10.0-SNAPSHOT</version>
88
<build>
99
<plugins>
1010
<plugin>
@@ -17,7 +17,7 @@
1717
</plugin>
1818
</plugins>
1919
</build>
20-
<name>tests-e2e-v9</name>
20+
<name>tests-e2e-v10</name>
2121
<description>End to End tests - Microservices - The Practical Way (Book)</description>
2222

2323
<properties>

ui/webapps/ui/gamification-client.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ function updateLeaderBoard() {
1212
});
1313
}
1414

15+
function updateStats(userId) {
16+
$.ajax({
17+
url: SERVER_URL + "/stats?userId=" + userId,
18+
success: function(data) {
19+
$('#stats-div').show();
20+
$('#stats-user-id').empty().append(userId);
21+
$('#stats-score').empty().append(data.score);
22+
$('#stats-badges').empty().append(data.badges.join());
23+
},
24+
error: function(data) {
25+
$('#stats-div').show();
26+
$('#stats-user-id').empty().append(userId);
27+
$('#stats-score').empty().append(0);
28+
$('#stats-badges').empty();
29+
}
30+
});
31+
}
32+
1533
$(document).ready(function() {
1634

1735
updateLeaderBoard();

ui/webapps/ui/index.html

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,25 @@ <h1 class="text-center">
3737
</p>
3838
<div class="result-message"></div>
3939

40-
<h2>Stats</h2>
41-
<table id="stats" class="table">
42-
<tr>
43-
<th>Attempt ID</th>
44-
<th>Multiplication</th>
45-
<th>You entered</th>
46-
<th>Correct?</th>
47-
</tr>
48-
<tbody id="stats-body"></tbody>
49-
</table>
40+
<div id="stats-div" style="display: none;">
41+
<h2>Your statistics</h2>
42+
<table id="stats" class="table">
43+
<tbody>
44+
<tr>
45+
<td class="info">User ID:</td>
46+
<td id="stats-user-id"></td>
47+
</tr>
48+
<tr>
49+
<td class="info">Score:</td>
50+
<td id="stats-score"></td>
51+
</tr>
52+
<tr>
53+
<td class="info">Badges:</td>
54+
<td id="stats-badges"></td>
55+
</tr>
56+
</tbody>
57+
</table>
58+
</div>
5059

5160
</div>
5261
<div class="col-md-6">
@@ -61,6 +70,19 @@ <h3>Leaderboard</h3>
6170
<div class="text-right">
6271
<button id="refresh-leaderboard" class="btn btn-default" type="submit">Refresh</button>
6372
</div>
73+
74+
<div id="results-div" style="display: none;">
75+
<h2>Your latest attempts</h2>
76+
<table id="results" class="table">
77+
<tr>
78+
<th>Attempt ID</th>
79+
<th>Multiplication</th>
80+
<th>You entered</th>
81+
<th>Correct?</th>
82+
</tr>
83+
<tbody id="results-body"></tbody>
84+
</table>
85+
</div>
6486
</div>
6587
</div>
6688
</div>

ui/webapps/ui/multiplication-client.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ function updateMultiplication() {
1313
});
1414
}
1515

16-
function updateStats(alias) {
16+
function updateResults(alias) {
17+
var userId = -1;
1718
$.ajax({
1819
url: SERVER_URL + "/results?alias=" + alias,
19-
}).then(function(data) {
20-
$('#stats-body').empty();
21-
data.forEach(function(row) {
22-
$('#stats-body').append('<tr><td>' + row.id + '</td>' +
23-
'<td>' + row.multiplication.factorA + ' x ' + row.multiplication.factorB + '</td>' +
24-
'<td>' + row.resultAttempt + '</td>' +
25-
'<td>' + (row.correct === true ? 'YES' : 'NO') + '</td></tr>');
26-
});
20+
async: false,
21+
success: function(data) {
22+
$('#results-div').show();
23+
$('#results-body').empty();
24+
data.forEach(function(row) {
25+
$('#results-body').append('<tr><td>' + row.id + '</td>' +
26+
'<td>' + row.multiplication.factorA + ' x ' + row.multiplication.factorB + '</td>' +
27+
'<td>' + row.resultAttempt + '</td>' +
28+
'<td>' + (row.correct === true ? 'YES' : 'NO') + '</td></tr>');
29+
});
30+
userId = data[0].user.id;
31+
}
2732
});
33+
return userId;
2834
}
2935

3036
$(document).ready(function() {
@@ -67,6 +73,10 @@ $(document).ready(function() {
6773

6874
updateMultiplication();
6975

70-
updateStats(userAlias);
76+
setTimeout(function(){
77+
var userId = updateResults(userAlias);
78+
updateStats(userId);
79+
updateLeaderBoard();
80+
}, 300);
7181
});
7282
});

0 commit comments

Comments
 (0)