Filesystem

/views/vfile/Tree.html (2.9 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
{% import (
"path"
"strings"

"{{{ .Package }}}/app"
"{{{ .Package }}}/app/controller/cutil"
"{{{ .Package }}}/app/lib/filesystem"
"{{{ .Package }}}/app/util"
"{{{ .Package }}}/views/components"
"{{{ .Package }}}/views/vutil"
) %}

{% func Tree(t *filesystem.Tree, urlPrefix string, actions func(p string, n *filesystem.Node) map[string]string, as *app.State, ps *cutil.PageState) %}{% stripspace %}
{%= vutil.Indent(true, 2) %}
<ul class="accordion">
{%= treeNodes(t.Nodes, "", urlPrefix, actions, as, ps, 2) %}
{%= vutil.Indent(true, 2) %}
</ul>
{% endstripspace %}{% endfunc %}

{% func treeNode(n *filesystem.Node, pth string, urlPrefix string, actions func(p string, n *filesystem.Node) map[string]string, as *app.State, ps *cutil.PageState, indent int) %}{% stripspace %}
{% code
pathID := n.Name
if pth != "" {
pathID = pth + "/" + pathID
}
pathID = strings.ReplaceAll(pathID, "/", "__")
%}
{%= vutil.Indent(true, indent) %}
<li>
{%= vutil.Indent(true, indent + 1) %}
<input id="accordion-{%s pathID %}" type="checkbox" hidden />
{%= vutil.Indent(true, indent + 1) %}
<label for="accordion-{%s pathID %}">
{%- code
var acts map[string]string
if actions != nil {
acts = actions(pth, n)
}
-%}
<div class="right">
{%- if n.Size > 0 -%}
<em>{%s util.ByteSizeSI(int64(n.Size)) %}</em>{% space %}
{%- endif -%}
{%- for k, v := range acts -%}
<a href="{%s v %}">{%s k %}</a>
{%- endfor -%}
</div>
{%= components.ExpandCollapse(indent + 2, ps) %}
{%- if n.Dir -%}
{%= components.SVGRef(`folder`, 15, 15, ``, ps) %}
{%- else -%}
{%= components.SVGRef(`file`, 15, 15, ``, ps) %}
{%- endif -%}
{% space %}{%s n.Name %}
{%= vutil.Indent(true, indent + 1) %}
</label>
{%= vutil.Indent(true, indent + 1) %}
<div class="bd"><div><div>
{%- if len(n.Children) == 0 -%}
{%= vutil.Indent(true, indent + 2) %}
<div>{%s n.Name %}</div>
{%- else -%}
{%= vutil.Indent(true, indent + 2) %}
<ul class="accordion" style="margin-left: {%d (indent / 3) * 6 %}px; margin-bottom: 0;">
{%= treeNodes(n.Children, path.Join(pth, n.Name), urlPrefix, actions, as, ps, indent + 3) %}
{%= vutil.Indent(true, indent + 2) %}
</ul>
{%- endif -%}
{%= vutil.Indent(true, indent + 1) %}
</div></div></div>
{%= vutil.Indent(true, indent) %}
</li>
{% endstripspace %}{% endfunc %}

{% func treeNodes(nodes filesystem.Nodes, pth string, urlPrefix string, actions func(p string, n *filesystem.Node) map[string]string, as *app.State, ps *cutil.PageState, indent int) %}{% stripspace %}
{%- for _, n := range nodes -%}
{%= treeNode(n, pth, urlPrefix, actions, as, ps, indent + 1) %}
{%- endfor -%}
{% endstripspace %}{% endfunc %}