Add features filter procedure for gestionnaire (not active on dossier list for now)
This commit is contained in:
parent
e944364929
commit
a612dc6021
9 changed files with 136 additions and 4 deletions
16
app/controllers/backoffice/procedure_filter_controller.rb
Normal file
16
app/controllers/backoffice/procedure_filter_controller.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class Backoffice::ProcedureFilterController < ApplicationController
|
||||
before_action :authenticate_gestionnaire!
|
||||
|
||||
def index
|
||||
@gestionnaire = current_gestionnaire
|
||||
@procedures = current_gestionnaire.procedures
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
current_gestionnaire.update_attribute(:procedure_filter, params[:procedure_filter])
|
||||
|
||||
flash.notice = 'Filtre mis à jour'
|
||||
redirect_to backoffice_filtres_path
|
||||
end
|
||||
end
|
16
app/views/backoffice/procedure_filter/index.html.haml
Normal file
16
app/views/backoffice/procedure_filter/index.html.haml
Normal file
|
@ -0,0 +1,16 @@
|
|||
%h2.text-primary Filtre des procédures
|
||||
%h4 Sélectionnez les procédures que vous souhaitez suivre.
|
||||
|
||||
= form_for @gestionnaire, url:{controller: 'backoffice/procedure_filter', action: :update } do |f|
|
||||
.input-group
|
||||
- @procedures.each do |procedure|
|
||||
.checkbox
|
||||
%label
|
||||
= check_box_tag 'procedure_filter[]', procedure.id, (true if @gestionnaire.procedure_filter.include?(procedure.id))
|
||||
= procedure.libelle
|
||||
%br
|
||||
= submit_tag 'Valider', class: 'btn btn-primary'
|
||||
|
||||
%br
|
||||
%b
|
||||
Aucune sélection = voir tout
|
17
app/views/gestionnaires/_login_banner.html.haml
Normal file
17
app/views/gestionnaires/_login_banner.html.haml
Normal file
|
@ -0,0 +1,17 @@
|
|||
%div{ style: "decorate:none; display: flex;box-shadow:none; float:right; display: flex" }
|
||||
%div{ style: "vertical-align: middle; margin-right: 10px; margin-top: auto; margin-bottom: auto;" }
|
||||
= current_gestionnaire.email
|
||||
.dropdown#admin_menu
|
||||
%button.btn.btn-default.dropdown-toggle#dropdownMenuAdmin{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false}
|
||||
%i.fa.fa-cog
|
||||
%span.caret
|
||||
%ul.dropdown-menu.dropdown-menu-right
|
||||
%li
|
||||
= link_to(backoffice_filtres_path, id: :filter) do
|
||||
%i.fa.fa-list
|
||||
Filtre procédure
|
||||
%li.divider{ role: :separator}
|
||||
%li
|
||||
= link_to('/gestionnaires/sign_out',id: :admin_sign_out, method: :delete) do
|
||||
%i.fa.fa-power-off
|
||||
Se déconnecter
|
|
@ -21,9 +21,7 @@
|
|||
|
||||
#sign_out
|
||||
-if gestionnaire_signed_in?
|
||||
%div
|
||||
= current_gestionnaire.email
|
||||
= link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md'
|
||||
= render partial: 'gestionnaires/login_banner'
|
||||
-elsif administrateur_signed_in?
|
||||
= render partial: 'administrateurs/login_banner'
|
||||
- elsif user_signed_in?
|
||||
|
|
|
@ -98,6 +98,10 @@ Rails.application.routes.draw do
|
|||
|
||||
get 'dossiers/search' => 'dossiers#search'
|
||||
|
||||
get 'filtres' => 'procedure_filter#index'
|
||||
patch 'filtres/update' => 'procedure_filter#update'
|
||||
|
||||
|
||||
resources :dossiers do
|
||||
post 'valid' => 'dossiers#valid'
|
||||
post 'close' => 'dossiers#close'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddProcedureFilterToGestionnaire < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :gestionnaires, :procedure_filter, :integer, array: true, default: []
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160223134354) do
|
||||
ActiveRecord::Schema.define(version: 20160314102523) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -172,6 +172,7 @@ ActiveRecord::Schema.define(version: 20160223134354) do
|
|||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "administrateur_id"
|
||||
t.integer "procedure_filter", default: [], array: true
|
||||
end
|
||||
|
||||
add_index "gestionnaires", ["email"], name: "index_gestionnaires_on_email", unique: true, using: :btree
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Backoffice::ProcedureFilterController, type: :controller do
|
||||
let(:gestionnaire) { create :gestionnaire }
|
||||
|
||||
before do
|
||||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
describe '#GET index' do
|
||||
it { expect(subject.status).to eq 200 }
|
||||
end
|
||||
|
||||
describe '#PATCH update' do
|
||||
context 'when procedure_filter is not present' do
|
||||
subject { patch :update }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to backoffice_filtres_path }
|
||||
it { expect(gestionnaire.procedure_filter).to eq [] }
|
||||
end
|
||||
|
||||
context 'when procedure_filter is present' do
|
||||
let (:procedure_filter) { ["3", "1"] }
|
||||
|
||||
subject { patch :update, procedure_filter: procedure_filter }
|
||||
|
||||
before do
|
||||
subject
|
||||
gestionnaire.reload
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to backoffice_filtres_path }
|
||||
it { expect(gestionnaire.procedure_filter.size).to eq 2 }
|
||||
it { expect(gestionnaire.procedure_filter).to include 1 }
|
||||
it { expect(gestionnaire.procedure_filter).to include 3 }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'backoffice/procedure_filter/index.html.haml', type: :view do
|
||||
let(:administrateur) { create :administrateur }
|
||||
|
||||
before do
|
||||
create :procedure, libelle: 'plip', administrateur: administrateur
|
||||
create :procedure, libelle: 'plop', administrateur: administrateur
|
||||
create :procedure, libelle: 'plap', administrateur: administrateur
|
||||
end
|
||||
|
||||
context 'when gestionnaire have already check procedure' do
|
||||
let(:gestionnaire) { create(:gestionnaire,
|
||||
administrateur: administrateur,
|
||||
procedure_filter: [administrateur.procedures.first.id,
|
||||
administrateur.procedures.last.id]) }
|
||||
|
||||
before do
|
||||
sign_in gestionnaire
|
||||
|
||||
assign(:gestionnaire, gestionnaire)
|
||||
assign(:procedures, gestionnaire.procedures)
|
||||
|
||||
render
|
||||
end
|
||||
|
||||
subject { rendered }
|
||||
|
||||
it { is_expected.to have_content('Filtre des procédures') }
|
||||
it { is_expected.to have_css("input[type=checkbox][value='#{gestionnaire.procedures.first.id}'][checked=checked]") }
|
||||
it { is_expected.to have_css("input[type=checkbox][value='#{gestionnaire.procedures.last.id}'][checked=checked]") }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue