{% extends "./browse.html" %}

{% comment %}
Copyright (C) 2017-2024  The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
{% endcomment %}

{% load render_bundle from webpack_loader %}
{% load swh_templatetags %}

{% block header %}
  {{ block.super }}
  {% render_bundle 'revision' %}
{% endblock header %}

{% block swh-browse-content %}
  {% if snapshot_context %}
    {% include "./includes/top-navigation.html" %}
  {% endif %}
  {% if snapshot_context and snapshot_context.is_empty %}
    {% include "./includes/empty-snapshot.html" %}
  {% else %}
    <hr class="mt-0 mb-0" />
    <form class="text-center">
      sort by:
      <div class="form-check form-check-inline"
           title="reverse chronological order">
        <input class="form-check-input"
               type="radio"
               name="revs-ordering"
               id="revs-ordering-date"
               value=""
               onclick="swh.revision.revsOrderingTypeClicked(event)"
               checked />
        <label class="form-check-label font-weight-normal" for="revs-ordering-date">revision date</label>
      </div>
      <div class="form-check form-check-inline"
           title="pre-order, depth-first visit on the revision graph">
        <input class="form-check-input"
               type="radio"
               name="revs-ordering"
               id="revs-ordering-dfs"
               value="dfs"
               onclick="swh.revision.revsOrderingTypeClicked(event)" />
        <label class="form-check-label font-weight-normal" for="revs-ordering-dfs">DFS</label>
      </div>
      <div class="form-check form-check-inline"
           title="post-order, depth-first visit on the revision graph">
        <input class="form-check-input"
               type="radio"
               name="revs-ordering"
               id="revs-ordering-dfs-post"
               value="dfs_post"
               onclick="swh.revision.revsOrderingTypeClicked(event)" />
        <label class="form-check-label font-weight-normal"
               for="revs-ordering-dfs-post">DFS post-ordering</label>
      </div>
      <div class="form-check form-check-inline"
           title="breadth-first visit on the revision graph">
        <input class="form-check-input"
               type="radio"
               name="revs-ordering"
               id="revs-ordering-bfs"
               value="bfs"
               onclick="swh.revision.revsOrderingTypeClicked(event)" />
        <label class="form-check-label font-weight-normal" for="revs-ordering-bfs">BFS</label>
      </div>
    </form>
    <div class="table-responsive mb-3">
      <table class="table swh-table swh-table-striped">
        <thead>
          <tr>
            <th>
              <i class="{{ swh_object_icons.revision }} mdi-fw" aria-hidden="true"></i>Revision
            </th>
            <th>Author</th>
            <th>Date</th>
            <th>Message</th>
            <th>Commit Date</th>
          </tr>
        </thead>
        <tbody>
          {% for rev in revision_log %}
            <tr class="swh-revision-log-entry swh-tr-hover-highlight"
                title="{{ rev.tooltip }}">
              <td class="swh-revision-log-entry-id">
                <a href="{{ rev.url }}">
                  <i class="{{ swh_object_icons|key_value:'revision' }} mdi-fw"
                     aria-hidden="true"></i>{{ rev.id }}
                </a>
              </td>
              <td class="swh-revision-log-entry-author">{{ rev.author }}</td>
              <td class="swh-revision-log-entry-date">{{ rev.date }}</td>
              <td class="swh-log-entry-message swh-table-cell-text-overflow">{{ rev.message }}</td>
              <td class="swh-revision-log-entry-commit-date">{{ rev.commit_date }}</td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
    <script>swh.revision.initRevisionsLog();</script>
  {% endif %}
{% endblock swh-browse-content %}

{% block swh-browse-after-content %}
  {% if not snapshot_context or not snapshot_context.is_empty %}
    <ul class="pagination justify-content-center">
      {% if next_log_url %}
        <li class="page-item">
          <a class="page-link" href="{{ next_log_url }}">
            {% if revs_ordering %}
              Previous
            {% else %}
              Newer
            {% endif %}
          </a>
        </li>
      {% else %}
        <li class="page-item disabled">
          <a class="page-link">
            {% if revs_ordering %}
              Previous
            {% else %}
              Newer
            {% endif %}
          </a>
        </li>
      {% endif %}
      {% if prev_log_url %}
        <li class="page-item">
          <a class="page-link" href="{{ prev_log_url }}">
            {% if revs_ordering %}
              Next
            {% else %}
              Older
            {% endif %}
          </a>
        </li>
      {% else %}
        <li class="page-item disabled">
          <a class="page-link">
            {% if revs_ordering %}
              Next
            {% else %}
              Older
            {% endif %}
          </a>
        </li>
      {% endif %}
    </ul>
  {% endif %}
{% endblock swh-browse-after-content %}
