Sha256: 9ad2f510218aec06e1ab07332145425f6ea5cd60573039c3c2402e2c9856474b

Contents?: true

Size: 1.73 KB

Versions: 8

Compression:

Stored size: 1.73 KB

Contents

module Spotlight
  ##
  # CRUD actions for Blacklight metadata fields (e.g. index/show fields for
  # various view types)
  class MetadataConfigurationsController < Spotlight::ApplicationController
    before_action :authenticate_user!
    load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
    load_and_authorize_resource :blacklight_configuration, through: :exhibit, singleton: true, parent: false

    def show
      respond_to do |format|
        format.json do
          render json: @blacklight_configuration.blacklight_config.index_fields.as_json
        end
      end
    end

    def edit
      add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), @exhibit
      add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
      add_breadcrumb t(:'spotlight.curation.sidebar.metadata'), edit_exhibit_metadata_configuration_path(@exhibit)
    end

    def update
      if @blacklight_configuration.update(exhibit_params)
        flash[:notice] = t(:'helpers.submit.blacklight_configuration.updated', model: @blacklight_configuration.class.model_name.human.downcase)
        redirect_to edit_exhibit_metadata_configuration_path(@exhibit)
      else
        render action: 'edit'
      end
    end

    private

    def exhibit_params
      params.require(:blacklight_configuration).permit(
        index_fields: [exhibit_configuration_index_params]
      )
    end

    def exhibit_configuration_index_params
      views = @blacklight_configuration.default_blacklight_config.view.keys | [:show]

      @blacklight_configuration.blacklight_config.index_fields.keys.each_with_object({}) do |element, result|
        result[element] = ([:enabled, :label, :weight] | views)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
blacklight-spotlight-0.8.2 app/controllers/spotlight/metadata_configurations_controller.rb
blacklight-spotlight-0.8.1 app/controllers/spotlight/metadata_configurations_controller.rb
blacklight-spotlight-0.8.0 app/controllers/spotlight/metadata_configurations_controller.rb
blacklight-spotlight-0.7.2 app/controllers/spotlight/metadata_configurations_controller.rb
blacklight-spotlight-0.7.1 app/controllers/spotlight/metadata_configurations_controller.rb
blacklight-spotlight-0.7.0 app/controllers/spotlight/metadata_configurations_controller.rb
blacklight-spotlight-0.6.0 app/controllers/spotlight/metadata_configurations_controller.rb
blacklight-spotlight-0.5.0 app/controllers/spotlight/metadata_configurations_controller.rb