Merge pull request #150 from sgmap/fix-99

[Fix #99] Improve the info message in _dossier_link.html.haml
This commit is contained in:
gregoirenovel 2017-04-26 16:51:37 +02:00 committed by GitHub
commit f1530d9a05
5 changed files with 17 additions and 19 deletions

View file

@ -5,7 +5,7 @@
};
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-warning').hide();
};
@ -18,7 +18,7 @@
var fetchProcedureLibelle = function(e) {
var dossierId = $(e.target).val();
if(dossierId) {
$.get('/users/dossiers/' + dossierId + '/procedure_libelle')
$.get('/users/dossiers/' + dossierId + '/text_summary')
.done(showData)
.fail(showNotFound);
} else {

View file

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

View file

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

View file

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

View file

@ -554,27 +554,27 @@ describe Users::DossiersController, type: :controller do
end
end
describe 'Get #procedure_libelle' do
describe 'Get #text_summary' do
let!(:dossier) { create(:dossier, procedure: procedure) }
context 'when user is connected' do
before { sign_in user }
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
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
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') }
end
end
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') }
end
end