diff --git a/app/models/communication/website/imported/category.rb b/app/models/communication/website/imported/category.rb index f4689184d7e9061672f05343bcfe395c43198fdd..cd7229095150075947dc546ba45a6e6ebfcd7663 100644 --- a/app/models/communication/website/imported/category.rb +++ b/app/models/communication/website/imported/category.rb @@ -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 diff --git a/app/models/communication/website/imported/page.rb b/app/models/communication/website/imported/page.rb index 4da684abac22eecb85fa6b4b83e10e97ba5ceac2..bfe5a63224e39ab7f9b5a344e32445e0c9a348ba 100644 --- a/app/models/communication/website/imported/page.rb +++ b/app/models/communication/website/imported/page.rb @@ -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 diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb index e10a5376d95ea35275fc7c967f6c9486fe6f07b5..2a168e2369076d02dfdc963ca9ad6dad25a2f0c0 100644 --- a/app/models/communication/website/imported/website.rb +++ b/app/models/communication/website/imported/website.rb @@ -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 diff --git a/app/views/admin/layouts/application.html.erb b/app/views/admin/layouts/application.html.erb index 94b603dc8736a2d557193600c99ec66e05321797..adabf291c242ffb062667deaa3a1c155e140ea4c 100644 --- a/app/views/admin/layouts/application.html.erb +++ b/app/views/admin/layouts/application.html.erb @@ -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>