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/templateVariables.go

92 lignes
2 Kio
Go
Brut Vue normale Historique

package router
import (
"github.com/ewhal/nyaa/model"
2017-05-06 10:36:37 +02:00
"github.com/gorilla/mux"
"net/url"
)
/* 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 {
Navigation Navigation
2017-05-06 10:36:37 +02:00
Search SearchForm
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
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
}
type HomeTemplateVariables struct {
ListTorrents []model.TorrentsJson
ListCategories []model.Categories
2017-05-06 10:36:37 +02:00
Search SearchForm
Navigation Navigation
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
2017-05-06 10:36:37 +02:00
type UploadTemplateVariables struct {
Upload UploadForm
Search SearchForm
Navigation Navigation
URL *url.URL
Route *mux.Route
}
/*
* Variables used by the upper ones
*/
type Navigation struct {
TotalItem int
MaxItemPerPage int
CurrentPage int
Route string
}
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
}
// Some Default Values to ease things out
func NewSearchForm(params ...string) (searchForm SearchForm) {
2017-05-06 10:36:37 +02:00
if len(params) > 1 {
searchForm.Category = params[0]
2017-05-06 10:36:37 +02:00
} else {
searchForm.Category = "_"
}
2017-05-06 10:36:37 +02:00
if len(params) > 2 {
searchForm.Sort = params[1]
} else {
searchForm.Sort = "torrent_id"
}
2017-05-06 10:36:37 +02:00
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 (?)
}
2017-05-06 10:36:37 +02:00
} else {
searchForm.Order = "DESC"
}
return
2017-05-06 10:36:37 +02:00
}