Merge pull request #9939 from demarches-simplifiees/feat/9937
ETQ Super-Admin, je souhaite marquer une démarche comme modèle
This commit is contained in:
commit
17a471e880
15 changed files with 70 additions and 8 deletions
|
@ -381,7 +381,6 @@ module Administrateurs
|
|||
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 @@ module Administrateurs
|
|||
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
|
||||
|
||||
|
|
|
@ -120,6 +120,14 @@ module Manager
|
|||
redirect_to manager_procedure_path(procedure)
|
||||
end
|
||||
|
||||
def update_template_status
|
||||
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(', ')
|
||||
end
|
||||
end
|
||||
|
||||
def import_data
|
||||
end
|
||||
|
||||
|
@ -176,6 +184,10 @@ module Manager
|
|||
params.require(:procedure).permit(:tags)
|
||||
end
|
||||
|
||||
def template_params
|
||||
params.require(:procedure).permit(:template)
|
||||
end
|
||||
|
||||
def tags_csv_file
|
||||
params[:tags_csv_file]
|
||||
end
|
||||
|
|
|
@ -47,7 +47,8 @@ class ProcedureDashboard < Administrate::BaseDashboard
|
|||
estimated_duration_visible: Field::Boolean,
|
||||
piece_justificative_multiple: Field::Boolean,
|
||||
replaced_by_procedure_id: Field::String,
|
||||
tags: Field::Text
|
||||
tags: Field::Text,
|
||||
template: Field::Boolean
|
||||
}.freeze
|
||||
|
||||
# COLLECTION_ATTRIBUTES
|
||||
|
@ -79,6 +80,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
|
|||
:libelle,
|
||||
:description,
|
||||
:tags,
|
||||
:template,
|
||||
:lien_site_web,
|
||||
:organisation,
|
||||
:zones,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,7 +8,7 @@ class ProceduresFilter
|
|||
|
||||
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 @@ class ProceduresFilter
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -89,6 +89,7 @@ as well as a link to its edit page.
|
|||
<% end %>
|
||||
<% end %>
|
||||
<% if attribute.name == 'tags' %>
|
||||
|
||||
<%= form_for procedure, url: add_tags_manager_procedure_path(procedure), html: { class: 'form procedure-form__column--form fr-background-alt--blue-france mt-1' } do %>
|
||||
<%= hidden_field_tag 'procedure[tags]', nil %>
|
||||
<%= react_component("ComboMultiple",
|
||||
|
@ -103,6 +104,12 @@ as well as a link to its edit page.
|
|||
<button class="mt-1">Ajouter des tags</button>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% 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 :template, 'Marquer comme modèle', for: 'template_checkbox' %>
|
||||
<%= f.check_box :template, id: 'template_checkbox', onchange: 'this.form.submit();' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</dd>
|
||||
<% end %>
|
||||
<dd class="attribute-data">
|
||||
|
|
|
@ -51,6 +51,7 @@ en:
|
|||
published_at: Publication date
|
||||
aasm_state: Status
|
||||
admin_count: Administrators count
|
||||
template: Is a template
|
||||
errors:
|
||||
models:
|
||||
procedure:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -24,6 +24,7 @@ Rails.application.routes.draw do
|
|||
post 'add_administrateur_with_confirmation', on: :member
|
||||
post 'change_piece_justificative_template', on: :member
|
||||
patch 'add_tags', on: :member
|
||||
patch 'update_template_status', on: :member
|
||||
get 'export_mail_brouillons', on: :member
|
||||
resources :confirmation_urls, only: :new
|
||||
resources :administrateur_confirmations, only: [:new, :create]
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddIsTemplateToProcedures < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :procedures, :template, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_01_23_085909) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_01_26_071130) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -890,6 +890,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_01_23_085909) do
|
|||
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
|
||||
|
|
|
@ -259,6 +259,17 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
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 »") }
|
||||
|
|
Loading…
Reference in a new issue