{% extends "rq_dashboard/base.html" %}

{% block content %}
<!--<div class="row" id="rq-instances-row" style="display: none">-->
<!--    <div class="span12">-->
<!--        <div class="section">-->
<!--            <h1>RQ Instances</h1>-->
<!--            <p class="intro">Select below the RRQ instance that you want to observe.</p>-->
<!--            <select id="rq-instances">-->
<!--            </select>-->
<!--        </div>-->
<!--    </div>-->
<!--</div>-->
<div class="row">
    <div class="col-sm-4">
        <div class="span6">
            <div class="section">

                <h2>Queues <a id="queues-btn" href="#">(toggle)</a></h2>
                <p class="fixed intro">This list below contains all the registered queues with the number of jobs currently
                    in the queue. Select a queue from above to view all jobs currently pending on the queue.</p>

                <table id="queues" class="table table-bordered">
                    <thead>
                    <tr>
                        <th>Queue</th>
                        <th class="narrow">Jobs</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr data-role="loading-placeholder">
                        <td colspan="2">Loading...</td>
                    </tr>
                    </tbody>
                </table>

                <script name="queue-row" type="text/template">
                    <tr data-role="queue" <% if (d.name === 'failed' && d.count > 0) { %> class="failed"<% } %>>
                    <td><i class="icon-inbox icon-right" style="opacity: .5;"></i> <a href="<%= d.url %>"><%= d.name %></a></td>
                    <td class="narrow"><%= d.count %></td>
                    </tr>
                </script>

                <script name="no-queues-row" type="text/template">
                    <tr>
                        <td colspan="3">No queues.</td>
                    </tr>
                </script>

            </div>
        </div>
        <div class="span6">
            <div class="section">

                <h2>Workers <a id="workers-btn" href="#">(toggle)</a></h2>

                <p id="workers-count" class="fixed intro">No workers registered!</p>

                <table id="workers" class="table table-bordered" style="display: none;">
                    <thead>
                    <tr>
                        <th style="width:48px">State</th>
                        <th>Worker</th>
                        <th>Queues</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr data-role="loading-placeholder">
                        <td colspan="3">Loading...</td>
                    </tr>
                    </tbody>
                </table>

                <script name="worker-row" type="text/template">
                    <tr data-role="worker">
                        <td><i class="icon-<%= d.state %> icon-right" title="Job ID: <%= d.current_job.job_id %>&#013;&#010;Description: <% if (d.current_job.description){ %> <%- d.current_job.description %> <% } %>&#013;&#010;Created at: <%= d.current_job.created_at %>&#013;&#010;"></i></td>
                        <td <% if (d.version && d.python_version) { %>title ="RQ <%= d.version %> / Python <%= d.python_version %>" <% } %>><%= d.name %></td>
                        <td><%= d.queues.join(', ') %></td>
                    </tr>
                </script>

                <script name="no-workers-row" type="text/template">
                    <tr>
                        <td colspan="3">No workers.</td>
                    </tr>
                </script>

            </div>
        </div>
    </div>
    <div class="col-sm-4">
        <div class="span12">
            <div class="section">

                <h2>Jobs on <strong{% if queue.name == 'failed' %} class="failed"{% endif %}>{{ queue.name }}</strong></h2>
                <p class="intro">
                    {% if queue.name != 'failed' %}
                    <a href="{{ url_for('rq_dashboard.empty_queue', queue_name=queue.name) }}" id="empty-btn"
                       class="btn btn-danger btn-small" style="float: right" data-toggle="tooltip"
                       title="Remove all jobs from this queue (<b>destructive</b>)" data-html=true><i
                            class="icon-trash icon-white icon-right"></i> Empty</a>
                    <a href="{{ url_for('rq_dashboard.compact_queue', queue_name=queue.name) }}" id="compact-btn"
                       class="btn btn-small" style="float: right; margin-right: 8px;" data-toggle="tooltip"
                       title="Remove all stale jobs from this queue (non-destructive)"><i class="icon-resize-small icon-right"></i>
                        Compact</a>
                    {% else %}
                    <a href="{{ url_for('rq_dashboard.requeue_all') }}" id="requeue-all-btn" class="btn btn-small"
                       style="float: right; margin-right: 8px;"><i class="icon-retweet icon-right"></i> Requeue All</a>
                    This list below contains all the registered jobs on queue <strong>{{ queue.name }}</strong>, sorted by
                    age (oldest on top).</p>
                    {% endif %}

                <table id="jobs" class="table table-bordered">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Age</th>
                        <th class="narrow">Actions</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr data-role="loading-placeholder">
                        <td colspan="2">Loading...</td>
                    </tr>
                    </tbody>
                </table>

                <script name="job-row" type="text/template">
                    <tr data-role="job" data-job-id="<%= d.id %>">
                        <td>
                            <i class="icon-file icon-right" style="opacity: .5;"></i>
                            <span class="description"><%= $('<div/>').text(d.description).html() %></span>
                            <% if (d.exc_info) { %>
                            <span class="origin">from <strong><%= d.origin %></strong></span>
                            <% } %>
                            <div class="job_id"><%= d.id %></div>
                            <% if (d.exc_info) { %>
                            <span class="end_date">Failed <%= d.ended_at %></span>
                            <pre class="exc_info"><%= $('<div/>').text(d.exc_info).html() %></pre>
                            <% } %>
                        </td>
                        <td><span class="creation_date"><%= d.created_at %></span></td>
                        <td class="actions narrow">
                            <% if (d.exc_info) { %>
                            <a href="#" data-role="requeue-job-btn" class="btn btn-small"><i class="icon-retweet icon-right"></i>
                                Requeue</a>
                            <% } %>
                            <a href="#" data-role="cancel-job-btn" class="btn btn-small"><i class="icon-remove icon-right"></i> Cancel</a>
                        </td>
                    </tr>
                </script>

                <script name="no-jobs-row" type="text/template">
                    <tr>
                        <td colspan="3">No jobs.</td>
                    </tr>
                </script>

                <div id="page-selection" class="pagination pagination-centered">
                    <ul>
                    </ul>
                </div>

                <script name="first-page-link" type="text/template">
                    <li><a href="<%= url %>">&laquo;</a></li>
                </script>

                <script name="no-previous-page-link" type="text/template">
                    <li class="disabled"><a href="#">&lsaquo;</a></li>
                </script>

                <script name="previous-page-link" type="text/template">
                    <li><a href="<%= url %>">&lsaquo;</a></li>
                </script>

                <script name="page-link" type="text/template">
                    <li><a href="<%= url %>"><%= number %></a></li>
                </script>

                <script name="next-page-link" type="text/template">
                    <li><a href="<%= url %>">&rsaquo;</a></li>
                </script>

                <script name="no-next-page-link" type="text/template">
                    <li class="disabled"><a href="#">&rsaquo;</a></li>
                </script>

                <script name="last-page-link" type="text/template">
                    <li><a href="<%= url %>">&raquo;</a></li>
                </script>

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


{% endblock %}

{% block footer %}

<!--<footer>-->
<!--    <a href="https://github.com/Parallels/rq-dashboard">RQ-dashboard</a><span class="text-white"> version: {{ rq_dashboard_version }}</span><br>-->
<!--    <a href="http://python-rq.org">Python RQ</a><span class="text-white"> version: {{ rq_version }}</span>-->
<!--</footer>-->

{% endblock %}


{% block inline_js %}
var POLL_INTERVAL = {{ poll_interval }};
{% include "rq_dashboard/dashboard.js" with context %}
{% endblock %}
