app/models/spotlight/exhibit.rb in blacklight-spotlight-0.14.2 vs app/models/spotlight/exhibit.rb in blacklight-spotlight-0.15.0

- old
+ new

@@ -2,10 +2,11 @@ module Spotlight ## # Spotlight exhibit class Exhibit < ActiveRecord::Base include Spotlight::ExhibitAnalytics + include Spotlight::ExhibitDefaults include Spotlight::ExhibitDocuments scope :published, -> { where(published: true) } scope :unpublished, -> { where(published: false) } @@ -15,10 +16,11 @@ validates :slug, uniqueness: true default_scope { order('weight ASC') } acts_as_tagger + acts_as_taggable delegate :blacklight_config, to: :blacklight_configuration serialize :facets, Array # Note: friendly id associations need to be 'destroy'ed to reap the slug history has_many :about_pages, extend: FriendlyId::FinderMethods @@ -33,30 +35,26 @@ has_many :roles, as: :resource, dependent: :delete_all has_many :searches, dependent: :destroy, extend: FriendlyId::FinderMethods has_many :solr_document_sidecars, dependent: :delete_all has_many :users, through: :roles, class_name: Spotlight::Engine.config.user_class has_many :pages, dependent: :destroy + has_many :filters, dependent: :delete_all has_one :blacklight_configuration, class_name: 'Spotlight::BlacklightConfiguration', dependent: :delete has_one :home_page belongs_to :site belongs_to :masthead, dependent: :destroy belongs_to :thumbnail, class_name: 'Spotlight::FeaturedImage', dependent: :destroy accepts_nested_attributes_for :about_pages, :attachments, :contacts, :custom_fields, :feature_pages, :main_navigations, :owned_taggings, :resources, :searches, :solr_document_sidecars - accepts_nested_attributes_for :blacklight_configuration, :home_page, :masthead, :thumbnail, update_only: true + accepts_nested_attributes_for :blacklight_configuration, :home_page, :masthead, :thumbnail, :filters, update_only: true accepts_nested_attributes_for :contact_emails, reject_if: proc { |attr| attr['email'].blank? } accepts_nested_attributes_for :roles, allow_destroy: true, reject_if: proc { |attr| attr['user_key'].blank? } before_save :sanitize_description, if: :description_changed? - before_create :build_home_page - before_create :add_site_reference - after_create :initialize_config - after_create :initialize_browse - after_create :initialize_main_navigation include Spotlight::DefaultThumbnailable def main_about_page @main_about_page ||= about_pages.published.first end @@ -73,11 +71,13 @@ Spotlight::ExhibitExportSerializer.prepare(self).from_hash(hash) self end def solr_data - Spotlight::Engine.config.exhibit_filter.call(self) + filters.each_with_object({}) do |filter, hash| + hash.merge! filter.to_hash + end end def reindex_later Spotlight::ReindexJob.perform_later(self) end @@ -102,35 +102,10 @@ @reindex_progress ||= ReindexProgress.new(resources.order('updated_at')) if resources end protected - def add_site_reference - self.site ||= Spotlight::Site.instance - end - - def initialize_config - self.blacklight_configuration ||= Spotlight::BlacklightConfiguration.create! - end - - def initialize_browse - return unless searches.blank? - - searches.create title: 'All Exhibit Items', - long_description: 'All items in this exhibit.' - end - - def initialize_main_navigation - default_main_navigations.each_with_index do |nav_type, weight| - main_navigations.create nav_type: nav_type, weight: weight - end - end - def sanitize_description self.description = ::Rails::Html::FullSanitizer.new.sanitize(description) - end - - def default_main_navigations - Spotlight::Engine.config.exhibit_main_navigation.dup end end end