Merge pull request #52 from sgmap/champ_dossier

Champ dossier
This commit is contained in:
LeSim 2017-04-11 14:20:07 +02:00 committed by GitHub
commit 1c3db68886
11 changed files with 166 additions and 3 deletions

View file

@ -0,0 +1,36 @@
(function() {
var showNotFound = function() {
$('.dossier-link .text-info').hide();
$('.dossier-link .text-warning').show();
};
var showData = function(data) {
$('.dossier-link .procedureLibelle').text(data.procedureLibelle);
$('.dossier-link .text-info').show();
$('.dossier-link .text-warning').hide();
};
var hideEverything = function() {
$('.dossier-link .text-info').hide();
$('.dossier-link .text-warning').hide();
};
var fetchProcedureLibelle = function(e) {
var dossierId = $(e.target).val();
if(dossierId) {
$.get('/users/dossiers/' + dossierId + '/procedure_libelle')
.done(showData)
.fail(showNotFound);
} else {
hideEverything();
}
};
var timeOut = null;
var debounceFetchProcedureLibelle = function(e) {
if(timeOut){ clearTimeout(timeOut); }
timeOut = setTimeout(function() { fetchProcedureLibelle(e); }, 300);
};
$(document).on('input', '[data-type=dossier-link]', debounceFetchProcedureLibelle);
})();

View file

@ -154,6 +154,13 @@ class Users::DossiersController < UsersController
redirect_to url_for users_dossiers_path
end
def procedure_libelle
dossier = Dossier.find(params[:dossier_id])
render json: { procedureLibelle: dossier.procedure.libelle }
rescue ActiveRecord::RecordNotFound
render json: {}, status: 404
end
private
def check_siret

View file

@ -18,7 +18,8 @@ class TypeDeChamp < ActiveRecord::Base
departements: 'departements',
engagement: 'engagement',
header_section: 'header_section',
explication: 'explication'
explication: 'explication',
dossier_link: 'dossier_link'
}
belongs_to :procedure

View file

@ -34,11 +34,18 @@
- else
.row
.col-xs-6.depositaire-label= champ.libelle
.col-md-1.col-lg-1.col-sm-1.col-xs-1.comments-off
.col-xs-1.comments-off
= "-"
.col-xs-5.depositaire-info{ id: "champ-#{champ.id}-value" }
- unless champ.decorate.value.blank?
= champ.decorate.value.html_safe
- if champ.type_champ == 'dossier_link'
- dossier = Dossier.find_by(id: champ.decorate.value)
- if dossier && gestionnaire_signed_in?
= link_to(dossier.procedure.libelle, backoffice_dossier_path(champ.decorate.value), target: '_blank')
- else
= dossier.nil? ? 'pas de dossier associé' : dossier.procedure.libelle
- else
= champ.decorate.value.html_safe
- if @facade.dossier.mandataire_social && gestionnaire_signed_in?
.mandataire_social.text-success.center

View file

@ -0,0 +1,21 @@
- dossier = Dossier.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-link
%input.form-control{ name: "champs['#{ champ.id }']",
placeholder: champ.libelle,
id: "champs_#{ champ.id }",
value: champ.value,
type: 'number',
'autocomplete' => 'off',
'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.procedureLibelle= procedure_libelle
%p.text-warning{ style: show_warning ? nil : 'display: none;' }
ce dossier est inconnu

View file

@ -41,6 +41,9 @@
- elsif champ.type_champ == 'departements'
= render partial: 'users/description/champs/departements', locals: { champ: champ }
- elsif champ.type_champ == 'dossier_link'
= render partial: 'users/description/champs/dossier_link', locals: { champ: champ }
- elsif champ.type_champ == 'explication'
- else

View file

@ -24,3 +24,4 @@ fr:
header_section: 'Titre de section'
explication: 'Explication'
multiple_drop_down_list: 'Menu déroulant à choix multiples'
dossier_link: 'Lien vers un autre dossier'

View file

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

View file

@ -554,4 +554,28 @@ describe Users::DossiersController, type: :controller do
end
end
describe 'Get #procedure_libelle' 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 } }
it 'returns the procedure name' do
expect(JSON.parse(response.body)).to eq('procedureLibelle' => procedure.libelle)
end
end
context 'when the dossier does not exist' do
before { get :procedure_libelle, 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 } }
it { expect(response.code).to eq('302') }
end
end
end

View file

@ -0,0 +1,47 @@
require 'spec_helper'
describe 'users/description/champs/dossier_link.html.haml', type: :view do
let(:type_champ) { create(:type_de_champ_public, type_champ: :dossier_link) }
before do
render 'users/description/champs/dossier_link.html.haml', champ: champ
end
context 'When no dossier is provided' do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }
it 'should not display the procedure libelle' do
expect(rendered).to have_css('.text-info[style*="display: none"]')
end
it 'should not display a warning' do
expect(rendered).to have_css('.text-warning[style*="display: none"]')
end
end
context 'When a dossier whith a procedure is provided' do
let!(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, procedure: procedure) }
let!(:champ) { create(:champ, type_de_champ: type_champ, value: dossier.id) }
it 'should display the procedure libelle' do
expect(rendered).not_to have_css('.text-info[style*="display: none"]')
end
it 'should not display a warning' do
expect(rendered).to have_css('.text-warning[style*="display: none"]')
end
end
context 'When a unknown dossier id is provided' do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: 666) }
it 'should not display the procedure libelle' do
expect(rendered).to have_css('.text-info[style*="display: none"]')
end
it 'should display a warning' do
expect(rendered).not_to have_css('.text-warning[style*="display: none"]')
end
end
end

View file

@ -24,4 +24,18 @@ describe 'users/description/champs/render_list_champs.html.haml', type: :view do
expect(rendered).to have_css('input[type=checkbox][checked]')
end
end
context 'with a dossier_link' do
let(:type_champ) { create(:type_de_champ_public, type_champ: :dossier_link) }
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }
before do
render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0
end
it 'should render a number input with the right data-attribute' do
expect(view).to render_template(partial: 'users/description/champs/_dossier_link',
locals: { champ: champ })
end
end
end