github.com/kyleu/dbaudit@v0.0.2-0.20240321155047-ff2f2c940496/views/components/TableHeader.html (about) 1 <!-- Content managed by Project Forge, see [projectforge.md] for details. --> 2 {% import ( 3 "net/url" 4 5 "github.com/kyleu/dbaudit/app/controller/cutil" 6 "github.com/kyleu/dbaudit/app/lib/filter" 7 ) %} 8 9 {% func TableHeader(section string, key string, title string, params *filter.Params, icon string, u *url.URL, tooltip string, sortable bool, cls string, resizable bool, ps *cutil.PageState) %}{% stripspace %} 10 <th class="{% if cls != `` %}{%s cls %}{% space %}{% endif %}no-padding" scope="col"> 11 <div class="{% if resizable %}resize{% else %}noresize{% endif %}"> 12 {% if !sortable %} 13 <div title="{%s tooltip %}"> 14 {% if icon != "" %} 15 {% space %} 16 {%= SVGRef(icon, 16, 16, "icon-block", ps) %} 17 {% endif %} 18 {%s title %} 19 </div> 20 {% elseif params == nil %} 21 {%= thNormal(section, key, title, params, icon, u, tooltip, ps) %} 22 {% else %} 23 {%code o := params.GetOrdering(key) %} 24 {% if o == nil %} 25 {%= thNormal(section, key, title, params, icon, u, tooltip, ps) %} 26 {% else %} 27 {%= thSorted(o.Asc, section, key, title, params, icon, u, tooltip, ps) %} 28 {% endif %} 29 {% endif %} 30 </div> 31 </th> 32 {% endstripspace %}{% endfunc %} 33 34 {% func TableHeaderSimple(section string, key string, title string, tooltip string, params *filter.Params, u *url.URL, ps *cutil.PageState) %}{% stripspace %} 35 {%= TableHeader(section, key, title, params, "", u, tooltip, u != nil, "", false, ps) %} 36 {% endstripspace %}{% endfunc %} 37 38 {% func thNormal(section string, key string, title string, params *filter.Params, icon string, u *url.URL, tooltip string, ps *cutil.PageState) %}{% stripspace %} 39 <a class="sort-hover" href="?{%s= params.CloneOrdering(&filter.Ordering{Column: key, Asc: true}).ToQueryString(u) %}" title="{%s tooltip %}"> 40 <div class="sort-icon" title="click to sort by this column, ascending">{%= SVGRef(`down`, 0, 0, ``, ps) %}</div> 41 <div class="sort-title"> 42 {% if icon != "" %} 43 {% space %} 44 {%= SVGRef(icon, 16, 16, "icon-block", ps) %} 45 {% endif %} 46 {%s title %} 47 </div> 48 </a> 49 {% endstripspace %}{% endfunc %} 50 51 {% func thSorted(asc bool, section string, key string, title string, params *filter.Params, icon string, u *url.URL, tooltip string, ps *cutil.PageState) %}{% stripspace %} 52 {% code 53 ascStr := "ascending" 54 dirStr := "up" 55 if(asc) { 56 ascStr = "descending" 57 dirStr = "down" 58 } 59 %} 60 <a href="?{%s= params.CloneOrdering(&filter.Ordering{Column: key, Asc: !asc}).ToQueryString(u) %}" title="{%s tooltip %}"> 61 <div class="sort-icon" title="click to sort by this column,{% space %}{%s ascStr %}">{%= SVGRef(dirStr, 0, 0, ``, ps) %}</div> 62 <div class="sort-title"> 63 {% if icon != "" %} 64 {% space %} 65 {%= SVGRef(icon, 16, 16, "icon-block", ps) %} 66 {% endif %} 67 {%s title %} 68 </div> 69 </a> 70 {% endstripspace %}{% endfunc %}