Add summary of settings to the index page.

This commit is contained in:
Mihai Parparita 2014-09-28 22:08:30 -07:00
parent 976beb08cc
commit 7405cb5651
2 changed files with 38 additions and 3 deletions

View file

@ -185,7 +185,37 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := templates["index"].Execute(w, nil); err != nil {
oauthTransport := githubOAuthTransport(c)
oauthTransport.Token = &account.OAuthToken
githubClient := github.NewClient(oauthTransport.Client())
user, _, err := githubClient.Users.Get("")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
repos, err := getRepos(c, githubClient, account, user)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
emailAddress, err := account.GetDigestEmailAddress(githubClient)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var settingsSummary = map[string]interface{}{
"Frequency": account.Frequency,
"RepositoryCount": strconv.Itoa(len(repos.AllRepos) - len(account.ExcludedRepoIds)),
"EmailAddress": emailAddress,
}
var data = map[string]interface{}{
"SettingsSummary": settingsSummary,
}
if err := templates["index"].Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

View file

@ -13,7 +13,12 @@
<form id="send-form" method="POST" action="{{routeUrl "send-digest"}}">
<input type="submit" value="Email Digest">
</form>
-
<a href="{{routeUrl "settings"}}">Settings</a>
<p>
You'll be getting a {{.SettingsSummary.Frequency}} digest of your past
past activity in {{.SettingsSummary.RepositoryCount}} repositories sent to
<code>{{.SettingsSummary.EmailAddress}}</code>.
<a href="{{routeUrl "settings"}}">Change settings</a>
<p>
{{end}}