Core

/views/components/Display.html (3.2 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{% import (
"fmt"
"strings"
"time"

"github.com/google/uuid"

"{{{ .Package }}}/app/controller/cutil"
"{{{ .Package }}}/app/lib/filter"
"{{{ .Package }}}/app/util"
) %}

{% func DisplayTimestamp(value *time.Time) %}{% stripspace %}
<span class="nowrap">{%s util.TimeToFull(value) %}</span>
{% endstripspace %}{% endfunc %}

{% func DisplayTimestampRelative(value *time.Time) %}{% stripspace %}
<span class="nowrap reltime" data-time="{%s util.TimeToFull(value) %}">{%s util.TimeRelative(value) %}</span>
{% endstripspace %}{% endfunc %}

{% func DisplayTimestampDay(value *time.Time) %}{% stripspace %}
{%s util.TimeToYMD(value) %}
{% endstripspace %}{% endfunc %}

{% func DisplayUUID(value *uuid.UUID) %}{% stripspace %}
{%- if value != nil -%}
{%s value.String() %}
{%- endif -%}
{% endstripspace %}{% endfunc %}

{% func DisplayStringArray(value []string) %}{% stripspace %}
{% if len(value) == 0 %}
<em>empty</em>
{% endif %}
{% code
maxCount := 3
display := value
var extra int
if len(value) > maxCount {
extra = len(value) - maxCount
display = display[:maxCount]
}
%}
{% if extra > 0 %}<span title="{%s strings.Join(value, `, `) %}">{% endif %}
{%- for idx, v := range display -%}
{% if idx > 0 %},{% space %}{% endif %}
{%s v %}
{% endfor %}
{% if extra > 0 %}, <em>and{% space %}{%d extra %}{% space %}more...</em>{% endif %}
{% if extra > 0 %}</span>{% endif %}
{% endstripspace %}{% endfunc %}

{% func DisplayDiffs(value util.Diffs) %}{% stripspace %}
{%- if len(value) == 0 -%}
<em>no changes</em>
{%- else -%}
<div class="overflow full-width">
<table>
<tbody>
{%- for _, d := range value -%}
<tr>
<td><code>{%s d.Path %}</code></td>
<td><code class="error">{%s d.Old %}</code></td>
<td></td>
<td><code class="success">{%s d.New %}</code></td>
</tr>
{%- endfor -%}
</tbody>
</table>
</div>
{%- endif -%}
{% endstripspace %}{% endfunc %}

{% func DisplayMaps(maps []util.ValueMap, params *filter.Params, preserveWhitespace bool, ps *cutil.PageState) %}{% stripspace %}
{%- if len(maps) == 0 -%}
<em>no results</em>
{%- else -%}
<div class="overflow full-width">
<table>
<thead>
<tr>
{%- for _, k := range maps[0].Keys() -%}
{%= TableHeaderSimple("map", k, k, "", params, nil, ps) %}
{%- endfor -%}
</tr>
</thead>
<tbody>
{%- for _, m := range maps -%}
<tr>
{%- for _, k := range m.Keys() -%}
{%- code
res := ""
switch t := m[k].(type) {
case string:
res = t
case []byte:
res = string(t)
default:
res = fmt.Sprint(m[k])
}
-%}
{%- if preserveWhitespace -%}
<td class="prews">{%s res %}</td>
{%- else -%}
<td>{%s res %}</td>
{%- endif -%}
{%- endfor -%}
</tr>
{%- endfor -%}
</tbody>
</table>
</div>
{%- endif -%}
{% endstripspace %}{% endfunc %}