From b1cb1455c2cca3d925462ac4395d9b178b9812e6 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 6 May 2022 17:36:05 +0200
Subject: [PATCH] statics

---
 Gemfile.lock                                    |  4 ++--
 .../communication/unsplash/_selector.html.erb   | 17 +++++++++--------
 .../communication/unsplash/_static.html.erb     | 10 ++++++++++
 .../website/categories/_form.html.erb           | 16 +---------------
 .../website/categories/static.html.erb          |  5 +----
 .../communication/website/pages/static.html.erb |  5 +----
 .../communication/website/posts/static.html.erb |  8 +-------
 .../admin/education/programs/static.html.erb    |  5 +----
 .../research/journal/volumes/static.html.erb    |  5 +----
 9 files changed, 27 insertions(+), 48 deletions(-)
 create mode 100644 app/views/admin/communication/unsplash/_static.html.erb

diff --git a/Gemfile.lock b/Gemfile.lock
index f9e1442a5..92baf7563 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -88,7 +88,7 @@ GEM
     autoprefixer-rails (10.4.7.0)
       execjs (~> 2)
     aws-eventstream (1.2.0)
-    aws-partitions (1.583.0)
+    aws-partitions (1.585.0)
     aws-sdk-core (3.130.2)
       aws-eventstream (~> 1, >= 1.0.2)
       aws-partitions (~> 1, >= 1.525.0)
@@ -304,7 +304,7 @@ GEM
       ruby2_keywords (~> 0.0.1)
     nesty (1.0.2)
     nio4r (2.5.8)
-    nokogiri (1.13.4)
+    nokogiri (1.13.5)
       mini_portile2 (~> 2.8.0)
       racc (~> 1.4)
     oauth2 (1.4.9)
diff --git a/app/views/admin/communication/unsplash/_selector.html.erb b/app/views/admin/communication/unsplash/_selector.html.erb
index d23320f0c..f2a614860 100644
--- a/app/views/admin/communication/unsplash/_selector.html.erb
+++ b/app/views/admin/communication/unsplash/_selector.html.erb
@@ -9,6 +9,8 @@ about_featured_image_image = ".#{about_identifier}_featured_image img"
 about_featured_image_alt = "##{about_identifier}_featured_image_alt"
 # #communication_website_page_featured_image_credit
 about_featured_image_credit = "##{about_identifier}_featured_image_credit"
+# fr, en...
+lang = about&.language&.iso_code if about.respond_to? :language
 %>
 
 <div id="unsplash-app" v-cloak>
@@ -55,9 +57,9 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
             <p v-if="data.results.length === 0 || !data" >Aucun résultat</p>
 
             <div v-for="image in data.results"  class="col-6 col-lg-2">
-              <img 
-                  :src="image.thumb" 
-                  :alt="image.alt" 
+              <img
+                  :src="image.thumb"
+                  :alt="image.alt"
                   v-on:click="select(image)"
                   class="img-fluid img-thumbnail mb-3"
                   :class="image === selected ? 'bg-secondary' : ''">
@@ -72,7 +74,7 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
             <div  href="#"
                 v-if="page < data.total_pages"
                 v-on:click="page = page + 1"
-                class="btn btn-secondary">Page suivante</div> 
+                class="btn btn-secondary">Page suivante</div>
           </div>
         </div>
       </div>
@@ -91,7 +93,7 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
         parameters: {
           url: '<%= admin_communication_unsplash_path(format: :json) %>',
           per_page: 12,
-          lang: '<%= about&.language&.iso_code %>',
+          lang: '<%= lang %>',
           query: '<%= search || "" %>'
         },
         page: 1,
@@ -113,7 +115,6 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
     },
     watch: {
       page(value) {
-        console.log(value)
         this.search();
       }
     },
@@ -124,7 +125,7 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
         }
 
         var xmlHttp = new XMLHttpRequest();
-        xmlHttp.onreadystatechange = function() { 
+        xmlHttp.onreadystatechange = function() {
           if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
             this.data = JSON.parse(xmlHttp.responseText);
             console.log(this.data)
@@ -150,7 +151,7 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
       }
     }
   });
-  
+
   window.addEventListener('load', function(){
     setTimeout(function() {
       app.mount('#unsplash-app');
diff --git a/app/views/admin/communication/unsplash/_static.html.erb b/app/views/admin/communication/unsplash/_static.html.erb
new file mode 100644
index 000000000..2264bbf50
--- /dev/null
+++ b/app/views/admin/communication/unsplash/_static.html.erb
@@ -0,0 +1,10 @@
+<%
+featured_image = @about&.best_featured_image || @about.featured_image
+if featured_image.attached?
+%>
+image:
+  id: "<%= featured_image.blob.id %>"
+  alt: "<%= @about.featured_image_alt %>"
+  credit: >
+    <%= prepare_html_for_static @about.featured_image_credit, @about.university %>
+<% end %>
diff --git a/app/views/admin/communication/website/categories/_form.html.erb b/app/views/admin/communication/website/categories/_form.html.erb
index 82a78b73b..39f92fdb0 100644
--- a/app/views/admin/communication/website/categories/_form.html.erb
+++ b/app/views/admin/communication/website/categories/_form.html.erb
@@ -31,21 +31,7 @@
           </ul>
         </div>
       </div>
-      <div class="card flex-fill w-100">
-        <div class="card-header">
-          <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/category.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,.svg' },
-                      preview: true
-           %>
-           <%= f.input :featured_image_alt %>
-        </div>
-      </div>
+      <%= render 'admin/application/featured_image/edit', about: category, f: f %>
       <div class="card flex-fill w-100">
         <div class="card-header">
           <h5 class="card-title mb-0"><%= t('seo') %></h5>
diff --git a/app/views/admin/communication/website/categories/static.html.erb b/app/views/admin/communication/website/categories/static.html.erb
index 0b08b2db6..6d3b3a714 100644
--- a/app/views/admin/communication/website/categories/static.html.erb
+++ b/app/views/admin/communication/website/categories/static.html.erb
@@ -5,10 +5,7 @@ slug: "<%= @about.path %>"
 parent: "<%= @about.parent.path %>"
 <% end %>
 position: <%= @about.position %>
-<% if @about.best_featured_image.attached? %>
-image: "<%= @about.best_featured_image.blob.id %>"
-image_alt: "<%= @about.featured_image_alt %>"
-<% end %>
+<%= render 'admin/communication/unsplash/static' %>
 description: >
   <%= prepare_text_for_static @about.description %>
 ---
diff --git a/app/views/admin/communication/website/pages/static.html.erb b/app/views/admin/communication/website/pages/static.html.erb
index 4d2c9f2f1..d4cc6399d 100644
--- a/app/views/admin/communication/website/pages/static.html.erb
+++ b/app/views/admin/communication/website/pages/static.html.erb
@@ -5,10 +5,7 @@ breadcrumb_title: "<%= @about.breadcrumb_title.blank? ? @about.title : @about.br
 url: "<%= @about.path %>"
 position: <%= @about.position %>
 bodyclass: <%= @about.best_bodyclass %>
-<% if @about.best_featured_image && @about.best_featured_image.attached? %>
-image: "<%= @about.best_featured_image.blob.id %>"
-image_alt: "<%= @about.featured_image_alt %>"
-<% end %>
+<%= render 'admin/communication/unsplash/static' %>
 <% if @about.children.published.any? %>
 children:
 <% @about.children.published.ordered.each do |child| %>
diff --git a/app/views/admin/communication/website/posts/static.html.erb b/app/views/admin/communication/website/posts/static.html.erb
index b33785c98..038b4bd0d 100644
--- a/app/views/admin/communication/website/posts/static.html.erb
+++ b/app/views/admin/communication/website/posts/static.html.erb
@@ -15,13 +15,7 @@ categories:
   - "<%= category.path %>"
   <% end %>
 <% end %>
-<% if @about.featured_image.attached? %>
-image:
-  id: "<%= @about.featured_image.blob.id %>"
-  alt: "<%= @about.featured_image_alt %>"
-  credit: >
-    <%= prepare_html_for_static @about.featured_image_credit, @about.university %>
-<% end %>
+<%= render 'admin/communication/unsplash/static' %>
 description: >
   <%= prepare_text_for_static @about.description %>
 description_short: >
diff --git a/app/views/admin/education/programs/static.html.erb b/app/views/admin/education/programs/static.html.erb
index b8cc5b821..80c1f3dde 100644
--- a/app/views/admin/education/programs/static.html.erb
+++ b/app/views/admin/education/programs/static.html.erb
@@ -7,10 +7,7 @@ url: <%= @website.special_page(:education_programs).path %><%= @about.path %>/
 description: >
   <%= prepare_text_for_static @about.description %>
 position: <%= @about.position %>
-<% if @about.best_featured_image.attached? %>
-image: "<%= @about.best_featured_image.blob.id %>"
-image_alt: "<%= @about.featured_image_alt %>"
-<% end %>
+<%= render 'admin/communication/unsplash/static' %>
 category: "<%= @website.categories.find_by(program_id: @about.id)&.path %>/"
 teachers:
 <% teacher_involvements.each do |involvement| %>
diff --git a/app/views/admin/research/journal/volumes/static.html.erb b/app/views/admin/research/journal/volumes/static.html.erb
index dca4bce63..2bba1c9be 100644
--- a/app/views/admin/research/journal/volumes/static.html.erb
+++ b/app/views/admin/research/journal/volumes/static.html.erb
@@ -6,10 +6,7 @@ issn: "<%= @about.journal.issn %>"
 keywords: >
   <%= @about.keywords %>
 date: "<%= @about.published_at.iso8601 %>"
-<% if @about.featured_image.attached? %>
-image: "<%= @about.featured_image.blob.id %>"
-image_alt: "<%= @about.featured_image_alt %>"
-<% end %>
+<%= render 'admin/communication/unsplash/static' %>
 description: >
   <%= prepare_text_for_static @about.description %>
 ---
-- 
GitLab