gosora/routes/panel/common.go
Azareal d14a7f028f Panel Dashboard now uses dyntmpl to make it a little bit faster.
Fixed a bug in the dashboard where report stats were being fetched by day rather than by week.
Reduced the amount of boilerplate in the dashboard with the GE type alias.
Tweaked the colour of hguides on Cosora.

Added the panel template.

Added the panel_dashboard_cpu_desc phrase.
Added the panel_dashboard_ram_desc phrase.
Added the panel_dashboard_online_desc phrase.
Added the panel_dashboard_guests_online_desc phrase.
Added the panel_dashboard_users_online_desc phrase.
Added the panel_dashboard_coming_soon phrase.
2019-04-29 11:28:55 +10:00

47 lines
1.5 KiB
Go

package panel
import (
"net/http"
c "github.com/Azareal/Gosora/common"
"github.com/Azareal/Gosora/common/phrases"
)
// A blank list to fill out that parameter in Page for routes which don't use it
var tList []interface{}
var successJSONBytes = []byte(`{"success":"1"}`)
// We're trying to reduce the amount of boilerplate in here, so I added these two functions, they might wind up circulating outside this file in the future
func successRedirect(dest string, w http.ResponseWriter, r *http.Request, isJs bool) c.RouteError {
if !isJs {
http.Redirect(w, r, dest, http.StatusSeeOther)
} else {
w.Write(successJSONBytes)
}
return nil
}
// TODO: Prerender needs to handle dyntmpl templates better...
func renderTemplate(tmplName string, w http.ResponseWriter, r *http.Request, header *c.Header, pi interface{}) c.RouteError {
header.AddScript("global.js")
if c.RunPreRenderHook("pre_render_"+tmplName, w, r, &header.CurrentUser, pi) {
return nil
}
// TODO: Prepend this with panel_?
err := header.Theme.RunTmpl(tmplName, pi, w)
if err != nil {
return c.InternalError(err, w, r)
}
return nil
}
func buildBasePage(w http.ResponseWriter, r *http.Request, user *c.User, titlePhrase string, zone string) (*c.BasePanelPage, c.RouteError) {
header, stats, ferr := c.PanelUserCheck(w, r, user)
if ferr != nil {
return nil, ferr
}
header.Title = phrases.GetTitlePhrase("panel_" + titlePhrase)
return &c.BasePanelPage{header, stats, zone, c.ReportForumID}, nil
}