From 46748091a61fe7fb00a2afd4ccbb040fbf77adb4 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Tue, 30 Jan 2024 10:16:24 +0000 Subject: [PATCH] =?UTF-8?q?Permet=20au=20Support=20de=20marquer=20une=20d?= =?UTF-8?q?=C3=A9marche=20comme=20mod=C3=A8le=20et=20de=20filtrer=20dans?= =?UTF-8?q?=20toutes=20les=20d=C3=A9marches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../administrateurs/procedures_controller.rb | 4 ++-- app/controllers/manager/procedures_controller.rb | 6 +++--- app/dashboards/procedure_dashboard.rb | 4 ++-- app/models/procedure_detail.rb | 4 ++-- app/models/procedures_filter.rb | 6 +++++- .../administrateurs/procedures/_detail.html.haml | 6 +++++- app/views/administrateurs/procedures/all.html.haml | 3 +++ app/views/layouts/all.html.haml | 10 ++++++++++ app/views/manager/procedures/show.html.erb | 6 +++--- config/locales/models/procedure/en.yml | 1 + config/locales/models/procedure/fr.yml | 1 + .../20240126071130_add_is_template_to_procedures.rb | 2 +- db/schema.rb | 6 +++--- .../administrateurs/procedures_controller_spec.rb | 11 +++++++++++ 14 files changed, 52 insertions(+), 18 deletions(-) diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index 2a40c1ce356..e48fe675d88 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -381,7 +381,6 @@ def detail def all @filter = ProceduresFilter.new(current_administrateur, params) all_procedures = filter_procedures(@filter).map { |p| ProcedureDetail.new(p) } - respond_to do |format| format.html do all_procedures = Kaminari.paginate_array(all_procedures.to_a, offset: 0, limit: ITEMS_PER_PAGE, total_count: all_procedures.count) @@ -417,13 +416,14 @@ def filter_procedures(filter) procedures_result = procedures_result.where(hidden_at_as_template: nil) procedures_result = procedures_result.where(aasm_state: filter.statuses) if filter.statuses.present? procedures_result = procedures_result.where("tags @> ARRAY[?]::text[]", filter.tags) if filter.tags.present? + procedures_result = procedures_result.where(template: true) if filter.template? procedures_result = procedures_result.where('published_at >= ?', filter.from_publication_date) if filter.from_publication_date.present? procedures_result = procedures_result.where(service: service) if filter.service_siret.present? procedures_result = procedures_result.where(service: services) if services procedures_result = procedures_result.where('unaccent(libelle) ILIKE unaccent(?)', "%#{filter.libelle}%") if filter.libelle.present? procedures_sql = procedures_result.to_sql - sql = "select id, libelle, published_at, aasm_state, estimated_dossiers_count, count(administrateurs_procedures.administrateur_id) as admin_count from administrateurs_procedures inner join procedures on procedures.id = administrateurs_procedures.procedure_id where procedures.id in (#{procedures_sql}) group by procedures.id order by published_at desc" + sql = "select id, libelle, published_at, aasm_state, estimated_dossiers_count, template, count(administrateurs_procedures.administrateur_id) as admin_count from administrateurs_procedures inner join procedures on procedures.id = administrateurs_procedures.procedure_id where procedures.id in (#{procedures_sql}) group by procedures.id order by published_at desc" ActiveRecord::Base.connection.execute(sql) end diff --git a/app/controllers/manager/procedures_controller.rb b/app/controllers/manager/procedures_controller.rb index fbbe8bb4869..6fb14e6d2ff 100644 --- a/app/controllers/manager/procedures_controller.rb +++ b/app/controllers/manager/procedures_controller.rb @@ -121,7 +121,7 @@ def add_tags end def update_template_status - if procedure.update(is_template_params) + if procedure.update(template_params) redirect_to manager_procedure_path(procedure), notice: 'Le statut de modèle a été mis à jour.' else flash.alert = procedure.errors.full_messages.join(', ') @@ -184,8 +184,8 @@ def tags_params params.require(:procedure).permit(:tags) end - def is_template_params - params.require(:procedure).permit(:is_template) + def template_params + params.require(:procedure).permit(:template) end def tags_csv_file diff --git a/app/dashboards/procedure_dashboard.rb b/app/dashboards/procedure_dashboard.rb index f6b9a3c9308..b7d889d3758 100644 --- a/app/dashboards/procedure_dashboard.rb +++ b/app/dashboards/procedure_dashboard.rb @@ -48,7 +48,7 @@ class ProcedureDashboard < Administrate::BaseDashboard piece_justificative_multiple: Field::Boolean, replaced_by_procedure_id: Field::String, tags: Field::Text, - is_template: Field::Boolean + template: Field::Boolean }.freeze # COLLECTION_ATTRIBUTES @@ -80,7 +80,7 @@ class ProcedureDashboard < Administrate::BaseDashboard :libelle, :description, :tags, - :is_template, + :template, :lien_site_web, :organisation, :zones, diff --git a/app/models/procedure_detail.rb b/app/models/procedure_detail.rb index d3dbf3dfb06..c590787b330 100644 --- a/app/models/procedure_detail.rb +++ b/app/models/procedure_detail.rb @@ -1,8 +1,8 @@ -ProcedureDetail = Struct.new(:id, :libelle, :published_at, :aasm_state, :estimated_dossiers_count, :admin_count, keyword_init: true) do +ProcedureDetail = Struct.new(:id, :libelle, :published_at, :aasm_state, :estimated_dossiers_count, :admin_count, :template, keyword_init: true) do include SpreadsheetArchitect def spreadsheet_columns - [:id, :libelle, :published_at, :aasm_state, :admin_count].map do |attribute| + [:id, :libelle, :published_at, :aasm_state, :admin_count, :template].map do |attribute| [I18n.t(attribute, scope: 'activerecord.attributes.procedure_export'), attribute] end end diff --git a/app/models/procedures_filter.rb b/app/models/procedures_filter.rb index 988003257f6..bc3213da77f 100644 --- a/app/models/procedures_filter.rb +++ b/app/models/procedures_filter.rb @@ -8,7 +8,7 @@ def initialize(admin, params) params[:zone_ids] = admin.zones.pluck(:id) if params[:zone_ids] == 'admin_default' - @params = params.permit(:page, :libelle, :email, :from_publication_date, :service_siret, :service_departement, tags: [], zone_ids: [], statuses: []) + @params = params.permit(:page, :libelle, :email, :from_publication_date, :service_siret, :service_departement, :template, tags: [], zone_ids: [], statuses: []) end def admin_zones @@ -35,6 +35,10 @@ def tags params[:tags].compact_blank.uniq if params[:tags].present? end + def template? + ActiveRecord::Type::Boolean.new.cast(params[:template]) + end + def service_siret params[:service_siret].presence end diff --git a/app/views/administrateurs/procedures/_detail.html.haml b/app/views/administrateurs/procedures/_detail.html.haml index beb4783c6a6..b2e89c4b7d2 100644 --- a/app/views/administrateurs/procedures/_detail.html.haml +++ b/app/views/administrateurs/procedures/_detail.html.haml @@ -6,7 +6,11 @@ = button_to detail_admin_procedure_path(procedure["id"]), method: :post, params:, title:, class: [icon, "fr-icon--sm fr-mr-1w fr-mb-1w fr-text-action-high--blue-france fr-btn fr-btn--tertiary-no-outline" ] do = title - %td= procedure.libelle + %td + - if procedure.template + %p.fr-badge.fr-badge--info.fr-badge--sm= "Modèle DS" + %br + = procedure.libelle %td= procedure.id %td= procedure.estimated_dossiers_count %td= procedure.administrateurs.count diff --git a/app/views/administrateurs/procedures/all.html.haml b/app/views/administrateurs/procedures/all.html.haml index 0484ce14e42..41eea5eb6e3 100644 --- a/app/views/administrateurs/procedures/all.html.haml +++ b/app/views/administrateurs/procedures/all.html.haml @@ -41,6 +41,9 @@ - @filter.tags.each do |tag| = link_to tag, all_admin_procedures_path(@filter.without(:tags, tag)), class: 'fr-tag fr-tag--dismiss fr-mb-1w' - params[:tags].delete(tag) + - if @filter.template? + .selected-template.fr-mb-2w + = link_to "Modèle DS", all_admin_procedures_path(@filter.without(:template)), 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' diff --git a/app/views/layouts/all.html.haml b/app/views/layouts/all.html.haml index bb581b79e7e..9fac8e5477c 100644 --- a/app/views/layouts/all.html.haml +++ b/app/views/layouts/all.html.haml @@ -100,6 +100,16 @@ - if @filter.tags.present? - @filter.tags.each do |tag| = f.hidden_field :tags, value: tag, multiple: true, id: "tag-#{tag.tr(' ', '_')}" + %li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" } + .fr-mb-1w + %button{ 'data-action': 'expand#toggle' } + %span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' } + Démarches modèles + .fr-ml-1w.hidden{ 'data-expand-target': 'content' } + .fr-checkbox-group.fr-ml-2w.fr-py-1w + = f.check_box :template, class: 'fr-input' + = f.label :template, 'Modèle DS', class: 'fr-label' + .fr-col-9 = yield(:results) = render template: 'layouts/application' diff --git a/app/views/manager/procedures/show.html.erb b/app/views/manager/procedures/show.html.erb index 51630eaefe6..f3ab35375cb 100644 --- a/app/views/manager/procedures/show.html.erb +++ b/app/views/manager/procedures/show.html.erb @@ -104,10 +104,10 @@ as well as a link to its edit page. <% end %> <% end %> - <% if attribute.name == 'is_template' %> + <% if attribute.name == 'template' %> <%= form_for procedure, url: update_template_status_manager_procedure_path(procedure), html: { method: :patch, class: 'procedure-form__column--form fr-background-alt--blue-france mt-1', id: 'template-form' } do |f| %> - <%= f.label :is_template, 'Marquer comme modèle', for: 'is_template_checkbox' %> - <%= f.check_box :is_template, id: 'is_template_checkbox', onchange: 'this.form.submit();' %> + <%= f.label :template, 'Marquer comme modèle', for: 'template_checkbox' %> + <%= f.check_box :template, id: 'template_checkbox', onchange: 'this.form.submit();' %> <% end %> <% end %> diff --git a/config/locales/models/procedure/en.yml b/config/locales/models/procedure/en.yml index d02ff7c63f8..e999c6afa05 100644 --- a/config/locales/models/procedure/en.yml +++ b/config/locales/models/procedure/en.yml @@ -51,6 +51,7 @@ en: published_at: Publication date aasm_state: Status admin_count: Administrators count + template: Is a template errors: models: procedure: diff --git a/config/locales/models/procedure/fr.yml b/config/locales/models/procedure/fr.yml index e88bb2fcc8b..5fa059494a2 100644 --- a/config/locales/models/procedure/fr.yml +++ b/config/locales/models/procedure/fr.yml @@ -57,6 +57,7 @@ fr: published_at: 'Date de publication' aasm_state: 'Statut' admin_count: 'Nb administrateurs' + template: 'Est un modèle' errors: models: procedure: diff --git a/db/migrate/20240126071130_add_is_template_to_procedures.rb b/db/migrate/20240126071130_add_is_template_to_procedures.rb index 17555ad68d6..72586bf35cb 100644 --- a/db/migrate/20240126071130_add_is_template_to_procedures.rb +++ b/db/migrate/20240126071130_add_is_template_to_procedures.rb @@ -1,5 +1,5 @@ class AddIsTemplateToProcedures < ActiveRecord::Migration[7.0] def change - add_column :procedures, :is_template, :boolean, default: false, null: false + add_column :procedures, :template, :boolean, default: false, null: false end end diff --git a/db/schema.rb b/db/schema.rb index 44c67f36ebc..19982ebfce9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -867,7 +867,6 @@ t.datetime "hidden_at", precision: nil t.datetime "hidden_at_as_template", precision: nil t.boolean "instructeurs_self_management_enabled" - t.boolean "is_template", default: false, null: false t.boolean "juridique_required", default: true t.string "libelle" t.string "lien_demarche" @@ -891,6 +890,7 @@ t.bigint "service_id" t.jsonb "sva_svr", default: {}, null: false t.text "tags", default: [], array: true + t.boolean "template", default: false, null: false t.datetime "test_started_at", precision: nil t.datetime "unpublished_at", precision: nil t.datetime "updated_at", precision: nil, null: false @@ -1177,7 +1177,7 @@ add_foreign_key "bulk_messages_groupe_instructeurs", "bulk_messages" add_foreign_key "bulk_messages_groupe_instructeurs", "groupe_instructeurs" add_foreign_key "champs", "champs", column: "parent_id" -add_foreign_key "champs", "dossiers" + add_foreign_key "champs", "dossiers" add_foreign_key "champs", "etablissements" add_foreign_key "champs", "types_de_champ" add_foreign_key "closed_mails", "procedures" @@ -1198,7 +1198,7 @@ add_foreign_key "dossiers", "groupe_instructeurs" add_foreign_key "dossiers", "procedure_revisions", column: "revision_id" add_foreign_key "dossiers", "users" -add_foreign_key "etablissements", "dossiers" + add_foreign_key "etablissements", "dossiers" add_foreign_key "experts", "users" add_foreign_key "experts_procedures", "experts" add_foreign_key "experts_procedures", "procedures" diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index e76d035d5ec..3499c679a1b 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -259,6 +259,17 @@ end end + context 'with template procedures' do + let!(:template_procedure) { create(:procedure, :published, template: true) } + let!(:other_procedure) { create(:procedure, :published, template: false) } + + it 'identifies a procedure as a template' do + get :all, params: { template: '1' } + expect(assigns(:procedures).any? { |p| p.id == template_procedure.id }).to be_truthy + expect(assigns(:procedures).any? { |p| p.id == other_procedure.id }).to be_falsey + end + end + context 'with libelle search' do let!(:procedure1) { create(:procedure, :published, libelle: 'Demande de subvention') } let!(:procedure2) { create(:procedure, :published, libelle: "Fonds d'aide public « Prime Entrepreneurs des Quartiers »") }