mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
add total repo count to high scores/stats page
This commit is contained in:
@@ -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})
|
||||
}
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user