diff --git a/app/controllers/admin/communication/website/categories_controller.rb b/app/controllers/admin/communication/website/categories_controller.rb index d0fa3d229983b4f8ab365ee4745c2006568b0f33..bb07fd3bd97cb1121e7ccc9d890bc7008dd345cc 100644 --- a/app/controllers/admin/communication/website/categories_controller.rb +++ b/app/controllers/admin/communication/website/categories_controller.rb @@ -11,13 +11,19 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication def reorder parent_id = params[:parentId].blank? ? nil : params[:parentId] ids = params[:ids] || [] + categories = [] ids.each.with_index do |id, index| category = @website.categories.find(id) + categories << category + categories.concat(category.descendents) if parent_id != category.parent_id category.update( parent_id: parent_id, - position: index + 1 + position: index + 1, + skip_github_publication: true ) end + github = Github.with_website @website + github.send_batch_to_website(categories, message: '[Category] Reorder categories.') end def children diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index d9788ae24b781adb603a2cc0d37234df2e1ebdb5..17fb1954a404bf45e7f1b0e0f16e680559b1473f 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -11,7 +11,6 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web parent_id = params[:parentId].blank? ? nil : params[:parentId] ids = params[:ids] || [] pages = [] - github_files = [] ids.each.with_index do |id, index| page = @website.pages.find(id) pages << page diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index c9c96a35aa16a3ab2aa155b699c19c413cd24c36..a055f367a59257ab701a278c6d8b3326ec6715f6 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -65,6 +65,8 @@ class Communication::Website::Category < ApplicationRecord validates :name, presence: true validates :slug, uniqueness: { scope: :communication_website_id } + after_save :update_children_paths, if: :saved_change_to_path? + scope :ordered, -> { order(:position) } before_create :set_position @@ -83,6 +85,13 @@ class Communication::Website::Category < ApplicationRecord "content/categories/#{path}/_index.html".gsub(/\/+/, '/') end + def update_children_paths + children.each do |child| + child.update_column :path, child.generated_path + child.update_children_paths + end + end + protected def set_position diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 55ed4b6ad2b1268825aa6ea507b097c69c24f433..f9b15c3add7cbb337a142dfb2ea315bc8d296ed3 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -90,7 +90,6 @@ class Education::Program < ApplicationRecord validates_presence_of :name - before_validation :make_path after_save :update_children_paths, if: :saved_change_to_path? after_save_commit :set_websites_categories, unless: :skip_websites_categories_callback @@ -125,6 +124,6 @@ class Education::Program < ApplicationRecord end def set_websites_categories - websites.find_each(&:set_programs_categories!) + # websites.find_each(&:set_programs_categories!) end end diff --git a/app/views/admin/communication/website/categories/static.html.erb b/app/views/admin/communication/website/categories/static.html.erb index cc16d53779680fb506b915e61d046e3a1f46ee70..9fe83ce6e974c099cfcef92959d5afff137c2aa0 100644 --- a/app/views/admin/communication/website/categories/static.html.erb +++ b/app/views/admin/communication/website/categories/static.html.erb @@ -1,5 +1,6 @@ --- title: "<%= @category.name %>" slug: "<%= @category.slug %>" +position: <%= @category.position %> --- <%= prepare_for_github @category.description, @category.university %>