delete filter procedure for gestionnaire

This commit is contained in:
Xavier J 2016-08-22 16:36:25 +02:00
parent b661a2eb38
commit 5b0e01f117
15 changed files with 39 additions and 212 deletions

View file

@ -1,16 +0,0 @@
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].nil? ? [] : params[:procedure_filter]))
flash.notice = 'Filtre mis à jour'
redirect_to backoffice_filtres_path
end
end

View file

@ -235,12 +235,12 @@ class Dossier < ActiveRecord::Base
#TODO refactor
composed_scope = composed_scope.where(
dossiers[:id].eq_any(current_gestionnaire.dossiers_filter.ids).and\
dossiers[:id].eq_any(current_gestionnaire.dossiers.ids).and\
dossiers[:state].does_not_match('draft').and\
dossiers[:archived].eq(false))
begin
if Float(terms) && terms.to_i <= 2147483647 && current_gestionnaire.dossiers_filter.ids.include?(terms.to_i)
if Float(terms) && terms.to_i <= 2147483647 && current_gestionnaire.dossiers.ids.include?(terms.to_i)
dossier = Dossier.where("state != 'draft'").find(terms.to_i)
end
rescue ArgumentError, ActiveRecord::RecordNotFound

View file

@ -12,18 +12,10 @@ class Gestionnaire < ActiveRecord::Base
after_create :build_default_preferences_list_dossier
def dossiers_filter
dossiers.where(procedure_id: procedure_filter_list)
end
def dossiers_follow
dossiers.joins(:follows).where("follows.gestionnaire_id = #{id}")
end
def procedure_filter_list
procedure_filter.empty? ? procedures.pluck(:id) : procedure_filter
end
def toggle_follow_dossier dossier_id
dossier = dossier_id
dossier = Dossier.find(dossier_id) unless dossier_id.class == Dossier

View file

@ -15,27 +15,27 @@ class DossiersListGestionnaireService
end
def nouveaux
@nouveaux ||= @current_devise_profil.dossiers_filter.nouveaux
@nouveaux ||= @current_devise_profil.dossiers.nouveaux
end
def waiting_for_gestionnaire
@waiting_for_gestionnaire ||= @current_devise_profil.dossiers_filter.waiting_for_gestionnaire
@waiting_for_gestionnaire ||= @current_devise_profil.dossiers.waiting_for_gestionnaire
end
def waiting_for_user
@waiting_for_user ||= @current_devise_profil.dossiers_filter.waiting_for_user
@waiting_for_user ||= @current_devise_profil.dossiers.waiting_for_user
end
def deposes
@deposes ||= @current_devise_profil.dossiers_filter.deposes
@deposes ||= @current_devise_profil.dossiers.deposes
end
def a_instruire
@a_instruire ||= @current_devise_profil.dossiers_filter.a_instruire
@a_instruire ||= @current_devise_profil.dossiers.a_instruire
end
def termine
@termine ||= @current_devise_profil.dossiers_filter.termine
@termine ||= @current_devise_profil.dossiers.termine
end
def suivi

View file

@ -1,16 +0,0 @@
%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

View file

@ -1,17 +1,6 @@
%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
&nbsp;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
&nbsp;Se déconnecter
%div.user
%i.fa.fa-user
= current_gestionnaire.email
= link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md'

View file

@ -18,19 +18,7 @@
-elsif administrateur_signed_in?
= render partial: 'administrateurs/login_banner'
- elsif user_signed_in?
%div.user
-if current_user.loged_in_with_france_connect?
%div{ id: "fconnect-profile", "data-fc-logout-url" => '/users/sign_out" data-method="delete' }
%a.text-info{ href: "#" }
= "#{current_user.given_name} #{current_user.family_name}"
= link_to "", '/users/sign_out', method: :delete, :class => 'btn fa fa-power-off off-fc-link'
-else
%i.fa.fa-user
= current_user.email
= link_to "Déconnexion", '/users/sign_out', method: :delete, :class => 'btn btn-md'
= render partial: 'users/login_banner'
- else
= link_to "Utilisateur", '/users/sign_in', method: :get, :class => 'btn btn-md'
= link_to "Accompagnateur", '/gestionnaires/sign_in', method: :get, :class => 'btn btn-md'

View file

@ -0,0 +1,13 @@
%div.user
-if current_user.loged_in_with_france_connect?
%div{ id: "fconnect-profile", "data-fc-logout-url" => '/users/sign_out" data-method="delete' }
%a.text-info{ href: "#" }
= "#{current_user.given_name} #{current_user.family_name}"
= link_to "", '/users/sign_out', method: :delete, :class => 'btn fa fa-power-off off-fc-link'
-else
%i.fa.fa-user
= current_user.email
= link_to "Déconnexion", '/users/sign_out', method: :delete, :class => 'btn btn-md'

View file

@ -142,9 +142,6 @@ Rails.application.routes.draw do
get 'dossiers/search' => 'dossiers#search'
get 'filtres' => 'procedure_filter#index'
patch 'filtres/update' => 'procedure_filter#update'
resource :private_formulaire
namespace :preference_list_dossier do

View file

@ -0,0 +1,9 @@
class DeleteValueOfFilterProcedure < ActiveRecord::Migration
class Gestionnaire < ActiveRecord::Base
end
def change
Gestionnaire.all.update_all(procedure_filter: '{}')
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160809083606) do
ActiveRecord::Schema.define(version: 20160822142045) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

View file

@ -1,62 +0,0 @@
require 'spec_helper'
describe Backoffice::ProcedureFilterController, type: :controller do
let(:gestionnaire) { create :gestionnaire }
before do
sign_in gestionnaire
end
describe '#GET index' do
subject { get :index }
before do
subject
end
it { expect(response.status).to eq 200 }
end
describe '#PATCH update' do
context 'when procedure_filter params 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 attribut is not empty and procedure_filter params is not present' do
let(:gestionnaire) { create :gestionnaire, procedure_filter: [3,2] }
subject { patch :update }
before do
subject
gestionnaire.reload
end
it { is_expected.to redirect_to backoffice_filtres_path }
it { expect(gestionnaire.procedure_filter).to eq [] }
end
context 'when procedure_filter params 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

View file

@ -35,36 +35,6 @@ describe Gestionnaire, type: :model do
it { is_expected.to have_many(:preference_list_dossiers) }
end
describe '#dossiers_filter' do
let!(:dossier) { create :dossier, procedure: procedure }
subject { gestionnaire.dossiers_filter }
context 'before filter' do
it { expect(subject.size).to eq 1 }
end
context 'after filter' do
let(:procedure_filter) { [procedure_2.id] }
it { expect(subject.size).to eq 0 }
end
end
describe '#procedure_filter_list' do
subject { gestionnaire.procedure_filter_list }
context 'when gestionnaire procedure_filter is empty' do
it { expect(subject).to eq [procedure.id, procedure_2.id] }
end
context 'when gestionnaire procedure_filter is no empty' do
let(:procedure_filter) { [procedure.id] }
it { expect(subject).to eq [procedure.id] }
end
end
describe '#toggle_follow_dossier' do
let!(:dossier) { create :dossier, procedure: procedure }

View file

@ -1,37 +0,0 @@
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,
administrateurs: [administrateur],
procedure_filter: [administrateur.procedures.first.id,
administrateur.procedures.last.id]) }
before do
create :assign_to, gestionnaire: gestionnaire, procedure: administrateur.procedures.first
create :assign_to, gestionnaire: gestionnaire, procedure: administrateur.procedures.second
create :assign_to, gestionnaire: gestionnaire, procedure: administrateur.procedures.last
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

View file

@ -52,7 +52,7 @@ describe 'layouts/_navbar.html.haml', type: :view do
it { is_expected.not_to match(/href="\/administrateurs\/sign_in">Administrateur/) }
it { is_expected.not_to match(/Mes Procédures/) }
it { is_expected.to match(/Mes Dossiers/) }
it { is_expected.to match(/Se déconnecter/) }
it { is_expected.to match(/Déconnexion/) }
end
end