Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fix table sorting

Cette révision appartient à :
Eliot Whalan 2017-05-14 22:30:09 +10:00
Parent 4c25077875
révision ec80ada958

Voir le fichier

@ -41,55 +41,56 @@ var FuncMap = template.FuncMap{
order := false order := false
if _, ok := values["order"]; ok { if _, ok := values["order"]; ok {
order, _ = strconv.ParseBool(values["order"][0]) order, _ = strconv.ParseBool(values["order"][0])
if values["sort"][0]==sortBy { if values["sort"][0] == sortBy {
order=!order //Flip order by repeat-clicking order = !order //Flip order by repeat-clicking
} else { } else {
order=false //Default to descending when sorting by something new order = false //Default to descending when sorting by something new
} }
} }
currentUrl.Path = "/search"
values.Set("sort", sortBy) values.Set("sort", sortBy)
values.Set("order", strconv.FormatBool(order)) values.Set("order", strconv.FormatBool(order))
currentUrl.RawQuery=values.Encode() currentUrl.RawQuery = values.Encode()
return template.URL(currentUrl.String()) return template.URL(currentUrl.String())
}, },
"genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML { "genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
var ret = "" var ret = ""
if (nav.TotalItem > 0) { if nav.TotalItem > 0 {
maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage)) maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage))
if nav.CurrentPage-1 > 0 { if nav.CurrentPage-1 > 0 {
url, _ := Router.Get(nav.Route).URL("page", "1") url, _ := Router.Get(nav.Route).URL("page", "1")
ret = ret + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>" ret = ret + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>"
}
startValue := 1
if nav.CurrentPage > pagesSelectable/2 {
startValue = (int(math.Min((float64(nav.CurrentPage)+math.Floor(float64(pagesSelectable)/2)), maxPages)) - pagesSelectable + 1)
}
endValue := (startValue + pagesSelectable - 1)
if endValue > int(maxPages) {
endValue = int(maxPages)
}
log.Println(nav.TotalItem)
for i := startValue; i <= endValue; i++ {
pageNum := strconv.Itoa(i)
url, _ := Router.Get(nav.Route).URL("page", pageNum)
ret = ret + "<li"
if i == nav.CurrentPage {
ret = ret + " class=\"active\""
} }
startValue := 1
if nav.CurrentPage > pagesSelectable/2 {
startValue = (int(math.Min((float64(nav.CurrentPage)+math.Floor(float64(pagesSelectable)/2)), maxPages)) - pagesSelectable + 1)
}
endValue := (startValue + pagesSelectable - 1)
if endValue > int(maxPages) {
endValue = int(maxPages)
}
log.Println(nav.TotalItem)
for i := startValue; i <= endValue; i++ {
pageNum := strconv.Itoa(i)
url, _ := Router.Get(nav.Route).URL("page", pageNum)
ret = ret + "<li"
if i == nav.CurrentPage {
ret = ret + " class=\"active\""
}
ret = ret + "><a href=\"" + url.String() + "?" + currentUrl.RawQuery + "\">" + strconv.Itoa(i) + "</a></li>" ret = ret + "><a href=\"" + url.String() + "?" + currentUrl.RawQuery + "\">" + strconv.Itoa(i) + "</a></li>"
} }
if nav.CurrentPage < int(maxPages) { if nav.CurrentPage < int(maxPages) {
url, _ := Router.Get(nav.Route).URL("page", strconv.Itoa(nav.CurrentPage+1)) url, _ := Router.Get(nav.Route).URL("page", strconv.Itoa(nav.CurrentPage+1))
ret = ret + "<li><a id=\"page-next\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a></li>" ret = ret + "<li><a id=\"page-next\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a></li>"
} }
} }
return template.HTML(ret) return template.HTML(ret)
}, },
"T": i18n.IdentityTfunc, "T": i18n.IdentityTfunc,
"Ts": i18n.IdentityTfunc, "Ts": i18n.IdentityTfunc,
"getAvatar": func(hash string, size int) string { "getAvatar": func(hash string, size int) string {
return "https://www.gravatar.com/avatar/" + hash + "?s=" + strconv.Itoa(size) return "https://www.gravatar.com/avatar/" + hash + "?s=" + strconv.Itoa(size)
@ -104,9 +105,9 @@ var FuncMap = template.FuncMap{
return template.HTML(str) return template.HTML(str)
}, },
"calcWidthSeed": func(seed uint32, leech uint32) float64 { "calcWidthSeed": func(seed uint32, leech uint32) float64 {
return float64(float64(seed)/(float64(seed)+float64(leech)))*100 return float64(float64(seed)/(float64(seed)+float64(leech))) * 100
}, },
"calcWidthLeech": func(seed uint32, leech uint32) float64 { "calcWidthLeech": func(seed uint32, leech uint32) float64 {
return float64(float64(leech)/(float64(seed)+float64(leech)))*100 return float64(float64(leech)/(float64(seed)+float64(leech))) * 100
}, },
} }