{% extends "base.html" %}

{% block title %}FireWorks Dashboard{% endblock %}

{% block content %}

{% with messages = get_flashed_messages() %}
  {% if messages %}
    <div class="flashes">
    {% for message in messages %}
      <p style="color:#FF0000"> Warning: {{ message }}</p>
    {% endfor %}
    </div>
  {% endif %}
{% endwith %}

 <div class="row">
    <div class="span12">
        <h3 class="text-center">Workflow Dashboard</h3>
    </div>
 </div>

<div class="row pull-down">
    <div class="span6">
        <table class="table table-bordered">
            <tr><th colspan="3"><a href="/wf">Newest Workflows</a></th></tr>
            {% for wf in wf_info %}
                <tr>
                    <td>
                        <div class="row pull-down-sm">
                            <div class="span2">
                                <a href="/wf/{{ wf.id }}"><strong>{{ wf.name }}</strong></a>
                            </div>
                            <div class="span3">
                                <span class="label {{wf.state}}">{{wf.state}}</span>
                                <span class="pull-right">
                                    ID: <a href="/wf/{{ wf.id }}">{{ wf.id }}</a>
                                </span>
                            </div>

                        </div>
                        <hr>
                        <div class="pull-up">
                            {% for fw  in wf.fireworks %}
                            <div>
                                <small><a class="fw-link {{fw.state}}" href="/fw/{{ fw.fw_id }}">{{fw.name}}</a></small>
                            </div>
                            {% endfor %}
                        </div>
                    </td>

                </tr>
            {% endfor %}
        </table>
    </div>
    <div class="span6">
        <table class="table table-bordered">
            <tr><th colspan="3">Current Database Status</th></tr>
            <tr>
                <th></th>
                <th><a href="/fw">Fireworks</a></th>
                <th><a href="/wf">Workflows</a></th>
            </tr>
            {% for state, fw_num, wf_num in state_nums %}
                <tr>
                    <td>
                        <span class="label {{state}}">
                            {{ state }}
                        </span>
                    </td>
                    <td><center><a href="/fw/{{ state }}">{{ '{:,}'.format(fw_num) }}</a></center></td>
                    <td><center><a href="/wf/{{ state }}">{{ '{:,}'.format(wf_num) }}</a></center></td>
                </tr>
            {% endfor %}
            <tr>
                <th><div align="right">TOTAL</div></th>
                <td><center><a href="/fw">{{ '{:,}'.format(tot_fws) }}</a></center></td>
                <td><center><a href="/wf">{{ '{:,}'.format(tot_wfs) }}</a></center></td>
            </tr>
        </table>

        <hr />
        <h3>Summary Reports</h3>
        <p>Get a report of all jobs for the past:</p>
        <ul>
            <li><a href="/report/minutes/30">30 minutes</a></li>
            <li><a href="/report/hours/24">24 hours</a></li>
            <li><a href="/report/days/7">7 days</a></li>
            <li><a href="/report/days/30">30 days</a></li>
            <li><a href="/report/months/6">6 months</a></li>
            <li><a href="/report/months/24">24 months</a></li>
            <li><a href="/report/years/10">10 years</a></li>
        </ul>
        <p>For more reporting options, use the "lpad report --help" command line tool.</p>

        <h3>MongoDB Query:</h3>
        <form class="query">
          <label>FW Query:</label>
          <input name="fw_query" value="{{ fw_querystr }}"
                 placeholder='{"spec.somevar": "someval"}'/>
          <br>
          <label>WF Query:</label>
          <input name="wf_query" value="{{ wf_querystr }}"
                 placeholder='{"metadata.somevar": "someval"}'/>
          <br>
          <button type="submit" class="btn btn-small btn-success">
            Submit</button>
        </form>


    </div>
</div>


{% endblock %}
