Merge pull request #1122 from ZmagoD/zd_SCI_2339

repository when sorting/searching bug fix [SCI-2339]
This commit is contained in:
Zmago Devetak 2018-05-03 12:05:39 +02:00 committed by GitHub
commit 4fe4fea4fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions

View file

@ -32,15 +32,25 @@ module SearchableModel
else
a_query = Regexp.escape(query)
end
a_query = '\\y(' + a_query + ')\\y'
# quick fix to enable searching by repositoy_row id
id_index = { present: false }
where_str =
(attrs.map.with_index do |a, i|
"(trim_html_tags(#{a})) #{like} :t#{i} OR "
if a == 'repository_rows.id'
id_index = { present: true, val: i }
"(#{a}) = :t#{i} OR "
else
"(trim_html_tags(#{a})) #{like} :t#{i} OR "
end
end
).join[0..-5]
vals = (
attrs.map.with_index do |_, i|
["t#{i}".to_sym, a_query]
if id_index[:present] && id_index[:val] == i
["t#{i}".to_sym, a_query.to_i]
else
["t#{i}".to_sym, '\\y(' + a_query + ')\\y']
end
end
).to_h
@ -53,14 +63,25 @@ module SearchableModel
if query.count(' ') > 0
unless attrs.empty?
a_query = query.split.map { |a| "%#{sanitize_sql_like(a)}%" }
# quick fix to enable searching by repositoy_row id
id_index = { present: false }
where_str =
(attrs.map.with_index do |a, i|
"(trim_html_tags(#{a})) #{like} ANY (array[:t#{i}]) OR "
if a == 'repository_rows.id'
id_index = { present: true, val: i }
"(#{a}) IN (:t#{i}) OR "
else
"(trim_html_tags(#{a})) #{like} ANY (array[:t#{i}]) OR "
end
end
).join[0..-5]
vals = (
attrs.map.with_index do |_, i|
["t#{i}".to_sym, a_query]
if id_index[:present] && id_index[:val] == i
["t#{i}".to_sym, a_query.map(&:to_i)]
else
["t#{i}".to_sym, a_query]
end
end
).to_h

View file

@ -123,6 +123,8 @@ class RepositoryDatatableService
type = RepositoryColumn.find_by_id(id)
return records unless type
return select_type(type.data_type, records, id, dir)
elsif sortable_columns[column_id - 1] == 'users.full_name'
return records.joins(:created_by).order("users.full_name #{dir}")
else
return records.order(
"#{sortable_columns[column_id - 1]} #{dir}"