Sha256: 7db1aaca736ac72703f0c63471d5475aef4e258f0600567e9e930745270c1d55

Contents?: true

Size: 1.53 KB

Versions: 26

Compression:

Stored size: 1.53 KB

Contents

class Hyrax::HomepageController < ApplicationController
  # Adds Hydra behaviors into the application controller
  include Blacklight::SearchContext
  include Blacklight::SearchHelper
  include Blacklight::AccessControls::Catalog

  # The search builder for finding recent documents
  # Override of Blacklight::RequestBuilders
  def search_builder_class
    Hyrax::HomepageSearchBuilder
  end

  class_attribute :presenter_class
  self.presenter_class = Hyrax::HomepagePresenter
  layout 'homepage'
  helper Hyrax::ContentBlockHelper

  def index
    @presenter = presenter_class.new(current_ability, collections)
    @featured_researcher = ContentBlock.for(:researcher)
    @marketing_text = ContentBlock.for(:marketing)
    @featured_work_list = FeaturedWorkList.new
    @announcement_text = ContentBlock.for(:announcement)
    recent
  end

  private

    # Return 5 collections
    def collections(rows: 5)
      builder = Hyrax::CollectionSearchBuilder.new(self)
                                              .rows(rows)
      response = repository.search(builder)
      response.documents
    rescue Blacklight::Exceptions::ECONNREFUSED, Blacklight::Exceptions::InvalidRequest
      []
    end

    def recent
      # grab any recent documents
      (_, @recent_documents) = search_results(q: '', sort: sort_field, rows: 4)
    rescue Blacklight::Exceptions::ECONNREFUSED, Blacklight::Exceptions::InvalidRequest
      @recent_documents = []
    end

    def sort_field
      "#{Solrizer.solr_name('date_uploaded', :stored_sortable, type: :date)} desc"
    end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/controllers/hyrax/homepage_controller.rb
hyrax-2.9.5 app/controllers/hyrax/homepage_controller.rb
hyrax-2.9.4 app/controllers/hyrax/homepage_controller.rb
hyrax-2.9.3 app/controllers/hyrax/homepage_controller.rb
hyrax-2.9.2 app/controllers/hyrax/homepage_controller.rb
hyrax-2.9.1 app/controllers/hyrax/homepage_controller.rb
hyrax-2.9.0 app/controllers/hyrax/homepage_controller.rb
hyrax-2.8.0 app/controllers/hyrax/homepage_controller.rb
hyrax-2.7.2 app/controllers/hyrax/homepage_controller.rb
hyrax-2.7.1 app/controllers/hyrax/homepage_controller.rb
hyrax-2.7.0 app/controllers/hyrax/homepage_controller.rb
hyrax-2.6.0 app/controllers/hyrax/homepage_controller.rb
hyrax-2.5.1 app/controllers/hyrax/homepage_controller.rb
hyrax-2.5.0 app/controllers/hyrax/homepage_controller.rb
hyrax-2.4.1 app/controllers/hyrax/homepage_controller.rb
hyrax-3.0.0.pre.beta1 app/controllers/hyrax/homepage_controller.rb
hyrax-2.4.0 app/controllers/hyrax/homepage_controller.rb
hyrax-2.3.3 app/controllers/hyrax/homepage_controller.rb
hyrax-2.3.2 app/controllers/hyrax/homepage_controller.rb
hyrax-2.3.1 app/controllers/hyrax/homepage_controller.rb