From ad4bd87b1faadd876c15fcb1341757ae92b4faf3 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 21 Apr 2017 17:02:37 +0200 Subject: [PATCH 01/14] Remove unused pending tests, and enable old tests disabled for sqlite --- spec/features/users/dossier_index_spec.rb | 2 +- spec/services/notification_service_spec.rb | 4 ---- spec/services/render_partial_service_spec.rb | 4 ---- spec/views/users/recapitulatif/show.html.haml_spec.rb | 6 ------ 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/spec/features/users/dossier_index_spec.rb b/spec/features/users/dossier_index_spec.rb index 9db5bd1e3..913efcf79 100644 --- a/spec/features/users/dossier_index_spec.rb +++ b/spec/features/users/dossier_index_spec.rb @@ -1,6 +1,6 @@ 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(:procedure_for_individual) { create(:procedure, :published, :for_individual) } diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index df7fe448b..6a6cc4762 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -22,8 +22,4 @@ describe NotificationService do end end end - - describe 'text_for_notif' do - pending - end end diff --git a/spec/services/render_partial_service_spec.rb b/spec/services/render_partial_service_spec.rb index ea94d3d5a..a8eee209c 100644 --- a/spec/services/render_partial_service_spec.rb +++ b/spec/services/render_partial_service_spec.rb @@ -16,8 +16,4 @@ describe RenderPartialService do it { is_expected.to eq 'layouts/left_panels/left_panel_'+controller.to_s.parameterize + '_' + method.to_s } end - - describe 'left_panel_exist?' do - pending - end end diff --git a/spec/views/users/recapitulatif/show.html.haml_spec.rb b/spec/views/users/recapitulatif/show.html.haml_spec.rb index ce0e52275..ccef84120 100644 --- a/spec/views/users/recapitulatif/show.html.haml_spec.rb +++ b/spec/views/users/recapitulatif/show.html.haml_spec.rb @@ -24,12 +24,6 @@ describe 'users/recapitulatif/show.html.haml', type: :view do expect(rendered).to have_selector('#messages') 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 context 'lien description' do it 'le lien vers description est présent' do From f8cb34a39318033b231fc3926a635ced6e737e91 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 18 Apr 2017 17:19:40 +0200 Subject: [PATCH 02/14] Add some spacing in _dossier_link.html.haml --- app/views/users/description/champs/_dossier_link.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/description/champs/_dossier_link.html.haml b/app/views/users/description/champs/_dossier_link.html.haml index 41d6f0526..1fa87656c 100644 --- a/app/views/users/description/champs/_dossier_link.html.haml +++ b/app/views/users/description/champs/_dossier_link.html.haml @@ -17,5 +17,6 @@ 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 From 8bea7cb610704e13db9336bdc0a4ff75b787f109 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 24 Apr 2017 10:12:02 +0200 Subject: [PATCH 03/14] Fix a typographic mistake in _dossier_link.html.haml Sentences should start with an uppercase letter --- app/views/users/description/champs/_dossier_link.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/description/champs/_dossier_link.html.haml b/app/views/users/description/champs/_dossier_link.html.haml index 1fa87656c..723f6a47a 100644 --- a/app/views/users/description/champs/_dossier_link.html.haml +++ b/app/views/users/description/champs/_dossier_link.html.haml @@ -19,4 +19,4 @@ %span.procedureLibelle= procedure_libelle %p.text-warning{ style: show_warning ? nil : 'display: none;' } - ce dossier est inconnu + Ce dossier est inconnu From 6bb67d639cf403b114e2a6779151ac97aba6946e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 18 Apr 2017 17:09:22 +0200 Subject: [PATCH 04/14] Use lowercase letters and dashes for CSS classes As enforced by scss-lint --- app/assets/javascripts/new-description.js | 2 +- app/views/users/description/champs/_dossier_link.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/new-description.js b/app/assets/javascripts/new-description.js index 8de71855e..6d56fe939 100644 --- a/app/assets/javascripts/new-description.js +++ b/app/assets/javascripts/new-description.js @@ -5,7 +5,7 @@ }; var showData = function(data) { - $('.dossier-link .procedureLibelle').text(data.procedureLibelle); + $('.dossier-link .procedure-libelle').text(data.procedureLibelle); $('.dossier-link .text-info').show(); $('.dossier-link .text-warning').hide(); }; diff --git a/app/views/users/description/champs/_dossier_link.html.haml b/app/views/users/description/champs/_dossier_link.html.haml index 723f6a47a..23874731f 100644 --- a/app/views/users/description/champs/_dossier_link.html.haml +++ b/app/views/users/description/champs/_dossier_link.html.haml @@ -16,7 +16,7 @@ %p.text-info{ style: show_procedure_libelle ? nil : 'display: none;' } ce dossier répond à la procédure : %br - %span.procedureLibelle= procedure_libelle + %span.procedure-libelle= procedure_libelle %p.text-warning{ style: show_warning ? nil : 'display: none;' } Ce dossier est inconnu From 14b7badfede16a87c781aaab5a314bbdbea9332f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 13 Apr 2017 15:42:54 +0200 Subject: [PATCH 05/14] =?UTF-8?q?Eager-load=20the=20dossier=E2=80=99s=20pr?= =?UTF-8?q?ocedure=20when=20possible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/dossiers_controller.rb | 2 +- app/views/dossiers/_infos_dossier.html.haml | 2 +- app/views/users/description/champs/_dossier_link.html.haml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 4b3abf481..61bf3a0e7 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -165,7 +165,7 @@ class Users::DossiersController < UsersController end def procedure_libelle - dossier = Dossier.find(params[:dossier_id]) + dossier = Dossier.includes(:procedure).find(params[:dossier_id]) render json: { procedureLibelle: dossier.procedure.libelle } rescue ActiveRecord::RecordNotFound render json: {}, status: 404 diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 00b37b627..090873fea 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -39,7 +39,7 @@ .col-xs-5.depositaire-info{ id: "champ-#{champ.id}-value" } - unless champ.decorate.value.blank? - 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? = link_to(dossier.procedure.libelle, backoffice_dossier_path(champ.decorate.value), target: '_blank') - else diff --git a/app/views/users/description/champs/_dossier_link.html.haml b/app/views/users/description/champs/_dossier_link.html.haml index 23874731f..d6fc6ff38 100644 --- a/app/views/users/description/champs/_dossier_link.html.haml +++ b/app/views/users/description/champs/_dossier_link.html.haml @@ -1,4 +1,4 @@ -- dossier = Dossier.find_by(id: champ.value) +- 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 From b34bf4846caf791d3c9d0e6347e3786c1bf8c569 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 13 Apr 2017 17:22:18 +0200 Subject: [PATCH 06/14] Improve a test title in the _render_list_champs test --- .../description/champs/_render_list_champs.html.haml_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb b/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb index 17ca6d9d3..b5a74ed58 100644 --- a/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb +++ b/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb @@ -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 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', locals: { champ: champ }) end From 2b23d0d087c96b61cfc797d15d38d75f04ca11a9 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 17 Apr 2017 17:20:32 +0200 Subject: [PATCH 07/14] Add a missing feature test for the linked dossier feature --- spec/factories/dossier.rb | 11 +++++++++++ spec/factories/procedure.rb | 8 ++++++++ spec/factories/type_de_champ_public.rb | 5 +++++ spec/features/users/dossier_edition_spec.rb | 16 +++++++++++----- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index a58e28bb0..415e1d58d 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -55,6 +55,17 @@ FactoryGirl.define do archived false 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 state 'replied' end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index b8e4d5e15..f38629fc7 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -61,6 +61,14 @@ FactoryGirl.define do 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 after(:build) do |procedure, _evaluator| rib = create(:type_de_piece_justificative, :rib, order_place: 1) diff --git a/spec/factories/type_de_champ_public.rb b/spec/factories/type_de_champ_public.rb index 3dad7603b..b1ef85016 100644 --- a/spec/factories/type_de_champ_public.rb +++ b/spec/factories/type_de_champ_public.rb @@ -9,5 +9,10 @@ FactoryGirl.define do trait :checkbox do type_champ 'checkbox' end + + trait :type_dossier_link do + libelle 'Référence autre dossier' + type_champ 'dossier_link' + end end end diff --git a/spec/features/users/dossier_edition_spec.rb b/spec/features/users/dossier_edition_spec.rb index 13bbf29a0..f82d94032 100644 --- a/spec/features/users/dossier_edition_spec.rb +++ b/spec/features/users/dossier_edition_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' feature 'As a User I want to edit a dossier I own' do let(:user) { create(:user) } - let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_type_de_champ, :with_two_type_de_piece_justificative) } - let!(:dossier) { create(:dossier, :with_entreprise, :for_individual, procedure: procedure_for_individual, user: user, autorisation_donnees: true, state: 'initiated') } + 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, :with_dossier_link, procedure: procedure_for_individual, user: user, autorisation_donnees: true, state: 'initiated') } before "Create dossier and visit root path" do login_as user, scope: :user @@ -23,7 +23,7 @@ feature 'As a User I want to edit a dossier I own' do end 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) page.find_by_id('open-message').click page.execute_script("$('#texte_commentaire').data('wysihtml5').editor.setValue('Contenu du nouveau message')") @@ -34,12 +34,18 @@ 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 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) + + # Linked Dossier + linked_dossier_id = dossier.champs.find { |c| c.type_de_champ.type_champ == 'dossier_link' }.value + linked_dossier = Dossier.find(linked_dossier_id) + expect(page).to have_content(linked_dossier.procedure.libelle) + 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) - 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 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 From b89e59192c3446acb28ce9036215fe1177dbd5a9 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 26 Apr 2017 11:24:37 +0200 Subject: [PATCH 08/14] Add a missing a test for the dossier link field in the form --- .../description/champs/_dossier_link.html.haml_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb b/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb index a61f09532..fc8a79850 100644 --- a/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb +++ b/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb @@ -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 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=#{champ.libelle}]") + end + end + context 'When no dossier is provided' do let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) } From 8deef8e8e31c80d5c5a60eb26347095f6ca8e882 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 17 Apr 2017 17:15:44 +0200 Subject: [PATCH 09/14] [Fix #137] Change the dossier link placeholder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we don’t know what to enter (words, numbers…) --- app/views/users/description/champs/_dossier_link.html.haml | 2 +- .../users/description/champs/_dossier_link.html.haml_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/users/description/champs/_dossier_link.html.haml b/app/views/users/description/champs/_dossier_link.html.haml index d6fc6ff38..f874c7e4a 100644 --- a/app/views/users/description/champs/_dossier_link.html.haml +++ b/app/views/users/description/champs/_dossier_link.html.haml @@ -5,7 +5,7 @@ .dossier-link %input.form-control{ name: "champs['#{ champ.id }']", - placeholder: champ.libelle, + placeholder: "Numéro de dossier", id: "champs_#{ champ.id }", value: champ.value, type: 'number', diff --git a/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb b/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb index fc8a79850..970ab4a43 100644 --- a/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb +++ b/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb @@ -11,7 +11,7 @@ describe 'users/description/champs/dossier_link.html.haml', type: :view 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=#{champ.libelle}]") + expect(rendered).to have_css("input[type=number][placeholder='Numéro de dossier']") end end From 7173d359d467c4d352831a864901414f0ced96eb Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 25 Apr 2017 09:47:13 +0200 Subject: [PATCH 10/14] [Fix #132] Show the dossier link in the dossier detail for Users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s no reason why they couldn’t easily navigate to it Also improve the typography of a placeholder message --- app/views/dossiers/_infos_dossier.html.haml | 4 ++-- spec/features/users/dossier_edition_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 090873fea..dedbd8acf 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -40,10 +40,10 @@ - unless champ.decorate.value.blank? - if champ.type_champ == 'dossier_link' - 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') - else - = dossier.nil? ? 'pas de dossier associé' : dossier.procedure.libelle + Pas de dossier associé - else = champ.decorate.value.html_safe diff --git a/spec/features/users/dossier_edition_spec.rb b/spec/features/users/dossier_edition_spec.rb index f82d94032..e66483d67 100644 --- a/spec/features/users/dossier_edition_spec.rb +++ b/spec/features/users/dossier_edition_spec.rb @@ -38,7 +38,7 @@ feature 'As a User I want to edit a dossier I own' do # Linked Dossier linked_dossier_id = dossier.champs.find { |c| c.type_de_champ.type_champ == 'dossier_link' }.value linked_dossier = Dossier.find(linked_dossier_id) - expect(page).to have_content(linked_dossier.procedure.libelle) + expect(page).to have_link(linked_dossier.procedure.libelle) 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) From f5c5ad532d2380afd19095bcdd1415a9fb7b5e59 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 18 Apr 2017 17:31:01 +0200 Subject: [PATCH 11/14] Add Dossier#text_summary --- app/models/dossier.rb | 22 ++++++++++++++++++++++ spec/models/dossier_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index f98e4e4c9..17c7bf03e 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -278,6 +278,28 @@ class Dossier < ActiveRecord::Base !(procedure.archived && draft?) 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 def update_state_dates diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index ba1dcef8d..576949f7b 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -809,6 +809,26 @@ describe Dossier do 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 let(:state) { 'draft' } let(:dossier) { create(:dossier, state: state) } From a6d3ea8536788953f1e1dedefd6f58d779cd7945 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 13 Apr 2017 15:47:42 +0200 Subject: [PATCH 12/14] [Fix #133] Improve the linked dossier informations displayed --- app/views/dossiers/_infos_dossier.html.haml | 4 +++- spec/features/users/dossier_edition_spec.rb | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index dedbd8acf..15a1aa744 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -41,7 +41,9 @@ - if champ.type_champ == 'dossier_link' - dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value) - 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 Pas de dossier associé - else diff --git a/spec/features/users/dossier_edition_spec.rb b/spec/features/users/dossier_edition_spec.rb index e66483d67..5aca700d9 100644 --- a/spec/features/users/dossier_edition_spec.rb +++ b/spec/features/users/dossier_edition_spec.rb @@ -37,8 +37,7 @@ feature 'As a User I want to edit a dossier I own' do # Linked Dossier linked_dossier_id = dossier.champs.find { |c| c.type_de_champ.type_champ == 'dossier_link' }.value - linked_dossier = Dossier.find(linked_dossier_id) - expect(page).to have_link(linked_dossier.procedure.libelle) + expect(page).to have_link("Dossier #{linked_dossier_id}") 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) From f58a6266481d2a2981f33ef74b0ba95bc9f8f949 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 26 Apr 2017 16:15:48 +0200 Subject: [PATCH 13/14] [Fix #99] Improve the info message in _dossier_link.html.haml --- app/assets/javascripts/new-description.js | 4 ++-- app/controllers/users/dossiers_controller.rb | 6 +++--- .../description/champs/_dossier_link.html.haml | 14 ++++++-------- config/routes.rb | 2 +- spec/controllers/users/dossiers_controller_spec.rb | 10 +++++----- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/new-description.js b/app/assets/javascripts/new-description.js index 6d56fe939..3b32782c4 100644 --- a/app/assets/javascripts/new-description.js +++ b/app/assets/javascripts/new-description.js @@ -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 { diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 61bf3a0e7..8f42f2581 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -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 diff --git a/app/views/users/description/champs/_dossier_link.html.haml b/app/views/users/description/champs/_dossier_link.html.haml index f874c7e4a..c29f2745c 100644 --- a/app/views/users/description/champs/_dossier_link.html.haml +++ b/app/views/users/description/champs/_dossier_link.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 6f0d9edad..16b0b090a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 601b243bc..f479f6eb9 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -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 From 6ef6a66c3f9d0dc25f133559c29b3bc5cde0c2cf Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 26 Apr 2017 11:28:58 +0200 Subject: [PATCH 14/14] Remove @facade_data_view from left_panel view --- app/models/gestionnaire.rb | 4 +++ app/models/notification.rb | 10 +----- app/models/procedure.rb | 3 ++ ...koffice_dossierscontroller_index.html.haml | 34 +++++++++---------- spec/models/gestionnaire_spec.rb | 31 +++++++++++++++++ 5 files changed, 56 insertions(+), 26 deletions(-) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index ada358189..d646d7177 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -98,6 +98,10 @@ class Gestionnaire < ActiveRecord::Base 0 end + def dossiers_with_notifications_count + notifications.pluck(:dossier_id).uniq.count + end + private def valid_couple_table_attr? table, column diff --git a/app/models/notification.rb b/app/models/notification.rb index 2d93de8b3..af36da06e 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,8 +1,5 @@ class Notification < ActiveRecord::Base belongs_to :dossier - - # after_save :broadcast_notification - enum type_notif: { commentaire: 'commentaire', cerfa: 'cerfa', @@ -10,10 +7,5 @@ class Notification < ActiveRecord::Base champs: 'champs', submitted: 'submitted' } - - # def broadcast_notification - # ActionCable.server.broadcast 'notifications', - # message: "Dossier nº #{self.dossier.id} : #{self.liste.last}", - # dossier: {id: self.dossier.id} - # end + scope :unread, -> { where(already_read: false) } end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 7d3624dca..2e910acd3 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -3,6 +3,7 @@ class Procedure < ActiveRecord::Base has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy has_many :types_de_champ_private, dependent: :destroy has_many :dossiers + has_many :notifications, through: :dossiers has_one :procedure_path, dependent: :destroy @@ -47,6 +48,8 @@ class Procedure < ActiveRecord::Base end scope :not_archived, -> { where(archived: false) } + scope :by_libelle, -> { order(libelle: :asc) } + def path procedure_path.path unless procedure_path.nil? diff --git a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml index c990c6836..5d6e6c9d7 100644 --- a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml +++ b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml @@ -1,42 +1,42 @@ -%div#first-block +#first-block .dossiers-en-cours - .count= @facade_data_view.total_dossier_follow + .count= current_gestionnaire.dossiers_follow.count .text SUIVIS .nouveaux-dossiers - .count= @facade_data_view.total_new_dossier + .count= current_gestionnaire.dossiers.nouveaux.count .text NOUVEAUX .nouvelles-notifications - .count= @facade_data_view.dossiers_with_unread_notifications.count + .count= current_gestionnaire.dossiers_with_notifications_count .text MODIFIÉS -%div#action-block +#action-block -%div#menu-block +#menu-block .split-hr-left #switch-buttons #switch-procedures.active Procédures #switch-notifications Notifications -%div#infos-block +#infos-block .split-hr-left #procedure-list - - @facade_data_view.gestionnaire_procedures_name_and_id_list.each do |procedure| - - = link_to backoffice_dossiers_procedure_path(procedure[:id]), { title: procedure[:libelle] } do - .procedure-list-element{ class: ('active' if procedure[:id] == @facade_data_view.procedure.id rescue '') } - = truncate(procedure[:libelle], length: 50) - - total_new = @facade_data_view.new_dossier_number procedure[:id] + - current_gestionnaire.procedures.by_libelle.each do |procedure| + = 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.libelle.truncate(50) + - total_new = procedure.dossiers.nouveaux.count - if total_new > 0 .badge.progress-bar-success{ title: 'Nouveaux dossiers' } = 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' } - = procedure[:unread_notifications] + = unread_notif_count #notifications-list.hidden - - if @facade_data_view.dossiers_with_unread_notifications.empty? + - if current_gestionnaire.notifications.empty? .no-notification Aucune notification pour le moment. - 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 .notification .dossier-index= "Dossier nº #{dossier.id}" diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 1d1ed1320..a9c88fa92 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -272,6 +272,37 @@ describe Gestionnaire, type: :model do it { is_expected.to be_nil } 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