More appropriate default sort order on sortable columns.
Sortable column added on issue subject (#580). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1121 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
80a60247f5
commit
54ff294da1
|
@ -22,7 +22,9 @@ module QueriesHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def column_header(column)
|
def column_header(column)
|
||||||
column.sortable ? sort_header_tag(column.sortable, :caption => column.caption) : content_tag('th', column.caption)
|
column.sortable ? sort_header_tag(column.sortable, :caption => column.caption,
|
||||||
|
:default_order => column.default_order) :
|
||||||
|
content_tag('th', column.caption)
|
||||||
end
|
end
|
||||||
|
|
||||||
def column_content(column, issue)
|
def column_content(column, issue)
|
||||||
|
|
|
@ -92,7 +92,7 @@ module SortHelper
|
||||||
# - The optional caption explicitly specifies the displayed link text.
|
# - The optional caption explicitly specifies the displayed link text.
|
||||||
# - A sort icon image is positioned to the right of the sort link.
|
# - A sort icon image is positioned to the right of the sort link.
|
||||||
#
|
#
|
||||||
def sort_link(column, caption=nil)
|
def sort_link(column, caption, default_order)
|
||||||
key, order = session[@sort_name][:key], session[@sort_name][:order]
|
key, order = session[@sort_name][:key], session[@sort_name][:order]
|
||||||
if key == column
|
if key == column
|
||||||
if order.downcase == 'asc'
|
if order.downcase == 'asc'
|
||||||
|
@ -104,11 +104,13 @@ module SortHelper
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
icon = nil
|
icon = nil
|
||||||
order = 'desc' # changed for desc order by default
|
order = default_order
|
||||||
end
|
end
|
||||||
caption = titleize(Inflector::humanize(column)) unless caption
|
caption = titleize(Inflector::humanize(column)) unless caption
|
||||||
|
|
||||||
url = {:sort_key => column, :sort_order => order, :issue_id => params[:issue_id], :project_id => params[:project_id]}
|
url = {:sort_key => column, :sort_order => order, :status => params[:status],
|
||||||
|
:issue_id => params[:issue_id],
|
||||||
|
:project_id => params[:project_id]}
|
||||||
|
|
||||||
link_to_remote(caption,
|
link_to_remote(caption,
|
||||||
{:update => "content", :url => url},
|
{:update => "content", :url => url},
|
||||||
|
@ -138,8 +140,9 @@ module SortHelper
|
||||||
#
|
#
|
||||||
def sort_header_tag(column, options = {})
|
def sort_header_tag(column, options = {})
|
||||||
caption = options.delete(:caption) || titleize(Inflector::humanize(column))
|
caption = options.delete(:caption) || titleize(Inflector::humanize(column))
|
||||||
|
default_order = options.delete(:default_order) || 'asc'
|
||||||
options[:title]= l(:label_sort_by, "\"#{caption}\"") unless options[:title]
|
options[:title]= l(:label_sort_by, "\"#{caption}\"") unless options[:title]
|
||||||
content_tag('th', sort_link(column, caption), options)
|
content_tag('th', sort_link(column, caption, default_order), options)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -16,12 +16,13 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class QueryColumn
|
class QueryColumn
|
||||||
attr_accessor :name, :sortable
|
attr_accessor :name, :sortable, :default_order
|
||||||
include GLoc
|
include GLoc
|
||||||
|
|
||||||
def initialize(name, options={})
|
def initialize(name, options={})
|
||||||
self.name = name
|
self.name = name
|
||||||
self.sortable = options[:sortable]
|
self.sortable = options[:sortable]
|
||||||
|
self.default_order = options[:default_order]
|
||||||
end
|
end
|
||||||
|
|
||||||
def caption
|
def caption
|
||||||
|
@ -94,18 +95,18 @@ class Query < ActiveRecord::Base
|
||||||
@@available_columns = [
|
@@available_columns = [
|
||||||
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position"),
|
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position"),
|
||||||
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position"),
|
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position"),
|
||||||
QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position"),
|
QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position", :default_order => 'desc'),
|
||||||
QueryColumn.new(:subject),
|
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
|
||||||
QueryColumn.new(:author),
|
QueryColumn.new(:author),
|
||||||
QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname"),
|
QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname"),
|
||||||
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on"),
|
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
|
||||||
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"),
|
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"),
|
||||||
QueryColumn.new(:fixed_version),
|
QueryColumn.new(:fixed_version),
|
||||||
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
|
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
|
||||||
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
|
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
|
||||||
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
|
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
|
||||||
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"),
|
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"),
|
||||||
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on"),
|
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
|
||||||
]
|
]
|
||||||
cattr_reader :available_columns
|
cattr_reader :available_columns
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
<%= sort_header_tag('name', :caption => l(:label_project)) %>
|
<%= sort_header_tag('name', :caption => l(:label_project)) %>
|
||||||
<th><%=l(:field_description)%></th>
|
<th><%=l(:field_description)%></th>
|
||||||
<th><%=l(:field_is_public)%></th>
|
|
||||||
<th><%=l(:label_subproject_plural)%></th>
|
<th><%=l(:label_subproject_plural)%></th>
|
||||||
<%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
|
<%= sort_header_tag('is_public', :caption => l(:field_is_public), :default_order => 'desc') %>
|
||||||
|
<%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr></thead>
|
</tr></thead>
|
||||||
|
@ -28,8 +28,8 @@
|
||||||
<tr class="<%= cycle("odd", "even") %>">
|
<tr class="<%= cycle("odd", "even") %>">
|
||||||
<td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %>
|
<td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %>
|
||||||
<td><%= textilizable project.short_description, :project => project %>
|
<td><%= textilizable project.short_description, :project => project %>
|
||||||
<td align="center"><%= image_tag 'true.png' if project.is_public? %>
|
|
||||||
<td align="center"><%= project.children.size %>
|
<td align="center"><%= project.children.size %>
|
||||||
|
<td align="center"><%= image_tag 'true.png' if project.is_public? %>
|
||||||
<td align="center"><%= format_date(project.created_on) %>
|
<td align="center"><%= format_date(project.created_on) %>
|
||||||
<td align="center" style="width:10%">
|
<td align="center" style="width:10%">
|
||||||
<small>
|
<small>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
:method => :get},
|
:method => :get},
|
||||||
{:title => l(:label_bulk_edit_selected_issues)}) if @project && User.current.allowed_to?(:edit_issues, @project) %>
|
{:title => l(:label_bulk_edit_selected_issues)}) if @project && User.current.allowed_to?(:edit_issues, @project) %>
|
||||||
</th>
|
</th>
|
||||||
<%= sort_header_tag("#{Issue.table_name}.id", :caption => '#') %>
|
<%= sort_header_tag("#{Issue.table_name}.id", :caption => '#', :default_order => 'desc') %>
|
||||||
<% query.columns.each do |column| %>
|
<% query.columns.each do |column| %>
|
||||||
<%= column_header(column) %>
|
<%= column_header(column) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
<%= sort_header_tag('login', :caption => l(:field_login)) %>
|
<%= sort_header_tag('login', :caption => l(:field_login)) %>
|
||||||
<%= sort_header_tag('firstname', :caption => l(:field_firstname)) %>
|
<%= sort_header_tag('firstname', :caption => l(:field_firstname)) %>
|
||||||
<%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
|
<%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
|
||||||
<th><%=l(:field_mail)%></th>
|
<%= sort_header_tag('mail', :caption => l(:field_mail)) %>
|
||||||
<%= sort_header_tag('admin', :caption => l(:field_admin)) %>
|
<%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %>
|
||||||
<%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
|
<%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
|
||||||
<%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on)) %>
|
<%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr></thead>
|
</tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
Loading…
Reference in New Issue