<h1>Queues</h1>
<div class="section">
  <h2>All queues</h2>
  <div class="hider">
<%= filter_ui(queues) %>
  <div class="updatable">
<% if (queues.length > 0) { %>
<%
   var col_redeliver = !is_col_empty(queues, 'redeliver');
%>
<table class="list">
 <thead>
  <tr>
    <th colspan="<% if (nodes_interesting && vhosts_interesting) { %>7<% } else if (nodes_interesting || vhosts_interesting) { %>6<% } else { %>5<% } %>">Overview</th>
    <th colspan="3">Messages</th>
<% if (statistics_level == 'fine') { %>
    <th colspan="3">Message rates</th>
<% } %>
  </tr>
  <tr>
<% if (vhosts_interesting) { %>
    <th><%= fmt_sort('Virtual host', 'vhost') %></th>
<% } %>
    <th><%= fmt_sort('Name',         'name') %></th>
<% if (nodes_interesting) { %>
    <th><%= fmt_sort('Node',         'node') %></th>
<% } %>
    <th><%= fmt_sort('Exclusive',    'owner_pid_details.name') %></th>
    <th>Parameters</th>
    <th><%= fmt_sort('Policy',       'policy') %></th>
    <th><%= fmt_sort('Status',       'idle_since') %></th>
    <th><%= fmt_sort('Ready',        'messages_ready') %></th>
    <th><%= fmt_sort('Unacked',      'messages_unacknowledged') %></th>
    <th><%= fmt_sort('Total',        'messages') %></th>
<% if (statistics_level == 'fine') { %>
    <th><%= fmt_sort('incoming', 'message_stats.publish_details.rate') %></th>
    <th><%= fmt_sort('deliver / get', 'message_stats.deliver_get_details.rate') %>
  <% if (col_redeliver) { %>
    <sub><%= fmt_sort('of which redelivered', 'message_stats.redeliver_details.rate') %></sub>
  <% } %>
</th>
    <th><%= fmt_sort('ack', 'message_stats.ack_details.rate') %></th>
<% } %>
  </tr>
 </thead>
 <tbody>
<%
  for (var i = 0; i < queues.length; i++) {
    var queue = queues[i];
%>
  <tr<%= alt_rows(i, queue.arguments) %>>
<% if (vhosts_interesting) { %>
   <td><%= fmt_string(queue.vhost) %></td>
<% } %>
   <td><%= link_queue(queue.vhost, queue.name, queue.arguments) %></td>
<% if (nodes_interesting) { %>
   <td>
     <%= fmt_node(queue.node) %>
     <%= fmt_mirrors(queue) %>
     <% if (queue.status == 'syncing') { %>
       <%= fmt_sync_status(queue) %>
     <% } %>
   </td>
<% } %>
   <td class="c">
     <% if (queue.owner_pid_details != undefined) { %>
     <%= link_conn(queue.owner_pid_details.name, "Owner") %>
     <% } %>
   </td>
   <td class="c"><%= fmt_parameters_short(queue) %></td>
   <td class="c"><%= fmt_string(queue.policy, '') %></td>
   <td class="c"><%= fmt_idle(queue) %></td>
   <td class="r"><%= fmt_num_thousands(queue.messages_ready) %></td>
   <td class="r"><%= fmt_num_thousands(queue.messages_unacknowledged) %></td>
   <td class="r"><%= fmt_num_thousands(queue.messages) %></td>
<% if (statistics_level == 'fine') { %>
    <td class="r"><%= fmt_rate(queue.message_stats, 'publish') %></td>
    <td class="r"><%= fmt_deliver_rate(queue.message_stats, col_redeliver) %></td>
    <td class="r"><%= fmt_rate(queue.message_stats, 'ack') %></td>
<% } %>
  </tr>
  <% } %>
 </tbody>
</table>
<% } else { %>
  <p>... no queues ...</p>
<% } %>
  </div>
  </div>
</div>

<div class="section-hidden">
  <h2>Add a new queue</h2>
  <div class="hider">
    <form action="#/queues" method="put">
      <table class="form">
<% if (vhosts_interesting) { %>
        <tr>
          <th><label>Virtual host:</label></th>
          <td>
            <select name="vhost">
              <% for (var i = 0; i < vhosts.length; i++) { %>
              <option value="<%= fmt_string(vhosts[i].name) %>"><%= fmt_string(vhosts[i].name) %></option>
              <% } %>
            </select>
          </td>
        </tr>
<% } else { %>
        <tr><td><input type="hidden" name="vhost" value="<%= fmt_string(vhosts[0].name) %>"/></td></tr>
<% } %>
        <tr>
          <th><label>Name:</label></th>
          <td><input type="text" name="name"/><span class="mand">*</span></td>
        </tr>
        <tr>
          <th><label>Durability:</label></th>
          <td>
            <select name="durable">
              <option value="true">Durable</option>
              <option value="false">Transient</option>
            </select>
          </td>
        </tr>
<%
  if (nodes_interesting) {
   var nodes = JSON.parse(sync_get('/nodes'));
%>
        <tr>
          <th><label>Node:</label></th>
          <td>
            <select name="node">
              <% for (var i = 0; i < nodes.length; i++) { %>
              <option value="<%= fmt_string(nodes[i].name) %>"><%= nodes[i].name %></option>
              <% } %>
            </select>
          </td>
        </tr>
<% } %>
        <tr>
          <th><label>Auto delete: <span class="help" id="queue-auto-delete"></span></label></th>
          <td>
            <select name="auto_delete">
              <option value="false">No</option>
              <option value="true">Yes</option>
            </select>
          </td>
        </tr>
        <tr>
          <th><label>Message TTL: <span class="help" id="queue-message-ttl"></span></label></th>
          <td><input type="text" name="x-message-ttl"/> ms</td>
        </tr>
        <tr>
          <th><label>Auto expire: <span class="help" id="queue-expires"></span></label></th>
          <td><input type="text" name="x-expires"/> ms</td>
        </tr>
        <tr>
          <th><label>Max length: <span class="help" id="queue-max-length"></span></label></th>
          <td><input type="text" name="x-max-length"/></td>
        </tr>
        <tr>
          <th><label>Dead letter exchange: <span class="help" id="queue-dead-letter-exchange"></span></label></th>
          <td><input type="text" name="x-dead-letter-exchange"/></td>
        </tr>
        <tr>
          <th><label>Dead letter routing key: <span class="help" id="queue-dead-letter-routing-key"></span></label></th>
          <td><input type="text" name="x-dead-letter-routing-key"/></td>
        </tr>
        <tr>
          <th><label>Arguments:</label></th>
          <td><div class="multifield" id="arguments"></div></td>
        </tr>
      </table>
      <input type="submit" value="Add queue"/>
    </form>
  </div>
</div>
