mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Move settings to a separate page and handler.
This commit is contained in:
parent
774f4b9769
commit
cdf8ee326b
3 changed files with 47 additions and 22 deletions
|
|
@ -48,6 +48,7 @@ func init() {
|
||||||
router.HandleFunc("/digest/send", sendDigestHandler).Name("send-digest").Methods("POST")
|
router.HandleFunc("/digest/send", sendDigestHandler).Name("send-digest").Methods("POST")
|
||||||
router.HandleFunc("/digest/cron", digestCronHandler)
|
router.HandleFunc("/digest/cron", digestCronHandler)
|
||||||
|
|
||||||
|
router.HandleFunc("/account/settings", settingsHandler).Name("settings")
|
||||||
router.HandleFunc("/account/set-timezone", setTimezoneHandler).Name("set-timezone").Methods("POST")
|
router.HandleFunc("/account/set-timezone", setTimezoneHandler).Name("set-timezone").Methods("POST")
|
||||||
|
|
||||||
router.HandleFunc("/admin/digest", digestAdminHandler)
|
router.HandleFunc("/admin/digest", digestAdminHandler)
|
||||||
|
|
@ -184,11 +185,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var data = map[string]interface{}{
|
if err := templates["index"].Execute(w, nil); err != nil {
|
||||||
"Account": account,
|
|
||||||
"Timezones": timezones,
|
|
||||||
}
|
|
||||||
if err := templates["index"].Execute(w, data); err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -339,6 +336,26 @@ func githubOAuthCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, indexUrl.String(), http.StatusFound)
|
http.Redirect(w, r, indexUrl.String(), http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func settingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
|
||||||
|
userId := session.Values[sessionConfig.UserIdKey].(int)
|
||||||
|
c := appengine.NewContext(r)
|
||||||
|
account, err := getAccount(c, userId)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = map[string]interface{}{
|
||||||
|
"Account": account,
|
||||||
|
"Timezones": timezones,
|
||||||
|
}
|
||||||
|
if err := templates["settings"].Execute(w, data); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func setTimezoneHandler(w http.ResponseWriter, r *http.Request) {
|
func setTimezoneHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
|
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
|
||||||
userId := session.Values[sessionConfig.UserIdKey].(int)
|
userId := session.Values[sessionConfig.UserIdKey].(int)
|
||||||
|
|
|
||||||
|
|
@ -13,22 +13,7 @@
|
||||||
<form id="send-form" method="POST" action="{{routeUrl "send-digest"}}">
|
<form id="send-form" method="POST" action="{{routeUrl "send-digest"}}">
|
||||||
<input type="submit" value="Email Digest">
|
<input type="submit" value="Email Digest">
|
||||||
</form>
|
</form>
|
||||||
|
-
|
||||||
<p>
|
<a href="{{routeUrl "settings"}}">Settings</a>
|
||||||
<form method="POST" action="{{routeUrl "set-timezone"}}">
|
|
||||||
<select name="timezone_name">
|
|
||||||
{{$accountTimezoneName := .Account.TimezoneName}}
|
|
||||||
{{range .Timezones}}
|
|
||||||
{{if .LocationName}}
|
|
||||||
<option value={{.LocationName}} {{if eq .LocationName $accountTimezoneName}}selected{{end}}>{{.LocationName}} (GMT {{.DisplayUTCOffset}})</option>
|
|
||||||
{{else}}
|
|
||||||
<option disabled></option>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<input type="submit" value="Set Timezone">
|
|
||||||
</form>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
23
app/templates/settings.html
Normal file
23
app/templates/settings.html
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
{{define "title"}}GitHop - Settings{{end}}
|
||||||
|
|
||||||
|
{{define "body"}}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<form method="POST" action="{{routeUrl "set-timezone"}}">
|
||||||
|
<select name="timezone_name">
|
||||||
|
{{$accountTimezoneName := .Account.TimezoneName}}
|
||||||
|
{{range .Timezones}}
|
||||||
|
{{if .LocationName}}
|
||||||
|
<option value={{.LocationName}} {{if eq .LocationName $accountTimezoneName}}selected{{end}}>{{.LocationName}} (GMT {{.DisplayUTCOffset}})</option>
|
||||||
|
{{else}}
|
||||||
|
<option disabled></option>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<input type="submit" value="Set Timezone">
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{{end}}
|
||||||
|
|
||||||
Loading…
Reference in a new issue