{% extends "suite-base.html" %}
{% block title_name %}cycles list{% endblock %}
{% block auto_refresh %}<meta http-equiv="refresh" content="120">{% endblock %}
{% block content %}
<div class="page-header">
  <div class="panel-group" id="accordion-0">
    <div class="panel panel-default">
      <div class="panel-heading">
        <a class="accordion-toggle" data-toggle="collapse"
        data-parent="#accordion-0" href="#filter">
          <i class="glyphicon glyphicon-wrench"></i>
          Display Options
        </a>
      </div>
      <div id="filter"
      class="panel-collapse collapse{% if not is_option_on %} in{% endif %}">
        <div class="panel-body">
          <form action="{{script}}/{{method}}">
            <input type="hidden" name="user" value="{{user}}" />
            <input type="hidden" name="suite" value="{{suite|replace("/", "%2F")}}" />
            <input type="hidden" name="no_fuzzy_time" value="{{no_fuzzy_time}}" />

            <div class="row">
              <div class="form-group col-sm-12 col-md-6 col-lg-4">
                <div class="input-group">
                  <label for="per_page">Entries/Page (Default=100)</label>
                  <input id="per_page" type="text" name="per_page"
                  title="Entries/Page, 0=unlimited" class="form-control"
                  placeholder="Entries/Page (Default={{per_page_default}})"
                  {% if per_page is defined and per_page != per_page_default -%}
                  value="{{per_page}}"
                  {% endif -%}
                  />
                </div>
              </div>

              <div class="form-group col-sm-12 col-md-6 col-lg-4">
                <div class="input-group">
                  <label for="order">Sort Order</label>
                  <select name="order" title="Sort Order" class="form-control">
                  {% for k, v in [("time_desc", "new-&gt;old"),
                                  ("time_asc", "old-&gt;new")] -%}
                    <option
                    {% if order and order == k -%}selected="selected"{% endif -%}
                    value="{{k}}">{{v}}</option>
                  {% endfor -%}
                  </select>
                </div>
              </div>

              <div class="form-group col-sm-12 col-md-12 col-lg-4">
                <div class="btn-group pull-right">
                  <input type="reset" class="btn btn-default" value="reset"
                  title="Reset Display Options"/>
                  <input type="submit" class="btn btn-primary" value="update"
                  title="Update Display Options"/>
                </div>
              </div>

            </div>

          </form>
        </div>
      </div>
    </div>
  </div>
</div>

{% include "pager.html" -%}

<div class="container-fluid">
  <div class="row">
    <div class="col-md-11">
      {% include "suite-state.html" -%}
    </div>
    <div class="col-md-1 text-right">
      <a id="toggle-fuzzy-time" data-no-fuzzy-time="{{no_fuzzy_time}}" href="#">
        <small>toggle &Delta;t</small>
      </a>
    </div>
  </div>
</div>

<table summary="cycles entries"
class="table table-bordered table-condensed table-striped">
  <thead>
    <tr>
      <th>cycle point</th>

      <th>last active time</th>

      <th>
        <span class="pull-right"># tasks</span>
        <span class="label label-info">
          <i class="glyphicon glyphicon-play" title="# active tasks"></i>
        </span>
      </th>

      <th>
        <span class="pull-right"># jobs</span>
        <span class="label label-info">
          <i class="glyphicon glyphicon-play-circle" title="# active jobs"></i>
        </span>
      </th>

      <th>
        <span class="pull-right"># tasks</span>
        <span class="label label-success">
          <i class="glyphicon glyphicon-ok" title="# succeeded tasks"></i>
        </span>
      </th>

      <th>
        <span class="pull-right"># jobs</span>
        <span class="label label-success">
          <i class="glyphicon glyphicon-ok-circle" title="# succeeded jobs"></i>
        </span>
      </th>

      <th>
        <span class="pull-right"># tasks</span>
        <span class="label label-danger">
          <i class="glyphicon glyphicon-remove" title="# failed tasks"></i>
        </span>
      </th>

      <th>
        <span class="pull-right"># jobs</span>
        <span class="label label-danger">
          <i class="glyphicon glyphicon-remove-circle"
          title="# failed jobs"></i>
        </span>
      </th>

      <th><i class="glyphicon glyphicon-download"
      title="download job logs archive"></i> log/job-CYCLE.tar.gz</th>
    </tr>
  </thead>
  <tbody>
{% for entry in entries -%}
  {% set cycle_in_url = entry.cycle|replace('+', '%2B') -%}
  {% set task_jobs_url = (
      script ~ "/taskjobs/" ~ user ~ "?&amp;suite=" ~
      suite|replace('+', '%2F') ~ "&amp;cycles=" ~ cycle_in_url
  ) -%}
    <tr class="entry">

      <td>
        <small>
          <a href="{{task_jobs_url}}"
          class="cycle" title="{{entry.cycle}}">{{entry.cycle}}</a>
        </small>
      </td>

      <td>
        <small>
          <abbr class="livestamp"
          title="{{entry.max_time_updated}}">{{entry.max_time_updated}}</abbr>
        </small>
      </td>

  {# task and jobs states -#}
  {% for state, icon, label, title_, unit1, unit2, url_arg in [
      ("active", "play", "info", "active", "task", "tasks",
       "&amp;task_status=" ~
       task_status_groups["active"]|join("&amp;task_status=")),
      ("job_active", "play-circle", "info", "active", "job", "jobs",
       "&amp;job_status=submitted,running"),
      ("success", "ok", "success", "succeeded", "task", "tasks",
       "&amp;task_status=" ~
       task_status_groups["success"]|join("&amp;task_status=")),
      ("job_success", "ok-circle", "success", "succeeded", "job", "jobs",
       "&amp;job_status=succeeded"),
      ("fail", "remove", "danger", "failed", "task", "tasks",
       "&amp;task_status=" ~
       task_status_groups["fail"]|join("&amp;task_status=")),
      ("job_fail", "remove-circle", "danger", "failed", "job", "jobs",
       "&amp;job_status=submission-failed,failed"),
  ] -%}
    {% set n_state = entry.n_states[state] -%}
    {% set unit = unit1 -%}
    {% if n_state -%}
      {% set more_label = "label-" ~ label -%}
      {% if n_state > 1 -%}
        {% set unit = unit2 -%}
      {% endif -%}
    {% else -%}
      {% set more_label = "label-default" -%}
    {% endif -%}

    {% if n_state -%}
    <td class="{{label}}">
      <a href="{{task_jobs_url}}{{url_arg}}">
        <span class="label {{more_label}}">
          <i class="glyphicon glyphicon-{{icon}}"></i>
        </span>
        <small class="pull-right">{{n_state}}</small>
      </a>
    </td>
    {% else -%}
    <td><small class="pull-right">{{n_state}}</small></td>
    {% endif -%}

  {% endfor -%}{# end task and jobs states -#}

    <td>
  {% if entry.has_log_job_tar_gz -%}
    {% set download = (
        script ~ "/view/" ~ user ~ "?&amp;suite=" ~ suite|replace('+', '%2F') ~
        "&amp;path=log/job-" ~ cycle_in_url ~ ".tar.gz&amp;mode=download"
    ) -%}
      <a href="{{download}}"
      download="{{user}}-{{suite|replace("/", "%2F")}}-log-job-{{entry.cycle}}.tar.gz">
        <i class="glyphicon glyphicon-download"
        title="download log/job-{{entry.cycle}}.tar.gz"></i>
        <small>
          log/job-{{entry.cycle}}.tar.gz
        </small>
      </a>
  {% endif -%}
    </td>

    </tr><!-- end table row for entry -->
{% endfor -%}{# end for entry in entries -#}
  </tbody><!-- end cycles entries -->
</table>
{% endblock %}
