parent
9a18a154ea
commit
aad685bb79
4 changed files with 30 additions and 10 deletions
|
@ -13,19 +13,16 @@ class Champs::CarteController < ApplicationController
|
|||
coordinates = params[:dossier][:champs_private_attributes][params[:position]][:value]
|
||||
end
|
||||
|
||||
if params[:champ_id].present?
|
||||
@champ = Champ
|
||||
@champ = if params[:champ_id].present?
|
||||
Champ
|
||||
.joins(:dossier)
|
||||
.where(dossiers: { user_id: logged_user_ids })
|
||||
.find(params[:champ_id])
|
||||
else
|
||||
@champ = Champs::CarteChamp.new(type_de_champ: TypeDeChamp.new(
|
||||
type_champ: TypeDeChamp.type_champs.fetch(:carte),
|
||||
options: {
|
||||
quartiers_prioritaires: true,
|
||||
cadastres: true
|
||||
}
|
||||
))
|
||||
TypeDeChamp
|
||||
.joins(:procedure)
|
||||
.where(procedures: { administrateur_id: logged_user_ids })
|
||||
.find(params[:type_de_champ_id]).champ.build
|
||||
end
|
||||
|
||||
geo_areas = []
|
||||
|
|
|
@ -9,4 +9,12 @@ module ChampHelper
|
|||
raw(champ.to_render_data.to_json)
|
||||
# rubocop:enable Rails/OutputSafety
|
||||
end
|
||||
|
||||
def champ_carte_params(champ)
|
||||
if champ.persisted?
|
||||
{ champ_id: champ.id }
|
||||
else
|
||||
{ type_de_champ_id: champ.type_de_champ_id }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,4 +8,4 @@
|
|||
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, error: false }
|
||||
|
||||
= form.hidden_field :value,
|
||||
data: { remote: true, url: champs_carte_path(form.index), params: { champ_id: champ&.id }.to_query, method: 'post' }
|
||||
data: { remote: true, url: champs_carte_path(form.index), params: champ_carte_params(champ).to_query, method: 'post' }
|
||||
|
|
|
@ -117,4 +117,19 @@ feature 'As an administrateur I can edit types de champ', js: true do
|
|||
|
||||
expect(page).to have_content('Supprimer', count: 3)
|
||||
end
|
||||
|
||||
it "Add carte champ" do
|
||||
select('Carte', from: 'procedure_types_de_champ_attributes_0_type_champ')
|
||||
fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libellé de champ carte'
|
||||
blur
|
||||
check 'Quartiers prioritaires'
|
||||
expect(page).to have_content('Formulaire enregistré')
|
||||
|
||||
preview_window = window_opened_by { click_on 'Prévisualiser le formulaire' }
|
||||
within_window(preview_window) do
|
||||
expect(page).to have_content('libellé de champ carte')
|
||||
expect(page).to have_content('Quartiers prioritaires')
|
||||
expect(page).not_to have_content('Cadastres')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue