refactor(dossier): improuve dossiers_count_summary

This commit is contained in:
Paul Chavard 2022-03-09 10:25:48 +01:00
parent 7c05a5fdee
commit 59b0f3961d
4 changed files with 41 additions and 39 deletions

View file

@ -231,14 +231,13 @@ class Instructeur < ApplicationRecord
def dossiers_count_summary(groupe_instructeur_ids) def dossiers_count_summary(groupe_instructeur_ids)
query = <<~EOF query = <<~EOF
SELECT SELECT
COUNT(DISTINCT dossiers.id) FILTER (where not archived AND NOT (dossiers.hidden_by_user_at IS NOT NULL AND state = 'en_construction') AND dossiers.state in ('en_construction', 'en_instruction') AND follows.id IS NULL) AS a_suivre, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND not archived AND dossiers.state in ('en_construction', 'en_instruction') AND follows.id IS NULL) AS a_suivre,
COUNT(DISTINCT dossiers.id) FILTER (where not archived AND dossiers.state in ('en_construction', 'en_instruction') AND follows.instructeur_id = :instructeur_id) AS suivis, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND not archived AND dossiers.state in ('en_construction', 'en_instruction') AND follows.instructeur_id = :instructeur_id) AS suivis,
COUNT(DISTINCT dossiers.id) FILTER (where not archived AND dossiers.state in ('accepte', 'refuse', 'sans_suite')) AS traites, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND not archived AND dossiers.state in ('accepte', 'refuse', 'sans_suite')) AS traites,
COUNT(DISTINCT dossiers.id) FILTER (where not archived AND NOT (dossiers.hidden_by_user_at IS NOT NULL AND state = 'en_construction') AND NOT (dossiers.hidden_by_administration_at IS NOT NULL)) AS tous, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND not archived) AS tous,
COUNT(DISTINCT dossiers.id) FILTER (where not archived AND (dossiers.hidden_by_administration_at IS NOT NULL AND dossiers.state in ('accepte', 'refuse', 'sans_suite') )) AS supprimes_recemment, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND archived) AS archives,
COUNT(DISTINCT dossiers.id) FILTER (where archived) AS archives, COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NOT NULL AND not archived AND dossiers.state in ('accepte', 'refuse', 'sans_suite')) AS supprimes_recemment,
COUNT(DISTINCT dossiers.id) FILTER (where COUNT(DISTINCT dossiers.id) FILTER (where dossiers.hidden_by_administration_at IS NULL AND procedures.procedure_expires_when_termine_enabled
procedures.procedure_expires_when_termine_enabled
AND ( AND (
dossiers.state in ('accepte', 'refuse', 'sans_suite') dossiers.state in ('accepte', 'refuse', 'sans_suite')
AND dossiers.processed_at + dossiers.conservation_extension + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now AND dossiers.processed_at + dossiers.conservation_extension + (procedures.duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now
@ -247,17 +246,18 @@ class Instructeur < ApplicationRecord
AND dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now AND dossiers.en_construction_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now
) )
) AS expirant ) AS expirant
FROM "dossiers" FROM dossiers
INNER JOIN "procedure_revisions" INNER JOIN procedure_revisions
ON "procedure_revisions"."id" = "dossiers"."revision_id" ON procedure_revisions.id = dossiers.revision_id
INNER JOIN "procedures" INNER JOIN procedures
ON "procedures"."id" = "procedure_revisions"."procedure_id" ON procedures.id = procedure_revisions.procedure_id
LEFT OUTER JOIN follows LEFT OUTER JOIN follows
ON follows.dossier_id = dossiers.id ON follows.dossier_id = dossiers.id
AND follows.unfollowed_at IS NULL AND follows.unfollowed_at IS NULL
WHERE "dossiers"."hidden_at" IS NULL WHERE dossiers.state != 'brouillon'
AND "dossiers"."state" != 'brouillon' AND dossiers.groupe_instructeur_id in (:groupe_instructeur_ids)
AND "dossiers"."groupe_instructeur_id" in (:groupe_instructeur_ids) AND dossiers.hidden_at IS NULL
AND NOT (dossiers.hidden_by_user_at IS NOT NULL AND dossiers.state = 'en_construction')
EOF EOF
sanitized_query = ActiveRecord::Base.sanitize_sql([ sanitized_query = ActiveRecord::Base.sanitize_sql([

View file

@ -1,21 +1,20 @@
- if dossier_count > 0 %span.dropdown
%span.dropdown %button.button.dropdown-button{ 'aria-expanded' => 'false', 'aria-controls' => 'download-menu' }
%button.button.dropdown-button{ 'aria-expanded' => 'false', 'aria-controls' => 'download-menu' } Télécharger tous les dossiers
Télécharger tous les dossiers #download-menu.dropdown-content.fade-in-down{ style: 'width: 450px' }
#download-menu.dropdown-content.fade-in-down{ style: 'width: 450px' } %ul.dropdown-items
%ul.dropdown-items - exports_list(exports).each do |(format, time_span_type, export)|
- exports_list(exports).each do |(format, time_span_type, export)| %li
%li - if export.nil?
- if export.nil? = link_to t("#{time_span_type}_#{format}_html", scope: [:instructeurs, :procedure, :export_stale]), download_export_instructeur_procedure_path(procedure, time_span_type: time_span_type, export_format: format), remote: true
= link_to t("#{time_span_type}_#{format}_html", scope: [:instructeurs, :procedure, :export_stale]), download_export_instructeur_procedure_path(procedure, time_span_type: time_span_type, export_format: format), remote: true - elsif export.ready?
- elsif export.ready? = link_to t("export_#{time_span_type}_ready_html", export_time: time_ago_in_words(export.updated_at), export_format: ".#{format}", scope: [:instructeurs, :procedure]), export.file.service_url, target: "_blank", rel: "noopener"
= link_to t("export_#{time_span_type}_ready_html", export_time: time_ago_in_words(export.updated_at), export_format: ".#{format}", scope: [:instructeurs, :procedure]), export.file.service_url, target: "_blank", rel: "noopener" - if export.old?
- if export.old? = button_to download_export_instructeur_procedure_path(procedure, export_format: format, time_span_type: time_span_type, force_export: true), class: "button small", style: "padding-right: 2px", title: t("#{time_span_type}_short", export_format: ".#{format}", scope: [:instructeurs, :procedure, :export_stale]), remote: true, method: :get, params: { export_format: format, time_span_type: time_span_type, force_export: true } do
= button_to download_export_instructeur_procedure_path(procedure, export_format: format, time_span_type: time_span_type, force_export: true), class: "button small", style: "padding-right: 2px", title: t("#{time_span_type}_short", export_format: ".#{format}", scope: [:instructeurs, :procedure, :export_stale]), remote: true, method: :get, params: { export_format: format, time_span_type: time_span_type, force_export: true } do .icon.retry
.icon.retry - else
- else %span{ 'data-export-poll-url': download_export_instructeur_procedure_path(procedure, export_format: format, no_progress_notification: true) }
%span{ 'data-export-poll-url': download_export_instructeur_procedure_path(procedure, export_format: format, no_progress_notification: true) } = t("export_#{time_span_type}_pending_html", export_time: time_ago_in_words(export.created_at), export_format: ".#{format}", scope: [:instructeurs, :procedure])
= t("export_#{time_span_type}_pending_html", export_time: time_ago_in_words(export.created_at), export_format: ".#{format}", scope: [:instructeurs, :procedure]) - if procedure.feature_enabled?(:archive_zip_globale)
- if procedure.feature_enabled?(:archive_zip_globale) %li
%li = link_to t(:download_archive, scope: [:instructeurs, :procedure]), instructeur_archives_path(procedure)
= link_to t(:download_archive, scope: [:instructeurs, :procedure]), instructeur_archives_path(procedure)

View file

@ -1,4 +1,6 @@
<%= render_to_element('.procedure-actions', partial: "download_dossiers", locals: { procedure: @procedure, exports: @exports, dossier_count: @dossier_count }) %> <% if @can_download_dossiers %>
<%= render_to_element('.procedure-actions', partial: "download_dossiers", locals: { procedure: @procedure, exports: @exports }) %>
<% end %>
<% @exports.each do |format, exports| %> <% @exports.each do |format, exports| %>
<% exports.each do |time_span_type, export| %> <% exports.each do |time_span_type, export| %>

View file

@ -10,7 +10,8 @@
= render partial: 'header', locals: { procedure: @procedure, statut: @statut } = render partial: 'header', locals: { procedure: @procedure, statut: @statut }
.procedure-actions .procedure-actions
= render partial: "download_dossiers", locals: { procedure: @procedure, exports: @exports, dossier_count: @tous_count + @archives_count } - if @can_download_dossiers
= render partial: "download_dossiers", locals: { procedure: @procedure, exports: @exports }
.container.flex= render partial: "tabs", locals: { procedure: @procedure, .container.flex= render partial: "tabs", locals: { procedure: @procedure,
statut: @statut, statut: @statut,
a_suivre_count: @a_suivre_count, a_suivre_count: @a_suivre_count,