Merge pull request #6704 from tchak/feat-commune-departement

Display commune departement information
This commit is contained in:
Paul Chavard 2021-12-06 21:08:00 +01:00 committed by GitHub
commit b83425896d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 106 additions and 6 deletions

View file

@ -50,7 +50,9 @@
color: $black;
}
.text-sm {
font-size: 14px;
}
.mt-1 {
margin-top: $default-spacer;

View file

@ -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,

View file

@ -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
"""

View file

@ -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

View file

@ -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

View file

@ -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);
}
}}

View file

@ -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

View file

@ -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