Old recherche with new design

This commit is contained in:
Mathieu Magnin 2017-07-31 11:58:52 +02:00
parent c74bf5dd8f
commit bf97a111f9
5 changed files with 93 additions and 1 deletions

View file

@ -0,0 +1,23 @@
module NewGestionnaire
class RecherchesController < GestionnaireController
def index
@search_terms = params[:q]
# exact id match?
if @search_terms.to_i != 0
@dossiers = current_gestionnaire.dossiers.where(id: @search_terms.to_i)
end
@dossiers = Dossier.none if @dossiers.nil?
# full text search
if @dossiers.empty?
@dossiers = Search.new(
gestionnaire: current_gestionnaire,
query: @search_terms,
page: params[:page]
).results
end
end
end
end

View file

@ -14,7 +14,7 @@
- if gestionnaire_signed_in?
%li
.header-search
= form_tag backoffice_dossiers_search_url, method: :get, class: "form" do
= form_tag recherche_path, method: :get, class: "form" do
= text_field_tag "q", "#{@search_terms unless @search_terms.nil?}", placeholder: "Rechercher"
%button{ title: "Rechercher" }
= image_tag "icons/search-blue.svg"

View file

@ -0,0 +1,27 @@
.container
.backoffice-title
Résultat de la recherche :
= pluralize(@dossiers.count, "dossier trouvé", "dossiers trouvés")
- if @dossiers.present?
%table.table.dossiers-table.hoverable
%thead
%tr
%th Nº
%th Procédure
%th Demandeur
%th Statut
%tbody
- @dossiers.each do |dossier|
%tr
%td.number-col
= link_to(dossier_path(dossier.procedure, dossier), class: 'cell-link') do
%i.folder>
= dossier.id
%td= link_to(dossier.procedure.libelle, dossier_path(dossier.procedure, dossier), class: 'cell-link')
%td= link_to(dossier.user.email, dossier_path(dossier.procedure, dossier), class: 'cell-link')
%td.status-col
= link_to(dossier_path(dossier.procedure, dossier), class: 'cell-link') do
= render partial: 'new_gestionnaire/procedures/status', locals: { dossier: dossier }
- else
%h2 Aucun dossier correspondant à votre recherche n'a été trouvé

View file

@ -258,6 +258,7 @@ Rails.application.routes.draw do
end
end
end
get "recherche" => "recherches#index"
end
apipie

View file

@ -0,0 +1,41 @@
require 'spec_helper'
describe NewGestionnaire::RecherchesController, type: :controller do
let(:dossier) { create(:dossier, :replied) }
let(:dossier2) { create(:dossier, :replied, procedure: dossier.procedure) }
let(:gestionnaire) { create(:gestionnaire) }
before { gestionnaire.procedures << dossier2.procedure }
describe 'GET #index' do
before { sign_in gestionnaire }
subject { get :index, params: { q: query } }
describe 'by id' do
context 'when gestionnaire own the dossier' do
let(:query) { dossier.id }
it { is_expected.to have_http_status(200) }
it 'returns the expected dossier' do
subject
expect(assigns(:dossiers).count).to eq(1)
expect(assigns(:dossiers).first.id).to eq(dossier.id)
end
end
context 'when gestionnaire do not own the dossier' do
let(:dossier3) { create(:dossier, :replied) }
let(:query) { dossier3.id }
it { is_expected.to have_http_status(200) }
it 'does not return the dossier' do
subject
expect(assigns(:dossiers).count).to eq(0)
end
end
end
end
end