diff --git a/app/controllers/backoffice/dossiers_list_controller.rb b/app/controllers/backoffice/dossiers_list_controller.rb index 2797203ea..535056b0c 100644 --- a/app/controllers/backoffice/dossiers_list_controller.rb +++ b/app/controllers/backoffice/dossiers_list_controller.rb @@ -13,7 +13,8 @@ class Backoffice::DossiersListController < ApplicationController end 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 end @@ -31,6 +32,10 @@ class Backoffice::DossiersListController < ApplicationController dossiers_list_facade liste dossiers_list = dossiers_list_facade.dossiers_to_display if dossiers_list.nil? + if param_page.nil? + params[:dossiers_smart_listing] = {page: dossiers_list_facade.service.default_page} + end + @dossiers = smart_listing_create :dossiers, dossiers_list, partial: "backoffice/dossiers/list", @@ -40,8 +45,19 @@ class Backoffice::DossiersListController < ApplicationController 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 - params[:dossiers_smart_listing][:sort] + params[:dossiers_smart_listing][:sort] unless param_smart_listing.nil? end def param_filter diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index dda64ec19..8696d16f1 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -4,6 +4,8 @@ class Gestionnaire < ActiveRecord::Base has_and_belongs_to_many :administrateurs + has_one :preference_smart_listing_page, dependent: :destroy + has_many :assign_to, dependent: :destroy has_many :procedures, through: :assign_to has_many :dossiers, through: :procedures @@ -11,6 +13,7 @@ class Gestionnaire < ActiveRecord::Base has_many :preference_list_dossiers after_create :build_default_preferences_list_dossier + after_create :build_default_preferences_smart_listing_page def dossiers_follow dossiers.joins(:follows).where("follows.gestionnaire_id = #{id}") @@ -55,6 +58,10 @@ class Gestionnaire < ActiveRecord::Base end end + def build_default_preferences_smart_listing_page + PreferenceSmartListingPage.create(page: 1, procedure: nil, gestionnaire: self, liste: 'a_traiter') + end + private def valid_couple_table_attr? table, column diff --git a/app/models/preference_smart_listing_page.rb b/app/models/preference_smart_listing_page.rb new file mode 100644 index 000000000..295a85a1a --- /dev/null +++ b/app/models/preference_smart_listing_page.rb @@ -0,0 +1,11 @@ +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 diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index bd4ea1c41..5ed7a7419 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -68,6 +68,32 @@ class DossiersListGestionnaireService } 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 return if new_sort.blank? @@ -137,4 +163,8 @@ class DossiersListGestionnaireService .where.not(filter: nil) .order(:id) end + + def current_preference_smart_listing_page + @current_devise_profil.preference_smart_listing_page + end end \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb index a40a9c2b6..811373464 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -11,11 +11,10 @@ require 'mina/rbenv' # for rbenv support. (http://rbenv.org) # branch - Branch name to deploy. (needed by mina/git) ENV['to'] ||= "staging" -ENV['to'] = "staging" unless ["staging", "production"].include?(ENV['to']) +ENV['to'] = "staging" unless ["staging", "production", "opensimplif"].include?(ENV['to']) raise "missing domain, run with 'rake deploy domain=37.187.154.237'" if ENV['domain'].nil? - print "Deploy to #{ENV['to']} environment branch #{branch}\n" # set :domain, '5.135.190.60' @@ -25,7 +24,6 @@ set :port, 2200 set :deploy_to, '/var/www/tps_dev' - if ENV["to"] == "staging" if ENV['branch'].nil? set :branch, 'staging' @@ -44,10 +42,24 @@ elsif ENV["to"] == "production" set :deploy_to, '/var/www/tps' set :user, 'tps' # Username in the server to SSH to. appname = 'tps' +elsif ENV["to"] == "opensimplif" + if ENV['branch'].nil? + set :branch, 'master' + else + set :branch, ENV['branch'] + end + set :deploy_to, '/var/www/opensimplif' + set :user, 'opensimplif' # Username in the server to SSH to. + appname = 'opensimplif' end set :rails_env, ENV["to"] + +if ENV["to"] == "opensimplif" + set :rails_env, "production" +end + # For system-wide RVM install. # set :rvm_path, '/usr/local/rvm/bin/rvm' @@ -66,7 +78,7 @@ set :shared_paths, [ "config/fog_credentials.yml", 'config/initializers/secret_token.rb', 'config/initializers/features.yml', - "config/environments/#{ENV['to']}.rb", + "config/environments/#{rails_env}.rb", "config/initializers/token.rb", "config/initializers/urls.rb", "config/initializers/super_admin.rb", @@ -74,7 +86,8 @@ set :shared_paths, [ "config/initializers/raven.rb", 'config/france_connect.yml', 'config/initializers/mailjet.rb', - 'config/initializers/storage_url.rb' + 'config/initializers/storage_url.rb', + 'app/views/root/landing.html.haml' ] @@ -112,6 +125,9 @@ task :setup => :environment do queue! %[mkdir -p "#{deploy_to}/shared/config"] queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"] + queue! %[mkdir -p "#{deploy_to}/shared/app"] + queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/app"] + queue! %[touch "#{deploy_to}/shared/config/database.yml"] queue %[echo "-----> Be sure to edit 'shared/config/database.yml'."] diff --git a/db/migrate/20161011125345_create_preference_smart_listing_page.rb b/db/migrate/20161011125345_create_preference_smart_listing_page.rb new file mode 100644 index 000000000..510cfc156 --- /dev/null +++ b/db/migrate/20161011125345_create_preference_smart_listing_page.rb @@ -0,0 +1,35 @@ +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 + create_table :preference_smart_listing_pages do |t| + t.string :liste + t.integer :page + end + + add_belongs_to :preference_smart_listing_pages, :procedure + add_belongs_to :preference_smart_listing_pages, :gestionnaire + + Gestionnaire.all.each do |gestionnaire| + gestionnaire.build_default_preferences_smart_listing_page if gestionnaire.preference_smart_listing_page.nil? + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3b3ca3b73..17762a2b4 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: 20161007095443) do +ActiveRecord::Schema.define(version: 20161011125345) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -269,6 +269,13 @@ ActiveRecord::Schema.define(version: 20161007095443) do t.integer "procedure_id" end + create_table "preference_smart_listing_pages", force: :cascade do |t| + t.string "liste" + t.integer "page" + t.integer "procedure_id" + t.integer "gestionnaire_id" + end + create_table "procedure_paths", force: :cascade do |t| t.string "path", limit: 30 t.integer "procedure_id" diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index dc5841a82..8ab20339f 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -28,6 +28,7 @@ describe Gestionnaire, type: :model do end describe 'association' do + it { is_expected.to have_one(:preference_smart_listing_page) } it { is_expected.to have_and_belong_to_many(:administrateurs) } it { is_expected.to have_many(:procedures) } it { is_expected.to have_many(:dossiers) } @@ -161,4 +162,26 @@ describe Gestionnaire, type: :model do end end end + + describe '#build_default_preferences_smart_listing_page' do + subject { gestionnaire.preference_smart_listing_page } + + context 'when gestionnaire is created' do + it 'build page column' do + expect(subject.page).to eq 1 + end + + it 'build liste column' do + expect(subject.liste).to eq 'a_traiter' + end + + it 'build procedure_id column' do + expect(subject.procedure).to eq nil + end + + it 'build gestionnaire column' do + expect(subject.gestionnaire).to eq gestionnaire + end + end + end end diff --git a/spec/models/preference_smart_listing_page_spec.rb b/spec/models/preference_smart_listing_page_spec.rb new file mode 100644 index 000000000..e5c673d9c --- /dev/null +++ b/spec/models/preference_smart_listing_page_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe PreferenceSmartListingPage do + it { is_expected.to have_db_column(:page) } + it { is_expected.to have_db_column(:liste) } + it { is_expected.to have_db_column(:procedure_id) } + + it { is_expected.to belong_to(:gestionnaire) } + it { is_expected.to belong_to(:procedure) } +end diff --git a/spec/services/dossiers_list_gestionnaire_service_spec.rb b/spec/services/dossiers_list_gestionnaire_service_spec.rb index 9c4c6b700..104f9f0ab 100644 --- a/spec/services/dossiers_list_gestionnaire_service_spec.rb +++ b/spec/services/dossiers_list_gestionnaire_service_spec.rb @@ -2,9 +2,10 @@ require 'spec_helper' describe DossiersListGestionnaireService do let(:gestionnaire) { create :gestionnaire } + let(:preference_smart_listing_page) { gestionnaire.preference_smart_listing_page } let(:liste) { 'a_traiter' } let(:dossier) { create :dossier } - let(:accompagnateur_service) { AccompagnateurService.new gestionnaire, procedure, 'assign'} + let(:accompagnateur_service) { AccompagnateurService.new gestionnaire, procedure, 'assign' } describe '#default_sort' do let(:procedure) { dossier.procedure } @@ -137,7 +138,7 @@ describe DossiersListGestionnaireService do 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 @@ -147,7 +148,7 @@ describe DossiersListGestionnaireService do .update_column :filter, 'plop*' 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 context 'when first filter caractere is *' do @@ -157,7 +158,7 @@ describe DossiersListGestionnaireService do .update_column :filter, '*23' 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 context 'when * caractere is presente' do @@ -167,7 +168,109 @@ describe DossiersListGestionnaireService do .update_column :filter, 'plop*plip' 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