add total repo count to high scores/stats page

This commit is contained in:
shawnps
2015-02-13 21:44:50 -08:00
parent c9be7a2858
commit 5927d9d69a
2 changed files with 18 additions and 7 deletions

View File

@@ -13,13 +13,13 @@ func add(x, y int) int {
return x + y
}
var highScores []struct {
Repo string
Files int
Average float64
}
func HighScoresHandler(w http.ResponseWriter, r *http.Request) {
var highScores []struct {
Repo string
Files int
Average float64
}
db := db.Mongo{URL: mongoURL, Database: mongoDatabase, CollectionName: mongoCollection}
coll, err := db.Collection()
if err != nil {
@@ -35,8 +35,15 @@ func HighScoresHandler(w http.ResponseWriter, r *http.Request) {
return
}
count, err := coll.Count()
if err != nil {
log.Println("ERROR: could not get high scores: ", err)
http.Error(w, err.Error(), 500)
return
}
funcs := template.FuncMap{"add": add}
t := template.Must(template.New("high_scores.html").Funcs(funcs).ParseFiles("templates/high_scores.html"))
t.Execute(w, map[string]interface{}{"HighScores": highScores})
t.Execute(w, map[string]interface{}{"HighScores": highScores, "Count": count})
}

View File

@@ -68,6 +68,10 @@
{{end}}
</tbody>
</table>
<h1>Stats</h1>
<ul>
<li><h4>Reports generated for {{ .Count }} repos.</h4></li>
</ul>
</div>
<div class="footer">
<div class="container">