<div class="row header">
  <div class="col-sm-8 pull-left">
    <h3><%= x.t("Processes") %></h3>
  </div>
  <div class="col-sm-4 pull-right">
    <form method="POST" style="margin-top: 20px; margin-bottom: 10px;">
      <%= x.csrf_tag %>
      <div class="btn-group pull-right">
        <button class="btn btn-warn" type="submit" name="quiet" value="1" data-confirm="<%= x.t("AreYouSure") %>"><%= x.t("QuietAll") %></button>
        <button class="btn btn-danger" type="submit" name="stop" value="1" data-confirm="<%= x.t("AreYouSure") %>"><%= x.t("StopAll") %></button>
      </div>
    </form>
  </div>
</div>

<div class="table_container">
  <table class="processes table table-hover table-bordered table-striped table-white">
    <thead>
      <th><%= x.t("Name") %></th>
      <th><%= x.t("Started") %></th>
      <th><%= x.t("Threads") %></th>
      <th><%= x.t("Busy") %></th>
      <th>&nbsp;</th>
    </thead>
    <% x.processes.each do |process| %>
      <tr>
        <td width="50%">
          <%= "#{process["hostname"]}:#{process["pid"]}" %>
          <span class="label label-success"><%= process.tag %></span>
          <% process.labels.each do |label| %>
            <span class="label label-info"><%= label %></span>
          <% end %>
          <% if process.stopping? %>
            <span class="label label-danger">Quiet</span>
          <% end %>
          <br>
          <b><%= "#{x.t("Queues")}: " %></b>
          <%= process.queues.join(", ") %>
        </td>
        <td><%= x.relative_time(process.started_at) %></td>
        <td><%= process["concurrency"] %></td>
        <td><%= process["busy"] %></td>
        <td>
          <div class="btn-group pull-right">
            <form method="POST">
              <%= x.csrf_tag %>
              <input type="hidden" name="identity" value="<%= process["identity"] %>"/>
              <% unless process.stopping? %>
                <button class="btn btn-warn" type="submit" name="quiet" value="1"><%= x.t("Quiet") %></button>
              <% end %>
              <button class="btn btn-danger" type="submit" name="stop" value="1"><%= x.t("Stop") %></button>
            </form>
          </div>
        </td>
      </tr>
    <% end %>
  </table>
</div>

<div class="row header">
  <div class="col-sm-7">
    <h3><%= x.t("Jobs") %></h3>
  </div>
</div>

<div class="table_container">
  <table class="workers table table-hover table-bordered table-striped table-white">
    <thead>
      <th><%= x.t("Process") %></th>
      <th><%= x.t("TID") %></th>
      <th><%= x.t("JID") %></th>
      <th><%= x.t("Queue") %></th>
      <th><%= x.t("Job") %></th>
      <th><%= x.t("Arguments") %></th>
      <th><%= x.t("Started") %></th>
    </thead>
    <% x.workers.each do |entry| %>
      <% job = entry.job_proxy %>
      <tr>
        <td><%= entry.process_id %></td>
        <td><%= entry.thread_id %></td>
        <td><%= job.jid %></td>
        <td>
          <a href="<%= x.root_path %>queues/<%= job.queue %>"><%= job.queue %></a>
        </td>
        <td><%= job.display_class %></td>
        <td>
          <div class="args"><%= x.display_args(job.display_args) %></div>
        </td>
        <td><%= x.relative_time(entry.run_at) %></td>
      </tr>
    <% end %>
  </table>
</div>
