github.com/kyleu/dbaudit@v0.0.2-0.20240321155047-ff2f2c940496/views/vfile/Tree.html (about)

     1  <!-- Content managed by Project Forge, see [projectforge.md] for details. -->
     2  {% import (
     3  	"path"
     4    "strings"
     5  
     6    "github.com/kyleu/dbaudit/app"
     7    "github.com/kyleu/dbaudit/app/controller/cutil"
     8    "github.com/kyleu/dbaudit/app/lib/filesystem"
     9    "github.com/kyleu/dbaudit/app/util"
    10    "github.com/kyleu/dbaudit/views/components"
    11  ) %}
    12  
    13  {% func Tree(t *filesystem.Tree, urlPrefix string, actions func(p string, n *filesystem.Node) map[string]string, as *app.State, ps *cutil.PageState) %}{% stripspace %}
    14    {%= components.Indent(true, 2) %}
    15    <ul class="accordion">
    16      {%= treeNodes(t.Nodes, "", urlPrefix, actions, as, ps, 2) %}
    17    {%= components.Indent(true, 2) %}
    18    </ul>
    19  {% endstripspace %}{% endfunc %}
    20  
    21  {% 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 %}
    22    {% code
    23      pathID := n.Name
    24      if pth != "" {
    25        pathID = pth + "/" + pathID
    26      }
    27      pathID = strings.ReplaceAll(pathID, "/", "__")
    28    %}
    29    {%= components.Indent(true, indent) %}
    30    <li>
    31      {%= components.Indent(true, indent + 1) %}
    32      <input id="accordion-{%s pathID %}" type="checkbox" hidden="hidden" />
    33      {%= components.Indent(true, indent + 1) %}
    34      <label for="accordion-{%s pathID %}">
    35        {%- code
    36          var acts map[string]string
    37          if actions != nil {
    38            acts = actions(pth, n)
    39          }
    40        -%}
    41        <div class="right">
    42          {%- if n.Size > 0 -%}
    43          <em>{%s util.ByteSizeSI(int64(n.Size)) %}</em>{% space %}
    44          {%- endif -%}
    45          {%- for k, v := range acts -%}
    46          <a href="{%s v %}">{%s k %}</a>
    47          {%- endfor -%}
    48        </div>
    49        {%= components.ExpandCollapse(indent + 2, ps) %}
    50        {%- if n.Dir -%}
    51        {%= components.SVGRef(`folder`, 15, 15, ``, ps) %}
    52        {%- else -%}
    53        {%= components.SVGRef(`file`, 15, 15, ``, ps) %}
    54        {%- endif -%}
    55        {% space %}{%s n.Name %}
    56        {%= components.Indent(true, indent + 1) %}
    57      </label>
    58      {%= components.Indent(true, indent + 1) %}
    59      <div class="bd"><div><div>
    60        {%- if len(n.Children) == 0 -%}
    61          {%= components.Indent(true, indent + 2) %}
    62          <div>{%s n.Name %}</div>
    63        {%- else -%}
    64          {%= components.Indent(true, indent + 2) %}
    65          <ul class="accordion" style="margin-left: {%d (indent / 3) * 6 %}px; margin-bottom: 0;">
    66            {%= treeNodes(n.Children, path.Join(pth, n.Name), urlPrefix, actions, as, ps, indent + 3) %}
    67          {%= components.Indent(true, indent + 2) %}
    68          </ul>
    69        {%- endif -%}
    70      {%= components.Indent(true, indent + 1) %}
    71      </div></div></div>
    72    {%= components.Indent(true, indent) %}
    73    </li>
    74  {% endstripspace %}{% endfunc %}
    75  
    76  {% 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 %}
    77    {%- for _, n := range nodes -%}
    78    {%= treeNode(n, pth, urlPrefix, actions, as, ps, indent + 1) %}
    79    {%- endfor -%}
    80  {% endstripspace %}{% endfunc %}