list all admins

This commit is contained in:
Christophe Robillard 2022-11-08 15:59:00 +01:00
parent 3b2df47ba0
commit c96781cfad
3 changed files with 137 additions and 58 deletions

View file

@ -5,7 +5,7 @@ class ProceduresFilter
def initialize(admin, params) def initialize(admin, params)
@admin = admin @admin = admin
@params = params.permit(:page, :from_publication_date, zone_ids: [], statuses: []) @params = params.permit(:page, :from_publication_date, :view_admins, zone_ids: [], statuses: [])
end end
def admin_zones def admin_zones
@ -36,6 +36,10 @@ class ProceduresFilter
nil nil
end end
def view_admins?
params[:view_admins] == 'true'
end
def zone_filtered?(zone_id) def zone_filtered?(zone_id)
zone_ids&.map(&:to_i)&.include?(zone_id) zone_ids&.map(&:to_i)&.include?(zone_id)
end end
@ -53,12 +57,32 @@ class ProceduresFilter
end end
end end
def with_view_admins(view_admins)
params.to_h.merge(view_admins: view_admins)
end
def procedures_result def procedures_result
return @procedures_result if @procedures_result return @procedures_result if @procedures_result
@procedures_result = Procedure.joins(:procedures_zones).publiees_ou_closes @procedures_result = paginate(filter_procedures, published_at: :desc)
@procedures_result = @procedures_result.where(procedures_zones: { zone_id: zone_ids }) if zone_ids.present? end
@procedures_result = @procedures_result.where(aasm_state: statuses) if statuses.present?
@procedures_result = @procedures_result.where('published_at >= ?', from_publication_date) if from_publication_date.present? def admins_result
@procedures_result = @procedures_result.page(params[:page]).per(ITEMS_PER_PAGE).order(published_at: :desc) return @admins_result if @admins_result
@admins_result = Administrateur.includes(:user).where(id: AdministrateursProcedure.where(procedure: filter_procedures).select(:administrateur_id))
@admins_result = paginate(@admins_result, 'users.email')
end
private
def filter_procedures
procedures_result = Procedure.joins(:procedures_zones).publiees_ou_closes
procedures_result = procedures_result.where(procedures_zones: { zone_id: zone_ids }) if zone_ids.present?
procedures_result = procedures_result.where(aasm_state: statuses) if statuses.present?
procedures_result = procedures_result.where('published_at >= ?', from_publication_date) if from_publication_date.present?
procedures_result
end
def paginate(result, ordered_by)
result.page(params[:page]).per(ITEMS_PER_PAGE).order(ordered_by)
end end
end end

View file

@ -64,52 +64,96 @@
= b.label(class: 'fr-label') { t b.text, scope: 'activerecord.attributes.procedure.aasm_state' } = b.label(class: 'fr-label') { t b.text, scope: 'activerecord.attributes.procedure.aasm_state' }
.fr-col-9 .fr-col-9
.main-filter-header.fr-my-3w - if @filter.view_admins?
.search .main-filter-header.fr-my-3w
= link_to 'Voir la liste des administeurs', '#', class: 'fr-btn fr-btn--secondary btn-admins' .search
.fr-table.fr-table--bordered = link_to 'Voir la liste des démarches', all_admin_procedures_path(@filter.with_view_admins(false)), class: 'fr-btn fr-btn--secondary btn-admins'
%table#all-demarches .fr-table.fr-table--bordered
%caption %table#all-admins
= "#{@filter.procedures_result.total_count} démarches" %caption
%span.hidden.fr-icon-ball-pen-fill{ 'aria-hidden': 'true', 'data-autosubmit-target': 'spinner' } = "#{@filter.admins_result.total_count} administrateurs"
- if @filter.selected_zones.present? %span.hidden.fr-icon-ball-pen-fill{ 'aria-hidden': 'true', 'data-autosubmit-target': 'spinner' }
.selected-zones.fr-mb-2w - if @filter.selected_zones.present?
- @filter.selected_zones.each do |zone| .selected-zones.fr-mb-2w
= link_to zone.current_label, all_admin_procedures_path(@filter.without(:zone_ids, zone.id)), class: 'fr-tag fr-tag--dismiss fr-mb-1w' - @filter.selected_zones.each do |zone|
- if @filter.statuses.present? = link_to zone.current_label, all_admin_procedures_path(@filter.without(:zone_ids, zone.id)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
.selected-statuses.fr-mb-2w - if @filter.statuses.present?
- @filter.statuses.each do |status| .selected-statuses.fr-mb-2w
= link_to status, all_admin_procedures_path(@filter.without(:statuses, status)), class: 'fr-tag fr-tag--dismiss fr-mb-1w' - @filter.statuses.each do |status|
- if @filter.from_publication_date.present? = link_to status, all_admin_procedures_path(@filter.without(:statuses, status)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
.selected-from-publication-date.fr-mb-2w - if @filter.from_publication_date.present?
= link_to "Depuis le #{l(@filter.from_publication_date)}", all_admin_procedures_path(@filter.without(:from_publication_date)), class: 'fr-tag fr-tag--dismiss fr-mb-1w' .selected-from-publication-date.fr-mb-2w
= paginate @filter.procedures_result, views_prefix: 'administrateurs' = link_to "Depuis le #{l(@filter.from_publication_date)}", all_admin_procedures_path(@filter.without(:from_publication_date)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
%thead = paginate @filter.admins_result, views_prefix: 'administrateurs'
%tr %thead
%th{ scope: 'col' } %tr
%th{ scope: 'col' } Démarche %th{ scope: 'col' }
%th{ scope: 'col' } N° %th{ scope: 'col' } Administrateurs
%th{ scope: 'col' } Administrateurs %th{ scope: 'col' } Nb démarches
%th{ scope: 'col' } Statut %th{ scope: 'col' } Inscrit le
%th{ scope: 'col' } Date - @filter.admins_result.each do |admin|
- @filter.procedures_result.each do |procedure| %tbody{ 'data-controller': 'expand' }
%tbody{ 'data-controller': 'expand' } %tr.procedure{ 'data-action': 'click->expand#toggle' }
%tr.procedure{ 'data-action': 'click->expand#toggle' } %td
%td %button.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-mb-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
%button.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-mb-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' } %td= admin.email
%td= procedure.libelle %td= admin.procedures.count
%td= procedure.id %td= l(admin.created_at, format: :message_date_without_time)
%td= procedure.administrateurs.count %tr.hidden{ 'data-expand-target': 'content' }
%td= t procedure.aasm_state, scope: 'activerecord.attributes.procedure.aasm_state' %td.fr-highlight--beige-gris-galet{ colspan: '6' }
%td= l(procedure.published_at, format: :message_date_without_time) .fr-container
%tr.hidden{ 'data-expand-target': 'content' } .fr-col-12.fr-mr-1w
%td.fr-highlight--beige-gris-galet{ colspan: '6' } %ul
.fr-container - admin.procedures.each do |procedure|
.fr-grid-row %li= procedure.libelle
.fr-col-6 .fr-mt-2w= paginate @filter.admins_result, views_prefix: 'administrateurs'
- procedure.zones.uniq.each do |zone| - else
= zone.label_at(procedure.published_or_created_at) .main-filter-header.fr-my-3w
.fr-col-6 .search
- procedure.administrateurs.uniq.each do |admin| = link_to 'Voir la liste des administrateurs', all_admin_procedures_path(@filter.with_view_admins(true)), class: 'fr-btn fr-btn--secondary btn-admins'
= admin.email .fr-table.fr-table--bordered
.fr-mt-2w= paginate @filter.procedures_result, views_prefix: 'administrateurs' %table#all-demarches
%caption
= "#{@filter.procedures_result.total_count} démarches"
%span.hidden.fr-icon-ball-pen-fill{ 'aria-hidden': 'true', 'data-autosubmit-target': 'spinner' }
- if @filter.selected_zones.present?
.selected-zones.fr-mb-2w
- @filter.selected_zones.each do |zone|
= link_to zone.current_label, all_admin_procedures_path(@filter.without(:zone_ids, zone.id)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- if @filter.statuses.present?
.selected-statuses.fr-mb-2w
- @filter.statuses.each do |status|
= link_to status, all_admin_procedures_path(@filter.without(:statuses, status)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- if @filter.from_publication_date.present?
.selected-from-publication-date.fr-mb-2w
= link_to "Depuis #{l(@filter.from_publication_date)}", all_admin_procedures_path(@filter.without(:from_publication_date)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
= paginate @filter.procedures_result, views_prefix: 'administrateurs'
%thead
%tr
%th{ scope: 'col' }
%th{ scope: 'col' } Démarche
%th{ scope: 'col' } N°
%th{ scope: 'col' } Administrateurs
%th{ scope: 'col' } Statut
%th{ scope: 'col' } Date
- @filter.procedures_result.each do |procedure|
%tbody{ 'data-controller': 'expand' }
%tr.procedure{ 'data-action': 'click->expand#toggle' }
%td
%button.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-mb-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
%td= procedure.libelle
%td= procedure.id
%td= procedure.administrateurs.count
%td= t procedure.aasm_state, scope: 'activerecord.attributes.procedure.aasm_state'
%td= l(procedure.published_at, format: :message_date_without_time)
%tr.hidden{ 'data-expand-target': 'content' }
%td.fr-highlight--beige-gris-galet{ colspan: '6' }
.fr-container
.fr-grid-row
.fr-col-6
- procedure.zones.uniq.each do |zone|
= zone.label_at(procedure.published_or_created_at)
.fr-col-6
- procedure.administrateurs.uniq.each do |admin|
= admin.email
.fr-mt-2w= paginate @filter.procedures_result, views_prefix: 'administrateurs'

View file

@ -5,15 +5,26 @@ describe ProceduresFilter do
context 'without filter' do context 'without filter' do
let(:filters) { {} } let(:filters) { {} }
let!(:draft_procedure) { create(:procedure) } let!(:draft_procedure) { create(:procedure, administrateur: admin3) }
let!(:published_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2) } let!(:published_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2, administrateur: admin1) }
let!(:closed_procedure) { create(:procedure, :closed) } let!(:closed_procedure) { create(:procedure, :closed, administrateur: admin2) }
let(:admin1) { create(:administrateur) }
let(:admin2) { create(:administrateur) }
let(:admin3) { create(:administrateur) }
it 'returns only published and closed procedures' do it 'returns only published and closed procedures' do
expect(subject.procedures_result).to include(published_procedure) expect(subject.procedures_result).to include(published_procedure)
expect(subject.procedures_result).to include(closed_procedure) expect(subject.procedures_result).to include(closed_procedure)
expect(subject.procedures_result).not_to include(draft_procedure) expect(subject.procedures_result).not_to include(draft_procedure)
end end
context 'with view_admins param' do
it 'returns admins of the procedures' do
expect(subject.admins_result).to include(admin1)
expect(subject.admins_result).to include(admin2)
expect(subject.admins_result).not_to include(admin3)
end
end
end end
context 'with zone filter' do context 'with zone filter' do