app/models/spina/account.rb in spina-0.11.1 vs app/models/spina/account.rb in spina-0.12.0

- old
+ new

@@ -1,9 +1,10 @@ module Spina class Account < ApplicationRecord + include Partable + serialize :preferences - include Spina::Partable mount_uploader :logo, LogoUploader has_many :layout_parts, dependent: :destroy accepts_nested_attributes_for :layout_parts, allow_destroy: true @@ -40,32 +41,41 @@ private def bootstrap_website theme_config = ::Spina::Theme.find_by_name(theme) - bootstrap_pages(theme_config) if theme_config + if theme_config + bootstrap_pages(theme_config) + bootstrap_navigations(theme_config) + end end def bootstrap_pages(theme) find_or_create_custom_pages(theme) deactivate_unused_view_templates(theme) activate_used_view_templates(theme) end + def bootstrap_navigations(theme) + theme.navigations.each_with_index do |navigation, index| + Navigation.where(name: navigation[:name]).first_or_create.update_attributes(navigation.merge(position: index)) + end + end + def find_or_create_custom_pages(theme) theme.custom_pages.each do |page| - Page.by_name(page[:name]) + Page.where(name: page[:name]) .first_or_create(title: page[:title]) - .update_columns(view_template: page[:view_template], deletable: page[:deletable]) + .update_attributes(view_template: page[:view_template], deletable: page[:deletable]) end end def deactivate_unused_view_templates(theme) - Page.active.not_by_config_theme(theme).update_all(active: false) + Page.active.where.not(view_template: theme.view_templates.map{|h|h[:name]}).update_all(active: false) end def activate_used_view_templates(theme) - Page.not_active.by_config_theme(theme).update_all(active: true) + Page.where(active: false, view_template: theme.view_templates.map{|h|h[:name]}).update_all(active: true) end end end