{% load i18n %}

<div class="panel panel-primary">
  <div class="panel-heading">Exporters</div>
  <table class="table">
    <tr>
      <th>Job</th>
      <th>Port</th>
      <th>Path</th>
      <th colspan="4">Actions</th>
    </tr>
  {% for exporter in project.exporter_set.all %}
    <tr {% if not exporter.enabled %}class="promgen-disabled"{% endif %}>
      <td>{{ exporter.job }}</td>
      <td>{{ exporter.scheme }}:{{ exporter.port }}</td>
      <td>{{ exporter.path | default:"/metrics" }}</td>
      <td style="white-space: nowrap">
        <input
          type="checkbox"
          {% if exporter.enabled %}checked{% endif %}
          data-size="mini"
          data-toggle="toggle"
          data-csrfmiddlewaretoken="{{csrf_token}}"
          data-action="{% url 'exporter-toggle' exporter.id %}"
        />
      </td>
      <td>
        <form id="{{exporter.job}}_{{exporter.port}}">
          {% csrf_token %}
          <input type="hidden" name="job" value="{{ exporter.job }}" />
          <input type="hidden" name="scheme" value="{{ exporter.scheme }}" />
          <input type="hidden" name="port" value="{{ exporter.port }}" />
          <input type="hidden" name="path" value="{{ exporter.path }}" />
          <exporter-test class="btn btn-info btn-xs" href="{% url 'exporter-scrape' project.id %}">
            {% trans "Test" %}
          </exporter-test>
        </form>
      </td>
      <td>
        <a
          @click="setSilenceDataset"
          class="btn btn-warning btn-xs"
          data-job="{{exporter.job}}"
          data-project="{{project.name}}"
          data-service="{{project.service.name}}"
          style="display: inline-block;"
        >{% trans "Silence" %}</a>
      </td>
      <td>
        <form method="post" action="{% url 'exporter-delete' exporter.id %}" onsubmit="return confirm('{% trans 'Delete this exporter?' %}')" style="display: inline">
          {% csrf_token %}
          <button class="btn btn-danger btn-xs">{% trans "Delete" %}</button>
        </form>
      </td>
    </tr>
  {% endfor %}
  </table>
  <div class="panel-footer">
    <a href="{% url 'project-exporter' project.id %}" class="btn btn-primary">{% trans "Register Exporter" %}</a>
  </div>
</div>

<div>
  <exporter-result />
</div>
