Merge pull request #3072 from tchak/fix-champ-cart-again
Make difference between error and empty geo json
This commit is contained in:
commit
df06c81305
3 changed files with 26 additions and 10 deletions
|
@ -1,6 +1,9 @@
|
|||
class Champs::CarteController < ApplicationController
|
||||
before_action :authenticate_logged_user!
|
||||
|
||||
EMPTY_GEO_JSON = '[]'
|
||||
ERROR_GEO_JSON = ''
|
||||
|
||||
def show
|
||||
@selector = ".carte-#{params[:position]}"
|
||||
|
||||
|
@ -26,13 +29,17 @@ class Champs::CarteController < ApplicationController
|
|||
end
|
||||
|
||||
geo_areas = []
|
||||
geo_json = geo_json.blank? ? [] : JSON.parse(geo_json)
|
||||
|
||||
if geo_json.empty?
|
||||
if geo_json == EMPTY_GEO_JSON
|
||||
@champ.value = nil
|
||||
@champ.geo_areas = []
|
||||
elsif geo_json == ERROR_GEO_JSON
|
||||
@error = true
|
||||
@champ.value = nil
|
||||
@champ.geo_areas = []
|
||||
elsif geo_json.present?
|
||||
else
|
||||
geo_json = JSON.parse(geo_json)
|
||||
|
||||
if @champ.cadastres?
|
||||
cadastres = ModuleApiCartoService.generate_cadastre(geo_json)
|
||||
geo_areas += cadastres.map do |cadastre|
|
||||
|
|
|
@ -107,15 +107,18 @@ export function getCurrentMap(input) {
|
|||
}
|
||||
}
|
||||
|
||||
const EMPTY_GEO_JSON = '[]';
|
||||
const ERROR_GEO_JSON = '';
|
||||
|
||||
export function addFreeDrawEvents(map, selector) {
|
||||
const input = findInput(selector);
|
||||
map.freeDraw.on('markers', ({ latLngs }) => {
|
||||
if (latLngs.length === 0) {
|
||||
input.value = '';
|
||||
input.value = EMPTY_GEO_JSON;
|
||||
} else if (polygonArea(latLngs) < 300000) {
|
||||
input.value = JSON.stringify(latLngs);
|
||||
} else {
|
||||
input.value = '';
|
||||
input.value = ERROR_GEO_JSON;
|
||||
}
|
||||
|
||||
fire(input, 'change');
|
||||
|
|
|
@ -8,7 +8,7 @@ describe Champs::CarteController, type: :controller do
|
|||
{
|
||||
dossier: {
|
||||
champs_attributes: {
|
||||
'1' => { value: selection.to_json }
|
||||
'1' => { value: value }
|
||||
}
|
||||
},
|
||||
position: '1',
|
||||
|
@ -35,13 +35,18 @@ describe Champs::CarteController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when coordinates are empty' do
|
||||
let(:selection) { [] }
|
||||
let(:value) { '[]' }
|
||||
|
||||
it { expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":[],\"quartiersPrioritaires\":[],\"cadastres\":[],\"parcellesAgricoles\":[]});") }
|
||||
it {
|
||||
expect(assigns(:error)).to eq(nil)
|
||||
expect(champ.reload.value).to eq(nil)
|
||||
expect(champ.reload.geo_areas).to eq([])
|
||||
expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":[],\"quartiersPrioritaires\":[],\"cadastres\":[],\"parcellesAgricoles\":[]});")
|
||||
}
|
||||
end
|
||||
|
||||
context 'when coordinates are informed' do
|
||||
let(:selection) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]] }
|
||||
let(:value) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]].to_json }
|
||||
|
||||
it { expect(response.body).not_to be_nil }
|
||||
it { expect(response.body).to include('MultiPolygon') }
|
||||
|
@ -50,9 +55,10 @@ describe Champs::CarteController, type: :controller do
|
|||
|
||||
context 'when error' do
|
||||
let(:geojson) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]] }
|
||||
let(:selection) { '' }
|
||||
let(:value) { '' }
|
||||
|
||||
it {
|
||||
expect(assigns(:error)).to eq(true)
|
||||
expect(champ.reload.value).to eq(nil)
|
||||
expect(champ.reload.geo_areas).to eq([])
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue