Merge pull request #6704 from tchak/feat-commune-departement
Display commune departement information
This commit is contained in:
commit
b83425896d
8 changed files with 106 additions and 6 deletions
|
@ -50,7 +50,9 @@
|
||||||
color: $black;
|
color: $black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text-sm {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
.mt-1 {
|
.mt-1 {
|
||||||
margin-top: $default-spacer;
|
margin-top: $default-spacer;
|
||||||
|
|
|
@ -43,6 +43,7 @@ class API::V2::Schema < GraphQL::Schema
|
||||||
Types::Champs::CarteChampType,
|
Types::Champs::CarteChampType,
|
||||||
Types::Champs::CheckboxChampType,
|
Types::Champs::CheckboxChampType,
|
||||||
Types::Champs::CiviliteChampType,
|
Types::Champs::CiviliteChampType,
|
||||||
|
Types::Champs::CommuneChampType,
|
||||||
Types::Champs::DateChampType,
|
Types::Champs::DateChampType,
|
||||||
Types::Champs::DatetimeChampType,
|
Types::Champs::DatetimeChampType,
|
||||||
Types::Champs::DecimalNumberChampType,
|
Types::Champs::DecimalNumberChampType,
|
||||||
|
|
|
@ -233,6 +233,30 @@ type CiviliteChamp implements Champ {
|
||||||
value: Civilite
|
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
|
GeoJSON coordinates
|
||||||
"""
|
"""
|
||||||
|
@ -649,6 +673,11 @@ enum DemarcheState {
|
||||||
publiee
|
publiee
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Departement {
|
||||||
|
code: String!
|
||||||
|
name: String!
|
||||||
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Represents direct upload credentials
|
Represents direct upload credentials
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -25,6 +25,12 @@ module Types
|
||||||
else
|
else
|
||||||
Types::Champs::DateChampType
|
Types::Champs::DateChampType
|
||||||
end
|
end
|
||||||
|
when ::Champs::CommuneChamp
|
||||||
|
if context.has_fragment?(:CommuneChamp)
|
||||||
|
Types::Champs::CommuneChampType
|
||||||
|
else
|
||||||
|
Types::Champs::TextChampType
|
||||||
|
end
|
||||||
when ::Champs::DossierLinkChamp
|
when ::Champs::DossierLinkChamp
|
||||||
Types::Champs::DossierLinkChampType
|
Types::Champs::DossierLinkChampType
|
||||||
when ::Champs::PieceJustificativeChamp
|
when ::Champs::PieceJustificativeChamp
|
||||||
|
|
36
app/graphql/types/champs/commune_champ_type.rb
Normal file
36
app/graphql/types/champs/commune_champ_type.rb
Normal 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
|
|
@ -93,10 +93,10 @@ function ComboCommunesSearch(params) {
|
||||||
placeholder={placeholderDepartement}
|
placeholder={placeholderDepartement}
|
||||||
addForeignDepartement={false}
|
addForeignDepartement={false}
|
||||||
required={params.mandatory}
|
required={params.mandatory}
|
||||||
onChange={(value, result) => {
|
onChange={(_, result) => {
|
||||||
setDepartementCode(result?.code);
|
setDepartementCode(result?.code);
|
||||||
if (hiddenDepartementField && hiddenCodeDepartementField) {
|
if (hiddenDepartementField && hiddenCodeDepartementField) {
|
||||||
hiddenDepartementField.setAttribute('value', value);
|
hiddenDepartementField.setAttribute('value', result?.nom);
|
||||||
hiddenCodeDepartementField.setAttribute('value', result?.code);
|
hiddenCodeDepartementField.setAttribute('value', result?.code);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -25,4 +25,25 @@ class Champs::CommuneChamp < Champs::TextChamp
|
||||||
def for_export
|
def for_export
|
||||||
[value, external_id]
|
[value, external_id]
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
= format_text_value(champ.to_s)
|
= format_text_value(champ.to_s)
|
||||||
- if champ.external_id.present?
|
- if champ.code?
|
||||||
|
%p.text-sm
|
||||||
Code INSEE :
|
Code INSEE :
|
||||||
= champ.external_id
|
= champ.code
|
||||||
|
- if champ.departement?
|
||||||
|
%br
|
||||||
|
Departement :
|
||||||
|
= champ.departement_code_and_name
|
||||||
|
|
Loading…
Add table
Reference in a new issue