From 0a710ea1fa2db2599309832c7af1d4a13cc08ff4 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Wed, 22 Mar 2023 09:42:46 +0100
Subject: [PATCH] wip

---
 .../stylesheets/admin/commons/blocks.sass     | 13 ++++---
 app/assets/stylesheets/admin/pure/style.sass  | 13 +++++--
 app/helpers/admin/application_helper.rb       | 35 ++++++++++---------
 .../communication/blocks/_block.html.erb      | 16 ++++++---
 .../{_list.html.erb => _index_edit.html.erb}  |  4 +--
 .../{_show.html.erb => _index_show.html.erb}  |  0
 .../admin/communication/blocks/edit.html.erb  |  1 +
 .../blocks/headings/_heading.html.erb         | 12 +++++--
 .../blocks/templates/embed/_preview.html.erb  |  2 +-
 .../templates/partners/_preview.html.erb      |  2 +-
 .../posts/categories/preview.html.erb         |  2 +-
 .../extranets/posts/preview.html.erb          |  2 +-
 .../extranets/posts/show.html.erb             |  2 +-
 .../websites/categories/show.html.erb         |  2 +-
 .../websites/pages/preview.html.erb           |  2 +-
 .../websites/pages/show.html.erb              |  8 ++---
 .../websites/posts/preview.html.erb           |  2 +-
 .../websites/posts/show.html.erb              |  2 +-
 .../admin/education/diplomas/show.html.erb    |  2 +-
 .../admin/education/programs/preview.html.erb |  2 +-
 .../admin/education/programs/show.html.erb    |  2 +-
 .../research/journals/papers/show.html.erb    |  2 +-
 .../university/organizations/show.html.erb    |  2 +-
 .../university/people/_main_infos.html.erb    |  2 +-
 app/views/extranet/posts/posts/show.html.erb  |  2 +-
 config/locales/en.yml                         |  1 +
 config/locales/fr.yml                         |  1 +
 27 files changed, 85 insertions(+), 51 deletions(-)
 rename app/views/admin/communication/blocks/{_list.html.erb => _index_edit.html.erb} (80%)
 rename app/views/admin/communication/blocks/{_show.html.erb => _index_show.html.erb} (100%)

diff --git a/app/assets/stylesheets/admin/commons/blocks.sass b/app/assets/stylesheets/admin/commons/blocks.sass
index deaacc5e5..6f70f7a19 100644
--- a/app/assets/stylesheets/admin/commons/blocks.sass
+++ b/app/assets/stylesheets/admin/commons/blocks.sass
@@ -1,13 +1,18 @@
 .blocks
     &__list
         &__element
+            &--hover
+                opacity: 0
+                transition: opacity 0.25s ease
             &:hover
-                .blocks__list__handle
+                .blocks__list__element--hover
                     opacity: 1
         &__handle
-            opacity: 0
-            width: 20px
-            transition: opacity 0.25s ease
+            margin-left: 10px
+            .fas // Icone
+                font-size: px2rem(13)
+            .handle
+                margin-right: 0
         &__image
             width: 170px
             img
diff --git a/app/assets/stylesheets/admin/pure/style.sass b/app/assets/stylesheets/admin/pure/style.sass
index 62a97e91e..1cf0cdac7 100644
--- a/app/assets/stylesheets/admin/pure/style.sass
+++ b/app/assets/stylesheets/admin/pure/style.sass
@@ -60,12 +60,21 @@ p
 a
     text-decoration: none
     text-decoration-thickness: 1px
-    text-underline-offset: 5px
+    text-underline-offset: 4px
     transition: text-decoration 0.5s, color 0.5s
-
     &:hover
         color: darken($primary, 10)
 
+.action
+    text-decoration: underline
+    text-decoration-thickness: 1px
+    text-decoration-color: rgba(0, 0, 0, 0.2)
+    text-underline-offset: 4px
+    transition: text-decoration 0.5s
+    font-size: px2rem(14)
+    &:hover
+        text-decoration-color: black
+
 .form-control:valid,
 .form-control.is-valid,
 .form-select:valid,
diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb
index 3379f7b00..01ba88e73 100644
--- a/app/helpers/admin/application_helper.rb
+++ b/app/helpers/admin/application_helper.rb
@@ -5,36 +5,46 @@ module Admin::ApplicationHelper
                 polymorphic_url_param(object, **options)
   end
 
-  def show_link(object, **options)
+  def show_link(object, html_classes: button_classes, **options)
     link_to_if  can?(:read, object),
                 options.delete(:label) || t('show'),
                 polymorphic_url_param(object, **options),
-                class: button_classes
+                class: html_classes
   end
 
-  def edit_link(object, **options)
+  def edit_link(object, html_classes: button_classes, **options)
     return unless can?(:update, object)
     link_to options.delete(:label) || t('edit'),
             polymorphic_url_param(object, prefix: :edit, **options),
-            class: button_classes
+            class: html_classes
   end
 
-  def destroy_link(object, **options)
+  def destroy_link(object, html_classes: button_classes_danger, **options)
     return unless can?(:destroy, object)
     link_to options.delete(:label) || t('delete'),
             polymorphic_url_param(object, **options),
             method: :delete,
             data: { confirm: options.delete(:confirm_message) || t('please_confirm') },
-            class: button_classes_danger
+            class: html_classes
   end
 
-  def create_link(object_class, **options)
+  def create_link(object_class, html_classes: button_classes, **options)
     return unless can?(:create, object_class)
     object_class_sym = object_class.name.underscore.gsub('/', '_').to_sym
 
     link_to options.delete(:label) || t('create'),
             polymorphic_url_param(object_class_sym, prefix: :new, **options),
-            class: button_classes
+            class: html_classes
+  end
+
+  def duplicate_link(object, html_classes: nil)
+    return unless can?(:update, object)
+    html_classes = button_classes('btn-light') if html_classes.nil?
+    link_to t('admin.duplicate'),
+            [:duplicate, :admin, object],
+            method: :post,
+            data: { confirm: t('please_confirm') },
+            class: html_classes
   end
 
   def preview_link
@@ -76,15 +86,6 @@ module Admin::ApplicationHelper
     " #{string}"
   end
 
-  def duplicate_link(object)
-    return unless can?(:update, object)
-    link_to t('admin.duplicate'),
-            [:duplicate, :admin, object],
-            method: :post,
-            data: { confirm: t('please_confirm') },
-            class: button_classes('btn-light')
-  end
-
   def button_classes(additional = '', **options)
     classes = "btn btn-primary btn-xs #{additional}"
     classes += ' disabled' if options[:disabled]
diff --git a/app/views/admin/communication/blocks/_block.html.erb b/app/views/admin/communication/blocks/_block.html.erb
index 071966af9..ba4c34b9d 100644
--- a/app/views/admin/communication/blocks/_block.html.erb
+++ b/app/views/admin/communication/blocks/_block.html.erb
@@ -1,13 +1,21 @@
 <div class="row" data-id="block_<%= block.id %>">
   <div class="offset-lg-4 col-lg-8">
     <article class="blocks__list__element mt-5 <%= 'draft' unless block.published? %>">
-      <div class="mb-2">
+      <div class="mb-1">
         <div class="float-end">
-          <%= duplicate_link block %>
-          <%= edit_link block %>
+          <span class="blocks__list__handle blocks__list__element--hover">
+            <span class="handle">
+              <span class="small"><%= t 'organize' %></span>
+              <i class="<%= Icon::SORT %>"></i>
+            </span>
+          </span>
+          <span class="blocks__list__element--hover">
+            <%= destroy_link block, html_classes: 'action text-danger ms-2' %>
+            <%= duplicate_link block, html_classes: 'action ms-2' %>
+          </span>
+          <%= edit_link block, html_classes: 'action ms-2' %>
         </div>
         <span class="small text-muted mb-2"><%= block.template_kind_i18n  %></span>
-        <span class="blocks__list__handle"><i class="<%= Icon::SORT %> handle"></i></span>
       </div>
       <div class="blocks__list__preview">
         <% 
diff --git a/app/views/admin/communication/blocks/_list.html.erb b/app/views/admin/communication/blocks/_index_edit.html.erb
similarity index 80%
rename from app/views/admin/communication/blocks/_list.html.erb
rename to app/views/admin/communication/blocks/_index_edit.html.erb
index 8be64161d..1ff42a3dd 100644
--- a/app/views/admin/communication/blocks/_list.html.erb
+++ b/app/views/admin/communication/blocks/_index_edit.html.erb
@@ -11,12 +11,12 @@
     <div class="col-lg-4">
       <%= link_to t('admin.communication.blocks.headings.add'),
                   new_admin_communication_heading_path(about_id: about.id, about_type: about.class.name),
-                  class: 'p-5 d-block bg-light text-center h4' if can? :create, Communication::Block::Heading%>
+                  class: 'py-5 px-2 d-block bg-light text-center h4' if can? :create, Communication::Block::Heading%>
     </div>
     <div class="col-lg-8">
       <%= link_to t('admin.communication.blocks.add'),
                   new_admin_communication_block_path(about_id: about.id, about_type: about.class.name),
-                  class: 'p-5 d-block bg-light text-center h4' if can? :create, Communication::Block%>
+                  class: 'py-5 px-2 d-block bg-light text-center h4' if can? :create, Communication::Block%>
     </div>
   </div>
 <% end %>
diff --git a/app/views/admin/communication/blocks/_show.html.erb b/app/views/admin/communication/blocks/_index_show.html.erb
similarity index 100%
rename from app/views/admin/communication/blocks/_show.html.erb
rename to app/views/admin/communication/blocks/_index_show.html.erb
diff --git a/app/views/admin/communication/blocks/edit.html.erb b/app/views/admin/communication/blocks/edit.html.erb
index b498bd9a6..e701c26d5 100644
--- a/app/views/admin/communication/blocks/edit.html.erb
+++ b/app/views/admin/communication/blocks/edit.html.erb
@@ -34,6 +34,7 @@
     </textarea>
     <% content_for :action_bar_left do %>
       <%= destroy_link @block %>
+      <%= duplicate_link @block %>
     <% end %>
     <% content_for :action_bar_right do %>
       <%= submit f %>
diff --git a/app/views/admin/communication/blocks/headings/_heading.html.erb b/app/views/admin/communication/blocks/headings/_heading.html.erb
index 72ce903ad..1af7fdcca 100644
--- a/app/views/admin/communication/blocks/headings/_heading.html.erb
+++ b/app/views/admin/communication/blocks/headings/_heading.html.erb
@@ -1,7 +1,15 @@
 <div data-id="heading_<%= heading.id %>" class="blocks__list__element mt-5">
   <div style="padding-left: <%= (heading.level - Communication::Block::Heading::DEFAULT_LEVEL) * 48 %>px">
-    <%= link_to heading, edit_admin_communication_heading_path(heading), class: 'h4' %>
-    <span class="ps-0 blocks__list__handle"><i class="<%= Icon::SORT %> handle"></i></span>
+    <span class="h4"><%= heading %></span>
+    <%= link_to t('edit'), 
+                edit_admin_communication_heading_path(heading), 
+                class: 'action ms-2' %>
+    <span class="blocks__list__handle blocks__list__element--hover">
+      <span class="handle">
+        <span class="small"><%= t 'organize' %></span>
+        <i class="<%= Icon::SORT %>"></i>
+      </span>
+    </span>
   </div>
 </div>
 <% heading.blocks.each do |block| %>
diff --git a/app/views/admin/communication/blocks/templates/embed/_preview.html.erb b/app/views/admin/communication/blocks/templates/embed/_preview.html.erb
index 9dd8ff9b7..ee1017d64 100644
--- a/app/views/admin/communication/blocks/templates/embed/_preview.html.erb
+++ b/app/views/admin/communication/blocks/templates/embed/_preview.html.erb
@@ -1 +1 @@
-<p><%= block_component_preview :transcription %></p>
\ No newline at end of file
+<p><%= strip_tags block_component_preview :transcription %></p>
\ No newline at end of file
diff --git a/app/views/admin/communication/blocks/templates/partners/_preview.html.erb b/app/views/admin/communication/blocks/templates/partners/_preview.html.erb
index 5ce92b992..0ed3c7414 100644
--- a/app/views/admin/communication/blocks/templates/partners/_preview.html.erb
+++ b/app/views/admin/communication/blocks/templates/partners/_preview.html.erb
@@ -1,7 +1,7 @@
 <% @block.template.elements.each do |element| %>
   <span class="me-2">
     <% if element.best_logo %>
-      <%= image_tag element.best_logo, width: 90 %>
+      <%= image_tag element.best_logo, height: 90, class: 'bg-light p-2' %>
     <% else %>
       <%= element.best_name %>
     <% end %>
diff --git a/app/views/admin/communication/extranets/posts/categories/preview.html.erb b/app/views/admin/communication/extranets/posts/categories/preview.html.erb
index b776b4a08..556e4ae55 100644
--- a/app/views/admin/communication/extranets/posts/categories/preview.html.erb
+++ b/app/views/admin/communication/extranets/posts/categories/preview.html.erb
@@ -1,3 +1,3 @@
 <% content_for :title, @post.title %>
 <% content_for :image, kamifusen_tag(@post.featured_image) if @post.featured_image.attached? %>
-<%= render 'admin/communication/blocks/show', about: @post %>
+<%= render 'admin/communication/blocks/index_show', about: @post %>
diff --git a/app/views/admin/communication/extranets/posts/preview.html.erb b/app/views/admin/communication/extranets/posts/preview.html.erb
index b776b4a08..556e4ae55 100644
--- a/app/views/admin/communication/extranets/posts/preview.html.erb
+++ b/app/views/admin/communication/extranets/posts/preview.html.erb
@@ -1,3 +1,3 @@
 <% content_for :title, @post.title %>
 <% content_for :image, kamifusen_tag(@post.featured_image) if @post.featured_image.attached? %>
-<%= render 'admin/communication/blocks/show', about: @post %>
+<%= render 'admin/communication/blocks/index_show', about: @post %>
diff --git a/app/views/admin/communication/extranets/posts/show.html.erb b/app/views/admin/communication/extranets/posts/show.html.erb
index 5332d5d25..cd49d50bd 100644
--- a/app/views/admin/communication/extranets/posts/show.html.erb
+++ b/app/views/admin/communication/extranets/posts/show.html.erb
@@ -4,7 +4,7 @@
   <div class="row">
     <div class="col-xl-8">
       <%= render 'admin/application/summary/show', about: @post %>
-      <%= render 'admin/communication/blocks/list', about: @post %>
+      <%= render 'admin/communication/blocks/index_edit', about: @post %>
     </div>
     <div class="col-xl-4">
       <%
diff --git a/app/views/admin/communication/websites/categories/show.html.erb b/app/views/admin/communication/websites/categories/show.html.erb
index 7bf647356..99f034375 100644
--- a/app/views/admin/communication/websites/categories/show.html.erb
+++ b/app/views/admin/communication/websites/categories/show.html.erb
@@ -4,7 +4,7 @@
   <div class="row">
     <div class="col-md-8">
       <%= render 'admin/application/summary/show', about: @category %>
-      <%= render 'admin/communication/blocks/list', about: @category %>
+      <%= render 'admin/communication/blocks/index_edit', about: @category %>
     </div>
     <div class="col-md-4">
       <%= render 'admin/application/i18n/widget', about: @category %>
diff --git a/app/views/admin/communication/websites/pages/preview.html.erb b/app/views/admin/communication/websites/pages/preview.html.erb
index e25884b6c..e61751b88 100644
--- a/app/views/admin/communication/websites/pages/preview.html.erb
+++ b/app/views/admin/communication/websites/pages/preview.html.erb
@@ -1,3 +1,3 @@
 <% content_for :title, @page.title %>
 <% content_for :image, kamifusen_tag(@page.best_featured_image) if @page.best_featured_image.attached? %>
-<%= render 'admin/communication/blocks/show', about: @page %>
+<%= render 'admin/communication/blocks/index_show', about: @page %>
diff --git a/app/views/admin/communication/websites/pages/show.html.erb b/app/views/admin/communication/websites/pages/show.html.erb
index 92226d322..77ef8d7cc 100644
--- a/app/views/admin/communication/websites/pages/show.html.erb
+++ b/app/views/admin/communication/websites/pages/show.html.erb
@@ -11,9 +11,9 @@
       <%= render 'admin/application/featured_image/show', about: @page %>
     </div>
   </div>
-  <hr class="mb-5">
+  <hr class="my-5">
   <%= render 'admin/application/a11y/widget', about: @page, horizontal: true %>
-  <hr class="mb-5">
+  <hr class="my-5">
   <div class="row">
     <div class="col-lg-4">
       <%= render 'admin/communication/websites/pages/show/metadata' %>
@@ -24,8 +24,8 @@
       <%= render 'admin/application/meta_description/show', about: @page %>
     </div>
   </div>
-  <hr class="mb-5">
-  <%= render 'admin/communication/blocks/list', about: @page %>
+  <hr class="my-5">
+  <%= render 'admin/communication/blocks/index_edit', about: @page %>
 <% end %>
 
 <%= render 'admin/application/dependencies',
diff --git a/app/views/admin/communication/websites/posts/preview.html.erb b/app/views/admin/communication/websites/posts/preview.html.erb
index b776b4a08..556e4ae55 100644
--- a/app/views/admin/communication/websites/posts/preview.html.erb
+++ b/app/views/admin/communication/websites/posts/preview.html.erb
@@ -1,3 +1,3 @@
 <% content_for :title, @post.title %>
 <% content_for :image, kamifusen_tag(@post.featured_image) if @post.featured_image.attached? %>
-<%= render 'admin/communication/blocks/show', about: @post %>
+<%= render 'admin/communication/blocks/index_show', about: @post %>
diff --git a/app/views/admin/communication/websites/posts/show.html.erb b/app/views/admin/communication/websites/posts/show.html.erb
index 784067d93..c560d5e92 100644
--- a/app/views/admin/communication/websites/posts/show.html.erb
+++ b/app/views/admin/communication/websites/posts/show.html.erb
@@ -4,7 +4,7 @@
   <div class="row">
     <div class="col-xl-8">
       <%= render 'admin/application/summary/show', about: @post %>
-      <%= render 'admin/communication/blocks/list', about: @post %>
+      <%= render 'admin/communication/blocks/index_edit', about: @post %>
     </div>
     <div class="col-xl-4">
       <%= render 'admin/application/i18n/widget', about: @post %>
diff --git a/app/views/admin/education/diplomas/show.html.erb b/app/views/admin/education/diplomas/show.html.erb
index 8726c1078..66a4783f0 100644
--- a/app/views/admin/education/diplomas/show.html.erb
+++ b/app/views/admin/education/diplomas/show.html.erb
@@ -3,7 +3,7 @@
 <div class="row">
   <div class="col-xl-8">
     <%= render 'admin/application/summary/show', about: @diploma %>
-    <%= render 'admin/communication/blocks/list', about: @diploma %>
+    <%= render 'admin/communication/blocks/index_edit', about: @diploma %>
     <%= osuny_panel Education::Diploma.human_attribute_name('programs') do %>
       <%= render 'admin/education/programs/list', programs: @programs, hide_diploma: true %>
     <% end %>
diff --git a/app/views/admin/education/programs/preview.html.erb b/app/views/admin/education/programs/preview.html.erb
index f694e83e7..323ed783f 100644
--- a/app/views/admin/education/programs/preview.html.erb
+++ b/app/views/admin/education/programs/preview.html.erb
@@ -49,7 +49,7 @@
 </section>
 
 <div class="blocks">
-  <%= render 'admin/communication/blocks/show', about: @program %>
+  <%= render 'admin/communication/blocks/index_show', about: @program %>
 </div>
 
 <section id="pedagogy">
diff --git a/app/views/admin/education/programs/show.html.erb b/app/views/admin/education/programs/show.html.erb
index c6926ee2b..8aa046bd9 100644
--- a/app/views/admin/education/programs/show.html.erb
+++ b/app/views/admin/education/programs/show.html.erb
@@ -51,7 +51,7 @@
         </div>
       </div>
     <% end %>
-    <%= render 'admin/communication/blocks/list', about: @program %>
+    <%= render 'admin/communication/blocks/index_edit', about: @program %>
     <hr class="pure__separation">
     <%= render 'admin/education/programs/forms/part', part: :pedagogy, collapsed: true do %>
       <div class="row">
diff --git a/app/views/admin/research/journals/papers/show.html.erb b/app/views/admin/research/journals/papers/show.html.erb
index 5718ef637..3eb4d9c0f 100644
--- a/app/views/admin/research/journals/papers/show.html.erb
+++ b/app/views/admin/research/journals/papers/show.html.erb
@@ -22,7 +22,7 @@
           <%= sanitize @paper.references %>
         <% end %>
       <% end %>
-      <%= render 'admin/communication/blocks/list', about: @paper %>
+      <%= render 'admin/communication/blocks/index_edit', about: @paper %>
       <%= render 'admin/application/dependencies',
                   git_dependencies: @paper.git_dependencies(@paper.journal.websites.first),
                   active_storage_blobs: @paper.active_storage_blobs %>
diff --git a/app/views/admin/university/organizations/show.html.erb b/app/views/admin/university/organizations/show.html.erb
index b89bb74eb..3995a9c11 100644
--- a/app/views/admin/university/organizations/show.html.erb
+++ b/app/views/admin/university/organizations/show.html.erb
@@ -81,7 +81,7 @@
       </div>
     <% end %>
 
-    <%= render 'admin/communication/blocks/list', about: @organization %>
+    <%= render 'admin/communication/blocks/index_edit', about: @organization %>
   </div>
 
   <div class="col-md-4">
diff --git a/app/views/admin/university/people/_main_infos.html.erb b/app/views/admin/university/people/_main_infos.html.erb
index 1a52c3e35..2fadaf7c7 100644
--- a/app/views/admin/university/people/_main_infos.html.erb
+++ b/app/views/admin/university/people/_main_infos.html.erb
@@ -69,7 +69,7 @@
       <% end %>
     <% end unless person.url.blank? && person.linkedin.blank? && person.twitter.blank? %>
 
-    <%= render 'admin/communication/blocks/list', about: person %>
+    <%= render 'admin/communication/blocks/index_edit', about: person %>
   </div>
   <div class="col-md-4 col-xl-3">
     <%= osuny_panel t('metadata') do %>
diff --git a/app/views/extranet/posts/posts/show.html.erb b/app/views/extranet/posts/posts/show.html.erb
index 57cade679..95b9aa46b 100644
--- a/app/views/extranet/posts/posts/show.html.erb
+++ b/app/views/extranet/posts/posts/show.html.erb
@@ -16,5 +16,5 @@
 <%= link_to @post.category, posts_category_path(slug: @post.category.slug) if @post.category %>
 
 </main>
-<%= render 'admin/communication/blocks/show', about: @post %>
+<%= render 'admin/communication/blocks/index_show', about: @post %>
 <main>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 85a703d66..a0a5498f5 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -250,6 +250,7 @@ en:
     sign_out: Log out
   metadata: Metadata
   open: Open
+  organize: Organize
   please_confirm: Are you sure?
   please_confirm_with_children: "WARNING: deleting this element will also remove every child. Are you sure?"
   preview:
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index 1e441444b..c55562e9c 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -250,6 +250,7 @@ fr:
     sign_out: Déconnexion
   metadata: Informations
   open: Ouvrir
+  organize: Organiser
   please_confirm: Est-ce que vous confirmez ?
   please_confirm_with_children: "ATTENTION : effacer cet élément supprimera aussi tous ses enfants. Est-ce que vous confirmez ?"
   preview:
-- 
GitLab