github.com/kyleu/dbaudit@v0.0.2-0.20240321155047-ff2f2c940496/views/components/view/Diff.html (about)

     1  <!-- Content managed by Project Forge, see [projectforge.md] for details. -->
     2  {% import (
     3    "github.com/samber/lo"
     4  
     5    "github.com/kyleu/dbaudit/app/controller/cutil"
     6    "github.com/kyleu/dbaudit/app/util"
     7    "github.com/kyleu/dbaudit/views/components"
     8  ) %}
     9  
    10  {% func Diffs(value util.Diffs) %}{% stripspace %}
    11    {%- if len(value) == 0 -%}
    12    <em>no changes</em>
    13    {%- else -%}
    14    <div class="overflow full-width">
    15      <table class="expanded">
    16        <thead>
    17          <tr>
    18            <th>Path</th>
    19            <th>Old</th>
    20            <th></th>
    21            <th>New</th>
    22          </tr>
    23        </thead>
    24        <tbody>
    25          {%- for _, d := range value -%}
    26          <tr>
    27            <td style="width: 30%;"><code>{%s d.Path %}</code></td>
    28            <td style="width: 30%;"><code><em>{%s d.Old %}</em></code></td>
    29            <td style="width: 10%;">→</td>
    30            <td style="width: 30%;"><code class="success">{%s d.New %}</code></td>
    31          </tr>
    32          {%- endfor -%}
    33        </tbody>
    34      </table>
    35    </div>
    36    {%- endif -%}
    37  {% endstripspace %}{% endfunc %}
    38  
    39  {% func DiffsSet(key string, value util.DiffsSet, ps *cutil.PageState) %}{% stripspace %}
    40    {%- if len(value) == 0 -%}
    41    <em>no changes</em>
    42    {%- else -%}
    43    <ul class="accordion">
    44      {%- for idx, k := range util.ArraySorted[string](lo.Keys(value)) -%}
    45        {% code dk, u := util.StringSplitLast(k, '^', true) %}
    46        {%- if idx < 100 -%}
    47          <li>
    48            <input id="accordion-{%s k %}-{%d idx %}" type="checkbox" hidden="hidden" />
    49            <label for="accordion-{%s k %}-{%d idx %}">
    50              {%= components.ExpandCollapse(3, ps) %}
    51              {% if u != "" %}<a href="{%s u %}">{%s dk %}</a>{% else %}{%s dk %}{% endif %}
    52            </label>
    53            <div class="bd"><div><div>
    54              {%= Diffs(value[k]) %}
    55            </div></div></div>
    56          </li>
    57        {%- endif -%}
    58        {%- if idx == 100 -%}
    59          <li>
    60            <input id="accordion-{%s k %}-extras" type="checkbox" hidden="hidden" />
    61            <label for="accordion-{%s k %}-extras">...and{% space %}{%d len(value) - 100 %}{% space %}extra</label>
    62          </li>
    63        {%- endif -%}
    64      {%- endfor -%}
    65    </ul>
    66    {%- endif -%}
    67  {% endstripspace %}{% endfunc %}