diff --git a/app/assets/javascripts/admin/pages/communication/website/pages.js b/app/assets/javascripts/admin/pages/communication/website/pages.js index f58361494a6a2093037148dbdcdd98a479039113..9939d94249b7f4805c44e06f9ecfcaa0b404f15e 100644 --- a/app/assets/javascripts/admin/pages/communication/website/pages.js +++ b/app/assets/javascripts/admin/pages/communication/website/pages.js @@ -4,31 +4,22 @@ window.osuny.pagesTree = { init: function () { 'use strict'; - $('.js-tree-element').click(this.branchClicked.bind(this)); + $('.js-treeview').on('click', '.js-treeview-element', this.branchClicked.bind(this)); }, branchClicked: function (e) { 'use strict'; var $target = $(e.currentTarget), - $branch = $target.parents('.js-treeview-element'); + $branch = $target.closest('.js-treeview-branch'); - e.preventDefault(); - e.stopPropagation(); + $branch.toggleClass('treeview__branch--opened'); - $branch.toggleClass('opened'); - - if ($branch.hasClass('opened') && !$branch.hasClass('loaded')) { - this.loadBranch($branch, $target.attr('href')); + if ($branch.hasClass('treeview__branch--loaded')) { + e.preventDefault(); + e.stopPropagation(); } }, - loadBranch: function ($branch, url) { - 'use strict'; - // TODO - console.log('ok'); - $branch.addClass('loaded'); - }, - invoke: function () { 'use strict'; return { diff --git a/app/assets/stylesheets/admin/treeview.sass b/app/assets/stylesheets/admin/treeview.sass index 8d0c535a6a3733ba8dc1b1255fad248bcc3a2fc0..82c5203f0a892eb954666a2ca4bcb949bb2087b9 100644 --- a/app/assets/stylesheets/admin/treeview.sass +++ b/app/assets/stylesheets/admin/treeview.sass @@ -1,17 +1,29 @@ .treeview - .branch - .close_btn - display: none - .open_btn - display: inline - .children + &__branch + & > .treeview__label + & > a .close_btn + display: none + & > a .open_btn + display: inline + & > .treeview__children display: none margin-left: 15px - &.opened - .close_btn - display: inline - .open_btn - display: none - .children + &--opened + & > .treeview__label + & > a .close_btn + display: inline + & > a .open_btn + display: none + & > .treeview__children display: block + + &__leaf + & > .treeview__label + & > a .close_btn + display: none + & > a .open_btn + display: none + + & > .treeview__children + display: none diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index 29936faf5dc8b2fcc9ee8e827c0e23dd53bd312c..c2731adb88fff1659b9ebdd535c15de1cf0f8b91 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -8,8 +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 + @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 248f6114750eba269dbc24350f9e5d19b7815356..0000000000000000000000000000000000000000 --- 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 20a415c655deaf08befa1c4a77cf15c2faa94b1f..0410c664d3b6e9859bf11e853a325e9043904631 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 new file mode 100644 index 0000000000000000000000000000000000000000..265834a3a533518ca036e2688fd1d48635f3f2ef --- /dev/null +++ b/app/views/admin/communication/website/pages/_treebranch.html.erb @@ -0,0 +1,22 @@ +<% pages.each do |page| %> + <li class="<%= page.has_children? ? 'treeview__branch js-treeview-branch' : 'treeview__leaf' %>" data-id="<%= page.id %>"> + <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', remote: true do %> + <span class="open_btn">+</span> + <span class="close_btn">-</span> + <%= page %> + <% end %> + <% else %> + <%= page %> + <% end %> + <%= link_to 'Voir', admin_communication_website_page_path(website_id: page.website.id, id: page.id), class: button_classes %> + </div> + <% if page.has_children? %> + <ul class="list-unstyled treeview__children js-treeview-children"> + <li>loading...</li> + </ul> + <% end %> + </li> +<% end %> diff --git a/app/views/admin/communication/website/pages/children.js.erb b/app/views/admin/communication/website/pages/children.js.erb index e641cd37b736b2d3bafb033d93873ccb218a648f..4436bef705778664931ace07708636d815a59e82 100644 --- a/app/views/admin/communication/website/pages/children.js.erb +++ b/app/views/admin/communication/website/pages/children.js.erb @@ -1 +1,5 @@ -$('.js-treeview-element-<%= @page.id %>').addClass('opened'); +<%#= 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/app/views/admin/communication/website/pages/index.html.erb b/app/views/admin/communication/website/pages/index.html.erb index 0f12f693f7f8f1a193c5462c975736d4c299cfbc..8bc0501a2a2c9e94e7e88fc7d46b55b1791554f0 100644 --- a/app/views/admin/communication/website/pages/index.html.erb +++ b/app/views/admin/communication/website/pages/index.html.erb @@ -1,23 +1,7 @@ <% content_for :title, Communication::Website::Page.model_name.human(count: 2) %> <ul class="list-unstyled treeview js-treeview"> - <% @pages.each do |page| %> - <li class="branch <%= 'with-children' if page.has_children? %> js-treeview-element js-treeview-element-<%= page.id %>"> - <div class="d-flex align-items-center"> - <%= link_to children_admin_communication_website_page_path(website_id: page.website.id, id: page.id), - class: 'js-tree-element' do %> - <span class="open_btn">+</span> - <span class="close_btn">-</span> - <%= page %> - <% end %> - <%= link_to 'Voir', admin_communication_website_page_path(website_id: page.website.id, id: page.id), class: button_classes %> - </div> - <ul class="list-unstyled children"> - <li>loading...</li> - </ul> - - </li> - <% end %> + <%= render 'treebranch', pages: @pages %> </ul> <%#= render 'admin/communication/website/pages/list', pages: @pages %> <%#= paginate @pages, theme: 'bootstrap-5' %> diff --git a/db/schema.rb b/db/schema.rb index a8b5b57149f48e017de43ae1bc14845f09c2adb6..84ec856e3dcd325301e07961061964a644bbc816 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"