Module: Spotlight::Controller

Extended by:
ActiveSupport::Concern
Includes:
Blacklight::Controller, Config
Included in:
Spotlight::Concerns::ApplicationController
Defined in:
app/controllers/concerns/spotlight/controller.rb

Overview

Spotlight controller helpers

Instance Method Summary collapse

Methods included from Config

#exhibit_specific_blacklight_config

Instance Method Details

#blacklight_configObject

overwrites Blacklight::Controller#blacklight_config



64
65
66
67
68
69
70
# File 'app/controllers/concerns/spotlight/controller.rb', line 64

def blacklight_config
  if current_exhibit
    exhibit_specific_blacklight_config
  else
    default_catalog_controller.blacklight_config
  end
end

#current_exhibitObject



26
27
28
# File 'app/controllers/concerns/spotlight/controller.rb', line 26

def current_exhibit
  @exhibit || (Spotlight::Exhibit.find(params[:exhibit_id]) if params[:exhibit_id].present?)
end

#current_mastheadObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/concerns/spotlight/controller.rb', line 30

def current_masthead
  @masthead ||= if resource_masthead?
                  # TODO: is there a way to get this generically, instead of requiring controllers
                  #  to override #current_masthead or set it explicitly?. In the meantime, `nil` is
                  #  hopefully less confusing than a wrong value.
                  nil
                elsif current_exhibit
                  current_exhibit.masthead if exhibit_masthead?
                elsif current_site.masthead&.display?
                  current_site.masthead
                end
end

#current_masthead=(masthead) ⇒ Object



43
44
45
# File 'app/controllers/concerns/spotlight/controller.rb', line 43

def current_masthead=(masthead)
  @masthead = masthead
end

#current_siteObject



22
23
24
# File 'app/controllers/concerns/spotlight/controller.rb', line 22

def current_site
  @current_site ||= Spotlight::Site.instance
end

#default_url_optionsObject



59
60
61
# File 'app/controllers/concerns/spotlight/controller.rb', line 59

def default_url_options
  super.merge(locale: (I18n.locale if I18n.locale != I18n.default_locale))
end

#exhibit_masthead?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/controllers/concerns/spotlight/controller.rb', line 51

def exhibit_masthead?
  current_exhibit&.masthead && current_exhibit.masthead.display?
end

#exhibit_search_action_url(*args, **kwargs) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/concerns/spotlight/controller.rb', line 96

def exhibit_search_action_url(*args, **kwargs)
  options = args.extract_options!
  options = options.merge(kwargs)
  only_path = options[:only_path]
  options.except! :exhibit_id, :only_path

  if only_path
    spotlight.search_exhibit_catalog_path(current_exhibit, *args, **options)
  else
    spotlight.search_exhibit_catalog_url(current_exhibit, *args, **options)
  end
end

#exhibit_search_facet_path(*args, **kwargs) ⇒ Object



109
110
111
112
113
# File 'app/controllers/concerns/spotlight/controller.rb', line 109

def exhibit_search_facet_path(*args, **kwargs)
  options = args.extract_options!
  options = Blacklight::Parameters.sanitize(params.to_unsafe_h.with_indifferent_access).merge(options).merge(kwargs).except(:exhibit_id, :only_path)
  spotlight.facet_exhibit_catalog_url(current_exhibit, *args, **options&.symbolize_keys)
end

#resource_masthead?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/controllers/concerns/spotlight/controller.rb', line 47

def resource_masthead?
  false
end

#search_action_url(*args, **kwargs) ⇒ Object



80
81
82
83
84
85
86
# File 'app/controllers/concerns/spotlight/controller.rb', line 80

def search_action_url(*args, **kwargs)
  if current_exhibit
    exhibit_search_action_url(*args, **kwargs)
  else
    main_app.search_catalog_url(*args, **kwargs)
  end
end

#search_facet_path(*args, **kwargs) ⇒ Object



88
89
90
91
92
93
94
# File 'app/controllers/concerns/spotlight/controller.rb', line 88

def search_facet_path(*args, **kwargs)
  if current_exhibit
    exhibit_search_facet_path(*args, **kwargs)
  else
    main_app.facet_catalog_url(*args, **kwargs)
  end
end

#search_stateObject



72
73
74
75
76
77
78
# File 'app/controllers/concerns/spotlight/controller.rb', line 72

def search_state
  if current_exhibit
    @search_state ||= Spotlight::SearchState.new(super, current_exhibit)
  else
    super
  end
end

#set_exhibit_locale_scopeObject



18
19
20
# File 'app/controllers/concerns/spotlight/controller.rb', line 18

def set_exhibit_locale_scope
  Translation.current_exhibit = current_exhibit
end

#set_localeObject



55
56
57
# File 'app/controllers/concerns/spotlight/controller.rb', line 55

def set_locale
  I18n.locale = params[:locale] || I18n.default_locale
end