def index
@projects = Project.public_or_internal_only(current_user)
@projects = @projects.search(params[:search]) if params[:search].present?
- @projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20)
+ @projects = case params[:sort]
+ when 'newest' then @projects.order('created_at DESC')
+ when 'oldest' then @projects.order('created_at ASC')
+ when 'recently_updated' then @projects.order('updated_at DESC')
+ when 'last_updated' then @projects.order('updated_at ASC')
+ else @projects.order("namespaces.path, projects.name ASC")
+ end
+ @projects = @projects.includes(:namespace).page(params[:page]).per(20)
end
end
-.row
- .span6
- %h3.page-title
- Projects (#{@projects.total_count})
- .light
- You can browse public projects in read-only mode until signed in.
+%h3.page-title
+ Projects (#{@projects.total_count})
+.light
+ You can browse public projects in read-only mode until signed in.
+%hr
+.clearfix
+ .pull-left
+ = form_tag public_projects_path, method: :get, class: 'form-inline form-tiny' do |f|
+ .search-holder
+ = search_field_tag :search, params[:search], placeholder: "Filter by name", class: "span4 search-text-input", id: "projects_search"
+ = submit_tag 'Search', class: "btn btn-primary wide"
+
+ .pull-right
+ .dropdown.inline
+ %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"}
+ %span.light sort:
+ - if @sort.present?
+ = @sort
+ - else
+ Newest
+ %b.caret
+ %ul.dropdown-menu
+ %li
+ = link_to public_projects_path(sort: 'newest') do
+ Newest
+ = link_to public_projects_path(sort: 'oldest') do
+ Oldest
+ = link_to public_projects_path(sort: 'recently_updated') do
+ Recently updated
+ = link_to public_projects_path(sort: 'last_updated') do
+ Last updated
- .span6
- .pull-right
- = form_tag public_projects_path, method: :get, class: 'form-inline' do |f|
- .search-holder
- = search_field_tag :search, params[:search], placeholder: "Filter by name", class: "span3 search-text-input", id: "projects_search"
- = submit_tag 'Search', class: "btn btn-primary wide"
%hr
.public-projects
%ul.bordered-list.top-list