2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-08-29 09:22:58 +02:00
|
|
|
class Procedure::ChorusFormComponent < ApplicationComponent
|
|
|
|
attr_reader :procedure
|
|
|
|
|
|
|
|
def initialize(procedure:)
|
|
|
|
@procedure = procedure
|
2023-10-20 16:29:53 +02:00
|
|
|
@chorus_configuration = @procedure.chorus_configuration
|
2023-08-29 09:22:58 +02:00
|
|
|
end
|
2023-10-19 15:19:23 +02:00
|
|
|
|
|
|
|
def map_attribute_to_autocomplete_endpoint
|
|
|
|
{
|
2023-11-09 09:59:04 +01:00
|
|
|
centre_de_cout: data_sources_search_centre_couts_path,
|
2023-10-19 15:19:23 +02:00
|
|
|
domaine_fonctionnel: data_sources_search_domaine_fonct_path,
|
|
|
|
referentiel_de_programmation: data_sources_search_ref_programmation_path
|
|
|
|
}
|
|
|
|
end
|
2023-10-20 16:29:53 +02:00
|
|
|
|
2024-05-07 11:28:14 +02:00
|
|
|
def selected_key(attribute_name)
|
|
|
|
items(attribute_name).first&.dig(:value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def items(attribute_name)
|
|
|
|
label = format_displayed_value(attribute_name)
|
|
|
|
data = format_hidden_value(attribute_name)
|
|
|
|
if label.present?
|
|
|
|
[{ label:, value: label, data: }]
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-20 16:29:53 +02:00
|
|
|
def format_displayed_value(attribute_name)
|
|
|
|
case attribute_name
|
2023-11-09 09:59:04 +01:00
|
|
|
when :centre_de_cout
|
|
|
|
ChorusConfiguration.format_centre_de_cout_label(@chorus_configuration.centre_de_cout)
|
2023-10-20 16:29:53 +02:00
|
|
|
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
|
2023-11-09 09:59:04 +01:00
|
|
|
when :centre_de_cout
|
2024-05-07 11:28:14 +02:00
|
|
|
@chorus_configuration.centre_de_cout
|
2023-10-20 16:29:53 +02:00
|
|
|
when :domaine_fonctionnel
|
2024-05-07 11:28:14 +02:00
|
|
|
@chorus_configuration.domaine_fonctionnel
|
2023-10-20 16:29:53 +02:00
|
|
|
when :referentiel_de_programmation
|
2024-05-07 11:28:14 +02:00
|
|
|
@chorus_configuration.referentiel_de_programmation
|
2023-10-20 16:29:53 +02:00
|
|
|
else
|
|
|
|
raise 'unknown attribute_name'
|
|
|
|
end
|
|
|
|
end
|
2024-05-07 11:28:14 +02:00
|
|
|
|
|
|
|
def react_props(name, chorus_configuration_attribute, datasource_endpoint)
|
|
|
|
{
|
|
|
|
name:,
|
|
|
|
selected_key: selected_key(chorus_configuration_attribute),
|
|
|
|
items: items(chorus_configuration_attribute),
|
|
|
|
loader: datasource_endpoint,
|
|
|
|
id: chorus_configuration_attribute
|
|
|
|
}
|
|
|
|
end
|
2023-08-29 09:22:58 +02:00
|
|
|
end
|