Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Port _search.html to quicktemplate

Cette révision appartient à :
bakape 2017-05-07 00:16:21 +03:00
Parent 8b71956412
révision f5bdb369c8
14 fichiers modifiés avec 528 ajouts et 163 suppressions

1
.gitignore externe
Voir le fichier

@ -6,3 +6,4 @@ nyaa.exe
nyaa-master.exe
*.zip
*.swp
.vscode

Voir le fichier

@ -4,20 +4,16 @@ 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 := NewSearchForm()
searchForm := templates.NewSearchForm()
searchForm.HideAdvancedSearch = true
err := faqTemplate.ExecuteTemplate(w, "index.html", FaqTemplateVariables{Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
err := faqTemplate.ExecuteTemplate(w, "index.html", FaqTemplateVariables{templates.Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}

Voir le fichier

@ -8,15 +8,12 @@ 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"]
@ -41,8 +38,8 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
b = append(b, res)
}
navigationTorrents := Navigation{nbTorrents, maxPerPage, pagenum, "search_page"}
htv := HomeTemplateVariables{b, torrentService.GetAllCategories(false), NewSearchForm(), navigationTorrents, r.URL, mux.CurrentRoute(r)}
navigationTorrents := templates.Navigation{nbTorrents, maxPerPage, pagenum, "search_page"}
htv := HomeTemplateVariables{b, torrentService.GetAllCategories(false), templates.NewSearchForm(), navigationTorrents, r.URL, mux.CurrentRoute(r)}
err := homeTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {

Voir le fichier

@ -8,16 +8,13 @@ import (
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/service/torrent"
"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"]
@ -37,8 +34,8 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
b = append(b, res)
}
navigationTorrents := Navigation{nbTorrents, search_param.Max, pagenum, "search_page"}
searchForm := SearchForm{
navigationTorrents := templates.Navigation{nbTorrents, search_param.Max, pagenum, "search_page"}
searchForm := templates.SearchForm{
search_param.Query,
search_param.Status,
search_param.Category,

Voir le fichier

@ -6,6 +6,8 @@ import (
"math"
"net/url"
"strconv"
"github.com/ewhal/nyaa/templates"
)
var FuncMap = template.FuncMap{
@ -20,11 +22,11 @@ var FuncMap = template.FuncMap{
"genRouteWithQuery": func(name string, currentUrl *url.URL, params ...string) template.HTML {
url, err := Router.Get(name).URL(params...)
if err == nil {
return template.HTML(url.String()+ "?" + currentUrl.RawQuery)
return template.HTML(url.String() + "?" + currentUrl.RawQuery)
}
return "error"
},
"genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
"genNav": func(nav templates.Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage))
var ret = ""
@ -57,4 +59,13 @@ 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))
},
}

Voir le fichier

@ -1,9 +1,11 @@
package router
import (
"github.com/ewhal/nyaa/model"
"github.com/gorilla/mux"
"net/url"
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/templates"
"github.com/gorilla/mux"
)
/* Each Page should have an object to pass to their own template
@ -13,16 +15,16 @@ import (
*/
type FaqTemplateVariables struct {
Navigation Navigation
Search SearchForm
Navigation templates.Navigation
Search templates.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 SearchForm
Navigation Navigation
Search templates.SearchForm
Navigation templates.Navigation
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
@ -30,62 +32,16 @@ type ViewTemplateVariables struct {
type HomeTemplateVariables struct {
ListTorrents []model.TorrentsJson
ListCategories []model.Categories
Search SearchForm
Navigation Navigation
Search templates.SearchForm
Navigation templates.Navigation
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
type UploadTemplateVariables struct {
Upload UploadForm
Search SearchForm
Navigation Navigation
Search templates.SearchForm
Navigation templates.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
}

Voir le fichier

@ -4,15 +4,12 @@ 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
@ -24,7 +21,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, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
htv := UploadTemplateVariables{uploadForm, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
err = uploadTemplate.ExecuteTemplate(w, "index.html", htv)
} else {
w.WriteHeader(http.StatusMethodNotAllowed)

Voir le fichier

@ -5,15 +5,12 @@ 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"]
@ -21,7 +18,7 @@ func ViewHandler(w http.ResponseWriter, r *http.Request) {
torrent, err := torrentService.GetTorrentById(id)
b := torrent.ToJson()
htv := ViewTemplateVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
htv := ViewTemplateVariables{b, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
err = viewTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {

Voir le fichier

@ -1,72 +0,0 @@
{{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>
</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}}

Voir le fichier

@ -41,7 +41,7 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="{{.URL.Parse "/upload"}}">Upload</a/></li>
<li><a href="{{.URL.Parse "/faq"}}">FAQ</a></li>
<li><a href="{{.URL.Parse "/faq"}}">FAQ</a></li>
<li><a href="irc://irc.rizon.net/nyaapantsu">IRC</a></li>
<li><a href="{{ genRouteWithQuery "feed" .URL }}">RSS</a></li>
<li><a href="https://sukebei.pantsu.cat">Fap</a></li>
@ -65,9 +65,9 @@
<font size="4.5">Advanced Search</font><br />
<form class="navbar-form" role="search" action="/search" method="get">
<div class="form-group">
{{block "search_common" .}}{{end}}
{{block "search_advanced" .}}{{end}}
{{block "search_button" .}}{{end}}
{{ SearchCommon .Search }}
{{ SearchAdvanced .Navigation .Search }}
{{ SearchButton .Search }}
</div>
</form>
<div style="clear:both"></div>

93
templates/search.html Fichier normal
Voir le fichier

@ -0,0 +1,93 @@
{% 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"},
}) %}
</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 %}

342
templates/search.html.go Fichier normal
Voir le fichier

@ -0,0 +1,342 @@
// 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"},
})
//line search.html:66
qw422016.N().S(`
</select>
<select name="order" class="form-control input-sm">
`)
//line search.html:69
streamsearchOptions(qw422016, search.Order, []searchField{
{"desc", "Descending"},
{"asc", "Ascending"},
})
//line search.html:72
qw422016.N().S(`
</select>
<select name="max" class="form-control input-sm">
`)
//line search.html:75
sel := strconv.Itoa(nav.MaxItemPerPage)
//line search.html:75
qw422016.N().S(`
`)
//line search.html:76
for _, m := range [...]int{5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 70, 100, 150, 200, 300} {
//line search.html:76
qw422016.N().S(`
`)
//line search.html:77
id := strconv.Itoa(m)
//line search.html:77
qw422016.N().S(`
`)
//line search.html:78
streamsearchOption(qw422016, sel, searchField{id, id})
//line search.html:78
qw422016.N().S(`
`)
//line search.html:79
}
//line search.html:79
qw422016.N().S(`
</select>
`)
//line search.html:81
}
//line search.html:81
func WriteSearchAdvanced(qq422016 qtio422016.Writer, nav Navigation, search SearchForm) {
//line search.html:81
qw422016 := qt422016.AcquireWriter(qq422016)
//line search.html:81
StreamSearchAdvanced(qw422016, nav, search)
//line search.html:81
qt422016.ReleaseWriter(qw422016)
//line search.html:81
}
//line search.html:81
func SearchAdvanced(nav Navigation, search SearchForm) string {
//line search.html:81
qb422016 := qt422016.AcquireByteBuffer()
//line search.html:81
WriteSearchAdvanced(qb422016, nav, search)
//line search.html:81
qs422016 := string(qb422016.B)
//line search.html:81
qt422016.ReleaseByteBuffer(qb422016)
//line search.html:81
return qs422016
//line search.html:81
}
//line search.html:83
func StreamSearchButton(qw422016 *qt422016.Writer, search SearchForm) {
//line search.html:83
qw422016.N().S(`
<div class="input-group">
<input name="q" class="form-control input-sm" placeholder="Search" type="text" value="`)
//line search.html:85
qw422016.E().S(search.Query)
//line search.html:85
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:93
}
//line search.html:93
func WriteSearchButton(qq422016 qtio422016.Writer, search SearchForm) {
//line search.html:93
qw422016 := qt422016.AcquireWriter(qq422016)
//line search.html:93
StreamSearchButton(qw422016, search)
//line search.html:93
qt422016.ReleaseWriter(qw422016)
//line search.html:93
}
//line search.html:93
func SearchButton(search SearchForm) string {
//line search.html:93
qb422016 := qt422016.AcquireByteBuffer()
//line search.html:93
WriteSearchButton(qb422016, search)
//line search.html:93
qs422016 := string(qb422016.B)
//line search.html:93
qt422016.ReleaseByteBuffer(qb422016)
//line search.html:93
return qs422016
//line search.html:93
}

3
templates/templates.go Fichier normal
Voir le fichier

@ -0,0 +1,3 @@
//go:generate qtc --file search.html
package templates

47
templates/vars.go Fichier normal
Voir le fichier

@ -0,0 +1,47 @@
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
}