
<h1>Queues</h1>
<div class="section" id="queues-paging-section">
  <%= paginate_ui(queues, 'queues') %>
</div>
<div class="updatable" id="queues-table-section">
<% if (queues.items.length > 0) { %>
<table class="list">
 <thead>
  <tr>
    <%= group_heading('queues', 'Overview', [display.vhosts, display.nodes, 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 (display.vhosts) { %>
    <th><%= fmt_sort('Virtual host', 'vhost') %></th>
<% } %>
    <th><%= fmt_sort('Name',         'name') %></th>
<% if (display.nodes) { %>
    <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 (display.vhosts) { %>
   <td><%= fmt_string(queue.vhost) %></td>
<% } %>
   <td><%= link_queue(queue.vhost, queue.name, queue.arguments) %></td>
<% if (display.nodes) { %>
   <td>
     <% if (queue.node) { %>
      <%= fmt_node(queue.node) %>
     <% } else { %>
      <%= fmt_node(queue.leader) %>
     <% } %>
     <% if (queue.hasOwnProperty('members')) { %>
      <%= fmt_members(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>

<% if (ac.canAccessVhosts()) { %>
<div class="section-hidden" id="add-new-queue">
  <h2>Add a new queue</h2>
  <div class="hider">
    <form action="#/queues" method="put">
      <table class="form">
<% if (display.vhosts) { %>
        <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="default">Default for virtual host</option>
                <% for (const [typename, type_config] of Object.entries(QUEUE_TYPE)) { %>
                  <% if (typename != "default") { %>
                  <% if (queue_type == typename) { %>
                      <option value="<%= typename%>" selected><%= type_config["label"]%></option>
                  <% } else { %>
                      <option value="<%= typename%>"><%= type_config["label"]%></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" || queue_type == "default") { %>
        <tr>
          <th><label>Durability:</label></th>
          <td>
            <select name="durable">
              <option value="true">Durable</option>
              <option value="false">Transient</option>
            </select>
          </td>
        </tr>
<% } %>
<%
  if (ac.canListNodes()) {
   var nodes = display.data.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>
                        <%= format(QUEUE_TYPE[queue_type].tmpl['arguments'], {}) %>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <input type="submit" value="Add queue"/>
    </form>
  </div>
  <% } %>
</div>
