{% extends "base.html" %}
{% load i18n risk_extras %}
{% block crumbs %}
  <li><a href="{% url 'risks:list_risks' %}">{% trans "Risk analysis" %}</a></li>
  <li><a href="{% url 'admin:risks_risk_add' %}"><span class="icon breadcrumb-add-icon"><i class="fas fa-add"></i></span></a></li>
{% endblock %}
{% block content %}

<!-- Filter Section -->
<section class="section has-background-light py-2">
  <form method="get" class="mb-4">
    <div class="columns is-multiline is-vcentered">

      <!-- Filter: Risk -->
      <div class="column is-2">
        <label class="label is-small">{% trans "Risks" %}</label>
        <div class="select is-small is-fullwidth">
          <select name="risk" onchange="this.form.submit()">
            <option value="">{% trans "All" %}</option>
            {% for r in risk_choices %}
              <option value="{{ r.id }}" {% if request.GET.risk == r.id|stringformat:"s" %}selected{% endif %}>
                {{ r.title }}
              </option>
            {% endfor %}
          </select>
        </div>
      </div><!-- Filter: Risk End -->

      <!-- Filter: Asset -->
      <div class="column is-2">
        <label class="label is-small">{% trans "Assets" %}</label>
        <div class="select is-small is-fullwidth">
          <select name="asset" onchange="this.form.submit()">
            <option value="">{% trans "All" %}</option>
            {% for a in asset_choices %}
              <option value="{{ a }}" {% if request.GET.asset == a|stringformat:"s" %}selected{% endif %}>
                {{ a }}
              </option>
            {% endfor %}
          </select>
        </div>
      </div><!-- Filter: Asset End -->

      <!-- Filter: Category -->
      <div class="column is-2">
        <label class="label is-small">{% trans "Categories" %}</label>
        <div class="select is-small is-fullwidth">
          <select name="category" onchange="this.form.submit()">
            <option value="">{% trans "All" %}</option>
            {% for cat in category_choices %}
              <option value="{{ cat }}" {% if request.GET.category == cat|stringformat:"s" %}selected{% endif %}>
                {{ cat }}
              </option>
            {% endfor %}
          </select>
        </div>
      </div><!-- Filter: Category End -->

      <!-- Filter: Process -->
      <div class="column is-2">
        <label class="label is-small">{% trans "Processes" %}</label>
        <div class="select is-small is-fullwidth">
          <select name="process" onchange="this.form.submit()">
            <option value="">{% trans "All" %}</option>
            {% for p in process_choices %}
              <option value="{{ p }}" {% if request.GET.process == p|stringformat:"s" %}selected{% endif %}>
                {{ p }}
              </option>
            {% endfor %}
          </select>
        </div>
      </div><!-- Filter: Process End -->

      <!-- Filter: Owner -->
      <div class="column is-2">
        <label class="label is-small">{% trans "Owners" %}</label>
        <div class="select is-small is-fullwidth">
          <select name="owner" onchange="this.form.submit()">
            <option value="">{% trans "All" %}</option>
            {% for u in owner_choices %}
              <option value="{{ u.id }}" {% if request.GET.owner == u.id|stringformat:"s" %}selected{% endif %}>
                {{ u.get_full_name|default:u.username }}
              </option>
            {% endfor %}
          </select>
        </div>
      </div><!-- Filter: Owner End -->

      <!-- Filter: Reset -->
      <div class="column is-2">
        <label class="label is-small">&nbsp;</label>
        <div class="control">
          <a href="{% url 'risks:list_risks' %}" class="button is-small is-light is-fullwidth">
            <span class="icon"><i class="fas fa-undo"></i></span>
            <span>{% trans "Reset filters" %}</span>
          </a>
        </div>
      </div><!-- Filter: Reset End -->

    </div>
  </form>
</section><!-- Filter Section End -->

<!-- Risk Table -->
<div class="table-container">
  <table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
    <thead>
      <tr class="has-background-prosoft">
        <th class="has-text-centered">
          <a href="{% sort_url request 'id' current_sort current_dir %}">{% trans "No." %}</a>
        </th>
        <th class="has-text-centered"><abbr title="{% trans 'Confidentiality' %}">C</abbr></th>
        <th class="has-text-centered"><abbr title="{% trans 'Integrity' %}">I</abbr></th>
        <th class="has-text-centered"><abbr title="{% trans 'Availability' %}">A</abbr></th>
        <th class="has-text-centered">
          <a href="{% sort_url request 'title' current_sort current_dir %}">{% trans "Risk" %}</a>
        </th>
        <th class="has-text-centered">
          <a href="{% sort_url request 'asset' current_sort current_dir %}">{% trans "Asset" %}</a>
        </th>
        <th class="has-text-centered">
          <a href="{% sort_url request 'category' current_sort current_dir %}">{% trans "Category" %}</a>
        </th>
        <th class="has-text-centered">
          <a href="{% sort_url request 'process' current_sort current_dir %}">{% trans "Process" %}</a>
        </th>
        <th class="has-text-centered">
          <a href="{% sort_url request 'status' current_sort current_dir %}">{% trans "Status" %}</a>
        </th>
        <th class="has-text-centered has-text-prosoft">{% trans "Created" %}</th>
        <th class="has-text-centered has-text-prosoft">{% trans "by" %}</th>
        <th class="has-text-centered has-text-prosoft">{% trans "Changed" %}</th>
        <th class="has-text-centered has-text-prosoft">{% trans "by" %}</th>
      </tr>
    </thead>
    <tbody>
      {% for r in risks %}
      <tr onclick="window.location.href='{% url 'risks:show_risk' r.id %}'" style="cursor:pointer;">
        <td>{{ r.id }}</td>
        <td class="has-text-centered">
          {% if "1" in r.cia %}
            <span class="icon is-small">
              <abbr title="{% trans 'Confidentiality' %}"><i class="fas fa-circle" aria-hidden="true" style="color: grey"></i></abbr>
            </span>
          {% endif %}
        </td>
        <td class="has-text-centered">
          {% if "2" in r.cia %}
            <span class="icon is-small">
              <abbr title="{% trans 'Integrity' %}"><i class="fas fa-circle" aria-hidden="true" style="color: grey"></i></abbr>
            </span>
          {% endif %}
        </td>
        <td class="has-text-centered">
          {% if "3" in r.cia %}
            <span class="icon is-small">
              <abbr title="{% trans 'Availability' %}"><i class="fas fa-circle" aria-hidden="true" style="color: grey"></i></abbr>
            </span>
          {% endif %}
        </td>
        <td>{{ r.title }}</td>
        <td>{{ r.asset }}</td>
        <td>{{ r.category }}</td>
        <td>{{ r.process }}</td>
        <td>
          <div class="tag 
            {% if r.status == 'open' %}
              is-info
            {% elif r.status == 'review_required' %}
              is-warning
            {% elif r.status == 'closed' %}
              is-success
            {% elif r.status == 'in_progress' %}
              is-link is-light
            {% endif %}
          ">
            {{ r.get_status_display }}
          </div> {% if not r.residual_risk %} / <div class="tag is-danger">Kein Restrisiko</div>{% endif %}</td>
        <td>{{ r.created_at|date:"d.m.Y H:i" }}</td>
        <td>{{ r.owner|user_display }}</td>
        <td>{{ r.updated_at|date:"d.m.Y H:i" }}</td>
        <td>{{ r.owner|user_display }}</td>
      </tr>
      {% empty %}
      <tr><td colspan="13" class="has-text-grey has-text-centered">{% trans "No data" %}</td></tr>
      {% endfor %}
    </tbody>
  </table>
</div><!-- Risk Table End -->

{% endblock %}
