Add total followers on dossier list and followers list on dossier page for gestionnaire

This commit is contained in:
Xavier J 2016-07-19 16:44:26 +02:00
parent 7d0bcfc35f
commit 127c9bb138
7 changed files with 82 additions and 27 deletions

View file

@ -49,4 +49,8 @@ class DossierFacades
def commentaires_files def commentaires_files
PieceJustificative.where(dossier_id: @dossier.id, type_de_piece_justificative_id: nil) PieceJustificative.where(dossier_id: @dossier.id, type_de_piece_justificative_id: nil)
end end
def followers
Gestionnaire.joins(:follows).where("follows.dossier_id=#{@dossier.id}")
end
end end

View file

@ -198,4 +198,8 @@ class Dossier < ActiveRecord::Base
update_attributes(autorisation_donnees: false) update_attributes(autorisation_donnees: false)
end end
def total_follow
follows.size
end
end end

View file

@ -0,0 +1,4 @@
- if current_gestionnaire.follow?(@facade.dossier.id)
= link_to('Quitter'.html_safe, backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), 'data-method' => :put, class: 'btn btn-md btn-danger', id: "suivre_dossier_#{@facade.dossier.id}")
-else
= link_to('Suivre', backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), 'data-method' => :put, class: 'btn btn-md btn-primary', id: "suivre_dossier_#{@facade.dossier.id}")

View file

@ -0,0 +1,14 @@
%h3 Personnes suivant l'activité de ce dossier
%br
.row
.col-md-4.col-lg-4
- if @facade.followers.size > 0
%ul
- @facade.followers.each do |follower|
%li
= follower.email
- else
Aucune personne ne suit ce dossier

View file

@ -6,7 +6,8 @@
%th= smart_listing.sortable 'État', 'state' %th= smart_listing.sortable 'État', 'state'
%th= smart_listing.sortable 'Date de mise à jour', 'updated_at' %th= smart_listing.sortable 'Date de mise à jour', 'updated_at'
- unless @liste == 'termine' - unless @liste == 'termine'
%th Actions %th.center Actions
%th.center Abonnés
- @dossiers.each do |dossier| - @dossiers.each do |dossier|
- dossier = dossier.decorate - dossier = dossier.decorate
@ -17,11 +18,13 @@
%td= dossier.display_state %td= dossier.display_state
%td= dossier.last_update %td= dossier.last_update
- unless @liste == 'termine' - unless @liste == 'termine'
%td %td.center
- if current_gestionnaire.follow?(dossier.id) - if current_gestionnaire.follow?(dossier.id)
= link_to('Quitter'.html_safe, backoffice_dossier_follow_path(dossier_id: dossier.id), 'data-method' => :put, class: 'btn-sm btn-danger', id: "suivre_dossier_#{dossier.id}") = link_to('Quitter'.html_safe, backoffice_dossier_follow_path(dossier_id: dossier.id), 'data-method' => :put, class: 'btn-sm btn-danger', id: "suivre_dossier_#{dossier.id}")
-else -else
= link_to('Suivre', backoffice_dossier_follow_path(dossier_id: dossier.id), 'data-method' => :put, class: 'btn-sm btn-primary', id: "suivre_dossier_#{dossier.id}") = link_to('Suivre', backoffice_dossier_follow_path(dossier_id: dossier.id), 'data-method' => :put, class: 'btn-sm btn-primary', id: "suivre_dossier_#{dossier.id}")
%td.center{style:"color: #{dossier.total_follow == 0 ? 'red' : ''}"}
= dossier.total_follow
= smart_listing.paginate = smart_listing.paginate
= smart_listing.pagination_per_page_links = smart_listing.pagination_per_page_links

View file

@ -6,10 +6,7 @@
%h3{:class => 'text-success'} %h3{:class => 'text-success'}
= @facade.dossier.display_state = @facade.dossier.display_state
- if current_gestionnaire.follow?(@facade.dossier.id) = render partial: 'follow_action'
= link_to('Quitter'.html_safe, backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), 'data-method' => :put, class: 'btn btn-md btn-danger', id: "suivre_dossier_#{@facade.dossier.id}")
-else
= link_to('Suivre', backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), 'data-method' => :put, class: 'btn btn-md btn-primary', id: "suivre_dossier_#{@facade.dossier.id}")
= render partial: '/dossiers/infos_entreprise' = render partial: '/dossiers/infos_entreprise'
@ -27,6 +24,9 @@
%li{role: "presentation"} %li{role: "presentation"}
%a{href: "#invites", 'aria-controls' => "invites", role: "tab", 'data-toggle' => "tab"} %a{href: "#invites", 'aria-controls' => "invites", role: "tab", 'data-toggle' => "tab"}
Invités Invités
%li{role: "presentation"}
%a{href: "#followers", 'aria-controls' => "followers", role: "tab", 'data-toggle' => "tab"}
Abonnés
%div{class: "tab-content"} %div{class: "tab-content"}
%div{role: "tabpanel", class: "tab-pane fade in active", id:"commentaires"} %div{role: "tabpanel", class: "tab-pane fade in active", id:"commentaires"}
@ -37,6 +37,8 @@
= render partial: '/dossiers/commentaires_files' = render partial: '/dossiers/commentaires_files'
%div{role: "tabpanel", class: "tab-pane fade", id:"invites"} %div{role: "tabpanel", class: "tab-pane fade", id:"invites"}
= render partial: '/dossiers/invites' = render partial: '/dossiers/invites'
%div{role: "tabpanel", class: "tab-pane fade", id:"followers"}
= render partial: 'followers'
%br %br
%br %br

View file

@ -2,6 +2,7 @@ require 'spec_helper'
describe Dossier do describe Dossier do
let(:user) { create(:user) } let(:user) { create(:user) }
describe 'database columns' do describe 'database columns' do
it { is_expected.to have_db_column(:autorisation_donnees) } it { is_expected.to have_db_column(:autorisation_donnees) }
it { is_expected.to have_db_column(:nom_projet) } it { is_expected.to have_db_column(:nom_projet) }
@ -623,4 +624,27 @@ describe Dossier do
end end
end end
describe '#total_follow' do
let(:dossier) { create(:dossier, :with_entreprise, user: user) }
let(:dossier2) { create(:dossier, :with_entreprise, user: user) }
subject { dossier.total_follow }
context 'when no body follow dossier' do
it { expect(subject).to eq 0 }
end
context 'when 2 people follow dossier' do
before do
create :follow, dossier_id: dossier.id, gestionnaire_id: (create :gestionnaire).id
create :follow, dossier_id: dossier.id, gestionnaire_id: (create :gestionnaire).id
create :follow, dossier_id: dossier2.id, gestionnaire_id: (create :gestionnaire).id
create :follow, dossier_id: dossier2.id, gestionnaire_id: (create :gestionnaire).id
end
it { expect(subject).to eq 2 }
end
end
end end