diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index cf9e2a493811202bb386eb7d9d07bc143a442fc0..c2d92946fe332882f35ca477a6a17445da9138d6 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -72,6 +72,14 @@ module Admin::ApplicationHelper sanitize text end + def collection_tree(list, except) + collection = [] + list.root.ordered.each do |object| + collection.concat(object.self_and_children(0)) + end + collection.reject { |o| o[:id] == except.id } + end + private def polymorphic_url_param(object_or_class, **options) diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 86dc769006126182703209e5c82f932904370180..b8aba04c715f284b7465ceae1b07c9b35911ce6d 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -41,14 +41,6 @@ class Communication::Website < ApplicationRecord "#{name}" end - def list_of_pages - all_pages = [] - pages.root.ordered.each do |page| - all_pages.concat(page.self_and_children(0)) - end - all_pages - end - def list_of_categories all_categories = [] categories.root.ordered.each do |category| diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 6d328380c59233afe4bd61bfe91397d2ab11de5f..631d3b0eddb63ab2345440ae100c8a39d8a65729 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -79,10 +79,6 @@ class Communication::Website::Page < ApplicationRecord descendents + siblings end - def list_of_other_pages - website.list_of_pages.reject! { |p| p[:id] == id } - end - def to_s "#{ title }" end diff --git a/app/models/concerns/with_tree.rb b/app/models/concerns/with_tree.rb index 4020468f6119d20961d12d5df0ba917724049079..8bfa2d5571d6533ce2c10f39786a67a30fbe7826 100644 --- a/app/models/concerns/with_tree.rb +++ b/app/models/concerns/with_tree.rb @@ -24,7 +24,7 @@ module WithTree end def siblings - self.class.where(parent: parent).where.not(id: id) + self.class.where(parent: parent, university: university, website: website).where.not(id: id) end def self_and_children(level) diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb index a750e89d7a4e5ce5ce29426f77f1e2b6eecfebf0..4cb44c14b3d4c36ef31dbaf1243e3246827fb8fe 100644 --- a/app/views/admin/communication/website/pages/_form.html.erb +++ b/app/views/admin/communication/website/pages/_form.html.erb @@ -30,7 +30,7 @@ } %> <%= f.input :published %> <%= f.association :parent, - collection: page.persisted? ? page.list_of_other_pages : page.website.list_of_pages, + collection: collection_tree(page.website.pages, page), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> <ul>