Add gestionnaire administration panel.
This commit is contained in:
parent
bc41412b6b
commit
2a2aef34db
10 changed files with 170 additions and 1 deletions
32
app/controllers/admin/gestionnaires_controller.rb
Normal file
32
app/controllers/admin/gestionnaires_controller.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
class Admin::GestionnairesController < AdminController
|
||||
include SmartListing::Helper::ControllerExtensions
|
||||
helper SmartListing::Helper
|
||||
|
||||
def index
|
||||
@gestionnaires = smart_listing_create :gestionnaires,
|
||||
current_administrateur.gestionnaires,
|
||||
partial: "admin/gestionnaires/list",
|
||||
array: true
|
||||
@gestionnaire ||= Gestionnaire.new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@gestionnaire = Gestionnaire.create(create_procedure_params)
|
||||
|
||||
if (@gestionnaire.errors.empty?)
|
||||
flash.notice = 'Gestionnaire ajouté'
|
||||
else
|
||||
flash.alert = @gestionnaire.errors.full_messages.join('<br />').html_safe
|
||||
end
|
||||
|
||||
redirect_to admin_gestionnaires_path
|
||||
end
|
||||
|
||||
def create_procedure_params
|
||||
params.require(:gestionnaire).permit(:email)
|
||||
.merge(administrateur_id: current_administrateur.id)
|
||||
.merge(password: SecureRandom.hex(5))
|
||||
end
|
||||
|
||||
end
|
5
app/views/admin/gestionnaires/_informations.html.haml
Normal file
5
app/views/admin/gestionnaires/_informations.html.haml
Normal file
|
@ -0,0 +1,5 @@
|
|||
-{email: 'Email*'}.each do |key, value|
|
||||
.form-group{class: ('has-error' if @gestionnaire.errors.messages[key])}
|
||||
%h4
|
||||
=value
|
||||
=f.text_field key, class: 'form-control', placeholder: value
|
15
app/views/admin/gestionnaires/_list.html.haml
Normal file
15
app/views/admin/gestionnaires/_list.html.haml
Normal file
|
@ -0,0 +1,15 @@
|
|||
- unless smart_listing.empty?
|
||||
%table.table
|
||||
%thead
|
||||
%th#libelle= smart_listing.sortable 'Email', 'email'
|
||||
|
||||
- @gestionnaires.each do |gestionnaire|
|
||||
%tr
|
||||
%td= gestionnaire.email
|
||||
|
||||
= smart_listing.paginate
|
||||
= smart_listing.pagination_per_page_links
|
||||
|
||||
- else
|
||||
%h4.center
|
||||
Aucun gestionnaire
|
19
app/views/admin/gestionnaires/index.html.haml
Normal file
19
app/views/admin/gestionnaires/index.html.haml
Normal file
|
@ -0,0 +1,19 @@
|
|||
%h1 Gestion des gestionnaires
|
||||
%br
|
||||
|
||||
.row
|
||||
.col-md-4.col-lg-4
|
||||
= smart_listing_render :gestionnaires
|
||||
.col-md-1.col-lg-1
|
||||
|
||||
.col-md-6.col-lg-6
|
||||
%h3 Ajouter un gestionnaire
|
||||
#procedure_new.section.section-label
|
||||
= form_for @gestionnaire, url: {controller: 'admin/gestionnaires', action: :create} do |f|
|
||||
.row
|
||||
.col-md-5.col-lg-5
|
||||
=render partial: 'informations', locals: {f: f}
|
||||
.col-md-2.col-lg-2
|
||||
%br
|
||||
%br
|
||||
=f.submit 'Valider', class: 'btn btn-info', style: 'float:left'
|
1
app/views/admin/gestionnaires/index.js.erb
Normal file
1
app/views/admin/gestionnaires/index.js.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= smart_listing_update :gestionnaires %>
|
|
@ -10,11 +10,15 @@
|
|||
= link_to(admin_procedures_path, id: :menu_item_procedure) do
|
||||
%i.fa.fa-list{ style: "background-size: 10px;"}
|
||||
Procédures
|
||||
%li
|
||||
= link_to(admin_gestionnaires_path) do
|
||||
%i.fa.fa-user
|
||||
Gestionnaires
|
||||
%li.divider{ role: :separator}
|
||||
%li
|
||||
= link_to(admin_profile_path, id: :profile) do
|
||||
%i.fa.fa-user
|
||||
Profile
|
||||
%li.divider{ role: :separator}
|
||||
%li
|
||||
= link_to('/administrateurs/sign_out',id: :admin_sign_out, method: :delete) do
|
||||
%i.fa.fa-power-off
|
||||
|
|
|
@ -57,6 +57,14 @@ fr:
|
|||
email:
|
||||
blank: est vide
|
||||
taken: ': Invitation déjà envoyée'
|
||||
gestionnaire:
|
||||
attributes:
|
||||
email:
|
||||
invalid: invalide
|
||||
taken: déjà utilisé
|
||||
blank: est vide
|
||||
password:
|
||||
blank: ': Le mot de passe est vide'
|
||||
|
||||
devise:
|
||||
confirmations:
|
||||
|
|
|
@ -74,6 +74,7 @@ Rails.application.routes.draw do
|
|||
resource :pieces_justificatives, only: [:show, :update]
|
||||
resources :pieces_justificatives, only: :destroy
|
||||
end
|
||||
resources :gestionnaires, only: [:index, :create]
|
||||
end
|
||||
|
||||
get 'backoffice' => 'backoffice#index'
|
||||
|
|
50
spec/controllers/admin/gestionnaires_controller_spec.rb
Normal file
50
spec/controllers/admin/gestionnaires_controller_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::GestionnairesController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
subject { get :index }
|
||||
it { expect(subject.status).to eq(200) }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:email) { 'test@plop.com' }
|
||||
before do
|
||||
post :create, gestionnaire: { email: email }
|
||||
end
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect(response).to redirect_to admin_gestionnaires_path }
|
||||
|
||||
describe 'Gestionnaire attributs in database' do
|
||||
let(:gestionnaire) { Gestionnaire.last }
|
||||
it { expect(gestionnaire.email).to eq(email) }
|
||||
it { expect(gestionnaire.administrateur_id).to eq(admin.id) }
|
||||
end
|
||||
|
||||
context 'when email is not valid' do
|
||||
let(:email) { 'piou' }
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect{ response }.not_to change(Gestionnaire, :count) }
|
||||
end
|
||||
|
||||
context 'when email is empty' do
|
||||
let(:email) { '' }
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect{ response }.not_to change(Gestionnaire, :count) }
|
||||
end
|
||||
|
||||
context ' when email already exists' do
|
||||
let(:email) { 'test@plop.com' }
|
||||
before do
|
||||
post :create, gestionnaire: { email: email }
|
||||
end
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect{ response }.not_to change(Gestionnaire, :count) }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
34
spec/views/admin/gestionnaires/index.html.haml_spec.rb
Normal file
34
spec/views/admin/gestionnaires/index.html.haml_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'admin/gestionnaires/index.html.haml', type: :view do
|
||||
let(:token) { 'super_token' }
|
||||
let(:admin) { create(:administrateur, api_token: token) }
|
||||
|
||||
before do
|
||||
assign(:gestionnaires, (smart_listing_create :gestionnaires,
|
||||
admin.gestionnaires,
|
||||
partial: "admin/gestionnaires/list",
|
||||
array: true))
|
||||
assign(:gestionnaire, Gestionnaire.new())
|
||||
end
|
||||
|
||||
context 'Aucun gestionnaire' do
|
||||
before do
|
||||
render
|
||||
end
|
||||
it { expect(rendered).to have_content('Aucun gestionnaire') }
|
||||
end
|
||||
|
||||
context 'Ajout d\'un gestionnaire' do
|
||||
before do
|
||||
create(:gestionnaire, administrateur: admin)
|
||||
admin.reload
|
||||
assign(:gestionnaires, (smart_listing_create :gestionnaires,
|
||||
admin.gestionnaires,
|
||||
partial: "admin/gestionnaires/list",
|
||||
array: true))
|
||||
render
|
||||
end
|
||||
it { expect(rendered).to match(/plop\d+@plop.com/) }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue