Skip to content

Commit

Permalink
wip display item even if not in db
Browse files Browse the repository at this point in the history
  • Loading branch information
E-L-T authored and lisa-durand committed Dec 11, 2024
1 parent 0841d8b commit 5f380d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app/models/champs/drop_down_list_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 3 additions & 5 deletions app/models/types_de_champ/drop_down_list_type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion app/views/shared/champs/drop_down_list/_show.html.haml
Original file line number Diff line number Diff line change
@@ -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|
Expand Down

0 comments on commit 5f380d7

Please sign in to comment.