Merge pull request #1050 from sgmap/fix-filtering

Fix filtering
This commit is contained in:
gregoirenovel 2017-12-07 15:17:41 +01:00 committed by GitHub
commit 5521983472
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -144,18 +144,20 @@ module NewGestionnaire
end
def add_filter
filters = procedure_presentation.filters
table, column = params[:field].split('/')
label = procedure.fields.find { |c| c['table'] == table && c['column'] == column }['label']
if params[:value].present?
filters = procedure_presentation.filters
table, column = params[:field].split('/')
label = procedure.fields.find { |c| c['table'] == table && c['column'] == column }['label']
filters[statut] << {
'label' => label,
'table' => table,
'column' => column,
'value' => params[:value]
}
filters[statut] << {
'label' => label,
'table' => table,
'column' => column,
'value' => params[:value]
}
procedure_presentation.update_attributes(filters: filters.to_json)
procedure_presentation.update_attributes(filters: filters.to_json)
end
redirect_back(fallback_location: procedure_url(procedure))
end
@ -236,9 +238,15 @@ module NewGestionnaire
.where("champs.value LIKE ?", "%#{filter['value']}%")
when 'user', 'etablissement', 'entreprise'
dossiers
if filter['column'] == 'date_creation'
dossiers
.includes(filter['table'])
.where("#{filter['table'].pluralize}.#{filter['column']} = ?", filter['value'].to_date)
else
dossiers
.includes(filter['table'])
.where("#{filter['table'].pluralize}.#{filter['column']} LIKE ?", "%#{filter['value']}%")
end
end.pluck(:id)
end.reduce(:&)