From 58dc5107785bad12bc78faae55559a4edac428dc Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Thu, 21 Oct 2021 14:36:39 +0200
Subject: [PATCH] pagetree

---
 .../pages/communication/website/pages.js      | 10 ++---
 .../communication/website/pages_controller.rb | 10 ++---
 app/inputs/trix_editor_input.rb               | 42 -------------------
 app/models/research/journal/article.rb        |  2 +-
 .../website/pages/_treebranch.html.erb        |  2 +-
 .../website/pages/children.html.erb           |  1 -
 .../website/pages/children.js.erb             |  5 +++
 db/schema.rb                                  |  2 +-
 8 files changed, 18 insertions(+), 56 deletions(-)
 delete mode 100644 app/inputs/trix_editor_input.rb
 delete mode 100644 app/views/admin/communication/website/pages/children.html.erb
 create mode 100644 app/views/admin/communication/website/pages/children.js.erb

diff --git a/app/assets/javascripts/admin/pages/communication/website/pages.js b/app/assets/javascripts/admin/pages/communication/website/pages.js
index 3586678d5..218cf689e 100644
--- a/app/assets/javascripts/admin/pages/communication/website/pages.js
+++ b/app/assets/javascripts/admin/pages/communication/website/pages.js
@@ -12,14 +12,14 @@ window.osuny.pagesTree = {
         var $target = $(e.currentTarget),
             $branch = $target.closest('.js-treeview-branch');
 
-        e.preventDefault();
-        e.stopPropagation();
+        // e.preventDefault();
+        // e.stopPropagation();
 
         $branch.toggleClass('treeview__branch--opened');
 
-        if ($branch.hasClass('treeview__branch--opened') && !$branch.hasClass('treeview__branch--loaded')) {
-            this.loadBranch($branch, $target.attr('href'));
-        }
+        // if ($branch.hasClass('treeview__branch--opened') && !$branch.hasClass('treeview__branch--loaded')) {
+        //     this.loadBranch($branch, $target.attr('href'));
+        // }
     },
 
     loadBranch: function ($branch, url) {
diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb
index 6980b8a32..c2731adb8 100644
--- a/app/controllers/admin/communication/website/pages_controller.rb
+++ b/app/controllers/admin/communication/website/pages_controller.rb
@@ -8,11 +8,11 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web
 
   def children
     return unless request.xhr?
-    page = @website.pages.find(params[:id])
-    @children = page.children.ordered
-    respond_to do |format|
-      format.html { render :layout => false }
-    end
+    @page = @website.pages.find(params[:id])
+    @children = @page.children.ordered
+    # respond_to do |format|
+    #   format.html { render :layout => false }
+    # end
   end
 
   def show
diff --git a/app/inputs/trix_editor_input.rb b/app/inputs/trix_editor_input.rb
deleted file mode 100644
index 248f61147..000000000
--- a/app/inputs/trix_editor_input.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-# I was using https://github.com/maclover7/trix to do:
-#
-# f.input :my_input, as: :trix_editor
-#
-# Its currently been over two weeks since Rails 5.2 was released, and the
-# gem was the only thing preventing me from using it in multiple projects:
-# https://github.com/maclover7/trix/pull/61#issuecomment-384312659
-#
-# So I made this custom simpleform input for my apps to prevent this from happening again in the future.
-#
-# For more info on SimpleForm custom form inputs, see:
-# https://github.com/plataformatec/simple_form/wiki/Adding-custom-input-components
-#
-
-class TrixEditorInput < SimpleForm::Inputs::Base
-  def input(wrapper_options)
-    template.concat @builder.text_field(attribute_name, input_html_options)
-    template.content_tag(:"trix-editor", nil, input: id)
-  end
-
-  def input_html_options
-    super.merge({
-      type: :hidden,
-      id: id,
-      name: name
-    })
-  end
-
-  def id
-    "#{object_name}_#{attribute_name}"
-  end
-
-  def name
-    "#{object_name}[#{attribute_name}]"
-  end
-
-  private
-
-  def object_name
-    @builder.object.class.to_s.downcase.gsub('::', '_')
-  end
-end
diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb
index 20a415c65..0410c664d 100644
--- a/app/models/research/journal/article.rb
+++ b/app/models/research/journal/article.rb
@@ -10,7 +10,7 @@
 #  text                       :text
 #  title                      :string
 #  created_at                 :datetime         not null
-#  updated_at                 :date             not null
+#  updated_at                 :datetime         not null
 #  research_journal_id        :uuid             not null
 #  research_journal_volume_id :uuid
 #  university_id              :uuid             not null
diff --git a/app/views/admin/communication/website/pages/_treebranch.html.erb b/app/views/admin/communication/website/pages/_treebranch.html.erb
index a04a5afb7..265834a3a 100644
--- a/app/views/admin/communication/website/pages/_treebranch.html.erb
+++ b/app/views/admin/communication/website/pages/_treebranch.html.erb
@@ -3,7 +3,7 @@
     <div class="d-flex align-items-center treeview__label">
       <% if page.has_children? %>
         <%= link_to children_admin_communication_website_page_path(website_id: page.website.id, id: page.id),
-                    class: 'js-treeview-element' do %>
+                    class: 'js-treeview-element', remote: true do %>
           <span class="open_btn">+</span>
           <span class="close_btn">-</span>
           <%= page %>
diff --git a/app/views/admin/communication/website/pages/children.html.erb b/app/views/admin/communication/website/pages/children.html.erb
deleted file mode 100644
index 727f780d9..000000000
--- a/app/views/admin/communication/website/pages/children.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= render 'treebranch', format: :js, pages: @children %>
diff --git a/app/views/admin/communication/website/pages/children.js.erb b/app/views/admin/communication/website/pages/children.js.erb
new file mode 100644
index 000000000..4436bef70
--- /dev/null
+++ b/app/views/admin/communication/website/pages/children.js.erb
@@ -0,0 +1,5 @@
+<%#= render 'treebranch', format: :js, pages: @children %>
+
+$branch = $('.js-treeview-branch[data-id=<%= @page.id %>]');
+$('.js-treeview-children', $branch).html("<%= escape_javascript(render 'treebranch', pages: @children) %>");
+$branch.addClass('treeview__branch--loaded');
diff --git a/db/schema.rb b/db/schema.rb
index a8b5b5714..84ec856e3 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -250,7 +250,7 @@ ActiveRecord::Schema.define(version: 2021_10_21_095157) do
     t.uuid "research_journal_id", null: false
     t.uuid "research_journal_volume_id"
     t.datetime "created_at", precision: 6, null: false
-    t.date "updated_at", null: false
+    t.datetime "updated_at", precision: 6, null: false
     t.uuid "updated_by_id"
     t.text "abstract"
     t.text "references"
-- 
GitLab