Project

General

Profile

Patch #36438 » 0001-nulls-last-first-option-for-sorting-order.patch

Dmitry Makurin , 2022-01-17 13:29

View differences:

app/views/queries/_form.html.erb
<%= label_tag "query_sort_criteria_direction_" + i.to_s,
l(:description_query_sort_criteria_direction), :class => "hidden-for-sighted" %>
<%= select_tag("query[sort_criteria][#{i}][]",
options_for_select([[], [l(:label_ascending), 'asc'], [l(:label_descending), 'desc']], @query.sort_criteria_order(i)),
options_for_select(
[
[],
[l(:label_ascending), 'asc'],
[l(:label_descending), 'desc'],
[l(:label_ascending_null_last), 'asc nulls last'],
[l(:label_descending_null_first), 'desc nulls first']
],
@query.sort_criteria_order(i)
),
:id => "query_sort_criteria_direction_" + i.to_s) %>
<br />
<% end %>
config/locales/en.yml
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."
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."
text_project_destroy_enter_identifier: "To confirm, please enter the project's identifier (%{identifier}) below."
label_ascending_null_last: Ascending nulls last
label_descending_null_first: Descending nulls first
config/locales/ru.yml
label_subtask: Subtask
label_default_query: Default query
field_default_project_query: Default project query
label_ascending_null_last: По возрастанию с пустыми значениями в конце
label_descending_null_first: По убыванию с пустыми значениями в начале
lib/redmine/sort_criteria.rb
end
def to_param
self.collect {|k,o| k + (o == 'desc' ? ':desc' : '')}.join(',')
collect do |k, o|
k + (case o
when 'desc'
':desc'
when /nulls (first|last)/
":#{o}"
else
''
end)
end.join(',')
end
def to_a
......
private
def normalize!
self.reject! {|s| s.first.blank?}
self.uniq! {|s| s.first}
self.collect! {|s| s = Array(s); [s.first, (s.last == false || s.last.to_s == 'desc') ? 'desc' : 'asc']}
self.replace self.first(3)
reject! {|s| s.first.blank? }
uniq! {|s| s.first }
collect! do |s|
s = Array(s)
[s.first,
if s.last == false || s.last.to_s == 'desc' # if sort is empty or desc => desc
'desc'
elsif !s.last.blank? && s.size > 1 && /nulls (first|last)/.match?(s.last) # nulls sort
s.last
else
'asc'
end]
end
replace first(3)
end
# Appends ASC/DESC to the sort criterion unless it has a fixed order
test/helpers/sort_helper_test.rb
assert_equal 'sort-by-foo-bar sort-asc', sort_css_classes
end
def test_nulls_sort
sort_init 'attr1', 'desc nulls first'
sort_update(['attr1', 'attr2'])
assert_equal ['attr1 DESC NULLS FIRST'], sort_clause
end
def test_params_nulls_sort
@sort_param = 'attr1,attr2:desc nulls last'
sort_init 'attr1', 'desc'
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
assert_equal ['table1.attr1 ASC', 'table2.attr2 DESC NULLS LAST'], sort_clause
assert_equal 'attr1,attr2:desc nulls last', @session['foo_bar_sort']
end
private
def controller_name; 'foo'; end
(3-3/3)