]> source.dussan.org Git - redmine.git/commitdiff
Adds a 'sorted' scope to Project.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Nov 2014 20:44:11 +0000 (20:44 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Nov 2014 20:44:11 +0000 (20:44 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13541 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/admin_controller.rb
app/controllers/projects_controller.rb
app/models/project.rb

index b09b1c4c9439f63c9ca4404938845d6ea4978cc1..0a89da0773d905e35d431449bd7e2ff51fd5cf00 100644 (file)
@@ -32,7 +32,7 @@ class AdminController < ApplicationController
   def projects
     @status = params[:status] || 1
 
-    scope = Project.status(@status).order('lft')
+    scope = Project.status(@status).sorted
     scope = scope.like(params[:name]) if params[:name].present?
     @projects = scope.to_a
 
index 9ab60a403242012d59618c620094c84593b99092..beb279476627e5f467868d6323d770a157f51d4f 100644 (file)
@@ -40,21 +40,22 @@ class ProjectsController < ApplicationController
 
   # Lists visible projects
   def index
+    scope = Project.visible.sorted
+
     respond_to do |format|
       format.html {
-        scope = Project
         unless params[:closed]
           scope = scope.active
         end
-        @projects = scope.visible.order('lft').to_a
+        @projects = scope.to_a
       }
       format.api  {
         @offset, @limit = api_offset_and_limit
-        @project_count = Project.visible.count
-        @projects = Project.visible.offset(@offset).limit(@limit).order('lft').to_a
+        @project_count = scope.count
+        @projects = scope.offset(@offset).limit(@limit).to_a
       }
       format.atom {
-        projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).to_a
+        projects = scope.reorder(:created_on => :desc).limit(Setting.feeds_limit.to_i).to_a
         render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
       }
     end
index f29f50f2148270f7bdc67ee3ac71832e173043f6..27cb4c7a649f6876619f0753cdb0fb920526f5c0 100644 (file)
@@ -111,6 +111,7 @@ class Project < ActiveRecord::Base
       where("LOWER(identifier) LIKE :p OR LOWER(name) LIKE :p", :p => pattern)
     end
   }
+  scope :sorted, lambda {order(:lft)}
 
   def initialize(attributes=nil, *args)
     super