Skip to content

Commit

Permalink
Update Spotlight to support and require Blacklight 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 10, 2016
1 parent e496307 commit e0ffaae
Show file tree
Hide file tree
Showing 69 changed files with 319 additions and 309 deletions.
Expand Up @@ -9,7 +9,7 @@ SirTrevor.Blocks.SolrDocuments = (function(){

icon_name: "items",

autocomplete_url: function() { return this.$instance().closest('form[data-autocomplete-exhibit-catalog-index-path]').data('autocomplete-exhibit-catalog-index-path').replace("%25QUERY", "%QUERY"); },
autocomplete_url: function() { return this.$instance().closest('form[data-autocomplete-exhibit-catalog-path]').data('autocomplete-exhibit-catalog-path').replace("%25QUERY", "%QUERY"); },
autocomplete_template: function() { return '<div class="autocomplete-item{{#if private}} blacklight-private{{/if}}">{{#if thumbnail}}<div class="document-thumbnail thumbnail"><img src="{{thumbnail}}" /></div>{{/if}}<span class="autocomplete-title">{{title}}</span><br/><small>&nbsp;&nbsp;{{description}}</small></div>' },

transform_autocomplete_results: function(response) {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/spotlight/search_typeahead.js
Expand Up @@ -36,7 +36,7 @@ function itemsBloodhound() {
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
remote: {
url: $('form[data-autocomplete-exhibit-catalog-index-path]').data('autocomplete-exhibit-catalog-index-path').replace("%25QUERY", "%QUERY"),
url: $('form[data-autocomplete-exhibit-catalog-path]').data('autocomplete-exhibit-catalog-path').replace("%25QUERY", "%QUERY"),
filter: function(response) {
return $.map(response['docs'], function(doc) {
return doc;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/spotlight/base.rb
Expand Up @@ -29,7 +29,7 @@ def autocomplete_json_response_for_document(doc)
full_images: doc.spotlight_image_versions.try(:full),
image_versions: doc.spotlight_image_versions.image_versions(:thumb, :full),
description: doc.id,
url: exhibit_catalog_path(current_exhibit, doc),
url: polymorphic_path([current_exhibit, doc]),
private: doc.private?(current_exhibit),
global_id: doc.to_global_id.to_s
}
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/concerns/spotlight/catalog.rb
Expand Up @@ -6,10 +6,6 @@ module Catalog
include Blacklight::Catalog
include Spotlight::Base

require 'spotlight/catalog/access_controls_enforcement'

include Spotlight::Catalog::AccessControlsEnforcement

included do
before_action :add_facet_visibility_field
end
Expand All @@ -26,5 +22,10 @@ def add_facet_visibility_field
fq: "#{blacklight_config.document_model.visibility_field(current_exhibit)}:false" }
}
end

def render_save_this_search?
(current_exhibit && can?(:curate, current_exhibit)) &&
!(params[:controller] == 'spotlight/catalog' && params[:action] == 'admin')
end
end
end

This file was deleted.

8 changes: 4 additions & 4 deletions app/controllers/concerns/spotlight/controller.rb
Expand Up @@ -56,7 +56,7 @@ def search_action_url(*args)
if current_exhibit
exhibit_search_action_url(*args)
else
main_app.catalog_index_url(*args)
main_app.search_catalog_url(*args)
end
end

Expand All @@ -74,17 +74,17 @@ def exhibit_search_action_url(*args)
options.except! :exhibit_id, :only_path

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

def exhibit_search_facet_url(*args)
options = args.extract_options!
options = params.merge(options).except(:exhibit_id, :only_path)

spotlight.exhibit_catalog_facet_url(current_exhibit, *args, options)
spotlight.facet_exhibit_catalog_url(current_exhibit, *args, options)
end
end
end
3 changes: 1 addition & 2 deletions app/controllers/spotlight/browse_controller.rb
Expand Up @@ -5,7 +5,6 @@ module Spotlight
class BrowseController < Spotlight::ApplicationController
load_and_authorize_resource :exhibit, class: 'Spotlight::Exhibit'
include Spotlight::Base
include Spotlight::Catalog::AccessControlsEnforcement

load_and_authorize_resource :search, except: :index, through: :exhibit, parent: false
before_action :attach_breadcrumbs
Expand All @@ -21,7 +20,7 @@ def show
blacklight_config.index.document_actions = blacklight_config.browse.document_actions

add_breadcrumb @search.title, exhibit_browse_path(@exhibit, @search)
(@response, @document_list) = search_results(@search.query_params.with_indifferent_access.merge(params), search_params_logic)
(@response, @document_list) = search_results(@search.query_params.with_indifferent_access.merge(params))
end

protected
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/spotlight/catalog_controller.rb
Expand Up @@ -52,7 +52,7 @@ def show
# results when a partial match is passed in the "q" parameter.
def autocomplete
search_params = params.merge(search_field: Spotlight::Engine.config.autocomplete_search_field)
(_, @document_list) = search_results(search_params.merge(public: true), search_params_logic)
(_, @document_list) = search_results(search_params.merge(public: true))

respond_to do |format|
format.json do
Expand All @@ -63,8 +63,8 @@ def autocomplete

def admin
add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
add_breadcrumb t(:'spotlight.curation.sidebar.items'), admin_exhibit_catalog_index_path(@exhibit)
(@response, @document_list) = search_results(params, search_params_logic)
add_breadcrumb t(:'spotlight.curation.sidebar.items'), admin_exhibit_catalog_path(@exhibit)
(@response, @document_list) = search_results(params)
@filters = params[:f] || []

respond_to do |format|
Expand All @@ -79,15 +79,15 @@ def update

try_solr_commit!

redirect_to exhibit_catalog_path(current_exhibit, @document)
redirect_to polymorphic_path([current_exhibit, @document])
end

def edit
@response, @document = fetch params[:id]
end

def make_private
@response, @document = fetch params[:catalog_id]
@response, @document = fetch params[:id]
@document.make_private!(current_exhibit)
@document.save

Expand All @@ -98,7 +98,7 @@ def make_private
end

def make_public
@response, @document = fetch params[:catalog_id]
@response, @document = fetch params[:id]
@document.make_public!(current_exhibit)
@document.save

Expand Down Expand Up @@ -205,7 +205,7 @@ def add_document_breadcrumbs(document)
add_breadcrumb t(:'spotlight.catalog.breadcrumb.index'), search_action_url(current_search_session.query_params)
end

add_breadcrumb Array(document[blacklight_config.view_config(:show).title_field]).join(', '), exhibit_catalog_path(current_exhibit, document)
add_breadcrumb Array(document[blacklight_config.view_config(:show).title_field]).join(', '), polymorphic_path([current_exhibit, document])
end
# rubocop:enable Metrics/AbcSize

Expand Down
61 changes: 61 additions & 0 deletions app/controllers/spotlight/concerns/application_controller.rb
Expand Up @@ -25,6 +25,67 @@ module ApplicationController
end
end
end

def enabled_in_spotlight_view_type_configuration?(config, *args)
case
when config.respond_to?(:upstream_if) &&
!config.upstream_if.nil? &&
!blacklight_configuration_context.evaluate_configuration_conditional(config.upstream_if, config, *args)
false
when current_exhibit.nil? || is_a?(Spotlight::PagesController)
true
else
current_exhibit.blacklight_configuration.document_index_view_types.include? config.key.to_s
end
end

# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
def field_enabled?(field, *args)
case
when !field.enabled
false
when field.respond_to?(:upstream_if) &&
!field.upstream_if.nil? &&
!blacklight_configuration_context.evaluate_configuration_conditional(field.upstream_if, field, *args)
false
when field.is_a?(Blacklight::Configuration::SortField) || field.is_a?(Blacklight::Configuration::SearchField)
field.enabled
when field.is_a?(Blacklight::Configuration::FacetField) || (is_a?(Blacklight::Catalog) && %w(edit show).include?(action_name))
field.show
else
field.send(document_index_view_type)
end
end
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength

private

##
# Get the current "view type" (and ensure it is a valid type)
#
# @param [Hash] the query parameters to check
# @return [Symbol]
def document_index_view_type
view_param = params[:view]
view_param ||= session[:preferred_view]
if view_param && document_index_views.keys.include?(view_param.to_sym)
view_param.to_sym
else
default_document_index_view_type
end
end

def document_index_views
blacklight_config.view.select do |_k, config|
blacklight_configuration_context.evaluate_if_unless_configuration config
end
end

##
# Get the default index view type
def default_document_index_view_type
document_index_views.select { |_k, config| config.respond_to?(:default) && config.default }.keys.first || document_index_views.keys.first
end
end
end
end
3 changes: 1 addition & 2 deletions app/controllers/spotlight/dashboards_controller.rb
Expand Up @@ -6,7 +6,6 @@ class DashboardsController < Spotlight::ApplicationController
load_and_authorize_resource :exhibit, class: Spotlight::Exhibit

include Spotlight::Base
include Spotlight::Catalog::AccessControlsEnforcement

before_action only: [:show] do
blacklight_config.view.reject! { |_k, _v| true }
Expand Down Expand Up @@ -47,7 +46,7 @@ def attach_dashboard_breadcrumbs

def load_recent_solr_documents(count)
solr_params = { sort: "#{blacklight_config.index.timestamp_field} desc" }
@response, docs = search_results(solr_params, search_params_logic)
@response, docs = search_results(solr_params)
docs.take(count)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spotlight/home_pages_controller.rb
Expand Up @@ -20,7 +20,7 @@ def index
end

def show
@response, @document_list = search_results({}, search_params_logic) if @page.display_sidebar?
@response, @document_list = search_results({}) if @page.display_sidebar?

if @page.nil? || !@page.published?
render '/catalog/index'
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/spotlight/pages_controller.rb
Expand Up @@ -8,9 +8,8 @@ class PagesController < Spotlight::ApplicationController
helper Openseadragon::OpenseadragonHelper
include Spotlight::Base
include Blacklight::SearchContext
include Spotlight::Catalog::AccessControlsEnforcement

helper_method :get_search_results, :search_results, :search_params_logic, :fetch, :page_collection_name
helper_method :get_search_results, :search_results, :fetch, :page_collection_name

# GET /exhibits/1/pages
def index
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/spotlight/resources/upload_controller.rb
Expand Up @@ -3,7 +3,7 @@ module Resources
##
# Creating new exhibit items from single-item entry forms
# or batch CSV upload
class UploadController < ApplicationController
class UploadController < Spotlight::ApplicationController
helper :all

before_action :authenticate_user!
Expand All @@ -22,11 +22,11 @@ def create
if params['add-and-continue']
redirect_to new_exhibit_resource_path(@resource.exhibit, anchor: :new_resources_upload)
else
redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
redirect_to admin_exhibit_catalog_path(@resource.exhibit, sort: :timestamp)
end
else
flash[:error] = t('spotlight.resources.upload.error')
redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
redirect_to admin_exhibit_catalog_path(@resource.exhibit, sort: :timestamp)
end
end
# rubocop:enable Metrics/MethodLength
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/spotlight/resources_controller.rb
Expand Up @@ -12,15 +12,15 @@ class ResourcesController < Spotlight::ApplicationController
def new
add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), exhibit_root_path(@exhibit)
add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
add_breadcrumb t(:'spotlight.curation.sidebar.items'), admin_exhibit_catalog_index_path(@exhibit)
add_breadcrumb t(:'spotlight.curation.sidebar.items'), admin_exhibit_catalog_path(@exhibit)
add_breadcrumb t(:'spotlight.resources.new.header'), new_exhibit_resource_path(@exhibit)

render
end

def create
if @resource.save_and_index
redirect_to admin_exhibit_catalog_index_path(@resource.exhibit, sort: :timestamp)
redirect_to admin_exhibit_catalog_path(@resource.exhibit, sort: :timestamp)
else
render action: 'new'
end
Expand All @@ -33,7 +33,7 @@ def monitor
def reindex_all
@exhibit.reindex_later

redirect_to admin_exhibit_catalog_index_path(@exhibit), notice: t(:'spotlight.resources.reindexing_in_progress')
redirect_to admin_exhibit_catalog_path(@exhibit), notice: t(:'spotlight.resources.reindexing_in_progress')
end

protected
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spotlight/searches_controller.rb
Expand Up @@ -31,7 +31,7 @@ def index

def autocomplete
search_params = autocomplete_params.merge(search_field: Spotlight::Engine.config.autocomplete_search_field)
(_, document_list) = search_results(search_params, search_params_logic)
(_, document_list) = search_results(search_params)

respond_to do |format|
format.json do
Expand Down
10 changes: 3 additions & 7 deletions app/helpers/spotlight/application_helper.rb
Expand Up @@ -51,7 +51,8 @@ def url_for_document(document)
# the current exhibit context
def document_action_path(action_opts, url_opts = nil)
if current_exhibit
spotlight.send(action_opts.path || "exhibit_#{action_opts.key}_#{controller_name}_path", url_opts)
model_name = current_exhibit.blacklight_config.document_model.model_name
spotlight.send(action_opts.path || "#{action_opts.key}_exhibit_#{model_name.collection}_path", url_opts)
else
super
end
Expand All @@ -61,7 +62,7 @@ def document_action_path(action_opts, url_opts = nil)
# Helper to turn tag data into facets
def url_to_tag_facet(tag)
if current_exhibit
search_action_url(add_facet_params(blacklight_config.document_model.solr_field_for_tagger(current_exhibit), tag, {}))
search_action_url(search_state.reset.add_facet_params(blacklight_config.document_model.solr_field_for_tagger(current_exhibit), tag))
else
search_action_url(q: tag)
end
Expand Down Expand Up @@ -134,11 +135,6 @@ def carrierwave_url(upload)
end
end

def render_save_this_search?
(current_exhibit && can?(:curate, current_exhibit)) &&
!(params[:controller] == 'spotlight/catalog' && params[:action] == 'admin')
end

def uploaded_field_label(config)
solr_field = Array(config.solr_field || config.field_name).first.to_s
config.label || blacklight_config.index_fields[solr_field].try(:label) || t(".#{solr_field}")
Expand Down

0 comments on commit e0ffaae

Please sign in to comment.