Adapt search function at the PreferenceListDossier table
This commit is contained in:
parent
7c2bcd0b64
commit
ac971a805e
9 changed files with 37 additions and 81 deletions
|
@ -27,18 +27,12 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
|
||||
def search
|
||||
@search_terms = params[:q]
|
||||
@dossiers_search, @dossier = Dossier.search(current_gestionnaire, @search_terms)
|
||||
@dossier = Dossier.search(current_gestionnaire, @search_terms)
|
||||
|
||||
dossiers_list_facade
|
||||
|
||||
unless @dossiers_search.empty?
|
||||
@dossiers_search = @dossiers_search.paginate(:page => params[:page]).decorate
|
||||
end
|
||||
|
||||
@dossier = @dossier.decorate unless @dossier.nil?
|
||||
smartlisting_dossier @dossier, 'search'
|
||||
|
||||
rescue RuntimeError
|
||||
@dossiers_search = []
|
||||
smartlisting_dossier [], 'search'
|
||||
end
|
||||
|
||||
def valid
|
||||
|
|
|
@ -22,9 +22,12 @@ class Backoffice::DossiersListController < ApplicationController
|
|||
@dossiers_list_facade ||= DossiersListFacades.new current_gestionnaire, liste, retrieve_procedure
|
||||
end
|
||||
|
||||
def smartlisting_dossier
|
||||
def smartlisting_dossier dossiers_list=nil, liste='a_traiter'
|
||||
dossiers_list_facade liste
|
||||
dossiers_list = dossiers_list_facade.dossiers_to_display if dossiers_list.nil?
|
||||
|
||||
@dossiers = smart_listing_create :dossiers,
|
||||
dossiers_list_facade.dossiers_to_display,
|
||||
dossiers_list,
|
||||
partial: "backoffice/dossiers/list",
|
||||
array: true,
|
||||
default_sort: dossiers_list_facade.service.default_sort
|
||||
|
|
|
@ -79,6 +79,10 @@ class DossiersListFacades
|
|||
(@liste == 'invite' ? 'active' : '')
|
||||
end
|
||||
|
||||
def search_class
|
||||
(@liste == 'search' ? 'active' : '')
|
||||
end
|
||||
|
||||
def brouillon_total
|
||||
service.brouillon.count
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ class Dossier < ActiveRecord::Base
|
|||
enum state: {draft: 'draft',
|
||||
initiated: 'initiated',
|
||||
replied: 'replied', #action utilisateur demandé
|
||||
updated: 'updated',#etude par l'administration en cours
|
||||
updated: 'updated', #etude par l'administration en cours
|
||||
validated: 'validated',
|
||||
submitted: 'submitted',
|
||||
received: 'received',
|
||||
|
@ -246,7 +246,7 @@ class Dossier < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.search current_gestionnaire, terms
|
||||
return [], nil if terms.blank?
|
||||
return [] if terms.blank?
|
||||
|
||||
dossiers = Dossier.arel_table
|
||||
users = User.arel_table
|
||||
|
@ -264,24 +264,16 @@ class Dossier < ActiveRecord::Base
|
|||
composed_scope = composed_scope.where(
|
||||
users[:email].matches(query_string).or\
|
||||
etablissements[:siret].matches(query_string_start_with).or\
|
||||
entreprises[:raison_sociale].matches(query_string))
|
||||
entreprises[:raison_sociale].matches(query_string).or\
|
||||
dossiers[:id].eq(word_is_an_integer word))
|
||||
end
|
||||
|
||||
#TODO refactor
|
||||
composed_scope = composed_scope.where(
|
||||
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.ids.include?(terms.to_i)
|
||||
dossier = Dossier.where("state != 'draft'").find(terms.to_i)
|
||||
end
|
||||
rescue ArgumentError, ActiveRecord::RecordNotFound
|
||||
dossier = nil
|
||||
end
|
||||
|
||||
return composed_scope, dossier
|
||||
composed_scope
|
||||
end
|
||||
|
||||
def cerfa_available?
|
||||
|
@ -290,8 +282,8 @@ class Dossier < ActiveRecord::Base
|
|||
|
||||
def as_csv(options={})
|
||||
dossier_attr = DossierSerializer.new(self).attributes
|
||||
etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map {|k, v| ["etablissement.#{k}", v] }.to_h
|
||||
entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map {|k, v| ["entreprise.#{k}", v] }.to_h
|
||||
etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}", v] }.to_h
|
||||
entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map { |k, v| ["entreprise.#{k}", v] }.to_h
|
||||
dossier_attr.merge(etablissement_attr).merge(entreprise_attr)
|
||||
end
|
||||
|
||||
|
@ -316,7 +308,7 @@ class Dossier < ActiveRecord::Base
|
|||
next_step! 'user', 'submit'
|
||||
NotificationMailer.dossier_submitted(self).deliver_now!
|
||||
end
|
||||
|
||||
|
||||
def read_only?
|
||||
validated? || received? || submitted? || closed? || refused? || without_continuation?
|
||||
end
|
||||
|
@ -328,4 +320,12 @@ class Dossier < ActiveRecord::Base
|
|||
def invite_by_user? email
|
||||
(invites_user.pluck :email).include? email
|
||||
end
|
||||
|
||||
def self.word_is_an_integer word
|
||||
return 0 if Float(word) > 2147483647
|
||||
|
||||
Float(word)
|
||||
rescue ArgumentError
|
||||
0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
=@dossiers_list_facade.termine_total
|
||||
|
||||
%ul.nav.nav-tabs.navbar-right{style:'border-bottom: none;'}
|
||||
%li#search{class: "#{'active' unless @dossiers_search.nil?}"}
|
||||
%li#search{ class: (@dossiers_list_facade.search_class) }
|
||||
%a
|
||||
= form_tag(backoffice_dossiers_search_url, method: :get) do
|
||||
.input-group{style:'width: 300px'}
|
||||
|
|
|
@ -1,45 +1,4 @@
|
|||
#backoffice_search
|
||||
= render partial: 'onglets'
|
||||
|
||||
- unless @dossier.nil?
|
||||
%table.table{style:'background-color: rgba(248, 248, 255, 0.8)'}
|
||||
%tr
|
||||
%th{colspan:2}
|
||||
%h4
|
||||
= "Dossier N°#{@dossier.id}"
|
||||
%tr
|
||||
%td.col-md-1.col-lg-1
|
||||
= @dossier.id
|
||||
%td.col-md-4.col-lg-4
|
||||
= @dossier.procedure.libelle
|
||||
%td.col-md-4.col-lg-4
|
||||
= link_to(@dossier.entreprise.raison_sociale, "/backoffice/dossiers/#{@dossier.id}")
|
||||
%td.col-md-2.col-lg-2
|
||||
= @dossier.user.email
|
||||
%td.col-md-1.col-lg-1{class: @dossier.state_color_class}
|
||||
= @dossier.display_state
|
||||
%br
|
||||
|
||||
- if @dossiers_search.empty? && @dossier.nil?
|
||||
%div{style: 'text-align:center'}
|
||||
%h4 Aucun dossier trouvé
|
||||
|
||||
- elsif !@dossiers_search.empty?
|
||||
%table.table
|
||||
%tr
|
||||
%th.col-md-1.col-lg-1 ID dossier
|
||||
%th.col-md-4.col-lg-4 Procédure
|
||||
%th.col-md-4.col-lg-4 Raison Sociale
|
||||
%th.col-md-2.col-lg-2 Email contact
|
||||
%th.col-md-1.col-lg-1 État
|
||||
|
||||
- @dossiers_search.each do |dossier|
|
||||
%tr
|
||||
%td= dossier.id
|
||||
%td= dossier.procedure.libelle
|
||||
%td= link_to(dossier.entreprise.raison_sociale, "/backoffice/dossiers/#{dossier.id}")
|
||||
%td= dossier.user.email
|
||||
%td{class: dossier.state_color_class}= dossier.display_state
|
||||
|
||||
.pagination
|
||||
= will_paginate @dossiers_search, renderer: BootstrapPagination::Rails
|
||||
= smart_listing_render :dossiers
|
|
@ -24,7 +24,7 @@ feature 'search file on gestionnaire backoffice' do
|
|||
it { expect(page).to have_css('#backoffice_search') }
|
||||
|
||||
context 'when terms input is empty' do
|
||||
it { expect(page).to have_content('Aucun dossier trouvé') }
|
||||
it { expect(page).to have_content('Aucun dossier') }
|
||||
end
|
||||
|
||||
context 'when terms input is informed' do
|
||||
|
@ -35,7 +35,7 @@ feature 'search file on gestionnaire backoffice' do
|
|||
end
|
||||
|
||||
context 'when terms input does not return result' do
|
||||
it { expect(page).to have_content('Aucun dossier trouvé') }
|
||||
it { expect(page).to have_content('Aucun dossier') }
|
||||
end
|
||||
|
||||
context 'when terms input does return result' do
|
||||
|
@ -45,12 +45,6 @@ feature 'search file on gestionnaire backoffice' do
|
|||
let(:terms) { dossier.entreprise.raison_sociale }
|
||||
|
||||
it { expect(page).to have_content(dossier.entreprise.raison_sociale) }
|
||||
|
||||
context "when terms is a file's id" do
|
||||
let(:terms) { dossier.id }
|
||||
|
||||
it { expect(page).to have_content("Dossier N°#{dossier.id}") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -559,8 +559,8 @@ describe Dossier do
|
|||
describe '.search' do
|
||||
subject { liste_dossiers }
|
||||
|
||||
let(:liste_dossiers) { described_class.search(gestionnaire_1, terms)[0] }
|
||||
let(:dossier) { described_class.search(gestionnaire_1, terms)[1] }
|
||||
let(:liste_dossiers) { described_class.search(gestionnaire_1, terms) }
|
||||
# let(:dossier) { described_class.search(gestionnaire_1, terms)[1] }
|
||||
|
||||
let(:administrateur_1) { create(:administrateur) }
|
||||
let(:administrateur_2) { create(:administrateur) }
|
||||
|
@ -596,6 +596,7 @@ describe Dossier do
|
|||
let(:terms) { 'brouillon' }
|
||||
|
||||
it { expect(subject.size).to eq(0) }
|
||||
it { expect(subject.class).to eq Dossier::ActiveRecord_Relation }
|
||||
end
|
||||
|
||||
describe 'search on contact email' do
|
||||
|
@ -607,7 +608,7 @@ describe Dossier do
|
|||
describe 'search on ID dossier' do
|
||||
let(:terms) { "#{dossier_2.id}" }
|
||||
|
||||
it { expect(dossier.id).to eq(dossier_2.id) }
|
||||
it { expect(subject.size).to eq(1) }
|
||||
end
|
||||
|
||||
describe 'search on SIRET' do
|
||||
|
|
|
@ -60,6 +60,7 @@ end
|
|||
DatabaseCleaner.strategy = :truncation
|
||||
|
||||
SIADETOKEN = :valid_token unless defined? SIADETOKEN
|
||||
BROWSER.value = Browser.new('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)')
|
||||
|
||||
include Warden::Test::Helpers
|
||||
|
||||
|
|
Loading…
Reference in a new issue