From 954d8957688facb7bf54c4e4ddbacda1c38f6dbb Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Fri, 22 Oct 2021 14:07:56 +0200
Subject: [PATCH] post featured image

---
 .../communication/website/posts_controller.rb     |  2 +-
 .../communication/website/posts/_form.html.erb    | 15 ++++++++++++++-
 config/locales/communication/en.yml               |  1 +
 config/locales/communication/fr.yml               |  1 +
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb
index ed5450d9e..ef53b51ce 100644
--- a/app/controllers/admin/communication/website/posts_controller.rb
+++ b/app/controllers/admin/communication/website/posts_controller.rb
@@ -57,6 +57,6 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web
 
   def post_params
     params.require(:communication_website_post)
-          .permit(:university_id, :website_id, :title, :description, :text, :published, :published_at)
+          .permit(:university_id, :website_id, :title, :description, :text, :published, :published_at, :featured_image, :featured_image_delete)
   end
 end
diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb
index f029d406f..7096f6dab 100644
--- a/app/views/admin/communication/website/posts/_form.html.erb
+++ b/app/views/admin/communication/website/posts/_form.html.erb
@@ -20,7 +20,20 @@
         <div class="card-body">
           <%= f.input :published %>
           <%= f.input :published_at, html5: true %>
-          <%= f.input :featured_image %>
+        </div>
+      </div>
+      <div class="card flex-fill w-100">
+        <div class="card-header">
+          <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/post.featured_image') %></h5>
+        </div>
+        <div class="card-body">
+          <%= f.input :featured_image,
+                      as: :single_deletable_file,
+                      direct_upload: true,
+                      label: false,
+                      input_html: { accept: '.jpg,.jpeg,.png' },
+                      preview: true
+           %>
         </div>
       </div>
     </div>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index ae2c0416a..e9d5e749c 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -52,6 +52,7 @@ en:
       communication/website/post:
         title: Title
         description: Description (SEO)
+        featured_image: Featured image
         text: Text
         published: Published ?
         published_at: Publication date
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 9ba816755..6b73c1ed7 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -51,6 +51,7 @@ fr:
         website: Site Web
       communication/website/post:
         description: Description (SEO)
+        featured_image: Image à la une
         published: Publié ?
         published_at: Date de publication
         text: Texte
-- 
GitLab