Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/router/template_variables.go

163 lignes
3,6 Kio
Go
Brut Vue normale Historique

package router
import (
"html/template"
"net/http"
"net/url"
2017-05-06 23:16:21 +02:00
2017-05-17 07:58:40 +02:00
"github.com/NyaaPantsu/nyaa/common"
"github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/service/user"
userForms "github.com/NyaaPantsu/nyaa/service/user/form"
"github.com/NyaaPantsu/nyaa/util/filelist"
"github.com/NyaaPantsu/nyaa/util/publicSettings"
"github.com/gorilla/csrf"
2017-05-06 10:36:37 +02:00
"github.com/gorilla/mux"
)
/* Each Page should have an object to pass to their own template
2017-05-15 11:08:17 +02:00
* Therefore, we put them in a separate file for better maintenance
*
* MAIN Template Variables
*/
type viewTemplateVariables struct {
commonTemplateVariables
Torrent model.TorrentJSON
RootFolder *filelist.FileListFolder // used for tree view
CaptchaID string
2017-05-24 09:11:13 +02:00
FormErrors map[string][]string
Infos map[string][]string
}
type formTemplateVariables struct {
commonTemplateVariables
Form interface{}
FormErrors map[string][]string
FormInfos map[string][]string
}
type modelListVbs struct {
commonTemplateVariables
Models interface{}
Errors map[string][]string
Infos map[string][]string
}
type userProfileEditVariables struct {
commonTemplateVariables
UserProfile *model.User
UserForm userForms.UserForm
FormErrors map[string][]string
FormInfos map[string][]string
2017-05-10 21:45:39 +02:00
Languages map[string]string
2017-05-09 17:47:06 +02:00
}
type userVerifyTemplateVariables struct {
commonTemplateVariables
FormErrors map[string][]string
}
type userProfileVariables struct {
commonTemplateVariables
UserProfile *model.User
2017-05-10 11:03:49 +02:00
FormInfos map[string][]string
}
type databaseDumpTemplateVariables struct {
commonTemplateVariables
2017-05-24 09:11:13 +02:00
ListDumps []model.DatabaseDumpJSON
GPGLink string
2017-05-11 05:06:12 +02:00
}
type changeLanguageVariables struct {
commonTemplateVariables
2017-05-24 09:11:13 +02:00
Language string
Languages map[string]string
2017-05-13 00:17:34 +02:00
}
type publicSettingsVariables struct {
commonTemplateVariables
Language string
Languages map[string]string
}
/* MODERATION Variables */
type panelIndexVbs struct {
commonTemplateVariables
2017-05-10 20:42:20 +02:00
Torrents []model.Torrent
TorrentReports []model.TorrentReportJSON
2017-05-10 20:42:20 +02:00
Users []model.User
Comments []model.Comment
}
2017-05-07 01:20:13 +02:00
/*
2017-05-15 11:08:17 +02:00
* Variables used by the upper ones
2017-05-07 01:20:13 +02:00
*/
type commonTemplateVariables struct {
Navigation navigation
Search searchForm
T publicSettings.TemplateTfunc
Theme string
Mascot string
User *model.User
2017-05-24 09:11:13 +02:00
URL *url.URL // for parsing URL in templates
Route *mux.Route // for getting current route in templates
CsrfField template.HTML
}
type navigation struct {
2017-05-07 01:20:13 +02:00
TotalItem int
2017-05-17 07:58:40 +02:00
MaxItemPerPage int // FIXME: shouldn't this be in SearchForm?
2017-05-07 01:20:13 +02:00
CurrentPage int
Route string
}
type searchForm struct {
2017-05-10 11:03:49 +02:00
common.SearchParam
Category string
ShowItemsPerPage bool
2017-05-07 01:20:13 +02:00
}
// Some Default Values to ease things out
func newNavigation() navigation {
return navigation{
MaxItemPerPage: 50,
}
}
func newSearchForm() searchForm {
return searchForm{
2017-05-15 11:08:17 +02:00
Category: "_",
ShowItemsPerPage: true,
2017-05-07 01:20:13 +02:00
}
}
func newModelList(r *http.Request, models interface{}) modelListVbs {
return modelListVbs{
commonTemplateVariables: newCommonVariables(r),
Models: models,
}
}
func getUser(r *http.Request) *model.User {
user, _, _ := userService.RetrieveCurrentUser(r)
return &user
}
func newCommonVariables(r *http.Request) commonTemplateVariables {
return commonTemplateVariables{
Navigation: newNavigation(),
Search: newSearchForm(),
T: publicSettings.GetTfuncFromRequest(r),
Theme: publicSettings.GetThemeFromRequest(r),
Mascot: publicSettings.GetMascotFromRequest(r),
User: getUser(r),
URL: r.URL,
Route: mux.CurrentRoute(r),
CsrfField: csrf.TemplateField(r),
}
}