From 2646d5a16224c0657531d8ab35d73acccd0ff353 Mon Sep 17 00:00:00 2001
From: alexisben <alexiben7@gmail.com>
Date: Thu, 3 Mar 2022 17:52:10 +0100
Subject: [PATCH] Blocks: add summernote to chapitre

---
 app/assets/stylesheets/admin/styles.sass      |  5 ++++
 .../admin/communication/blocks/edit.html.erb  | 26 ++++++++++++++++++-
 .../blocks/templates/chapter/_edit.html.erb   |  7 +++--
 .../blocks/templates/chapter/_show.html.erb   |  2 +-
 .../templates/testimonials/_show.html.erb     |  4 +--
 5 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/app/assets/stylesheets/admin/styles.sass b/app/assets/stylesheets/admin/styles.sass
index 87493f3e2..5a4ddc5e0 100644
--- a/app/assets/stylesheets/admin/styles.sass
+++ b/app/assets/stylesheets/admin/styles.sass
@@ -31,3 +31,8 @@ h1
     padding-right: 2.5rem
     .nav-link--last
         padding-right: 0
+
+.img-circle
+    aspect-ratio: 1/1
+    object-fit: cover
+    width: 100%
\ No newline at end of file
diff --git a/app/views/admin/communication/blocks/edit.html.erb b/app/views/admin/communication/blocks/edit.html.erb
index 369de6643..35011324f 100644
--- a/app/views/admin/communication/blocks/edit.html.erb
+++ b/app/views/admin/communication/blocks/edit.html.erb
@@ -1,6 +1,7 @@
 <% content_for :title, @block %>
 <%
 @block.data = {} if @block.data.nil? || @block.data.blank?
+# Default elements array to move outside : it is only required when block type has an elements list
 @block.data['elements'] ||= []
 %>
 <div id="app" v-cloak>
@@ -67,8 +68,31 @@
       },
       getImageUrl(data) {
         return this.getFileUrl(data.signed_id, data.filename);
+      },
+      handleSummernote() {
+        $(this.$refs.summernoteInput).summernote({
+          toolbar: [
+            ['font', ['bold', 'italic']],
+            ['insert', ['link']],
+            ['view', ['codeview']]
+          ],
+          callbacks: {
+            onChange: function(contents, $editable) { 
+              this.$refs.summernoteInput.value = contents;
+              this.$refs.summernoteInput.dispatchEvent(new Event('input'));
+            }.bind(this)
+          }
+        });
+      }
+    },
+    mounted: function() {
+      if (this.$refs.summernoteInput) {
+        this.handleSummernote();
       }
     }
   });
-  app.mount('#app')
+
+  window.addEventListener('load', function(){
+    app.mount('#app')
+  });
 </script>
diff --git a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb
index d9dd8648e..aec413429 100644
--- a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb
+++ b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb
@@ -4,10 +4,13 @@
             for="text">
       <%= t '.text_label' %>
     </label>
-    <textarea id="text"
+    <div class="summernote">
+      <textarea id="text"
               class="form-control"
               v-model="data.text"
+              ref="summernoteInput"
+              data-summernote-config="mini"
               placeholder="<%= t '.text_placeholder' %>"></textarea>
-
+    </div>
   </div>
 </div>
diff --git a/app/views/admin/communication/blocks/templates/chapter/_show.html.erb b/app/views/admin/communication/blocks/templates/chapter/_show.html.erb
index 0de9bf668..8749cc2ce 100644
--- a/app/views/admin/communication/blocks/templates/chapter/_show.html.erb
+++ b/app/views/admin/communication/blocks/templates/chapter/_show.html.erb
@@ -1 +1 @@
-<%= @block.data['text'] %>
+<%= @block.data['text'].html_safe %>
diff --git a/app/views/admin/communication/blocks/templates/testimonials/_show.html.erb b/app/views/admin/communication/blocks/templates/testimonials/_show.html.erb
index 584a79f9e..e44bebd93 100644
--- a/app/views/admin/communication/blocks/templates/testimonials/_show.html.erb
+++ b/app/views/admin/communication/blocks/templates/testimonials/_show.html.erb
@@ -11,8 +11,8 @@
               <% photo = testimonial.dig('photo', 'id') %>
               <% unless photo.blank? %>
                 <% blob = ActiveStorage::Blob.find photo %>
-                <div style="max-width: 80px" class="me-3">
-                  <%= kamifusen_tag blob, width: 80, class: 'img-fluid rounded-circle' %>
+                <div style="max-width: 80px;" class="me-3">
+                  <%= kamifusen_tag blob, width: 80, class: 'img-fluid rounded-circle img-circle' %>
                 </div>
               <% end %>
               <p class="flex-fill mb-0">
-- 
GitLab