Commit 6a0c0f3f3fc114a8b02e2d3f44539cf36534061c
1 parent
8310b458
Exists in
spb-stable
and in
3 other branches
Add sorting to public projects page
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
44 additions
and
15 deletions
Show diff stats
app/assets/stylesheets/gitlab_bootstrap/forms.scss
app/contexts/issues/list_context.rb
... | ... | @@ -29,7 +29,7 @@ module Issues |
29 | 29 | if params[:milestone_id].present? |
30 | 30 | @issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id])) |
31 | 31 | end |
32 | - | |
32 | + | |
33 | 33 | # Sort by :sort param |
34 | 34 | @issues = sort(@issues, params[:sort]) |
35 | 35 | |
... | ... | @@ -49,6 +49,5 @@ module Issues |
49 | 49 | else issues |
50 | 50 | end |
51 | 51 | end |
52 | - | |
53 | 52 | end |
54 | 53 | end | ... | ... |
app/controllers/public/projects_controller.rb
... | ... | @@ -8,6 +8,13 @@ class Public::ProjectsController < ApplicationController |
8 | 8 | def index |
9 | 9 | @projects = Project.public_or_internal_only(current_user) |
10 | 10 | @projects = @projects.search(params[:search]) if params[:search].present? |
11 | - @projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20) | |
11 | + @projects = case params[:sort] | |
12 | + when 'newest' then @projects.order('created_at DESC') | |
13 | + when 'oldest' then @projects.order('created_at ASC') | |
14 | + when 'recently_updated' then @projects.order('updated_at DESC') | |
15 | + when 'last_updated' then @projects.order('updated_at ASC') | |
16 | + else @projects.order("namespaces.path, projects.name ASC") | |
17 | + end | |
18 | + @projects = @projects.includes(:namespace).page(params[:page]).per(20) | |
12 | 19 | end |
13 | 20 | end | ... | ... |
app/views/public/projects/index.html.haml
1 | -.row | |
2 | - .span6 | |
3 | - %h3.page-title | |
4 | - Projects (#{@projects.total_count}) | |
5 | - .light | |
6 | - You can browse public projects in read-only mode until signed in. | |
1 | +%h3.page-title | |
2 | + Projects (#{@projects.total_count}) | |
3 | +.light | |
4 | + You can browse public projects in read-only mode until signed in. | |
5 | +%hr | |
6 | +.clearfix | |
7 | + .pull-left | |
8 | + = form_tag public_projects_path, method: :get, class: 'form-inline form-tiny' do |f| | |
9 | + .search-holder | |
10 | + = search_field_tag :search, params[:search], placeholder: "Filter by name", class: "span4 search-text-input", id: "projects_search" | |
11 | + = submit_tag 'Search', class: "btn btn-primary wide" | |
12 | + | |
13 | + .pull-right | |
14 | + .dropdown.inline | |
15 | + %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} | |
16 | + %span.light sort: | |
17 | + - if @sort.present? | |
18 | + = @sort | |
19 | + - else | |
20 | + Newest | |
21 | + %b.caret | |
22 | + %ul.dropdown-menu | |
23 | + %li | |
24 | + = link_to public_projects_path(sort: 'newest') do | |
25 | + Newest | |
26 | + = link_to public_projects_path(sort: 'oldest') do | |
27 | + Oldest | |
28 | + = link_to public_projects_path(sort: 'recently_updated') do | |
29 | + Recently updated | |
30 | + = link_to public_projects_path(sort: 'last_updated') do | |
31 | + Last updated | |
7 | 32 | |
8 | - .span6 | |
9 | - .pull-right | |
10 | - = form_tag public_projects_path, method: :get, class: 'form-inline' do |f| | |
11 | - .search-holder | |
12 | - = search_field_tag :search, params[:search], placeholder: "Filter by name", class: "span3 search-text-input", id: "projects_search" | |
13 | - = submit_tag 'Search', class: "btn btn-primary wide" | |
14 | 33 | %hr |
15 | 34 | .public-projects |
16 | 35 | %ul.bordered-list.top-list | ... | ... |