
<h1>Queues</h1>
<div class="section">
  <%= paginate_ui(queues, 'queues') %>
</div>
<div class="updatable">
<% if (queues.items.length > 0) { %>
<table class="list">
 <thead>
  <tr>
    <%= group_heading('queues', 'Overview', [vhosts_interesting, nodes_interesting, true]) %>
<% if(disable_stats && enable_queue_totals) { %>
    <%= group_heading('queues', 'Messages', []) %>
<% } else { %>
<% if(!disable_stats) { %>
    <%= group_heading('queues', 'Messages', []) %>
    <%= group_heading('queues', 'Message bytes', []) %>
<% if (rates_mode != 'none') { %>
    <%= group_heading('queues', 'Message rates', []) %>
<% } %>
<% } %>
<% } %>
    <th class="plus-minus"><span class="popup-options-link" title="Click to change columns" type="columns" for="queues">+/-</span></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>
<% } %>
<% if (show_column('queues', 'type')) { %>
    <th><%= fmt_sort('Type', 'type') %></th>
<% } %>
<% if (show_column('queues', 'features')) { %>
    <th>Features</th>
<% } %>
<% if (show_column('queues', 'features_no_policy')) { %>
    <th>Features</th>
<% } %>
<% if (show_column('queues', 'policy')) { %>
    <th><%= fmt_sort('Policy','policy') %></th>
<% } %>
<% if (show_column('queues', 'consumers')) { %>
    <th><%= fmt_sort('Consumers',    'consumers') %></th>
<% } %>
<% if (show_column('queues', 'consumer_capacity')) { %>
    <th><%= fmt_sort('Consumer capacity', 'consumer_capacity') %></th>
<% } %>
<% if (show_column('queues', 'state')) { %>
    <th><%= fmt_sort('State',        'state') %></th>
<% } %>
<% if(disable_stats && enable_queue_totals) { %>
<% if (show_column('queues', 'msgs-ready')) { %>
    <th><%= fmt_sort('Ready',        'messages_ready') %></th>
<% } %>
<% if (show_column('queues', 'msgs-unacked')) { %>
    <th><%= fmt_sort('Unacked',      'messages_unacknowledged') %></th>
<% } %>
<% if (show_column('queues', 'msgs-total')) { %>
    <th><%= fmt_sort('Total',        'messages') %></th>
<% } %>
<% } %>
<% if(!disable_stats) { %>
<% if (show_column('queues', 'msgs-ready')) { %>
    <th><%= fmt_sort('Ready',        'messages_ready') %></th>
<% } %>
<% if (show_column('queues', 'msgs-unacked')) { %>
    <th><%= fmt_sort('Unacked',      'messages_unacknowledged') %></th>
<% } %>
<% if (show_column('queues', 'msgs-ram')) { %>
    <th><%= fmt_sort('In Memory',    'messages_ram') %></th>
<% } %>
<% if (show_column('queues', 'msgs-persistent')) { %>
    <th><%= fmt_sort('Persistent',   'messages_persistent') %></th>
<% } %>
<% if (show_column('queues', 'msgs-total')) { %>
    <th><%= fmt_sort('Total',        'messages') %></th>
<% } %>
<% if (show_column('queues', 'msg-bytes-ready')) { %>
    <th><%= fmt_sort('Ready',        'message_bytes_ready') %></th>
<% } %>
<% if (show_column('queues', 'msg-bytes-unacked')) { %>
    <th><%= fmt_sort('Unacked',      'message_bytes_unacknowledged') %></th>
<% } %>
<% if (show_column('queues', 'msg-bytes-ram')) { %>
    <th><%= fmt_sort('In Memory',    'message_bytes_ram') %></th>
<% } %>
<% if (show_column('queues', 'msg-bytes-persistent')) { %>
    <th><%= fmt_sort('Persistent',   'message_bytes_persistent') %></th>
<% } %>
<% if (show_column('queues', 'msg-bytes-total')) { %>
    <th><%= fmt_sort('Total',        'message_bytes') %></th>
<% } %>
<% if (rates_mode != 'none') { %>
  <% if (show_column('queues', 'rate-incoming')) { %>
    <th><%= fmt_sort('incoming', 'message_stats.publish_details.rate') %></th>
  <% } %>
  <% if (show_column('queues', 'rate-deliver')) { %>
    <th><%= fmt_sort('deliver / get', 'message_stats.deliver_get_details.rate') %></th>
  <% } %>
  <% if (show_column('queues', 'rate-redeliver')) { %>
    <th><%= fmt_sort('redelivered', 'message_stats.redeliver_details.rate') %></th>
  <% } %>
  <% if (show_column('queues', 'rate-ack')) { %>
    <th><%= fmt_sort('ack', 'message_stats.ack_details.rate') %></th>
  <% } %>
<% } %>
<% } %>
  </tr>
 </thead>
 <tbody>
<%
  for (var i = 0; i < queues.items.length; i++) {
    var queue = queues.items[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>
     <% if (queue.node) { %>
      <%= fmt_node(queue.node) %>
     <% } else { %>
      <%= fmt_node(queue.leader) %>
     <% } %>
     <% if (queue.hasOwnProperty('members')) { %>
      <%= fmt_members(queue) %>
     <% } else { %>
      <%= fmt_mirrors(queue) %>
      <% if (queue.state == 'syncing') { %>
        <%= fmt_sync_state(queue) %>
      <% } %>
     <% } %>
   </td>
<% } %>
<% if (show_column('queues', 'type')) { %>
   <td><%= fmt_string(queue.type, '') %></td>
<% } %>
<% if (show_column('queues', 'features')) { %>
   <td class="c">
     <%= fmt_features_short(queue) %>
     <%= fmt_policy_short(queue) %>
     <%= fmt_op_policy_short(queue) %>
   </td>
<% } %>
<% if (show_column('queues', 'features_no_policy')) { %>
   <td class="c"><%= fmt_features_short(queue) %></td>
<% } %>
<% if (show_column('queues', 'policy')) { %>
   <td class="c"><%= link_policy(queue.vhost, queue.policy) %>
                 <%= fmt_string(queue.operator_policy) %></td>
<% } %>
<% if (show_column('queues', 'consumers')) { %>
   <td class="c"><%= fmt_string(queue.consumers) %></td>
<% } %>
<% if (show_column('queues', 'consumer_capacity')) { %>
   <td class="c"><%= fmt_percent(queue.consumer_capacity) %></td>
<% } %>
<% if (show_column('queues', 'state')) { %>
   <td class="c"><%= fmt_object_state(queue) %></td>
<% } %>
<% if(!disable_stats || (disable_stats && enable_queue_totals)) { %>
<% if (show_column('queues', 'msgs-ready')) { %>
   <td class="r"><%= fmt_num_thousands(queue.messages_ready) %></td>
<% } %>
<% if (show_column('queues', 'msgs-unacked')) { %>
   <td class="r"><%= fmt_num_thousands(queue.messages_unacknowledged) %></td>
<% } %>
<% } %>
<% if(!disable_stats) { %>
<% if (show_column('queues', 'msgs-ram')) { %>
   <td class="r"><%= fmt_num_thousands(queue.messages_ram) %></td>
<% } %>
<% if (show_column('queues', 'msgs-persistent')) { %>
   <td class="r"><%= fmt_num_thousands(queue.messages_persistent) %></td>
<% } %>
<% } %>
<% if(!disable_stats || (disable_stats && enable_queue_totals)) { %>
<% if (show_column('queues', 'msgs-total')) { %>
   <td class="r"><%= fmt_num_thousands(queue.messages) %></td>
<% } %>
<% } %>
<% if(!disable_stats) { %>
<% if (show_column('queues', 'msg-bytes-ready')) { %>
   <td class="r"><%= fmt_bytes(queue.message_bytes_ready) %></td>
<% } %>
<% if (show_column('queues', 'msg-bytes-unacked')) { %>
   <td class="r"><%= fmt_bytes(queue.message_bytes_unacknowledged) %></td>
<% } %>
<% if (show_column('queues', 'msg-bytes-ram')) { %>
   <td class="r"><%= fmt_bytes(queue.message_bytes_ram) %></td>
<% } %>
<% if (show_column('queues', 'msg-bytes-persistent')) { %>
   <td class="r"><%= fmt_bytes(queue.message_bytes_persistent) %></td>
<% } %>
<% if (show_column('queues', 'msg-bytes-total')) { %>
   <td class="r"><%= fmt_bytes(queue.message_bytes) %></td>
<% } %>
<% if (rates_mode != 'none') { %>
  <% if (show_column('queues', 'rate-incoming')) { %>
    <td class="r"><%= fmt_detail_rate(queue.message_stats, 'publish') %></td>
  <% } %>
  <% if (show_column('queues', 'rate-deliver')) { %>
    <td class="r"><%= fmt_detail_rate(queue.message_stats, 'deliver_get') %></td>
  <% } %>
  <% if (show_column('queues', 'rate-redeliver')) { %>
    <td class="r"><%= fmt_detail_rate(queue.message_stats, 'redeliver') %></td>
  <% } %>
  <% if (show_column('queues', 'rate-ack')) { %>
    <td class="r"><%= fmt_detail_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) %>" <%= (vhosts[i].name === current_vhost) ? 'selected="selected"' : '' %>><%= 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>Type:</label></th>
          <td>
            <select name="queuetype" onchange="select_queue_type(queuetype)">
              <option value="classic">Classic</option>
              <% if (queue_type == "quorum") { %>
               <option value="quorum" selected>Quorum</option>
              <% } else { %>
               <option value="quorum">Quorum</option>
              <% } %>
              <% if (queue_type == "stream") { %>
               <option value="stream" selected>Stream</option>
              <% } else { %>
               <option value="stream">Stream</option>
              <% } %>
            </select>
          </td>
        </tr>
        <tr>
          <th><label>Name:</label></th>
          <td><input type="text" name="name"/><span class="mand">*</span></td>
        </tr>
<% if (queue_type == "classic") { %>
        <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) %>"><%= fmt_node(nodes[i].name) %></option>
              <% } %>
            </select>
          </td>
        </tr>
<% } %>
<% if (queue_type == "classic") { %>
        <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>Arguments:</label></th>
          <td>
            <div class="multifield" id="arguments"></div>
            <table class="argument-links">
              <tr>
                <td>Add</td>
                <td>
                <% if (queue_type == "classic") { %>
                  <span class="argument-link" field="arguments" key="x-message-ttl" type="number">Message TTL</span> <span class="help" id="queue-message-ttl"></span> |
                <% } %>
                <% if (queue_type != "stream") { %>
                  <span class="argument-link" field="arguments" key="x-expires" type="number">Auto expire</span> <span class="help" id="queue-expires"></span> |
                  <span class="argument-link" field="arguments" key="x-overflow" type="string">Overflow behaviour</span> <span class="help" id="queue-overflow"></span> |
                  <span class="argument-link" field="arguments" key="x-single-active-consumer" type="boolean">Single active consumer</span> <span class="help" id="queue-single-active-consumer"></span><br/>
                  <span class="argument-link" field="arguments" key="x-dead-letter-exchange" type="string">Dead letter exchange</span> <span class="help" id="queue-dead-letter-exchange"></span> |
                  <span class="argument-link" field="arguments" key="x-dead-letter-routing-key" type="string">Dead letter routing key</span> <span class="help" id="queue-dead-letter-routing-key"></span><br/>
                  <span class="argument-link" field="arguments" key="x-max-length" type="number">Max length</span> <span class="help" id="queue-max-length"></span> |
                <% } %>
                  <span class="argument-link" field="arguments" key="x-max-length-bytes" type="number">Max length bytes</span> <span class="help" id="queue-max-length-bytes"></span><br/>
                <% if (queue_type == "classic") { %>
                <span class="argument-link" field="arguments" key="x-max-priority" type="number">Maximum priority</span> <span class="help" id="queue-max-priority"></span>
                | <span class="argument-link" field="arguments" key="x-queue-mode" type="string" value="lazy">Lazy mode</span> <span class="help" id="queue-lazy"></span>
                | <span class="argument-link" field="arguments" key="x-queue-master-locator" type="string" value="">Master locator</span> <span class="help" id="queue-master-locator"></span>
                <% } %>
                <% if (queue_type == "quorum") { %>
                  <span class="argument-link" field="arguments" key="x-delivery-limit" type="number">Delivery limit</span><span class="help" id="delivery-limit"></span>
                  | <span class="argument-link" field="arguments" key="x-max-in-memory-length" type="number">Max in memory length</span><span class="help" id="queue-max-in-memory-length"></span>
                  | <span class="argument-link" field="arguments" key="x-max-in-memory-bytes" type="number">Max in memory bytes</span><span class="help" id="queue-max-in-memory-bytes"></span>
                  | <span class="argument-link" field="arguments" key="x-quorum-initial-group-size" type="number">Initial cluster size</span><span class="help" id="queue-quorum-initial-group-size"></span><br/>
                <% } %>
                <% if (queue_type == "stream") { %>
                  <span class="argument-link" field="arguments" key="x-max-age" type="string">Max time retention</span><span class="help" id="queue-max-age"></span>
                  | <span class="argument-link" field="arguments" key="x-stream-max-segment-size-bytes" type="number">Max segment size in bytes</span><span class="help" id="queue-stream-max-segment-size-bytes"></span>
                  | <span class="argument-link" field="arguments" key="x-initial-cluster-size" type="number">Initial cluster size</span><span class="help" id="queue-initial-cluster-size"></span>
                  | <span class="argument-link" field="arguments" key="x-queue-leader-locator" type="string">Leader locator</span><span class="help" id="queue-leader-locator"></span>
                <% } %>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <input type="submit" value="Add queue"/>
    </form>
  </div>
</div>
