From 5f380d72c556a3295d7efcfaee2ee796e1b1f326 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Wed, 11 Dec 2024 14:54:31 +0100 Subject: [PATCH] wip display item even if not in db --- app/models/champs/drop_down_list_champ.rb | 8 ++++---- app/models/types_de_champ/drop_down_list_type_de_champ.rb | 8 +++----- app/views/shared/champs/drop_down_list/_show.html.haml | 5 ++++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/models/champs/drop_down_list_champ.rb b/app/models/champs/drop_down_list_champ.rb index cd82c045fb7..af5d431c9f5 100644 --- a/app/models/champs/drop_down_list_champ.rb +++ b/app/models/champs/drop_down_list_champ.rb @@ -80,6 +80,10 @@ def referentiel_item_option_value referentiel_item_option.values.first end + def value_is_in_referentiel_ids? + referentiel_drop_down_options.map { _1['id'] }.include?(value.to_i) + end + private def value_is_in_options @@ -88,8 +92,4 @@ def value_is_in_options errors.add(:value, :not_in_options) end - - def value_is_in_referentiel_ids? - referentiel_drop_down_options.map { _1['id'] }.include?(value.to_i) - end end diff --git a/app/models/types_de_champ/drop_down_list_type_de_champ.rb b/app/models/types_de_champ/drop_down_list_type_de_champ.rb index 973ed0b845b..69c93ade707 100644 --- a/app/models/types_de_champ/drop_down_list_type_de_champ.rb +++ b/app/models/types_de_champ/drop_down_list_type_de_champ.rb @@ -8,11 +8,9 @@ def champ_blank?(champ) private def champ_value_in_options?(champ) - if champ.referentiel? - champ_with_other_value?(champ) || referentiel_drop_down_options.map { _1['id'] }.include?(champ.value.to_i) - else - champ_with_other_value?(champ) || drop_down_options.include?(champ.value) - end + # we want to display referentiel item even if it is not in db anymore + return true if champ.referentiel? + champ_with_other_value?(champ) || drop_down_options.include?(champ.value) end def champ_with_other_value?(champ) diff --git a/app/views/shared/champs/drop_down_list/_show.html.haml b/app/views/shared/champs/drop_down_list/_show.html.haml index a9f71829781..e6ea8cb66ab 100644 --- a/app/views/shared/champs/drop_down_list/_show.html.haml +++ b/app/views/shared/champs/drop_down_list/_show.html.haml @@ -1,6 +1,9 @@ - if champ.referentiel? && champ.referentiel_item_option.present? - - if current_user.instructeur? && !current_user.owns_or_invite?(champ.dossier) + - if current_user.instructeur? && !current_user.owns_or_invite?(champ.dossier) .fr-background-alt--grey.fr-p-3v + - if !champ.value_is_in_referentiel_ids? + + %span.fr-badge.fr-badge--warning.fr-badge--sm.pull-right Valeur retirée du référentiel - champ.referentiel_item_option.merge(champ.referentiel_item_data).each do |key, value| - if key.present? = render Dossiers::RowShowComponent.new(label: key) do |c|