Permet au Support de marquer une démarche comme modèle et de filtrer dans toutes les démarches
This commit is contained in:
parent
94389bb66d
commit
46748091a6
14 changed files with 52 additions and 18 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
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ module Manager
|
|||
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 @@ module Manager
|
|||
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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -104,10 +104,10 @@ as well as a link to its edit page.
|
|||
<button class="mt-1">Ajouter des tags</button>
|
||||
<% 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 %>
|
||||
</dd>
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -867,7 +867,6 @@ ActiveRecord::Schema[7.0].define(version: 2024_01_26_071130) do
|
|||
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 @@ ActiveRecord::Schema[7.0].define(version: 2024_01_26_071130) 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