{% extends "layout.html" %}

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

{% block header %}
{{ block.super }}
{% render_bundle 'admin' %}
{% render_bundle 'save' %}
{% endblock %}

{% block title %} Save origin administration {% endblock %}

{% block navbar-content %}
<h4>Save origin administration</h4>
{% endblock %}

{% block content %}

<ul class="nav nav-tabs" style="padding-left: 5px;">
  <li class="nav-item"><a class="nav-link active" data-toggle="tab" id="swh-origin-save-requests-nav-item" href="#swh-origin-save-requests">Submitted save origin requests</a></li>
  <li class="nav-item"><a class="nav-link" data-toggle="tab" id="swh-origin-save-url-filters-nav-item" href="#swh-origin-save-url-filters">Origin urls filtering</a></li>
</ul>

<div class="tab-content">

  <div id="swh-origin-save-requests" class="tab-pane active">
    <ul class="nav nav-pills mt-3 mb-3" role="tablist">
      <li class="nav-item">
        <a class="nav-link active" id="swh-save-requests-pending-tab" data-toggle="pill" href="#swh-save-requests-pending" role="tab" aria-controls="swh-save-requests-pending" aria-selected="true">Pending</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" id="swh-save-requests-accepted-tab" data-toggle="pill" href="#swh-save-requests-accepted" role="tab" aria-controls="swh-save-requests-accepted" aria-selected="false">Accepted</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" id="swh-save-requests-rejected-tab" data-toggle="pill" href="#swh-save-requests-rejected" role="tab" aria-controls="swh-save-requests-rejected" aria-selected="false">Rejected</a>
      </li>
    </ul>
    <div class="tab-content">
      <div class="tab-pane fade show active" id="swh-save-requests-pending" role="tabpanel" aria-labelledby="swh-save-requests-pending-tab">
        <table id="swh-origin-save-pending-requests" class="table swh-table swh-table-striped" width="100%">
          <thead>
            <tr>
              <th></th>
              <th data-priority="2">Date</th>
              <th data-priority="3">Type</th>
              <th data-priority="1">Url</th>
            </tr>
          </thead>
        </table>
        <div class="row text-right mt-3">
          <div class="col-md-6">
          </div>
          <div class="col-md-2">
            <button id="swh-accept-save-origin-request" class="btn btn-default swh-action-need-selection" onclick="swh.admin.acceptOriginSaveRequest()" disabled>Accept selected</button>
          </div>
          <div class="col-md-2">
            <button id="swh-reject-save-origin-request" class="btn btn-default swh-action-need-selection" onclick="swh.admin.rejectOriginSaveRequest()" disabled>Reject selected</button>
          </div>
          <div class="col-md-2">
            <button id="swh-remove-save-origin-request" class="btn btn-default swh-action-need-selection" onclick="swh.admin.removePendingOriginSaveRequest()" disabled>Remove selected</button>
          </div>
        </div>
      </div>
      <div class="tab-pane fade" id="swh-save-requests-accepted" role="tabpanel" aria-labelledby="swh-save-requests-accepted-tab">
        <table id="swh-origin-save-accepted-requests" class="table swh-table swh-table-striped" width="100%">
          <thead>
            <tr>
              <th></th>
              <th data-priority="3">Date</th>
              <th data-priority="4">Type</th>
              <th data-priority="1">Url</th>
              <th data-priority="2">Status</th>
              <th data-priority="5">Info</th>
            </tr>
          </thead>
        </table>
        <div class="row text-right mt-3">
          <div class="col-md-10">
          </div>
          <div class="col-md-2">
            <button id="swh-remove-accepted-save-origin-request" class="btn btn-default swh-action-need-selection" onclick="swh.admin.removeAcceptedOriginSaveRequest()" disabled>Remove selected</button>
          </div>
        </div>
      </div>
      <div class="tab-pane fade" id="swh-save-requests-rejected" role="tabpanel" aria-labelledby="swh-save-requests-rejected-tab">
        <table id="swh-origin-save-rejected-requests" class="table swh-table swh-table-striped" width="100%">
          <thead>
            <tr>
              <th></th>
              <th data-priority="2">Date</th>
              <th data-priority="3">Type</th>
              <th data-priority="1">Url</th>
              <th data-priority="4">Info</th>
            </tr>
          </thead>
        </table>
        <div class="row text-right mt-3">
          <div class="col-md-10">
          </div>
          <div class="col-md-2">
            <button id="swh-remove-rejected-save-origin-request" class="btn btn-default swh-action-need-selection" onclick="swh.admin.removeRejectedOriginSaveRequest()" disabled>Remove selected</button>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div id="swh-origin-save-url-filters" class="tab-pane">
    <ul class="nav nav-pills mt-3 mb-3" role="tablist">
      <li class="nav-item">
        <a class="nav-link active" id="swh-authorized-origins-tab" data-toggle="pill" href="#swh-authorized-origins" role="tab" aria-controls="swh-authorized-origins"
          aria-selected="true">Authorized urls</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" id="swh-unauthorized-origins-tab" data-toggle="pill" href="#swh-unauthorized-origins" role="tab" aria-controls="swh-unauthorized-origins"
          aria-selected="false">Unauthorized urls</a>
      </li>
    </ul>

    <div class="tab-content">
      <div class="tab-pane fade show active" id="swh-authorized-origins" role="tabpanel" aria-labelledby="swh-authorized-origins-tab">
        <table id="swh-authorized-origin-urls" class="table swh-table swh-table-striped" width="100%">
          <thead>
            <tr>
              <th>Url</th>
            </tr>
          </thead>
        </table>
        <div class="row text-right mt-3">
          <div class="col-md-10">
            <div class="input-group">
              <input class="form-control" placeholder="Enter authorized origin url prefix to add" type="text" id="swh-authorized-url-prefix"/>
              <div class="input-group-append">
                <button id="swh-add-authorized-origin-url" class="btn btn-default" onclick="swh.admin.addAuthorizedOriginUrl()">Add new</button>
              </div>
            </div>
          </div>
          <div class="col-md-2">
            <button id="swh-remove-authorized-origin-url" class="btn btn-default swh-action-need-selection" onclick="swh.admin.removeAuthorizedOriginUrl()" disabled>Remove selected</button>
          </div>
        </div>
        <div class="row mt-3 swh-add-authorized-origin-status">
        </div>
      </div>

      <div class="tab-pane fade" id="swh-unauthorized-origins" role="tabpanel" aria-labelledby="swh-unauthorized-origins-tab">
        <table id="swh-unauthorized-origin-urls" class="table swh-table swh-table-striped" width="100%">
          <thead>
            <tr>
              <th>Url</th>
            </tr>
          </thead>
        </table>
        <div class="row text-right mt-3">
          <div class="col-md-10">
            <div class="input-group">
              <input class="form-control" placeholder="Enter unauthorized origin url prefix to add" type="text" id="swh-unauthorized-url-prefix"/>
              <div class="input-group-append">
                <button id="swh-add-unauthorized-origin-url" class="btn btn-default" onclick="swh.admin.addUnauthorizedOriginUrl()">Add new</button>
              </div>
            </div>
          </div>
          <div class="col-md-2">
            <button id="swh-remove-unauthorized-origin-url" class="btn btn-default swh-action-need-selection" onclick="swh.admin.removeUnauthorizedOriginUrl()" disabled>Remove selected</button>
          </div>
        </div>
        <div class="row mt-3 swh-add-unauthorized-origin-status">
        </div>
      </div>
    </div>
  </div>
</div>

<script>
  swh.webapp.initPage('origin-save-admin');
  swh.admin.initOriginSaveAdmin();
</script>
{% endblock %}
