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

{% comment %}
Copyright (C) 2022  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 static %}

{% block header %}
{% render_bundle 'add_forge' %}
{% endblock %}

{% block title %}
Add forge now – Software Heritage archive
{% endblock %}

{% block navbar-content %}
<h4>Request the addition of a forge into the archive</h4>
{% endblock %}

{% block content %}
<div class="col-md-12 offset-md-1">
  <div class="col-md-8">
    <h5 class="d-flex justify-content-between align-items-center mb-3">
    </h5>
    <p style="margin-top: 1rem;">
      “Add forge now” provides a service for Software Heritage users to save a
      complete forge in the Software Heritage archive by requesting the addition
      of the forge URL into the list of regularly visited forges.
      {% if not user.is_authenticated %}
      <p>
        You can submit an “Add forge now” request only when you are authenticated,
        please login to submit the request.
      </p>
      {% endif %}
    </p>
  </div>

  <!-- Tabs in the page -->
  <div class="col-md-8">
    <ul class="nav nav-tabs">
      <li class="nav-item"><a class="nav-link active" data-toggle="tab" id="swh-add-forge-tab" href="#swh-add-forge-submit-request">Submit a Request</a></li>
      <li class="nav-item"><a class="nav-link" data-toggle="tab" id="swh-add-forge-requests-list-tab" href="#swh-add-forge-requests-list">Browse Requests</a></li>
    </ul>

    <div class="tab-content">
      <div id="swh-add-forge-submit-request" class="tab-pane active" style="padding-top: 10px;">
        {% if not user.is_authenticated %}
        <h3>
          <p class="text-primary">
            You must be logged in to submit an add forge request. Please
            <a id="loginLink" href="{% url 'login' %}?next={% url 'forge-add' %}" class="link-primary">log in</a>
          </p>
        </h3>
        {% else %}

        <form method="POST" action="{% url 'api-1-add-forge-request-create' %}"
              id="requestCreateForm" class="collapse show">
          {% csrf_token %}
          <div class="form-row">
            <div class="form-group col-md-5">
              <label for="swh-input-forge-type">Forge type</label>
              <select class="form-control" id="swh-input-forge-type" name="forge_type" autofocus>
                {% for forge_type in forge_types %}
                <option value={{ forge_type }}>{{ forge_type}}</option>
                {% endfor %}
              </select>
              <small class="form-text text-muted">
                Supported forge types in software archive.
              </small>
            </div>

            <div class="form-group col-md-7">
              <label for="swh-input-forge-url">Forge URL</label>
              <input type="text" class="form-control" id="swh-input-forge-url" name="forge_url" required>
              <small class="form-text text-muted">
                Remote URL of the forge to list.
              </small>
            </div>
          </div>

          <div class="form-row">
            <div class="form-group col-md-5">
              <label for="swh-input-forge-contact-name">Forge contact name</label>
              <input type="text" class="form-control" name="forge_contact_name" id="swh-input-forge-contact-name" required>
              <small class="form-text text-muted">
                Name of the Forge administrator.
              </small>
            </div>

            <div class="form-group col-md-7">
              <label for="swh-input-forge-contact-email">Forge contact email</label>
              <input type="email" class="form-control" name="forge_contact_email" id="swh-input-forge-contact-email" required>
              <small class="form-text text-muted">
                Email of the forge administrator. The given email address will not be used for any purpose outside the “add forge now” process.
              </small>
            </div>
          </div>

          <div class="form-row">
            <div class="form-group form-check">
              <input class="form-check-input" type="checkbox"
                     id="swh-input-consent-check" name="consent_to_add_name">
              <label for="swh-input-consent-check">
                I consent to add my username in the communication with the forge
              </label>
            </div>
          </div>

          <div class="form-row">
            <div class="form-group col-md-12">
              <label for="swh-input-forge-comment">Comment</label>
              <textarea class="form-control" id="swh-input-forge-comment" name="forge_contact_comment" rows="3"></textarea>
              <small class="form-text text-muted">
                If you wish to leave a comment regarding your request.
              </small>
            </div>
          </div>

          <div class="form-row">
            <div class="col-md-12">
              <input id="swh-input-form-submit" type="submit" value="Submit Add Request" class="btn btn-default float-right">
            </div>
          </div>

          <div class="form-row">
            <div class="col-md-12">
              <h3 class="text-center">
                <span id="userMessage" class="badge"></span>
              </h3>
              <p class="text-center">
                <span id="userMessageDetail"></span>
              </p>
            </div>
          </div>
        </form>
        <div class="panel panel-info">
          <div class="panel-heading">
            <a data-toggle="collapse" href="#swh-forge-add-request-help" role="button" aria-expanded="false" class="text-primary">
              For more information
            </a>
          </div>
          <div id="swh-forge-add-request-help" class="collapse panel-body">
            <p>
              Once submitted, your "add forge" request can either be:
            </p>
            <ul>
              <li>
                <strong>Pending:</strong>
                the request was submitted and is waiting for a moderator
                to check its validity.
              </li>

              <li>
                <strong>Waiting for feedback:</strong>
                the request was processed by a moderator
                and the forge was contacted, the request is waiting for feedback from the
                forge.
              </li>

              <li>
                <strong>Feedback to handle:</strong>
                the forge has responded to the request and
                there is feedback to handle for the request.</li>

              <li>
                <strong>Accepted:</strong>
                the request has been accepted and waiting to be
                scheduled.
              </li>

              <li>
                <strong>Scheduled:</strong>
                the request has been scheduled is considered
                done.
              </li>

              <li>
                <strong>First listing done:</strong>
                The first listing of the forge is
                completed.
              </li>

              <li>
                <strong>First origin loaded:</strong>
                The first origin or repository processed by
                loader and archived (using a search query).
              </li>

              <li><strong>Rejected:</strong> the request is not a valid request and is rejected by a
                Software Heritage moderator.</li>

              <li><strong>Denied:</strong> the forge has requested not to archive the forge.</li>

              <li><strong>Suspended:</strong> the request is for a forge with a non supported
                VCS.</li>
            </ul>
            <p>
              Once a add request has been submitted, you can follow its current status in
              the <a id="swh-show-forge-add-requests-list" href="#browse-requests">
                submitted requests list
              </a>. This process is depending on human interactions and might take a few days to be
              handled (it primarily depends on the response time of the forge).
            </p>
          </div>
        </div>
        {% endif %}
      </div>
      <div id="swh-add-forge-requests-list" class="tab-pane fade show">
        <table id="add-forge-request-browse" class="table swh-table swh-table-striped" style="width: 100%;">
          <thead>
            <tr>
              <th>Submission date</th>
              <th>Forge type</th>
              <th>Forge URL</th>
              <th>Status</th>
            </tr>
          </thead>
        </table>
        <div id="add-forge-browse-request-error"></div>
      </div>
    </div>
  </div>
</div>

<script>
  swh.add_forge.onCreateRequestPageLoad();
</script>

{% endblock %}
