[Fix #1182] Add a “create new procedure from an existing one” feature

This commit is contained in:
gregoirenovel 2018-01-04 18:36:45 +01:00
parent 27a8aba53e
commit bf5e21d6de
4 changed files with 43 additions and 0 deletions

View file

@ -175,6 +175,20 @@ class Admin::ProceduresController < AdminController
redirect_to admin_procedures_path
end
def new_from_existing
procedures_with_more_than_30_dossiers_ids = Procedure
.publiees_ou_archivees
.joins(:dossiers)
.group("procedures.id")
.having("count(dossiers.id) > ?", 30)
.pluck('procedures.id')
@grouped_procedures = Procedure
.where(id: procedures_with_more_than_30_dossiers_ids)
.group_by(&:administrateur)
.sort_by { |a, _| a.created_at }
end
def active_class
@active_class = 'active'
end

View file

@ -1,3 +1,7 @@
.row.white-back
%a{ href: '/admin/procedures/new_from_existing', class: 'btn-sm btn-primary' }
Créer une nouvelle procédure à partir d'une procédure existante
.row.white-back
%h2
= t('dynamics.admin.dossiers.tableau_de_bord.nouvelle_procedure')

View file

@ -0,0 +1,21 @@
.row.white-back
%h2
Créer une nouvelle procédure à partir d'une procédure existante
.section.section-label
Pour rechercher dans cette liste, utilisez la fonction "Recherche" de votre navigateur (CTRL+F ou command+F)
%br
%br
- @grouped_procedures.each do |_, procedures|
%b
= procedures.first.organisation
%table{ style: 'margin-bottom: 40px;' }
- procedures.sort_by(&:id).each do |procedure|
%tr{ style: 'height: 36px;' }
%td{ style: 'width: 750px;' }
= procedure.libelle
%td{ style: 'padding-right: 10px; padding-left: 10px; width: 60px;' }
- if !procedure.archivee?
= link_to('Tester', commencer_path(procedure_path: procedure.path), target: "_blank")
%td
= link_to('Cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-sm btn-primary clone-btn')

View file

@ -117,6 +117,10 @@ Rails.application.routes.draw do
patch 'change_dossier_state' => 'change_dossier_state#change'
resources :procedures do
collection do
get 'new_from_existing' => 'procedures#new_from_existing', as: :new_from_existing
end
member do
post :hide
end