From ed2cbdc9661a59750800c1b884f668ffa83d56a1 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 30 Nov 2021 19:38:21 +0100 Subject: [PATCH 1/3] fix(champ): save departement name without code prefix --- app/javascript/components/ComboCommunesSearch.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/javascript/components/ComboCommunesSearch.jsx b/app/javascript/components/ComboCommunesSearch.jsx index 16a2815fe..c9dac0a21 100644 --- a/app/javascript/components/ComboCommunesSearch.jsx +++ b/app/javascript/components/ComboCommunesSearch.jsx @@ -93,10 +93,10 @@ function ComboCommunesSearch(params) { placeholder={placeholderDepartement} addForeignDepartement={false} required={params.mandatory} - onChange={(value, result) => { + onChange={(_, result) => { setDepartementCode(result?.code); if (hiddenDepartementField && hiddenCodeDepartementField) { - hiddenDepartementField.setAttribute('value', value); + hiddenDepartementField.setAttribute('value', result?.nom); hiddenCodeDepartementField.setAttribute('value', result?.code); } }} From fcbe364ac84fc74647c166617d3eb25e15e745a9 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 30 Nov 2021 19:39:25 +0100 Subject: [PATCH 2/3] feat(commune): display departement information on commune champ --- app/assets/stylesheets/utils.scss | 4 +++- app/models/champs/commune_champ.rb | 21 +++++++++++++++++++ .../shared/champs/communes/_show.html.haml | 11 +++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/utils.scss b/app/assets/stylesheets/utils.scss index 72c8b8e4e..f0cd725c9 100644 --- a/app/assets/stylesheets/utils.scss +++ b/app/assets/stylesheets/utils.scss @@ -50,7 +50,9 @@ color: $black; } - +.text-sm { + font-size: 14px; +} .mt-1 { margin-top: $default-spacer; diff --git a/app/models/champs/commune_champ.rb b/app/models/champs/commune_champ.rb index 5f3ccdc05..6a53d1101 100644 --- a/app/models/champs/commune_champ.rb +++ b/app/models/champs/commune_champ.rb @@ -25,4 +25,25 @@ class Champs::CommuneChamp < Champs::TextChamp def for_export [value, external_id] end + + def name_departement + #FIXME we originaly saved already formatted departement with the code in the name + departement&.gsub(/^(.[0-9])\s-\s/, '') + end + + def departement_code_and_name + "#{code_departement} - #{name_departement}" + end + + def departement? + departement.present? + end + + def code? + code.present? + end + + def code + external_id + end end diff --git a/app/views/shared/champs/communes/_show.html.haml b/app/views/shared/champs/communes/_show.html.haml index 4a901ea30..a162917b4 100644 --- a/app/views/shared/champs/communes/_show.html.haml +++ b/app/views/shared/champs/communes/_show.html.haml @@ -1,4 +1,9 @@ = format_text_value(champ.to_s) -- if champ.external_id.present? - Code INSEE : - = champ.external_id +- if champ.code? + %p.text-sm + Code INSEE : + = champ.code + - if champ.departement? + %br + Departement : + = champ.departement_code_and_name From 00369334259cd4a5c2c06725015895c1a952eb84 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 30 Nov 2021 19:44:07 +0100 Subject: [PATCH 3/3] feat(graphql): add commune and departement information to API --- app/graphql/api/v2/schema.rb | 1 + app/graphql/schema.graphql | 29 +++++++++++++++ app/graphql/types/champ_type.rb | 6 ++++ .../types/champs/commune_champ_type.rb | 36 +++++++++++++++++++ app/models/champs/commune_champ.rb | 2 +- 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 app/graphql/types/champs/commune_champ_type.rb diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index b783a5945..1b599ab86 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -43,6 +43,7 @@ class API::V2::Schema < GraphQL::Schema Types::Champs::CarteChampType, Types::Champs::CheckboxChampType, Types::Champs::CiviliteChampType, + Types::Champs::CommuneChampType, Types::Champs::DateChampType, Types::Champs::DatetimeChampType, Types::Champs::DecimalNumberChampType, diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index f50607b3c..3208c71fd 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -233,6 +233,30 @@ type CiviliteChamp implements Champ { value: Civilite } +type Commune { + """ + Le code INSEE + """ + code: String! + name: String! +} + +type CommuneChamp implements Champ { + commune: Commune + departement: Departement + id: ID! + + """ + Libellé du champ. + """ + label: String! + + """ + La valeur du champ sous forme texte. + """ + stringValue: String +} + """ GeoJSON coordinates """ @@ -649,6 +673,11 @@ enum DemarcheState { publiee } +type Departement { + code: String! + name: String! +} + """ Represents direct upload credentials """ diff --git a/app/graphql/types/champ_type.rb b/app/graphql/types/champ_type.rb index 4cb5bf989..e9e8900c0 100644 --- a/app/graphql/types/champ_type.rb +++ b/app/graphql/types/champ_type.rb @@ -25,6 +25,12 @@ module Types else Types::Champs::DateChampType end + when ::Champs::CommuneChamp + if context.has_fragment?(:CommuneChamp) + Types::Champs::CommuneChampType + else + Types::Champs::TextChampType + end when ::Champs::DossierLinkChamp Types::Champs::DossierLinkChampType when ::Champs::PieceJustificativeChamp diff --git a/app/graphql/types/champs/commune_champ_type.rb b/app/graphql/types/champs/commune_champ_type.rb new file mode 100644 index 000000000..a26403f18 --- /dev/null +++ b/app/graphql/types/champs/commune_champ_type.rb @@ -0,0 +1,36 @@ +module Types::Champs + class CommuneChampType < Types::BaseObject + implements Types::ChampType + + class CommuneType < Types::BaseObject + field :name, String, null: false + field :code, String, "Le code INSEE", null: false + end + + class DepartementType < Types::BaseObject + field :name, String, null: false + field :code, String, null: false + end + + field :commune, CommuneType, null: true + field :departement, DepartementType, null: true + + def commune + if object.code? + { + name: object.to_s, + code: object.code + } + end + end + + def departement + if object.departement? + { + name: object.name_departement, + code: object.code_departement + } + end + end + end +end diff --git a/app/models/champs/commune_champ.rb b/app/models/champs/commune_champ.rb index 6a53d1101..526814c52 100644 --- a/app/models/champs/commune_champ.rb +++ b/app/models/champs/commune_champ.rb @@ -27,7 +27,7 @@ class Champs::CommuneChamp < Champs::TextChamp end def name_departement - #FIXME we originaly saved already formatted departement with the code in the name + # FIXME we originaly saved already formatted departement with the code in the name departement&.gsub(/^(.[0-9])\s-\s/, '') end