<% @pagetitle = "Project #{@project} Status Monitor"
   @metarobots = 'noindex,nofollow'
   project_bread_crumb( 'Status Monitor' ) -%>

<%= content_for :ready_function do %>
  project_monitor_ready();
<% end %>


<%= render :partial => "tabs" %>

<div id="monitor-wrapper">

  <!-- Filter Settings -->
  <%= form_tag({:controller => 'project', :action => 'monitor'}, :method => :get) do %>
    <div id='filter_settings'>
      <%= submit_tag 'Filter:'%>
      <span class="strong filterlink" id="statuslink">Status <%= image_tag 'arrow.png' %></span>
      <div id="statusbox" class="filterbox hidden">
        <a class="filterbox_close" href="#" id="statusbox_close">[x]</a>
        <% unless @avail_status_values.empty? -%>
        <ul>
          <% @avail_status_values.each do |s| %>
            <% id=s.gsub(' ', '') -%>
            <li class="nowrap filteritem" id="li_<%= id %>">
              <%= check_box_tag id, 1, @status_filter.include?(s), :class => "statusitem" %>
              <label for="<%= id %>" class="strong"><%= s %></label>
            </li>
          <% end %>
        </ul>
        <% end -%>
        <a href="#" id="statusbox_all" class="filterbox_all">Select all</a><a href="#" id="statusbox_none" class="filterbox_none">Select none</a>
      </div>
      <label for="pkgname" class="strong">Packagename: </label><%= text_field_tag "pkgname", @name_filter %>

      <span class="strong filterlink" id="repolink">Repository <%= image_tag 'arrow.png' %></span>
      <div id="repobox" class="hidden filterbox">
        <a class="filterbox_close" href="#" id="repobox_close">[x]</a>
        <% unless @avail_repo_values.empty? -%>
        <ul>
          <% @avail_repo_values.each do |s| %>
            <li class="nowrap filteritem">
              <% sname = valid_xml_id('repo_' + s) %>
              <%= check_box_tag s, 1, @repo_filter.include?(s), :class => "repoitem", :id => sname, :name => sname %>
              <label for="<%= sname %>" class="strong"><%= s %></label>
            </li>
          <% end %>
        </ul>
        <% end -%>
        <a href="#" id="repobox_all" class="filterbox_all">Select all</a><a href="#" id="repobox_none" class="filterbox_none">Select none</a>
      </div>

      <span class="strong filterlink" id="archlink">Architecture <%= image_tag 'arrow.png' %></span>
      <div id="archbox" class="hidden filterbox">
        <a class="filterbox_close" href="#" id="archbox_close">[x]</a>
        <% unless @avail_arch_values.empty? -%>
        <ul>
          <% @avail_arch_values.each do |s| %>
            <li class="nowrap filteritem">
              <% sname = valid_xml_id('arch_' + s) %>
              <%= check_box_tag s, 1, @arch_filter.include?(s), :class => "architem", :id => sname, :name => sname %>
              <label for="<%= sname %>" class="strong"><%= s %></label>
            </li>
          <% end %>
        </ul>
        <% end -%>
        <a href="#" id="archbox_all" class="filterbox_all">Select all</a><a href="#" id="archbox_none" class="filterbox_none">Select none</a>
      </div>
      <label for="lastbuild" class="strong">Last time results: </label><%= check_box_tag "lastbuild", 1, @lastbuild_switch %>
      <%= hidden_field_tag 'project', @project %>
      <%= hidden_field_tag 'defaults', '0' %>
    </div>
  <% end %>


  <% if @buildresult_unavailable -%>
    <h3>Buildstatus unavailable</h3>
  <% elsif @packagenames.empty? -%>
    <h3>No Results</h3>
  <% else -%>
    <table class="buildstatus">
      <!-- repo row -->
      <thead class="header">
        <tr>
          <th></th>
          <% @repohash.sort.each do |repo,archlist|
            next if archlist.empty? -%>
            <th colspan="<%= archlist.length %>"><span class="strong"><%= repo %></span></th>
          <% end -%>
        </tr>
        <!-- arch row -->
        <tr>
          <th></th>
          <% @repohash.sort.each do |repo, archlist| -%>
            <% archlist.sort.each do |arch| -%>
              <th class="buildstatus"><%= repo_status_icon(@repostatushash[repo][arch],@repostatusdetailshash[repo][arch]) %> <%= arch %></th>
            <% end -%>
          <% end -%>
        </tr>
      </thead>

      <tbody>      <!-- package rows -->
        <% @packagenames.each do |packname| -%>
          <tr>
            <td>
              <%= link_to word_break(packname, 40), :controller => "package", :action => "show",
                :package => packname, :project => @project.to_s %>
            </td>
            <% @repohash.sort.each do |repo, archlist| -%>
              <% archlist.sort.each do |arch| -%>
                <%= arch_repo_table_cell(repo, arch, packname, nil, false) %>
              <% end -%>
            <% end -%>
          </tr>
        <% end -%>
      </tbody>
    </table>
  <% end -%>
  <div id="refresh_date"><p>Updated at: <%= DateTime.now.to_s.sub(/T/, " ") %></p></div>
  <div id="legend">
    <h3>Legend</h3>
    <ul>
      <% Buildresult::STATUS_DESCRIPTION.each do |status, description| %>
        <li><strong><%= status %>: </strong><span class="descr"><%= description %></span></li>
      <% end %>
    </ul>
  </div>

  <div id="start_link">
  </div>

</div>

<% content_for :ready_function do %>
    $('.unresolvable, .blocked').click(function() {
    var title = $(this).attr('title');
    alert(title);
    return false;
    });
<% end %>
