Changing catSelect Behavior
Return now Categories object instead of map[string]string. Remove some debug log
Cette révision appartient à :
Parent
4d0c3a18c8
révision
03ded2e027
10 fichiers modifiés avec 39 ajouts et 51 suppressions
|
@ -8,8 +8,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"sort"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
"github.com/NyaaPantsu/nyaa/models"
|
||||
"github.com/NyaaPantsu/nyaa/models/users"
|
||||
|
@ -177,30 +175,26 @@ func RSSTorznabHandler(c *gin.Context) {
|
|||
}
|
||||
if t == "caps" {
|
||||
T := publicSettings.GetTfuncFromRequest(c)
|
||||
cat := categories.GetSelect(true, true)
|
||||
cats := categories.GetSelect(true, true)
|
||||
var categories []*nyaafeeds.RssCategoryTorznab
|
||||
categories = append(categories, &nyaafeeds.RssCategoryTorznab{
|
||||
ID: "5070",
|
||||
Name: "Anime",
|
||||
Description: "Anime",
|
||||
})
|
||||
var keys []string
|
||||
for name := range cat {
|
||||
keys = append(keys, name)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
last := 0
|
||||
for _, key := range keys {
|
||||
if len(cat[key]) <= 2 {
|
||||
for _, v := range cats {
|
||||
if len(v.ID) <= 2 {
|
||||
categories = append(categories, &nyaafeeds.RssCategoryTorznab{
|
||||
ID: nyaafeeds.ConvertFromCat(cat[key]),
|
||||
Name: string(T(key)),
|
||||
ID: nyaafeeds.ConvertFromCat(v.ID),
|
||||
Name: string(T(v.Name)),
|
||||
})
|
||||
last++
|
||||
} else {
|
||||
categories[last].Subcat = append(categories[last].Subcat, &nyaafeeds.RssSubCat{
|
||||
ID: nyaafeeds.ConvertFromCat(cat[key]),
|
||||
Name: string(T(key)),
|
||||
ID: nyaafeeds.ConvertFromCat(v.ID),
|
||||
Name: string(T(v.Name)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"html/template"
|
||||
"math"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -161,29 +160,23 @@ func templateFunctions(vars jet.VarMap) jet.VarMap {
|
|||
return t.Format(time.RFC3339)
|
||||
})
|
||||
vars.Set("GetHostname", format.GetHostname)
|
||||
vars.Set("GetCategories", func(keepParent bool, keepChild bool) map[string]string {
|
||||
vars.Set("GetCategories", func(keepParent bool, keepChild bool) categories.Categories {
|
||||
return categories.GetSelect(keepParent, keepChild)
|
||||
})
|
||||
vars.Set("GetCategory", func(category string, keepParent bool) (categoryRet map[string]string) {
|
||||
cat := categories.GetSelect(true, true)
|
||||
var keys []string
|
||||
for name := range cat {
|
||||
keys = append(keys, name)
|
||||
}
|
||||
|
||||
sort.Strings(keys)
|
||||
vars.Set("GetCategory", func(category string, keepParent bool) (categoryRet categories.Categories) {
|
||||
cats := categories.GetSelect(true, true)
|
||||
found := false
|
||||
categoryRet = make(map[string]string)
|
||||
for _, key := range keys {
|
||||
if cat[key] == category+"_" {
|
||||
categoryRet = make(categories.Categories, len(cats))
|
||||
for _, v := range cats {
|
||||
if v.ID == category+"_" {
|
||||
found = true
|
||||
if keepParent {
|
||||
categoryRet[key] = cat[key]
|
||||
categoryRet = append(categoryRet, v)
|
||||
}
|
||||
} else if len(cat[key]) <= 2 && len(categoryRet) > 0 {
|
||||
} else if len(v.ID) <= 2 && len(categoryRet) > 0 {
|
||||
break
|
||||
} else if found {
|
||||
categoryRet[key] = cat[key]
|
||||
categoryRet = append(categoryRet, v)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
<label for="c">{{ T("category")}}</label>
|
||||
<select name="c" class="form-input up-input">
|
||||
<option value="">{{ T("select_a_torrent_category")}}</option>
|
||||
{{ range name_cat, id_cat := GetCategories(false, true) }}
|
||||
<option value="{{ id_cat }}" {{if Form.Category == id_cat }}selected{{end}}>{{ T(name_cat) }}</option>
|
||||
{{ range _, cat := GetCategories(false, true) }}
|
||||
<option value="{{ cat.ID }}" {{if Form.Category == cat.ID }}selected{{end}}>{{ T(cat.Name) }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
{{block search_common()}}
|
||||
<select name="c" class="form-input hide-xs">
|
||||
<option value="_">{{ T("all_categories")}}</option>
|
||||
{{ range name_cat, id_cat := GetCategories(true, true) }}
|
||||
<option value="{{ id_cat }}" {{if Search.Category == id_cat }}selected{{end}}>{{ T(name_cat) }}</option>
|
||||
{{ range _, cat := GetCategories(true, true) }}
|
||||
<option value="{{ cat.ID }}" {{if Search.Category == cat.ID }}selected{{end}}>{{ T(cat.Name) }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
<label><span class="select-icon caret-down-icon"></span></label>
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
<label class="input-label" for="c">{{ T("category")}}</label>
|
||||
<select name="c" class="form-input up-input">
|
||||
<option value="">{{ T("select_a_torrent_category")}}</option>
|
||||
{{ range name_cat, id_cat := GetCategories(false, true) }}
|
||||
<option value="{{ id_cat }}" {{if Form.Category == id_cat }}selected{{end}}>{{T(name_cat) }}</option>
|
||||
{{ range _, cat := GetCategories(false, true) }}
|
||||
<option value="{{ cat.ID }}" {{if Form.Category == cat.ID }}selected{{end}}>{{T(cat.Name) }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
{{ yield errors(name="c")}}
|
||||
|
|
|
@ -105,8 +105,8 @@
|
|||
<span class="btn-group">
|
||||
<select class="cb_action" name="category_id" style="width: 14em;">
|
||||
<option value="">{{ T("category")}}</option>
|
||||
{{ range name_cat, id_cat := GetCategories(true, true) }}
|
||||
<option value="{{ id_cat }}">{{ T(name_cat) }}</option>
|
||||
{{ range _, cat := GetCategories(true, true) }}
|
||||
<option value="{{ cat.ID }}">{{ T(cat.Name) }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
<input class="cb_action" type="number" name="owner_id" style="width: 10em;" placeholder="{{ T("owner_id_placeholder") }}">
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
<h3>{{ T("category")}}</h3>
|
||||
<select name="c" id="c" class="form-input up-input" required>
|
||||
<option value="">{{ T("select_a_torrent_category")}}</option>
|
||||
{{ range name_cat, id_cat := GetCategories(false, true) }}
|
||||
<option value="{{ id_cat }}" {{if Form.Category == id_cat }}selected{{end}}>{{ T(name_cat) }}</option>
|
||||
{{ range _, cat := GetCategories(false, true) }}
|
||||
<option value="{{ cat.ID }}" {{if Form.Category == cat.ID }}selected{{end}}>{{ T(cat.Name) }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
{{ yield errors(name="c")}}
|
||||
|
|
|
@ -79,11 +79,13 @@ func Exists(category string) bool {
|
|||
}
|
||||
|
||||
// GetSelect : Format categories in map ordered alphabetically
|
||||
func GetSelect(keepParent bool, keepChild bool) map[string]string {
|
||||
catSelect := make(map[string]string, len(categories))
|
||||
func GetSelect(keepParent bool, keepChild bool) Categories {
|
||||
catSelect := make(Categories, len(categories))
|
||||
k := 0
|
||||
for _, v := range categories {
|
||||
if (keepParent && keepChild) || (len(v.ID) > 2 && !keepParent) || (len(v.ID) <= 2 && !keepChild) {
|
||||
catSelect[v.Name] = v.ID
|
||||
catSelect[k] = v
|
||||
k++
|
||||
}
|
||||
}
|
||||
return catSelect
|
||||
|
|
|
@ -38,9 +38,9 @@ func TestCategoryExists(t *testing.T) {
|
|||
func TestGetCategoriesSelect(t *testing.T) {
|
||||
cats := GetSelect(true, false)
|
||||
for _, value := range cats {
|
||||
split := strings.Split(value, "_")
|
||||
split := strings.Split(value.ID, "_")
|
||||
if len(split) != 2 {
|
||||
t.Errorf("The category %s doesn't have only one underscore", value)
|
||||
t.Errorf("The category %s doesn't have only one underscore", value.Name)
|
||||
}
|
||||
if split[1] != "" {
|
||||
t.Errorf("The function doesn't filter out child categories, expected '', got %s", split[1])
|
||||
|
@ -48,9 +48,9 @@ func TestGetCategoriesSelect(t *testing.T) {
|
|||
}
|
||||
cats = GetSelect(false, true)
|
||||
for _, value := range cats {
|
||||
split := strings.Split(value, "_")
|
||||
split := strings.Split(value.ID, "_")
|
||||
if len(split) != 2 {
|
||||
t.Errorf("The category %s doesn't have only one underscore", value)
|
||||
t.Errorf("The category %s doesn't have only one underscore", value.Name)
|
||||
}
|
||||
if split[1] == "" {
|
||||
t.Error("The function doesn't filter out parent categories, expected a string, got nothing")
|
||||
|
|
|
@ -92,11 +92,10 @@ func ExtractBasicValue(c *gin.Context, r *torrentValidator.TorrentRequest) error
|
|||
r.WebsiteLink = strings.TrimSpace(r.WebsiteLink)
|
||||
r.Magnet = strings.TrimSpace(r.Magnet)
|
||||
|
||||
fmt.Println("Languages:")
|
||||
fmt.Println(r.Languages)
|
||||
r.Languages = c.PostFormArray("languages")
|
||||
if len(r.Languages) == 0 { // Shouldn't have to do that since c.Bind actually bind arrays, but better off adding it in case gin doesn't do his work
|
||||
r.Languages = c.PostFormArray("languages")
|
||||
}
|
||||
// then actually check that we have everything we need
|
||||
fmt.Println(r.Languages)
|
||||
|
||||
err := r.ValidateDescription()
|
||||
if err != nil {
|
||||
|
|
Référencer dans un nouveau ticket