review(tech): utilise un code unique pr les elements de l'autocomplete, corrections de typos, amelioration du code
Co-authored-by: LeSim <mail@simon.lehericey.net>
This commit is contained in:
parent
c7d5bf8dc7
commit
87c3615774
15 changed files with 39 additions and 33 deletions
|
@ -8,7 +8,7 @@ class Procedure::ChorusFormComponent < ApplicationComponent
|
||||||
|
|
||||||
def map_attribute_to_autocomplete_endpoint
|
def map_attribute_to_autocomplete_endpoint
|
||||||
{
|
{
|
||||||
centre_de_coup: data_sources_search_centre_couts_path,
|
centre_de_cout: data_sources_search_centre_couts_path,
|
||||||
domaine_fonctionnel: data_sources_search_domaine_fonct_path,
|
domaine_fonctionnel: data_sources_search_domaine_fonct_path,
|
||||||
referentiel_de_programmation: data_sources_search_ref_programmation_path
|
referentiel_de_programmation: data_sources_search_ref_programmation_path
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ class Procedure::ChorusFormComponent < ApplicationComponent
|
||||||
|
|
||||||
def format_displayed_value(attribute_name)
|
def format_displayed_value(attribute_name)
|
||||||
case attribute_name
|
case attribute_name
|
||||||
when :centre_de_coup
|
when :centre_de_cout
|
||||||
ChorusConfiguration.format_centre_de_coup_label(@chorus_configuration.centre_de_coup)
|
ChorusConfiguration.format_centre_de_cout_label(@chorus_configuration.centre_de_cout)
|
||||||
when :domaine_fonctionnel
|
when :domaine_fonctionnel
|
||||||
ChorusConfiguration.format_domaine_fonctionnel_label(@chorus_configuration.domaine_fonctionnel)
|
ChorusConfiguration.format_domaine_fonctionnel_label(@chorus_configuration.domaine_fonctionnel)
|
||||||
when :referentiel_de_programmation
|
when :referentiel_de_programmation
|
||||||
|
@ -29,8 +29,8 @@ class Procedure::ChorusFormComponent < ApplicationComponent
|
||||||
|
|
||||||
def format_hidden_value(attribute_name)
|
def format_hidden_value(attribute_name)
|
||||||
case attribute_name
|
case attribute_name
|
||||||
when :centre_de_coup
|
when :centre_de_cout
|
||||||
@chorus_configuration.centre_de_coup.to_json
|
@chorus_configuration.centre_de_cout.to_json
|
||||||
when :domaine_fonctionnel
|
when :domaine_fonctionnel
|
||||||
@chorus_configuration.domaine_fonctionnel.to_json
|
@chorus_configuration.domaine_fonctionnel.to_json
|
||||||
when :referentiel_de_programmation
|
when :referentiel_de_programmation
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
= form_for([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_id = "#{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_id
|
||||||
= 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
|
= render Dsfr::ComboboxComponent.new form: f,
|
||||||
|
url: datasource_endpoint,
|
||||||
|
selected: format_displayed_value(chorus_configuration_attribute),
|
||||||
|
id: chorus_configuration_attribute,
|
||||||
|
class: 'fr-select',
|
||||||
|
describedby: label_id,
|
||||||
|
name: :chorus_configuration_attribute do
|
||||||
= f.hidden_field chorus_configuration_attribute, data: { value_slot: 'data' }, value: 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'
|
||||||
|
|
|
@ -96,7 +96,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent
|
||||||
if coordinate.private?
|
if coordinate.private?
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
!TypeDeChamp::PRIVATE_TYPES.include?(type_champ)
|
!TypeDeChamp::PRIVATE_ONLY_TYPES.include?(type_champ)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ module Administrateurs
|
||||||
|
|
||||||
def configurations_params
|
def configurations_params
|
||||||
params.require(:chorus_configuration)
|
params.require(:chorus_configuration)
|
||||||
.permit(:centre_de_coup, :domaine_fonctionnel, :referentiel_de_programmation)
|
.permit(:centre_de_cout, :domaine_fonctionnel, :referentiel_de_programmation)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ class DataSources::ChorusController < ApplicationController
|
||||||
def search_centre_couts
|
def search_centre_couts
|
||||||
result_json = APIBretagneService.new.search_centre_couts(code_or_label: params[:q])
|
result_json = APIBretagneService.new.search_centre_couts(code_or_label: params[:q])
|
||||||
render json: format_result(result_json:,
|
render json: format_result(result_json:,
|
||||||
label_formatter: ChorusConfiguration.method(:format_centre_de_coup_label))
|
label_formatter: ChorusConfiguration.method(:format_centre_de_cout_label))
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_ref_programmation
|
def search_ref_programmation
|
||||||
|
@ -25,7 +25,7 @@ class DataSources::ChorusController < ApplicationController
|
||||||
result_json.map do |item|
|
result_json.map do |item|
|
||||||
{
|
{
|
||||||
label: label_formatter.call(item),
|
label: label_formatter.call(item),
|
||||||
value: "#{item[:label]} - #{item[:code_programme]}",
|
value: item[:code],
|
||||||
data: item
|
data: item
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,11 @@ class ChorusConfiguration
|
||||||
include ActiveModel::Model
|
include ActiveModel::Model
|
||||||
include ActiveModel::Attributes
|
include ActiveModel::Attributes
|
||||||
|
|
||||||
attribute :centre_de_coup, :simple_json, default: '{}'
|
attribute :centre_de_cout, :simple_json, default: '{}'
|
||||||
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 self.format_centre_de_coup_label(api_result)
|
def self.format_centre_de_cout_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
|
||||||
"#{api_result[:description]} - #{api_result[:code]}"
|
"#{api_result[:description]} - #{api_result[:code]}"
|
||||||
|
@ -26,7 +26,7 @@ class ChorusConfiguration
|
||||||
|
|
||||||
def complete?
|
def complete?
|
||||||
[
|
[
|
||||||
centre_de_coup,
|
centre_de_cout,
|
||||||
domaine_fonctionnel,
|
domaine_fonctionnel,
|
||||||
referentiel_de_programmation
|
referentiel_de_programmation
|
||||||
].all?(&:present?)
|
].all?(&:present?)
|
||||||
|
|
|
@ -1231,8 +1231,8 @@ class Dossier < ApplicationRecord
|
||||||
if procedure.chorusable? && procedure.chorus.complete?
|
if procedure.chorusable? && procedure.chorus.complete?
|
||||||
columns += [
|
columns += [
|
||||||
['Domaine Fonctionnel', procedure.chorus_configuration.domaine_fonctionnel.code],
|
['Domaine Fonctionnel', procedure.chorus_configuration.domaine_fonctionnel.code],
|
||||||
['Referentiel De Programmation', procedure.chorus_configuration.referentiel_de_programmation.code],
|
['Référentiel De Programmation', procedure.chorus_configuration.referentiel_de_programmation.code],
|
||||||
['Centre De Coup', procedure.chorus_configuration.centre_de_coup.code]
|
['Centre De Coup', procedure.chorus_configuration.centre_de_cout.code]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
columns += [
|
columns += [
|
||||||
|
|
|
@ -118,7 +118,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
type_champs.fetch(:epci)
|
type_champs.fetch(:epci)
|
||||||
]
|
]
|
||||||
|
|
||||||
PRIVATE_TYPES = [
|
PRIVATE_ONLY_TYPES = [
|
||||||
type_champs.fetch(:engagement_juridique)
|
type_champs.fetch(:engagement_juridique)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_10_26_161609) do
|
ActiveRecord::Schema[7.0].define(version: 2023_11_03_084116) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pgcrypto"
|
enable_extension "pgcrypto"
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
|
@ -38,7 +38,7 @@ describe TypesDeChampEditor::ChampComponent, type: :component do
|
||||||
let(:coordinate) { procedure.draft_revision.revision_types_de_champ_public.first }
|
let(:coordinate) { procedure.draft_revision.revision_types_de_champ_public.first }
|
||||||
|
|
||||||
it 'does not include Engagement Juridique' do
|
it 'does not include Engagement Juridique' do
|
||||||
expect(page).not_to have_css(:option, text: "Engagement Juridique")
|
expect(page).not_to have_css('option', text: "Engagement Juridique")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ describe TypesDeChampEditor::ChampComponent, type: :component do
|
||||||
let(:coordinate) { procedure.draft_revision.revision_types_de_champ_private.first }
|
let(:coordinate) { procedure.draft_revision.revision_types_de_champ_private.first }
|
||||||
|
|
||||||
it 'includes Engagement Juridique' do
|
it 'includes Engagement Juridique' do
|
||||||
expect(page).to have_css(:option, text: "Engagement Juridique")
|
expect(page).to have_css('option', text: "Engagement Juridique")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,10 +52,10 @@ describe Administrateurs::ChorusController, type: :controller do
|
||||||
let(:referentiel_de_programmation) { nil }
|
let(:referentiel_de_programmation) { nil }
|
||||||
|
|
||||||
context "partial valid payload" do
|
context "partial valid payload" do
|
||||||
let(:centre_de_coup) { '{"code":"D00C8DX004","label":"Aumôniers+protestant","ville":null,"code_postal":null,"description":"Aumoniers+protestants"}' }
|
let(:centre_de_cout) { '{"code":"D00C8DX004","label":"Aumôniers+protestant","ville":null,"code_postal":null,"description":"Aumoniers+protestants"}' }
|
||||||
let(:chorus_configuration_params) do
|
let(:chorus_configuration_params) do
|
||||||
{
|
{
|
||||||
centre_de_coup:, domaine_fonctionnel:, referentiel_de_programmation:
|
centre_de_cout:, domaine_fonctionnel:, referentiel_de_programmation:
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
it 'updates params and redirect back to complete all infos' do
|
it 'updates params and redirect back to complete all infos' do
|
||||||
|
@ -64,19 +64,19 @@ describe Administrateurs::ChorusController, type: :controller do
|
||||||
|
|
||||||
procedure.reload
|
procedure.reload
|
||||||
|
|
||||||
expect(procedure.chorus_configuration.centre_de_coup).to eq(JSON.parse(centre_de_coup))
|
expect(procedure.chorus_configuration.centre_de_cout).to eq(JSON.parse(centre_de_cout))
|
||||||
expect(procedure.chorus_configuration.domaine_fonctionnel).to eq(nil)
|
expect(procedure.chorus_configuration.domaine_fonctionnel).to eq(nil)
|
||||||
expect(procedure.chorus_configuration.referentiel_de_programmation).to eq(nil)
|
expect(procedure.chorus_configuration.referentiel_de_programmation).to eq(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "full valid payload" do
|
context "full valid payload" do
|
||||||
let(:centre_de_coup) { '{"code":"D00C8DX004","label":"Aumôniers+protestant","ville":null,"code_postal":null,"description":"Aumoniers+protestants"}' }
|
let(:centre_de_cout) { '{"code":"D00C8DX004","label":"Aumôniers+protestant","ville":null,"code_postal":null,"description":"Aumoniers+protestants"}' }
|
||||||
let(:domaine_fonctionnel) { '{"code":"0105-05-01","label":"Formation+des+élites+et+cadres+de+sécurité+et+de+défense","description":null,"code_programme":"105"}' }
|
let(:domaine_fonctionnel) { '{"code":"0105-05-01","label":"Formation+des+élites+et+cadres+de+sécurité+et+de+défense","description":null,"code_programme":"105"}' }
|
||||||
let(:referentiel_de_programmation) { '{"code":"010101010101","label":"DOTATIONS+CARPA+AJ+ET+AUTRES+INTERVENTIONS","description":null,"code_programme":"101"}' }
|
let(:referentiel_de_programmation) { '{"code":"010101010101","label":"DOTATIONS+CARPA+AJ+ET+AUTRES+INTERVENTIONS","description":null,"code_programme":"101"}' }
|
||||||
let(:chorus_configuration_params) do
|
let(:chorus_configuration_params) do
|
||||||
{
|
{
|
||||||
centre_de_coup:, domaine_fonctionnel:, referentiel_de_programmation:
|
centre_de_cout:, domaine_fonctionnel:, referentiel_de_programmation:
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ describe Administrateurs::ChorusController, type: :controller do
|
||||||
|
|
||||||
procedure.reload
|
procedure.reload
|
||||||
|
|
||||||
expect(procedure.chorus_configuration.centre_de_coup).to eq(JSON.parse(centre_de_coup))
|
expect(procedure.chorus_configuration.centre_de_cout).to eq(JSON.parse(centre_de_cout))
|
||||||
expect(procedure.chorus_configuration.domaine_fonctionnel).to eq(JSON.parse(domaine_fonctionnel))
|
expect(procedure.chorus_configuration.domaine_fonctionnel).to eq(JSON.parse(domaine_fonctionnel))
|
||||||
expect(procedure.chorus_configuration.referentiel_de_programmation).to eq(JSON.parse(referentiel_de_programmation))
|
expect(procedure.chorus_configuration.referentiel_de_programmation).to eq(JSON.parse(referentiel_de_programmation))
|
||||||
end
|
end
|
||||||
|
|
|
@ -428,12 +428,12 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :partial_chorus do
|
trait :partial_chorus do
|
||||||
chorus { ChorusConfiguration.new(centre_de_coup: { a: 1 }) }
|
chorus { ChorusConfiguration.new(centre_de_cout: { a: 1 }) }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :filled_chorus do
|
trait :filled_chorus do
|
||||||
chorus do
|
chorus do
|
||||||
ChorusConfiguration.new(centre_de_coup: { a: 1 },
|
ChorusConfiguration.new(centre_de_cout: { a: 1 },
|
||||||
domaine_fonctionnel: { b: 2 },
|
domaine_fonctionnel: { b: 2 },
|
||||||
referentiel_de_programmation: { c: 3 })
|
referentiel_de_programmation: { c: 3 })
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,9 +14,9 @@ describe '20220705164551_remove_unused_champs' do
|
||||||
|
|
||||||
describe 'remove_unused_champs' do
|
describe 'remove_unused_champs' do
|
||||||
it "with bad champs" do
|
it "with bad champs" do
|
||||||
expect(Champ.where(dossier: dossier).count).to eq(43)
|
expect(Champ.where(dossier: dossier).count).to eq(44)
|
||||||
run_task
|
run_task
|
||||||
expect(Champ.where(dossier: dossier).count).to eq(42)
|
expect(Champ.where(dossier: dossier).count).to eq(43)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe ChorusConfiguration do
|
||||||
it 'works with existing args' do
|
it 'works with existing args' do
|
||||||
expect do
|
expect do
|
||||||
cc = ChorusConfiguration.new()
|
cc = ChorusConfiguration.new()
|
||||||
cc.assign_attributes(centre_de_coup: {}, domaine_fonctionnel: {}, referentiel_de_programmation: {})
|
cc.assign_attributes(centre_de_cout: {}, domaine_fonctionnel: {}, referentiel_de_programmation: {})
|
||||||
end.not_to raise_error
|
end.not_to raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -149,7 +149,7 @@ describe ProcedureExportService do
|
||||||
it 'includes chorus headers' do
|
it 'includes chorus headers' do
|
||||||
expected_headers = [
|
expected_headers = [
|
||||||
'Domaine Fonctionnel',
|
'Domaine Fonctionnel',
|
||||||
'Referentiel De Programmation',
|
'Référentiel De Programmation',
|
||||||
'Centre De Coup'
|
'Centre De Coup'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue