Skip to content

Commit 8861220

Browse files
committed
stats on home page are now loaded in the background (makes main site load much faster)
1 parent 0059e78 commit 8861220

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed
Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
11
<h2>Current Statistics</h2>
22

3-
<p>There have been
4-
<span class="label label-info">${statsSummary["userCount"]}</span> user${statsSummary["userCount"] == 1 ? "" : "s"}
5-
of this system who have logged in to
6-
<span class="label label-info">${statsSummary["clientCount"]}</span> total site${statsSummary["clientCount"] == 1 ? "" : "s"},
7-
for a total of
8-
<span class="label label-info">${statsSummary["approvalCount"]}</span> site approval${statsSummary["approvalCount"] == 1 ? "" : "s"}.</p>
3+
<p id="statsloader" class="muted">Loading statistics...</p>
4+
5+
<p id="stats">There have been
6+
<span class="label label-info" id="userCount">?</span> <span id="userCountLabel">users</span>
7+
of this system who have authorized
8+
<span class="label label-info" id="clientCount">?</span> total <span id="clientCountLabel">sites</span>,
9+
with a total of
10+
<span class="label label-info" id="approvalCount">?</span> site <span id="approvalCountLabel">approvals</span>.</p>
11+
12+
<script type="text/javascript">
13+
14+
$(document).ready(function() {
15+
16+
$('#stats').hide();
17+
18+
var base = $('base').attr('href');
19+
$.getJSON(base + 'api/stats/summary', function(data) {
20+
var stats = data;
21+
22+
$('#userCount').html(stats.userCount);
23+
if (stats.userCount == 1) {
24+
$('#userCountLabel').append('s');
25+
}
26+
$('#clientCount').html(stats.clientCount);
27+
if (stats.clientCount == 1) {
28+
$('#clientCount').append('s');
29+
}
30+
$('#approvalCount').html(stats.approvalCount);
31+
if (stats.approvalCount == 1) {
32+
$('#approvalCount').append('s');
33+
}
34+
35+
36+
$('#statsloader').hide();
37+
$('#stats').show();
38+
39+
});
40+
41+
42+
});
43+
44+
</script>

openid-connect-server/src/main/java/org/mitre/openid/connect/web/ManagerController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public class ManagerController {
3838
@RequestMapping({"", "home", "index"})
3939
public String showHomePage(ModelMap m) {
4040

41-
Map<String, Integer> summary = statsService.getSummaryStats();
41+
//Map<String, Integer> summary = statsService.getSummaryStats();
4242

43-
m.put("statsSummary", summary);
43+
//m.put("statsSummary", summary);
4444
return "home";
4545
}
4646

openid-connect-server/src/main/java/org/mitre/openid/connect/web/StatsAPI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.web.bind.annotation.RequestMapping;
2828

2929
@Controller
30-
@PreAuthorize("hasRole('ROLE_USER')")
3130
@RequestMapping("/api/stats")
3231
public class StatsAPI {
3332

@@ -45,6 +44,7 @@ public String statsSummary(ModelMap m) {
4544

4645
}
4746

47+
@PreAuthorize("hasRole('ROLE_USER')")
4848
@RequestMapping(value = "byclientid", produces = "application/json")
4949
public String statsByClient(ModelMap m) {
5050
Map<Long, Integer> e = statsService.getByClientId();
@@ -54,6 +54,7 @@ public String statsByClient(ModelMap m) {
5454
return "jsonEntityView";
5555
}
5656

57+
@PreAuthorize("hasRole('ROLE_USER')")
5758
@RequestMapping(value = "byclientid/{id}", produces = "application/json")
5859
public String statsByClientId(@PathVariable("id") Long id, ModelMap m) {
5960
Integer e = statsService.getCountForClientId(id);

0 commit comments

Comments
 (0)