tech(amelioration.chorus_configuration): deplace les methodes liées au rendu du model ChorusConfiguration dans le ChorusFormComponent
This commit is contained in:
parent
a6cf22edb8
commit
39abf283d9
3 changed files with 30 additions and 29 deletions
|
@ -3,6 +3,7 @@ class Procedure::ChorusFormComponent < ApplicationComponent
|
||||||
|
|
||||||
def initialize(procedure:)
|
def initialize(procedure:)
|
||||||
@procedure = procedure
|
@procedure = procedure
|
||||||
|
@chorus_configuration = @procedure.chorus_configuration
|
||||||
end
|
end
|
||||||
|
|
||||||
def map_attribute_to_autocomplete_endpoint
|
def map_attribute_to_autocomplete_endpoint
|
||||||
|
@ -12,4 +13,30 @@ class Procedure::ChorusFormComponent < ApplicationComponent
|
||||||
referentiel_de_programmation: data_sources_search_ref_programmation_path
|
referentiel_de_programmation: data_sources_search_ref_programmation_path
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def format_displayed_value(attribute_name)
|
||||||
|
case attribute_name
|
||||||
|
when :centre_de_coup
|
||||||
|
ChorusConfiguration.format_centre_de_coup_label(@chorus_configuration.centre_de_coup)
|
||||||
|
when :domaine_fonctionnel
|
||||||
|
ChorusConfiguration.format_domaine_fonctionnel_label(@chorus_configuration.domaine_fonctionnel)
|
||||||
|
when :referentiel_de_programmation
|
||||||
|
ChorusConfiguration.format_ref_programmation_label(@chorus_configuration.referentiel_de_programmation)
|
||||||
|
else
|
||||||
|
raise 'unknown attribute_name'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_hidden_value(attribute_name)
|
||||||
|
case attribute_name
|
||||||
|
when :centre_de_coup
|
||||||
|
@chorus_configuration.centre_de_coup.to_json
|
||||||
|
when :domaine_fonctionnel
|
||||||
|
@chorus_configuration.domaine_fonctionnel.to_json
|
||||||
|
when :referentiel_de_programmation
|
||||||
|
@chorus_configuration.referentiel_de_programmation.to_json
|
||||||
|
else
|
||||||
|
raise 'unknown attribute_name'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
= form_for([procedure, procedure.chorus_configuration],url: admin_procedure_chorus_path(procedure), method: :put) do |f|
|
= form_for([procedure, @chorus_configuration],url: admin_procedure_chorus_path(procedure), method: :put) do |f|
|
||||||
- map_attribute_to_autocomplete_endpoint.map do |chorus_configuration_attribute, datasource_endpoint|
|
- map_attribute_to_autocomplete_endpoint.map do |chorus_configuration_attribute, datasource_endpoint|
|
||||||
- label_class_name = "#{chorus_configuration_attribute}-label"
|
- label_class_name = "#{chorus_configuration_attribute}-label"
|
||||||
.fr-select-group
|
.fr-select-group
|
||||||
= f.label chorus_configuration_attribute, class: 'fr-label', id: label_class_name
|
= f.label chorus_configuration_attribute, class: 'fr-label', id: label_class_name
|
||||||
= render Dsfr::ComboboxComponent.new form: f, name: :chorus_configuration_attribute, url: datasource_endpoint, selected: procedure.chorus_configuration.format_displayed_value(chorus_configuration_attribute), id: chorus_configuration_attribute, class: 'fr-select', describedby: label_class_name do
|
= render Dsfr::ComboboxComponent.new form: f, name: :chorus_configuration_attribute, url: datasource_endpoint, selected: format_displayed_value(chorus_configuration_attribute), id: chorus_configuration_attribute, class: 'fr-select', describedby: label_class_name do
|
||||||
= f.hidden_field chorus_configuration_attribute, data: { value_slot: 'data' }, value: procedure.chorus_configuration.format_hidden_value(chorus_configuration_attribute)
|
= f.hidden_field chorus_configuration_attribute, data: { value_slot: 'data' }, value: format_hidden_value(chorus_configuration_attribute)
|
||||||
|
|
||||||
= f.submit "Enregister", class: 'fr-btn'
|
= f.submit "Enregister", class: 'fr-btn'
|
||||||
|
|
|
@ -6,32 +6,6 @@ class ChorusConfiguration
|
||||||
attribute :domaine_fonctionnel, :simple_json, default: '{}'
|
attribute :domaine_fonctionnel, :simple_json, default: '{}'
|
||||||
attribute :referentiel_de_programmation, :simple_json, default: '{}'
|
attribute :referentiel_de_programmation, :simple_json, default: '{}'
|
||||||
|
|
||||||
def format_displayed_value(attribute_name)
|
|
||||||
case attribute_name
|
|
||||||
when :centre_de_coup
|
|
||||||
ChorusConfiguration.format_centre_de_coup_label(centre_de_coup)
|
|
||||||
when :domaine_fonctionnel
|
|
||||||
ChorusConfiguration.format_domaine_fonctionnel_label(domaine_fonctionnel)
|
|
||||||
when :referentiel_de_programmation
|
|
||||||
ChorusConfiguration.format_ref_programmation_label(referentiel_de_programmation)
|
|
||||||
else
|
|
||||||
raise 'unknown attribute_name'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def format_hidden_value(attribute_name)
|
|
||||||
case attribute_name
|
|
||||||
when :centre_de_coup
|
|
||||||
centre_de_coup.to_json
|
|
||||||
when :domaine_fonctionnel
|
|
||||||
domaine_fonctionnel.to_json
|
|
||||||
when :referentiel_de_programmation
|
|
||||||
referentiel_de_programmation.to_json
|
|
||||||
else
|
|
||||||
raise 'unknown attribute_name'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.format_centre_de_coup_label(api_result)
|
def self.format_centre_de_coup_label(api_result)
|
||||||
return "" if api_result.blank?
|
return "" if api_result.blank?
|
||||||
api_result = api_result.symbolize_keys
|
api_result = api_result.symbolize_keys
|
||||||
|
|
Loading…
Reference in a new issue