Merge branch 'dev' into instruct-filter-yes-no

This commit is contained in:
jpoulvel 2020-06-16 14:53:22 +02:00 committed by GitHub
commit adaf0753b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 410 additions and 306 deletions

View file

@ -245,7 +245,7 @@ GEM
et-orbi (~> 1.1, >= 1.1.8) et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.1) raabro (~> 1.1)
geo_coord (0.1.0) geo_coord (0.1.0)
geocoder (1.6.0) geocoder (1.6.1)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
gon (6.3.2) gon (6.3.2)

View file

@ -0,0 +1,13 @@
.areas-title {
font-weight: bold;
margin-top: 5px;
margin-bottom: 5px;
}
.areas {
margin-bottom: 10px;
input {
margin-top: 5px;
}
}

View file

@ -1,80 +0,0 @@
.carte {
height: 400px;
margin-bottom: 16px;
z-index: 0;
}
.leaflet-container path {
cursor: url("/assets/edit.png"), default !important;
}
.carte {
&.edit {
g path.leaflet-polygon {
transition: all 0.25s;
stroke-width: 4px;
stroke-opacity: 1;
stroke: #D7217E;
position: absolute;
z-index: 100;
fill: #D7217E;
fill-opacity: 0.75;
}
div.leaflet-edge {
box-shadow: 0 0 0 2px #FFFFFF, 0 0 10px rgba(0, 0, 0, 0.35);
border: 5px solid #D7217E;
border-radius: 10px;
transition: opacity 0.25s;
cursor: move;
opacity: 0;
pointer-events: none;
box-sizing: border-box;
width: 0 !important;
height: 0 !important;
}
}
&.mode-create {
cursor: url("/assets/pencil.png"), crosshair !important;
}
&.mode-edit div.leaflet-edge {
opacity: 1;
pointer-events: all;
}
&.mode-delete path.leaflet-polygon {
cursor: no-drop !important;
&:hover {
fill: #4D4D4D !important;
}
}
}
.editable-champ-carte {
.toolbar {
display: flex;
align-items: center;
margin-bottom: 10px;
.button {
width: 200px;
margin-right: 10px;
}
.select2-container {
margin-bottom: 0;
}
}
}
.areas-title {
font-weight: bold;
margin-bottom: 5px;
}
.areas {
margin-bottom: 10px;
}

View file

@ -53,3 +53,7 @@
.mt-2 { .mt-2 {
margin-top: 2 * $default-spacer; margin-top: 2 * $default-spacer;
} }
.mb-2 {
margin-bottom: 2 * $default-spacer;
}

View file

@ -19,7 +19,7 @@ class Champs::CarteController < ApplicationController
def create def create
champ = policy_scope(Champ).find(params[:champ_id]) champ = policy_scope(Champ).find(params[:champ_id])
geo_area = champ.geo_areas.selections_utilisateur.new geo_area = champ.geo_areas.selections_utilisateur.new
save_geometry!(geo_area, params_feature) save_feature!(geo_area, params_feature)
render json: { feature: geo_area.to_feature }, status: :created render json: { feature: geo_area.to_feature }, status: :created
end end
@ -27,7 +27,7 @@ class Champs::CarteController < ApplicationController
def update def update
champ = policy_scope(Champ).find(params[:champ_id]) champ = policy_scope(Champ).find(params[:champ_id])
geo_area = champ.geo_areas.selections_utilisateur.find(params[:id]) geo_area = champ.geo_areas.selections_utilisateur.find(params[:id])
save_geometry!(geo_area, params_feature) save_feature!(geo_area, params_feature)
head :no_content head :no_content
end end
@ -43,7 +43,7 @@ class Champs::CarteController < ApplicationController
champ = policy_scope(Champ).find(params[:champ_id]) champ = policy_scope(Champ).find(params[:champ_id])
params_features.each do |feature| params_features.each do |feature|
geo_area = champ.geo_areas.selections_utilisateur.new geo_area = champ.geo_areas.selections_utilisateur.new
save_geometry!(geo_area, feature) save_feature!(geo_area, feature)
end end
render json: champ.to_feature_collection, status: :created render json: champ.to_feature_collection, status: :created
@ -59,8 +59,13 @@ class Champs::CarteController < ApplicationController
params[:features] params[:features]
end end
def save_geometry!(geo_area, feature) def save_feature!(geo_area, feature)
geo_area.geometry = feature[:geometry] if feature[:geometry]
geo_area.geometry = feature[:geometry]
end
if feature[:properties] && feature[:properties][:description]
geo_area.description = feature[:properties][:description]
end
geo_area.save! geo_area.save!
end end

View file

@ -46,7 +46,7 @@ class Champs::SiretController < ApplicationController
@champ = policy_scope(Champ).find(params[:champ_id]) @champ = policy_scope(Champ).find(params[:champ_id])
@etablissement = @champ&.etablissement @etablissement = @champ&.etablissement
end end
@procedure_id = @champ&.dossier&.procedure_id || 'aperçu' @procedure_id = @champ&.dossier&.procedure&.id || 'aperçu'
end end
def find_etablissement_with_siret def find_etablissement_with_siret

View file

@ -5,7 +5,7 @@ module Instructeurs
@dossiers = DossierSearchService.matching_dossiers_for_instructeur(@search_terms, current_instructeur) @dossiers = DossierSearchService.matching_dossiers_for_instructeur(@search_terms, current_instructeur)
@followed_dossiers_id = current_instructeur @followed_dossiers_id = current_instructeur
.followed_dossiers .followed_dossiers
.where(procedure_id: @dossiers.pluck(:procedure_id)) .where(groupe_instructeur_id: @dossiers.pluck(:groupe_instructeur_id))
.pluck(:id) .pluck(:id)
end end
end end

View file

@ -1,69 +1,102 @@
import React, { useState, useRef, useEffect } from 'react'; import React, { useState, useCallback, useRef } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import mapboxgl from 'mapbox-gl'; import mapboxgl from 'mapbox-gl';
import ReactMapboxGl, { GeoJSONLayer, ZoomControl } from 'react-mapbox-gl'; import ReactMapboxGl, { GeoJSONLayer, ZoomControl } from 'react-mapbox-gl';
import DrawControl from 'react-mapbox-gl-draw'; import DrawControl from 'react-mapbox-gl-draw';
import SwitchMapStyle from './SwitchMapStyle';
import SearchInput from './SearchInput';
import { getJSON, ajax } from '@utils';
import { gpx, kml } from '@tmcw/togeojson/dist/togeojson.es.js'; import { gpx, kml } from '@tmcw/togeojson/dist/togeojson.es.js';
import ortho from '../MapStyles/ortho.json';
import orthoCadastre from '../MapStyles/orthoCadastre.json';
import vector from '../MapStyles/vector.json';
import vectorCadastre from '../MapStyles/vectorCadastre.json';
import { polygonCadastresFill, polygonCadastresLine } from './utils';
import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css'; import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
import { getJSON, ajax, fire } from '@utils';
import SwitchMapStyle from './SwitchMapStyle';
import { getMapStyle } from '../MapStyles';
import SearchInput from './SearchInput';
import { polygonCadastresFill, polygonCadastresLine } from './utils';
import {
noop,
filterFeatureCollection,
fitBounds,
generateId,
useEvent,
findFeature
} from '../shared/map';
const Map = ReactMapboxGl({}); const Map = ReactMapboxGl({});
function filterFeatureCollection(featureCollection, source) {
return {
type: 'FeatureCollection',
features: featureCollection.features.filter(
(feature) => feature.properties.source === source
)
};
}
function noop() {}
function MapEditor({ featureCollection, url, preview, hasCadastres }) { function MapEditor({ featureCollection, url, preview, hasCadastres }) {
const drawControl = useRef(null); const drawControl = useRef(null);
const [currentMap, setCurrentMap] = useState(null);
const [style, setStyle] = useState('ortho'); const [style, setStyle] = useState('ortho');
const [coords, setCoords] = useState([1.7, 46.9]); const [coords, setCoords] = useState([1.7, 46.9]);
const [zoom, setZoom] = useState([5]); const [zoom, setZoom] = useState([5]);
const [currentMap, setCurrentMap] = useState({});
const [bbox, setBbox] = useState(featureCollection.bbox); const [bbox, setBbox] = useState(featureCollection.bbox);
const [importInputs, setImportInputs] = useState([]); const [importInputs, setImportInputs] = useState([]);
let mapStyle = style === 'ortho' ? ortho : vector; const [cadastresFeatureCollection, setCadastresFeatureCollection] = useState(
filterFeatureCollection(featureCollection, 'cadastre')
);
const mapStyle = getMapStyle(style, hasCadastres);
if (hasCadastres) { const onFeatureFocus = useCallback(
mapStyle = style === 'ortho' ? orthoCadastre : vectorCadastre; ({ detail }) => {
} const { id } = detail;
const featureCollection = drawControl.current.draw.getAll();
const cadastresFeatureCollection = filterFeatureCollection( const feature = findFeature(featureCollection, id);
featureCollection, if (feature) {
'cadastre' fitBounds(currentMap, feature);
}
},
[currentMap, drawControl.current]
); );
function updateFeaturesList(features) { const onFeatureUpdate = useCallback(
const cadastres = features.find( async ({ detail }) => {
({ geometry }) => geometry.type === 'Polygon' const { id, properties } = detail;
const featureCollection = drawControl.current.draw.getAll();
const feature = findFeature(featureCollection, id);
if (feature) {
getJSON(`${url}/${id}`, { feature: { properties } }, 'patch');
}
},
[url, drawControl.current]
);
const updateFeaturesList = useCallback(
async (features) => {
const cadastres = features.find(
({ geometry }) => geometry.type === 'Polygon'
);
await ajax({
url,
type: 'get',
data: cadastres ? 'cadastres=update' : ''
});
fire(document, 'ds:page:update');
},
[url]
);
const onCadastresUpdate = useCallback(({ detail }) => {
setCadastresFeatureCollection(
filterFeatureCollection(detail.featureCollection, 'cadastre')
); );
ajax({ url, type: 'get', data: cadastres ? 'cadastres=update' : '' }); }, []);
}
useEvent('map:feature:focus', onFeatureFocus);
useEvent('map:feature:update', onFeatureUpdate);
useEvent('cadastres:update', onCadastresUpdate);
function setFeatureId(lid, feature) { function setFeatureId(lid, feature) {
const draw = drawControl.current.draw; const draw = drawControl.current.draw;
draw.setFeatureProperty(lid, 'id', feature.properties.id); draw.setFeatureProperty(lid, 'id', feature.properties.id);
} }
const generateId = () => Math.random().toString(20).substr(2, 6); function updateImportInputs(inputs, inputId) {
const updateImportInputs = (inputs, inputId) => {
const updatedInputs = inputs.filter((input) => input.id !== inputId); const updatedInputs = inputs.filter((input) => input.id !== inputId);
setImportInputs(updatedInputs); setImportInputs(updatedInputs);
}; }
async function onDrawCreate({ features }) { async function onDrawCreate({ features }) {
for (const feature of features) { for (const feature of features) {
@ -92,23 +125,13 @@ function MapEditor({ featureCollection, url, preview, hasCadastres }) {
updateFeaturesList(features); updateFeaturesList(features);
} }
const onMapLoad = (map) => { function onMapLoad(map) {
setCurrentMap(map); setCurrentMap(map);
drawControl.current.draw.set( drawControl.current.draw.set(
filterFeatureCollection(featureCollection, 'selection_utilisateur') filterFeatureCollection(featureCollection, 'selection_utilisateur')
); );
}; }
const onCadastresUpdate = (evt) => {
if (currentMap) {
currentMap
.getSource('cadastres-layer')
.setData(
filterFeatureCollection(evt.detail.featureCollection, 'cadastre')
);
}
};
const onFileImport = (e, inputId) => { const onFileImport = (e, inputId) => {
const isGpxFile = e.target.files[0].name.includes('.gpx'); const isGpxFile = e.target.files[0].name.includes('.gpx');
@ -190,11 +213,6 @@ function MapEditor({ featureCollection, url, preview, hasCadastres }) {
updateImportInputs(inputs, inputId); updateImportInputs(inputs, inputId);
}; };
useEffect(() => {
addEventListener('cadastres:update', onCadastresUpdate);
return () => removeEventListener('cadastres:update', onCadastresUpdate);
});
if (!mapboxgl.supported()) { if (!mapboxgl.supported()) {
return ( return (
<p> <p>

View file

@ -1,25 +1,100 @@
import React, { useState } from 'react'; import React, { useState, useCallback, useMemo } from 'react';
import ReactMapboxGl, { ZoomControl, GeoJSONLayer } from 'react-mapbox-gl'; import ReactMapboxGl, { ZoomControl, GeoJSONLayer } from 'react-mapbox-gl';
import mapboxgl from 'mapbox-gl'; import mapboxgl, { Popup } from 'mapbox-gl';
import SwitchMapStyle from './SwitchMapStyle';
import ortho from '../MapStyles/ortho.json';
import orthoCadastre from '../MapStyles/orthoCadastre.json';
import vector from '../MapStyles/vector.json';
import vectorCadastre from '../MapStyles/vectorCadastre.json';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import SwitchMapStyle from './SwitchMapStyle';
import { getMapStyle } from '../MapStyles';
import {
filterFeatureCollection,
filterFeatureCollectionByGeometryType,
useEvent,
findFeature,
fitBounds,
getCenter
} from '../shared/map';
const Map = ReactMapboxGl({}); const Map = ReactMapboxGl({});
const MapReader = ({ featureCollection }) => { const MapReader = ({ featureCollection }) => {
const [currentMap, setCurrentMap] = useState(null);
const [style, setStyle] = useState('ortho'); const [style, setStyle] = useState('ortho');
const hasCadastres = featureCollection.features.find( const cadastresFeatureCollection = useMemo(
(feature) => feature.properties.source === 'cadastre' () => filterFeatureCollection(featureCollection, 'cadastre'),
[featureCollection]
);
const selectionsUtilisateurFeatureCollection = useMemo(
() => filterFeatureCollection(featureCollection, 'selection_utilisateur'),
[featureCollection]
);
const selectionsLineFeatureCollection = useMemo(
() =>
filterFeatureCollectionByGeometryType(
selectionsUtilisateurFeatureCollection,
'LineString'
),
[selectionsUtilisateurFeatureCollection]
);
const selectionsPolygonFeatureCollection = useMemo(
() =>
filterFeatureCollectionByGeometryType(
selectionsUtilisateurFeatureCollection,
'Polygon'
),
[selectionsUtilisateurFeatureCollection]
);
const selectionsPointFeatureCollection = useMemo(
() =>
filterFeatureCollectionByGeometryType(
selectionsUtilisateurFeatureCollection,
'Point'
),
[selectionsUtilisateurFeatureCollection]
);
const mapStyle = useMemo(
() => getMapStyle(style, cadastresFeatureCollection.length),
[style, cadastresFeatureCollection]
);
const popup = useMemo(
() =>
new Popup({
closeButton: false,
closeOnClick: false
})
); );
let mapStyle = style === 'ortho' ? ortho : vector;
if (hasCadastres) { const onMouseEnter = useCallback(
mapStyle = style === 'ortho' ? orthoCadastre : vectorCadastre; (event) => {
} const feature = event.features[0];
if (feature.properties && feature.properties.description) {
const coordinates = getCenter(feature.geometry, event.lngLat);
const description = feature.properties.description;
currentMap.getCanvas().style.cursor = 'pointer';
popup.setLngLat(coordinates).setHTML(description).addTo(currentMap);
} else {
popup.remove();
}
},
[currentMap, popup]
);
const onMouseLeave = useCallback(() => {
currentMap.getCanvas().style.cursor = '';
popup.remove();
}, [currentMap, popup]);
const onFeatureFocus = useCallback(
({ detail }) => {
const feature = findFeature(featureCollection, detail.id);
if (feature) {
fitBounds(currentMap, feature);
}
},
[currentMap, featureCollection]
);
useEvent('map:feature:focus', onFeatureFocus);
const [a1, a2, b1, b2] = featureCollection.bbox; const [a1, a2, b1, b2] = featureCollection.bbox;
const boundData = [ const boundData = [
@ -27,26 +102,6 @@ const MapReader = ({ featureCollection }) => {
[b1, b2] [b1, b2]
]; ];
const cadastresFeatureCollection = {
type: 'FeatureCollection',
features: []
};
const selectionsLineFeatureCollection = {
type: 'FeatureCollection',
features: []
};
const selectionsPolygonFeatureCollection = {
type: 'FeatureCollection',
features: []
};
const selectionsPointFeatureCollection = {
type: 'FeatureCollection',
features: []
};
const polygonSelectionFill = { const polygonSelectionFill = {
'fill-color': '#EC3323', 'fill-color': '#EC3323',
'fill-opacity': 0.5 'fill-opacity': 0.5
@ -77,25 +132,8 @@ const MapReader = ({ featureCollection }) => {
'line-dasharray': [1, 1] 'line-dasharray': [1, 1]
}; };
for (let feature of featureCollection.features) { function onMapLoad(map) {
switch (feature.properties.source) { setCurrentMap(map);
case 'selection_utilisateur':
switch (feature.geometry.type) {
case 'LineString':
selectionsLineFeatureCollection.features.push(feature);
break;
case 'Polygon':
selectionsPolygonFeatureCollection.features.push(feature);
break;
case 'Point':
selectionsPointFeatureCollection.features.push(feature);
break;
}
break;
case 'cadastre':
cadastresFeatureCollection.features.push(feature);
break;
}
} }
if (!mapboxgl.supported()) { if (!mapboxgl.supported()) {
@ -110,6 +148,7 @@ const MapReader = ({ featureCollection }) => {
return ( return (
<Map <Map
onStyleLoad={(map) => onMapLoad(map)}
fitBounds={boundData} fitBounds={boundData}
fitBoundsOptions={{ padding: 100 }} fitBoundsOptions={{ padding: 100 }}
style={mapStyle} style={mapStyle}
@ -122,14 +161,20 @@ const MapReader = ({ featureCollection }) => {
data={selectionsPolygonFeatureCollection} data={selectionsPolygonFeatureCollection}
fillPaint={polygonSelectionFill} fillPaint={polygonSelectionFill}
linePaint={polygonSelectionLine} linePaint={polygonSelectionLine}
fillOnMouseEnter={onMouseEnter}
fillOnMouseLeave={onMouseLeave}
/> />
<GeoJSONLayer <GeoJSONLayer
data={selectionsLineFeatureCollection} data={selectionsLineFeatureCollection}
linePaint={lineStringSelectionLine} linePaint={lineStringSelectionLine}
lineOnMouseEnter={onMouseEnter}
lineOnMouseLeave={onMouseLeave}
/> />
<GeoJSONLayer <GeoJSONLayer
data={selectionsPointFeatureCollection} data={selectionsPointFeatureCollection}
circlePaint={pointSelectionFill} circlePaint={pointSelectionFill}
circleOnMouseEnter={onMouseEnter}
circleOnMouseLeave={onMouseLeave}
/> />
<GeoJSONLayer <GeoJSONLayer
data={cadastresFeatureCollection} data={cadastresFeatureCollection}

View file

@ -0,0 +1,11 @@
import ortho from './ortho.json';
import orthoCadastre from './orthoCadastre.json';
import vector from './vector.json';
import vectorCadastre from './vectorCadastre.json';
export function getMapStyle(style, hasCadastres) {
if (hasCadastres) {
return style === 'ortho' ? orthoCadastre : vectorCadastre;
}
return style === 'ortho' ? ortho : vector;
}

View file

@ -0,0 +1,78 @@
import { LngLatBounds } from 'mapbox-gl';
import { useEffect } from 'react';
export function getBounds(geometry) {
const bbox = new LngLatBounds();
if (geometry.type === 'Point') {
return [geometry.coordinates, geometry.coordinates];
} else if (geometry.type === 'LineString') {
for (const coordinate of geometry.coordinates) {
bbox.extend(coordinate);
}
} else {
for (const coordinate of geometry.coordinates[0]) {
bbox.extend(coordinate);
}
}
return bbox;
}
export function fitBounds(map, feature) {
if (map) {
map.fitBounds(getBounds(feature.geometry), { padding: 100 });
}
}
export function findFeature(featureCollection, id) {
return featureCollection.features.find(
(feature) => feature.properties.id === id
);
}
export function filterFeatureCollection(featureCollection, source) {
return {
type: 'FeatureCollection',
features: featureCollection.features.filter(
(feature) => feature.properties.source === source
)
};
}
export function filterFeatureCollectionByGeometryType(featureCollection, type) {
return {
type: 'FeatureCollection',
features: featureCollection.features.filter(
(feature) => feature.geometry.type === type
)
};
}
export function noop() {}
export function generateId() {
return Math.random().toString(20).substr(2, 6);
}
export function useEvent(eventName, callback) {
return useEffect(() => {
addEventListener(eventName, callback);
return () => removeEventListener(eventName, callback);
}, [eventName, callback]);
}
export function getCenter(geometry, lngLat) {
const bbox = new LngLatBounds();
switch (geometry.type) {
case 'Point':
return [...geometry.coordinates];
case 'LineString':
return [lngLat.lng, lngLat.lat];
default:
for (const coordinate of geometry.coordinates[0]) {
bbox.extend(coordinate);
}
return bbox.getCenter();
}
}

View file

@ -0,0 +1,40 @@
import { delegate, fire, debounce } from '@utils';
const inputHandlers = new Map();
addEventListener('ds:page:update', () => {
const inputs = document.querySelectorAll('.areas input[data-geo-area]');
for (const input of inputs) {
input.addEventListener('focus', (event) => {
const id = parseInt(event.target.dataset.geoArea);
fire(document, 'map:feature:focus', { id });
});
}
});
delegate('click', '.areas a[data-geo-area]', (event) => {
event.preventDefault();
const id = parseInt(event.target.dataset.geoArea);
fire(document, 'map:feature:focus', { id });
});
delegate('input', '.areas input[data-geo-area]', (event) => {
const id = parseInt(event.target.dataset.geoArea);
let handler = inputHandlers.get(id);
if (!handler) {
handler = debounce(() => {
const input = document.querySelector(`input[data-geo-area="${id}"]`);
if (input) {
fire(document, 'map:feature:update', {
id,
properties: { description: input.value.trim() }
});
}
}, 200);
inputHandlers.set(id, handler);
}
handler();
});

View file

@ -24,6 +24,7 @@ import '../new_design/support';
import '../new_design/dossiers/auto-save'; import '../new_design/dossiers/auto-save';
import '../new_design/dossiers/auto-upload'; import '../new_design/dossiers/auto-upload';
import '../new_design/champs/carte';
import '../new_design/champs/linked-drop-down-list'; import '../new_design/champs/linked-drop-down-list';
import '../new_design/champs/repetition'; import '../new_design/champs/repetition';

View file

@ -1,8 +1,8 @@
class ApiEntreprise::EffectifsJob < ApiEntreprise::Job class ApiEntreprise::EffectifsJob < ApiEntreprise::Job
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
etablissement = Etablissement.find(etablissement_id) etablissement = Etablissement.find(etablissement_id)
# effectifs endpoint currently only works when asking for february 2020 month # april 2020 is at the moment the most actual info for effectifs endpoint
etablissement_params = ApiEntreprise::EffectifsAdapter.new(etablissement.siret, procedure_id, "2020", "02").to_params etablissement_params = ApiEntreprise::EffectifsAdapter.new(etablissement.siret, procedure_id, "2020", "04").to_params
etablissement.update!(etablissement_params) etablissement.update!(etablissement_params)
end end

View file

@ -1,4 +1,7 @@
class ApiEntreprise::ExercicesJob < ApiEntreprise::Job class ApiEntreprise::ExercicesJob < ApiEntreprise::Job
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
end
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
etablissement = Etablissement.find(etablissement_id) etablissement = Etablissement.find(etablissement_id)
etablissement_params = ApiEntreprise::ExercicesAdapter.new(etablissement.siret, procedure_id).to_params etablissement_params = ApiEntreprise::ExercicesAdapter.new(etablissement.siret, procedure_id).to_params

View file

@ -1,5 +1,14 @@
class ApiEntreprise::Job < ApplicationJob class ApiEntreprise::Job < ApplicationJob
DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5 DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5
rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
error(self, exception)
end
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
error(self, exception)
end
def max_attempts def max_attempts
ENV[MAX_ATTEMPTS_API_ENTREPRISE_JOBS].to_i || DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS ENV[MAX_ATTEMPTS_API_ENTREPRISE_JOBS].to_i || DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS
end end

View file

@ -9,14 +9,6 @@ class ApplicationJob < ActiveJob::Base
Rails.logger.info("#{job.class.name} ended at #{Time.zone.now}") Rails.logger.info("#{job.class.name} ended at #{Time.zone.now}")
end end
rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
error(self, exception)
end
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
error(self, exception)
end
def error(job, exception) def error(job, exception)
Raven.capture_exception(exception) Raven.capture_exception(exception)
end end

View file

@ -1,7 +1,7 @@
class EtablissementUpdateJob < ApplicationJob class EtablissementUpdateJob < ApplicationJob
def perform(dossier, siret) def perform(dossier, siret)
begin begin
etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, dossier.procedure_id) etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, dossier.procedure.id)
rescue rescue
return return
end end

View file

@ -78,7 +78,7 @@ class ApiEntreprise::API
elsif response.code == 400 elsif response.code == 400
raise BadFormatRequest, "url: #{url}" raise BadFormatRequest, "url: #{url}"
else else
raise RequestFailed, "HTTP Error Code: #{response.code} for #{url}" raise RequestFailed, "HTTP Error Code: #{response.code} for #{url}\nheaders: #{response.headers}\nbody: #{response.body}"
end end
end end

View file

@ -16,8 +16,8 @@ class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter
if data_source[:effectifs_mensuels].present? if data_source[:effectifs_mensuels].present?
{ {
entreprise_effectif_mensuel: data_source[:effectifs_mensuels], entreprise_effectif_mensuel: data_source[:effectifs_mensuels],
entreprise_effectif_mois: @mois, entreprise_effectif_mois: data_source[:mois],
entreprise_effectif_annee: @annee entreprise_effectif_annee: data_source[:annee]
} }
else else
{} {}

View file

@ -1,5 +1,5 @@
class Dossier < ApplicationRecord class Dossier < ApplicationRecord
self.ignored_columns = ['json_latlngs'] self.ignored_columns = ['procedure_id']
include DossierFilteringConcern include DossierFilteringConcern
include Discard::Model include Discard::Model

View file

@ -2,6 +2,7 @@ class GeoArea < ApplicationRecord
belongs_to :champ belongs_to :champ
store :properties, accessors: [ store :properties, accessors: [
:description,
:surface_intersection, :surface_intersection,
:surface_parcelle, :surface_parcelle,
:numero, :numero,

View file

@ -1,10 +1,10 @@
class GroupeInstructeur < ApplicationRecord class GroupeInstructeur < ApplicationRecord
DEFAULT_LABEL = 'défaut' DEFAULT_LABEL = 'défaut'
belongs_to :procedure, -> { with_discarded }, inverse_of: :groupe_instructeurs belongs_to :procedure, -> { with_discarded }, inverse_of: :groupe_instructeurs
has_many :assign_tos has_many :assign_tos, dependent: :destroy
has_many :instructeurs, through: :assign_tos, dependent: :destroy has_many :instructeurs, through: :assign_tos
has_many :dossiers has_many :dossiers
has_and_belongs_to_many :exports has_and_belongs_to_many :exports, dependent: :destroy
validates :label, presence: { message: 'doit être renseigné' }, allow_nil: false validates :label, presence: { message: 'doit être renseigné' }, allow_nil: false
validates :label, uniqueness: { scope: :procedure, message: 'existe déjà' } validates :label, uniqueness: { scope: :procedure, message: 'existe déjà' }

View file

@ -2,7 +2,7 @@
<%= render_to_element("#{@selector} + .geo-areas", <%= render_to_element("#{@selector} + .geo-areas",
partial: 'shared/champs/carte/geo_areas', partial: 'shared/champs/carte/geo_areas',
locals: { champ: @champ }) %> locals: { champ: @champ, editing: true }) %>
<% if @update_cadastres %> <% if @update_cadastres %>
<%= fire_event('cadastres:update', { featureCollection: @champ.to_feature_collection }.to_json) %> <%= fire_event('cadastres:update', { featureCollection: @champ.to_feature_collection }.to_json) %>

View file

@ -3,19 +3,17 @@
.areas .areas
%ul %ul
- champ.selections_utilisateur.each do |geo_area| - champ.selections_utilisateur.each do |geo_area|
%li= geo_area_label(geo_area) %li{ class: editing ? '' : 'flex column mb-2' }
- if editing
- if champ.quartiers_prioritaires? = link_to '#', data: { geo_area: geo_area.id } do
.areas-title Quartiers prioritaires = geo_area_label(geo_area)
.areas = text_field_tag :description, geo_area.description, data: { geo_area: geo_area.id }, placeholder: 'Description de la sélection'
- if !champ.geometry? - else
Aucune zone tracée = link_to '#', data: { geo_area: geo_area.id } do
- elsif champ.quartiers_prioritaires.blank? = geo_area_label(geo_area)
= t('errors.messages.quartiers_prioritaires_empty', count: champ.selections_utilisateur.size) - if geo_area.description.present?
- else %span
%ul = geo_area.description
- champ.quartiers_prioritaires.each do |geo_area|
%li= geo_area_label(geo_area)
- if champ.cadastres? - if champ.cadastres?
.areas-title Parcelles cadastrales .areas-title Parcelles cadastrales
@ -27,16 +25,6 @@
- else - else
%ul %ul
- champ.cadastres.each do |geo_area| - champ.cadastres.each do |geo_area|
%li= geo_area_label(geo_area) %li.flex.column.mb-2
= link_to '#', data: { geo_area: geo_area.id } do
- if champ.parcelles_agricoles? = geo_area_label(geo_area)
.areas-title Parcelles agricoles (RPG)
.areas
- if !champ.geometry?
Aucune zone tracée
- elsif champ.parcelles_agricoles.blank?
= t('errors.messages.parcelles_agricoles_empty', count: champ.selections_utilisateur.size)
- else
%ul
- champ.parcelles_agricoles.each do |geo_area|
%li= geo_area_label(geo_area)

View file

@ -1,4 +1,4 @@
- if champ.geometry? - if champ.geometry?
= react_component("MapReader", { featureCollection: champ.to_feature_collection } ) = react_component("MapReader", { featureCollection: champ.to_feature_collection } )
.geo-areas .geo-areas
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ } = render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: false }

View file

@ -2,4 +2,4 @@
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: champs_carte_features_path(preview ? 'preview' : champ), preview: preview, hasCadastres: !!champ.cadastres? }, class: "carte-#{champ.id}") = react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: champs_carte_features_path(preview ? 'preview' : champ), preview: preview, hasCadastres: !!champ.cadastres? }, class: "carte-#{champ.id}")
.geo-areas .geo-areas
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ } = render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: true }

View file

@ -0,0 +1,5 @@
class RemoveDossierProcedureId < ActiveRecord::Migration[5.2]
def change
remove_column :dossiers, :procedure_id
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_04_29_191305) do ActiveRecord::Schema.define(version: 2020_06_11_122406) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -238,7 +238,6 @@ ActiveRecord::Schema.define(version: 2020_04_29_191305) do
create_table "dossiers", id: :serial, force: :cascade do |t| create_table "dossiers", id: :serial, force: :cascade do |t|
t.boolean "autorisation_donnees" t.boolean "autorisation_donnees"
t.integer "procedure_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "state" t.string "state"
@ -262,7 +261,6 @@ ActiveRecord::Schema.define(version: 2020_04_29_191305) do
t.index ["archived"], name: "index_dossiers_on_archived" t.index ["archived"], name: "index_dossiers_on_archived"
t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id" t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id"
t.index ["hidden_at"], name: "index_dossiers_on_hidden_at" t.index ["hidden_at"], name: "index_dossiers_on_hidden_at"
t.index ["procedure_id"], name: "index_dossiers_on_procedure_id"
t.index ["state"], name: "index_dossiers_on_state" t.index ["state"], name: "index_dossiers_on_state"
t.index ["user_id"], name: "index_dossiers_on_user_id" t.index ["user_id"], name: "index_dossiers_on_user_id"
end end

View file

@ -1,15 +0,0 @@
namespace :after_party do
desc 'Deployment task: link_dossier_and_groupe_instructeur'
task link_dossier_and_groupe_instructeur: :environment do
sql = <<~SQL
UPDATE dossiers AS d1 SET groupe_instructeur_id = g.id
FROM groupe_instructeurs AS g
WHERE g.procedure_id = d1.procedure_id
and d1.groupe_instructeur_id is null;
SQL
ActiveRecord::Base.connection.execute(sql)
AfterParty::TaskRecord.create version: '20190826153115'
end
end

View file

@ -44,19 +44,43 @@ describe Champs::CarteController, type: :controller do
end end
describe 'PATCH #update' do describe 'PATCH #update' do
let(:params) do
{
champ_id: champ.id,
id: geo_area.id,
feature: feature
}
end
before do before do
patch :update, params: params patch :update, params: params
end end
it { expect(response.status).to eq 204 } context 'update geometry' do
let(:params) do
{
champ_id: champ.id,
id: geo_area.id,
feature: feature
}
end
it { expect(response.status).to eq 204 }
end
context 'update description' do
let(:feature) do
{
properties: {
description: 'un point'
}
}
end
let(:params) do
{
champ_id: champ.id,
id: geo_area.id,
feature: feature
}
end
it {
expect(response.status).to eq 204
expect(geo_area.reload.description).to eq('un point')
}
end
end end
describe 'DELETE #destroy' do describe 'DELETE #destroy' do

View file

@ -6,7 +6,7 @@ RSpec.describe ApiEntreprise::EffectifsJob, type: :job do
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
let(:now) { Time.zone.local(2020, 3, 12) } let(:now) { Time.zone.local(2020, 3, 12) }
let(:annee) { "2020" } let(:annee) { "2020" }
let(:mois) { "02" } let(:mois) { "04" }
let(:body) { File.read('spec/fixtures/files/api_entreprise/effectifs.json') } let(:body) { File.read('spec/fixtures/files/api_entreprise/effectifs.json') }
let(:status) { 200 } let(:status) { 200 }

View file

@ -1,36 +0,0 @@
describe '20190826153115_link_dossier_and_groupe_instructeur.rake' do
let(:rake_task) { Rake::Task['after_party:link_dossier_and_groupe_instructeur'] }
subject { rake_task.invoke }
after { rake_task.reenable }
context 'with 3 dossiers' do
let!(:procedure) { create(:procedure) }
let!(:procedure2) { create(:procedure) }
let!(:other_procedure_needed_to_create_dossier) { create(:procedure) }
let!(:other_gi) { other_procedure_needed_to_create_dossier.defaut_groupe_instructeur }
let!(:dossier) { Dossier.create(user: create(:user), procedure_id: procedure.id, groupe_instructeur: other_gi) }
let!(:dossier2) { Dossier.create(user: create(:user), procedure_id: procedure2.id, groupe_instructeur: other_gi) }
let!(:dossier3) { Dossier.create(user: create(:user), procedure_id: procedure2.id, groupe_instructeur: other_gi) }
before do
[dossier, dossier2, dossier3].each do |d|
d.update_column('groupe_instructeur_id', nil)
end
other_procedure_needed_to_create_dossier.groupe_instructeurs.destroy_all
other_procedure_needed_to_create_dossier.destroy
end
it do
expect(dossier.reload.groupe_instructeur_id).to be_nil
subject
expect(Dossier.count).to eq(3)
expect(Procedure.count).to eq(2)
expect(GroupeInstructeur.count).to eq(2)
expect(dossier.reload.groupe_instructeur_id).to eq(procedure.defaut_groupe_instructeur.id)
expect(dossier2.reload.groupe_instructeur_id).to eq(procedure2.defaut_groupe_instructeur.id)
expect(dossier3.reload.groupe_instructeur_id).to eq(procedure2.defaut_groupe_instructeur.id)
end
end
end