Add dashboard
This commit is contained in:
parent
4695977bd8
commit
533f8241c2
5 changed files with 51 additions and 16 deletions
26
template.go
26
template.go
|
@ -8,18 +8,19 @@ import (
|
|||
import txt_tmpl "text/template"
|
||||
|
||||
type Status struct {
|
||||
BaseURL string
|
||||
FullURL string
|
||||
Search string
|
||||
User string
|
||||
IsAdmin bool
|
||||
Notif []Notification
|
||||
Home bool
|
||||
About bool
|
||||
News bool
|
||||
Upload bool
|
||||
Stats bool
|
||||
Help bool
|
||||
BaseURL string
|
||||
FullURL string
|
||||
Search string
|
||||
User string
|
||||
IsAdmin bool
|
||||
Notif []Notification
|
||||
Home bool
|
||||
About bool
|
||||
News bool
|
||||
Upload bool
|
||||
Stats bool
|
||||
Help bool
|
||||
Dasboard bool
|
||||
}
|
||||
|
||||
func GetStatus(h handler) Status {
|
||||
|
@ -47,6 +48,7 @@ var templates = template.Must(template.ParseFiles(TEMPLATE_PATH+"header.html",
|
|||
TEMPLATE_PATH+"new.html",
|
||||
TEMPLATE_PATH+"read.html",
|
||||
TEMPLATE_PATH+"edit.html",
|
||||
TEMPLATE_PATH+"dashboard.html",
|
||||
TEMPLATE_PATH+"settings.html",
|
||||
TEMPLATE_PATH+"stats.html",
|
||||
TEMPLATE_PATH+"help.html",
|
||||
|
|
18
templates/dashboard.html
Normal file
18
templates/dashboard.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
{{template "header.html" .S}}
|
||||
|
||||
<h4>Dashboard</h4>
|
||||
|
||||
<div class="span8 offset2">
|
||||
<ul class="nav nav-tabs nav-stacked">
|
||||
{{if .S.IsAdmin}}
|
||||
<li><a href="/new/"><i class="icon-book"></i> New books</a></li>
|
||||
<li><a href="/news/edit"><i class="icon-certificate"></i> Edit news</a></li>
|
||||
<li class="divider"></li>
|
||||
{{end}}
|
||||
<li><a href="/settings/"><i class="icon-wrench"></i> Settings</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="/logout/"><i class="icon-off"></i> Log Out</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{{template "footer.html"}}
|
|
@ -63,10 +63,11 @@
|
|||
<li class="divider-vertical"></li>
|
||||
{{if .User}}
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<a href="/dashboard/" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<i class="icon-user icon-white"></i> {{.User}}<b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="/dashboard/"><i class="icon-tasks"></i> Dashboard</a></li>
|
||||
{{if .IsAdmin}}
|
||||
<li><a href="/new/"><i class="icon-book"></i> New books</a></li>
|
||||
<li><a href="/news/edit"><i class="icon-certificate"></i> Edit news</a></li>
|
||||
|
|
|
@ -185,6 +185,7 @@ func initRouter(db *DB) {
|
|||
r.HandleFunc("/help/", GatherStats(helpHandler, db))
|
||||
r.HandleFunc("/download/{id:[0-9a-fA-F]+}/{epub:.*}", GatherStats(downloadHandler, db))
|
||||
r.HandleFunc("/cover/{id:[0-9a-fA-F]+}/{size}/{img:.*}", GatherStats(coverHandler, db))
|
||||
r.HandleFunc("/dashboard/", GatherStats(dashboardHandler, db))
|
||||
r.HandleFunc("/settings/", GatherStats(settingsHandler, db))
|
||||
r.HandleFunc("/stats/", GatherStats(statsHandler, db))
|
||||
r.HandleFunc("/news/", GatherStats(newsHandler, db))
|
||||
|
|
19
user.go
19
user.go
|
@ -6,6 +6,11 @@ import (
|
|||
)
|
||||
|
||||
func loginHandler(h handler) {
|
||||
if h.sess.User != "" {
|
||||
http.Redirect(h.w, h.r, "/dashboard/", http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
var data statusData
|
||||
data.S = GetStatus(h)
|
||||
loadTemplate(h.w, "login", data)
|
||||
|
@ -44,8 +49,16 @@ func createUserHandler(h handler) {
|
|||
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
|
||||
}
|
||||
|
||||
type settingsData struct {
|
||||
S Status
|
||||
func dashboardHandler(h handler) {
|
||||
if h.sess.User == "" {
|
||||
notFound(h)
|
||||
return
|
||||
}
|
||||
|
||||
var data statusData
|
||||
data.S = GetStatus(h)
|
||||
data.S.Dasboard = true
|
||||
loadTemplate(h.w, "dashboard", data)
|
||||
}
|
||||
|
||||
func settingsHandler(h handler) {
|
||||
|
@ -69,7 +82,7 @@ func settingsHandler(h handler) {
|
|||
h.sess.Save(h.w, h.r)
|
||||
}
|
||||
|
||||
var data settingsData
|
||||
var data statusData
|
||||
data.S = GetStatus(h)
|
||||
loadTemplate(h.w, "settings", data)
|
||||
}
|
||||
|
|
Reference in a new issue