From 765ac176f6da637465d58a16dcb359762979c7c1 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 7 Jan 2022 10:43:46 +0100
Subject: [PATCH] featured_image for volumes

---
 .../admin/research/journal/volumes_controller.rb          | 2 +-
 app/models/research/journal/volume.rb                     | 8 ++------
 app/views/admin/research/journal/volumes/_form.html.erb   | 4 ++--
 app/views/admin/research/journal/volumes/show.html.erb    | 6 +++---
 app/views/admin/research/journal/volumes/static.html.erb  | 6 +++---
 config/locales/research/en.yml                            | 2 +-
 config/locales/research/fr.yml                            | 4 ++--
 ...07094053_rename_cover_to_featured_image_for_volumes.rb | 5 +++++
 db/schema.rb                                              | 4 ++--
 9 files changed, 21 insertions(+), 20 deletions(-)
 create mode 100644 db/migrate/20220107094053_rename_cover_to_featured_image_for_volumes.rb

diff --git a/app/controllers/admin/research/journal/volumes_controller.rb b/app/controllers/admin/research/journal/volumes_controller.rb
index 5c9f49db2..c470f7e80 100644
--- a/app/controllers/admin/research/journal/volumes_controller.rb
+++ b/app/controllers/admin/research/journal/volumes_controller.rb
@@ -56,7 +56,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap
     params.require(:research_journal_volume)
           .permit(
             :title, :slug, :number, :keywords, :published_at, :description,
-            :cover, :cover_infos, :cover_delete, :cover_alt
+            :featured_image, :featured_image_infos, :featured_image_delete, :featured_image_alt
           )
           .merge(university_id: current_university.id)
   end
diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb
index fd9764617..8f66ce3e6 100644
--- a/app/models/research/journal/volume.rb
+++ b/app/models/research/journal/volume.rb
@@ -3,8 +3,8 @@
 # Table name: research_journal_volumes
 #
 #  id                  :uuid             not null, primary key
-#  cover_alt           :string
 #  description         :text
+#  featured_image_alt  :string
 #  keywords            :text
 #  number              :integer
 #  published_at        :date
@@ -29,7 +29,7 @@ class Research::Journal::Volume < ApplicationRecord
   include WithGit
   include WithMedia
 
-  has_one_attached_deletable :cover
+  has_one_attached_deletable :featured_image
 
   belongs_to :university
   belongs_to :journal, foreign_key: :research_journal_id
@@ -39,10 +39,6 @@ class Research::Journal::Volume < ApplicationRecord
 
   scope :ordered, -> { order(number: :desc, published_at: :desc) }
 
-  def cover_path
-    "/assets/img/volumes/#{id}#{cover.filename.extension_with_delimiter}"
-  end
-
   def website
     journal.website
   end
diff --git a/app/views/admin/research/journal/volumes/_form.html.erb b/app/views/admin/research/journal/volumes/_form.html.erb
index dff3da118..0b53bf292 100644
--- a/app/views/admin/research/journal/volumes/_form.html.erb
+++ b/app/views/admin/research/journal/volumes/_form.html.erb
@@ -13,12 +13,12 @@
                         class: 'js-slug-input',
                         data: { source: '#research_journal_volume_title' }
                       } %>
-          <%= f.input :cover,
+          <%= f.input :featured_image,
                       as: :single_deletable_file,
                       input_html: { accept: '.jpg,.jpeg,.png' },
                       preview: 200,
                       direct_upload: true %>
-          <%= f.input :cover_alt %>
+          <%= f.input :featured_image_alt %>
           <%= f.input :description, input_html: { rows: 10 } %>
         </div>
       </div>
diff --git a/app/views/admin/research/journal/volumes/show.html.erb b/app/views/admin/research/journal/volumes/show.html.erb
index 68e885b99..403477a98 100644
--- a/app/views/admin/research/journal/volumes/show.html.erb
+++ b/app/views/admin/research/journal/volumes/show.html.erb
@@ -28,13 +28,13 @@
         <p><%= l @volume.published_at.to_time, format: :date_with_explicit_month if @volume.published_at %></p>
       </div>
     </div>
-    <% if @volume.cover.attached? %>
+    <% if @volume.featured_image.attached? %>
       <div class="card">
         <div class="card-header">
-          <h2 class="card-title"><%= Research::Journal::Volume.human_attribute_name('cover') %></h2>
+          <h2 class="card-title"><%= Research::Journal::Volume.human_attribute_name('featured_image') %></h2>
         </div>
         <div class="card-body">
-          <%= kamifusen_tag @volume.cover, class: 'img-fluid' %>
+          <%= kamifusen_tag @volume.featured_image, class: 'img-fluid' %>
         </div>
       </div>
     <% end %>
diff --git a/app/views/admin/research/journal/volumes/static.html.erb b/app/views/admin/research/journal/volumes/static.html.erb
index a90daf583..43be3b9d7 100644
--- a/app/views/admin/research/journal/volumes/static.html.erb
+++ b/app/views/admin/research/journal/volumes/static.html.erb
@@ -4,9 +4,9 @@ number: <%= @volume.number %>
 issn: "<%= @volume.journal.issn %>"
 keywords: "<%= @volume.keywords %>"
 date: "<%= @volume.published_at %>"
-<% if @volume.cover.attached? %>
-image: "<%= @volume.cover.blob.id %>"
-image_alt: "<%= @volume.cover_alt %>"
+<% if @volume.featured_image.attached? %>
+image: "<%= @volume.featured_image.blob.id %>"
+image_alt: "<%= @volume.featured_image_alt %>"
 <% end %>
 articles:
 <% @volume.articles.each do |article| %>
diff --git a/config/locales/research/en.yml b/config/locales/research/en.yml
index eeb3d4532..795cc6f97 100644
--- a/config/locales/research/en.yml
+++ b/config/locales/research/en.yml
@@ -27,7 +27,7 @@ en:
         text: Text
         title: Title
       research/journal/volume:
-        cover: Cover
+        featured_image: Cover
         featured_image_alt: Alt text
         description: Description
         keywords: Keywords
diff --git a/config/locales/research/fr.yml b/config/locales/research/fr.yml
index 10719c2d3..df48aabfb 100644
--- a/config/locales/research/fr.yml
+++ b/config/locales/research/fr.yml
@@ -27,8 +27,8 @@ fr:
         text: Texte
         title: Titre
       research/journal/volume:
-        cover: Couverture
-        cover_alt: Texte alternatif
+        featured_image: Couverture
+        featured_image_alt: Texte alternatif
         description: Description
         keywords: Mots clés
         number: Numéro
diff --git a/db/migrate/20220107094053_rename_cover_to_featured_image_for_volumes.rb b/db/migrate/20220107094053_rename_cover_to_featured_image_for_volumes.rb
new file mode 100644
index 000000000..cfca960bf
--- /dev/null
+++ b/db/migrate/20220107094053_rename_cover_to_featured_image_for_volumes.rb
@@ -0,0 +1,5 @@
+class RenameCoverToFeaturedImageForVolumes < ActiveRecord::Migration[6.1]
+  def change
+    rename_column :research_journal_volumes, :cover_alt, :featured_image_alt
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index b8e59bfdb..0271d5650 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2022_01_06_134525) do
+ActiveRecord::Schema.define(version: 2022_01_07_094053) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -465,7 +465,7 @@ ActiveRecord::Schema.define(version: 2022_01_06_134525) do
     t.text "description"
     t.text "keywords"
     t.string "slug"
-    t.string "cover_alt"
+    t.string "featured_image_alt"
     t.index ["research_journal_id"], name: "index_research_journal_volumes_on_research_journal_id"
     t.index ["university_id"], name: "index_research_journal_volumes_on_university_id"
   end
-- 
GitLab