diff --git a/CHANGELOG.md b/CHANGELOG.md index c0601b2517..a6dae52704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 4.0.5 (unreleased) + +- Do not cache sitemap in Turbolinks [#1463](https://github.com/AlchemyCMS/alchemy_cms/pull/1463) ([tvdeyen](https://github.com/tvdeyen)) +- Skip folded deeper levels when rendering page tree [#1324](https://github.com/AlchemyCMS/alchemy_cms/pull/1324) ([pascalj](https://github.com/pascalj)) + ## 4.0.4 (2018-09-05) - Allow Kaminari 1.x [#1467](https://github.com/AlchemyCMS/alchemy_cms/pull/1467) ([tvdeyen](https://github.com/tvdeyen)) diff --git a/app/models/alchemy/folded_page.rb b/app/models/alchemy/folded_page.rb index 261525081b..50f04da428 100644 --- a/app/models/alchemy/folded_page.rb +++ b/app/models/alchemy/folded_page.rb @@ -15,5 +15,10 @@ class FoldedPage < ActiveRecord::Base belongs_to :page, required: true belongs_to :user, required: true, class_name: Alchemy.user_class_name + + def self.folded_for_user(user) + return none unless Alchemy.user_class < ActiveRecord::Base + where(user: user, folded: true) + end end end diff --git a/app/serializers/alchemy/page_tree_serializer.rb b/app/serializers/alchemy/page_tree_serializer.rb index 1cf8d9a4c9..fd8ae77bdc 100644 --- a/app/serializers/alchemy/page_tree_serializer.rb +++ b/app/serializers/alchemy/page_tree_serializer.rb @@ -10,23 +10,24 @@ def pages tree = [] path = [{id: object.parent_id, children: tree}] page_list = object.self_and_descendants - skip_branch = false base_level = object.level - 1 + # Load folded pages in advance + folded_user_pages = FoldedPage.folded_for_user(opts[:user]).pluck(:page_id) + folded_depth = Float::INFINITY page_list.each_with_index do |page, i| has_children = page_list[i + 1] && page_list[i + 1].parent_id == page.id - folded = has_children && page.folded?(opts[:user]) + folded = has_children && folded_user_pages.include?(page.id) - if skip_branch - next if page.parent_id == path.last[:children].last[:id] - - skip_branch = false + if page.depth > folded_depth + next + else + folded_depth = Float::INFINITY end - # Do not walk my children if I'm folded and you don't need to have the - # full tree. + # If this page is folded, skip all pages that are on a higher level (further down the tree). if folded && !opts[:full] - skip_branch = true + folded_depth = page.depth end if page.parent_id != path.last[:id] diff --git a/app/views/alchemy/admin/pages/index.html.erb b/app/views/alchemy/admin/pages/index.html.erb index 8d1914f080..9af6c2f64d 100644 --- a/app/views/alchemy/admin/pages/index.html.erb +++ b/app/views/alchemy/admin/pages/index.html.erb @@ -1,3 +1,7 @@ +<% content_for :javascript_includes do %> + +<% end %> + <% content_for :toolbar do %>