Service: add service to procedure
This commit is contained in:
parent
5d7455f436
commit
af7be58132
5 changed files with 76 additions and 2 deletions
7
app/assets/stylesheets/new_design/services-index.scss
Normal file
7
app/assets/stylesheets/new_design/services-index.scss
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
@import "constants";
|
||||||
|
|
||||||
|
#services-index {
|
||||||
|
h1 {
|
||||||
|
margin-top: 2 * $default-padding;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ module NewAdministrateur
|
||||||
class ServicesController < AdministrateurController
|
class ServicesController < AdministrateurController
|
||||||
def index
|
def index
|
||||||
@services = services.ordered
|
@services = services.ordered
|
||||||
|
@procedure = procedure
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@ -36,6 +37,16 @@ module NewAdministrateur
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_to_procedure
|
||||||
|
procedure = current_administrateur.procedures.find(procedure_params[:id])
|
||||||
|
service = services.find(procedure_params[:service_id])
|
||||||
|
|
||||||
|
procedure.update(service: service)
|
||||||
|
|
||||||
|
redirect_to admin_procedure_path(procedure.id),
|
||||||
|
notice: "service affecté : #{procedure.service.nom}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def service_params
|
def service_params
|
||||||
|
@ -49,5 +60,13 @@ module NewAdministrateur
|
||||||
def services
|
def services
|
||||||
current_administrateur.services
|
current_administrateur.services
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def procedure_params
|
||||||
|
params.require(:procedure).permit(:id, :service_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def procedure
|
||||||
|
current_administrateur.procedures.find(params[:procedure_id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
.container
|
#services-index.container
|
||||||
|
%h1 Choix du service pour la procédure
|
||||||
|
|
||||||
|
= form_for @procedure, url: { controller: "new_administrateur/services", action: :add_to_procedure } , html: { class: 'form' } do |f|
|
||||||
|
= f.label :service_id, "La procédure #{@procedure.libelle} est affectée au service"
|
||||||
|
= f.select :service_id,
|
||||||
|
current_administrateur.services.map { |s| [ s.nom, s.id ] },
|
||||||
|
{ prompt: 'choisir un service', selected: @procedure.service&.id },
|
||||||
|
required: true
|
||||||
|
|
||||||
|
= f.hidden_field :id
|
||||||
|
= f.submit 'valider', class: 'button primary'
|
||||||
|
|
||||||
%h1 Liste des Services
|
%h1 Liste des Services
|
||||||
|
|
||||||
%table.table.table-service.hoverable
|
%table.table.table-service.hoverable
|
||||||
|
|
|
@ -287,7 +287,11 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :services, except: [:destroy, :show]
|
resources :services, except: [:destroy, :show] do
|
||||||
|
collection do
|
||||||
|
patch 'add_to_procedure'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
apipie
|
apipie
|
||||||
|
|
|
@ -62,4 +62,36 @@ describe NewAdministrateur::ServicesController, type: :controller do
|
||||||
it { expect(response).to render_template(:edit) }
|
it { expect(response).to render_template(:edit) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#add_to_procedure' do
|
||||||
|
let!(:procedure) { create(:procedure, administrateur: admin) }
|
||||||
|
let!(:service) { create(:service, administrateur: admin) }
|
||||||
|
|
||||||
|
def post_add_to_procedure
|
||||||
|
sign_in admin
|
||||||
|
params = {
|
||||||
|
procedure: {
|
||||||
|
id: procedure.id,
|
||||||
|
service_id: service.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
patch :add_to_procedure, params: params
|
||||||
|
procedure.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when adding a service to a procedure' do
|
||||||
|
before { post_add_to_procedure }
|
||||||
|
|
||||||
|
it { expect(flash.alert).to be_nil }
|
||||||
|
it { expect(flash.notice).to eq("service affecté : #{service.nom}") }
|
||||||
|
it { expect(procedure.service_id).to eq(service.id) }
|
||||||
|
it { expect(response).to redirect_to(admin_procedure_path(procedure.id)) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when stealing a service to add it to a procedure' do
|
||||||
|
let!(:service) { create(:service) }
|
||||||
|
|
||||||
|
it { expect { post_add_to_procedure }.to raise_error(ActiveRecord::RecordNotFound) }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue