2017-05-05 16:39:15 +02:00
package router
2017-05-05 03:53:38 +02:00
import (
2017-05-06 23:16:21 +02:00
"net/url"
2017-05-08 01:46:30 +02:00
"net/http"
2017-05-06 23:16:21 +02:00
2017-05-05 14:20:51 +02:00
"github.com/ewhal/nyaa/model"
2017-05-07 00:10:40 +02:00
userForms "github.com/ewhal/nyaa/service/user/form"
2017-05-08 01:46:30 +02:00
"github.com/ewhal/nyaa/service/user"
2017-05-06 10:36:37 +02:00
"github.com/gorilla/mux"
2017-05-05 03:53:38 +02:00
)
2017-05-05 06:07:45 +02:00
/ * Each Page should have an object to pass to their own template
2017-05-05 03:53:38 +02:00
* Therefore , we put them in a separate file for better maintenance
2017-05-05 10:52:08 +02:00
*
* MAIN Template Variables
2017-05-05 06:07:45 +02:00
* /
2017-05-05 03:53:38 +02:00
type FaqTemplateVariables struct {
2017-05-07 01:20:13 +02:00
Navigation Navigation
Search SearchForm
2017-05-08 01:46:30 +02:00
User model . User
2017-05-05 06:07:45 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-05 10:52:08 +02:00
}
2017-05-07 08:59:45 +02:00
type NotFoundTemplateVariables struct {
Navigation Navigation
Search SearchForm
2017-05-08 01:46:30 +02:00
User model . User
2017-05-07 08:59:45 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
}
2017-05-05 10:52:08 +02:00
type ViewTemplateVariables struct {
2017-05-06 10:36:37 +02:00
Torrent model . TorrentsJson
2017-05-07 01:20:13 +02:00
Search SearchForm
Navigation Navigation
2017-05-08 01:46:30 +02:00
User model . User
2017-05-06 10:36:37 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-05 03:53:38 +02:00
}
2017-05-07 00:10:40 +02:00
type UserRegisterTemplateVariables struct {
2017-05-07 01:20:13 +02:00
RegistrationForm userForms . RegistrationForm
2017-05-07 19:59:38 +02:00
FormErrors map [ string ] [ ] string
2017-05-07 01:20:13 +02:00
Search SearchForm
Navigation Navigation
2017-05-08 01:46:30 +02:00
User model . User
2017-05-07 01:20:13 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-07 00:10:40 +02:00
}
2017-05-07 22:00:45 +02:00
type UserVerifyTemplateVariables struct {
FormErrors map [ string ] [ ] string
Search SearchForm
Navigation Navigation
2017-05-08 01:46:30 +02:00
User model . User
2017-05-07 22:00:45 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
}
2017-05-07 04:02:57 +02:00
type UserLoginFormVariables struct {
LoginForm userForms . LoginForm
2017-05-08 00:21:31 +02:00
FormErrors map [ string ] [ ] string
2017-05-07 04:02:57 +02:00
Search SearchForm
Navigation Navigation
2017-05-08 01:46:30 +02:00
User model . User
2017-05-07 04:02:57 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
}
2017-05-05 03:53:38 +02:00
type HomeTemplateVariables struct {
2017-05-07 01:20:13 +02:00
ListTorrents [ ] model . TorrentsJson
Search SearchForm
Navigation Navigation
2017-05-08 01:46:30 +02:00
User model . User
2017-05-07 01:20:13 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-05 03:53:38 +02:00
}
2017-05-06 10:36:37 +02:00
type UploadTemplateVariables struct {
Upload UploadForm
2017-05-07 01:20:13 +02:00
Search SearchForm
Navigation Navigation
2017-05-08 01:46:30 +02:00
User model . User
2017-05-06 10:36:37 +02:00
URL * url . URL
Route * mux . Route
}
2017-05-07 01:20:13 +02:00
/ *
* Variables used by the upper ones
* /
type Navigation struct {
TotalItem int
MaxItemPerPage int
CurrentPage int
Route string
}
type SearchForm struct {
Query string
Status string
Category string
Sort string
Order string
HideAdvancedSearch bool
}
// Some Default Values to ease things out
func NewSearchForm ( params ... string ) ( searchForm SearchForm ) {
if len ( params ) > 1 {
searchForm . Category = params [ 0 ]
} else {
searchForm . Category = "_"
}
if len ( params ) > 2 {
searchForm . Sort = params [ 1 ]
} else {
searchForm . Sort = "torrent_id"
}
if len ( params ) > 3 {
order := params [ 2 ]
if order == "DESC" {
searchForm . Order = order
} else if order == "ASC" {
searchForm . Order = order
} else {
// TODO: handle invalid value (?)
}
} else {
searchForm . Order = "DESC"
}
return
}
2017-05-08 01:46:30 +02:00
func GetUser ( r * http . Request ) model . User {
user , _ , _ := userService . RetrieveCurrentUser ( r )
return user
}