Commit 6a0c0f3f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add sorting to public projects page

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 8310b458
......@@ -21,6 +21,10 @@ form {
text-align: left;
}
}
&.form-tiny {
margin: 0;
}
}
input.input-xpadding,
......
......@@ -29,7 +29,7 @@ module Issues
if params[:milestone_id].present?
@issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id]))
end
# Sort by :sort param
@issues = sort(@issues, params[:sort])
......@@ -49,6 +49,5 @@ module Issues
else issues
end
end
end
end
......@@ -8,6 +8,13 @@ class Public::ProjectsController < ApplicationController
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment