révision
e90309615e
3 fichiers modifiés avec 28 ajouts et 6 suppressions
13
index.html
13
index.html
|
@ -67,8 +67,17 @@
|
|||
<option value="4" {{if eq .Status "4"}}selected{{end}}>A+</option>
|
||||
</select>
|
||||
<input name="q" class="form-control input-sm" placeholder="Search" type="text" value={{.Query}}>
|
||||
<select name="sort" class="form-control input-sm">
|
||||
<option value="torrent_id" {{if eq .Sort "torrent_id"}}selected{{end}}>Id</option>
|
||||
<option value="torrent_name" {{if eq .Sort "torrent_name"}}selected{{end}}>Name</option>
|
||||
<option value="date" {{if eq .Sort "date"}}selected{{end}}>Date</option>
|
||||
<option value="downloads" {{if eq .Sort "downloads"}}selected{{end}}>Downloads</option>
|
||||
</select>
|
||||
<select name="order" class="form-control input-sm">
|
||||
<option value="desc" {{if eq .Order "desc"}}selected{{end}}>Descend</option>
|
||||
<option value="asc" {{if eq .Order "asc"}}selected{{end}}>Ascend</option>
|
||||
</select>
|
||||
<select name="max" class="form-control input-sm" value>
|
||||
<option value="">No Items per Page</option>
|
||||
<option value="5" {{if eq .QueryRecordCount 5}}selected{{end}}>5</option>
|
||||
<option value="10" {{if eq .QueryRecordCount 10}}selected{{end}}>10</option>
|
||||
<option value="15" {{if eq .QueryRecordCount 15}}selected{{end}}>15</option>
|
||||
|
@ -91,7 +100,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="container">
|
||||
<table class="table">
|
||||
<tr>
|
||||
|
|
19
main.go
19
main.go
|
@ -98,6 +98,9 @@ func searchHandler(w http.ResponseWriter, r *http.Request) {
|
|||
searchQuery := r.URL.Query().Get("q")
|
||||
cat := r.URL.Query().Get("c")
|
||||
stat := r.URL.Query().Get("s")
|
||||
sort := r.URL.Query().Get("sort")
|
||||
order := r.URL.Query().Get("order")
|
||||
|
||||
catsSplit := strings.Split(cat, "_")
|
||||
// need this to prevent out of index panics
|
||||
var searchCatId, searchSubCatId string
|
||||
|
@ -106,13 +109,21 @@ func searchHandler(w http.ResponseWriter, r *http.Request) {
|
|||
searchCatId = html.EscapeString(catsSplit[0])
|
||||
searchSubCatId = html.EscapeString(catsSplit[1])
|
||||
}
|
||||
if sort == "" {
|
||||
sort = "torrent_id"
|
||||
}
|
||||
if order == "" {
|
||||
order = "desc"
|
||||
}
|
||||
order_by := sort + " " + order
|
||||
|
||||
nbTorrents := 0
|
||||
|
||||
b := []TorrentsJson{}
|
||||
|
||||
torrents := getTorrents(createWhereParams("torrent_name LIKE ? AND status_id LIKE ? AND category_id LIKE ? AND sub_category_id LIKE ?",
|
||||
"%"+searchQuery+"%", stat+"%", searchCatId+"%", searchSubCatId+"%"), maxPerPage, maxPerPage*(pagenum-1))
|
||||
parameters := createWhereParams("torrent_name LIKE ? AND status_id LIKE ? AND category_id LIKE ? AND sub_category_id LIKE ?",
|
||||
"%"+searchQuery+"%", stat+"%", searchCatId+"%", searchSubCatId+"%")
|
||||
torrents := getTorrentsOrderBy(¶meters, order_by, maxPerPage, maxPerPage*(pagenum-1))
|
||||
|
||||
for i, _ := range torrents {
|
||||
nbTorrents++
|
||||
|
@ -122,7 +133,7 @@ func searchHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
}
|
||||
|
||||
htv := HomeTemplateVariables{b, getAllCategories(false), searchQuery, stat, cat, maxPerPage, nbTorrents}
|
||||
htv := HomeTemplateVariables{b, getAllCategories(false), searchQuery, stat, cat, sort, order, maxPerPage, nbTorrents}
|
||||
|
||||
err := templates.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
|
@ -226,7 +237,7 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
}
|
||||
|
||||
htv := HomeTemplateVariables{b, getAllCategories(false), "", "", "_", maxPerPage, nbTorrents}
|
||||
htv := HomeTemplateVariables{b, getAllCategories(false), "", "", "_", "torrent_id", "desc", maxPerPage, nbTorrents}
|
||||
|
||||
err := templates.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
|
|
|
@ -89,6 +89,8 @@ type HomeTemplateVariables struct {
|
|||
Query string
|
||||
Status string
|
||||
Category string
|
||||
Sort string
|
||||
Order string
|
||||
QueryRecordCount int
|
||||
TotalRecordCount int
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket