From c86651cfc5da45782a42ebabafa3ca7169993362 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 27 Jul 2023 14:35:01 +0200 Subject: [PATCH 1/7] refactor(routing): refactor options for select --- app/components/procedure/one_groupe_management_component.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/procedure/one_groupe_management_component.rb b/app/components/procedure/one_groupe_management_component.rb index bba162b9b..80ab87cd1 100644 --- a/app/components/procedure/one_groupe_management_component.rb +++ b/app/components/procedure/one_groupe_management_component.rb @@ -60,6 +60,6 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent return [] if targeted_champ.is_a?(Logic::Empty) targeted_champ .options(@revision.types_de_champ_public) - .map { |tdc| [tdc.first, constant(tdc.first).to_json] } + .map { |(label, value)| [label, constant(value).to_json] } end end From 4749b436971ee053118eb524e9b75199365ffcc1 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 27 Jul 2023 14:35:47 +0200 Subject: [PATCH 2/7] refactor(routing): use drop_down_options --- .../administrateurs/groupe_instructeurs_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/administrateurs/groupe_instructeurs_controller.rb b/app/controllers/administrateurs/groupe_instructeurs_controller.rb index 101d05c1f..c0525b819 100644 --- a/app/controllers/administrateurs/groupe_instructeurs_controller.rb +++ b/app/controllers/administrateurs/groupe_instructeurs_controller.rb @@ -40,7 +40,7 @@ module Administrateurs tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id } - tdc_options = tdc.options["drop_down_options"].reject(&:empty?) + tdc_options = tdc.drop_down_options.reject(&:empty?) tdc_options.each do |option_label| gi = @procedure.groupe_instructeurs.find_by({ label: option_label }) || @procedure.groupe_instructeurs From 7680d5093e59201dda26c4da4ed62a93c8b4f34f Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 27 Jul 2023 14:37:01 +0200 Subject: [PATCH 3/7] feat(routing): create routing rule for dropdown other option --- .../groupe_instructeurs_controller.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/administrateurs/groupe_instructeurs_controller.rb b/app/controllers/administrateurs/groupe_instructeurs_controller.rb index c0525b819..33491a1be 100644 --- a/app/controllers/administrateurs/groupe_instructeurs_controller.rb +++ b/app/controllers/administrateurs/groupe_instructeurs_controller.rb @@ -43,9 +43,19 @@ module Administrateurs tdc_options = tdc.drop_down_options.reject(&:empty?) tdc_options.each do |option_label| - gi = @procedure.groupe_instructeurs.find_by({ label: option_label }) || @procedure.groupe_instructeurs - .create({ label: option_label, instructeurs: [current_administrateur.instructeur] }) - gi.update(routing_rule: ds_eq(champ_value(stable_id), constant(gi.label))) + routing_rule = ds_eq(champ_value(stable_id), constant(option_label)) + @procedure + .groupe_instructeurs + .find_or_create_by(label: option_label) + .update(instructeurs: [current_administrateur.instructeur], routing_rule:) + end + + if tdc.drop_down_other? + routing_rule = ds_eq(champ_value(stable_id), constant(Champs::DropDownListChamp::OTHER)) + @procedure + .groupe_instructeurs + .find_or_create_by(label: 'Autre') + .update(instructeurs: [current_administrateur.instructeur], routing_rule:) end @procedure.toggle_routing From 155a797abaf1c11469794fd67207aba8239fe74b Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Wed, 26 Jul 2023 17:28:28 +0200 Subject: [PATCH 4/7] feat(routing): update method checking if routling rule match tdc --- app/models/groupe_instructeur.rb | 3 ++- app/models/type_de_champ.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/groupe_instructeur.rb b/app/models/groupe_instructeur.rb index 7acf19561..133d01711 100644 --- a/app/models/groupe_instructeur.rb +++ b/app/models/groupe_instructeur.rb @@ -117,7 +117,8 @@ class GroupeInstructeur < ApplicationRecord def routing_rule_matches_tdc? routing_tdc = procedure.active_revision.types_de_champ.find_by(stable_id: routing_rule.left.stable_id) - routing_rule.right.value.in?(routing_tdc.options['drop_down_options']) + options = routing_tdc.options_with_drop_down_other + routing_rule.right.value.in?(options) end serialize :routing_rule, LogicSerializer diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 39a23f5a8..e6dc16c57 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -517,6 +517,14 @@ class TypeDeChamp < ApplicationRecord (drop_down_list_options - drop_down_list_disabled_options).reject(&:empty?) end + def options_with_drop_down_other + if drop_down_other? + drop_down_options + [Champs::DropDownListChamp::OTHER] + else + drop_down_options + end + end + def layer_enabled?(layer) options && options[layer] && options[layer] != '0' end From c85d7f8a5a2f8712e098fdb500e9e5c8aef2374d Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Wed, 26 Jul 2023 17:29:54 +0200 Subject: [PATCH 5/7] feat(routing): compute from selected if drop_down_other --- app/models/logic/champ_value.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb index 462f33880..dee68529f 100644 --- a/app/models/logic/champ_value.rb +++ b/app/models/logic/champ_value.rb @@ -31,7 +31,7 @@ class Logic::ChampValue < Logic::Term targeted_champ = champ(champs) return nil if !targeted_champ.visible? - return nil if targeted_champ.blank? + return nil if targeted_champ.blank? & !targeted_champ.drop_down_other? # on dépense 22ms ici, à cause du map, mais on doit pouvoir passer par un champ type case targeted_champ.type From cb3d971dcba33deabca4e95493f3f01fd1e886cf Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 28 Jul 2023 10:18:39 +0200 Subject: [PATCH 6/7] fix(routing): display Autre instead of __other__ in gis list --- app/models/logic/constant.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/logic/constant.rb b/app/models/logic/constant.rb index 201e37228..e1042d580 100644 --- a/app/models/logic/constant.rb +++ b/app/models/logic/constant.rb @@ -17,6 +17,8 @@ class Logic::Constant < Logic::Term I18n.t('utils.yes') when FalseClass I18n.t('utils.no') + when Champs::DropDownListChamp::OTHER + 'Autre' else @value.to_s end From 550b92500366bd4d5089aaec192ea013c36a99a1 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 28 Jul 2023 14:06:34 +0200 Subject: [PATCH 7/7] db(routing): task to update routing rule for groupe instructeurs routing from drop down other option --- ...r_groups_routing_from_drop_down_other.rake | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/tasks/deployment/20230728085422_update_routing_rule_for_groups_routing_from_drop_down_other.rake diff --git a/lib/tasks/deployment/20230728085422_update_routing_rule_for_groups_routing_from_drop_down_other.rake b/lib/tasks/deployment/20230728085422_update_routing_rule_for_groups_routing_from_drop_down_other.rake new file mode 100644 index 000000000..672975800 --- /dev/null +++ b/lib/tasks/deployment/20230728085422_update_routing_rule_for_groups_routing_from_drop_down_other.rake @@ -0,0 +1,23 @@ +namespace :after_party do + desc 'Deployment task: update_routing_rule_for_groups_routing_from_drop_down_other' + task update_routing_rule_for_groups_routing_from_drop_down_other: :environment do + puts "Running deploy task 'update_routing_rule_for_groups_routing_from_drop_down_other'" + + # Put your task implementation HERE. + include Logic + + GroupeInstructeur + .joins(:procedure) + .where(procedures: { routing_enabled: true }) + .in_batches do |groupe_instructeurs| + groupe_instructeurs + .filter { |gi| gi.routing_rule.present? && gi.routing_rule.right.value == 'Autre' } + .each { |gi| gi.update(routing_rule: ds_eq(gi.routing_rule.left, constant('__other__'))) } + end + + # Update task as completed. If you remove the line below, the task will + # run with every deploy (or every time you call after_party:run). + AfterParty::TaskRecord + .create version: AfterParty::TaskRecorder.new(__FILE__).timestamp + end +end