Merge branch 'develop' into staging

This commit is contained in:
gregoirenovel 2017-04-27 16:59:32 +02:00
commit f7d6f013f1
23 changed files with 166 additions and 70 deletions

View file

@ -5,7 +5,7 @@
}; };
var showData = function(data) { var showData = function(data) {
$('.dossier-link .procedureLibelle').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.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

@ -278,6 +278,28 @@ class Dossier < ActiveRecord::Base
!(procedure.archived && draft?) !(procedure.archived && draft?)
end end
def text_summary
if brouillon?
parts = [
"Dossier en brouillon répondant à la démarche ",
procedure.libelle,
", gérée par l'organisme ",
procedure.organisation
]
else
parts = [
"Dossier déposé le ",
initiated_at.strftime("%d/%m/%Y"),
", sur la démarche ",
procedure.libelle,
", gérée par l'organisme ",
procedure.organisation
]
end
parts.join
end
private private
def update_state_dates def update_state_dates

View file

@ -98,6 +98,10 @@ class Gestionnaire < ActiveRecord::Base
0 0
end end
def dossiers_with_notifications_count
notifications.pluck(:dossier_id).uniq.count
end
private private
def valid_couple_table_attr? table, column def valid_couple_table_attr? table, column

View file

@ -1,8 +1,5 @@
class Notification < ActiveRecord::Base class Notification < ActiveRecord::Base
belongs_to :dossier belongs_to :dossier
# after_save :broadcast_notification
enum type_notif: { enum type_notif: {
commentaire: 'commentaire', commentaire: 'commentaire',
cerfa: 'cerfa', cerfa: 'cerfa',
@ -10,10 +7,5 @@ class Notification < ActiveRecord::Base
champs: 'champs', champs: 'champs',
submitted: 'submitted' submitted: 'submitted'
} }
scope :unread, -> { where(already_read: false) }
# def broadcast_notification
# ActionCable.server.broadcast 'notifications',
# message: "Dossier nº #{self.dossier.id} : #{self.liste.last}",
# dossier: {id: self.dossier.id}
# end
end end

View file

@ -3,6 +3,7 @@ class Procedure < ActiveRecord::Base
has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy
has_many :types_de_champ_private, dependent: :destroy has_many :types_de_champ_private, dependent: :destroy
has_many :dossiers has_many :dossiers
has_many :notifications, through: :dossiers
has_one :procedure_path, dependent: :destroy has_one :procedure_path, dependent: :destroy
@ -47,6 +48,8 @@ class Procedure < ActiveRecord::Base
end end
scope :not_archived, -> { where(archived: false) } scope :not_archived, -> { where(archived: false) }
scope :by_libelle, -> { order(libelle: :asc) }
def path def path
procedure_path.path unless procedure_path.nil? procedure_path.path unless procedure_path.nil?

View file

@ -39,11 +39,13 @@
.col-xs-5.depositaire-info{ id: "champ-#{champ.id}-value" } .col-xs-5.depositaire-info{ id: "champ-#{champ.id}-value" }
- unless champ.decorate.value.blank? - unless champ.decorate.value.blank?
- if champ.type_champ == 'dossier_link' - if champ.type_champ == 'dossier_link'
- dossier = Dossier.find_by(id: champ.decorate.value) - dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value)
- if dossier && gestionnaire_signed_in? - if dossier
= link_to(dossier.procedure.libelle, backoffice_dossier_path(champ.decorate.value), target: '_blank') = link_to("Dossier #{dossier.id}", backoffice_dossier_path(champ.decorate.value), target: '_blank')
%br
= dossier.text_summary
- else - else
= dossier.nil? ? 'pas de dossier associé' : dossier.procedure.libelle Pas de dossier associé
- else - else
= champ.decorate.value.html_safe = champ.decorate.value.html_safe

View file

@ -1,42 +1,42 @@
%div#first-block #first-block
.dossiers-en-cours .dossiers-en-cours
.count= @facade_data_view.total_dossier_follow .count= current_gestionnaire.dossiers_follow.count
.text SUIVIS .text SUIVIS
.nouveaux-dossiers .nouveaux-dossiers
.count= @facade_data_view.total_new_dossier .count= current_gestionnaire.dossiers.nouveaux.count
.text NOUVEAUX .text NOUVEAUX
.nouvelles-notifications .nouvelles-notifications
.count= @facade_data_view.dossiers_with_unread_notifications.count .count= current_gestionnaire.dossiers_with_notifications_count
.text MODIFIÉS .text MODIFIÉS
%div#action-block #action-block
%div#menu-block #menu-block
.split-hr-left .split-hr-left
#switch-buttons #switch-buttons
#switch-procedures.active Procédures #switch-procedures.active Procédures
#switch-notifications Notifications #switch-notifications Notifications
%div#infos-block #infos-block
.split-hr-left .split-hr-left
#procedure-list #procedure-list
- @facade_data_view.gestionnaire_procedures_name_and_id_list.each do |procedure| - current_gestionnaire.procedures.by_libelle.each do |procedure|
= link_to backoffice_dossiers_procedure_path(procedure.id), { title: procedure.libelle } do
= link_to backoffice_dossiers_procedure_path(procedure[:id]), { title: procedure[:libelle] } do .procedure-list-element{ class: ('active' if procedure.id.to_s == params[:id]) }
.procedure-list-element{ class: ('active' if procedure[:id] == @facade_data_view.procedure.id rescue '') } = procedure.libelle.truncate(50)
= truncate(procedure[:libelle], length: 50) - total_new = procedure.dossiers.nouveaux.count
- total_new = @facade_data_view.new_dossier_number procedure[:id]
- if total_new > 0 - if total_new > 0
.badge.progress-bar-success{ title: 'Nouveaux dossiers' } .badge.progress-bar-success{ title: 'Nouveaux dossiers' }
= total_new = total_new
- if procedure[:unread_notifications] > 0 - unread_notif_count = procedure.notifications.unread.count
- if unread_notif_count > 0
.badge.progress-bar-warning{ title: 'Notifications' } .badge.progress-bar-warning{ title: 'Notifications' }
= procedure[:unread_notifications] = unread_notif_count
#notifications-list.hidden #notifications-list.hidden
- if @facade_data_view.dossiers_with_unread_notifications.empty? - if current_gestionnaire.notifications.empty?
.no-notification Aucune notification pour le moment. .no-notification Aucune notification pour le moment.
- else - else
- @facade_data_view.dossiers_with_unread_notifications.each do |dossier| - current_gestionnaire.notifications.includes(:dossier).map(&:dossier).uniq.each do |dossier|
= link_to backoffice_dossier_path(dossier.id) do = link_to backoffice_dossier_path(dossier.id) do
.notification .notification
.dossier-index= "Dossier nº #{dossier.id}" .dossier-index= "Dossier nº #{dossier.id}"

View file

@ -1,11 +1,11 @@
- dossier = Dossier.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 }']",
placeholder: champ.libelle, placeholder: "Numéro de dossier",
id: "champs_#{ champ.id }", id: "champs_#{ champ.id }",
value: champ.value, value: champ.value,
type: 'number', type: 'number',
@ -13,9 +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.procedureLibelle= 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

View file

@ -55,6 +55,17 @@ FactoryGirl.define do
archived false archived false
end end
trait :with_dossier_link do
after(:create) do |dossier, _evaluator|
linked_dossier = create(:dossier)
type_de_champ = dossier.procedure.types_de_champ.find { |t| t.type_champ == 'dossier_link' }
champ = dossier.champs.find { |c| c.type_de_champ == type_de_champ }
champ.value = linked_dossier.id
champ.save!
end
end
trait :replied do trait :replied do
state 'replied' state 'replied'
end end

View file

@ -61,6 +61,14 @@ FactoryGirl.define do
end end
end end
trait :with_dossier_link do
after(:build) do |procedure, _evaluator|
type_de_champ = create(:type_de_champ_public, :type_dossier_link)
procedure.types_de_champ << type_de_champ
end
end
trait :with_two_type_de_piece_justificative do trait :with_two_type_de_piece_justificative do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
rib = create(:type_de_piece_justificative, :rib, order_place: 1) rib = create(:type_de_piece_justificative, :rib, order_place: 1)

View file

@ -9,5 +9,10 @@ FactoryGirl.define do
trait :checkbox do trait :checkbox do
type_champ 'checkbox' type_champ 'checkbox'
end end
trait :type_dossier_link do
libelle 'Référence autre dossier'
type_champ 'dossier_link'
end
end end
end end

View file

@ -3,8 +3,8 @@ require 'spec_helper'
feature 'As a User I want to edit a dossier I own' do feature 'As a User I want to edit a dossier I own' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_type_de_champ, :with_two_type_de_piece_justificative) } let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_type_de_champ, :with_two_type_de_piece_justificative, :with_dossier_link) }
let!(:dossier) { create(:dossier, :with_entreprise, :for_individual, procedure: procedure_for_individual, user: user, autorisation_donnees: true, state: 'initiated') } let!(:dossier) { create(:dossier, :with_entreprise, :for_individual, :with_dossier_link, procedure: procedure_for_individual, user: user, autorisation_donnees: true, state: 'initiated') }
before "Create dossier and visit root path" do before "Create dossier and visit root path" do
login_as user, scope: :user login_as user, scope: :user
@ -23,7 +23,7 @@ feature 'As a User I want to edit a dossier I own' do
end end
scenario 'Getting a dossier, I want to create a new message on', js: true do scenario 'Getting a dossier, I want to create a new message on', js: true do
page.find_by_id('tr_dossier_' + Dossier.last.id.to_s).click page.find_by_id('tr_dossier_' + dossier.id.to_s).click
expect(page).to have_current_path(users_dossier_recapitulatif_path(Dossier.first.id.to_s), only_path: true) expect(page).to have_current_path(users_dossier_recapitulatif_path(Dossier.first.id.to_s), only_path: true)
page.find_by_id('open-message').click page.find_by_id('open-message').click
page.execute_script("$('#texte_commentaire').data('wysihtml5').editor.setValue('Contenu du nouveau message')") page.execute_script("$('#texte_commentaire').data('wysihtml5').editor.setValue('Contenu du nouveau message')")
@ -34,12 +34,17 @@ feature 'As a User I want to edit a dossier I own' do
scenario 'On the same dossier, I want to edit informations', js: true do scenario 'On the same dossier, I want to edit informations', js: true do
page.find_by_id('tr_dossier_' + dossier.id.to_s).click page.find_by_id('tr_dossier_' + dossier.id.to_s).click
expect(page).to have_current_path(users_dossier_recapitulatif_path(dossier.id.to_s), only_path: true) expect(page).to have_current_path(users_dossier_recapitulatif_path(dossier.id.to_s), only_path: true)
# Linked Dossier
linked_dossier_id = dossier.champs.find { |c| c.type_de_champ.type_champ == 'dossier_link' }.value
expect(page).to have_link("Dossier #{linked_dossier_id}")
page.find_by_id('maj_infos').trigger('click') page.find_by_id('maj_infos').trigger('click')
expect(page).to have_current_path(users_dossier_description_path(dossier.id.to_s), only_path: true) expect(page).to have_current_path(users_dossier_description_path(dossier.id.to_s), only_path: true)
fill_in "champs_#{dossier.champs.first.id.to_s}", with: 'Contenu du champ 1' fill_in "champs_#{dossier.champs.order(:id).first.id.to_s}", with: 'Contenu du champ 1'
page.find_by_id('modification_terminee').click page.find_by_id('modification_terminee').click
expect(page).to have_current_path(users_dossier_recapitulatif_path(dossier.id.to_s), only_path: true) expect(page).to have_current_path(users_dossier_recapitulatif_path(dossier.id.to_s), only_path: true)
expect(page.find("#champ-#{dossier.champs.first.id}-value").text).to eq('Contenu du champ 1') expect(page.find("#champ-#{dossier.champs.order(:id).first.id}-value").text).to eq('Contenu du champ 1')
end end
end end
end end

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
xfeature 'As a User I want to sort and paginate dossiers', js: true do feature 'As a User I want to sort and paginate dossiers', js: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:procedure_for_individual) { create(:procedure, :published, :for_individual) } let(:procedure_for_individual) { create(:procedure, :published, :for_individual) }

View file

@ -809,6 +809,26 @@ describe Dossier do
end end
end end
describe "#text_summary" do
let(:procedure) { create(:procedure, libelle: "Démarche", organisation: "Organisation") }
context 'when the dossier has been initiated' do
let(:dossier) { create :dossier, procedure: procedure, state: 'initiated', initiated_at: "31/12/2010".to_date }
subject { dossier.text_summary }
it { is_expected.to eq("Dossier déposé le 31/12/2010, sur la démarche Démarche, gérée par l'organisme Organisation") }
end
context 'when the dossier has not been initiated' do
let(:dossier) { create :dossier, procedure: procedure, state: 'draft' }
subject { dossier.text_summary }
it { is_expected.to eq("Dossier en brouillon répondant à la démarche Démarche, gérée par l'organisme Organisation") }
end
end
describe '#update_state_dates' do describe '#update_state_dates' do
let(:state) { 'draft' } let(:state) { 'draft' }
let(:dossier) { create(:dossier, state: state) } let(:dossier) { create(:dossier, state: state) }

View file

@ -272,6 +272,37 @@ describe Gestionnaire, type: :model do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
end end
end
describe '#dossiers_with_notifications_count' do
subject { gestionnaire.dossiers_with_notifications_count }
context 'when there is no notifications' do
it { is_expected.to eq(0) }
end
context 'when there is one notification for one dossier' do
let(:notification){ create(:notification, already_read: false) }
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
it { is_expected.to eq(1) }
end
context 'when there are many notifications for one dossier' do
let(:notification){ create(:notification, already_read: false) }
let(:notification2){ create(:notification, already_read: false, dossier: notification.dossier) }
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
it { is_expected.to eq(1) }
end
context 'when there are many notifications for many dossiers' do
let(:notification){ create(:notification, already_read: false) }
let(:notification2){ create(:notification, already_read: false) }
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
let!(:follow2){ create(:follow, dossier: notification2.dossier, gestionnaire: gestionnaire) }
it { is_expected.to eq(2) }
end
end end
end end

View file

@ -22,8 +22,4 @@ describe NotificationService do
end end
end end
end end
describe 'text_for_notif' do
pending
end
end end

View file

@ -16,8 +16,4 @@ describe RenderPartialService do
it { is_expected.to eq 'layouts/left_panels/left_panel_'+controller.to_s.parameterize + '_' + method.to_s } it { is_expected.to eq 'layouts/left_panels/left_panel_'+controller.to_s.parameterize + '_' + method.to_s }
end end
describe 'left_panel_exist?' do
pending
end
end end

View file

@ -7,6 +7,14 @@ describe 'users/description/champs/dossier_link.html.haml', type: :view do
render 'users/description/champs/dossier_link.html.haml', champ: champ render 'users/description/champs/dossier_link.html.haml', champ: champ
end end
context 'in all cases' do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }
it 'should render an input for the dossier link' do
expect(rendered).to have_css("input[type=number][placeholder='Numéro de dossier']")
end
end
context 'When no dossier is provided' do context 'When no dossier is provided' do
let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) } let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) }

View file

@ -33,7 +33,7 @@ describe 'users/description/champs/render_list_champs.html.haml', type: :view do
render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0 render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0
end end
it 'should render a number input with the right data-attribute' do it 'should render the _dossier_link partial' do
expect(view).to render_template(partial: 'users/description/champs/_dossier_link', expect(view).to render_template(partial: 'users/description/champs/_dossier_link',
locals: { champ: champ }) locals: { champ: champ })
end end

View file

@ -24,12 +24,6 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
expect(rendered).to have_selector('#messages') expect(rendered).to have_selector('#messages')
end end
it 'le numéro de dossier est présent' do
pending 'move to test layout'
expect(rendered).to have_selector('#dossier_id')
expect(rendered).to have_content(dossier_id)
end
describe 'les liens de modifications' do describe 'les liens de modifications' do
context 'lien description' do context 'lien description' do
it 'le lien vers description est présent' do it 'le lien vers description est présent' do