]> source.dussan.org Git - redmine.git/commitdiff
Adds css classes to get sort order on the issue list (#17993).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 4 Oct 2014 09:36:35 +0000 (09:36 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 4 Oct 2014 09:36:35 +0000 (09:36 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13425 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/sort_helper.rb
app/views/issues/_list.html.erb
test/functional/issues_controller_test.rb
test/unit/helpers/sort_helper_test.rb

index 13beed3c27597c84b4e265bb5911eaffba0675c9..cbdc41883817a15976b6d3e713b338c2d220aa4c 100644 (file)
@@ -239,5 +239,17 @@ module SortHelper
     options[:title] = l(:label_sort_by, "\"#{caption}\"") unless options[:title]
     content_tag('th', sort_link(column, caption, default_order), options)
   end
+
+  # Returns the css classes for the current sort order
+  #
+  # Example:
+  #
+  #   sort_css_classes
+  #   # => "sort-by-created-on sort-desc"
+  def sort_css_classes
+    if @sort_criteria.first_key
+      "sort-by-#{@sort_criteria.first_key.to_s.dasherize} sort-#{@sort_criteria.first_asc? ? 'asc' : 'desc'}"
+    end
+  end
 end
 
index 17bf99623294a7e893adaafb4ae00848022b90de..fb190d42b66dd1bf30f23091e389a15a2241095d 100644 (file)
@@ -1,7 +1,7 @@
 <%= form_tag({}) do -%>
 <%= hidden_field_tag 'back_url', url_for(params), :id => nil %>
 <div class="autoscroll">
-<table class="list issues">
+<table class="list issues <%= sort_css_classes %>">
   <thead>
     <tr>
       <th class="checkbox hide-when-print">
index bf1397c681b6ddbe8957a0c281c9198773a259d7..44c43e3b2a27843edd50c4a755ba54745b8f8aa9 100644 (file)
@@ -624,6 +624,7 @@ class IssuesControllerTest < ActionController::TestCase
     assert_not_nil issues
     assert !issues.empty?
     assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
+    assert_select 'table.issues.sort-by-tracker.sort-asc'
   end
 
   def test_index_sort_by_field_not_included_in_columns
@@ -636,6 +637,7 @@ class IssuesControllerTest < ActionController::TestCase
     assert_response :success
     assignees = assigns(:issues).collect(&:assigned_to).compact
     assert_equal assignees.sort, assignees
+    assert_select 'table.issues.sort-by-assigned-to.sort-asc'
   end
   
   def test_index_sort_by_assigned_to_desc
@@ -643,6 +645,7 @@ class IssuesControllerTest < ActionController::TestCase
     assert_response :success
     assignees = assigns(:issues).collect(&:assigned_to).compact
     assert_equal assignees.sort.reverse, assignees
+    assert_select 'table.issues.sort-by-assigned-to.sort-desc'
   end
   
   def test_index_group_by_assigned_to
index e66a591efbf20a1be56d06fe74e2376226ba3bee..0c79f8c2a28e5381515046d347e7e38d90f7e711 100644 (file)
@@ -78,6 +78,28 @@ class SortHelperTest < ActionView::TestCase
     assert_equal 'attr1,attr2', @session['foo_bar_sort']
   end
 
+  def test_sort_css_without_params_should_use_default_sort
+    sort_init 'attr1', 'desc'
+    sort_update(['attr1', 'attr2'])
+
+    assert_equal 'sort-by-attr1 sort-desc', sort_css_classes
+  end
+
+  def test_sort_css_should_use_params
+    @sort_param = 'attr2,attr1'
+    sort_init 'attr1', 'desc'
+    sort_update(['attr1', 'attr2'])
+
+    assert_equal 'sort-by-attr2 sort-asc', sort_css_classes
+  end
+
+  def test_sort_css_should_dasherize_sort_name
+    sort_init 'foo_bar'
+    sort_update(['foo_bar'])
+
+    assert_equal 'sort-by-foo-bar sort-asc', sort_css_classes
+  end
+
   private
 
   def controller_name; 'foo'; end