Skip to content

Commit

Permalink
Merge pull request #1331 from betagouv/feature/notifications-conserva…
Browse files Browse the repository at this point in the history
…teurs

Ajout d'un raccourci vers l'activité des communes pour les conservateurs
  • Loading branch information
goulvench authored Oct 28, 2024
2 parents 47b92ab + e5e4089 commit 83d7e1a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 61 deletions.
32 changes: 23 additions & 9 deletions app/controllers/conservateurs/departements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

module Conservateurs
class DepartementsController < BaseController
before_action :set_departements, only: [:index, :activite_des_departements]
before_action :set_departement, only: [:show, :carte, :activite]
before_action :set_date_range, only: [:activite, :activite_des_departements]
before_action :set_communes, only: [:show, :carte]
before_action :set_status_global_filter, only: [:show]
before_action :set_tabs, only: [:show, :carte, :activite]

def index
@departements = policy_scope(Departement).include_objets_count.order(:code)
skip_after_action :verify_authorized, only: :activite_des_departements

def index; end

def activite_des_departements
if @departements.length == 1
redirect_to activite_conservateurs_departement_path(@departements.first)
else
render "activite"
end
end

def show
set_communes
@ransack = @communes.select("nom").ransack(params[:q])

# Remonte par défaut les communes avec le plus d'objets en péril
Expand All @@ -27,7 +37,6 @@ def show
end

def carte
set_communes
@communes.select(%w[code_insee nom status objets_count en_peril_count latitude longitude]).to_a
@departement_json = {
code: @departement.code,
Expand All @@ -37,16 +46,15 @@ def carte
end

def activite
@date_start = parse_date(params[:du])
@date_end = parse_date(params[:au])
@date_range = @date_start && @date_end ? @date_start..@date_end : Date.current.all_week
@date_start ||= @date_range.first
@date_end ||= @date_range.last
render "tabs"
end

protected

def set_departements
@departements = policy_scope(Departement).include_objets_count.order(:code)
end

def set_departement
@departement = Departement.find(params[:id])
authorize(@departement)
Expand All @@ -56,6 +64,12 @@ def set_communes
@communes = @departement.communes.include_statut_global
end

def set_date_range
@date_start = parse_date(params[:du]) || 1.week.ago.at_beginning_of_week
@date_end = parse_date(params[:au]) || Time.zone.today
@date_range = @date_start..@date_end
end

def set_tabs
anchor = :tabpanel
@tabs = [
Expand Down
36 changes: 36 additions & 0 deletions app/views/conservateurs/departements/_activite.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.fr-grid-row.fr-grid-row--gutters.fr-mb-4w
.fr-col
.fr-card
.fr-card__body
.fr-card__content
%h2.fr-card__title.fr-text-title--blue-france
Nouveaux messages : #{commune_messages_count.values.sum}
.fr-card__desc
- if commune_messages_count.size.positive?
%ul.fr-links-group.fr-pl-0.fr-mb-0
- commune_messages_count.each do |commune, count|
%li.co-flex.co-flex--space-between.co-flex--align-items-center.co-position-relative.fr-enlarge-link.fr-px-1w.fr-mx-n1w.fr-pt-1w.fr-mt-n1w
- title = "#{commune.nom} : #{Message.human_attribute_name(:count, count:)}"
= link_to commune.nom, conservateurs_commune_messages_path(commune), class: "fr-link", title:, "data-turbo-frame": :_top
= badge :info, class: "fr-badge--no-icon" do count end
- else
%p.co-text--italic Aucun message des communes entre #{l @date_start.to_date, format: :long_with_weekday} et #{l @date_end.to_date, format: :long_with_weekday}.

.fr-col
.fr-card
.fr-card__body
.fr-card__content
%h2.fr-card__title.fr-text-title--blue-france
Dossiers transmis : #{commune_dossiers_transmis.load.size}
.fr-card__desc
- if commune_dossiers_transmis.size.positive?
%ul.fr-links-group.fr-pl-0.fr-mb-0
- commune_dossiers_transmis.each do |commune|
%li.co-flex.co-flex--space-between.co-flex--align-items-center.co-position-relative.fr-enlarge-link.fr-px-1w.fr-mx-n1w.fr-pt-1w.fr-mt-n1w
= link_to commune.nom, conservateurs_commune_path(commune), class: "fr-link", title: "Recensement des objets de #{commune_name_with_objets_rouges_count(commune)}", "data-turbo-frame": :_top
- if commune.en_peril_count.positive?
= badge :warning do Objet.human_attribute_name(:en_peril_count, count: commune.en_peril_count) end
- if commune.disparus_count.positive?
= badge :warning do Objet.human_attribute_name(:disparus_count, count: commune.disparus_count) end
- else
%p.co-text--italic Aucun dossier transmis du #{l @date_start.to_date, format: :long_with_weekday} au #{l @date_end.to_date, format: :long_with_weekday}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
= form_with url: url_for, method: :GET, builder: FormBuilderDsfr, data: { turbo_action: :replace } do |f|
.fr-grid-row.fr-grid-row--gutters.co-flex--align-items-end.fr-mb-2w
.fr-col-md-4
.fr-input-group
= f.label :du, "Date de début"
= f.date_field :du, value: @date_start, class: "fr-input"
.fr-col-md-4
.fr-input-group
= f.label :au, "Date de fin"
= f.date_field :au, value: @date_end, class: "fr-input"
.fr-col-md-4
= f.button "Voir l'activité dans cette période", name: nil, class: "fr-btn fr-btn--secondary"
54 changes: 2 additions & 52 deletions app/views/conservateurs/departements/_tab_activite.html.haml
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
- commune_messages_count = @departement.commune_messages_count(@date_range)
- commune_dossiers_transmis = @departement.commune_dossiers_transmis(@date_range)

= turbo_frame_tag :activite do
= form_with url: url_for, method: :GET, builder: FormBuilderDsfr, data: { turbo_action: :replace } do |f|
.fr-grid-row.fr-grid-row--gutters.co-flex--align-items-end.fr-mb-2w
.fr-col-md-4
.fr-input-group
= f.label :du, "Date de début"
= f.date_field :du, value: @date_start, class: "fr-input"
.fr-col-md-4
.fr-input-group
= f.label :au, "Date de fin"
= f.date_field :au, value: @date_end, class: "fr-input"
.fr-col-md-4
= f.button "Voir l'activité dans cette période", name: nil, class: "fr-btn fr-btn--secondary"

.fr-grid-row.fr-grid-row--gutters
.fr-col
.fr-card
.fr-card__body
.fr-card__content
%h2.fr-card__title.fr-text-title--blue-france
Nouveaux messages : #{commune_messages_count.values.sum}
.fr-card__desc
- if commune_messages_count.size.positive?
%ul.fr-links-group.fr-pl-0.fr-mb-0
- commune_messages_count.each do |commune, count|
%li.co-flex.co-flex--space-between.co-flex--align-items-center.co-position-relative.fr-enlarge-link.fr-px-1w.fr-mx-n1w.fr-pt-1w.fr-mt-n1w
- title = "#{commune.nom} : #{Message.human_attribute_name(:count, count:)}"
= link_to commune.nom, conservateurs_commune_messages_path(commune), class: "fr-link", title:, "data-turbo-frame": :_top
= badge :info, class: "fr-badge--no-icon" do count end
- else
%p.co-text--italic Aucun message des communes entre #{l @date_start.to_date, format: :long_with_weekday} et #{l @date_end.to_date, format: :long_with_weekday}.

.fr-col
.fr-card
.fr-card__body
.fr-card__content
%h2.fr-card__title.fr-text-title--blue-france
Dossiers transmis : #{commune_dossiers_transmis.load.size}
.fr-card__desc
- if commune_dossiers_transmis.size.positive?
%ul.fr-links-group.fr-pl-0.fr-mb-0
- commune_dossiers_transmis.each do |commune|
%li.co-flex.co-flex--space-between.co-flex--align-items-center.co-position-relative.fr-enlarge-link.fr-px-1w.fr-mx-n1w.fr-pt-1w.fr-mt-n1w
= link_to commune.nom, conservateurs_commune_path(commune), class: "fr-link", title: "Recensement des objets de #{commune_name_with_objets_rouges_count(commune)}", "data-turbo-frame": :_top
- if commune.en_peril_count.positive?
= badge :warning do Objet.human_attribute_name(:en_peril_count, count: commune.en_peril_count) end
- if commune.disparus_count.positive?
= badge :warning do Objet.human_attribute_name(:disparus_count, count: commune.disparus_count) end
- else
%p.co-text--italic Aucun dossier transmis du #{l @date_start.to_date, format: :long_with_weekday} au #{l @date_end.to_date, format: :long_with_weekday}.
= render "selecteur_de_periode"
= render "activite", commune_messages_count: @departement.commune_messages_count(@date_range), commune_dossiers_transmis: @departement.commune_dossiers_transmis(@date_range)
12 changes: 12 additions & 0 deletions app/views/conservateurs/departements/activite.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- title = "Activité de vos départements"
- content_for(:head_title) { title }

%main#contenu.fr-container.fr-py-4w.co-min-height-50vh
%h1= title

= render "selecteur_de_periode"

- @departements.each do |departement|
%h2= departement.nom

= render "activite", commune_messages_count: departement.commune_messages_count(@date_range), commune_dossiers_transmis: departement.commune_dossiers_transmis(@date_range)
1 change: 1 addition & 0 deletions app/views/shared/_header.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

- if current_conservateur
- c.with_tool_link title: current_conservateur, path: edit_conservateur_registration_path, classes: ["fr-icon-settings-5-line"]
- c.with_tool_link title: "Activité des communes", path: activite_conservateurs_departements_path, classes: ["fr-icon-notification-3-line"]
- c.with_tool_link title: "Déconnexion", path: destroy_conservateur_session_path, classes: ["fr-icon-logout-box-r-line"], html_attributes: { "data-turbo-method": "DELETE" }

- if current_conservateur.departements.count > 2
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

namespace :conservateurs do
resources :departements, only: %i[index show] do
get :activite, on: :collection, action: :activite_des_departements
get :carte, on: :member
get :activite, on: :member
resources :campaigns, only: %i[new]
Expand Down

0 comments on commit 83d7e1a

Please sign in to comment.