Filter by procedure is activated on route /backoffice/dossiers/procedure/:id

This commit is contained in:
Xavier J 2016-09-08 16:21:54 +02:00
parent bb19982011
commit 62a0b84048
21 changed files with 287 additions and 15 deletions

View file

@ -23,7 +23,13 @@ class Admin::AccompagnateursController < AdminController
end
def update
AccompagnateurService.change_assignement! Gestionnaire.find(params[:accompagnateur_id]), Procedure.find(params[:procedure_id]), params[:to]
gestionnaire = Gestionnaire.find(params[:accompagnateur_id])
procedure = Procedure.find(params[:procedure_id])
to = params[:to]
AccompagnateurService.change_assignement! gestionnaire, procedure, to
AccompagnateurService.build_default_column gestionnaire, procedure, to
flash.notice = "Assignement effectué"
redirect_to admin_procedure_accompagnateurs_path, procedure_id: params[:procedure_id]

View file

@ -123,7 +123,7 @@ class Backoffice::DossiersController < ApplicationController
end
def create_dossiers_list_facade liste='a_traiter'
@dossiers_list_facade = DossiersListFacades.new current_gestionnaire, liste
@dossiers_list_facade = DossiersListFacades.new current_gestionnaire, liste, retrieve_procedure
end
def create_dossier_facade dossier_id
@ -133,4 +133,10 @@ class Backoffice::DossiersController < ApplicationController
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: '/backoffice')
end
def retrieve_procedure
return if params[:procedure_id].blank?
current_gestionnaire.procedures.find params[:procedure_id]
end
end

View file

@ -3,6 +3,7 @@ class Backoffice::PreferenceListDossierController < ApplicationController
helper SmartListing::Helper
before_action :authenticate_gestionnaire!
before_action :params_procedure_id
def add
PreferenceListDossier.create(
@ -13,14 +14,17 @@ class Backoffice::PreferenceListDossierController < ApplicationController
bootstrap_lg: params[:bootstrap_lg],
order: nil,
filter: nil,
gestionnaire: current_gestionnaire
gestionnaire: current_gestionnaire,
procedure_id: params_procedure_id
)
render partial: 'backoffice/dossiers/pref_list', formats: :js
end
def reload_pref_list
render partial: 'backoffice/dossiers/pref_list'
@dossiers_list_facade = DossiersListFacades.new current_gestionnaire, '', retrieve_procedure
render partial: 'backoffice/dossiers/pref_list', id: params_procedure_id
end
def delete
@ -28,4 +32,15 @@ class Backoffice::PreferenceListDossierController < ApplicationController
render partial: 'backoffice/dossiers/pref_list', formats: :js
end
private
def params_procedure_id
@procedure_id ||= params[:procedure_id]
end
def retrieve_procedure
return if params[:procedure_id].blank?
current_gestionnaire.procedures.find params_procedure_id
end
end

View file

@ -19,10 +19,18 @@ class DossiersListFacades
@liste
end
def procedure_id
@procedure.nil? ? nil : @procedure.id
end
def dossiers_to_display
service.dossiers_to_display
end
def preference_list_dossiers_filter
@list_table_columns ||= @current_devise_profil.preference_list_dossiers.where(procedure: @procedure).order(:id)
end
def nouveaux_class
(@liste == 'nouveaux' ? 'active' : '')
end

View file

@ -1,5 +1,6 @@
class PreferenceListDossier < ActiveRecord::Base
belongs_to :gestionnaire
belongs_to :procedure
def table_attr
return self.attr if table.nil? || table.empty?

View file

@ -15,6 +15,8 @@ class Procedure < ActiveRecord::Base
has_many :assign_to, dependent: :destroy
has_many :gestionnaires, through: :assign_to
has_many :preference_list_dossiers
delegate :use_api_carto, to: :module_api_carto
accepts_nested_attributes_for :types_de_champ, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true

View file

@ -9,4 +9,16 @@ class AccompagnateurService
AssignTo.delete_all(gestionnaire: accompagnateur, procedure: procedure)
end
end
def self.build_default_column accompagnateur, procedure, to
return unless to == ASSIGN
return unless PreferenceListDossier.where(gestionnaire: accompagnateur, procedure: procedure).empty?
accompagnateur.preference_list_dossiers.each do |pref|
clone = pref.dup
clone.procedure = procedure
clone.save
end
end
end

View file

@ -39,6 +39,6 @@ class DossiersListGestionnaireService
end
def filter_dossiers
@procedure.nil? ? @current_devise_profil.dossiers : @procedure.dossiers
@filter_dossiers ||= @procedure.nil? ? @current_devise_profil.dossiers : @procedure.dossiers
end
end

View file

@ -1,14 +1,14 @@
- unless smart_listing.empty?
%table.table
%thead
- current_gestionnaire.preference_list_dossiers.order(:id).each do |preference|
- @dossiers_list_facade.preference_list_dossiers_filter.each do |preference|
%th{class: "col-md-#{preference.bootstrap_lg} col-lg-#{preference.bootstrap_lg}"}= smart_listing.sortable preference.libelle, preference.table_attr
%th.col-md-1.col-lg-1.center Actions
%th.col-md-1.col-lg-1.center Abonnés
- @dossiers.each do |dossier|
%tr
- current_gestionnaire.preference_list_dossiers.order(:id).each_with_index do |preference, index|
- @dossiers_list_facade.preference_list_dossiers_filter.each_with_index do |preference, index|
%td
- if preference.table.nil? || preference.table.empty?
- value = dossier.decorate.public_send(preference.attr_decorate)

View file

@ -9,10 +9,11 @@
Actuelles
%ul
- current_gestionnaire.preference_list_dossiers.order(:id).each_with_index do |preference, index|
- @dossiers_list_facade.preference_list_dossiers_filter.each_with_index do |preference, index|
%li
= form_tag backoffice_preference_list_dossier_delete_path, method: :delete, remote: true do
= hidden_field_tag :pref_id, preference.id
= hidden_field_tag :procedure_id, preference.procedure_id
= preference.libelle
%button.btn.btn-default.btn-xs{type: :submit, id: "delete_pref_list_#{preference[:table]}_#{preference[:attr]}"}
%i.fa.fa-minus
@ -36,6 +37,7 @@
= hidden_field_tag :attr, columns.second[:attr]
= hidden_field_tag :attr_decorate, columns.second[:attr_decorate]
= hidden_field_tag :bootstrap_lg, columns.second[:bootstrap_lg]
= hidden_field_tag :procedure_id, @dossiers_list_facade.procedure_id
= columns.second[:libelle]
%button.btn.btn-default.btn-xs{type: :submit, id: "add_pref_list_#{columns.second[:table]}_#{columns.second[:attr]}"}

View file

@ -1,12 +1,12 @@
$.ajax({
method: 'get',
url: '/backoffice/preference_list_dossier/reload_smartlisting',
url: '/backoffice/preference_list_dossier/reload_smartlisting?procedure_id=<%= @procedure_id %>',
async: true
});
$.ajax({
methd: 'get',
url: '/backoffice/preference_list_dossier/reload_pref_list',
url: '/backoffice/preference_list_dossier/reload_pref_list?procedure_id=<%= @procedure_id %>',
async: true
}).done(function (data) {
$("#pref_list_menu").html(data);

View file

@ -0,0 +1,5 @@
class AddHasProcedureToPrefListDossier < ActiveRecord::Migration
def change
add_belongs_to :preference_list_dossiers, :procedure
end
end

View file

@ -0,0 +1,44 @@
class BuildDefaultPrefListDossierProcedure < ActiveRecord::Migration
class Gestionnaire < ActiveRecord::Base
has_many :assign_to, dependent: :destroy
has_many :procedures, through: :assign_to
has_many :preference_list_dossiers
end
class PreferenceListDossier < ActiveRecord::Base
belongs_to :gestionnaire
belongs_to :procedure
end
class AssignTo < ActiveRecord::Base
belongs_to :procedure
belongs_to :gestionnaire
end
class Procedure < ActiveRecord::Base
has_many :gestionnaires, through: :assign_to
has_many :preference_list_dossiers
end
def up
Gestionnaire.all.each do |gestionnaire|
gestionnaire.procedures.each do |procedure|
gestionnaire.preference_list_dossiers.where(procedure: nil).each do |preference|
clone = preference.dup
clone.procedure = procedure
clone.save
end
base_object = gestionnaire.preference_list_dossiers.where(procedure: nil).size
created_object = gestionnaire.preference_list_dossiers.where(procedure: procedure).size
raise "ERROR nb object (#{base_object} != #{created_object})" unless created_object == base_object
end
end
end
def down
PreferenceListDossier.where('procedure_id IS NOT NULL')
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: 20160901082824) do
ActiveRecord::Schema.define(version: 20160906134155) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -264,6 +264,7 @@ ActiveRecord::Schema.define(version: 20160901082824) do
t.string "order"
t.string "filter"
t.integer "gestionnaire_id"
t.integer "procedure_id"
end
create_table "procedure_paths", force: :cascade do |t|

View file

@ -15,7 +15,7 @@ describe Admin::AccompagnateursController, type: :controller do
end
describe 'PUT #update' do
subject { put :update, accompagnateur_id: gestionnaire.id ,procedure_id: procedure.id }
subject { put :update, accompagnateur_id: gestionnaire.id ,procedure_id: procedure.id, to: 'assign' }
it { expect(subject).to redirect_to admin_procedure_accompagnateurs_path(procedure_id: procedure.id) }
@ -25,6 +25,10 @@ describe Admin::AccompagnateursController, type: :controller do
end
it { expect(flash[:notice]).to be_present }
it 'default pref list dossier procedure columns are created' do
expect(procedure.preference_list_dossiers.size).to eq gestionnaire.preference_list_dossiers.where('procedure_id IS NULL').size
end
end
end
end

View file

@ -36,6 +36,7 @@ describe Backoffice::PreferenceListDossierController, type: :controller do
it { expect(last.bootstrap_lg).to eq bootstrap_lg }
it { expect(last.order).to be_nil }
it { expect(last.filter).to be_nil }
it { expect(last.procedure_id).to be_nil }
it { expect(last.gestionnaire).to eq gestionnaire }
end
end

View file

@ -0,0 +1,39 @@
require 'spec_helper'
describe DossiersListFacades do
let(:gestionnaire) { create :gestionnaire }
let(:procedure) { create :procedure }
before do
create :preference_list_dossier,
gestionnaire: gestionnaire,
table: '',
attr: 'state',
attr_decorate: 'display_state'
create :preference_list_dossier,
gestionnaire: gestionnaire,
table: '',
attr: 'state',
attr_decorate: 'display_state',
procedure_id: procedure.id
end
describe '#preference_list_dossiers_filter' do
subject { facade.preference_list_dossiers_filter }
context 'when procedure is not pasted at the facade' do
let(:facade) { described_class.new gestionnaire, 'nouveaux' }
it { expect(subject.size).to eq 6 }
end
context 'when procedure is pasted at the facade' do
let(:facade) { described_class.new gestionnaire, 'nouveaux', procedure }
it { expect(subject.size).to eq 1 }
end
end
end

View file

@ -0,0 +1,92 @@
require 'spec_helper'
feature 'usage of pref list dossier lateral panel by procedure', js: true do
let(:administrateur) { create(:administrateur) }
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
let(:procedure) { create(:procedure, administrateur: administrateur) }
before do
create(:dossier, :with_entreprise, procedure: procedure, state: 'updated')
create :assign_to, procedure: procedure, gestionnaire: gestionnaire
visit backoffice_path
end
scenario 'he is redirected to /gestionnaires/sign_id' do
expect(page).to have_css('#gestionnaire_login')
end
context 'when user enter good credentials' do
before do
page.find_by_id(:gestionnaire_email).set gestionnaire.email
page.find_by_id(:gestionnaire_password).set gestionnaire.password
page.click_on 'Se connecter'
end
scenario 'he is redirected to /backoffice/dossiers/' do
expect(page).to have_css('#backoffice_index')
end
describe 'user navigate to dossiers list by procedure' do
before do
visit backoffice_dossiers_procedure_path(procedure.id)
end
scenario 'lateral panel is masked' do
expect(page).to have_css('#pref_list_menu', visible: false)
end
context 'when on click on pref list button' do
before do
page.click_on 'pref_list_dossier_open_action'
end
scenario 'lateral panel is appeared' do
expect(page).to have_css('#pref_list_menu')
end
context 'when on click on add attribut button' do
before do
page.click_on 'add_pref_list_entreprise_siren'
end
scenario 'preference list panel is brought up to date' do
wait_for_ajax
expect(page).to have_css('#delete_pref_list_entreprise_siren')
end
scenario 'dossier is brought up to date' do
wait_for_ajax
expect(page).to have_selector("a.sortable[data-attr='entreprise.siren']")
end
context 'when on click on delete attribut button' do
before do
page.click_on 'delete_pref_list_entreprise_siren'
end
scenario 'preference list panel is brought up to date' do
wait_for_ajax
expect(page).not_to have_css('#delete_pref_list_entreprise_siren')
end
scenario 'dossier is brought up to date' do
wait_for_ajax
expect(page).not_to have_selector("a.sortable[data-attr='entreprise.siren']")
end
context 'when on click on close pref list button' do
before do
page.click_on 'pref_list_dossier_close_action'
end
scenario 'lateral panel is masked' do
expect(page).to have_css('#pref_list_menu', visible: false)
end
end
end
end
end
end
end
end

View file

@ -11,6 +11,7 @@ describe PreferenceListDossier do
it { is_expected.to have_db_column(:gestionnaire_id) }
it { is_expected.to belong_to(:gestionnaire) }
it { is_expected.to belong_to(:procedure) }
describe '.available_columns' do
subject { PreferenceListDossier.available_columns }

View file

@ -9,6 +9,7 @@ describe Procedure do
it { is_expected.to have_one(:mail_received) }
it { is_expected.to have_one(:module_api_carto) }
it { is_expected.to belong_to(:administrateur) }
it { is_expected.to have_many(:preference_list_dossiers) }
end
describe 'attributes' do

View file

@ -1,11 +1,12 @@
require 'spec_helper'
describe AccompagnateurService do
describe '#change_assignement!' do
let(:procedure) { create :procedure }
let(:accompagnateur) { create :gestionnaire }
describe '#change_assignement!' do
subject { AccompagnateurService.change_assignement! accompagnateur, procedure, to }
context 'when accompagnateur is not assign at the procedure' do
@ -29,4 +30,35 @@ describe AccompagnateurService do
it { expect(accompagnateur.procedures).not_to include procedure }
end
end
describe '#build_default_column' do
subject { AccompagnateurService.build_default_column accompagnateur, procedure, to }
context 'when to is not assign' do
let(:to) { AccompagnateurService::NOT_ASSIGN }
it { is_expected.to be_nil }
end
context 'when to is assign' do
let(:to) { AccompagnateurService::ASSIGN }
context 'when gestionnaire has already preference for this procedure' do
before do
create :preference_list_dossier, gestionnaire: accompagnateur, procedure: procedure
end
it { is_expected.to be_nil }
end
context 'when gestionnaire has not preference for this procedure' do
before do
subject
end
it { expect(accompagnateur.preference_list_dossiers.where('procedure_id IS NULL').size).to eq procedure.preference_list_dossiers.size }
end
end
end
end