diff --git a/app/controllers/backoffice/procedure_filter_controller.rb b/app/controllers/backoffice/procedure_filter_controller.rb deleted file mode 100644 index 97f0bc57d..000000000 --- a/app/controllers/backoffice/procedure_filter_controller.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 051438c48..120d56f35 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -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 diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 5f9d2baff..68d8f30ee 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -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 diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index 1f72288a7..2ef534620 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -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 diff --git a/app/views/backoffice/procedure_filter/index.html.haml b/app/views/backoffice/procedure_filter/index.html.haml deleted file mode 100644 index d616eb6a2..000000000 --- a/app/views/backoffice/procedure_filter/index.html.haml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/app/views/gestionnaires/_login_banner.html.haml b/app/views/gestionnaires/_login_banner.html.haml index 0a4d33e33..40651db9d 100644 --- a/app/views/gestionnaires/_login_banner.html.haml +++ b/app/views/gestionnaires/_login_banner.html.haml @@ -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 -  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 +%div.user + + %i.fa.fa-user + = current_gestionnaire.email + + = link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md' \ No newline at end of file diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index 2849be7cf..718624635 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -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' diff --git a/app/views/users/_login_banner.html.haml b/app/views/users/_login_banner.html.haml new file mode 100644 index 000000000..f467eebea --- /dev/null +++ b/app/views/users/_login_banner.html.haml @@ -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' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 66e600ab1..9c582b394 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20160822142045_delete_value_of_filter_procedure.rb b/db/migrate/20160822142045_delete_value_of_filter_procedure.rb new file mode 100644 index 000000000..f541aefc9 --- /dev/null +++ b/db/migrate/20160822142045_delete_value_of_filter_procedure.rb @@ -0,0 +1,9 @@ +class DeleteValueOfFilterProcedure < ActiveRecord::Migration + class Gestionnaire < ActiveRecord::Base + + end + + def change + Gestionnaire.all.update_all(procedure_filter: '{}') + end +end diff --git a/db/schema.rb b/db/schema.rb index 86f0bac18..80b669500 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/spec/controllers/backoffice/procedure_filter_controller_spec.rb b/spec/controllers/backoffice/procedure_filter_controller_spec.rb deleted file mode 100644 index 4f8aac276..000000000 --- a/spec/controllers/backoffice/procedure_filter_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index ff8762702..dc5841a82 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -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 } diff --git a/spec/views/backoffice/procedure_filter/index_html.haml_spec.rb b/spec/views/backoffice/procedure_filter/index_html.haml_spec.rb deleted file mode 100644 index 3f4a8b442..000000000 --- a/spec/views/backoffice/procedure_filter/index_html.haml_spec.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/spec/views/layouts/_navbar_spec.rb b/spec/views/layouts/_navbar_spec.rb index 3c3156d6d..dab6e8493 100644 --- a/spec/views/layouts/_navbar_spec.rb +++ b/spec/views/layouts/_navbar_spec.rb @@ -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