Commit c608a5dceab0a5fa2df8286d5808091f2517d4ab
1 parent
9dfc4fe6
Exists in
spb-stable
and in
2 other branches
Add sort dropdown for admin projects page
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
3 changed files
with
25 additions
and
0 deletions
Show diff stats
app/controllers/admin/projects_controller.rb
... | ... | @@ -12,6 +12,7 @@ class Admin::ProjectsController < Admin::ApplicationController |
12 | 12 | @projects = @projects.with_push if params[:with_push].present? |
13 | 13 | @projects = @projects.abandoned if params[:abandoned].present? |
14 | 14 | @projects = @projects.search(params[:name]) if params[:name].present? |
15 | + @projects = @projects.sort(@sort = params[:sort]) | |
15 | 16 | @projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20) |
16 | 17 | end |
17 | 18 | ... | ... |
app/models/project.rb
... | ... | @@ -203,6 +203,7 @@ class Project < ActiveRecord::Base |
203 | 203 | when 'oldest' then reorder('projects.created_at ASC') |
204 | 204 | when 'recently_updated' then reorder('projects.updated_at DESC') |
205 | 205 | when 'last_updated' then reorder('projects.updated_at ASC') |
206 | + when 'largest_repository' then reorder('projects.repository_size DESC') | |
206 | 207 | else reorder("namespaces.path, projects.name ASC") |
207 | 208 | end |
208 | 209 | end | ... | ... |
app/views/admin/projects/index.html.haml
... | ... | @@ -32,6 +32,7 @@ |
32 | 32 | = visibility_level_icon(level) |
33 | 33 | = label |
34 | 34 | .form-actions |
35 | + = hidden_field_tag :sort, params[:sort] | |
35 | 36 | = submit_tag "Search", class: "btn submit btn-primary" |
36 | 37 | = link_to "Reset", admin_projects_path, class: "btn" |
37 | 38 | |
... | ... | @@ -40,6 +41,28 @@ |
40 | 41 | .title |
41 | 42 | Projects (#{@projects.total_count}) |
42 | 43 | .pull-right |
44 | + .dropdown.inline | |
45 | + %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} | |
46 | + %span.light sort: | |
47 | + - if @sort.present? | |
48 | + = @sort.humanize | |
49 | + - else | |
50 | + Name | |
51 | + %b.caret | |
52 | + %ul.dropdown-menu | |
53 | + %li | |
54 | + = link_to admin_projects_path(sort: nil) do | |
55 | + Name | |
56 | + = link_to admin_projects_path(sort: 'newest') do | |
57 | + Newest | |
58 | + = link_to admin_projects_path(sort: 'oldest') do | |
59 | + Oldest | |
60 | + = link_to admin_projects_path(sort: 'recently_updated') do | |
61 | + Recently updated | |
62 | + = link_to admin_projects_path(sort: 'last_updated') do | |
63 | + Last updated | |
64 | + = link_to admin_projects_path(sort: 'largest_repository') do | |
65 | + Largest repository | |
43 | 66 | = link_to 'New Project', new_project_path, class: "btn btn-new" |
44 | 67 | %ul.well-list |
45 | 68 | - @projects.each do |project| | ... | ... |