- @no_container = true
- page_title "Projects"
- params[:visibility_level] ||= []

= render "admin/dashboard/head"

%div{ class: container_class }
  .top-area
    .prepend-top-default
      = form_tag admin_namespaces_projects_path, method: :get do |f|
        .search-holder
          .search-field-holder
            = search_field_tag :name, params[:name], class: "form-control search-text-input js-search-input", id: "dashboard_search", autofocus: true, spellcheck: false, placeholder: 'Search by name'

            - if params[:visibility_level].present?
              = hidden_field_tag 'visibility_level', params[:visibility_level]

            - if params[:sort].present?
              = hidden_field_tag 'sort', params[:sort]

            - if params[:personal].present?
              = hidden_field_tag 'visibility_level', 'true'

            - if params[:archived].present?
              = hidden_field_tag 'archived', 'true'

            = icon("search", class: "search-icon")

          .dropdown
            - toggle_text = 'Search for Namespace'
            - if params[:namespace_id].present?
              - namespace = Namespace.find(params[:namespace_id])
              - toggle_text = "#{namespace.kind}: #{namespace.path}"
            = dropdown_toggle(toggle_text, { toggle: 'dropdown' }, { toggle_class: 'js-namespace-select large' })
            .dropdown-menu.dropdown-select.dropdown-menu-align-right
              = dropdown_title('Namespaces')
              = dropdown_filter("Search for Namespace")
              = dropdown_content
              = dropdown_loading

          = button_tag "Search", class: "btn btn-primary btn-search"

    %ul.nav-links
      - opts = params[:visibility_level].present? ? {} : { page: admin_namespaces_projects_path }
      = nav_link(opts) do
        = link_to admin_namespaces_projects_path do
          All

      = nav_link(html_options: { class: params[:visibility_level] == Gitlab::VisibilityLevel::PRIVATE.to_s ? 'active' : '' }) do
        = link_to admin_namespaces_projects_path(visibility_level: Gitlab::VisibilityLevel::PRIVATE) do
          Private
      = nav_link(html_options: { class: params[:visibility_level] == Gitlab::VisibilityLevel::INTERNAL.to_s ? 'active' : '' }) do
        = link_to admin_namespaces_projects_path(visibility_level: Gitlab::VisibilityLevel::INTERNAL) do
          Internal
      = nav_link(html_options: { class: params[:visibility_level] == Gitlab::VisibilityLevel::PUBLIC.to_s ? 'active' : '' }) do
        = link_to admin_namespaces_projects_path(visibility_level: Gitlab::VisibilityLevel::PUBLIC) do
          Public

    .nav-controls
      = render 'shared/projects/dropdown'
      = link_to new_project_path, class: 'btn btn-new' do
        New Project

  .projects-list-holder
    - if @projects.any?
      %ul.projects-list.content-list
        - @projects.each_with_index do |project|
          %li.project-row
            .controls
              - if project.archived
                %span.label.label-warning archived
              %span.label.label-gray
                = repository_size(project)
              = link_to 'Edit', edit_namespace_project_path(project.namespace, project), id: "edit_#{dom_id(project)}", class: "btn"
              = link_to 'Delete', [project.namespace.becomes(Namespace), project], data: { confirm: remove_project_message(project) }, method: :delete, class: "btn btn-remove"
            .title
              = link_to [:admin, project.namespace.becomes(Namespace), project] do
                .dash-project-avatar
                  .avatar-container.s40
                    = project_icon(project, alt: '', class: 'avatar project-avatar s40')
                %span.project-full-name
                  %span.namespace-name
                    - if project.namespace
                      = project.namespace.human_name
                      \/
                  %span.project-name.filter-title
                    = project.name

            - if project.description.present?
              .description
                = markdown_field(project, :description)

      = paginate @projects, theme: 'gitlab'
    - else
      .nothing-here-block No projects found
