Merge pull request #9879 from demarches-simplifiees/cleaning-conditional-and-routing-code
Tech : nettoyage du code conditionnel et routage
This commit is contained in:
commit
6203b1fd05
6 changed files with 11 additions and 102 deletions
|
@ -6,95 +6,4 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent
|
|||
@groupe_instructeur = groupe_instructeur
|
||||
@procedure = revision.procedure
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def targeted_champ
|
||||
@groupe_instructeur.routing_rule&.left || empty
|
||||
end
|
||||
|
||||
def value
|
||||
@groupe_instructeur.routing_rule&.right || empty
|
||||
end
|
||||
|
||||
def operator_name
|
||||
@groupe_instructeur.routing_rule&.class&.name || empty
|
||||
end
|
||||
|
||||
def targeted_champ_tag
|
||||
select_tag(
|
||||
'targeted_champ',
|
||||
options_for_select(targeted_champs_for_select, selected: targeted_champ.to_json),
|
||||
class: 'fr-select'
|
||||
)
|
||||
end
|
||||
|
||||
def targeted_champs_for_select
|
||||
empty_target_for_select + available_targets_for_select
|
||||
end
|
||||
|
||||
def empty_target_for_select
|
||||
[[t('.select'), empty.to_json]]
|
||||
end
|
||||
|
||||
def available_targets_for_select
|
||||
@revision
|
||||
.routable_types_de_champ
|
||||
.map { |tdc| [tdc.libelle, champ_value(tdc.stable_id).to_json] }
|
||||
end
|
||||
|
||||
def operator_tag
|
||||
select_tag('operator_name',
|
||||
options_for_select(
|
||||
options_for_operator_tag,
|
||||
selected: operator_name
|
||||
),
|
||||
class: 'fr-select')
|
||||
end
|
||||
|
||||
def options_for_operator_tag
|
||||
[Eq, NotEq]
|
||||
.map(&:name)
|
||||
.map { |name| [t(name, scope: 'logic.operators'), name] }
|
||||
end
|
||||
|
||||
def value_tag
|
||||
select_tag(
|
||||
'value',
|
||||
options_for_select(
|
||||
values_for_select(targeted_champ),
|
||||
selected: value.to_json
|
||||
),
|
||||
class: 'fr-select'
|
||||
)
|
||||
end
|
||||
|
||||
def values_for_select(targeted_champ)
|
||||
(empty_target_for_select + available_values_for_select(targeted_champ))
|
||||
# add id to help morph render selected option
|
||||
.map { |(libelle, json)| [libelle, json, { id: "option-#{libelle}" }] }
|
||||
end
|
||||
|
||||
def available_values_for_select(targeted_champ)
|
||||
return [] if targeted_champ.is_a?(Logic::Empty)
|
||||
|
||||
case @revision.types_de_champ_public.find_by(stable_id: targeted_champ.stable_id).type_champ
|
||||
when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:epci)
|
||||
departements_for_select
|
||||
when TypeDeChamp.type_champs.fetch(:regions)
|
||||
regions_for_select
|
||||
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||
targeted_champ
|
||||
.options(@revision.types_de_champ_public)
|
||||
.map { |(label, value)| [label, constant(value).to_json] }
|
||||
end
|
||||
end
|
||||
|
||||
def departements_for_select
|
||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", constant(_1[:code]).to_json] }
|
||||
end
|
||||
|
||||
def regions_for_select
|
||||
APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", constant(_1[:code]).to_json] }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,8 +53,6 @@ class Logic::ChampValue < Logic::Term
|
|||
targeted_champ.selected_options
|
||||
when "Champs::DepartementChamp", "Champs::RegionChamp"
|
||||
targeted_champ.code
|
||||
when "Champs::CommuneChamp", "Champs::EpciChamp"
|
||||
targeted_champ.code_departement
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,4 +13,4 @@
|
|||
- elsif dossier.forced_groupe_instructeur
|
||||
%p.tab-paragraph Ce dossier a été réaffecté au groupe « #{dossier.groupe_instructeur.label} »
|
||||
- else
|
||||
%p.tab-paragraph Ce dossier n'a pas été réaffecté
|
||||
%p.tab-paragraph Ce dossier n’a pas été réaffecté
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
|
||||
= render partial: 'instructeurs/dossiers/decisions_rendues_block', locals: { traitements: @dossier.traitements }
|
||||
|
||||
= render partial: 'instructeurs/dossiers/reaffectations_block', locals: { manual_assignments: @manual_assignments, dossier: @dossier }
|
||||
- if @dossier.procedure.routing_enabled?
|
||||
= render partial: 'instructeurs/dossiers/reaffectations_block', locals: { manual_assignments: @manual_assignments, dossier: @dossier }
|
||||
|
||||
- if @dossier.archived? && @dossier.archived_at.present?
|
||||
= render partial: 'instructeurs/dossiers/archived_block', locals: @dossier.slice(:archived_by, :archived_at)
|
||||
|
|
|
@ -1275,10 +1275,11 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#personnes_impliquees' do
|
||||
let!(:gi_1) { procedure.groupe_instructeurs.first }
|
||||
let!(:gi_2) { GroupeInstructeur.create(label: 'deuxième groupe', procedure: procedure) }
|
||||
let!(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure, groupe_instructeur: gi_1) }
|
||||
let!(:new_instructeur) { create(:instructeur) }
|
||||
let(:routed_procedure) { create(:procedure, :routee, :published, :for_individual) }
|
||||
let(:gi_1) { routed_procedure.groupe_instructeurs.first }
|
||||
let(:gi_2) { routed_procedure.groupe_instructeurs.last }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: routed_procedure, groupe_instructeur: gi_1) }
|
||||
let(:new_instructeur) { create(:instructeur) }
|
||||
|
||||
before do
|
||||
gi_1.instructeurs << new_instructeur
|
||||
|
@ -1288,7 +1289,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
|
||||
get :personnes_impliquees,
|
||||
params: {
|
||||
procedure_id: procedure.id,
|
||||
procedure_id: routed_procedure.id,
|
||||
dossier_id: dossier.id
|
||||
}
|
||||
end
|
||||
|
|
|
@ -122,7 +122,7 @@ describe RoutingEngine, type: :model do
|
|||
|
||||
context 'with a matching rule' do
|
||||
before do
|
||||
gi_2.update(routing_rule: ds_eq(champ_value(communes_tdc.stable_id), constant('92')))
|
||||
gi_2.update(routing_rule: ds_in_departement(champ_value(communes_tdc.stable_id), constant('92')))
|
||||
dossier.champs.first.update(code_postal: '92500', external_id: '92063')
|
||||
end
|
||||
|
||||
|
@ -141,7 +141,7 @@ describe RoutingEngine, type: :model do
|
|||
|
||||
context 'with a matching rule' do
|
||||
before do
|
||||
gi_2.update(routing_rule: ds_eq(champ_value(epci_tdc.stable_id), constant('42')))
|
||||
gi_2.update(routing_rule: ds_in_departement(champ_value(epci_tdc.stable_id), constant('42')))
|
||||
dossier.champs.first.update_columns(
|
||||
external_id: 244200895,
|
||||
value: 'CC du Pilat Rhodanien',
|
||||
|
|
Loading…
Reference in a new issue