remove now useless add_filters and remove_filters

This commit is contained in:
simon lehericey 2024-09-27 15:25:00 +02:00
parent 72c389161a
commit 4c5d7e2950
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
3 changed files with 0 additions and 131 deletions

View file

@ -166,12 +166,6 @@ module Instructeurs
@column = procedure.find_column(h_id:)
end
def remove_filter
procedure_presentation.remove_filter(statut, params[:column], params[:value])
redirect_back(fallback_location: instructeur_procedure_url(procedure))
end
def download_export
groupe_instructeurs = current_instructeur
.groupe_instructeurs

View file

@ -18,7 +18,6 @@ class ProcedurePresentation < ApplicationRecord
delegate :procedure, :instructeur, to: :assign_to
validate :check_allowed_displayed_fields
validate :check_allowed_filter_columns
validate :check_filters_max_length
validate :check_filters_max_integer
@ -91,46 +90,6 @@ class ProcedurePresentation < ApplicationRecord
nil
end
def add_filter(statut, column_id, value)
h_id = JSON.parse(column_id, symbolize_names: true)
if value.present?
column = procedure.find_column(h_id:)
case column.table
when TYPE_DE_CHAMP
value = find_type_de_champ(column.column).dynamic_type.human_to_filter(value)
end
updated_filters = filters.dup
updated_filters[statut] << {
'label' => column.label,
TABLE => column.table,
COLUMN => column.column,
'value_column' => column.value_column,
'value' => value
}
filters_for(statut) << { id: h_id, filter: value }
update(filters: updated_filters)
end
end
def remove_filter(statut, column_id, value)
h_id = JSON.parse(column_id, symbolize_names: true)
column = procedure.find_column(h_id:)
updated_filters = filters.dup
updated_filters[statut] = filters[statut].reject do |filter|
filter.values_at(TABLE, COLUMN, 'value') == [column.table, column.column, value]
end
collection = filters_for(statut)
collection.delete(collection.find { sym_h = _1.deep_symbolize_keys; sym_h[:id] == h_id && sym_h[:filter] == value })
update!(filters: updated_filters)
end
def update_displayed_fields(column_ids)
h_ids = Array.wrap(column_ids).map { |id| JSON.parse(id, symbolize_names: true) }
columns = h_ids.map { |h_id| procedure.find_column(h_id:) }
@ -278,15 +237,6 @@ class ProcedurePresentation < ApplicationRecord
end
end
def check_allowed_filter_columns
filters.each do |key, columns|
return true if key == 'migrated'
columns.each do |column|
check_allowed_field(:filters, column)
end
end
end
def check_allowed_field(kind, field, extra_columns = {})
table, column = field.values_at(TABLE, COLUMN)
if !valid_column?(table, column, extra_columns)

View file

@ -809,81 +809,6 @@ describe ProcedurePresentation do
end
end
describe "#add_filter" do
let(:filters) { { "suivis" => [] } }
context 'when type_de_champ yes_no' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no, libelle: 'oui ou non' }]) }
it 'should downcase and transform value' do
column_id = procedure.find_column(label: 'oui ou non').id
procedure_presentation.add_filter("suivis", column_id, "Oui")
expect(procedure_presentation.filters).to eq({
"suivis" =>
[
{ "label" => first_type_de_champ.libelle, "table" => "type_de_champ", "column" => first_type_de_champ_id, "value" => "true", "value_column" => "value" }
]
})
suivis = procedure_presentation.suivis_filters.map { [_1['id'], _1['filter']] }
expect(suivis).to eq([[{ "column_id" => "type_de_champ/#{first_type_de_champ_id}", "procedure_id" => procedure.id }, "true"]])
end
end
context 'when type_de_champ text' do
let(:filters) { { "suivis" => [] } }
let(:column_id) { procedure.find_column(label: first_type_de_champ.libelle).id }
it 'should passthrough value' do
procedure_presentation.add_filter("suivis", column_id, "Oui")
expect(procedure_presentation.filters).to eq({
"suivis" => [
{ "label" => first_type_de_champ.libelle, "table" => "type_de_champ", "column" => first_type_de_champ_id, "value" => "Oui", "value_column" => "value" }
]
})
end
end
context 'when type_de_champ departements' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :departements }]) }
let(:column_id) { procedure.find_column(label: first_type_de_champ.libelle).id }
let(:filters) { { "suivis" => [] } }
it 'should set value_column' do
procedure_presentation.add_filter("suivis", column_id, "13")
expect(procedure_presentation.filters).to eq({
"suivis" => [
{ "label" => first_type_de_champ.libelle, "table" => "type_de_champ", "column" => first_type_de_champ_id, "value" => "13", "value_column" => "external_id" }
]
})
end
end
end
describe "#remove_filter" do
let(:filters) { { "suivis" => [] } }
let(:email_column_id) { procedure.find_column(label: 'Demandeur').id }
before do
procedure_presentation.add_filter("suivis", email_column_id, "a@a.com")
end
it 'should remove filter' do
expect(procedure_presentation.filters).to eq({ "suivis" => [{ "column" => "email", "label" => "Demandeur", "table" => "user", "value" => "a@a.com", "value_column" => "value" }] })
expect(procedure_presentation.suivis_filters).to eq([{ "filter" => "a@a.com", "id" => { "column_id" => "user/email", "procedure_id" => procedure.id } }])
procedure_presentation.remove_filter("suivis", email_column_id, "a@a.com")
procedure_presentation.reload
expect(procedure_presentation.filters).to eq({ "suivis" => [] })
expect(procedure_presentation.suivis_filters).to eq([])
end
end
describe '#filtered_sorted_ids' do
let(:procedure_presentation) { create(:procedure_presentation, assign_to:) }
let(:dossier_1) { create(:dossier) }