Sha256: 24c2bf48826eaee9716f6f85243e277e6fd1ab6f20464a8907e1e2dc9d435280

Contents?: true

Size: 1.47 KB

Versions: 13

Compression:

Stored size: 1.47 KB

Contents

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

  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)
    Hyrax::CollectionsService.new(self).search_results do |builder|
      builder.rows(rows)
    end
  rescue Blacklight::Exceptions::ECONNREFUSED, Blacklight::Exceptions::InvalidRequest
    []
  end

  def recent
    # grab any recent documents
    (_, @recent_documents) = search_service.search_results do |builder|
      builder.rows(4)
      builder.merge(sort: sort_field)
    end
  rescue Blacklight::Exceptions::ECONNREFUSED, Blacklight::Exceptions::InvalidRequest
    @recent_documents = []
  end

  def search_service
    Hyrax::SearchService.new(config: blacklight_config, user_params: { q: '' }, scope: self, search_builder_class: Hyrax::HomepageSearchBuilder)
  end

  def sort_field
    "date_uploaded_dtsi desc"
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hyrax-3.6.0 app/controllers/hyrax/homepage_controller.rb
hyrax-3.5.0 app/controllers/hyrax/homepage_controller.rb
hyrax-3.4.2 app/controllers/hyrax/homepage_controller.rb
hyrax-3.4.1 app/controllers/hyrax/homepage_controller.rb
hyrax-3.4.0 app/controllers/hyrax/homepage_controller.rb
hyrax-3.3.0 app/controllers/hyrax/homepage_controller.rb
hyrax-3.2.0 app/controllers/hyrax/homepage_controller.rb
hyrax-3.1.0 app/controllers/hyrax/homepage_controller.rb
hyrax-3.0.2 app/controllers/hyrax/homepage_controller.rb
hyrax-3.0.1 app/controllers/hyrax/homepage_controller.rb
hyrax-3.0.0 app/controllers/hyrax/homepage_controller.rb
hyrax-3.0.0.pre.rc4 app/controllers/hyrax/homepage_controller.rb
hyrax-3.0.0.pre.rc3 app/controllers/hyrax/homepage_controller.rb