{% comment %}
Copyright (C) 2015-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 js_reverse %}
{% load static %}
{% load render_bundle from webpack_loader %}
{% load swh_templatetags %}

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport"
          content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>
      {% block title %}
        {% block page_title %}
        {% endblock page_title %}

        &ndash;
        {% if not SWH_MIRROR_CONFIG %}
          Software Heritage archive
        {% else %}
          {{ SWH_MIRROR_CONFIG.partner_name }} Mirror of the Software Heritage archive
        {% endif %}
      {% endblock title %}

    </title>
    {% render_bundle 'vendors' %}
    {% render_bundle 'webapp' %}
    {% render_bundle 'guided_tour' %}
    <script>
/*
@licstart  The following is the entire license notice for the JavaScript code in this page.

Copyright (C) 2015-2024  The Software Heritage developers

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses />.

@licend  The above is the entire license notice for the JavaScript code in this page.
*/
    </script>
    <script>
      SWH_CONFIG = {{swh_client_config|jsonify}};
      swh.webapp.sentryInit(SWH_CONFIG.sentry_dsn);
    </script>
    <script src="{% url 'js-reverse' %}" type="text/javascript"></script>
    <script>swh.webapp.setSwhObjectIcons({{ swh_object_icons|jsonify }});</script>
    {{ request.user.is_authenticated|json_script:"swh_user_logged_in" }}
    {{ request.user.is_staff|json_script:"swh_user_is_staff" }}
    {{ SWH_MIRROR_CONFIG|json_script:"swh_mirror_config" }}
    {% include "includes/favicon.html" %}
    {% block header %}
    {% endblock header %}

    {% if "url" in matomo and "site_id" in matomo %}
      <!-- Matomo -->
      <script type="text/javascript">
        var _paq = window._paq = window._paq || [];
        _paq.push(['trackPageView']);
        (function() {
          var u='{{ matomo.url }}';
          _paq.push(['setTrackerUrl', u+'matomo.php']);
          _paq.push(['setSiteId', '{{ matomo.site_id }}']);
          var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
          g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
        })();
      </script>
      <!-- End Matomo Code -->
    {% endif %}
  </head>
  <body class="hold-transition layout-fixed sidebar-mini {% if sidebar_state == 'collapsed' %}sidebar-collapse{% endif %}">
    <a id="top"></a>
    <div class="wrapper">
      <header class="main-header navbar navbar-expand-lg navbar-light navbar-static-top swh-navbar {% if 'swh.web.banners' in SWH_DJANGO_APPS %}swh-navbar-banner{% endif %}"
              aria-label="Top bar">
        {% include "./includes/top-bar.html" %}
        {% if "swh.web.banners" in SWH_DJANGO_APPS %}
          <div class="swh-banner">{% include "downtime-banner.html" %}</div>
        {% endif %}
        <div class="navbar-header">
          <a class="nav-link swh-push-menu"
             data-widget="pushmenu"
             data-enable-remember="true"
             role="button"
             aria-label="Collapse sidebar"
             aria-expanded="true"
             href="#">
            <i class="mdi mdi-24px mdi-menu mdi-fw" aria-hidden="true"></i>
          </a>
        </div>
        <div class="navbar" style="width: 94%;">
          <div class="swh-navbar-content">
            {% block navbar-content %}
            {% endblock navbar-content %}

            {% if "partner_logo_static_path" in SWH_MIRROR_CONFIG %}
              {% with SWH_MIRROR_CONFIG.partner_logo_static_path as mirror_partner_logo %}
                {% if "partner_url" in SWH_MIRROR_CONFIG %}
                  <a href="{{ SWH_MIRROR_CONFIG.partner_url }}"
                     target="_blank"
                     rel="noopener noreferrer"
                     class="d-none d-lg-block">
                  {% endif %}
                  {% if request.resolver_match.url_name != 'swh-web-homepage' and request.resolver_match.url_name != 'browse-search' %}
                    <img class="swh-mirror-partner-logo"
                         src="{% static mirror_partner_logo %}"
                         alt="swh mirror partner logo" />
                  {% else %}
                    <img class="swh-mirror-partner-logo swh-mirror-partner-logo-no-search"
                         src="{% static mirror_partner_logo %}"
                         alt="swh mirror partner logo" />
                  {% endif %}
                  {% if "partner_url" in SWH_MIRROR_CONFIG %}</a>{% endif %}
              {% endwith %}
            {% endif %}
            {% if request.resolver_match.url_name != 'swh-web-homepage' and request.resolver_match.url_name != 'browse-search' %}
              <form class="form-horizontal d-none d-md-flex input-group swh-search-navbar needs-validation"
                    id="swh-origins-search-top">
                <input class="form-control"
                       placeholder="Enter a SWHID to resolve or keyword(s) to search for in origin URLs"
                       type="text"
                       id="swh-origins-search-top-input"
                       oninput="swh.webapp.validateSWHIDInput(this)"
                       required />
                <div class="input-group-append">
                  <button class="btn btn-primary"
                          type="submit"
                          aria-label="Search software origins">
                    <i class="swh-search-icon mdi mdi-24px mdi-magnify" aria-hidden="true"></i>
                  </button>
                </div>
              </form>
            {% endif %}
          </div>
        </div>
      </header>
    </div>
    <aside class="swh-sidebar main-sidebar {% if 'swh.web.banners' in SWH_DJANGO_APPS %}main-sidebar-banner{% endif %} sidebar-no-expand sidebar-light-primary elevation-4 swh-sidebar-{{ sidebar_state }}"
           aria-label="Sidebar">
      <a href="{% url 'swh-web-homepage' %}" class="brand-link">
        {% if not SWH_MIRROR_CONFIG %}
          <img class="brand-image"
               src="{% static 'img/swh-logo.png' %}"
               alt="swh logo" />
        {% else %}
          <img class="brand-image"
               src="{% static 'img/swh-mirror.png' %}"
               alt="swh logo" />
        {% endif %}
        <div class="brand-text sitename">
          <span class="first-word">Software</span> <span class="second-word">Heritage</span>
        </div>
      </a>
      <div class="swh-words-logo">
        <div class="swh-words-logo-swh">
          <span class="first-word">Software</span>
          <span class="second-word">Heritage</span>
        </div>
        <span class="swh-text-under-logo">
          {% if not SWH_MIRROR_CONFIG %}
            Archive
          {% else %}
            Mirror
          {% endif %}
        </span>
      </div>
      <div class="sidebar">
        <h6 class="nav-header">Features</h6>
        <nav class="mt-2" aria-label="Features">
          <ul class="nav nav-pills nav-sidebar flex-column"
              data-widget="treeview"
              role="menu"
              data-accordion="false">
            <li class="nav-item swh-menu-item swh-search-item"
                title="Search archived software"
                role="menuitem"
                tabindex="0">
              <a href="{% url 'browse-search' %}" class="nav-link swh-search-link">
                <i class="nav-icon mdi mdi-24px mdi-magnify"></i>
                <p>Search</p>
              </a>
            </li>
            {% if "swh.web.vault" in SWH_DJANGO_APPS %}
              <li class="nav-item swh-menu-item swh-vault-item"
                  title="Download archived software from the Vault"
                  role="menuitem">
                <a href="{% url 'vault' %}" class="nav-link swh-vault-link">
                  <i class="nav-icon mdi mdi-24px mdi-download"></i>
                  <p>Downloads</p>
                </a>
              </li>
            {% endif %}
            {% if "swh.web.save_code_now" in SWH_DJANGO_APPS or SWH_MIRROR_CONFIG %}
              <li class="nav-item swh-menu-item swh-origin-save-item"
                  title="Request the saving of a software origin into the archive"
                  role="menuitem">
                {% if "swh.web.save_code_now" in SWH_DJANGO_APPS %}
                  <a class="nav-link swh-origin-save-link" href="{% url 'origin-save' %}">
                    <i class="nav-icon mdi mdi-24px mdi-camera"></i>
                    <p>Save code now</p>
                  </a>
                {% elif SWH_MIRROR_CONFIG %}
                  <a class="nav-link swh-origin-save-link"
                     href="https://archive.softwareheritage.org/save/"
                     target="_blank"
                     rel="noopener noreferrer">
                    <i class="nav-icon mdi mdi-24px mdi-camera"></i>
                    <p>Save code now</p>
                    <i class="nav-icon mdi mdi-open-in-new"></i>
                  </a>
                {% endif %}
              </li>
            {% endif %}
            {% if "swh.web.add_forge_now" in SWH_DJANGO_APPS or SWH_MIRROR_CONFIG %}
              <li class="nav-item swh-menu-item swh-add-forge-now-item"
                  title="Request adding a new forge listing"
                  role="menuitem">
                {% if "swh.web.add_forge_now" in SWH_DJANGO_APPS %}
                  <a href="{% url 'forge-add-create' %}"
                     class="nav-link swh-add-forge-now-link">
                    <i class="nav-icon mdi mdi-24px mdi-anvil"></i>
                    <p>Add forge now</p>
                  </a>
                {% elif SWH_MIRROR_CONFIG %}
                  <a href="https://archive.softwareheritage.org/add-forge/request/create/"
                     class="nav-link swh-add-forge-now-link"
                     target="_blank"
                     rel="noopener noreferrer">
                    <i class="nav-icon mdi mdi-24px mdi-anvil"></i>
                    <p>Add forge now</p>
                    <i class="nav-icon mdi mdi-open-in-new"></i>
                  </a>
                {% endif %}
              </li>
            {% endif %}
            <li class="nav-item swh-menu-item swh-help-item"
                title="How to browse the archive ?"
                role="menuitem">
              <a href="#"
                 class="nav-link swh-help-link"
                 onclick="swh.guided_tour.guidedTourButtonClick(event)">
                <i class="nav-icon mdi mdi-24px mdi-help-circle"></i>
                <p>Help</p>
              </a>
            </li>
          </ul>
        </nav>
        {% if user.is_authenticated %}
          <h6 class="nav-header">Administration</h6>
          <nav class="mt-2" aria-label="Administration">
            <ul class="nav nav-pills nav-sidebar flex-column"
                data-widget="treeview"
                role="menu"
                data-accordion="false">
              {% if "swh.web.admin" in SWH_DJANGO_APPS and user.is_staff %}
                <li class="nav-item swh-admin-menu-item swh-origin-manage-item"
                    title="Users administration"
                    role="menuitem">
                  <a href="{% if oidc_enabled %}{{ keycloak.server_url }}admin/master/console/#/realms/{{ keycloak.realm_name }}/users{% else %}{% url 'admin:index' %}auth/user{% endif %}"
                     class="nav-link swh-admin-manage-link"
                     target="_blank"
                     rel="noopener noreferrer">
                    <i class="nav-icon mdi mdi-24px mdi-account-cog"></i>
                    <p>Users & permissions</p>
                  </a>
                </li>
              {% endif %}
              {% if not SWH_MIRROR_CONFIG %}
                {% if "swh.web.save_code_now" in SWH_DJANGO_APPS and user.is_staff %}
                  <li class="nav-item swh-admin-menu-item swh-origin-save-admin-item"
                      title="Save code now administration"
                      role="menuitem">
                    <a href="{% url 'admin-origin-save-requests' %}"
                       class="nav-link swh-origin-save-admin-link">
                      {% if pending_save_code_now_requests %}
                        <div class="nav-icon mdi-stack">
                          <i class="mdi mdi-24px mdi-camera"></i>
                          <i class="mdi mdi-18px mdi-bell swh-notification-icon"></i>
                        </div>
                      {% else %}
                        <i class="nav-icon mdi mdi-24px mdi-camera"></i>
                      {% endif %}
                      <p>Save code now</p>
                    </a>
                  </li>
                {% endif %}
                {% if "swh.web.add_forge_now" in SWH_DJANGO_APPS %}
                  {% if user.is_staff or ADD_FORGE_MODERATOR_PERMISSION in user.get_all_permissions %}
                    <li class="nav-item swh-admin-menu-item swh-add-forge-now-moderation-item"
                        title="Add forge now moderation"
                        role="menuitem">
                      <a href="{% url 'add-forge-now-requests-moderation' %}"
                         class="nav-link swh-add-forge-now-moderation-link">
                        <i class="nav-icon mdi mdi-24px mdi-anvil"></i>
                        <p>Add forge now</p>
                      </a>
                    </li>
                  {% endif %}
                {% endif %}
                {% if "swh.web.deposit" in SWH_DJANGO_APPS %}
                  {% if user.is_staff or ADMIN_LIST_DEPOSIT_PERMISSION in user.get_all_permissions %}
                    <li class="nav-item swh-admin-menu-item swh-deposit-admin-item"
                        title="Deposit administration"
                        role="menuitem">
                      <a href="{% url 'admin-deposit' %}"
                         class="nav-link swh-deposit-admin-link">
                        <i class="nav-icon mdi mdi-24px mdi-folder-upload"></i>
                        <p>Deposit</p>
                      </a>
                    </li>
                  {% endif %}
                {% endif %}
              {% endif %}
              {% if "swh.web.mailmap" in SWH_DJANGO_APPS and MAILMAP_ADMIN_PERMISSION in user.get_all_permissions %}
                <li class="nav-item swh-admin-menu-item swh-mailmap-admin-item"
                    title="Mailmap administration"
                    role="menuitem">
                  <a href="{% url 'admin-mailmap' %}"
                     class="nav-link swh-mailmap-admin-link">
                    <i class="nav-icon mdi mdi-24px mdi-email"></i>
                    <p>Mailmap</p>
                  </a>
                </li>
              {% endif %}
            </ul>
          </nav>
        {% endif %}
      </div>
    </aside>
    <div class="content-wrapper">
      <main class="content">
        <div class="container" id="swh-web-content">
          {% if show_corner_ribbon %}
            {% if swh_web_staging %}
              <div class="swh-corner-ribbon {% if 'swh.web.banners' in SWH_DJANGO_APPS %}swh-corner-ribbon-banner{% endif %}">
                Staging
                <br />
                v{{ swh_web_version }}
              </div>
            {% elif swh_web_dev %}
              <div class="swh-corner-ribbon {% if 'swh.web.banners' in SWH_DJANGO_APPS %}swh-corner-ribbon-banner{% endif %}">
                Development
                <br />
                v{{ swh_web_version|split:"+"|first }}
              </div>
            {% endif %}
          {% endif %}
          {% block content %}
          {% endblock content %}

        </div>
      </main>
    </div>
    {% include "includes/global-modals.html" %}
    <footer class="footer">
      <div class="container text-center">
        <p>
          {% if not SWH_MIRROR_CONFIG %}
            {% include "./includes/footer.html" %}
          {% else %}
            {% include "mirror-footer.html" %}
          {% endif %}
          <br />
          {% if "production" not in DJANGO_SETTINGS_MODULE %}swh-web v{{ swh_web_version }}{% endif %}
        </p>
      </div>
    </footer>
    <div id="back-to-top">
      <a href="#top">
        <img alt="back to top" src="{% static 'img/arrow-up-small.png' %}" />
      </a>
    </div>
    <script>
      swh.webapp.setContainerFullWidth();
      {% if "server_url" in status and "json_path" in status %}
        var statusServerURL = {{ status.server_url|jsonify }};
        var statusJsonPath = {{ status.json_path|jsonify }};
        swh.webapp.initStatusWidget(statusServerURL + statusJsonPath);
      {% endif %}
    </script>
  </body>
</html>
