Active feature "keep actual smart listing page"
This commit is contained in:
parent
64d46a25df
commit
d5a85d17c7
7 changed files with 182 additions and 44 deletions
|
@ -13,7 +13,8 @@ class Backoffice::DossiersListController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
dossiers_list_facade param_liste
|
dossiers_list_facade param_liste
|
||||||
dossiers_list_facade.service.change_sort! param_sort unless params[:dossiers_smart_listing].nil?
|
dossiers_list_facade.service.change_sort! param_sort unless param_smart_listing.nil?
|
||||||
|
dossiers_list_facade.service.change_page! param_page
|
||||||
|
|
||||||
smartlisting_dossier
|
smartlisting_dossier
|
||||||
end
|
end
|
||||||
|
@ -31,12 +32,8 @@ class Backoffice::DossiersListController < ApplicationController
|
||||||
dossiers_list_facade liste
|
dossiers_list_facade liste
|
||||||
dossiers_list = dossiers_list_facade.dossiers_to_display if dossiers_list.nil?
|
dossiers_list = dossiers_list_facade.dossiers_to_display if dossiers_list.nil?
|
||||||
|
|
||||||
if params[:dossiers_smart_listing].nil? || params[:dossiers_smart_listing][:page].nil?
|
if param_page.nil?
|
||||||
pref = current_gestionnaire.preference_smart_listing_page
|
params[:dossiers_smart_listing] = {page: dossiers_list_facade.service.default_page}
|
||||||
|
|
||||||
if pref.liste == liste && pref.procedure_id == dossiers_list_facade.procedure_id
|
|
||||||
params[:dossiers_smart_listing] = {page: pref.page.to_s}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@dossiers = smart_listing_create :dossiers,
|
@dossiers = smart_listing_create :dossiers,
|
||||||
|
@ -48,8 +45,19 @@ class Backoffice::DossiersListController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def param_smart_listing
|
||||||
|
params[:dossiers_smart_listing]
|
||||||
|
end
|
||||||
|
|
||||||
|
def param_page
|
||||||
|
unless param_smart_listing.nil?
|
||||||
|
return 1 if params[:dossiers_smart_listing][:page].blank?
|
||||||
|
params[:dossiers_smart_listing][:page]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def param_sort
|
def param_sort
|
||||||
params[:dossiers_smart_listing][:sort]
|
params[:dossiers_smart_listing][:sort] unless param_smart_listing.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def param_filter
|
def param_filter
|
||||||
|
|
|
@ -6,4 +6,6 @@ class PreferenceSmartListingPage < ActiveRecord::Base
|
||||||
validates :liste, presence: true, allow_blank: false, allow_nil: false
|
validates :liste, presence: true, allow_blank: false, allow_nil: false
|
||||||
validates :procedure, presence: true, allow_blank: true, allow_nil: true
|
validates :procedure, presence: true, allow_blank: true, allow_nil: true
|
||||||
validates :gestionnaire, presence: true, allow_blank: false, allow_nil: false
|
validates :gestionnaire, presence: true, allow_blank: false, allow_nil: false
|
||||||
|
|
||||||
|
validates_uniqueness_of :gestionnaire_id
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,6 +68,32 @@ class DossiersListGestionnaireService
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default_page
|
||||||
|
pref = current_preference_smart_listing_page
|
||||||
|
return pref.page if pref.procedure == @procedure && pref.liste == @liste
|
||||||
|
|
||||||
|
1
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_page! new_page
|
||||||
|
pref = current_preference_smart_listing_page
|
||||||
|
|
||||||
|
unless pref.liste == @liste && pref.procedure == @procedure
|
||||||
|
pref.liste = @liste
|
||||||
|
pref.procedure = @procedure
|
||||||
|
|
||||||
|
if new_page.nil?
|
||||||
|
pref.page = 1
|
||||||
|
pref.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
unless new_page.nil?
|
||||||
|
pref.page = new_page
|
||||||
|
pref.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def change_sort! new_sort
|
def change_sort! new_sort
|
||||||
return if new_sort.blank?
|
return if new_sort.blank?
|
||||||
|
|
||||||
|
@ -137,4 +163,8 @@ class DossiersListGestionnaireService
|
||||||
.where.not(filter: nil)
|
.where.not(filter: nil)
|
||||||
.order(:id)
|
.order(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_preference_smart_listing_page
|
||||||
|
@current_devise_profil.preference_smart_listing_page
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,26 @@
|
||||||
class CreatePreferenceSmartListingPage < ActiveRecord::Migration
|
class CreatePreferenceSmartListingPage < ActiveRecord::Migration
|
||||||
|
class Gestionnaire < ActiveRecord::Base
|
||||||
|
has_one :preference_smart_listing_page, dependent: :destroy
|
||||||
|
|
||||||
|
def build_default_preferences_smart_listing_page
|
||||||
|
PreferenceSmartListingPage.create(page: 1, procedure: nil, gestionnaire: self, liste: 'a_traiter')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class PreferenceSmartListingPage < ActiveRecord::Base
|
||||||
|
belongs_to :gestionnaire
|
||||||
|
belongs_to :procedure
|
||||||
|
|
||||||
|
validates :page, presence: true, allow_blank: false, allow_nil: false
|
||||||
|
validates :liste, presence: true, allow_blank: false, allow_nil: false
|
||||||
|
validates :procedure, presence: true, allow_blank: true, allow_nil: true
|
||||||
|
validates :gestionnaire, presence: true, allow_blank: false, allow_nil: false
|
||||||
|
|
||||||
|
validates_uniqueness_of :gestionnaire_id
|
||||||
|
end
|
||||||
|
|
||||||
def change
|
def change
|
||||||
create_table :preference_smart_listing_pages, id: false do |t|
|
create_table :preference_smart_listing_pages do |t|
|
||||||
t.string :liste
|
t.string :liste
|
||||||
t.integer :page
|
t.integer :page
|
||||||
end
|
end
|
||||||
|
@ -8,6 +28,8 @@ class CreatePreferenceSmartListingPage < ActiveRecord::Migration
|
||||||
add_belongs_to :preference_smart_listing_pages, :procedure
|
add_belongs_to :preference_smart_listing_pages, :procedure
|
||||||
add_belongs_to :preference_smart_listing_pages, :gestionnaire
|
add_belongs_to :preference_smart_listing_pages, :gestionnaire
|
||||||
|
|
||||||
add_index :preference_smart_listing_pages, :gestionnaire_id, unique: true
|
Gestionnaire.all.each do |gestionnaire|
|
||||||
|
gestionnaire.build_default_preferences_smart_listing_page if gestionnaire.preference_smart_listing_page.nil?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
class BuildDefaultPreferenceSmartListingPageForAllGestionnaire < ActiveRecord::Migration
|
|
||||||
class Gestionnaire < ActiveRecord::Base
|
|
||||||
has_one :preference_smart_listing_page, dependent: :destroy
|
|
||||||
|
|
||||||
def build_default_preferences_smart_listing_page
|
|
||||||
PreferenceSmartListingPage.create(page: 1, procedure: nil, gestionnaire: self, liste: 'a_traiter')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class PreferenceSmartListingPage < ActiveRecord::Base
|
|
||||||
belongs_to :gestionnaire
|
|
||||||
belongs_to :procedure
|
|
||||||
|
|
||||||
validates :page, presence: true, allow_blank: false, allow_nil: false
|
|
||||||
validates :liste, presence: true, allow_blank: false, allow_nil: false
|
|
||||||
validates :procedure, presence: true, allow_blank: true, allow_nil: true
|
|
||||||
validates :gestionnaire, presence: true, allow_blank: false, allow_nil: false
|
|
||||||
end
|
|
||||||
|
|
||||||
def change
|
|
||||||
Gestionnaire.all.each do |gestionnaire|
|
|
||||||
gestionnaire.build_default_preferences_smart_listing_page if gestionnaire.preference_smart_listing_page.nil?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20161011132750) do
|
ActiveRecord::Schema.define(version: 20161011125345) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -269,15 +269,13 @@ ActiveRecord::Schema.define(version: 20161011132750) do
|
||||||
t.integer "procedure_id"
|
t.integer "procedure_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "preference_smart_listing_pages", id: false, force: :cascade do |t|
|
create_table "preference_smart_listing_pages", force: :cascade do |t|
|
||||||
t.string "liste"
|
t.string "liste"
|
||||||
t.integer "page"
|
t.integer "page"
|
||||||
t.integer "procedure_id"
|
t.integer "procedure_id"
|
||||||
t.integer "gestionnaire_id"
|
t.integer "gestionnaire_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "preference_smart_listing_pages", ["gestionnaire_id"], name: "index_preference_smart_listing_pages_on_gestionnaire_id", unique: true, using: :btree
|
|
||||||
|
|
||||||
create_table "procedure_paths", force: :cascade do |t|
|
create_table "procedure_paths", force: :cascade do |t|
|
||||||
t.string "path", limit: 30
|
t.string "path", limit: 30
|
||||||
t.integer "procedure_id"
|
t.integer "procedure_id"
|
||||||
|
|
|
@ -2,9 +2,10 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe DossiersListGestionnaireService do
|
describe DossiersListGestionnaireService do
|
||||||
let(:gestionnaire) { create :gestionnaire }
|
let(:gestionnaire) { create :gestionnaire }
|
||||||
|
let(:preference_smart_listing_page) { gestionnaire.preference_smart_listing_page }
|
||||||
let(:liste) { 'a_traiter' }
|
let(:liste) { 'a_traiter' }
|
||||||
let(:dossier) { create :dossier }
|
let(:dossier) { create :dossier }
|
||||||
let(:accompagnateur_service) { AccompagnateurService.new gestionnaire, procedure, 'assign'}
|
let(:accompagnateur_service) { AccompagnateurService.new gestionnaire, procedure, 'assign' }
|
||||||
|
|
||||||
describe '#default_sort' do
|
describe '#default_sort' do
|
||||||
let(:procedure) { dossier.procedure }
|
let(:procedure) { dossier.procedure }
|
||||||
|
@ -137,7 +138,7 @@ describe DossiersListGestionnaireService do
|
||||||
|
|
||||||
subject { DossiersListGestionnaireService.new(gestionnaire, liste, nil).where_filter }
|
subject { DossiersListGestionnaireService.new(gestionnaire, liste, nil).where_filter }
|
||||||
|
|
||||||
it { is_expected.to eq "id LIKE '%23%' AND entreprises.raison_sociale LIKE '%plop%'" }
|
it { is_expected.to eq "CAST(dossiers.id as TEXT) LIKE '%23%' AND CAST(entreprises.raison_sociale as TEXT) LIKE '%plop%'" }
|
||||||
|
|
||||||
context 'when last filter caractere is *' do
|
context 'when last filter caractere is *' do
|
||||||
|
|
||||||
|
@ -147,7 +148,7 @@ describe DossiersListGestionnaireService do
|
||||||
.update_column :filter, 'plop*'
|
.update_column :filter, 'plop*'
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq "id LIKE '%23%' AND entreprises.raison_sociale LIKE 'plop%'" }
|
it { is_expected.to eq "CAST(dossiers.id as TEXT) LIKE '%23%' AND CAST(entreprises.raison_sociale as TEXT) LIKE 'plop%'" }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when first filter caractere is *' do
|
context 'when first filter caractere is *' do
|
||||||
|
@ -157,7 +158,7 @@ describe DossiersListGestionnaireService do
|
||||||
.update_column :filter, '*23'
|
.update_column :filter, '*23'
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq "id LIKE '%23' AND entreprises.raison_sociale LIKE '%plop%'" }
|
it { is_expected.to eq "CAST(dossiers.id as TEXT) LIKE '%23' AND CAST(entreprises.raison_sociale as TEXT) LIKE '%plop%'" }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when * caractere is presente' do
|
context 'when * caractere is presente' do
|
||||||
|
@ -167,7 +168,109 @@ describe DossiersListGestionnaireService do
|
||||||
.update_column :filter, 'plop*plip'
|
.update_column :filter, 'plop*plip'
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq "id LIKE '%23%' AND entreprises.raison_sociale LIKE 'plop%plip'" }
|
it { is_expected.to eq "CAST(dossiers.id as TEXT) LIKE '%23%' AND CAST(entreprises.raison_sociale as TEXT) LIKE 'plop%plip'" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#default_page' do
|
||||||
|
let(:page) { 2 }
|
||||||
|
let(:procedure) { nil }
|
||||||
|
|
||||||
|
before do
|
||||||
|
preference_smart_listing_page.update page: page, liste: 'a_traiter'
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { described_class.new(gestionnaire, liste, procedure).default_page }
|
||||||
|
|
||||||
|
context 'when liste and procedure match with the actual preference' do
|
||||||
|
let(:liste) { 'a_traiter' }
|
||||||
|
|
||||||
|
it { is_expected.to eq 2 }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when liste and procedure does not match with the actual preference' do
|
||||||
|
let(:liste) { 'en_attente' }
|
||||||
|
|
||||||
|
it { is_expected.to eq 1 }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#change_page!' do
|
||||||
|
let(:procedure) { nil }
|
||||||
|
let(:liste) { 'a_traiter' }
|
||||||
|
|
||||||
|
let(:page) { 2 }
|
||||||
|
let(:new_page) { 1 }
|
||||||
|
|
||||||
|
before do
|
||||||
|
preference_smart_listing_page.update page: page, liste: 'a_traiter', procedure: nil
|
||||||
|
subject
|
||||||
|
preference_smart_listing_page.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { described_class.new(gestionnaire, liste, procedure).change_page! new_page }
|
||||||
|
|
||||||
|
context 'when liste and procedure does not change' do
|
||||||
|
it { expect(preference_smart_listing_page.liste).to eq liste }
|
||||||
|
it { expect(preference_smart_listing_page.procedure).to eq procedure }
|
||||||
|
it { expect(preference_smart_listing_page.page).to eq new_page }
|
||||||
|
|
||||||
|
context 'when new_page is nil' do
|
||||||
|
let(:new_page) { nil }
|
||||||
|
|
||||||
|
it { expect(preference_smart_listing_page.liste).to eq liste }
|
||||||
|
it { expect(preference_smart_listing_page.procedure).to eq procedure }
|
||||||
|
it { expect(preference_smart_listing_page.page).to eq page }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when liste change' do
|
||||||
|
let(:liste) { 'en_attente' }
|
||||||
|
|
||||||
|
it { expect(preference_smart_listing_page.liste).to eq liste }
|
||||||
|
it { expect(preference_smart_listing_page.procedure).to eq procedure }
|
||||||
|
it { expect(preference_smart_listing_page.page).to eq new_page }
|
||||||
|
|
||||||
|
context 'when new_page is nil' do
|
||||||
|
let(:new_page) { nil }
|
||||||
|
|
||||||
|
it { expect(preference_smart_listing_page.liste).to eq liste }
|
||||||
|
it { expect(preference_smart_listing_page.procedure).to eq procedure }
|
||||||
|
it { expect(preference_smart_listing_page.page).to eq 1 }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when procedure change' do
|
||||||
|
let(:procedure) { dossier.procedure }
|
||||||
|
|
||||||
|
it { expect(preference_smart_listing_page.liste).to eq liste }
|
||||||
|
it { expect(preference_smart_listing_page.procedure).to eq procedure }
|
||||||
|
it { expect(preference_smart_listing_page.page).to eq new_page }
|
||||||
|
|
||||||
|
context 'when new_page is nil' do
|
||||||
|
let(:new_page) { nil }
|
||||||
|
|
||||||
|
it { expect(preference_smart_listing_page.liste).to eq liste }
|
||||||
|
it { expect(preference_smart_listing_page.procedure).to eq procedure }
|
||||||
|
it { expect(preference_smart_listing_page.page).to eq 1 }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when procedure and liste change' do
|
||||||
|
let(:liste) { 'en_attente' }
|
||||||
|
let(:procedure) { dossier.procedure }
|
||||||
|
|
||||||
|
it { expect(preference_smart_listing_page.liste).to eq liste }
|
||||||
|
it { expect(preference_smart_listing_page.procedure).to eq procedure }
|
||||||
|
it { expect(preference_smart_listing_page.page).to eq new_page }
|
||||||
|
|
||||||
|
context 'when new_page is nil' do
|
||||||
|
let(:new_page) { nil }
|
||||||
|
|
||||||
|
it { expect(preference_smart_listing_page.liste).to eq liste }
|
||||||
|
it { expect(preference_smart_listing_page.procedure).to eq procedure }
|
||||||
|
it { expect(preference_smart_listing_page.page).to eq 1 }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue