Skip to content

Commit

Permalink
Add sorting to public projects page
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
  • Loading branch information
dzaporozhets committed Dec 26, 2013
1 parent 8310b45 commit 6a0c0f3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/gitlab_bootstrap/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ form {
text-align: left;
}
}

&.form-tiny {
margin: 0;
}
}

input.input-xpadding,
Expand Down
3 changes: 1 addition & 2 deletions app/contexts/issues/list_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def execute
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])

Expand All @@ -49,6 +49,5 @@ def sort(issues, condition)
else issues
end
end

end
end
9 changes: 8 additions & 1 deletion app/controllers/public/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 31 additions & 12 deletions app/views/public/projects/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
.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
Expand Down

0 comments on commit 6a0c0f3

Please sign in to comment.