2017-05-05 16:39:15 +02:00
package router
2017-05-05 03:53:38 +02:00
import (
2017-05-05 14:20:51 +02:00
"github.com/ewhal/nyaa/model"
2017-05-06 10:36:37 +02:00
"github.com/gorilla/mux"
2017-05-05 06:07:45 +02:00
"net/url"
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-05 10:52:08 +02:00
Navigation Navigation
2017-05-06 10:36:37 +02:00
Search SearchForm
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
}
type ViewTemplateVariables struct {
2017-05-06 10:36:37 +02:00
Torrent model . TorrentsJson
Search SearchForm
Navigation Navigation
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-05 14:20:51 +02:00
ListTorrents [ ] model . TorrentsJson
ListCategories [ ] model . Categories
2017-05-06 10:36:37 +02:00
Search SearchForm
2017-05-05 06:07:45 +02:00
Navigation Navigation
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
Search SearchForm
Navigation Navigation
URL * url . URL
Route * mux . Route
}
2017-05-05 10:52:08 +02:00
/ *
* Variables used by the upper ones
* /
2017-05-05 03:53:38 +02:00
type Navigation struct {
2017-05-05 06:07:45 +02:00
TotalItem int
MaxItemPerPage int
CurrentPage int
Route string
2017-05-05 03:53:38 +02:00
}
2017-05-05 10:52:08 +02:00
type SearchForm struct {
2017-05-06 10:36:37 +02:00
Query string
Status string
Category string
Sort string
Order string
2017-05-05 18:02:18 +02:00
HideAdvancedSearch bool
2017-05-05 10:52:08 +02:00
}
2017-05-06 10:36:37 +02:00
type UploadForm struct {
Name string
Magnet string
Category string
Description string
}
2017-05-05 10:52:08 +02:00
// Some Default Values to ease things out
func NewSearchForm ( params ... string ) SearchForm {
searchForm := SearchForm { }
2017-05-06 10:36:37 +02:00
if len ( params ) > 1 {
2017-05-05 10:52:08 +02:00
searchForm . Category = params [ 0 ]
2017-05-06 10:36:37 +02:00
} else {
searchForm . Category = "_"
2017-05-05 10:52:08 +02:00
}
2017-05-06 10:36:37 +02:00
if len ( params ) > 2 {
searchForm . Sort = params [ 1 ]
} else {
searchForm . Sort = "torrent_id"
2017-05-05 10:52:08 +02:00
}
2017-05-06 10:36:37 +02:00
if len ( params ) > 3 {
searchForm . Order = params [ 2 ]
} else {
searchForm . Order = "DESC"
2017-05-05 10:52:08 +02:00
}
return searchForm
2017-05-05 18:02:18 +02:00
}
2017-05-06 10:36:37 +02:00
func NewUploadForm ( params ... string ) UploadForm {
uploadForm := UploadForm { }
if len ( params ) > 1 {
uploadForm . Category = params [ 0 ]
} else {
uploadForm . Category = "3_12"
}
if len ( params ) > 2 {
uploadForm . Description = params [ 1 ]
} else {
uploadForm . Description = "Description"
}
return uploadForm
}