{% extends "layout.html" %}

{% block content %}
<!-- Header container -->
<div class="container-fluid container-pf-nav-pf-vertical container-pf-nav-pf-vertical-with-secondary">
  <div class="row">
    <div class="col-xs-12 col-sm-6 col-md-10 col-md-offset-1">
      <h1><strong>Playbook</strong>: {{ macros.make_link('playbook.show_playbook', playbook.path, playbook=playbook.id) }}</h1>
      <h2>{{ playbook.time_start |datefmt }} <span class="fa fa-angle-double-right"></span> {{ playbook.time_end |datefmt }}</h2>
    </div>
  </div>
</div>
<!-- Dashboard container -->
<div class="container-fluid container-cards-pf container-pf-nav-pf-vertical container-pf-nav-pf-vertical-with-secondary">
  <div class="row row-cards-pf">
    <div class="col-md-2 col-md-offset-1">
      <div class="card-pf card-pf-accented card-pf-aggregate-status card-pf-aggregate-status-mini" style="height: 59px;">
        <h2 class="card-pf-title" style="height: 42px;">
          <a href="#hosts">
          <span class="pficon pficon-server"></span>
          <span class="card-pf-aggregate-status-count">{{ playbook.hosts.count() }}</span> <strong>Hosts</strong>
          </a>
        </h2>
      </div>
    </div>

    <div class="col-md-2">
      <div class="card-pf card-pf-accented card-pf-aggregate-status card-pf-aggregate-status-mini" style="height: 59px;">
        <h2 class="card-pf-title" style="height: 42px;">
          <a href="#plays">
          <span class="pficon pficon-flag"></span>
          <span class="card-pf-aggregate-status-count">{{ playbook.plays.count() }}</span> <strong>Plays</strong>
          </a>
        </h2>
      </div>
    </div>

    <div class="col-md-2">
      <div class="card-pf card-pf-accented card-pf-aggregate-status card-pf-aggregate-status-mini" style="height: 59px;">
        <h2 class="card-pf-title" style="height: 42px;">
          <a href="#files">
          <span class="pficon pficon-folder-open"></span>
          <span class="card-pf-aggregate-status-count">{{ playbook.files.count() }}</span> <strong>Files</strong>
          </a>
        </h2>
      </div>
    </div>

    <div class="col-md-2">
      <div class="card-pf card-pf-accented card-pf-aggregate-status card-pf-aggregate-status-mini" style="height: 59px;">
        <h2 class="card-pf-title" style="height: 42px;">
          <a href="#tasks">
          <span class="fa fa-check"></span>
          <span class="card-pf-aggregate-status-count">{{ playbook.tasks.count() }}</span> <strong>Tasks</strong>
          </a>
        </h2>
      </div>
    </div>

    <div class="col-md-2">
      <div class="card-pf card-pf-accented card-pf-aggregate-status card-pf-aggregate-status-mini" style="height: 59px;">
        <h2 class="card-pf-title" style="height: 42px;">
          <span class="fa fa-clock-o"></span>
          <span class="card-pf-aggregate-status-count">{{ playbook.duration |timefmt }}</span> <strong>Duration</strong>
        </h2>
      </div>
    </div>
  </div>
</div>
<!-- Detail container -->
<div class="container-fluid container-pf-nav-pf-vertical container-pf-nav-pf-vertical-with-secondary">
  <div class="row">
    <div class="col-md-10 col-md-offset-1">
      <a href="#hosts"><h2 id="hosts"><strong>Hosts</strong></h2></a>
      <table class="table table-striped table-bordered table-hover table-condensed">
        <thead>
          <tr>
            <th><span class="pull-left">Host</span></th>
            <th class="col-md-1"><span class="ok label status-label">OK</span></th>
            <th class="col-md-1"><span class="changed label status-label">CHANGED</span></th>
            <th class="col-md-1"><span class="failed label status-label">FAILED</span></th>
            <th class="col-md-1"><span class="skipped label status-label">SKIPPED</span></th>
            <th class="col-md-1"><span class="unreachable label status-label">UNREACHABLE</span></th>
          </tr>
        </thead>
        <tbody>
          {% for stat in playbook.stats %}
          {% if hosts and stat.host.name in hosts %}
          <tr class="active">
          {% else %}
          <tr>
          {% endif %}
            <td>
                {% if stat.host.facts %}
                <a href="{{ url_for('host.show_host', id=stat.host.id) }}">
                <span class="pf pficon-info action-icon action-available pull-left" title="Host facts available"></span>
                </a>
                {% else %}
                <span class="pf pficon-info action-icon action-unavailable pull-left" title="Host facts unavailable"></span>
                {% endif %}
                <span class="pull-left">{{ macros.make_link('playbook.playbook_results', stat.host.name, playbook=playbook.id, host=stat.host.name) }}</span>
            </td>
              {{ macros.statslink(stat, 'ok', playbook, stat.host) }}
              {{ macros.statslink(stat, 'changed', playbook, stat.host) }}
              {{ macros.statslink(stat, 'failed', playbook, stat.host) }}
              {{ macros.statslink(stat, 'skipped', playbook, stat.host) }}
              {{ macros.statslink(stat, 'unreachable', playbook, stat.host) }}
          </tr>
          {% endfor %}
        </tbody>
      </table>

      <a href="#plays"><h2 id="plays"><strong>Plays</strong></h2></a>
      <table class="table table-striped table-bordered table-hover table-condensed">
        <thead>
          <tr>
            <th><span class="pull-left">Play</span></th>
            <th class="date col-md-2">Start</th>
            <th class="date col-md-2">End</th>
            <th class="date col-md-1">Duration</th>
          </tr>
        </thead>

        <tbody>
          {% for play in playbook.plays %}
          {% if plays and play.id in plays %}
          <tr class="active">
          {% else %}
          <tr>
          {% endif %}
            <td><span class="pull-left">{{ macros.make_link('playbook.playbook_results', play.name, playbook=playbook.id, play=play.id) }}</span></td>
            <td class="date">{{ play.time_start |datefmt }}</td>
            <td class="date">{{ play.time_end |datefmt }}</td>
            <td>{{ play.duration |timefmt }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>

      <a href="#files"><h2 id="files"><strong>Files</strong></h2></a>
      <table class="table table-striped table-bordered table-hover table-condensed">
        <thead>
          <tr>
            <th><span class="pull-left">File</span></th>
            <th class="date col-md-1"></th>
            <th class="date col-md-1"></th>
          </tr>
        </thead>

        <tbody>
          <tr>
              <td><span class="pull-left">{{ playbook_file.path |pathtruncate(75) }} <strong>(Playbook)</strong></span></td>
              <td colspan="2">{{ macros.make_link('file.show_file', 'View', file_=playbook_file.id) }}</td>
          </tr>
          {% for file in files %}
          <tr>
            <td><span class="pull-left">{{ file.path |pathtruncate(75) }}</span></td>
            <td>{{ macros.make_link('file.show_file', 'View', file_=file.id) }}</td>
            <td>{{ macros.make_link('playbook.show_playbook', 'Filter', playbook=playbook.id, file_=file.id) }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>

      <a href="#tasks"><h2 id="tasks"><strong>Task Results</strong></h2></a>
      <table class="table table-striped table-bordered table-hover table-condensed">
        <thead>
          <tr>
            <th><span class="pull-left">Task</span></th>
            <th>Host</th>
            <th>Action</th>
            <th class="date col-md-1">Elapsed</th>
            <th class="date col-md-1">Duration</th>
            <th class="col-md-1">Status</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          {% for result in task_results %}
          {% set status = result.derived_status %}
          <tr>
            <td><span class="pull-left">{{ result.task.name }}</span></td>
            <td>{{ result.host.name }}</td>
            <td>{{ result.task.action }}</td>
            <td>{{ result.task.offset_from_playbook|timefmt }}</td>
            <td>{{ result.duration |timefmt }}</td>
            <td><span class="{{ status }} label status-label">{{ status |upper }}</span></td>
            <td>
                {{ macros.make_link('result.show_result', 'details', task_result=result.id) }}
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>

      <h2><strong>Recorded data</strong></h2>
      {% if data %}
      <table class="table table-striped table-bordered table-hover table-condensed">
        <thead>
          <tr>
            <th><span class="pull-right">Key</span></th>
            <th><span class="pull-left">Value</span></th>
          </tr>
        </thead>

        <tbody>
          {% for item in data %}
          <tr>
            <td class="vert-align" id="{{ item.id }}"><span class="pull-right"><a href="#{{ item.id }}">{{ item.key }}</a></span></td>
            <td><span class="pull-left">{{ macros.render_value_type(item.value, item.type) }}</span></td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      {% else %}
      <h3>There is no recorded data for this playbook. Get started with <a href="http://ara.readthedocs.io/en/latest/usage.html#using-the-ara-record-module" target="_blank">ara_record</a>.</h3>
      {% endif %}
    </div>
  </div>
</div>
{% endblock %}