Better handle empty user selection layers
This commit is contained in:
parent
4249f8ae25
commit
c8c75fc254
4 changed files with 21 additions and 4 deletions
|
@ -26,11 +26,11 @@ class Champs::CarteController < ApplicationController
|
|||
end
|
||||
|
||||
geo_areas = []
|
||||
geo_json = JSON.parse(geo_json)
|
||||
geo_json = geo_json.blank? ? [] : JSON.parse(geo_json)
|
||||
|
||||
if geo_json.first == ["error", "TooManyPolygons"]
|
||||
@error = true
|
||||
else
|
||||
elsif geo_json.present?
|
||||
if @champ.cadastres?
|
||||
cadastres = ModuleApiCartoService.generate_cadastre(geo_json)
|
||||
geo_areas += cadastres.map do |cadastre|
|
||||
|
|
|
@ -97,7 +97,9 @@ export function getCurrentMap(input) {
|
|||
export function addFreeDrawEvents(map, selector) {
|
||||
const input = findInput(selector);
|
||||
map.freeDraw.on('markers', ({ latLngs }) => {
|
||||
if (polygonArea(latLngs) < 300000) {
|
||||
if (latLngs.length === 0) {
|
||||
input.value = '';
|
||||
} else if (polygonArea(latLngs) < 300000) {
|
||||
input.value = JSON.stringify(latLngs);
|
||||
} else {
|
||||
input.value = '{ "error": "TooManyPolygons" }';
|
||||
|
|
|
@ -17,7 +17,16 @@ class Champ < ApplicationRecord
|
|||
end
|
||||
|
||||
def mandatory_and_blank?
|
||||
mandatory? && value.blank?
|
||||
if mandatory?
|
||||
case type_de_champ.type_champ
|
||||
when TypeDeChamp.type_champs.fetch(:carte)
|
||||
value.blank? || value == '[]'
|
||||
else
|
||||
value.blank?
|
||||
end
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def search_terms
|
||||
|
|
|
@ -9,6 +9,12 @@ shared_examples 'champ_spec' do
|
|||
it { expect(champ.mandatory_and_blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when carte mandatory and blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
||||
let(:value) { '[]' }
|
||||
it { expect(champ.mandatory_and_blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when not blank' do
|
||||
let(:value) { 'yop' }
|
||||
it { expect(champ.mandatory_and_blank?).to be(false) }
|
||||
|
|
Loading…
Reference in a new issue