Patch #36438 » 0001-nulls-last-first-option-for-sorting-order.patch
| app/views/queries/_form.html.erb | ||
|---|---|---|
| 83 | 83 |
<%= label_tag "query_sort_criteria_direction_" + i.to_s, |
| 84 | 84 |
l(:description_query_sort_criteria_direction), :class => "hidden-for-sighted" %> |
| 85 | 85 |
<%= select_tag("query[sort_criteria][#{i}][]",
|
| 86 |
options_for_select([[], [l(:label_ascending), 'asc'], [l(:label_descending), 'desc']], @query.sort_criteria_order(i)), |
|
| 86 |
options_for_select( |
|
| 87 |
[ |
|
| 88 |
[], |
|
| 89 |
[l(:label_ascending), 'asc'], |
|
| 90 |
[l(:label_descending), 'desc'], |
|
| 91 |
[l(:label_ascending_null_last), 'asc nulls last'], |
|
| 92 |
[l(:label_descending_null_first), 'desc nulls first'] |
|
| 93 |
], |
|
| 94 |
@query.sort_criteria_order(i) |
|
| 95 |
), |
|
| 87 | 96 |
:id => "query_sort_criteria_direction_" + i.to_s) %> |
| 88 | 97 |
<br /> |
| 89 | 98 |
<% end %> |
| config/locales/en.yml | ||
|---|---|---|
| 1376 | 1376 |
twofa_text_group_disabled: "This setting is only effective when the global two factor authentication setting is set to 'optional'. Currently, two factor authentication is disabled." |
| 1377 | 1377 |
text_user_destroy_confirmation: "Are you sure you want to delete this user and remove all references to them? This cannot be undone. Often, locking a user instead of deleting them is the better solution. To confirm, please enter their login (%{login}) below."
|
| 1378 | 1378 |
text_project_destroy_enter_identifier: "To confirm, please enter the project's identifier (%{identifier}) below."
|
| 1379 |
label_ascending_null_last: Ascending nulls last |
|
| 1380 |
label_descending_null_first: Descending nulls first |
|
| config/locales/ru.yml | ||
|---|---|---|
| 1513 | 1513 |
label_subtask: Subtask |
| 1514 | 1514 |
label_default_query: Default query |
| 1515 | 1515 |
field_default_project_query: Default project query |
| 1516 |
label_ascending_null_last: По возрастанию с пустыми значениями в конце |
|
| 1517 |
label_descending_null_first: По убыванию с пустыми значениями в начале |
|
| lib/redmine/sort_criteria.rb | ||
|---|---|---|
| 34 | 34 |
end |
| 35 | 35 | |
| 36 | 36 |
def to_param |
| 37 |
self.collect {|k,o| k + (o == 'desc' ? ':desc' : '')}.join(',')
|
|
| 37 |
collect do |k, o| |
|
| 38 |
k + (case o |
|
| 39 |
when 'desc' |
|
| 40 |
':desc' |
|
| 41 |
when /nulls (first|last)/ |
|
| 42 |
":#{o}"
|
|
| 43 |
else |
|
| 44 |
'' |
|
| 45 |
end) |
|
| 46 |
end.join(',')
|
|
| 38 | 47 |
end |
| 39 | 48 | |
| 40 | 49 |
def to_a |
| ... | ... | |
| 89 | 98 |
private |
| 90 | 99 | |
| 91 | 100 |
def normalize! |
| 92 |
self.reject! {|s| s.first.blank?}
|
|
| 93 |
self.uniq! {|s| s.first}
|
|
| 94 |
self.collect! {|s| s = Array(s); [s.first, (s.last == false || s.last.to_s == 'desc') ? 'desc' : 'asc']}
|
|
| 95 |
self.replace self.first(3) |
|
| 101 |
reject! {|s| s.first.blank? }
|
|
| 102 |
uniq! {|s| s.first }
|
|
| 103 |
collect! do |s| |
|
| 104 |
s = Array(s) |
|
| 105 |
[s.first, |
|
| 106 |
if s.last == false || s.last.to_s == 'desc' # if sort is empty or desc => desc |
|
| 107 |
'desc' |
|
| 108 |
elsif !s.last.blank? && s.size > 1 && /nulls (first|last)/.match?(s.last) # nulls sort |
|
| 109 |
s.last |
|
| 110 |
else |
|
| 111 |
'asc' |
|
| 112 |
end] |
|
| 113 |
end |
|
| 114 |
replace first(3) |
|
| 96 | 115 |
end |
| 97 | 116 | |
| 98 | 117 |
# Appends ASC/DESC to the sort criterion unless it has a fixed order |
| test/helpers/sort_helper_test.rb | ||
|---|---|---|
| 102 | 102 |
assert_equal 'sort-by-foo-bar sort-asc', sort_css_classes |
| 103 | 103 |
end |
| 104 | 104 | |
| 105 |
def test_nulls_sort |
|
| 106 |
sort_init 'attr1', 'desc nulls first' |
|
| 107 |
sort_update(['attr1', 'attr2']) |
|
| 108 | ||
| 109 |
assert_equal ['attr1 DESC NULLS FIRST'], sort_clause |
|
| 110 |
end |
|
| 111 | ||
| 112 |
def test_params_nulls_sort |
|
| 113 |
@sort_param = 'attr1,attr2:desc nulls last' |
|
| 114 | ||
| 115 |
sort_init 'attr1', 'desc' |
|
| 116 |
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
|
|
| 117 | ||
| 118 |
assert_equal ['table1.attr1 ASC', 'table2.attr2 DESC NULLS LAST'], sort_clause |
|
| 119 |
assert_equal 'attr1,attr2:desc nulls last', @session['foo_bar_sort'] |
|
| 120 |
end |
|
| 121 | ||
| 105 | 122 |
private |
| 106 | 123 | |
| 107 | 124 |
def controller_name; 'foo'; end |
- « Previous
- 1
- 2
- 3
- Next »