Added two new functions for @kipukun
GetCategory categoryID keepParent (eg: GetCategory "3" true <= for all anime) Modified GetCategories to (keepParent, keepChild) (eg: GetCategories true true <= for every catagories)
Cette révision appartient à :
Parent
c9c2b8bf46
révision
5e65b20c89
8 fichiers modifiés avec 35 ajouts et 10 suppressions
|
@ -137,7 +137,7 @@ func RSSTorznabHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if t == "caps" {
|
||||
T := publicSettings.GetTfuncFromRequest(r)
|
||||
cat := categories.GetCategoriesSelect(true)
|
||||
cat := categories.GetCategoriesSelect(true, true)
|
||||
var categories []*nyaafeeds.RssCategoryTorznab
|
||||
var keys []string
|
||||
for name := range cat {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"html/template"
|
||||
"math"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -174,8 +175,32 @@ var FuncMap = template.FuncMap{
|
|||
return t.Format(time.RFC3339)
|
||||
},
|
||||
"GetHostname": util.GetHostname,
|
||||
"GetCategories": func(keepParent bool) map[string]string {
|
||||
return categories.GetCategoriesSelect(keepParent)
|
||||
"GetCategories": func(keepParent bool, keepChild bool) map[string]string {
|
||||
return categories.GetCategoriesSelect(keepParent, keepChild)
|
||||
},
|
||||
"GetCategory": func(category string, keepParent bool) (categoryRet map[string]string) {
|
||||
cat := categories.GetCategoriesSelect(true, true)
|
||||
var keys []string
|
||||
for name := range cat {
|
||||
keys = append(keys, name)
|
||||
}
|
||||
|
||||
sort.Strings(keys)
|
||||
found := false
|
||||
categoryRet = make(map[string]string)
|
||||
for _, key := range keys {
|
||||
if cat[key] == category+"_" {
|
||||
found = true
|
||||
if keepParent {
|
||||
categoryRet[key] = cat[key]
|
||||
}
|
||||
} else if len(cat[key]) <= 2 && len(categoryRet) > 0 {
|
||||
break
|
||||
} else if found {
|
||||
categoryRet[key] = cat[key]
|
||||
}
|
||||
}
|
||||
return
|
||||
},
|
||||
"CategoryName": func(category string, sub_category string) string {
|
||||
s := category + "_" + sub_category
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{define "search_common"}}
|
||||
<select name="c" class="form-input hide-xs">
|
||||
<option value="_">{{call $.T "all_categories"}}</option>
|
||||
{{ range $name_cat, $id_cat := (GetCategories true) }}
|
||||
{{ range $name_cat, $id_cat := (GetCategories true true) }}
|
||||
<option value="{{ $id_cat }}" {{if eq $.Search.Category $id_cat }}selected{{end}}>{{call $.T $name_cat }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<label for="c">{{call $.T "category"}}</label>
|
||||
<select name="c" class="form-input up-input">
|
||||
<option value="">{{call $.T "select_a_torrent_category"}}</option>
|
||||
{{ range $name_cat, $id_cat := (GetCategories false) }}
|
||||
{{ range $name_cat, $id_cat := (GetCategories false true) }}
|
||||
<option value="{{ $id_cat }}" {{if eq $.Form.Category $id_cat }}selected{{end}}>{{call $.T $name_cat }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
|
|
|
@ -103,7 +103,7 @@
|
|||
<span class="btn-group">
|
||||
<select class="cb_action" name="category_id" style="width: 14em;">
|
||||
<option value="">{{call $.T "category"}}</option>
|
||||
{{ range $name_cat, $id_cat := (GetCategories true) }}
|
||||
{{ range $name_cat, $id_cat := (GetCategories true true) }}
|
||||
<option value="{{ $id_cat }}">{{call $.T $name_cat }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<h3>{{call $.T "category"}}</h3>
|
||||
<select name="c" id="c" class="form-input up-input" required>
|
||||
<option value="">{{call $.T "select_a_torrent_category"}}</option>
|
||||
{{ range $name_cat, $id_cat := (GetCategories false) }}
|
||||
{{ range $name_cat, $id_cat := (GetCategories false true) }}
|
||||
<option value="{{ $id_cat }}" {{if eq $.Form.Category $id_cat }}selected{{end}}>{{call $.T $name_cat }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<label for="c">{{call $.T "category"}}</label>
|
||||
<select name="c" class="form-input up-input">
|
||||
<option value="">{{call $.T "select_a_torrent_category"}}</option>
|
||||
{{ range $name_cat, $id_cat := (GetCategories false) }}
|
||||
{{ range $name_cat, $id_cat := (GetCategories false true) }}
|
||||
<option value="{{ $id_cat }}" {{if eq $.Form.Category $id_cat }}selected{{end}}>{{call $.T $name_cat }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
|
|
|
@ -28,11 +28,11 @@ func CategoryExists(category string) bool {
|
|||
}
|
||||
|
||||
// GetCategoriesSelect : Format categories in map ordered alphabetically
|
||||
func GetCategoriesSelect(keepParent bool) map[string]string {
|
||||
func GetCategoriesSelect(keepParent bool, keepChild bool) map[string]string {
|
||||
categories := GetCategories()
|
||||
catSelect := make(map[string]string, len(categories))
|
||||
for k, v := range categories {
|
||||
if len(k) > 2 || keepParent {
|
||||
if (keepParent && keepChild) || (len(k) > 2 && !keepParent) || (len(k) <= 2 && !keepChild) {
|
||||
catSelect[v] = k
|
||||
}
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket