1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
package router
import (
"net/http"
"net/url"
"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/languages"
"github.com/gorilla/mux"
)
/* Each Page should have an object to pass to their own template
* Therefore, we put them in a separate file for better maintenance
*
* MAIN Template Variables
*/
type FaqTemplateVariables struct {
CommonTemplateVariables
}
type NotFoundTemplateVariables struct {
CommonTemplateVariables
}
type ViewTemplateVariables struct {
CommonTemplateVariables
Torrent model.TorrentJSON
CaptchaID string
FormErrors map[string][]string
Infos map[string][]string
}
type UserRegisterTemplateVariables struct {
CommonTemplateVariables
RegistrationForm userForms.RegistrationForm
FormErrors map[string][]string
}
type UserProfileEditVariables struct {
CommonTemplateVariables
UserProfile *model.User
UserForm userForms.UserForm
FormErrors map[string][]string
FormInfos map[string][]string
Languages map[string]string
}
type UserVerifyTemplateVariables struct {
CommonTemplateVariables
FormErrors map[string][]string
}
type UserLoginFormVariables struct {
CommonTemplateVariables
LoginForm userForms.LoginForm
FormErrors map[string][]string
}
type UserProfileVariables struct {
CommonTemplateVariables
UserProfile *model.User
FormInfos map[string][]string
}
type UserProfileNotifVariables struct {
CommonTemplateVariables
Infos map[string][]string
}
type HomeTemplateVariables struct {
CommonTemplateVariables
ListTorrents []model.TorrentJSON
}
type DatabaseDumpTemplateVariables struct {
CommonTemplateVariables
ListDumps []model.DatabaseDumpJSON
GPGLink string
}
type UploadTemplateVariables struct {
CommonTemplateVariables
Upload UploadForm
FormErrors map[string][]string
}
type ChangeLanguageVariables struct {
CommonTemplateVariables
Language string
Languages map[string]string
}
/* MODERATION Variables */
type PanelIndexVbs struct {
CommonTemplateVariables
Torrents []model.Torrent
TorrentReports []model.TorrentReportJson
Users []model.User
Comments []model.Comment
}
type PanelTorrentListVbs struct {
CommonTemplateVariables
Torrents []model.Torrent
Errors map[string][]string
Infos map[string][]string
}
type PanelUserListVbs struct {
CommonTemplateVariables
Users []model.User
}
type PanelCommentListVbs struct {
CommonTemplateVariables
Comments []model.Comment
}
type PanelTorrentEdVbs struct {
CommonTemplateVariables
Upload UploadForm
FormErrors map[string][]string
FormInfos map[string][]string
}
type PanelTorrentReportListVbs struct {
CommonTemplateVariables
TorrentReports []model.TorrentReportJson
}
type PanelTorrentReassignVbs struct {
CommonTemplateVariables
Reassign ReassignForm
FormErrors map[string][]string
FormInfos map[string][]string
}
/*
* Variables used by the upper ones
*/
type CommonTemplateVariables struct {
Navigation Navigation
Search SearchForm
T languages.TemplateTfunc
User *model.User
URL *url.URL // for parsing URL in templates
Route *mux.Route // for getting current route in templates
}
type Navigation struct {
TotalItem int
MaxItemPerPage int // FIXME: shouldn't this be in SearchForm?
CurrentPage int
Route string
}
type SearchForm struct {
common.SearchParam
Category string
ShowItemsPerPage bool
}
// Some Default Values to ease things out
func NewNavigation() Navigation {
return Navigation{
MaxItemPerPage: 50,
}
}
func NewSearchForm() SearchForm {
return SearchForm{
Category: "_",
ShowItemsPerPage: true,
}
}
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: languages.GetTfuncFromRequest(r),
User: GetUser(r),
URL: r.URL,
Route: mux.CurrentRoute(r),
}
}
|