Revert quicktemplate search template
Cette révision appartient à :
Parent
c2bdfa784a
révision
8e15b211df
15 fichiers modifiés avec 179 ajouts et 541 suppressions
|
@ -12,7 +12,6 @@ install:
|
|||
- go get github.com/gorilla/securecookie
|
||||
- go get golang.org/x/crypto/bcrypt
|
||||
- go get github.com/nicksnyder/go-i18n/i18n
|
||||
- go get github.com/valyala/quicktemplate
|
||||
- go build
|
||||
deploy:
|
||||
provider: releases
|
||||
|
|
|
@ -4,16 +4,20 @@ import (
|
|||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/ewhal/nyaa/templates"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var faqTemplate = template.Must(template.New("FAQ").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/FAQ.html"))
|
||||
|
||||
func init() {
|
||||
// common
|
||||
template.Must(faqTemplate.ParseGlob("templates/_*.html"))
|
||||
}
|
||||
|
||||
func FaqHandler(w http.ResponseWriter, r *http.Request) {
|
||||
searchForm := templates.NewSearchForm()
|
||||
searchForm := NewSearchForm()
|
||||
searchForm.HideAdvancedSearch = true
|
||||
err := faqTemplate.ExecuteTemplate(w, "index.html", FaqTemplateVariables{templates.Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
|
||||
err := faqTemplate.ExecuteTemplate(w, "index.html", FaqTemplateVariables{Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
|
|
@ -8,12 +8,15 @@ import (
|
|||
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/service/torrent"
|
||||
"github.com/ewhal/nyaa/templates"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var homeTemplate = template.Must(template.New("home").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/home.html"))
|
||||
|
||||
func init() {
|
||||
template.Must(homeTemplate.ParseGlob("templates/_*.html")) // common
|
||||
}
|
||||
|
||||
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
page := vars["page"]
|
||||
|
@ -38,8 +41,8 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
b = append(b, res)
|
||||
}
|
||||
|
||||
navigationTorrents := templates.Navigation{nbTorrents, maxPerPage, pagenum, "search_page"}
|
||||
htv := HomeTemplateVariables{b, templates.NewSearchForm(), navigationTorrents, r.URL, mux.CurrentRoute(r)}
|
||||
navigationTorrents := Navigation{nbTorrents, maxPerPage, pagenum, "search_page"}
|
||||
htv := HomeTemplateVariables{b, NewSearchForm(), navigationTorrents, r.URL, mux.CurrentRoute(r)}
|
||||
|
||||
err := homeTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
|
|
|
@ -7,13 +7,16 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/templates"
|
||||
"github.com/ewhal/nyaa/util/search"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var searchTemplate = template.Must(template.New("home").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/home.html"))
|
||||
|
||||
func init() {
|
||||
template.Must(searchTemplate.ParseGlob("templates/_*.html")) // common
|
||||
}
|
||||
|
||||
func SearchHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
page := vars["page"]
|
||||
|
@ -33,8 +36,8 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
|
|||
b = append(b, res)
|
||||
}
|
||||
|
||||
navigationTorrents := templates.Navigation{nbTorrents, search_param.Max, pagenum, "search_page"}
|
||||
searchForm := templates.SearchForm{
|
||||
navigationTorrents := Navigation{nbTorrents, search_param.Max, pagenum, "search_page"}
|
||||
searchForm := SearchForm{
|
||||
search_param.Query,
|
||||
search_param.Status,
|
||||
search_param.Category,
|
||||
|
|
|
@ -6,8 +6,6 @@ import (
|
|||
"math"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/ewhal/nyaa/templates"
|
||||
)
|
||||
|
||||
var FuncMap = template.FuncMap{
|
||||
|
@ -26,7 +24,7 @@ var FuncMap = template.FuncMap{
|
|||
}
|
||||
return "error"
|
||||
},
|
||||
"genNav": func(nav templates.Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
|
||||
"genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
|
||||
maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage))
|
||||
|
||||
var ret = ""
|
||||
|
@ -59,13 +57,4 @@ var FuncMap = template.FuncMap{
|
|||
}
|
||||
return template.HTML(ret)
|
||||
},
|
||||
"SearchCommon": func(s templates.SearchForm) template.HTML {
|
||||
return template.HTML(templates.SearchCommon(s))
|
||||
},
|
||||
"SearchButton": func(s templates.SearchForm) template.HTML {
|
||||
return template.HTML(templates.SearchButton(s))
|
||||
},
|
||||
"SearchAdvanced": func(nav templates.Navigation, s templates.SearchForm) template.HTML {
|
||||
return template.HTML(templates.SearchAdvanced(nav, s))
|
||||
},
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"net/url"
|
||||
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/templates"
|
||||
userForms "github.com/ewhal/nyaa/service/user/form"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
@ -16,40 +15,86 @@ import (
|
|||
*/
|
||||
|
||||
type FaqTemplateVariables struct {
|
||||
Navigation templates.Navigation
|
||||
Search templates.SearchForm
|
||||
Navigation Navigation
|
||||
Search SearchForm
|
||||
URL *url.URL // For parsing Url in templates
|
||||
Route *mux.Route // For getting current route in templates
|
||||
}
|
||||
|
||||
type ViewTemplateVariables struct {
|
||||
Torrent model.TorrentsJson
|
||||
Search templates.SearchForm
|
||||
Navigation templates.Navigation
|
||||
Search SearchForm
|
||||
Navigation Navigation
|
||||
URL *url.URL // For parsing Url in templates
|
||||
Route *mux.Route // For getting current route in templates
|
||||
}
|
||||
|
||||
type UserRegisterTemplateVariables struct {
|
||||
RegistrationForm userForms.RegistrationForm
|
||||
Search templates.SearchForm
|
||||
Navigation templates.Navigation
|
||||
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
|
||||
Search templates.SearchForm
|
||||
Navigation templates.Navigation
|
||||
Search SearchForm
|
||||
Navigation Navigation
|
||||
URL *url.URL // For parsing Url in templates
|
||||
Route *mux.Route // For getting current route in templates
|
||||
}
|
||||
|
||||
type UploadTemplateVariables struct {
|
||||
Upload UploadForm
|
||||
Search templates.SearchForm
|
||||
Navigation templates.Navigation
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -4,12 +4,15 @@ import (
|
|||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/ewhal/nyaa/templates"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var uploadTemplate = template.Must(template.New("upload").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/upload.html"))
|
||||
|
||||
func init() {
|
||||
template.Must(uploadTemplate.ParseGlob("templates/_*.html")) // common
|
||||
}
|
||||
|
||||
func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
var uploadForm UploadForm
|
||||
|
@ -21,7 +24,7 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
//add to db and redirect depending on result
|
||||
}
|
||||
} else if r.Method == "GET" {
|
||||
htv := UploadTemplateVariables{uploadForm, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
htv := UploadTemplateVariables{uploadForm, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
err = uploadTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
|
|
|
@ -4,23 +4,27 @@ import(
|
|||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/ewhal/nyaa/templates"
|
||||
"github.com/ewhal/nyaa/service/user/form"
|
||||
"github.com/ewhal/nyaa/util/modelHelper"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var viewRegisterTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/user/register.html"))
|
||||
|
||||
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
|
||||
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
|
||||
|
||||
func init() {
|
||||
template.Must(viewRegisterTemplate.ParseGlob("templates/_*.html"))
|
||||
}
|
||||
|
||||
// Getting View User Registration
|
||||
|
||||
func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
b := form.RegistrationForm{}
|
||||
modelHelper.BindValueForm(b, r)
|
||||
htv := UserRegisterTemplateVariables{b, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
htv := UserRegisterTemplateVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
err := viewTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -56,4 +60,3 @@ func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
|
|||
func UserProfilePostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,15 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/ewhal/nyaa/service/torrent"
|
||||
"github.com/ewhal/nyaa/templates"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
|
||||
|
||||
func init() {
|
||||
template.Must(viewTemplate.ParseGlob("templates/_*.html")) // common
|
||||
}
|
||||
|
||||
func ViewHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
id := vars["id"]
|
||||
|
@ -18,7 +21,7 @@ func ViewHandler(w http.ResponseWriter, r *http.Request) {
|
|||
torrent, err := torrentService.GetTorrentById(id)
|
||||
b := torrent.ToJson()
|
||||
|
||||
htv := ViewTemplateVariables{b, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
htv := ViewTemplateVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
|
||||
err = viewTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
|
|
73
templates/_search.html
Fichier normal
73
templates/_search.html
Fichier normal
|
@ -0,0 +1,73 @@
|
|||
{{define "search_common"}}
|
||||
<select name="c" class="form-control input-sm" value>
|
||||
<option value="_">All categories</option>
|
||||
<option value="3_" {{if eq .Search.Category "3_"}}selected{{end}}>Anime</option>
|
||||
<option value="3_12" {{if eq .Search.Category "3_12"}}selected{{end}}>Anime - Anime Music Video</option>
|
||||
<option value="3_5" {{if eq .Search.Category "3_5"}}selected{{end}}>Anime - English-translated</option>
|
||||
<option value="3_13" {{if eq .Search.Category "3_13"}}selected{{end}}>Anime - Non-English-translated</option>
|
||||
<option value="3_6" {{if eq .Search.Category "3_6"}}selected{{end}}>Anime - Raw</option>
|
||||
<option value="2_" {{if eq .Search.Category "2_"}}selected{{end}}>Audio</option>
|
||||
<option value="2_3" {{if eq .Search.Category "2_3"}}selected{{end}}>Audio - Lossless</option>
|
||||
<option value="2_4" {{if eq .Search.Category "2_4"}}selected{{end}}>Audio - Lossy</option>
|
||||
<option value="4_" {{if eq .Search.Category "4_"}}selected{{end}}>Literature</option>
|
||||
<option value="4_7" {{if eq .Search.Category "4_7"}}selected{{end}}>Literature - English-translated</option>
|
||||
<option value="4_8" {{if eq .Search.Category "4_8"}}selected{{end}}>Literature - Raw</option>
|
||||
<option value="4_14" {{if eq .Search.Category "4_14"}}selected{{end}}>Literature - Non-English-translated</option>
|
||||
<option value="5_" {{if eq .Search.Category "5_"}}selected{{end}}>Live Action</option>
|
||||
<option value="5_9" {{if eq .Search.Category "5_9"}}selected{{end}}>Live Action - English-translated</option>
|
||||
<option value="5_10" {{if eq .Search.Category "5_10"}}selected{{end}}>Live Action - Idol/Promotional Video</option>
|
||||
<option value="5_18" {{if eq .Search.Category "5_18"}}selected{{end}}>Live Action - Non-English-translated</option>
|
||||
<option value="5_11" {{if eq .Search.Category "5_11"}}selected{{end}}>Live Action - Raw</option>
|
||||
<option value="6_" {{if eq .Search.Category "6_"}}selected{{end}}>Pictures</option>
|
||||
<option value="6_15" {{if eq .Search.Category "6_15"}}selected{{end}}>Pictures - Graphics</option>
|
||||
<option value="6_16" {{if eq .Search.Category "6_16"}}selected{{end}}>Pictures - Photos</option>
|
||||
<option value="1_" {{if eq .Search.Category "1_"}}selected{{end}}>Software</option>
|
||||
<option value="1_1" {{if eq .Search.Category "1_1"}}selected{{end}}>Software - Applications</option>
|
||||
<option value="1_2" {{if eq .Search.Category "1_2"}}selected{{end}}>Software - Games</option>
|
||||
</select>
|
||||
<select name="s" class="form-control input-sm">
|
||||
<option value="">Show all</option>
|
||||
<option value="2" {{if eq .Search.Status "2"}}selected{{end}}>Filter Remakes</option>
|
||||
<option value="3" {{if eq .Search.Status "3"}}selected{{end}}>Trusted</option>
|
||||
<option value="4" {{if eq .Search.Status "4"}}selected{{end}}>A+</option>
|
||||
</select>
|
||||
{{end}}
|
||||
{{define "search_advanced"}}
|
||||
<select name="sort" class="form-control input-sm">
|
||||
<option value="torrent_id" {{if eq .Search.Sort "torrent_id"}}selected{{end}}>ID</option>
|
||||
<option value="torrent_name" {{if eq .Search.Sort "torrent_name"}}selected{{end}}>Name</option>
|
||||
<option value="date" {{if eq .Search.Sort "date"}}selected{{end}}>Date</option>
|
||||
<option value="downloads" {{if eq .Search.Sort "downloads"}}selected{{end}}>Downloads</option>
|
||||
<option value="filesize" {{if eq .Search.Sort "filesize"}}selected{{end}}>Size</option>
|
||||
</select>
|
||||
<select name="order" class="form-control input-sm">
|
||||
<option value="desc" {{if eq .Search.Order "desc"}}selected{{end}}>Descending</option>
|
||||
<option value="asc" {{if eq .Search.Order "asc"}}selected{{end}}>Ascending</option>
|
||||
</select>
|
||||
<select name="max" class="form-control input-sm">
|
||||
<option value="5" {{if eq .Navigation.MaxItemPerPage 5}}selected{{end}}>5</option>
|
||||
<option value="10" {{if eq .Navigation.MaxItemPerPage 10}}selected{{end}}>10</option>
|
||||
<option value="15" {{if eq .Navigation.MaxItemPerPage 15}}selected{{end}}>15</option>
|
||||
<option value="20" {{if eq .Navigation.MaxItemPerPage 20}}selected{{end}}>20</option>
|
||||
<option value="25" {{if eq .Navigation.MaxItemPerPage 25}}selected{{end}}>25</option>
|
||||
<option value="30" {{if eq .Navigation.MaxItemPerPage 30}}selected{{end}}>30</option>
|
||||
<option value="35" {{if eq .Navigation.MaxItemPerPage 35}}selected{{end}}>35</option>
|
||||
<option value="40" {{if eq .Navigation.MaxItemPerPage 40}}selected{{end}}>40</option>
|
||||
<option value="45" {{if eq .Navigation.MaxItemPerPage 45}}selected{{end}}>45</option>
|
||||
<option value="50" {{if eq .Navigation.MaxItemPerPage 50}}selected{{end}}>50</option>
|
||||
<option value="70" {{if eq .Navigation.MaxItemPerPage 70}}selected{{end}}>70</option>
|
||||
<option value="100" {{if eq .Navigation.MaxItemPerPage 100}}selected{{end}}>100</option>
|
||||
<option value="150" {{if eq .Navigation.MaxItemPerPage 150}}selected{{end}}>150</option>
|
||||
<option value="200" {{if eq .Navigation.MaxItemPerPage 200}}selected{{end}}>200</option>
|
||||
<option value="300" {{if eq .Navigation.MaxItemPerPage 300}}selected{{end}}>300</option>
|
||||
</select>
|
||||
{{end}}
|
||||
|
||||
{{define "search_button"}}
|
||||
<div class="input-group">
|
||||
<input name="q" class="form-control input-sm" placeholder="Search" type="text" value="{{.Search.Query}}">
|
||||
<span class="input-group-btn">
|
||||
<button type="submit" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> Search</button>
|
||||
</span>
|
||||
</div>
|
||||
{{end}}
|
|
@ -50,8 +50,8 @@
|
|||
</ul>
|
||||
<form class="navbar-form navbar-right" role="search" action="/search" method="get">
|
||||
<div class="form-group">
|
||||
{{ SearchCommon .Search }}
|
||||
{{ SearchButton .Search }}
|
||||
{{block "search_common" .}}{{end}}
|
||||
{{block "search_button" .}}{{end}}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -67,9 +67,9 @@
|
|||
<font size="4.5">Advanced Search</font><br />
|
||||
<form class="navbar-form" role="search" action="/search" method="get">
|
||||
<div class="form-group">
|
||||
{{ SearchCommon .Search }}
|
||||
{{ SearchAdvanced .Navigation .Search }}
|
||||
{{ SearchButton .Search }}
|
||||
{{block "search_common" .}}{{end}}
|
||||
{{block "search_advanced" .}}{{end}}
|
||||
{{block "search_button" .}}{{end}}
|
||||
</div>
|
||||
</form>
|
||||
<div style="clear:both"></div>
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
{% import "strconv" %}
|
||||
|
||||
{% code type searchField struct{
|
||||
id, name string
|
||||
} %}
|
||||
|
||||
Common seatch part of many pages
|
||||
{% func SearchCommon(search SearchForm) %}
|
||||
<select name="c" class="form-control input-sm" value>
|
||||
<option value="_">All categories</option>
|
||||
{%= searchOptions(search.Category, []searchField{
|
||||
{"3_", "Anime"},
|
||||
{"3_12", "Anime - Anime Music Video"},
|
||||
{"3_5", "Anime - English-translated"},
|
||||
{"3_13", "Anime - Non-English-translated"},
|
||||
{"3_6", "Anime - Raw"},
|
||||
{"2_", "Audio"},
|
||||
{"2_3", "Audio - Lossless"},
|
||||
{"2_4", "Audio - Lossy"},
|
||||
{"4_", "Literature"},
|
||||
{"4_7", "Literature - English-translated"},
|
||||
{"4_8", "Literature - Raw"},
|
||||
{"4_14", "Literature - Non-English-translated"},
|
||||
{"5_", "Live Action"},
|
||||
{"5_9", "Live Action - English-translated"},
|
||||
{"5_10", "Live Action - Idol/Promotional Video"},
|
||||
{"5_18", "Live Action - Non-English-translated"},
|
||||
{"5_11", "Live Action - Raw"},
|
||||
{"6_", "Pictures"},
|
||||
{"6_15", "Pictures - Graphics"},
|
||||
{"6_16", "Pictures - Photos"},
|
||||
{"1_", "Software"},
|
||||
{"1_1", "Software - Applications"},
|
||||
{"1_2", "Software - Games"},
|
||||
}) %}
|
||||
</select>
|
||||
<select name="s" class="form-control input-sm">
|
||||
<option value="">Show all</option>
|
||||
{%= searchOptions(search.Status, []searchField{
|
||||
{"2", "Filter Remakes"},
|
||||
{"3", "Trusted"},
|
||||
{"4", "A+"},
|
||||
}) %}
|
||||
</select>
|
||||
{% endfunc %}
|
||||
|
||||
Options fields of a search <select> element
|
||||
{% func searchOptions(selected string, s []searchField) %}
|
||||
{% for _, s := range s %}
|
||||
{%= searchOption(selected, s) %}
|
||||
{% endfor %}
|
||||
{% endfunc %}
|
||||
|
||||
Single search optiion field of a <select>
|
||||
{% func searchOption(selected string, s searchField) %}
|
||||
<option value="{%s= s.id %}" {% if selected == s.id %}selected{% endif %}>{%s= s.name %}</option>
|
||||
{% endfunc %}
|
||||
|
||||
{% func SearchAdvanced(nav Navigation, search SearchForm) %}
|
||||
<select name="sort" class="form-control input-sm">
|
||||
{%= searchOptions(search.Sort, []searchField{
|
||||
{"torrent_id", "ID"},
|
||||
{"torrent_name", "Name"},
|
||||
{"date", "Date"},
|
||||
{"downloads", "Downloads"},
|
||||
{"filesize", "Size"},
|
||||
}) %}
|
||||
</select>
|
||||
<select name="order" class="form-control input-sm">
|
||||
{%= searchOptions(search.Order, []searchField{
|
||||
{"desc", "Descending"},
|
||||
{"asc", "Ascending"},
|
||||
}) %}
|
||||
</select>
|
||||
<select name="max" class="form-control input-sm">
|
||||
{% code sel := strconv.Itoa(nav.MaxItemPerPage) %}
|
||||
{% for _, m := range [...]int{5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 70, 100, 150, 200, 300} %}
|
||||
{% code id := strconv.Itoa(m) %}
|
||||
{%= searchOption(sel, searchField{id, id}) %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% endfunc %}
|
||||
|
||||
{% func SearchButton(search SearchForm) %}
|
||||
<div class="input-group">
|
||||
<input name="q" class="form-control input-sm" placeholder="Search" type="text" value="{%s search.Query %}">
|
||||
<span class="input-group-btn">
|
||||
<button type="submit" class="btn btn-sm btn-success">
|
||||
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
|
||||
Search
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
{% endfunc %}
|
|
@ -1,343 +0,0 @@
|
|||
// This file is automatically generated by qtc from "search.html".
|
||||
// See https://github.com/valyala/quicktemplate for details.
|
||||
|
||||
//line search.html:1
|
||||
package templates
|
||||
|
||||
//line search.html:1
|
||||
import (
|
||||
qtio422016 "io"
|
||||
|
||||
qt422016 "github.com/valyala/quicktemplate"
|
||||
)
|
||||
|
||||
//line search.html:1
|
||||
import "strconv"
|
||||
|
||||
//line search.html:3
|
||||
var (
|
||||
_ = qtio422016.Copy
|
||||
_ = qt422016.AcquireByteBuffer
|
||||
)
|
||||
|
||||
//line search.html:3
|
||||
type searchField struct {
|
||||
id, name string
|
||||
}
|
||||
|
||||
// Common seatch part of many pages
|
||||
|
||||
//line search.html:8
|
||||
func StreamSearchCommon(qw422016 *qt422016.Writer, search SearchForm) {
|
||||
//line search.html:8
|
||||
qw422016.N().S(`
|
||||
<select name="c" class="form-control input-sm" value>
|
||||
<option value="_">All categories</option>
|
||||
`)
|
||||
//line search.html:11
|
||||
streamsearchOptions(qw422016, search.Category, []searchField{
|
||||
{"3_", "Anime"},
|
||||
{"3_12", "Anime - Anime Music Video"},
|
||||
{"3_5", "Anime - English-translated"},
|
||||
{"3_13", "Anime - Non-English-translated"},
|
||||
{"3_6", "Anime - Raw"},
|
||||
{"2_", "Audio"},
|
||||
{"2_3", "Audio - Lossless"},
|
||||
{"2_4", "Audio - Lossy"},
|
||||
{"4_", "Literature"},
|
||||
{"4_7", "Literature - English-translated"},
|
||||
{"4_8", "Literature - Raw"},
|
||||
{"4_14", "Literature - Non-English-translated"},
|
||||
{"5_", "Live Action"},
|
||||
{"5_9", "Live Action - English-translated"},
|
||||
{"5_10", "Live Action - Idol/Promotional Video"},
|
||||
{"5_18", "Live Action - Non-English-translated"},
|
||||
{"5_11", "Live Action - Raw"},
|
||||
{"6_", "Pictures"},
|
||||
{"6_15", "Pictures - Graphics"},
|
||||
{"6_16", "Pictures - Photos"},
|
||||
{"1_", "Software"},
|
||||
{"1_1", "Software - Applications"},
|
||||
{"1_2", "Software - Games"},
|
||||
})
|
||||
//line search.html:35
|
||||
qw422016.N().S(`
|
||||
</select>
|
||||
<select name="s" class="form-control input-sm">
|
||||
<option value="">Show all</option>
|
||||
`)
|
||||
//line search.html:39
|
||||
streamsearchOptions(qw422016, search.Status, []searchField{
|
||||
{"2", "Filter Remakes"},
|
||||
{"3", "Trusted"},
|
||||
{"4", "A+"},
|
||||
})
|
||||
//line search.html:43
|
||||
qw422016.N().S(`
|
||||
</select>
|
||||
`)
|
||||
//line search.html:45
|
||||
}
|
||||
|
||||
//line search.html:45
|
||||
func WriteSearchCommon(qq422016 qtio422016.Writer, search SearchForm) {
|
||||
//line search.html:45
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line search.html:45
|
||||
StreamSearchCommon(qw422016, search)
|
||||
//line search.html:45
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line search.html:45
|
||||
}
|
||||
|
||||
//line search.html:45
|
||||
func SearchCommon(search SearchForm) string {
|
||||
//line search.html:45
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line search.html:45
|
||||
WriteSearchCommon(qb422016, search)
|
||||
//line search.html:45
|
||||
qs422016 := string(qb422016.B)
|
||||
//line search.html:45
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line search.html:45
|
||||
return qs422016
|
||||
//line search.html:45
|
||||
}
|
||||
|
||||
// Options fields of a search <select> element
|
||||
|
||||
//line search.html:48
|
||||
func streamsearchOptions(qw422016 *qt422016.Writer, selected string, s []searchField) {
|
||||
//line search.html:48
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line search.html:49
|
||||
for _, s := range s {
|
||||
//line search.html:49
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line search.html:50
|
||||
streamsearchOption(qw422016, selected, s)
|
||||
//line search.html:50
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line search.html:51
|
||||
}
|
||||
//line search.html:51
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line search.html:52
|
||||
}
|
||||
|
||||
//line search.html:52
|
||||
func writesearchOptions(qq422016 qtio422016.Writer, selected string, s []searchField) {
|
||||
//line search.html:52
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line search.html:52
|
||||
streamsearchOptions(qw422016, selected, s)
|
||||
//line search.html:52
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line search.html:52
|
||||
}
|
||||
|
||||
//line search.html:52
|
||||
func searchOptions(selected string, s []searchField) string {
|
||||
//line search.html:52
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line search.html:52
|
||||
writesearchOptions(qb422016, selected, s)
|
||||
//line search.html:52
|
||||
qs422016 := string(qb422016.B)
|
||||
//line search.html:52
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line search.html:52
|
||||
return qs422016
|
||||
//line search.html:52
|
||||
}
|
||||
|
||||
// Single search optiion field of a <select>
|
||||
|
||||
//line search.html:55
|
||||
func streamsearchOption(qw422016 *qt422016.Writer, selected string, s searchField) {
|
||||
//line search.html:55
|
||||
qw422016.N().S(`
|
||||
<option value="`)
|
||||
//line search.html:56
|
||||
qw422016.N().S(s.id)
|
||||
//line search.html:56
|
||||
qw422016.N().S(`" `)
|
||||
//line search.html:56
|
||||
if selected == s.id {
|
||||
//line search.html:56
|
||||
qw422016.N().S(`selected`)
|
||||
//line search.html:56
|
||||
}
|
||||
//line search.html:56
|
||||
qw422016.N().S(`>`)
|
||||
//line search.html:56
|
||||
qw422016.N().S(s.name)
|
||||
//line search.html:56
|
||||
qw422016.N().S(`</option>
|
||||
`)
|
||||
//line search.html:57
|
||||
}
|
||||
|
||||
//line search.html:57
|
||||
func writesearchOption(qq422016 qtio422016.Writer, selected string, s searchField) {
|
||||
//line search.html:57
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line search.html:57
|
||||
streamsearchOption(qw422016, selected, s)
|
||||
//line search.html:57
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line search.html:57
|
||||
}
|
||||
|
||||
//line search.html:57
|
||||
func searchOption(selected string, s searchField) string {
|
||||
//line search.html:57
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line search.html:57
|
||||
writesearchOption(qb422016, selected, s)
|
||||
//line search.html:57
|
||||
qs422016 := string(qb422016.B)
|
||||
//line search.html:57
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line search.html:57
|
||||
return qs422016
|
||||
//line search.html:57
|
||||
}
|
||||
|
||||
//line search.html:59
|
||||
func StreamSearchAdvanced(qw422016 *qt422016.Writer, nav Navigation, search SearchForm) {
|
||||
//line search.html:59
|
||||
qw422016.N().S(`
|
||||
<select name="sort" class="form-control input-sm">
|
||||
`)
|
||||
//line search.html:61
|
||||
streamsearchOptions(qw422016, search.Sort, []searchField{
|
||||
{"torrent_id", "ID"},
|
||||
{"torrent_name", "Name"},
|
||||
{"date", "Date"},
|
||||
{"downloads", "Downloads"},
|
||||
{"filesize", "Size"},
|
||||
})
|
||||
//line search.html:67
|
||||
qw422016.N().S(`
|
||||
</select>
|
||||
<select name="order" class="form-control input-sm">
|
||||
`)
|
||||
//line search.html:70
|
||||
streamsearchOptions(qw422016, search.Order, []searchField{
|
||||
{"desc", "Descending"},
|
||||
{"asc", "Ascending"},
|
||||
})
|
||||
//line search.html:73
|
||||
qw422016.N().S(`
|
||||
</select>
|
||||
<select name="max" class="form-control input-sm">
|
||||
`)
|
||||
//line search.html:76
|
||||
sel := strconv.Itoa(nav.MaxItemPerPage)
|
||||
|
||||
//line search.html:76
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line search.html:77
|
||||
for _, m := range [...]int{5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 70, 100, 150, 200, 300} {
|
||||
//line search.html:77
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line search.html:78
|
||||
id := strconv.Itoa(m)
|
||||
|
||||
//line search.html:78
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line search.html:79
|
||||
streamsearchOption(qw422016, sel, searchField{id, id})
|
||||
//line search.html:79
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line search.html:80
|
||||
}
|
||||
//line search.html:80
|
||||
qw422016.N().S(`
|
||||
</select>
|
||||
`)
|
||||
//line search.html:82
|
||||
}
|
||||
|
||||
//line search.html:82
|
||||
func WriteSearchAdvanced(qq422016 qtio422016.Writer, nav Navigation, search SearchForm) {
|
||||
//line search.html:82
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line search.html:82
|
||||
StreamSearchAdvanced(qw422016, nav, search)
|
||||
//line search.html:82
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line search.html:82
|
||||
}
|
||||
|
||||
//line search.html:82
|
||||
func SearchAdvanced(nav Navigation, search SearchForm) string {
|
||||
//line search.html:82
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line search.html:82
|
||||
WriteSearchAdvanced(qb422016, nav, search)
|
||||
//line search.html:82
|
||||
qs422016 := string(qb422016.B)
|
||||
//line search.html:82
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line search.html:82
|
||||
return qs422016
|
||||
//line search.html:82
|
||||
}
|
||||
|
||||
//line search.html:84
|
||||
func StreamSearchButton(qw422016 *qt422016.Writer, search SearchForm) {
|
||||
//line search.html:84
|
||||
qw422016.N().S(`
|
||||
<div class="input-group">
|
||||
<input name="q" class="form-control input-sm" placeholder="Search" type="text" value="`)
|
||||
//line search.html:86
|
||||
qw422016.E().S(search.Query)
|
||||
//line search.html:86
|
||||
qw422016.N().S(`">
|
||||
<span class="input-group-btn">
|
||||
<button type="submit" class="btn btn-sm btn-success">
|
||||
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
|
||||
Search
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
`)
|
||||
//line search.html:94
|
||||
}
|
||||
|
||||
//line search.html:94
|
||||
func WriteSearchButton(qq422016 qtio422016.Writer, search SearchForm) {
|
||||
//line search.html:94
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line search.html:94
|
||||
StreamSearchButton(qw422016, search)
|
||||
//line search.html:94
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line search.html:94
|
||||
}
|
||||
|
||||
//line search.html:94
|
||||
func SearchButton(search SearchForm) string {
|
||||
//line search.html:94
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line search.html:94
|
||||
WriteSearchButton(qb422016, search)
|
||||
//line search.html:94
|
||||
qs422016 := string(qb422016.B)
|
||||
//line search.html:94
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line search.html:94
|
||||
return qs422016
|
||||
//line search.html:94
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
//go:generate qtc --file search.html
|
||||
|
||||
package templates
|
|
@ -1,47 +0,0 @@
|
|||
package templates
|
||||
|
||||
/*
|
||||
* 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
|
||||
}
|
Référencer dans un nouveau ticket