From 11f8e7a3f9d9b3c6c532de383558dd9f879bf39d Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 17 Apr 2019 16:33:24 +0200 Subject: [PATCH 1/2] Small refactor --- app/controllers/manager/procedures_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/manager/procedures_controller.rb b/app/controllers/manager/procedures_controller.rb index d5bef5228..dd3aa1401 100644 --- a/app/controllers/manager/procedures_controller.rb +++ b/app/controllers/manager/procedures_controller.rb @@ -1,14 +1,12 @@ module Manager class ProceduresController < Manager::ApplicationController def whitelist - procedure = Procedure.find(params[:id]) procedure.whitelist! flash[:notice] = "Démarche whitelistée." redirect_to manager_procedure_path(procedure) end def draft - procedure = Procedure.find(params[:id]) if procedure.dossiers.empty? procedure.draft! flash[:notice] = "La démarche a bien été passée en brouillon." @@ -19,14 +17,12 @@ module Manager end def hide - procedure = Procedure.find(params[:id]) procedure.hide! flash[:notice] = "La démarche a bien été supprimée, en cas d'erreur contactez un développeur." redirect_to manager_procedures_path end def add_administrateur - procedure = Procedure.find(params[:id]) administrateur = Administrateur.find_by(email: params[:email]) if administrateur procedure.administrateurs << administrateur @@ -36,5 +32,11 @@ module Manager end redirect_to manager_procedure_path(procedure) end + + private + + def procedure + Procedure.find(params[:id]) + end end end From 1d051dc3ef744e7452d6247982aacacc0434f7f1 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 17 Apr 2019 16:36:57 +0200 Subject: [PATCH 2/2] Can change a piece_justificative_template on a type_de_champ --- .../manager/procedures_controller.rb | 17 +++++++++++++++++ .../_show.html.haml | 10 ++++++++++ config/routes.rb | 1 + 3 files changed, 28 insertions(+) diff --git a/app/controllers/manager/procedures_controller.rb b/app/controllers/manager/procedures_controller.rb index dd3aa1401..b3241429f 100644 --- a/app/controllers/manager/procedures_controller.rb +++ b/app/controllers/manager/procedures_controller.rb @@ -33,10 +33,27 @@ module Manager redirect_to manager_procedure_path(procedure) end + def change_piece_justificative_template + if type_de_champ.update(type_de_champ_params) + flash[:notice] = "Le modèle est mis à jour." + else + flash[:alert] = type_de_champ.errors.full_messages.join(', ') + end + redirect_to manager_procedure_path(procedure) + end + private def procedure Procedure.find(params[:id]) end + + def type_de_champ + TypeDeChamp.find(params[:type_de_champ][:id]) + end + + def type_de_champ_params + params.require(:type_de_champ).permit(:piece_justificative_template) + end end end diff --git a/app/views/fields/types_de_champ_collection_field/_show.html.haml b/app/views/fields/types_de_champ_collection_field/_show.html.haml index 86b298e54..f70d88c66 100644 --- a/app/views/fields/types_de_champ_collection_field/_show.html.haml +++ b/app/views/fields/types_de_champ_collection_field/_show.html.haml @@ -5,6 +5,7 @@ %td.cell-label Libelle %td.cell-label Type de champ %td.cell-label Rempli + %td.cell-label Modifier le modèle %tbody - field.data.order(:order_place).each do |f| %tr @@ -20,5 +21,14 @@ vide - else rempli + + %td.cell-data + - if f.type_champ == 'piece_justificative' + = form_for f, + url: change_piece_justificative_template_manager_procedure_path, + method: :post do |form| + = form.hidden_field :id + = form.file_field :piece_justificative_template + = form.submit 'modifier' - else Aucun diff --git a/config/routes.rb b/config/routes.rb index 20cd28d8a..33493af6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,7 @@ Rails.application.routes.draw do post 'draft', on: :member post 'hide', on: :member post 'add_administrateur', on: :member + post 'change_piece_justificative_template', on: :member end resources :dossiers, only: [:index, :show] do