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

     1  <!-- Content managed by Project Forge, see [projectforge.md] for details. -->
     2  {% import (
     3    "strings"
     4  
     5    "github.com/kyleu/dbaudit/app/controller/cmenu"
     6    "github.com/kyleu/dbaudit/app/controller/cutil"
     7    "github.com/kyleu/dbaudit/app/lib/menu"
     8    "github.com/kyleu/dbaudit/views/components"
     9  ) %}
    10  
    11  {% func Menu(ps *cutil.PageState) %}{% stripspace %}
    12    {% if len(ps.Menu) > 0 %}
    13    <div class="menu-container">
    14      {%= components.Indent(true, 2) %}
    15      <div class="menu">
    16        {%= components.Indent(true, 3) %}
    17        <menu class="level-0">
    18          {% for _, i := range ps.Menu %}
    19            {%= MenuItem(i, []string{}, ps.Breadcrumbs, 3, ps) %}
    20          {% endfor %}
    21        {%= components.Indent(true, 3) %}
    22        </menu>
    23      {%= components.Indent(true, 2) %}
    24      </div>
    25    {%= components.Indent(true, 1) %}
    26    </div>
    27    {% endif %}
    28  {% endstripspace %}{% endfunc %}
    29  
    30  {% func MenuItem(i *menu.Item, path []string, breadcrumbs cmenu.Breadcrumbs, indent int, ps *cutil.PageState) %}{% stripspace %}
    31    {% code
    32      path = append(path, i.Key)
    33      active, final := breadcrumbs.Active(i, path)
    34    %}
    35    {% if i.Key == "" %}
    36      {%= components.Indent(true, indent + 1) %}
    37      <li class="separator"></li>
    38    {% elseif len(i.Children) > 0 %}
    39      {% code itemID := strings.Join(path, "--")%}
    40      {%= components.Indent(true, indent + 1) %}
    41      {% if active %}<li class="active" data-menu-key="{%s i.Key %}">{% else %}<li data-menu-key="{%s i.Key %}">{% endif %}
    42        {%= components.Indent(true, indent + 2) %}
    43        <input id="{%s itemID %}-input" type="checkbox"{% if active %}{% space %}checked="checked"{% endif %}{% space %}hidden="hidden" />
    44        {%= components.Indent(true, indent + 2) %}
    45        {% if final %}<label class="final" for="{%s itemID %}-input" title="{%s i.Desc() %}">{% else %}<label for="{%s itemID %}-input" title="{%s i.Desc() %}">{% endif %}
    46          {% if i.Route != "" %}
    47            {%= components.Indent(true, indent + 3) %}
    48            <a class="label-link" href="{%s i.Route %}">{%= components.SVGRef(`link`, 15, 15, ``, ps) %}</a>
    49          {% endif %}
    50          {%= components.ExpandCollapse(indent + 3, ps) %}
    51          {% if i.Badge != "" %}
    52            {%= components.Indent(true, indent + 3) %}
    53            <div class="badge">{%s i.Badge %}</div>
    54          {% endif %}
    55          {%= components.Indent(true, indent + 3) %}
    56          {% if i.Icon != "" %}
    57            {%= components.SVGRef(i.Icon, 16, 16, "icon", ps) %}
    58          {% endif %}
    59          {% if i.Route != "" %}
    60            {% if i.Warning != "" %}
    61              <a class="link-confirm" data-message="{%s i.Warning %}" href="{%s i.Route %}">{%s i.Title %}</a>
    62            {% else %}
    63              <a href="{%s i.Route %}">{%s i.Title %}</a>
    64            {% endif %}
    65          {% else %}
    66            {%s i.Title %}
    67          {% endif %}
    68        {%= components.Indent(true, indent + 2) %}
    69        </label>
    70        {%= components.Indent(true, indent + 2) %}
    71        <div class="menu-content level-{%d len(path) %}">
    72          {%= components.Indent(true, indent + 3) %}
    73          <menu>
    74            {% for _, i := range i.Children %}
    75              {%= MenuItem(i, path, breadcrumbs, indent + 3, ps) %}
    76            {% endfor %}
    77            {%= components.Indent(true, indent + 3) %}
    78          </menu>
    79        {%= components.Indent(true, indent + 2) %}
    80        </div>
    81        {%= components.Indent(true, indent + 1) %}
    82      </li>
    83    {% else %}
    84      {% code
    85        finalClass := "item"
    86        if active {
    87          finalClass += " active"
    88        }
    89        if final {
    90          finalClass += " final"
    91        }
    92        if i.Warning != "" {
    93          finalClass += " link-confirm"
    94        }
    95      %}
    96      {%= components.Indent(true, indent + 1) %}
    97      <li data-menu-key="{%s i.Key %}">
    98        {% if i.Warning != "" %}
    99        <a class="{%s finalClass %}" data-message="{%s i.Warning %}" href="{%s i.Route %}" title="{%s i.Desc() %}">
   100        {% else %}
   101        <a class="{%s finalClass %}" href="{%s i.Route %}" title="{%s i.Desc() %}">
   102        {% endif %}
   103          {% if i.Badge != "" %}
   104            {%= components.Indent(true, indent + 3) %}
   105            <div class="badge">{%s i.Badge %}</div>
   106          {% endif %}
   107          {% if i.Icon != "" %}
   108            {%= components.SVGRef(i.Icon, 16, 16, "icon", ps) %}
   109          {% endif %}
   110          {%s i.Title %}
   111        </a>
   112      </li>
   113    {% endif %}
   114  {% endstripspace %}{% endfunc %}