From e5da1d7111ca718b4e12ed971866a53f4ea594ea Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 30 Oct 2020 14:34:00 +0100 Subject: [PATCH] move remove_filter --- app/controllers/instructeurs/procedures_controller.rb | 7 +------ app/models/procedure_presentation.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index f22d44d38..e389ab07d 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -156,12 +156,7 @@ module Instructeurs end def remove_filter - filters = procedure_presentation.filters - - to_remove = params.values_at(:table, :column, :value) - filters[statut].reject! { |filter| filter.values_at('table', 'column', 'value') == to_remove } - - procedure_presentation.update(filters: filters) + procedure_presentation.remove_filter(statut, params[:field], params[:value]) redirect_back(fallback_location: instructeur_procedure_url(procedure)) end diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index d0eb61ec6..7ee650812 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -217,6 +217,16 @@ class ProcedurePresentation < ApplicationRecord end end + def remove_filter(statut, field, value) + table, column = field.split('/') + + updated_filters = filters.dup + updated_filters[statut] = filters[statut].reject do |filter| + filter.values_at('table', 'column', 'value') == [table, column, value] + end + + update!(filters: updated_filters) + end def update_displayed_fields(values) if values.nil?