{% extends "app.html" %}
{% comment %}
# SPDX-License-Identifier: AGPL-3.0-or-later
{% endcomment %}

{% load bootstrap %}
{% load i18n %}
{% load plinth_extras %}
{% load static %}

{% block page_head %}
  <style type="text/css">
    .progress {
        margin-bottom: 0;
    }
  </style>
{% endblock %}


{% block configuration %}
  {{ block.super }}

  {% if is_enabled %}
    <h3>{% trans "Shares" %}</h3>
    <p>
    {% blocktrans trimmed %}
      Note: Only specially created directories will be shared on selected disks,
      not the whole disk.
    {% endblocktrans %}
    </p>
      <table class="table table-bordered table-condensed table-striped">
      <thead>
        <tr>
          <th>{% trans "Disk Name" %}</th>
          <th>{% trans "Shares" %}</th>
          <th>{% trans "Used" %}</th>
        </tr>
      </thead>
      <tbody>
        {% for disk in disks %}
        <tr>
          <td>{{ disk.name|default_if_none:"" }}</td>
          <td>
            <form class="form shareform" method="post"
                  action="{% url 'samba:share' disk.mount_point|urlencode:'' %}">
            {% csrf_token %}
            <input type="hidden" name="filesystem_type" value="{{ disk.filesystem_type }}">

            {% for share_type in share_types %}
              <button type="submit"
                {% if share_type.0 in shared_mounts|lookup:disk.mount_point %}
                  class="btn btn-success" name="{{ share_type.0 }}_share" value="disable"
                {% else %}
                  class="btn btn-default" name="{{ share_type.0 }}_share" value="enable"
                {% endif %}
                {% if disk.filesystem_type == 'vfat' %}
                  title='{% trans "VFAT partitions are not supported" %}' disabled
                {% endif %}>{{ share_type.1 }}
              </button>
            {% endfor %}
            </form>
          </td>
          <td >
            <div class="progress">
              {% if disk.percent_used < 75 %}
                <div class="progress-bar progress-bar-striped progress-bar-success"
              {% elif disk.percent_used < 90 %}
                <div class="progress-bar progress-bar-striped progress-bar-warning"
              {% else %}
                <div class="progress-bar progress-bar-striped progress-bar-danger"
              {% endif %}
                     role="progressbar" aria-valuenow="{{ disk.percent_used }}"
                     aria-valuemin="0" aria-valuemax="100"
                     style="width: {{ disk.percent_used }}%;">
                  {{ disk.percent_used }}%
                </div>
            </div>
            <div>{{ disk.used_str }} / {{ disk.size_str }}</div>
          </td>
        </tr>
        {% endfor %}
      </tbody>
      </table>

      <p>
      {% url 'storage:index' as storage_url %}
      {% url 'users:index' as users_url %}
      {% blocktrans trimmed %}
        You can find additional information about disks on the
        <a href="{{ storage_url }}">storage</a> module page and configure
        access to the shares on the <a href="{{ users_url }}">users</a> module page.
      {% endblocktrans %}</p>

      <p>{% trans "Users who can currently access group and home shares" %}:
        {{ users.access_ok|join:", " }}</p>

      {% if users.password_re_enter_needed %}
        <p>{% trans "Users needing to re-enter their password on the password change page to access group and home shares" %}:
          <strong>{{ users.password_re_enter_needed|join:", " }}</strong>.</p>
      {% endif %}

    {% if unavailable_shares %}
      <h3>{% trans "Unavailable Shares" %}</h3>
      <p>
      {% blocktrans trimmed %}
        Shares that are configured but the disk is not available. If the disk
        is plugged back in, sharing will be automatically enabled.
      {% endblocktrans %}
      </p>
      <table class="table table-bordered table-condensed table-striped">
        <thead>
          <tr>
            <th>{% trans "Share name" %}</th>
            <th>{% trans "Action" %}</th>
          </tr>
        </thead>
        <tbody>
        {% for share in unavailable_shares %}
          <tr>
            <td>{{ share.name }}</td>
            <td>
              <form class="form" method="post"
                    action="{% url 'samba:share' share.mount_point|urlencode:'' %}">
                {% csrf_token %}
                <button type="submit" class="btn btn-danger"
                        name="{{ share.share_type }}_share"
                        value="disable">{% trans "Delete" %}
                </button>
              </form>
            </td>
          </tr>
        {% endfor %}
        </tbody>
      </table>
    {% endif %}
  {% endif %}
{% endblock %}

