Skip to content

Commit

Permalink
[Fix #1016] display notifications for champs publics
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagn committed Dec 13, 2017
1 parent 2fb3e25 commit 834cce4
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 29 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/new_design/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ $lighter-green: lighten($green, 30%);
$light-green: lighten($green, 25%);
$dark-green: darken($green, 20%);
$orange: #F59415;
$orange-bg: lighten($orange, 35%);
22 changes: 21 additions & 1 deletion app/assets/stylesheets/new_design/dossier_champs.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "colors";
@import "constants";

.dossier-champs {
.table.dossier-champs {
th,
td {
vertical-align: top;
Expand All @@ -9,4 +10,23 @@
.libelle {
width: 250px;
}

td.updated-at {
font-size: 13px;
color: $grey;
text-align: right;
width: 190px;

> span {
opacity: 0;

&.highlighted {
opacity: 1;
}
}
}

tr:hover .updated-at > span {
opacity: 1;
}
}
7 changes: 7 additions & 0 deletions app/assets/stylesheets/new_design/utils.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "colors";

.pull-left {
float: left;
}
Expand Down Expand Up @@ -32,3 +34,8 @@
text-align: center;
margin: 60px 0;
}

.highlighted {
background: $orange-bg;
color: $black;
}
10 changes: 8 additions & 2 deletions app/controllers/new_gestionnaire/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ class DossiersController < ProceduresController
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::TextHelper

after_action :mark_demande_as_read, only: :show

def attestation
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
end

def show
dossier.notifications.demande.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :demande)
@demande_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.demande_seen_at
end

def messagerie
Expand Down Expand Up @@ -192,5 +193,10 @@ def check_attestation_emailable

dossier&.attestation&.emailable?
end

def mark_demande_as_read
dossier.notifications.demande.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :demande)
end
end
end
6 changes: 6 additions & 0 deletions app/helpers/dossier_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ def button_or_label_class(dossier)
'refused'
end
end

def highlight_if_unseen_class(seen_at, updated_at)
if seen_at&.<(updated_at)
"highlighted"
end
end
end
8 changes: 4 additions & 4 deletions app/models/follow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Follow < ActiveRecord::Base
private

def set_default_date
self.demande_seen_at = DateTime.now
self.annotations_privees_seen_at = DateTime.now
self.avis_seen_at = DateTime.now
self.messagerie_seen_at = DateTime.now
self.demande_seen_at ||= DateTime.now
self.annotations_privees_seen_at ||= DateTime.now
self.avis_seen_at ||= DateTime.now
self.messagerie_seen_at ||= DateTime.now
end
end
2 changes: 1 addition & 1 deletion app/views/new_gestionnaire/avis/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- champs = @dossier.ordered_champs.decorate
- if champs.any?
.card
= render partial: 'new_gestionnaire/dossiers/champs', locals: { champs: champs }
= render partial: 'new_gestionnaire/dossiers/champs', locals: { champs: champs, dossier: @dossier, follow: nil }

- if @dossier.procedure.use_api_carto
.accompagnateur-title Cartographie
Expand Down
10 changes: 8 additions & 2 deletions app/views/new_gestionnaire/dossiers/_champs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%tr
- case c.type_champ
- when "header_section"
%th.header-section{ colspan: 2 }
%th.header-section{ colspan: 3 }
= c.libelle
- when "multiple_drop_down_list"
%th.libelle
Expand All @@ -30,4 +30,10 @@
%th.libelle
= "#{c.libelle} :"
%td.rich-text
= sanitize(c.value)
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
= sanitize(c.value)
- if c.type_champ != "header_section"
%td.updated-at
%span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) }
modifié le
= c.updated_at.localtime.strftime("%d/%m/%Y à %H:%M")
2 changes: 1 addition & 1 deletion app/views/new_gestionnaire/dossiers/print.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

- champs = @dossier.ordered_champs.decorate
- if champs.any?
= render partial: "champs", locals: { champs: champs }
= render partial: "champs", locals: { champs: champs, dossier: @dossier }

- if @dossier.procedure.use_api_carto
%h3 Cartographie
Expand Down
2 changes: 1 addition & 1 deletion app/views/new_gestionnaire/dossiers/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- champs = @dossier.ordered_champs.includes(:type_de_champ).decorate
- if champs.any?
.card
= render partial: "champs", locals: { champs: champs }
= render partial: "champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: @demande_seen_at }

- if @dossier.procedure.use_api_carto
.accompagnateur-title Cartographie
Expand Down
49 changes: 32 additions & 17 deletions spec/views/new_gestionnaire/dossiers/_champs.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do
before { render 'new_gestionnaire/dossiers/champs.html.haml', champs: champs }
before { view.extend DossierHelper }

context "there are some champs" do
let(:dossier) { create(:dossier) }
let(:champ1) { create(:champ, :checkbox, value: "true") }
let(:champ2) { create(:champ, :header_section, value: "Section") }
let(:champ3) { create(:champ, :explication, value: "mazette") }
let(:champ4) { create(:champ, :dossier_link, value: dossier.id) }
let(:champs) { [champ1, champ2, champ3, champ4] }
subject { render 'new_gestionnaire/dossiers/champs.html.haml', champs: champs, dossier: dossier, demande_seen_at: seen_at }

let(:dossier) { create(:dossier) }
let(:champ1) { create(:champ, :checkbox, value: "true") }
let(:champ2) { create(:champ, :header_section, value: "Section") }
let(:champ3) { create(:champ, :explication, value: "mazette") }
let(:champ4) { create(:champ, :dossier_link, value: dossier.id) }
let(:champs) { [champ1, champ2, champ3, champ4] }
let(:seen_at) { champ1.updated_at + 1.hour }

it { expect(rendered).to include(champ1.libelle) }
it { expect(rendered).to include(champ1.value) }
context "there are some champs" do
it { is_expected.to include(champ1.libelle) }
it { is_expected.to include(champ1.value) }

it { expect(rendered).to have_css(".header-section") }
it { expect(rendered).to include(champ2.libelle) }
it { is_expected.to have_css(".header-section") }
it { is_expected.to include(champ2.libelle) }

it { expect(rendered).not_to include(champ3.libelle) }
it { expect(rendered).not_to include(champ3.value) }
it { is_expected.not_to include(champ3.libelle) }
it { is_expected.not_to include(champ3.value) }

it { expect(rendered).to have_link("Dossier nº #{dossier.id}") }
it { expect(rendered).to include(dossier.text_summary) }
it { is_expected.to have_link("Dossier nº #{dossier.id}") }
it { is_expected.to include(dossier.text_summary) }
end

context "with a dossier_link champ but without value" do
let(:champ) { create(:champ, :dossier_link, value: nil) }
let(:champs) { [champ] }

it { expect(rendered).to include("Pas de dossier associé") }
it { is_expected.to include("Pas de dossier associé") }
end

context "with a seen_at after champ updated_at" do
let(:seen_at) { champ1.updated_at + 1.hour }

it { is_expected.not_to have_css(".highlighted") }
end

context "with a seen_at after champ updated_at" do
let(:seen_at) { champ1.updated_at - 1.hour }

it { is_expected.to have_css(".highlighted") }
end
end
2 changes: 2 additions & 0 deletions spec/views/new_gestionnaire/dossiers/show.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe 'new_gestionnaire/dossiers/show.html.haml', type: :view do
before { view.extend DossierHelper }

let(:current_gestionnaire) { create(:gestionnaire) }
let(:individual) { nil }
let(:entreprise) { nil }
Expand Down

0 comments on commit 834cce4

Please sign in to comment.