Refactor: Extract Query#sortable_columns from the controller.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3604 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-03-19 15:42:03 +00:00
parent 5e4eef1a4e
commit 6e6e260cea
2 changed files with 10 additions and 2 deletions

View File

@ -56,7 +56,7 @@ class IssuesController < ApplicationController
def index
retrieve_query
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
sort_update(@query.sortable_columns)
if @query.valid?
limit = case params[:format]
@ -94,7 +94,7 @@ class IssuesController < ApplicationController
def changes
retrieve_query
sort_init 'id', 'desc'
sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
sort_update(@query.sortable_columns)
if @query.valid?
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",

View File

@ -270,6 +270,14 @@ class Query < ActiveRecord::Base
def groupable_columns
available_columns.select {|c| c.groupable}
end
# Returns a Hash of columns and the key for sorting
def sortable_columns
{'id' => "#{Issue.table_name}.id"}.merge(available_columns.inject({}) {|h, column|
h[column.name.to_s] = column.sortable
h
})
end
def columns
if has_default_columns?