From 4b195c974030372de07d232a34fd42f1b8ce112d Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Wed, 27 Dec 2023 15:58:10 +0100 Subject: [PATCH] Better --- app/models/concerns/with_publication.rb | 2 +- .../application/property/_publication.html.erb | 14 ++++++++++++++ .../communication/websites/pages/show.html.erb | 6 +----- .../communication/websites/posts/show.html.erb | 6 +----- 4 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 app/views/admin/application/property/_publication.html.erb diff --git a/app/models/concerns/with_publication.rb b/app/models/concerns/with_publication.rb index ae94dce5f..539d96def 100644 --- a/app/models/concerns/with_publication.rb +++ b/app/models/concerns/with_publication.rb @@ -13,7 +13,7 @@ module WithPublication end def draft? - !published || published_in_the_future? + !published end def published_in_the_future? diff --git a/app/views/admin/application/property/_publication.html.erb b/app/views/admin/application/property/_publication.html.erb new file mode 100644 index 000000000..55171777d --- /dev/null +++ b/app/views/admin/application/property/_publication.html.erb @@ -0,0 +1,14 @@ +<% +object ||= about +# admin.communication.website.posts +i18n_key = "admin.#{object.class.to_s.pluralize.downcase.gsub('::', '.')}" +%> +<% if object.draft? %> + <span class="badge bg-secondary"> + <%= t("#{i18n_key}.draft") %> + </span> +<% elsif object.published_in_the_future? %> + <span class="badge bg-secondary"> + <%= t("#{i18n_key}.published_on", date: l(object.published_at.to_date)) %> + </span> +<% end %> diff --git a/app/views/admin/communication/websites/pages/show.html.erb b/app/views/admin/communication/websites/pages/show.html.erb index c7ba609be..947ce7aba 100644 --- a/app/views/admin/communication/websites/pages/show.html.erb +++ b/app/views/admin/communication/websites/pages/show.html.erb @@ -5,11 +5,7 @@ <div class="col-lg-7"> <%= osuny_panel Communication::Website::Page.human_attribute_name(:title), small: true do %> <p class="lead mb-1"><%= @page.title %></p> - <% if @page.draft? %> - <span class="badge bg-secondary"> - <%= t('admin.communication.website.posts.draft') %> - </span> - <% end %> + <%= render 'admin/application/property/publication', about: @page %> <% end %> </div> <div class="offset-lg-1 col-lg-4"> diff --git a/app/views/admin/communication/websites/posts/show.html.erb b/app/views/admin/communication/websites/posts/show.html.erb index 89590fee0..49e0b6328 100644 --- a/app/views/admin/communication/websites/posts/show.html.erb +++ b/app/views/admin/communication/websites/posts/show.html.erb @@ -5,11 +5,7 @@ <div class="col-lg-7"> <%= osuny_panel Communication::Website::Post.human_attribute_name(:title), small: true do %> <p class="lead mb-1"><%= @post.title %></p> - <% if @post.draft? %> - <span class="badge bg-secondary"> - <%= t('admin.communication.website.posts.draft') %> - </span> - <% end %> + <%= render 'admin/application/property/publication', about: @post %> <% end %> </div> <div class="offset-lg-1 col-lg-4"> -- GitLab