Skip to content

Commit

Permalink
consolidate CSV handling into BL respond_to Proc and delete redundant…
Browse files Browse the repository at this point in the history
… code

- enable editable site CSV behavior on front-end
- DLC-1157
- DLC-530
  • Loading branch information
barmintor committed Oct 15, 2024
1 parent 490e835 commit de6aedb
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 54 deletions.
13 changes: 0 additions & 13 deletions app/controllers/carnegie_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ class CarnegieController < SubsitesController
prepend_view_path('app/views/signature')
prepend_view_path('app/views/carnegie')

def index
if request.format.csv?
stream_csv_response_for_search_results
else
super
if !has_search_parameters? && request.format.html?
# we override the view rendered for the subsite home on html requests
params[:action] = 'home'
render "home"
end
end
end

def subsite_layout
'signature'
end
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/concerns/dcv/sites/searchable_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ module Dcv::Sites::SearchableController
included do
helper_method :search_action_path, :search_action_url
end

def default_search_mode
search_config = load_subsite&.search_configuration
search_config ? search_config.display_options.default_search_mode : :grid
end

def show_csv_results?
search_config = load_subsite&.search_configuration
search_config ? search_config.display_options.show_csv_results : false
end

def default_search_mode_cookie
slug = load_subsite&.slug || controller_path
cookie_name = "#{slug}_search_mode"
Expand Down
13 changes: 0 additions & 13 deletions app/controllers/lcaaj_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ class LcaajController < SubsitesController
configure_blacklight_scope_constraints(config)
end

def index
if request.format.csv?
stream_csv_response_for_search_results
else
super
if !has_search_parameters? && request.format.html?
# we override the view rendered for the subsite home on html requests
params[:action] = 'home'
render 'home'
end
end
end

def about
end

Expand Down
13 changes: 0 additions & 13 deletions app/controllers/nyre_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@ class NyreController < SubsitesController
prepend_view_path('app/views/signature')
prepend_view_path('app/views/nyre')

def index
if request.format.csv?
stream_csv_response_for_search_results
else
super
if !has_search_parameters? && request.format.html?
# we override the view rendered for the subsite home on html requests
params[:action] = 'home'
render 'home'
end
end
end

def about
end

Expand Down
8 changes: 0 additions & 8 deletions app/controllers/repositories/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ def subsite_styles
["#{subsite_layout}-#{Dcv::Sites::Constants.default_palette}", "catalog"]
end

def index
if request.format.csv?
stream_csv_response_for_search_results
else
super
end
end

def about
end

Expand Down
4 changes: 0 additions & 4 deletions app/controllers/sites/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ def legacy_redirect
end
end

def index
super
end

def subsite_config
@subsite_config ||= (load_subsite&.to_subsite_config || {})
end
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/subsites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ def self.configure_blacklight_scope_constraints(config, exclude_by_id = false)
config.default_solr_params[:fq] << '-id:("' + publishers.map{|info_fedora_prefixed_pid| info_fedora_prefixed_pid.gsub('info:fedora/', '') }.join('" OR "') + '")'
end
end

def index
super
if !has_search_parameters? && request.format.html?
# we override the view rendered for the subsite home on html requests
params[:action] = 'home'
render 'home'
end
end

# PUT /subsite/publish/:id
def update
pid = params[:id]
Expand Down
11 changes: 10 additions & 1 deletion app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,28 @@ def self.configure_blacklight_search_repositories(config, search_configuration:,
else
Dcv::Configurators::DcvBlacklightConfigurator.configure_keyword_search_field(config)
end
config.search_state_fields << :repository_id # allow repository id for routing
Dcv::Configurators::DcvBlacklightConfigurator.default_component_configuration(config, search_bar: Dcv::SearchBar::RepositoriesComponent)
config.search_state_fields << :repository_id # allow repository id for routing
config
end

def self.configure_csv_results(config, search_configuration:)
# the Proc (if configured) is run via instnace_exec in controller
if search_configuration.display_options.show_csv_results
config.index.respond_to.csv = Proc.new { stream_csv_response_for_search_results }
end
end

def self.configure_site_blacklight(config, default_fq:, routing_params:, search_configuration:, search_type:)
config.default_solr_params[:fq] += default_fq
config.show.route = routing_params
config.track_search_session = search_type != SEARCH_CATALOG
if search_type == SEARCH_LOCAL
configure_blacklight_search_local(config, search_configuration: search_configuration)
configure_csv_results(config, search_configuration: search_configuration)
elsif search_type == SEARCH_REPOSITORIES
configure_blacklight_search_repositories(config, search_configuration: search_configuration)
configure_csv_results(config, search_configuration: search_configuration)
else
Dcv::Configurators::DcvBlacklightConfigurator.configure_facet_fields(config)
Dcv::Configurators::DcvBlacklightConfigurator.configure_keyword_search_field(config)
Expand Down
3 changes: 2 additions & 1 deletion lib/dcv/configurators/carnegie_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def self.configure(config, fulltext: true)
config.add_sort_field 'lib_start_date_year_itsi desc', :label => 'date (latest to earliest)'

# Respond to CSV
config.index.respond_to.csv = true
# the Proc is run via instance_exec in controller
config.index.respond_to.csv = Proc.new { stream_csv_response_for_search_results }

default_component_configuration(config, disclaimer: Dcv::Alerts::Disclaimers::CarnegieComponent)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/dcv/configurators/lcaaj_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def self.configure(config)
config.add_sort_field 'lib_start_date_year_itsi desc', :label => 'date (latest to earliest)'

# Respond to CSV
config.index.respond_to.csv = true
# the Proc is run via instance_exec in controller
config.index.respond_to.csv = Proc.new { stream_csv_response_for_search_results }

default_component_configuration(config)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/dcv/configurators/nyre_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def self.configure(config)
config.add_sort_field 'lib_start_date_year_itsi asc', :label => 'date (earliest to latest)'
config.add_sort_field 'lib_start_date_year_itsi desc', :label => 'date (latest to earliest)'

# Respond to CSV
# the Proc is run via instance_exec in controller
config.index.respond_to.csv = Proc.new { stream_csv_response_for_search_results }

default_component_configuration(config)
end

Expand Down

0 comments on commit de6aedb

Please sign in to comment.