factorize departements and regions options
This commit is contained in:
parent
aa8ce15c2a
commit
08fb49d176
13 changed files with 27 additions and 26 deletions
|
@ -10,7 +10,7 @@ class EditableChamp::DepartementsComponent < EditableChamp::EditableChampBaseCom
|
|||
end
|
||||
|
||||
def options
|
||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
APIGeoService.departement_options
|
||||
end
|
||||
|
||||
def select_options
|
||||
|
|
|
@ -10,7 +10,7 @@ class EditableChamp::RegionsComponent < EditableChamp::EditableChampBaseComponen
|
|||
private
|
||||
|
||||
def options
|
||||
APIGeoService.regions.map { [_1[:name], _1[:code]] }
|
||||
APIGeoService.region_options
|
||||
end
|
||||
|
||||
def select_options
|
||||
|
|
|
@ -49,16 +49,16 @@ module Administrateurs
|
|||
|
||||
case tdc.type_champ
|
||||
when TypeDeChamp.type_champs.fetch(:departements)
|
||||
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
tdc_options = APIGeoService.departement_options
|
||||
rule_operator = :ds_eq
|
||||
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
||||
when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:epci), TypeDeChamp.type_champs.fetch(:address)
|
||||
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
tdc_options = APIGeoService.departement_options
|
||||
rule_operator = :ds_in_departement
|
||||
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
||||
when TypeDeChamp.type_champs.fetch(:regions)
|
||||
rule_operator = :ds_eq
|
||||
tdc_options = APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
tdc_options = APIGeoService.region_options
|
||||
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
||||
when TypeDeChamp.type_champs.fetch(:pays)
|
||||
rule_operator = :ds_eq
|
||||
|
|
|
@ -5,15 +5,11 @@ module AddressableColumnConcern
|
|||
|
||||
included do
|
||||
def columns(procedure:, displayable: true, prefix: nil)
|
||||
departement_options = APIGeoService.departements
|
||||
.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
region_options = APIGeoService.regions.map { [_1[:name], _1[:name]] }
|
||||
|
||||
addressable_columns = [
|
||||
["code postal (5 chiffres)", '$.postal_code', :text, []],
|
||||
["commune", '$.city_name', :text, []],
|
||||
["département", '$.departement_code', :enum, departement_options],
|
||||
["region", '$.region_name', :enum, region_options]
|
||||
["département", '$.departement_code', :enum, APIGeoService.departement_options],
|
||||
["region", '$.region_name', :enum, APIGeoService.region_options]
|
||||
].map do |(label, jsonpath, type, options_for_select)|
|
||||
Columns::JSONPathColumn.new(
|
||||
procedure_id: procedure.id,
|
||||
|
|
|
@ -131,9 +131,9 @@ class Logic::ChampValue < Logic::Term
|
|||
tdc = type_de_champ(type_de_champs)
|
||||
|
||||
if operator_name.in?([Logic::InRegionOperator.name, Logic::NotInRegionOperator.name]) || tdc.type_champ == MANAGED_TYPE_DE_CHAMP.fetch(:regions)
|
||||
APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
APIGeoService.region_options
|
||||
elsif operator_name.in?([Logic::InDepartementOperator.name, Logic::NotInDepartementOperator.name]) || tdc.type_champ.in?([MANAGED_TYPE_DE_CHAMP.fetch(:communes), MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:address)])
|
||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
APIGeoService.departement_options
|
||||
elsif tdc.type_champ == MANAGED_TYPE_DE_CHAMP.fetch(:pays)
|
||||
APIGeoService.countries.map { ["#{_1[:name]} – #{_1[:code]}", _1[:code]] }
|
||||
else
|
||||
|
|
|
@ -547,9 +547,9 @@ class TypeDeChamp < ApplicationRecord
|
|||
|
||||
def options_for_select
|
||||
if departement?
|
||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }.sort
|
||||
APIGeoService.departement_options
|
||||
elsif region?
|
||||
APIGeoService.regions.map { [_1[:name], _1[:code]] }
|
||||
APIGeoService.region_options
|
||||
elsif drop_down_list?
|
||||
drop_down_options
|
||||
elsif yes_no?
|
||||
|
|
|
@ -27,6 +27,8 @@ class APIGeoService
|
|||
get_from_api_geo(:regions).sort_by { I18n.transliterate(_1[:name]) }
|
||||
end
|
||||
|
||||
def region_options = regions.map { [_1[:name], _1[:code]] }
|
||||
|
||||
def region_name(code)
|
||||
regions.find { _1[:code] == code }&.dig(:name)
|
||||
end
|
||||
|
@ -42,7 +44,11 @@ class APIGeoService
|
|||
end
|
||||
|
||||
def departements
|
||||
[{ code: '99', name: 'Etranger' }] + get_from_api_geo(:departements).sort_by { _1[:code] }
|
||||
([{ code: '99', name: 'Etranger' }] + get_from_api_geo(:departements)).sort_by { _1[:code] }
|
||||
end
|
||||
|
||||
def departement_options
|
||||
departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
end
|
||||
|
||||
def departement_name(code)
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
|
||||
%div
|
||||
= f.select :service_departement,
|
||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] },
|
||||
APIGeoService.departement_options,
|
||||
{ selected: @filter.service_departement, include_blank: ''},
|
||||
id: "service_dep_select",
|
||||
class: 'fr-select'
|
||||
|
|
|
@ -123,7 +123,7 @@ describe Conditions::ChampsConditionsComponent, type: :component do
|
|||
let(:regions) { create(:type_de_champ_regions) }
|
||||
let(:upper_tdcs) { [regions] }
|
||||
let(:condition) { empty_operator(champ_value(regions.stable_id), constant(true)) }
|
||||
let(:region_options) { APIGeoService.regions.map { "#{_1[:code]} – #{_1[:name]}" } }
|
||||
let(:region_options) { APIGeoService.regions.map { _1[:name] } }
|
||||
|
||||
it do
|
||||
expect(page).to have_select('type_de_champ[condition_form][rows][][operator_name]', with_options: ['Est'])
|
||||
|
|
|
@ -959,8 +959,8 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
it do
|
||||
expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure3))
|
||||
expect(flash.notice).to eq 'Les groupes instructeurs ont été ajoutés'
|
||||
expect(procedure3.groupe_instructeurs.pluck(:label)).to include("01 – Guadeloupe")
|
||||
expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_eq(champ_value(regions_tdc.stable_id), constant('01')))
|
||||
expect(procedure3.groupe_instructeurs.pluck(:label)).to include("Guadeloupe")
|
||||
expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_eq(champ_value(regions_tdc.stable_id), constant('84')))
|
||||
expect(procedure3.routing_enabled).to be_truthy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ describe 're_routing_dossiers' do
|
|||
|
||||
tdc = procedure.active_revision.simple_routable_types_de_champ.first
|
||||
|
||||
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
tdc_options = APIGeoService.departement_options
|
||||
|
||||
rule_operator = :ds_eq
|
||||
|
||||
|
|
|
@ -32,9 +32,8 @@ describe APIGeoService do
|
|||
describe 'departements' do
|
||||
it 'return sorted results' do
|
||||
expect(APIGeoService.departements.size).to eq(110)
|
||||
expect(APIGeoService.departements.first).to eq(code: '99', name: 'Etranger')
|
||||
expect(APIGeoService.departements.second).to eq(code: '01', name: 'Ain', region_code: "84")
|
||||
expect(APIGeoService.departements.last).to eq(code: '989', name: 'Île de Clipperton', region_code: "989")
|
||||
expect(APIGeoService.departements.first).to eq(code: '01', name: 'Ain', region_code: "84")
|
||||
expect(APIGeoService.departements.last).to eq(code: '99', name: 'Etranger')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -556,7 +556,7 @@ describe DossierFilterService do
|
|||
|
||||
it 'describes column' do
|
||||
expect(column.type).to eq(:enum)
|
||||
expect(column.options_for_select.first).to eq(["99 – Etranger", "99"])
|
||||
expect(column.options_for_select.first).to eq(["01 – Ain", "01"])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -573,7 +573,7 @@ describe DossierFilterService do
|
|||
|
||||
it 'describes column' do
|
||||
expect(column.type).to eq(:enum)
|
||||
expect(column.options_for_select.first).to eq(["Auvergne-Rhône-Alpes", "Auvergne-Rhône-Alpes"])
|
||||
expect(column.options_for_select.first).to eq(["Auvergne-Rhône-Alpes", "84"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue