Add annuaire_education champ ui

This commit is contained in:
Paul Chavard 2021-01-14 17:30:55 +01:00
parent 54f2084aef
commit 91be115c70
7 changed files with 98 additions and 2 deletions

View file

@ -0,0 +1,28 @@
import React from 'react';
import { ReactQueryCacheProvider } from 'react-query';
import ComboSearch from './ComboSearch';
import { queryCache } from './shared/queryCache';
function ComboAnnuaireEducationSearch(params) {
return (
<ReactQueryCacheProvider queryCache={queryCache}>
<ComboSearch
required={params.mandatory}
hiddenFieldId={params.hiddenFieldId}
scope="annuaire-education"
minimumInputLength={3}
transformResults={(_, { records }) => records}
transformResult={({
fields: {
identifiant_de_l_etablissement: id,
nom_etablissement,
nom_commune
}
}) => [id, `${nom_etablissement}, ${nom_commune} (${id})`]}
/>
</ReactQueryCacheProvider>
);
}
export default ComboAnnuaireEducationSearch;

View file

@ -2,7 +2,8 @@ import { QueryCache } from 'react-query';
import { isNumeric } from '@utils';
import matchSorter from 'match-sorter';
const { api_geo_url, api_adresse_url } = gon.autocomplete || {};
const { api_geo_url, api_adresse_url, api_education_url } =
gon.autocomplete || {};
export const queryCache = new QueryCache({
defaultConfig: {
@ -13,8 +14,11 @@ export const queryCache = new QueryCache({
});
function buildURL(scope, term) {
term = encodeURIComponent(term);
if (scope === 'adresse') {
return `${api_adresse_url}/search?q=${term}&limit=5`;
} else if (scope === 'annuaire-education') {
return `${api_education_url}/search?dataset=fr-en-annuaire-education&q=${term}&rows=5`;
} else if (isNumeric(term)) {
const code = term.padStart(2, '0');
return `${api_geo_url}/${scope}?code=${code}&limit=5`;

View file

@ -0,0 +1,5 @@
import Loadable from '../components/Loadable';
export default Loadable(() =>
import('../components/ComboAnnuaireEducationSearch')
);

View file

@ -0,0 +1,54 @@
- if champ.data.blank?
= champ.to_s
- else
%table.table.vertical.dossier-champs
%tbody
%tr
%th.libelle Nom de létablissement :
%td= champ.data['nom_etablissement']
%tr
%th.libelle Lidentifiant de letablissement :
%td= champ.data['identifiant_de_l_etablissement']
%tr
%th.libelle SIREN/SIRET :
%td= champ.data['siren_siret']
%tr
%th.libelle Commune :
%td= "#{champ.data['nom_commune']} (#{champ.data['code_commune']})"
%tr
%th.libelle Academie :
%td= "#{champ.data['libelle_academie']} (#{champ.data['code_academie']})"
%tr
%th.libelle Nature de létablissement :
%td= "#{champ.data['libelle_nature']} (#{champ.data['code_nature']})"
- if champ.data['type_contrat_prive'] != 'SANS OBJET'
%tr
%th.libelle Type de contrat privé :
%td= champ.data['type_contrat_prive']
%tr
%th.libelle Nombre délèves :
%td= champ.data['nombre_d_eleves']
%tr
%th.libelle Adresse :
%td
= champ.data['adresse_1']
%br
= "#{champ.data['code_postal']} #{champ.data['nom_commune']}"
%br
= "#{champ.data['libelle_region']} (#{champ.data['code_region']})"
- if champ.data['telephone'].present?
%tr
%th.libelle Téléphone :
%td= champ.data['telephone']
- if champ.data['mail'].present?
%tr
%th.libelle Email :
%td= champ.data['mail']
- if champ.data['web'].present?
%tr
%th.libelle Site internet :
%td= champ.data['web']

View file

@ -34,6 +34,8 @@
= render partial: "shared/champs/iban/show", locals: { champ: c }
- when TypeDeChamp.type_champs.fetch(:textarea)
= render partial: "shared/champs/textarea/show", locals: { champ: c }
- when TypeDeChamp.type_champs.fetch(:annuaire_education)
= render partial: "shared/champs/annuaire_education/show", locals: { champ: c }
- when TypeDeChamp.type_champs.fetch(:date)
= c.to_s
- when TypeDeChamp.type_champs.fetch(:datetime)

View file

@ -0,0 +1,3 @@
- hidden_field_id = SecureRandom.uuid
= form.hidden_field :value, { data: { uuid: hidden_field_id } }
= react_component("ComboAnnuaireEducationSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id )

View file

@ -9,7 +9,7 @@ Rails.application.config.content_security_policy do |policy|
# c'est trop compliqué pour être rectifié immédiatement (et sans valeur ajoutée:
# c'est hardcodé dans les vues, donc pas injectable).
policy.style_src :self, "*.crisp.chat", "crisp.chat", 'cdn.jsdelivr.net', 'maxcdn.bootstrapcdn.com', :unsafe_inline
policy.connect_src :self, "wss://*.crisp.chat", "*.crisp.chat", "*.demarches-simplifiees.fr", "in-automate.sendinblue.com", "app.franceconnect.gouv.fr", "sentry.io", "geo.api.gouv.fr", "api-adresse.data.gouv.fr", "openmaptiles.geo.data.gouv.fr", "openmaptiles.github.io", "tiles.geo.api.gouv.fr", "wxs.ign.fr"
policy.connect_src :self, "wss://*.crisp.chat", "*.crisp.chat", "*.demarches-simplifiees.fr", "in-automate.sendinblue.com", "app.franceconnect.gouv.fr", "sentry.io", "geo.api.gouv.fr", "api-adresse.data.gouv.fr", "openmaptiles.geo.data.gouv.fr", "openmaptiles.github.io", "tiles.geo.api.gouv.fr", "wxs.ign.fr", "data.education.gouv.fr"
# Pour tout le reste, par défaut on accepte uniquement ce qui vient de chez nous
# et dans la notification on inclue la source de l'erreur
policy.default_src :self, :data, :blob, :report_sample, "fonts.gstatic.com", "in-automate.sendinblue.com", "player.vimeo.com", "app.franceconnect.gouv.fr", "sentry.io", "static.demarches-simplifiees.fr", "*.crisp.chat", "crisp.chat", "*.crisp.help", "*.sibautomation.com", "sibautomation.com", "data"