Search

/views/vsearch/Result.html (1.5 KB)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{% import (
"strings"

"{{{ .Package }}}/app"
"{{{ .Package }}}/app/controller/cutil"
"{{{ .Package }}}/app/lib/search"
"{{{ .Package }}}/app/lib/search/result"
"{{{ .Package }}}/views/components"
) %}

{% func Result(res *result.Result, params *search.Params, as *app.State, ps *cutil.PageState) %}
<div class="card">
<div class="right">
{%- if res.Data == nil -%}
<em>{%s res.Type %}</em>
{%- elseif res.ID != "" -%}
<a href="#modal-{%s res.Type %}-{%s res.ID %}"><button type="button">{%s res.Type %}</button></a>
{%= components.JSONModal(res.Type + "-" + res.ID, res.Type, res.Data, 3) %}
{%- endif -%}
</div>
<h3><a href="{%s res.URL %}">{% if res.Icon != "" %}{%= components.SVGRefIcon(res.Icon, ps) %}{% endif %}{% if res.Title == "" %}{%s res.URL %}{% else %}{%s res.Title %}{% endif %}</a></h3>
<p>{%= Match(params, res.Matches) %}</p>
{%- if res.HTML != "" -%}
<div>{%s= res.HTML %}</div>
{%- endif -%}
</div>
{% endfunc %}

{% func Match(params *search.Params, matches result.Matches) %}
<ul>
{%- if len(matches) == 0 -%}
<li><em>{%s params.Q %}</em></li>
{%- endif -%}
{%- for _, m := range matches -%}
<li>
<em>{%s m.Key %}</em>:
{%- code split := m.ValueSplit(params.Q) -%}
{%- for _, x := range split -%}{% if strings.EqualFold(x, params.Q) %}<strong>{%s x %}</strong>{% else %}{%s x %}{% endif %}{%- endfor -%}
</li>
{%- endfor -%}
</ul>
{% endfunc %}