[Fix #99] Improve the info message in _dossier_link.html.haml

This commit is contained in:
gregoirenovel 2017-04-26 16:15:48 +02:00
parent d596dbfd1b
commit f58a626648
5 changed files with 17 additions and 19 deletions

View file

@ -5,7 +5,7 @@
}; };
var showData = function(data) { var showData = function(data) {
$('.dossier-link .procedure-libelle').text(data.procedureLibelle); $('.dossier-link .dossier-text-summary').text(data.textSummary);
$('.dossier-link .text-info').show(); $('.dossier-link .text-info').show();
$('.dossier-link .text-warning').hide(); $('.dossier-link .text-warning').hide();
}; };
@ -18,7 +18,7 @@
var fetchProcedureLibelle = function(e) { var fetchProcedureLibelle = function(e) {
var dossierId = $(e.target).val(); var dossierId = $(e.target).val();
if(dossierId) { if(dossierId) {
$.get('/users/dossiers/' + dossierId + '/procedure_libelle') $.get('/users/dossiers/' + dossierId + '/text_summary')
.done(showData) .done(showData)
.fail(showNotFound); .fail(showNotFound);
} else { } else {

View file

@ -164,9 +164,9 @@ class Users::DossiersController < UsersController
redirect_to url_for users_dossiers_path redirect_to url_for users_dossiers_path
end end
def procedure_libelle def text_summary
dossier = Dossier.includes(:procedure).find(params[:dossier_id]) dossier = Dossier.find(params[:dossier_id])
render json: { procedureLibelle: dossier.procedure.libelle } render json: { textSummary: dossier.text_summary }
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render json: {}, status: 404 render json: {}, status: 404
end end

View file

@ -1,7 +1,7 @@
- dossier = Dossier.includes(:procedure).find_by(id: champ.value) - dossier = Dossier.find_by(id: champ.value)
- show_procedure_libelle = dossier ? true : false - show_text_summary = dossier.present?
- show_warning = !show_procedure_libelle && champ.value.present? - show_warning = !show_text_summary && champ.value.present?
- procedure_libelle = dossier.nil? ? '' : dossier.procedure.libelle - text_summary = dossier.try(:text_summary)
.dossier-link .dossier-link
%input.form-control{ name: "champs['#{ champ.id }']", %input.form-control{ name: "champs['#{ champ.id }']",
@ -13,10 +13,8 @@
'data-type' => 'dossier-link' } 'data-type' => 'dossier-link' }
.help-block .help-block
%p.text-info{ style: show_procedure_libelle ? nil : 'display: none;' } %p.text-info{ style: show_text_summary ? nil : 'display: none;' }
ce dossier répond à la procédure : %span.dossier-text-summary= text_summary
%br
%span.procedure-libelle= procedure_libelle
%p.text-warning{ style: show_warning ? nil : 'display: none;' } %p.text-warning{ style: show_warning ? nil : 'display: none;' }
Ce dossier est inconnu Ce dossier est inconnu

View file

@ -95,7 +95,7 @@ Rails.application.routes.draw do
post '/siret_informations' => 'dossiers#siret_informations' post '/siret_informations' => 'dossiers#siret_informations'
put '/change_siret' => 'dossiers#change_siret' put '/change_siret' => 'dossiers#change_siret'
get 'procedure_libelle' => 'dossiers#procedure_libelle' get 'text_summary' => 'dossiers#text_summary'
end end
resource :dossiers resource :dossiers
end end

View file

@ -554,27 +554,27 @@ describe Users::DossiersController, type: :controller do
end end
end end
describe 'Get #procedure_libelle' do describe 'Get #text_summary' do
let!(:dossier) { create(:dossier, procedure: procedure) } let!(:dossier) { create(:dossier, procedure: procedure) }
context 'when user is connected' do context 'when user is connected' do
before { sign_in user } before { sign_in user }
context 'when the dossier exist' do context 'when the dossier exist' do
before { get :procedure_libelle, params: { dossier_id: dossier.id } } before { get :text_summary, params: { dossier_id: dossier.id } }
it 'returns the procedure name' do it 'returns the procedure name' do
expect(JSON.parse(response.body)).to eq('procedureLibelle' => procedure.libelle) expect(JSON.parse(response.body)).to eq("textSummary" => "Dossier en brouillon répondant à la démarche #{procedure.libelle}, gérée par l'organisme #{procedure.organisation}")
end end
end end
context 'when the dossier does not exist' do context 'when the dossier does not exist' do
before { get :procedure_libelle, params: { dossier_id: 666 } } before { get :text_summary, params: { dossier_id: 666 } }
it { expect(response.code).to eq('404') } it { expect(response.code).to eq('404') }
end end
end end
context 'when user is not connected' do context 'when user is not connected' do
before { get :procedure_libelle, params: { dossier_id: dossier.id } } before { get :text_summary, params: { dossier_id: dossier.id } }
it { expect(response.code).to eq('302') } it { expect(response.code).to eq('302') }
end end
end end