Revision 14207
Added by Jean-Philippe Lang about 10 years ago
branches/3.0-stable/app/helpers/sort_helper.rb | ||
---|---|---|
85 | 85 |
sql = @criteria.collect do |k,o| |
86 | 86 |
if s = @available_criteria[k] |
87 | 87 |
s = [s] unless s.is_a?(Array) |
88 |
(o ? s : s.collect {|c| append_desc(c)})
|
|
88 |
s.collect {|c| append_order(c, o ? "ASC" : "DESC")}
|
|
89 | 89 |
end |
90 | 90 |
end.flatten.compact |
91 | 91 |
sql.blank? ? nil : sql |
... | ... | |
129 | 129 |
self |
130 | 130 |
end |
131 | 131 |
|
132 |
# Appends DESC to the sort criterion unless it has a fixed order |
|
133 |
def append_desc(criterion)
|
|
132 |
# Appends ASC/DESC to the sort criterion unless it has a fixed order
|
|
133 |
def append_order(criterion, order)
|
|
134 | 134 |
if criterion =~ / (asc|desc)$/i |
135 | 135 |
criterion |
136 | 136 |
else |
137 |
"#{criterion} DESC"
|
|
137 |
"#{criterion} #{order}"
|
|
138 | 138 |
end |
139 | 139 |
end |
140 |
|
|
141 |
# Appends DESC to the sort criterion unless it has a fixed order |
|
142 |
def append_desc(criterion) |
|
143 |
append_order(criterion, "DESC") |
|
144 |
end |
|
140 | 145 |
end |
141 | 146 |
|
142 | 147 |
def sort_name |
branches/3.0-stable/test/functional/issues_controller_test.rb | ||
---|---|---|
265 | 265 |
assert_not_nil assigns(:issue_count_by_group) |
266 | 266 |
end |
267 | 267 |
|
268 |
def test_index_with_query_grouped_and_sorted_by_category |
|
269 |
get :index, :project_id => 1, :set_filter => 1, :group_by => "category", :sort => "category" |
|
270 |
assert_response :success |
|
271 |
assert_template 'index' |
|
272 |
assert_not_nil assigns(:issues) |
|
273 |
assert_not_nil assigns(:issue_count_by_group) |
|
274 |
end |
|
275 |
|
|
268 | 276 |
def test_index_with_query_grouped_by_list_custom_field |
269 | 277 |
get :index, :project_id => 1, :query_id => 9 |
270 | 278 |
assert_response :success |
branches/3.0-stable/test/unit/helpers/sort_helper_test.rb | ||
---|---|---|
54 | 54 |
sort_init 'attr1', 'desc' |
55 | 55 |
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
56 | 56 |
|
57 |
assert_equal ['table1.attr1', 'table2.attr2 DESC'], sort_clause |
|
57 |
assert_equal ['table1.attr1 ASC', 'table2.attr2 DESC'], sort_clause
|
|
58 | 58 |
assert_equal 'attr1,attr2:desc', @session['foo_bar_sort'] |
59 | 59 |
end |
60 | 60 |
|
... | ... | |
74 | 74 |
sort_init 'attr1', 'desc' |
75 | 75 |
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'}) |
76 | 76 |
|
77 |
assert_equal ['table1.attr1', 'table2.attr2'], sort_clause
|
|
77 |
assert_equal ['table1.attr1 ASC', 'table2.attr2 ASC'], sort_clause
|
|
78 | 78 |
assert_equal 'attr1,attr2', @session['foo_bar_sort'] |
79 | 79 |
end |
80 | 80 |
|
Also available in: Unified diff
Merged r14165 and r14166 (#19544).