Skip to content
Snippets Groups Projects
Unverified Commit 6001f7bf authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

reorder

parent e4a22c4f
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
---
title: "<%= @category.name %>"
slug: "<%= @category.slug %>"
position: <%= @category.position %>
---
<%= prepare_for_github @category.description, @category.university %>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment