display filter tags
This commit is contained in:
parent
e9c11a95f1
commit
175f303399
5 changed files with 24 additions and 20 deletions
|
@ -73,7 +73,7 @@ module Instructeurs
|
|||
# Setting it here to make clear that it is used by the view
|
||||
@procedure_presentation = procedure_presentation
|
||||
|
||||
@current_filters = current_filters
|
||||
@current_filters = procedure_presentation.filters_for(statut)
|
||||
@counts = current_instructeur
|
||||
.dossiers_count_summary(groupe_instructeur_ids)
|
||||
.symbolize_keys
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class FilteredColumn
|
||||
attr_reader :column, :filter
|
||||
|
||||
def initialize(column:, filter:)
|
||||
@column = column
|
||||
@filter = filter
|
||||
|
|
|
@ -60,28 +60,28 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def human_value_for_filter(filter)
|
||||
if filter[TABLE] == TYPE_DE_CHAMP
|
||||
find_type_de_champ(filter[COLUMN]).dynamic_type.filter_to_human(filter['value'])
|
||||
elsif filter['column'] == 'state'
|
||||
if filter['value'] == 'pending_correction'
|
||||
def human_value_for_filter(filtered_column)
|
||||
if filtered_column.column.table == TYPE_DE_CHAMP
|
||||
find_type_de_champ(filtered_column.column.column).dynamic_type.filter_to_human(filtered_column.filter)
|
||||
elsif filtered_column.column.column == 'state'
|
||||
if filtered_column.filter == 'pending_correction'
|
||||
Dossier.human_attribute_name("pending_correction.for_instructeur")
|
||||
else
|
||||
Dossier.human_attribute_name("state.#{filter['value']}")
|
||||
Dossier.human_attribute_name("state.#{filtered_column.filter}")
|
||||
end
|
||||
elsif filter['table'] == 'groupe_instructeur' && filter['column'] == 'id'
|
||||
elsif filtered_column.column.table == 'groupe_instructeur' && filtered_column.column.column == 'id'
|
||||
instructeur.groupe_instructeurs
|
||||
.find { _1.id == filter['value'].to_i }&.label || filter['value']
|
||||
.find { _1.id == filtered_column.filter.to_i }&.label || filtered_column.filter
|
||||
else
|
||||
column = procedure.columns.find { _1.table == filter[TABLE] && _1.column == filter[COLUMN] }
|
||||
column = procedure.columns.find { _1.table == filtered_column.column.table && _1.column == filtered_column.column.column }
|
||||
|
||||
if column.type == :date
|
||||
parsed_date = safe_parse_date(filter['value'])
|
||||
parsed_date = safe_parse_date(filtered_column.filter)
|
||||
|
||||
return parsed_date.present? ? I18n.l(parsed_date) : nil
|
||||
end
|
||||
|
||||
filter['value']
|
||||
filtered_column.filter
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
- if current_filters.count > 0
|
||||
.fr-mb-2w
|
||||
- current_filters.group_by { |filter| filter['table'] }.each_with_index do |(table, filters), i|
|
||||
- current_filters.group_by { |filter| filter.column.table }.each_with_index do |(table, filters), i|
|
||||
- if i > 0
|
||||
= " et "
|
||||
- filters.each_with_index do |filter, i|
|
||||
- if i > 0
|
||||
= " ou "
|
||||
= link_to remove_filter_instructeur_procedure_path(procedure, { statut: statut, column: { procedure_id: procedure.id, column_id: filter['table'] + "/" + filter['column'] }.to_json, value: filter['value'] }),
|
||||
class: "fr-tag fr-tag--dismiss fr-my-1w", aria: { label: "Retirer le filtre #{filter['column']}" } do
|
||||
= "#{filter['label'].truncate(50)} : #{procedure_presentation.human_value_for_filter(filter)}"
|
||||
= link_to remove_filter_instructeur_procedure_path(procedure, { statut: statut, column: filter.column.id, value: filter.filter }),
|
||||
class: "fr-tag fr-tag--dismiss fr-my-1w", aria: { label: "Retirer le filtre #{filter.column.label}" } do
|
||||
= "#{filter.column.label.truncate(50)} : #{procedure_presentation.human_value_for_filter(filter)}"
|
||||
|
|
|
@ -772,9 +772,11 @@ describe ProcedurePresentation do
|
|||
end
|
||||
|
||||
describe "#human_value_for_filter" do
|
||||
let(:filters) { { "suivis" => [{ label: "label1", table: "type_de_champ", column: first_type_de_champ_id, "value" => "true" }] } }
|
||||
let(:filtered_column) { to_filter([first_type_de_champ.libelle, "true"]) }
|
||||
|
||||
subject { procedure_presentation.human_value_for_filter(procedure_presentation.filters["suivis"].first) }
|
||||
subject do
|
||||
procedure_presentation.human_value_for_filter(filtered_column)
|
||||
end
|
||||
|
||||
context 'when type_de_champ text' do
|
||||
it 'should passthrough value' do
|
||||
|
@ -791,7 +793,7 @@ describe ProcedurePresentation do
|
|||
end
|
||||
|
||||
context 'when filter is state' do
|
||||
let(:filters) { { "suivis" => [{ table: "self", column: "state", "value" => "en_construction" }] } }
|
||||
let(:filtered_column) { to_filter(['Statut', "en_construction"]) }
|
||||
|
||||
it 'should get i18n value' do
|
||||
expect(subject).to eq("En construction")
|
||||
|
@ -799,7 +801,7 @@ describe ProcedurePresentation do
|
|||
end
|
||||
|
||||
context 'when filter is a date' do
|
||||
let(:filters) { { "suivis" => [{ table: "self", column: "en_instruction_at", "value" => "15/06/2023" }] } }
|
||||
let(:filtered_column) { to_filter(['Créé le', "15/06/2023"]) }
|
||||
|
||||
it 'should get formatted value' do
|
||||
expect(subject).to eq("15/06/2023")
|
||||
|
|
Loading…
Reference in a new issue