Search page title function & Fix ES (#1745)
* Update torrentParam.go * Update template_functions.go * Update listing.jet.html * Update listing.jet.html * Update template_functions.go * Update template_functions_test.go * Update template_functions_test.go * Update template_functions_test.go * Update template_functions_test.go * Update torrentParam_test.go * Update template_functions_test.go * rollback * Update torrentParam.go * Update torrentParam_test.go
Cette révision appartient à :
Parent
0a765b5589
révision
a2ea5b3bea
|
@ -52,9 +52,9 @@
|
||||||
</span>
|
</span>
|
||||||
<span class="form-refine">
|
<span class="form-refine">
|
||||||
<span class="spacing">{{ T("from")}}</span>
|
<span class="spacing">{{ T("from")}}</span>
|
||||||
<input class="form-input refine-date" name="fromDate" type="date" value="{{Search.FromDate}}" placeholder="YYYY/MM/DD"/>
|
<input class="form-input refine-date" name="fromDate" type="text" value="{{Search.FromDate}}" placeholder="YYYY/MM/DD"/>
|
||||||
{{ T("to")}}
|
{{ T("to")}}
|
||||||
<input class="form-input refine-date spacing" size="7" name="toDate" type="date" value="{{Search.ToDate}}" placeholder="YYYY/MM/DD"/>
|
<input class="form-input refine-date spacing" size="7" name="toDate" type="text" value="{{Search.ToDate}}" placeholder="YYYY/MM/DD"/>
|
||||||
</span>
|
</span>
|
||||||
<span class="form-refine" style="margin-bottom: 2px;">
|
<span class="form-refine" style="margin-bottom: 2px;">
|
||||||
<span class="spacing">{{T("sort_by")}}</span>
|
<span class="spacing">{{T("sort_by")}}</span>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{ extends "layouts/index_site" }}
|
{{ extends "layouts/index_site" }}
|
||||||
{{ import "layouts/partials/helpers/search" }}
|
{{ import "layouts/partials/helpers/search" }}
|
||||||
{{block title()}}{{if Search.UserName != ""}}{{Search.UserName}}{{else if Search.NameLike != ""}}{{Search.NameLike}}{{else if Search.Category != ""}}{{T(GetCategoryName(Search.Category))}}{{else}}{{ T("home")}}{{end}}{{end}}
|
{{block title()}}{{GenSearchName(Search, URL.String(), T)}}{{end}}
|
||||||
{{block contclass()}}{{if User.IsModerator() }}content-admin{{end}}{{end}}
|
{{block contclass()}}{{if User.IsModerator() }}content-admin{{end}}{{end}}
|
||||||
{{block content_body()}}
|
{{block content_body()}}
|
||||||
{{ if OldNav || Theme == "classic"}}
|
{{ if OldNav || Theme == "classic"}}
|
||||||
|
|
|
@ -42,6 +42,7 @@ func templateFunctions(vars jet.VarMap) jet.VarMap {
|
||||||
vars.Set("CategoryName", categoryName)
|
vars.Set("CategoryName", categoryName)
|
||||||
vars.Set("GetCategoryName", GetCategoryName)
|
vars.Set("GetCategoryName", GetCategoryName)
|
||||||
vars.Set("GetTorrentLanguages", torrentLanguages.GetTorrentLanguages)
|
vars.Set("GetTorrentLanguages", torrentLanguages.GetTorrentLanguages)
|
||||||
|
vars.Set("GenSearchName", GenSearchName)
|
||||||
vars.Set("LanguageName", languageName)
|
vars.Set("LanguageName", languageName)
|
||||||
vars.Set("LanguageNameFromCode", languageNameFromCode)
|
vars.Set("LanguageNameFromCode", languageNameFromCode)
|
||||||
vars.Set("fileSize", fileSize)
|
vars.Set("fileSize", fileSize)
|
||||||
|
@ -451,3 +452,19 @@ func formatDate(Date time.Time, short bool) string {
|
||||||
return fmt.Sprintf("%d/%d/%d, %d:%.2d:%.2d AM UTC+0", Date.Month(), Date.Day(), Date.Year(), Date.Hour(), Date.Minute(), Date.Second())
|
return fmt.Sprintf("%d/%d/%d, %d:%.2d:%.2d AM UTC+0", Date.Month(), Date.Day(), Date.Year(), Date.Hour(), Date.Minute(), Date.Second())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenSearchName(Search SearchForm, currentURL string, T publicSettings.TemplateTfunc) string {
|
||||||
|
if currentURL == "/" {
|
||||||
|
return string(T("home"))
|
||||||
|
}
|
||||||
|
if Search.UserName != "" {
|
||||||
|
return Search.UserName
|
||||||
|
}
|
||||||
|
if Search.NameSearch != "" {
|
||||||
|
return Search.NameSearch
|
||||||
|
}
|
||||||
|
if Search.Category != "" {
|
||||||
|
return string(T(GetCategoryName(Search.Category)))
|
||||||
|
}
|
||||||
|
return string(T("search"))
|
||||||
|
}
|
||||||
|
|
|
@ -830,6 +830,54 @@ func testFormatDate(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testGenSearchName(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
Search SearchForm
|
||||||
|
currentURL string
|
||||||
|
Expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Search: SearchForm{},
|
||||||
|
currentURL: "/",
|
||||||
|
Expected: "home",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Search: SearchForm{},
|
||||||
|
currentURL: "/search",
|
||||||
|
Expected: "search",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Search: SearchForm{UserName: "yiiT"},
|
||||||
|
currentURL: "/username/yiiT/search",
|
||||||
|
Expected: "yiiT",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Search: SearchForm{Category: "3_"},
|
||||||
|
currentURL: "/search?c=3_",
|
||||||
|
Expected: "anime",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Search: SearchForm{Category: "3_12"},
|
||||||
|
currentURL: "/search?c=3_12",
|
||||||
|
Expected: "anime_amv",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
Ts, _, err := publicSettings.TfuncAndLanguageWithFallback("en-us")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Couldn't load language files!")
|
||||||
|
}
|
||||||
|
var T publicSettings.TemplateTfunc
|
||||||
|
T = func(id string, args ...interface{}) template.HTML {
|
||||||
|
return template.HTML(fmt.Sprintf(Ts(id), args...))
|
||||||
|
}
|
||||||
|
value := GenSearchName(test.Search, test.currentURL, T)
|
||||||
|
if value != test.Expected {
|
||||||
|
t.Errorf("Unexpected value from the function GenSearchName, got '%s' wanted '%s'", value, test.Expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func mockupTemplateT(t *testing.T) publicSettings.TemplateTfunc {
|
func mockupTemplateT(t *testing.T) publicSettings.TemplateTfunc {
|
||||||
conf := config.Get().I18n
|
conf := config.Get().I18n
|
||||||
|
|
|
@ -40,6 +40,7 @@ type TorrentParam struct {
|
||||||
ToDate DateFilter
|
ToDate DateFilter
|
||||||
NotNull string // csv
|
NotNull string // csv
|
||||||
NameLike string // csv
|
NameLike string // csv
|
||||||
|
NameSearch string //Contains what NameLike contains but without the excluded keywords, not used for search, just for page title
|
||||||
Languages publicSettings.Languages
|
Languages publicSettings.Languages
|
||||||
MinSize SizeBytes
|
MinSize SizeBytes
|
||||||
MaxSize SizeBytes
|
MaxSize SizeBytes
|
||||||
|
@ -117,6 +118,12 @@ func (p *TorrentParam) FromRequest(c *gin.Context) {
|
||||||
// Search by name
|
// Search by name
|
||||||
// We take the search arguments from "q" in url
|
// We take the search arguments from "q" in url
|
||||||
p.NameLike = strings.TrimSpace(c.Query("q"))
|
p.NameLike = strings.TrimSpace(c.Query("q"))
|
||||||
|
|
||||||
|
for _, word := range strings.Fields(p.NameLike) {
|
||||||
|
if word[0] != '-' {
|
||||||
|
p.NameSearch += word + " "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Maximum results returned
|
// Maximum results returned
|
||||||
// We take the maxximum results to display from "limit" in url
|
// We take the maxximum results to display from "limit" in url
|
||||||
|
@ -254,7 +261,8 @@ func (p *TorrentParam) toESQuery(c *gin.Context) *Query {
|
||||||
query.Append(p.Status.ToESQuery())
|
query.Append(p.Status.ToESQuery())
|
||||||
}
|
}
|
||||||
if !p.Locked {
|
if !p.Locked {
|
||||||
query.Append("!status:5")
|
//query.Append("!status:5")
|
||||||
|
//This line breaks ES but this check is needed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ func TestTorrentParam_FromRequest(t *testing.T) {
|
||||||
c = mockRequest(t, "/?fromID=3&q=xx&c=_")
|
c = mockRequest(t, "/?fromID=3&q=xx&c=_")
|
||||||
torrentParam.FromRequest(c)
|
torrentParam.FromRequest(c)
|
||||||
defTorrent.FromID, defTorrent.NameLike = 3, "xx"
|
defTorrent.FromID, defTorrent.NameLike = 3, "xx"
|
||||||
|
defTorrent.NameSearch = "xx "
|
||||||
assert.Equal(defTorrent, torrentParam)
|
assert.Equal(defTorrent, torrentParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,14 +58,14 @@ func TestTorrentParam_ToESQuery(t *testing.T) {
|
||||||
Test TorrentParam
|
Test TorrentParam
|
||||||
Expected string
|
Expected string
|
||||||
}{
|
}{
|
||||||
{TorrentParam{}, "!status:5"},
|
{TorrentParam{}, ""},
|
||||||
{TorrentParam{NameLike: "lol"}, "!status:5"},
|
{TorrentParam{NameLike: "lol"}, ""},
|
||||||
{TorrentParam{NameLike: "lol", FromID: 12}, "!status:5 id:>12"},
|
{TorrentParam{NameLike: "lol", FromID: 12}, "id:>12"},
|
||||||
{TorrentParam{NameLike: "lol", FromID: 12, FromDate: DateFilter("2017-08-01"), ToDate: DateFilter("2017-08-05")}, "!status:5 id:>12 date: [2017-08-01 2017-08-05]"},
|
{TorrentParam{NameLike: "lol", FromID: 12, FromDate: DateFilter("2017-08-01"), ToDate: DateFilter("2017-08-05")}, "id:>12 date: [2017-08-01 2017-08-05]"},
|
||||||
{TorrentParam{NameLike: "lol", FromID: 12, ToDate: DateFilter("2017-08-05")}, "!status:5 id:>12 date: [* 2017-08-05]"},
|
{TorrentParam{NameLike: "lol", FromID: 12, ToDate: DateFilter("2017-08-05")}, "id:>12 date: [* 2017-08-05]"},
|
||||||
{TorrentParam{NameLike: "lol", FromID: 12, FromDate: DateFilter("2017-08-01")}, "!status:5 id:>12 date: [2017-08-01 *]"},
|
{TorrentParam{NameLike: "lol", FromID: 12, FromDate: DateFilter("2017-08-01")}, "id:>12 date: [2017-08-01 *]"},
|
||||||
{TorrentParam{NameLike: "lol", FromID: 12, Category: Categories{&Category{3, 12}}}, "(category: 3 AND sub_category: 12) !status:5 id:>12"},
|
{TorrentParam{NameLike: "lol", FromID: 12, Category: Categories{&Category{3, 12}}}, "(category: 3 AND sub_category: 12) id:>12"},
|
||||||
{TorrentParam{NameLike: "lol", FromID: 12, Category: Categories{&Category{3, 12}, &Category{3, 12}}}, "((category: 3 AND sub_category: 12) OR (category: 3 AND sub_category: 12)) !status:5 id:>12"},
|
{TorrentParam{NameLike: "lol", FromID: 12, Category: Categories{&Category{3, 12}, &Category{3, 12}}}, "((category: 3 AND sub_category: 12) OR (category: 3 AND sub_category: 12)) id:>12"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Référencer dans un nouveau ticket