diff --git a/app/decorators/procedure_decorator.rb b/app/decorators/procedure_decorator.rb deleted file mode 100644 index e4933fbea..000000000 --- a/app/decorators/procedure_decorator.rb +++ /dev/null @@ -1,25 +0,0 @@ -class ProcedureDecorator < Draper::Decorator - delegate_all - - def created_at_fr - created_at.strftime('%d/%m/%Y %H:%M') - end - - def published_at_fr - if published_at.present? - published_at.strftime('%d/%m/%Y %H:%M') - end - end - - def logo_img - if logo.blank? - h.image_url("marianne.svg") - else - if Flipflop.remote_storage? - (RemoteDownloader.new logo.filename).url - else - (LocalDownloader.new logo.path, 'logo').url - end - end - end -end diff --git a/app/helpers/procedure_helper.rb b/app/helpers/procedure_helper.rb index 4305b05e5..62ff0f9ee 100644 --- a/app/helpers/procedure_helper.rb +++ b/app/helpers/procedure_helper.rb @@ -19,4 +19,18 @@ module ProcedureHelper action = procedure.archivee? ? :reopen : :publish t(action, scope: [:modal, :publish, key]) end + + def logo_img(procedure) + logo = procedure.logo + + if logo.blank? + ActionController::Base.helpers.image_url("marianne.svg") + else + if Flipflop.remote_storage? + RemoteDownloader.new(logo.filename).url + else + LocalDownloader.new(logo.path, 'logo').url + end + end + end end diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index bad8e62ed..460f04211 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -101,7 +101,7 @@ .col-md-6 %h4 Logo de la démarche - if @procedure.logo.present? - = image_tag @procedure.decorate.logo_img, { style: 'height: 40px; display: inline; margin-right: 6px;', id: 'preview_procedure_logo' } + = image_tag logo_img(@procedure), { style: 'height: 40px; display: inline; margin-right: 6px;', id: 'preview_procedure_logo' } \- - if @procedure.persisted? diff --git a/app/views/admin/procedures/_list.html.haml b/app/views/admin/procedures/_list.html.haml index d1691b639..9c5ce616a 100644 --- a/app/views/admin/procedures/_list.html.haml +++ b/app/views/admin/procedures/_list.html.haml @@ -12,7 +12,7 @@ %th Actions - @procedures.each do |procedure| - - procedure = procedure.decorate + - procedure = procedure - admin_procedure_href = admin_procedure_path(procedure) %tr{ id: "tr_dossier_#{procedure.id}", data: { href: admin_procedure_href } } %td= link_to(procedure.id, admin_procedure_href) @@ -20,9 +20,9 @@ - if procedure.publiee? %td.procedure-lien= link_to(procedure_lien(procedure), procedure_lien(procedure)) - if procedure.publiee_ou_archivee? - %td= link_to(procedure.published_at_fr, admin_procedure_href) + %td= link_to(published_at.present? ? published_at.strftime('%d/%m/%Y %H:%M') : "", admin_procedure_href) - else - %td= link_to(procedure.created_at_fr, admin_procedure_href) + %td= link_to(procedure.created_at.strftime('%d/%m/%Y %H:%M'), admin_procedure_href) %td = link_to('Cloner', admin_procedure_clone_path(procedure.id), data: { method: :put }, class: 'btn-sm btn-primary clone-btn') - if !procedure.publiee_ou_archivee? diff --git a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml index 560f960b9..25dd50bed 100644 --- a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml +++ b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml @@ -1,7 +1,7 @@ #first-block .en-cours - if @procedure.logo.present? - = image_tag @procedure.decorate.logo_img, style: 'width: 30px;' + = image_tag logo_img(@procedure), style: 'width: 30px;' %b = @procedure.libelle diff --git a/app/views/new_user/dossiers/_demarche_overview.html.haml b/app/views/new_user/dossiers/_demarche_overview.html.haml index e0a451247..548bdf757 100644 --- a/app/views/new_user/dossiers/_demarche_overview.html.haml +++ b/app/views/new_user/dossiers/_demarche_overview.html.haml @@ -1,5 +1,5 @@ .procedure-logos - = image_tag procedure.decorate.logo_img + = image_tag logo_img(procedure) - if procedure.euro_flag = image_tag "flag_of_europe.svg" diff --git a/app/views/users/sessions/_resume_procedure.html.haml b/app/views/users/sessions/_resume_procedure.html.haml index 9df51d63b..895730eef 100644 --- a/app/views/users/sessions/_resume_procedure.html.haml +++ b/app/views/users/sessions/_resume_procedure.html.haml @@ -8,7 +8,7 @@ = image_tag('drapeau_europe.png') #logo_procedure.flag - = image_tag( @dossier.procedure.decorate.logo_img ) + = image_tag(logo_img(dossier.procedure)) %h2#titre-procedure.text-info = @dossier.procedure.libelle diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml index d231b6ac9..f58a19f6c 100644 --- a/app/views/users/sessions/new.html.haml +++ b/app/views/users/sessions/new.html.haml @@ -13,7 +13,7 @@ .text-right = link_to "Fermer", users_no_procedure_url, class: "link close-procedure" .procedure-logos - = image_tag @dossier.procedure.decorate.logo_img + = image_tag logo_img(@dossier.procedure) - if @dossier.procedure.euro_flag = image_tag "flag_of_europe.svg" diff --git a/spec/decorators/procedure_decorator_spec.rb b/spec/decorators/procedure_decorator_spec.rb deleted file mode 100644 index 2c7972076..000000000 --- a/spec/decorators/procedure_decorator_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'spec_helper' - -describe ProcedureDecorator do - let(:published_at) { Time.zone.local(2017, 12, 24, 14, 12) } - let(:procedure) { create(:procedure, published_at: published_at, created_at: Time.zone.local(2015, 12, 24, 14, 10)) } - - subject { procedure.decorate } - - describe 'created_at_fr' do - subject { super().created_at_fr } - it { is_expected.to eq('24/12/2015 14:10') } - end - - describe 'published_at_fr' do - subject { super().published_at_fr } - it { is_expected.to eq('24/12/2017 14:12') } - - context 'published_at is nil' do - let(:published_at) { nil } - it { is_expected.to eq(nil) } - end - end - - describe 'logo_img' do - subject { super().logo_img } - it { is_expected.to match(/http.*#{ActionController::Base.helpers.image_url("marianne.svg")}/) } - end -end diff --git a/spec/helpers/procedure_helper_spec.rb b/spec/helpers/procedure_helper_spec.rb new file mode 100644 index 000000000..838e05e1f --- /dev/null +++ b/spec/helpers/procedure_helper_spec.rb @@ -0,0 +1,9 @@ +RSpec.describe ProcedureHelper, type: :helper do + let(:procedure) { create(:procedure) } + + describe ".logo_img" do + subject { logo_img(procedure) } + + it { is_expected.to match(/#{ActionController::Base.helpers.image_url("marianne.svg")}/) } + end +end