Project

General

Profile

« Previous | Next » 

Revision 1121

More appropriate default sort order on sortable columns.
Sortable column added on issue subject (#580).

View differences:

trunk/app/helpers/queries_helper.rb
22 22
  end
23 23
  
24 24
  def column_header(column)
25
    column.sortable ? sort_header_tag(column.sortable, :caption => column.caption) : content_tag('th', column.caption)
25
    column.sortable ? sort_header_tag(column.sortable, :caption => column.caption,
26
                                                       :default_order => column.default_order) : 
27
                      content_tag('th', column.caption)
26 28
  end
27 29
  
28 30
  def column_content(column, issue)
trunk/app/helpers/sort_helper.rb
92 92
  # - The optional caption explicitly specifies the displayed link text.
93 93
  # - A sort icon image is positioned to the right of the sort link.
94 94
  #
95
  def sort_link(column, caption=nil)
95
  def sort_link(column, caption, default_order)
96 96
    key, order = session[@sort_name][:key], session[@sort_name][:order]
97 97
    if key == column
98 98
      if order.downcase == 'asc'
......
104 104
      end
105 105
    else
106 106
      icon = nil
107
      order = 'desc' # changed for desc order by default
107
      order = default_order
108 108
    end
109 109
    caption = titleize(Inflector::humanize(column)) unless caption
110 110
    
111
    url = {:sort_key => column, :sort_order => order, :issue_id => params[:issue_id], :project_id => params[:project_id]}
111
    url = {:sort_key => column, :sort_order => order, :status => params[:status], 
112
                                                      :issue_id => params[:issue_id], 
113
                                                      :project_id => params[:project_id]}
112 114
    
113 115
    link_to_remote(caption,
114 116
                  {:update => "content", :url => url},
......
138 140
  #
139 141
  def sort_header_tag(column, options = {})
140 142
    caption = options.delete(:caption) || titleize(Inflector::humanize(column))
143
    default_order = options.delete(:default_order) || 'asc'
141 144
    options[:title]= l(:label_sort_by, "\"#{caption}\"") unless options[:title]
142
    content_tag('th', sort_link(column, caption), options)
145
    content_tag('th', sort_link(column, caption, default_order), options)
143 146
  end
144 147

  
145 148
  private
trunk/app/models/query.rb
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 17

  
18 18
class QueryColumn  
19
  attr_accessor :name, :sortable
19
  attr_accessor :name, :sortable, :default_order
20 20
  include GLoc
21 21
  
22 22
  def initialize(name, options={})
23 23
    self.name = name
24 24
    self.sortable = options[:sortable]
25
    self.default_order = options[:default_order]
25 26
  end
26 27
  
27 28
  def caption
......
94 95
  @@available_columns = [
95 96
    QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position"),
96 97
    QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position"),
97
    QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position"),
98
    QueryColumn.new(:subject),
98
    QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position", :default_order => 'desc'),
99
    QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
99 100
    QueryColumn.new(:author),
100 101
    QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname"),
101
    QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on"),
102
    QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
102 103
    QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"),
103 104
    QueryColumn.new(:fixed_version),
104 105
    QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
105 106
    QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
106 107
    QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
107 108
    QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"),
108
    QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on"),
109
    QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
109 110
  ]
110 111
  cattr_reader :available_columns
111 112
  
trunk/app/views/admin/projects.rhtml
17 17
  <thead><tr>
18 18
	<%= sort_header_tag('name', :caption => l(:label_project)) %>
19 19
	<th><%=l(:field_description)%></th>
20
	<th><%=l(:field_is_public)%></th>
21 20
	<th><%=l(:label_subproject_plural)%></th>
22
	<%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
21
	<%= sort_header_tag('is_public', :caption => l(:field_is_public), :default_order => 'desc') %>
22
	<%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
23 23
    <th></th>
24 24
    <th></th>
25 25
  </tr></thead>
......
28 28
  <tr class="<%= cycle("odd", "even") %>">
29 29
	<td><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %>
30 30
	<td><%= textilizable project.short_description, :project => project %>
31
	<td align="center"><%= project.children.size %>
31 32
	<td align="center"><%= image_tag 'true.png' if project.is_public? %>
32
	<td align="center"><%= project.children.size %>
33 33
	<td align="center"><%= format_date(project.created_on) %>
34 34
  <td align="center" style="width:10%">
35 35
    <small>
trunk/app/views/issues/_list.rhtml
6 6
                                :method => :get},
7 7
                               {:title => l(:label_bulk_edit_selected_issues)}) if @project && User.current.allowed_to?(:edit_issues, @project) %>
8 8
        </th>
9
		<%= sort_header_tag("#{Issue.table_name}.id", :caption => '#') %>
9
		<%= sort_header_tag("#{Issue.table_name}.id", :caption => '#', :default_order => 'desc') %>
10 10
        <% query.columns.each do |column| %>
11 11
          <%= column_header(column) %>
12 12
        <% end %>
trunk/app/views/users/list.rhtml
17 17
	<%= sort_header_tag('login', :caption => l(:field_login)) %>
18 18
	<%= sort_header_tag('firstname', :caption => l(:field_firstname)) %>
19 19
	<%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
20
	<th><%=l(:field_mail)%></th>
21
	<%= sort_header_tag('admin', :caption => l(:field_admin)) %>
22
	<%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
23
	<%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on)) %>
20
	<%= sort_header_tag('mail', :caption => l(:field_mail)) %>
21
	<%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %>
22
	<%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
23
	<%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %>
24 24
    <th></th>
25 25
  </tr></thead>
26 26
  <tbody>

Also available in: Unified diff