Project

General

Profile

Patch #25066 » Added_null_placement_at_order_statement_v2.patch

Andrey Lobanov (RedSoft), 2017-02-21 13:34

View differences:

app/models/query.rb (date 1487680385000)
arg = arg.keys.sort.collect {|k| arg[k]}
end
if arg
c = arg.select {|k,o| !k.to_s.blank?}.slice(0,3).collect {|k,o| [k.to_s, (o == 'desc' || o == false) ? 'desc' : 'asc']}
c = arg.select { |k, o| !k.to_s.blank? }.slice(0, 3).collect { |k, o| [k.to_s, o.to_s.empty? ? 'asc' : o.to_s] }
end
write_attribute(:sort_criteria, c)
end
......
" SELECT customized_id FROM #{CustomValue.table_name}" +
" WHERE customized_type='#{target_class}' AND custom_field_id=#{chained_custom_field_id}" +
" AND #{sql_for_field(field, operator, value, CustomValue.table_name, 'value')}))"
end
def sql_for_custom_field_attribute(field, operator, value, custom_field_id, attribute)
config/locales/ar.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/az.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/bg.yml (date 1487680385000)
description_date_from: Въведете начална дата
description_date_to: Въведете крайна дата
text_repository_identifier_info: 'Позволени са малки букви (a-z), цифри, тирета и _.<br />Промяна след създаването му не е възможна.'
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/bs.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/ca.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/cs.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/da.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/de.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/el.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/en.yml (date 1487680385000)
label_sort: Sort
label_ascending: Ascending
label_descending: Descending
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
label_date_from_to: From %{start} to %{end}
label_wiki_content_added: Wiki page added
label_wiki_content_updated: Wiki page updated
config/locales/es.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/et.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/eu.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/fa.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top\
config/locales/fi.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/fr.yml (date 1487680385000)
label_no_preview: No preview available
label_user_mail_option_only_assigned: Only for things I watch or I am assigned to
label_user_mail_option_only_owner: Only for things I watch or I am the owner of
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/gl.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/he.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/hr.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/hu.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/id.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/it.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/ja.yml (date 1487680385000)
field_updated_by: 更新者
field_last_updated_by: 最終更新者
field_full_width_layout: ワイド表示
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/ko.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/lt.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/lv.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/mk.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/mn.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/nl.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/no.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/pl.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/pt.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/ro.yml (date 1487680385000)
month_names: [~, Ianuarie, Februarie, Martie, Aprilie, Mai, Iunie, Iulie, August, Septembrie, Octombrie, Noiembrie, Decembrie]
abbr_month_names: [~, Ian, Feb, Mar, Apr, Mai, Iun, Iul, Aug, Sep, Oct, Noi, Dec]
order:
- :day
- :month
- :day- :month
- :year
time:
......
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/ru.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: По возрастанию с пустыми значениями в конце
label_descending_nulls_first: По убыванию с пустыми значениями в начале
config/locales/sk.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/sl.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/sq.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/sr.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/sv.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/th.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/tr.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/uk.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/vi.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/zh.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
lib/redmine/database.rb (date 1487680385000)
(ActiveRecord::Base.connection.adapter_name =~ /mysql/i).present?
end
def sqlite3?
(ActiveRecord::Base.connection.adapter_name =~ /sqlite/i).present?
end
def sqlserver?
(ActiveRecord::Base.connection.adapter_name =~ /sqlserver/i).present?
end
# Returns a SQL statement for case/accent (if possible) insensitive match
def like(left, right, options={})
neg = (options[:match] == false ? 'NOT ' : '')
......
end
end
def firebird?
(ActiveRecord::Base.connection.adapter_name =~ /firebird/i).present?
end
# Resets database information
def reset
@postgresql_unaccent = nil
config/locales/en-GB.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/es-PA.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/pt-BR.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/sr-YU.yml (date 1487680385000)
field_updated_by: Updated by
field_last_updated_by: Last updated by
field_full_width_layout: Full width layout
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
config/locales/zh-TW.yml (date 1487680385000)
description_date_from: 輸入起始日期
description_date_to: 輸入結束日期
text_repository_identifier_info: '僅允許使用小寫英文字母 (a-z), 阿拉伯數字, 虛線與底線。<br />一旦儲存之後, 代碼便無法再次被更改。'
label_ascending_nulls_last: Ascending with null values at the end
label_descending_nulls_first: Descending with null values at the top
app/helpers/sort_helper.rb (date 1487680385000)
def available_criteria=(criteria)
unless criteria.is_a?(Hash)
criteria = criteria.inject({}) {|h,k| h[k] = k; h}
criteria = criteria.inject({}) { |h, k| h[k] = k; h }
end
@available_criteria = criteria
end
def from_param(param)
@criteria = param.to_s.split(',').collect {|s| s.split(':')[0..1]}
@criteria = param.to_s.split(',').collect { |s| s.split(':')[0..1] }
normalize!
end
......
end
def to_param
@criteria.collect {|k,o| k + (o ? '' : ':desc')}.join(',')
@criteria.collect { |k, o| k + ":#{o.to_s}" }.join(',')
end
# Returns an array of SQL fragments used to sort the list
def to_sql
sql = @criteria.collect do |k,o|
sql = @criteria.collect do |k, o|
if s = @available_criteria[k]
s = [s] unless s.is_a?(Array)
s.collect {|c| append_order(c, o ? "ASC" : "DESC")}
s.collect { |c| append_order(c, o.to_s.upcase) }
end
end.flatten.compact
sql.blank? ? nil : sql
......
end
def add!(key, asc)
@criteria.delete_if {|k,o| k == key}
@criteria.delete_if { |k, o| k == key }
@criteria = [[key, asc]] + @criteria
normalize!
end
......
end
def first_asc?
@criteria.first && @criteria.first.last
@criteria.first && @criteria.first.last.to_s.downcase.start_with?("asc")
end
def empty?
......
def normalize!
@criteria ||= []
@criteria = @criteria.collect {|s| s = Array(s); [s.first, (s.last == false || s.last == 'desc') ? false : true]}
@criteria = @criteria.select {|k,o| @available_criteria.has_key?(k)} if @available_criteria
@criteria = @criteria.collect { |s| s = Array(s); [s.first, s[1].nil? ? 'asc' :
(s.last.to_s.downcase.start_with?('desc', 'asc')? s.last.to_s : 'asc')] }
@criteria = @criteria.select { |k, o| @available_criteria.has_key?(k) } if @available_criteria
@criteria.slice!(3)
self
end
......
if criterion =~ / (asc|desc)$/i
criterion
else
"#{criterion} #{order}"
if (order =~ /nulls/i).present?
t = order.to_s.split(' ')
sort_order = t.first
nulls_last = t.last.to_s.downcase.eql?("last")
if Redmine::Database.mysql?
"ISNULL(#{criterion}) #{nulls_last ? "ASC" : "DESC"}, #{criterion} #{sort_order}"
elsif Redmine::Database.sqlserver? || Redmine::Database.sqlite3?
"#{criterion} IS NULL #{nulls_last ? "ASC" : "DESC"}, #{criterion} #{sort_order}"
else
"#{criterion} #{order}"
end
else
"#{criterion} #{order}"
end
end
end
......
#
def sort_init(*args)
case args.size
when 1
@sort_default = args.first.is_a?(Array) ? args.first : [[args.first]]
when 2
@sort_default = [[args.first, args.last]]
else
raise ArgumentError
when 1
@sort_default = args.first.is_a?(Array) ? args.first : [[args.first]]
when 2
@sort_default = [[args.first, args.last]]
else
raise ArgumentError
end
end
......
end
caption = column.to_s.humanize unless caption
sort_options = { :sort => @sort_criteria.add(column.to_s, order).to_param }
sort_options = {:sort => @sort_criteria.add(column.to_s, order).to_param}
link_to(caption, {:params => request.query_parameters.merge(sort_options)}, :class => css)
end
lib/redmine/field_format.rb (date 1487680385000)
# objects by their value of the custom field.
# Returns nil if the custom field can not be used for sorting.
def order_statement(custom_field)
# COALESCE is here to make sure that blank and NULL values are sorted equally
"COALESCE(#{join_alias custom_field}.value, '')"
"#{join_alias custom_field}.value" #COALESCE removed to allow null placement on order
end
# Returns a GROUP BY clause that can used to group by custom value
app/views/queries/_form.html.erb (date 1487680385000)
<%= 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_nulls_last), 'asc nulls last'], [l(:label_descending_nulls_first), 'desc nulls first']], @query.sort_criteria_order(i)),
:id => "query_sort_criteria_direction_" + i.to_s) %>
<br />
<% end %>
(2-2/3)