{% extends 'projectroles/base.html' %}

{% load projectroles_common_tags %}

{% block title %}Remote SODAR Sites{% endblock title %}

{% block css %}
  {{ block.super }}
  <style type="text/css">
    @media screen and (max-width: 1200px) {
      .table#sodar-pr-remote-site-table thead tr th:nth-child(3),
      .table#sodar-pr-remote-site-table tbody tr td:nth-child(3),
      .table#sodar-pr-remote-site-table thead tr th:nth-child(5),
      .table#sodar-pr-remote-site-table tbody tr td:nth-child(5) {
        display: none;
      }
    }

    @media screen and (max-width: 900px) {
      .table#sodar-pr-remote-site-table thead tr th:nth-child(2),
      .table#sodar-pr-remote-site-table tbody tr td:nth-child(2) {
        display: none;
      }
    }
  </style>
{% endblock css %}

{% block projectroles %}

{% get_django_setting 'PROJECTROLES_SITE_MODE' as site_mode %}

<div class="row sodar-subtitle-container">
  <h2><i class="iconify" data-icon="mdi:cloud"></i> Remote SODAR Sites</h2>
  {% if site_mode == 'SOURCE' or not sites %}
    <a role="button" class="btn btn-primary ml-auto"
       href="{% url 'projectroles:remote_site_create' %}">
      <i class="iconify" data-icon="mdi:plus-thick"></i>
      Add {% if site_mode == 'TARGET' %}Source{% else %}Target{% endif %} Site
    </a>
  {% endif %}
</div>

<div class="container-fluid sodar-page-container">

  {% if sites.count == 0 %}
    <div class="alert alert-info">
      {% if site_mode == 'SOURCE' %}
        No target sites have been added.
      {% else %}
        A source site has not been set.
      {% endif %}
    </div>

  {% else %}
    <div class="card">
      <div class="card-header">
        <h4>
          {% if site_mode == 'SOURCE' %}
            <i class="iconify" data-icon="mdi:cloud-upload"></i> Target Sites
          {% else %}
            <i class="iconify" data-icon="mdi:cloud-download"></i> Source Site
          {% endif %}
        </h4>
      </div>
      <div class="card-body p-0">
        <table class="table table-striped sodar-card-table"
               id="sodar-pr-remote-site-table">
          <thead>
            <tr>
              <th>Name</th>
              <th>URL</th>
              <th class="text-right">{% get_display_name 'PROJECT' title=True plural=True %}</th>
              <th>Token</th>
              <th>Accessed</th>
              {% if site_mode == 'SOURCE' %}
                <th>Visible</th>
              {% endif %}
              <th></th>
            </tr>
          </thead>
          <tbody>
            {% for site in sites %}
              {% include 'projectroles/_remote_site_list_item.html' %}
            {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
  {% endif %}

  <div class="alert alert-info">
    Your site is in <code>{{ site_mode }}</code> mode.
  </div>

  {% get_django_setting 'PROJECTROLES_ALLOW_LOCAL_USERS' as allow_local_users %}
  {% if site_mode == 'TARGET' and allow_local_users %}
    <div class="alert alert-warning">
      <code>PROJECTROLES_ALLOW_LOCAL_USERS</code> is enabled in site
      configuration. Please note that this will allow synchronizing project
      roles to local non-LDAP users based on the user name. You should
      personally ensure that the users in question are authorized for these
      roles. Furthermore, only roles for existing local users will be
      synchronized. New local users will have to be added manually through the
      Django admin or shell.
    </div>
  {% endif %}

</div>

{% endblock projectroles %}
