diff options
author | 6543 <6543@obermui.de> | 2020-06-25 00:23:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-24 23:23:05 +0100 |
commit | c86478ec47366dfb7081cc2eb2790a0af1880eca (patch) | |
tree | 6301cdfabec3f619cd61e673fa9bef3802a16b82 /modules/templates | |
parent | ae20de7771d81d76ff62227e464a699d55c62084 (diff) | |
download | gitea-c86478ec47366dfb7081cc2eb2790a0af1880eca.tar.gz gitea-c86478ec47366dfb7081cc2eb2790a0af1880eca.zip |
[UI] Sortable Tables Header By Click (#7980)
* [UI] Sortable Tables Header By Click
* get rid of padding above header
* restart CI
* fix lint
* convert getArrow JS to SortArrow go func
* addopt SortArrow funct
* suggestions from @silverwind - tablesort.js
Co-authored-by: silverwind <me@silverwind.io>
* Update web_src/js/features/tablesort.js
Co-authored-by: silverwind <me@silverwind.io>
* Update web_src/js/features/tablesort.js
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'modules/templates')
-rw-r--r-- | modules/templates/helper.go | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 374f13af0f..ff974aba9f 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -298,8 +298,30 @@ func NewFuncMap() []template.FuncMap { } return false }, - "svg": func(icon string, size int) template.HTML { - return template.HTML(fmt.Sprintf(`<svg class="svg %s" width="%d" height="%d" aria-hidden="true"><use xlink:href="#%s" /></svg>`, icon, size, size, icon)) + "svg": SVG, + "SortArrow": func(normSort, revSort, urlSort string, isDefault bool) template.HTML { + // if needed + if len(normSort) == 0 || len(urlSort) == 0 { + return "" + } + + if len(urlSort) == 0 && isDefault { + // if sort is sorted as default add arrow tho this table header + if isDefault { + return SVG("octicon-triangle-down", 16) + } + } else { + // if sort arg is in url test if it correlates with column header sort arguments + if urlSort == normSort { + // the table is sorted with this header normal + return SVG("octicon-triangle-down", 16) + } else if urlSort == revSort { + // the table is sorted with this header reverse + return SVG("octicon-triangle-up", 16) + } + } + // the table is NOT sorted with this header + return "" }, }} } @@ -410,6 +432,11 @@ func NewTextFuncMap() []texttmpl.FuncMap { }} } +// SVG render icons +func SVG(icon string, size int) template.HTML { + return template.HTML(fmt.Sprintf(`<svg class="svg %s" width="%d" height="%d" aria-hidden="true"><use xlink:href="#%s" /></svg>`, icon, size, size, icon)) +} + // Safe render raw as HTML func Safe(raw string) template.HTML { return template.HTML(raw) |