Administrateur can be select dynamically the activation of api carto modules

This commit is contained in:
Xavier J 2015-12-08 10:11:58 +01:00
parent 8130e7d155
commit 0e3bec7f9f
17 changed files with 186 additions and 25 deletions

View file

@ -0,0 +1,12 @@
$(document).on('page:load', buttons_api_carto);
$(document).ready(buttons_api_carto);
function buttons_api_carto () {
$("#procedure_module_api_carto_use_api_carto").on('change', function() {
$("#modules_api_carto").toggle()
});
if ($('#procedure_module_api_carto_use_api_carto').is(':checked'))
$("#modules_api_carto").show();
}

View file

@ -91,6 +91,10 @@ input#nom_projet {
max-width: 27px; max-width: 27px;
} }
label {
font-weight: normal;
}
div.pagination { div.pagination {
padding-top: 20px; padding-top: 20px;
display: block; display: block;

View file

@ -0,0 +1,3 @@
#modules_api_carto {
display: none;
}

View file

@ -24,10 +24,12 @@ class Admin::ProceduresController < AdminController
def new def new
@procedure ||= Procedure.new @procedure ||= Procedure.new
@procedure.module_api_carto ||= ModuleAPICarto.new
end end
def create def create
@procedure = Procedure.new(create_procedure_params) @procedure = Procedure.new(create_procedure_params)
@procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params) if @procedure.valid?
unless @procedure.save unless @procedure.save
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
@ -64,7 +66,11 @@ class Admin::ProceduresController < AdminController
private private
def create_procedure_params def create_procedure_params
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :use_api_carto).merge(administrateur_id: current_administrateur.id) params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
end
def create_module_api_carto_params
params.require(:procedure).require(:module_api_carto_attributes).permit(:id, :use_api_carto, :quartiers_prioritaires, :cadastre)
end end
def informations def informations

View file

@ -88,7 +88,7 @@ class Users::DossiersController < UsersController
if checked_autorisation_donnees? if checked_autorisation_donnees?
@dossier.update_attributes(update_params) @dossier.update_attributes(update_params)
if @dossier.procedure.use_api_carto if @dossier.procedure.module_api_carto.use_api_carto
redirect_to url_for(controller: :carte, action: :show, dossier_id: @dossier.id) redirect_to url_for(controller: :carte, action: :show, dossier_id: @dossier.id)
else else
redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id) redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id)

View file

@ -1,7 +1,7 @@
class ModuleAPICarto < ActiveRecord::Base class ModuleAPICarto < ActiveRecord::Base
enum name: {'quartiers_prioritaires' => 'quartiers_prioritaires'}
belongs_to :procedure belongs_to :procedure
validates :name, presence: true, allow_blank: false, allow_nil: false validates :use_api_carto, presence: true, allow_blank: true, allow_nil: false
validates :quartiers_prioritaires, presence: true, allow_blank: true, allow_nil: false
validates :cadastre, presence: true, allow_blank: true, allow_nil: false
end end

View file

@ -2,9 +2,10 @@ class Procedure < ActiveRecord::Base
has_many :types_de_piece_justificative has_many :types_de_piece_justificative
has_many :types_de_champ has_many :types_de_champ
has_many :dossiers has_many :dossiers
has_many :module_api_cartos has_one :module_api_carto
accepts_nested_attributes_for :types_de_champ,:reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true accepts_nested_attributes_for :types_de_champ,:reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
accepts_nested_attributes_for :types_de_piece_justificative, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true accepts_nested_attributes_for :types_de_piece_justificative, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
accepts_nested_attributes_for :module_api_carto
belongs_to :administrateur belongs_to :administrateur
validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :libelle, presence: true, allow_blank: false, allow_nil: false

View file

@ -9,6 +9,19 @@
%br %br
%label{ style:'font-weight:normal' } %h4 Cartographie
=f.check_box :use_api_carto
Utilisation de l'API Carto = f.fields_for :module_api_carto, @procedure.module_api_carto do |ff|
%label
=ff.check_box :use_api_carto, {id: :procedure_module_api_carto_use_api_carto}
Utilisation de la cartographie
%ul#modules_api_carto
%li
%label
= ff.check_box :quartiers_prioritaires
Quartiers Prioritaires
%li
%label
= ff.check_box :cadastre
Cadastre

View file

@ -12,7 +12,7 @@
%br %br
- rescue - rescue
='' =''
- if @dossier.procedure.use_api_carto - if @dossier.procedure.module_api_carto.use_api_carto
.col-lg-6.col-md-6 .col-lg-6.col-md-6
#map.mini #map.mini
%input{id: 'json_latlngs', type:'hidden', value: "#{@dossier.json_latlngs}"} %input{id: 'json_latlngs', type:'hidden', value: "#{@dossier.json_latlngs}"}
@ -39,7 +39,7 @@
%div.row{style: 'text-align:right'} %div.row{style: 'text-align:right'}
-unless gestionnaire_signed_in? -unless gestionnaire_signed_in?
-if !@dossier.validated? && !@dossier.submitted? && !@dossier.closed? -if !@dossier.validated? && !@dossier.submitted? && !@dossier.closed?
-if @dossier.procedure.use_api_carto -if @dossier.procedure.module_api_carto.use_api_carto
%a#maj_carte.btn.btn-primary{href: "/users/dossiers/#{@dossier.id}/carte"} %a#maj_carte.btn.btn-primary{href: "/users/dossiers/#{@dossier.id}/carte"}
= 'Editer ma carte' = 'Editer ma carte'
%a#maj_infos.btn.btn-info{href: "/users/dossiers/#{@dossier.id}/description"} %a#maj_infos.btn.btn-info{href: "/users/dossiers/#{@dossier.id}/description"}

View file

@ -0,0 +1,47 @@
class UpdateModuleAPICarto < ActiveRecord::Migration
class Procedure < ActiveRecord::Base
end
class ModuleAPICarto < ActiveRecord::Base
end
def up
remove_column :module_api_cartos, :name
add_index :module_api_cartos, [:procedure_id], unique: true
add_column :module_api_cartos, :use_api_carto, :boolean, default: false
add_column :module_api_cartos, :quartiers_prioritaires, :boolean, default: false
add_column :module_api_cartos, :cadastre, :boolean, default: false
Procedure.all.each do |procedure|
module_api_carto = ModuleAPICarto.new(procedure_id: procedure.id)
module_api_carto.use_api_carto = procedure.use_api_carto
module_api_carto.quartiers_prioritaires = procedure.use_api_carto
module_api_carto.save!
end
remove_column :procedures, :use_api_carto
end
def down
add_column :procedures, :use_api_carto, :boolean, default: false
remove_index :module_api_cartos, [:procedure_id]
Procedure.all.each do |procedure|
procedure.use_api_carto = ModuleAPICarto.find_by(procedure_id: procedure.id).use_api_carto
procedure.save!
end
remove_column :module_api_cartos, :use_api_carto
remove_column :module_api_cartos, :quartiers_prioritaires
remove_column :module_api_cartos, :cadastre
add_column :module_api_cartos, :name, :string
ModuleAPICarto.destroy_all
end
end

View file

@ -11,7 +11,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: 20151207095904) do ActiveRecord::Schema.define(version: 20151207140202) 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"
@ -133,10 +133,14 @@ ActiveRecord::Schema.define(version: 20151207095904) do
add_index "gestionnaires", ["reset_password_token"], name: "index_gestionnaires_on_reset_password_token", unique: true, using: :btree add_index "gestionnaires", ["reset_password_token"], name: "index_gestionnaires_on_reset_password_token", unique: true, using: :btree
create_table "module_api_cartos", force: :cascade do |t| create_table "module_api_cartos", force: :cascade do |t|
t.string "name"
t.integer "procedure_id" t.integer "procedure_id"
t.boolean "use_api_carto", default: false
t.boolean "quartiers_prioritaires", default: false
t.boolean "cadastre", default: false
end end
add_index "module_api_cartos", ["procedure_id"], name: "index_module_api_cartos_on_procedure_id", unique: true, using: :btree
create_table "pieces_justificatives", force: :cascade do |t| create_table "pieces_justificatives", force: :cascade do |t|
t.string "content" t.string "content"
t.integer "dossier_id" t.integer "dossier_id"
@ -154,7 +158,6 @@ ActiveRecord::Schema.define(version: 20151207095904) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.boolean "test" t.boolean "test"
t.boolean "use_api_carto", default: false
t.integer "administrateur_id" t.integer "administrateur_id"
t.boolean "archived", default: false t.boolean "archived", default: false
end end

View file

@ -10,7 +10,9 @@ describe Admin::ProceduresController, type: :controller do
let(:organisation) { 'Organisation de test' } let(:organisation) { 'Organisation de test' }
let(:direction) { 'Direction de test' } let(:direction) { 'Direction de test' }
let(:lien_demarche) { 'http://localhost.com' } let(:lien_demarche) { 'http://localhost.com' }
let(:use_api_carto) { '1' } let(:use_api_carto) { '0' }
let(:quartiers_prioritaires) { '0' }
let(:cadastre) { '0' }
let(:procedure_params) { let(:procedure_params) {
{ {
@ -19,7 +21,11 @@ describe Admin::ProceduresController, type: :controller do
organisation: organisation, organisation: organisation,
direction: direction, direction: direction,
lien_demarche: lien_demarche, lien_demarche: lien_demarche,
use_api_carto: use_api_carto module_api_carto_attributes: {
use_api_carto: use_api_carto,
quartiers_prioritaires: quartiers_prioritaires,
cadastre: cadastre
}
} }
} }
@ -89,11 +95,22 @@ describe Admin::ProceduresController, type: :controller do
it { expect(subject.organisation).to eq(organisation) } it { expect(subject.organisation).to eq(organisation) }
it { expect(subject.direction).to eq(direction) } it { expect(subject.direction).to eq(direction) }
it { expect(subject.lien_demarche).to eq(lien_demarche) } it { expect(subject.lien_demarche).to eq(lien_demarche) }
it { expect(subject.use_api_carto).to be_truthy }
it { expect(subject.administrateur_id).to eq(admin.id) } it { expect(subject.administrateur_id).to eq(admin.id) }
end end
describe 'procedure module api carto attributs in database' do
let(:procedure) { Procedure.last }
let(:use_api_carto) { '1' }
let(:quartiers_prioritaires) { '1' }
subject { ModuleAPICarto.last }
it { expect(subject.procedure).to eq(procedure) }
it { expect(subject.use_api_carto).to be_truthy }
it { expect(subject.quartiers_prioritaires).to be_truthy }
end
it { expect(subject).to redirect_to(admin_procedure_types_de_champ_path(procedure_id: Procedure.last.id)) } it { expect(subject).to redirect_to(admin_procedure_types_de_champ_path(procedure_id: Procedure.last.id)) }
it { expect(flash[:notice]).to be_present } it { expect(flash[:notice]).to be_present }
@ -108,6 +125,10 @@ describe Admin::ProceduresController, type: :controller do
subject { post :create, procedure: procedure_params } subject { post :create, procedure: procedure_params }
it { expect { subject }.to change { Procedure.count }.by(0) } it { expect { subject }.to change { Procedure.count }.by(0) }
describe 'no new module api carto in database' do
it { expect { subject }.to change { ModuleAPICarto.count }.by(0) }
end
end end
describe 'flash message is present' do describe 'flash message is present' do
@ -145,7 +166,8 @@ describe Admin::ProceduresController, type: :controller do
let(:organisation) { 'plop' } let(:organisation) { 'plop' }
let(:direction) { 'plap' } let(:direction) { 'plap' }
let(:lien_demarche) { 'http://plip.com' } let(:lien_demarche) { 'http://plip.com' }
let(:use_api_carto) { '0' } let(:use_api_carto) { '1' }
let(:cadastre) { '1' }
describe 'procedure attributs in database' do describe 'procedure attributs in database' do
subject { procedure } subject { procedure }
@ -155,7 +177,14 @@ describe Admin::ProceduresController, type: :controller do
it { expect(subject.organisation).to eq(organisation) } it { expect(subject.organisation).to eq(organisation) }
it { expect(subject.direction).to eq(direction) } it { expect(subject.direction).to eq(direction) }
it { expect(subject.lien_demarche).to eq(lien_demarche) } it { expect(subject.lien_demarche).to eq(lien_demarche) }
it { expect(subject.use_api_carto).to be_falsey } end
describe 'procedure module api carto attributs in database' do
subject { procedure.module_api_carto }
it { expect(subject.use_api_carto).to be_truthy }
it { expect(subject.quartiers_prioritaires).to be_falsey }
it { expect(subject.cadastre).to be_truthy }
end end
it { expect(subject).to redirect_to(admin_procedures_path) } it { expect(subject).to redirect_to(admin_procedures_path) }
@ -169,6 +198,14 @@ describe Admin::ProceduresController, type: :controller do
describe 'flash message is present' do describe 'flash message is present' do
it { expect(flash[:alert]).to be_present } it { expect(flash[:alert]).to be_present }
end end
describe 'procedure module api carto attributs in database' do
subject { procedure.module_api_carto }
it { expect(subject.use_api_carto).to be_falsey }
it { expect(subject.quartiers_prioritaires).to be_falsey }
it { expect(subject.cadastre).to be_falsey }
end
end end
end end
end end

View file

@ -3,8 +3,7 @@ require 'spec_helper'
describe Users::DossiersController, type: :controller do describe Users::DossiersController, type: :controller do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:use_api_carto) { false } let(:procedure) { create(:procedure) }
let(:procedure) { create(:procedure, use_api_carto: use_api_carto) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
@ -170,7 +169,7 @@ describe Users::DossiersController, type: :controller do
end end
context 'procedure use api carto' do context 'procedure use api carto' do
let(:use_api_carto) { true } let(:procedure) { create(:procedure, :with_api_carto) }
before do before do
put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees} put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees}

View file

@ -0,0 +1,27 @@
FactoryGirl.define do
factory :module_api_carto do
use_api_carto false
quartiers_prioritaires false
cadastre false
trait :with_api_carto do
use_api_carto true
end
trait :with_qp do
use_api_carto true
quartiers_prioritaires true
end
trait :with_cadastre do
use_api_carto true
cadastre true
end
trait :with_qp_and_cadastre do
use_api_carto true
quartiers_prioritaires true
cadastre true
end
end
end

View file

@ -4,8 +4,15 @@ FactoryGirl.define do
libelle 'Demande de subvention' libelle 'Demande de subvention'
description "Demande de subvention à l'intention des associations" description "Demande de subvention à l'intention des associations"
after(:build) do |procedure, _evaluator|
module_api_carto = create(:module_api_carto)
procedure.module_api_carto = module_api_carto
end
trait :with_api_carto do trait :with_api_carto do
use_api_carto true after(:build) do |procedure, _evaluator|
procedure.module_api_carto.use_api_carto = true
end
end end
trait :with_type_de_champ do trait :with_type_de_champ do

View file

@ -6,6 +6,8 @@ describe ModuleAPICarto do
end end
describe 'attributes' do describe 'attributes' do
it { is_expected.to have_db_column(:name) } it { is_expected.to have_db_column(:use_api_carto) }
it { is_expected.to have_db_column(:quartiers_prioritaires) }
it { is_expected.to have_db_column(:cadastre) }
end end
end end

View file

@ -5,7 +5,7 @@ describe Procedure do
it { is_expected.to have_many(:types_de_piece_justificative) } it { is_expected.to have_many(:types_de_piece_justificative) }
it { is_expected.to have_many(:types_de_champ) } it { is_expected.to have_many(:types_de_champ) }
it { is_expected.to have_many(:dossiers) } it { is_expected.to have_many(:dossiers) }
it { is_expected.to have_many(:module_api_cartos) } it { is_expected.to have_one(:module_api_carto) }
it { is_expected.to belong_to(:administrateur) } it { is_expected.to belong_to(:administrateur) }
end end