[#3477] Clarify variable name

This commit is contained in:
Frederic Merizen 2019-02-26 16:11:02 +01:00 committed by Frederic Merizen
parent cf2b40f6a0
commit 35d5322a9b

View file

@ -103,14 +103,14 @@ class ProcedurePresentation < ApplicationRecord
dossiers.each { |dossier| assert_matching_procedure(dossier) } dossiers.each { |dossier| assert_matching_procedure(dossier) }
filters[statut].group_by { |filter| filter.slice('table', 'column') } .map do |field, filters| filters[statut].group_by { |filter| filter.slice('table', 'column') } .map do |field, filters|
table = field['table'] table = field['table']
column = sanitized_column(field) table_column = sanitized_column(field)
values = filters.pluck('value') values = filters.pluck('value')
case table case table
when 'self' when 'self'
dates = values.map { |v| Time.zone.parse(v).beginning_of_day rescue nil } dates = values.map { |v| Time.zone.parse(v).beginning_of_day rescue nil }
Filter.new( Filter.new(
dossiers dossiers
).where_datetime_matches(column, dates) ).where_datetime_matches(table_column, dates)
when 'type_de_champ', 'type_de_champ_private' when 'type_de_champ', 'type_de_champ_private'
relation = table == 'type_de_champ' ? :champs : :champs_private relation = table == 'type_de_champ' ? :champs : :champs_private
Filter.new( Filter.new(
@ -123,18 +123,18 @@ class ProcedurePresentation < ApplicationRecord
dates = values.map { |v| v.to_date rescue nil } dates = values.map { |v| v.to_date rescue nil }
Filter.new( Filter.new(
dossiers.includes(table) dossiers.includes(table)
).where_equals(column, dates) ).where_equals(table_column, dates)
else else
Filter.new( Filter.new(
dossiers dossiers
.includes(table) .includes(table)
).where_ilike(column, values) ).where_ilike(table_column, values)
end end
when 'user', 'individual' when 'user', 'individual'
Filter.new( Filter.new(
dossiers dossiers
.includes(table) .includes(table)
).where_ilike(column, values) ).where_ilike(table_column, values)
end.pluck(:id) end.pluck(:id)
end.reduce(:&) end.reduce(:&)
end end
@ -174,23 +174,23 @@ class ProcedurePresentation < ApplicationRecord
@dossiers = dossiers @dossiers = dossiers
end end
def where_datetime_matches(column, dates) def where_datetime_matches(table_column, dates)
dates = dates.compact.flat_map { |d| [d, d + 1.day] } dates = dates.compact.flat_map { |d| [d, d + 1.day] }
if dates.present? if dates.present?
q = Array.new(dates.count / 2, "(#{column} BETWEEN ? AND ?)").join(' OR ') q = Array.new(dates.count / 2, "(#{table_column} BETWEEN ? AND ?)").join(' OR ')
@dossiers.where(q, *dates) @dossiers.where(q, *dates)
else else
[] []
end end
end end
def where_ilike(column, values) def where_ilike(table_column, values)
q = Array.new(values.count, "(#{column} ILIKE ?)").join(' OR ') q = Array.new(values.count, "(#{table_column} ILIKE ?)").join(' OR ')
@dossiers.where(q, *(values.map { |value| "%#{value}%" })) @dossiers.where(q, *(values.map { |value| "%#{value}%" }))
end end
def where_equals(column, values) def where_equals(table_column, values)
@dossiers.where("#{column} IN (?)", values) @dossiers.where("#{table_column} IN (?)", values)
end end
end end