Sha256: fa90b7d48a66730e3683628f413de4990a48049cdf0d07cf0756d70ac2f29604

Contents?: true

Size: 1.52 KB

Versions: 28

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true
module Hyrax
  class SelectTypePresenter
    def initialize(concern)
      @concern = concern
    end

    attr_reader :concern

    def icon_class
      ModelIcon.css_class_for(concern)
    end

    def description
      translate('description')
    end

    def name
      translate('name', object_name.to_s.titleize)
    end

    def switch_to_new_work_path(route_set:, params:)
      col_id = collection_id(params)
      if col_id
        route_set.new_polymorphic_path(concern, add_works_to_collection: col_id)
      else
        route_set.new_polymorphic_path(concern)
      end
    end

    def switch_to_batch_upload_path(route_set:, params:)
      col_id = collection_id(params)
      if col_id
        route_set.new_batch_upload_path(payload_concern: concern, add_works_to_collection: col_id)
      else
        route_set.new_batch_upload_path(payload_concern: concern)
      end
    end

    private

    def object_name
      @object_name ||= concern.model_name.i18n_key
    end

    def translate(key, default = nil)
      defaults = []
      defaults << :"hyrax.select_type.#{object_name}.#{key}"
      defaults << default
      defaults << :"hyrax.select_type.#{key}"
      defaults << ''
      I18n.t(defaults.shift, default: defaults)
    end

    def collection_id(params)
      return nil unless params
      collection_id = params[:add_works_to_collection]
      collection_id ||= params[:id] if params[:id] && params[:controller] == 'hyrax/dashboard/collections'
      collection_id
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/presenters/hyrax/select_type_presenter.rb
hyrax-5.0.4 app/presenters/hyrax/select_type_presenter.rb
hyrax-5.0.3 app/presenters/hyrax/select_type_presenter.rb
hyrax-5.0.2 app/presenters/hyrax/select_type_presenter.rb
hyrax-5.0.1 app/presenters/hyrax/select_type_presenter.rb
hyrax-5.0.0 app/presenters/hyrax/select_type_presenter.rb
hyrax-5.0.0.rc3 app/presenters/hyrax/select_type_presenter.rb
hyrax-5.0.0.rc2 app/presenters/hyrax/select_type_presenter.rb
hyrax-5.0.0.rc1 app/presenters/hyrax/select_type_presenter.rb
hyrax-3.6.0 app/presenters/hyrax/select_type_presenter.rb
hyrax-4.0.0 app/presenters/hyrax/select_type_presenter.rb
hyrax-4.0.0.rc3 app/presenters/hyrax/select_type_presenter.rb
hyrax-4.0.0.rc2 app/presenters/hyrax/select_type_presenter.rb
hyrax-4.0.0.rc1 app/presenters/hyrax/select_type_presenter.rb
hyrax-3.5.0 app/presenters/hyrax/select_type_presenter.rb
hyrax-4.0.0.beta2 app/presenters/hyrax/select_type_presenter.rb
hyrax-3.4.2 app/presenters/hyrax/select_type_presenter.rb
hyrax-4.0.0.beta1 app/presenters/hyrax/select_type_presenter.rb
hyrax-3.4.1 app/presenters/hyrax/select_type_presenter.rb
hyrax-3.4.0 app/presenters/hyrax/select_type_presenter.rb