Skip to content
Snippets Groups Projects
Commit f5a63cfc authored by pabois's avatar pabois
Browse files

import of categories with parents

parent df25260d
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@ class Communication::Website::Imported::Category < ApplicationRecord
belongs_to :category,
class_name: 'Communication::Website::Category',
optional: true
alias_attribute :generated_object, :category
before_validation :sync
......
......@@ -44,6 +44,7 @@ class Communication::Website::Imported::Page < ApplicationRecord
belongs_to :page,
class_name: 'Communication::Website::Page',
optional: true
alias_attribute :generated_object, :category
belongs_to :featured_medium,
class_name: 'Communication::Website::Imported::Medium',
optional: true
......
......@@ -52,6 +52,7 @@ class Communication::Website::Imported::Website < ApplicationRecord
category.data = data
category.save
end
sync_tree(categories)
end
def sync_media
......@@ -70,15 +71,7 @@ class Communication::Website::Imported::Website < ApplicationRecord
page.data = data
page.save
end
# The order will treat parents before children
pages.order(:url).find_each do |page|
next if page.parent.blank?
parent = pages.where(identifier: page.parent).first
next if parent.nil?
generated_page = page.page
generated_page.parent = parent.page
generated_page.save
end
sync_tree(pages)
# Batch update all changes (1 query only, good for github API limits)
github = Github.with_site website
if github.valid?
......@@ -114,4 +107,16 @@ class Communication::Website::Imported::Website < ApplicationRecord
Communication::Website::Post.set_callback(:save, :after, :publish_to_github)
end
end
def sync_tree(elements)
# The order will treat parents before children
elements.order(:url).find_each do |element|
next if element.parent.blank?
parent = elements.where(identifier: element.parent).first
next if parent.nil?
generated_element = element.generated_object
generated_element.parent = parent.generated_object
generated_element.save
end
end
end
......@@ -31,8 +31,10 @@
<%= render 'admin/application/top' %>
<main class="content">
<div class="container-fluid p-0">
<p class="float-end text-end pt-1"><%= yield :title_right %></p>
<h1><%= yield :title %></h1>
<div class="d-flex justify-content-between">
<h1><%= yield :title %></h1>
<p class="text-end pt-1"><%= yield :title_right %></p>
</div>
<%= yield %>
</div>
</main>
......
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