From 5667cfe74740374e93a4d4d025be49fa01dd16ab Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 11 Apr 2018 14:35:52 +0200 Subject: [PATCH] [fix #675] upload notice in DS --- app/controllers/admin/procedures_controller.rb | 2 +- app/helpers/notice_url_helper.rb | 9 +++++++++ app/models/procedure.rb | 2 ++ .../admin/procedures/_informations.html.haml | 16 +++++++++++++++- app/views/admin/procedures/edit.html.haml | 2 +- app/views/new_user/dossiers/modifier.html.haml | 4 ++-- app/views/users/description/_show.html.haml | 4 ++-- 7 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 app/helpers/notice_url_helper.rb diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index a159762b0..d761f78ec 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -250,7 +250,7 @@ class Admin::ProceduresController < AdminController private def procedure_params - editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :lien_notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on] + editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on] if @procedure.try(:locked?) params.require(:procedure).permit(*editable_params) else diff --git a/app/helpers/notice_url_helper.rb b/app/helpers/notice_url_helper.rb new file mode 100644 index 000000000..337cb228a --- /dev/null +++ b/app/helpers/notice_url_helper.rb @@ -0,0 +1,9 @@ +module NoticeUrlHelper + def notice_url(procedure) + if procedure.notice.attached? + url_for(procedure.notice) + elsif procedure.lien_notice.present? + procedure.lien_notice + end + end +end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 2c9244d64..b76eb3393 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -22,6 +22,8 @@ class Procedure < ApplicationRecord has_one :refused_mail, class_name: "Mails::RefusedMail", dependent: :destroy has_one :without_continuation_mail, class_name: "Mails::WithoutContinuationMail", dependent: :destroy + has_one_attached :notice + delegate :use_api_carto, to: :module_api_carto accepts_nested_attributes_for :types_de_champ, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index ba6ccefde..a42154928 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -2,7 +2,7 @@ .alert.alert-info Cette procédure est publiée, certains éléments de la description ne sont plus modifiables -- { libelle: 'Libellé*', description: 'Description*', organisation: 'Organisme*', direction: 'Direction', lien_site_web: 'Lien site internet', lien_notice: 'Lien notice', web_hook_url: 'Lien de rappel HTTP' }.each do |key, value| +- { libelle: 'Libellé*', description: 'Description*', organisation: 'Organisme*', direction: 'Direction', lien_site_web: 'Lien site internet', web_hook_url: 'Lien de rappel HTTP' }.each do |key, value| - if key != :web_hook_url || current_administrateur&.feature_enabled?(:web_hook_allowed) .form-group %h4 @@ -16,6 +16,20 @@ - else = f.text_field key, class: 'form-control', placeholder: value +.form-group + %h4 Notice explicative de la procédure + - notice = @procedure.notice + - if !notice.attached? + = f.file_field :notice, + direct_upload: true + - else + %a{ href: url_for(notice), target: '_blank' } + = notice.filename.to_s + %br + Modifier : + = f.file_field :notice, + direct_upload: true + .row .col-md-6 %h4 Logo de la procédure diff --git a/app/views/admin/procedures/edit.html.haml b/app/views/admin/procedures/edit.html.haml index 6ffe6fb12..5efaea830 100644 --- a/app/views/admin/procedures/edit.html.haml +++ b/app/views/admin/procedures/edit.html.haml @@ -3,4 +3,4 @@ = form_for @procedure, url: url_for({ controller: 'admin/procedures', action: :update, id: @procedure.id }), multipart: true do |f| = render partial: 'informations', locals: { f: f } .text-right - = f.submit 'Enregistrer', class: 'btn btn-success' + = f.button 'Enregistrer', class: 'btn btn-success' diff --git a/app/views/new_user/dossiers/modifier.html.haml b/app/views/new_user/dossiers/modifier.html.haml index 6728a0974..de6867daa 100644 --- a/app/views/new_user/dossiers/modifier.html.haml +++ b/app/views/new_user/dossiers/modifier.html.haml @@ -4,10 +4,10 @@ %h1= @dossier.procedure.libelle .container - - if @dossier.procedure.lien_notice.present? + - if notice_url(@dossier.procedure).present? %p Pour vous aider à remplir votre dossier, vous pouvez consulter - = link_to 'le guide de cette démarche', @dossier.procedure.lien_notice, { target: '_blank' } + = link_to 'le guide de cette démarche', notice_url(@dossier.procedure), { target: '_blank' } %p.thanks Les champs avec une asterisque (*) sont obligatoires. diff --git a/app/views/users/description/_show.html.haml b/app/views/users/description/_show.html.haml index 56234b031..e1495c4d9 100644 --- a/app/views/users/description/_show.html.haml +++ b/app/views/users/description/_show.html.haml @@ -1,5 +1,5 @@ .container#description-page - - if @dossier.procedure.lien_notice.present? + - if notice_url(@dossier.procedure).present? #lien_notice_panel.row{ style: 'width: 280px; position: fixed; background-color: white; right: 5%; top: 80px; z-index: 200;' } .panel.panel-info{ style: 'margin-bottom: 0;' } .panel-body.center @@ -8,7 +8,7 @@ .fa.fa-info-circle.text-info{ style: 'font-size: 2em; margin-top: 20%;' } .col-xs-10{ style: 'padding-right: 0px;' } %b - = link_to 'Accéder au guide', @dossier.procedure.lien_notice, { target: '_blank' } + = link_to 'Accéder au guide', notice_url(@dossier.procedure), { target: '_blank' } pour remplir pour votre dossier %h2.text-info