Skip to content

Commit

Permalink
N'affiche plus les stats Comptes et Structures par défaut
Browse files Browse the repository at this point in the history
Pour une question de performance
  • Loading branch information
etienneCharignon committed Dec 14, 2023
1 parent 2411f3c commit 66e2f92
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
23 changes: 15 additions & 8 deletions app/admin/comptes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@
if: proc { can? :manage, Compte }

def filtrer_par_activation_structure(statut_activation, options = {})
options.merge!({ if: -> { can? :manage, Compte } })
options.merge!({ if: -> { params[:stats] && can?(:manage, Compte) } })
scope statut_activation, options do |scope|
scope.where(structure: Structure.send(statut_activation))
end
end

scope :all, { default: true, if: -> { can? :manage, Compte } }

scope :all, { default: true, if: -> { params[:stats] && can?(:manage, Compte) } }
filtrer_par_activation_structure(:pas_vraiment_utilisatrices)
filtrer_par_activation_structure(:non_activees)
filtrer_par_activation_structure(:actives)
Expand All @@ -80,6 +79,19 @@ def filtrer_par_activation_structure(statut_activation, options = {})
actions
end

action_item :stats, only: :index, if: -> { can? :manage, Compte } do
if params[:stats]
link_to t('.sans_stats'), admin_comptes_path
else
link_to t('.stats'), admin_comptes_path(stats: true)
end
end

sidebar :aide_filtres,
partial: 'admin/structures_locales/aide_filtres_sidebar',
only: :index,
if: -> { params[:stats] && can?(:manage, Compte) }

form do |f|
f.inputs do
f.input :prenom
Expand All @@ -106,11 +118,6 @@ def filtrer_par_activation_structure(statut_activation, options = {})
end
end

sidebar :aide_filtres,
partial: 'admin/structures_locales/aide_filtres_sidebar',
only: :index,
if: -> { can? :manage, Compte }

csv do
column :prenom
column :nom
Expand Down
26 changes: 17 additions & 9 deletions app/admin/structures_locales.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@
collection: proc { Structure.distinct.order(:region).pluck(:region) }
filter :created_at

scope :all, default: true
scope :sans_campagne
scope :pas_vraiment_utilisatrices
scope :non_activees
scope :actives
scope :inactives
scope :abandonnistes
scope :all, default: true, if: -> { params[:stats] }
scope :sans_campagne, if: -> { params[:stats] }
scope :pas_vraiment_utilisatrices, if: -> { params[:stats] }
scope :non_activees, if: -> { params[:stats] }
scope :actives, if: -> { params[:stats] }
scope :inactives, if: -> { params[:stats] }
scope :abandonnistes, if: -> { params[:stats] }

action_item :stats, only: :index do
if params[:stats]
link_to t('.sans_stats'), admin_structures_locales_path
else
link_to t('.stats'), admin_structures_locales_path(stats: true)
end
end

sidebar :aide_filtres, only: :index, if: -> { params[:stats] }

index do
column :nom
Expand Down Expand Up @@ -67,8 +77,6 @@
render partial: 'admin/structures/show', locals: { structure: resource }
end

sidebar :aide_filtres, only: :index

form partial: 'form'

controller do
Expand Down
1 change: 0 additions & 1 deletion app/models/compte.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Compte < ApplicationRecord

accepts_nested_attributes_for :structure


def display_name
nom_complet.presence || email
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/activeadmin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ fr:
statistiques: Voir les statistiques
resource:
index:
stats: Afficher les statistiques
sans_stats: Masquer les statistiques
rapport: Rapport
evenements: Évenements
sidebars:
Expand Down

0 comments on commit 66e2f92

Please sign in to comment.