app/controllers/spotlight/searches_controller.rb in blacklight-spotlight-0.3.1 vs app/controllers/spotlight/searches_controller.rb in blacklight-spotlight-0.4.1
- old
+ new
@@ -18,16 +18,17 @@
end
def index
respond_to do |format|
format.html
- format.json { render json: @searches, root: false }
+ format.json { render json: @searches.published.as_json(methods: [:count, :thumbnail_image_url]), root: false }
end
end
def autocomplete
- (_, document_list) = get_search_results autocomplete_params
+ (_, document_list) = get_search_results(autocomplete_params, blacklight_config.default_autocomplete_solr_params)
+
respond_to do |format|
format.json do
render json: { docs: autocomplete_json_response(document_list) }
end
end
@@ -37,11 +38,11 @@
add_breadcrumb @search.title, edit_exhibit_search_path(@search.exhibit, @search)
@exhibit = @search.exhibit
end
def update
- if @search.update params.require(:search).permit(:title, :short_description, :long_description, :featured_item_id)
+ if @search.update search_params
redirect_to exhibit_searches_path(@search.exhibit), notice: t(:'helpers.submit.search.updated', model: @search.class.model_name.human.downcase)
else
render action: 'edit'
end
end
@@ -58,16 +59,23 @@
t(:'helpers.submit.search.batch_error', model: Spotlight::Search.model_name.human.pluralize.downcase)
end
redirect_to :back, notice: notice
end
+ def show
+ redirect_to exhibit_browse_url(@search.exhibit, @search)
+ end
+
protected
def autocomplete_params
+ ##
+ # Ideally, we would be able to search within results for all queries, but in practice
+ # searching within saved searches with a `q` parameter is.. hard.
+
query_params = @search.query_params.with_indifferent_access
- query_params[:q] = [query_params[:q], params[:q]].compact.join(' ')
- query_params
+ query_params.merge(q: params[:q])
end
def attach_breadcrumbs
e = @exhibit || (@search.exhibit if @search)
add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: e.title), e
@@ -75,9 +83,17 @@
add_breadcrumb t(:'spotlight.curation.sidebar.browse'), exhibit_searches_path(e)
end
def batch_search_params
params.require(:exhibit).permit("searches_attributes" => [:id, :on_landing_page, :weight])
+ end
+
+ def search_params
+ params.require(:search).permit(:title, :long_description, masthead_attributes: featured_image_attributes, thumbnail_attributes: featured_image_attributes)
+ end
+
+ def featured_image_attributes
+ [:display, :source, :image, :remote_image_url, :document_global_id, :image_crop_x, :image_crop_y, :image_crop_w, :image_crop_h]
end
def only_curators!
authorize! :curate, @exhibit if @exhibit
end