<% @pagetitle = "Show #{@project}" %>
<% @layouttype = 'custom' %>
<% project_bread_crumb 'Overview' %>

<% content_for :content_for_head do -%>
    <%= auto_discovery_link_tag(:atom, commits_feed_path(project: @project, format: 'atom'), { title: "Commits for #{@project}" }) %>
<% end %>

<div class="grid_16 alpha omega box box-shadow">
  <%= render partial: 'tabs' %>
  <div class="grid_10 alpha">
    <h3 id="project_title"><%= @project.title %><%= @project if @project.title.blank? -%></h3>
    <%= description_wrapper(@project.description) %>
    <% if @project.url.present? %>
      <p>
      <%= link_to(@project.url, @project.url) %>
      </p>
    <% end %>
  </div>
  <div class="grid_6 omega" id="infos_list">
    <%= possibly_empty_ul class: :clean_list do %>
        <% if @is_maintenance_project %>
            <li>
              <% if @open_maintenance_incidents %>
                  <%= sprite_tag 'accept' %>
              <% else %>
                  <%= sprite_tag 'exclamation' %>
              <% end %>
              <%= link_to(pluralize(@open_maintenance_incidents.count, "open incident"), action: 'maintenance_incidents', project: @project) %>
            </li>
            <li>
              <% if @maintained_projects.empty? %>
                  <%= sprite_tag 'exclamation' %>
              <% else %>
                  <%= sprite_tag 'accept' %>
              <% end %>
              <%= link_to(pluralize(@maintained_projects.count, "maintained project"), action: 'maintained_projects', project: @project) %>
            </li>
        <% else # also for incident project                                    %>
            <% if @nr_of_problem_packages && @nr_of_problem_packages > 0 %>
                <li>
                  <%= sprite_tag 'exclamation' %>
                  <%= link_to(pluralize(@nr_of_problem_packages, "build error"), action: 'monitor', project: @project, succeeded: 0, blocked: 0, finished: 0, signing: 0, dispatching: 0, scheduled: 0, building: 0) %>
                </li>
            <% end %>
            <% if @has_patchinfo %>
                <li>
                  <%= sprite_tag 'accept' %>
                  <%= link_to('Patchinfo present', controller: 'patchinfo', action: 'show', project: @project, package: 'patchinfo') %>
                </li>
            <% end %>
            <% if @is_incident_project %>
                <% if !@has_patchinfo %>
                    <li>
                      <%= sprite_tag 'exclamation' %>
                      <%= link_to_if(User.current.can_modify_project?(@project), 'Patchinfo missing', { controller: 'patchinfo', action: 'new_patchinfo', project: @project, package: 'patchinfo' }, method: :post) %>
                    </li>
                <% end %>
                <% if @open_release_requests.length > 0 %>
                    <li>
                      <%= sprite_tag 'flag_green' %>
                      <% if @open_release_requests.length == 1 %>
                          <% path = request_show_path(@open_release_requests[0]) %>
                      <% else %>
                          <% path = project_requests_path(@project.name, type: "maintenance_release") %>
                      <% end %>
                      <%= link_to(pluralize(@open_release_requests.length, "release request"), path) %>
                    </li>
                <% end %>
            <% end %>
            <% if @releasetargets.length > 0 %>
                <li>
                  <%= sprite_tag 'information' %>
                  <%= link_to pluralize(@releasetargets.length, "Release Target"), action: 'meta', project: @project %>
                </li>
            <% end %>
        <% end %>

        <%= render partial: 'shared/open_requests' %>

        <% if @project.defines_remote_instance? %>
            <li>
              <%= sprite_tag 'information' %>
              Links against the remote OBS instance at: <i><%= link_to_if(@project.remoteurl,
                                                                          @project.remoteurl, @project.remoteurl) %></i>
            </li>
        <% end %>
        <% if @linking_projects.size > 0 %>
            <li>
              <%= sprite_tag 'information' %>
              <%= link_to(pluralize(@linking_projects.size, "linking project"), { action: 'linking_projects', project: @project }, remote: true) %>
            </li>
        <% end %>
        <% if @project_maintenance_project %>
            <li>
              <%= sprite_tag('accept') %>
              Maintained
              by <%= link_to(@project_maintenance_project, action: 'show', project: @project_maintenance_project) %>
            </li>
        <% end %>
        <% if @project.is_locked? %>
            <li>
              <%= sprite_tag 'lock' %> is locked
            </li>
        <% end %>
    <% end %>
  </div>

  <% if (!@bugowners_mail.empty? && !CONFIG['bugzilla_host'].nil?) || !User.current.is_nobody? %>
      <div class="grid_16 alpha omega">
        <ul class="horizontal-list">
          <% if !@bugowners_mail.empty? && !CONFIG['bugzilla_host'].nil? %>
              <li>
                <%= link_to(sprited_text('tools-report-bug', 'Report bug'), bugzilla_url(@bugowners_mail, "#{@project.name}: Bug")) -%>
              </li>
          <% end -%>
          <% if @project.is_locked? && User.current.can_modify_project?(@project, true) %>
                  <li>
                    <%= link_to(sprited_text('lock_open', 'Unlock project'), { controller: 'project', action: 'unlock_dialog', project: @project.name }, remote: true) %>
                  </li>
          <% elsif User.current.can_modify_project?(@project) %>
              <% unless @project.defines_remote_instance? %>
                  <% if @is_incident_project && @packages.present? && @has_patchinfo && @open_release_requests.blank? %>
                      <li>
                        <%= link_to(sprited_text('brick_go', 'Request to release'), { controller: 'project', action: 'release_request_dialog', project: @project }, remote: true) %>
                      </li>
                  <% elsif @is_maintenance_project %>
                      <li>
                        <%= link_to(sprited_text('brick_add', 'Create maintenance incident'), { controller: 'project', action: 'new_incident', ns: @project.name }, method: :post) %>
                      </li>
                  <% else %>
                      <% if @has_patchinfo %>
                          <li>
                            <%= link_to(sprited_text('information', 'Show patchinfo'), controller: 'patchinfo', action: 'show', project: @project, package: 'patchinfo') %>
                          </li>
                      <% else %>
                          <li>
                            <%= link_to(sprited_text('plugin_add', 'Create patchinfo'), { controller: 'patchinfo', action: :new_patchinfo, project: @project }, method: :post) %>
                          </li>
                      <% end %>
                      <% if !@is_incident_project && @releasetargets.length > 0 %>
                          <li>
                            <%= link_to(sprited_text('brick_go', 'Submit as update'), { controller: 'project', action: 'incident_request_dialog', project: @project }, remote: true) %>
                          </li>
                      <% end %>
                      <%= render partial: 'webui/project/show/encryption_key_download_links' %>
                  <% end %>
              <% end %>
              <li>
                <%= link_to(sprited_text('brick_edit', 'Edit description'), { action: 'edit', project: @project }, id: 'edit-description') %>
              </li>
              <li>
                <%= link_to(sprited_text('brick_delete', 'Delete project'), { controller: 'project', action: 'delete_dialog', project: @project.name }, remote: true, id: 'delete-project') %>
              </li>
          <% elsif !@project.is_locked? %>
              <li>
                <%= link_to(sprited_text('user_add', 'Request role addition'), { controller: 'request', action: 'add_role_request_dialog', project: @project }, remote: true) %>
              </li>
              <li>
                <%= link_to(sprited_text('package_delete', 'Request deletion'), { controller: 'request', action: 'delete_request_dialog', project: @project }, remote: true, id: 'request-deletion') %>
              </li>
          <% end %>
        </ul>
      </div>
  <% else %>
    <div class="grid_16 alpha omega">
      <ul class="horizontal-list">
        <%= render partial: 'webui/project/show/encryption_key_download_links' %>
      </ul>
    </div>
  <% end %>
</div>

<% if @is_maintenance_project %>
    <%# TODO: Show some maintenance stuff here %>
<% else %>
    <%= render partial: 'packages_table' %>
<% end %>

<div class="grid_6 omega box box-shadow">
  <%= render partial: 'shared/buildresult_box', locals: { project: @project.name } %>
</div>
<div class="grid_16 box box-shadow alpha omega">
  <h2 class="box-header">Comments for <%= @project.name %> (<%= @comments.length %>)</h2>
  <div id="comments">
    <%= render partial: 'webui/comment/show', locals: { commentable: @project } %>
  </div>
</div>
