Sha256: 7d3cebbe70a6a24c4ac90ade15fdf5c9ea72e200fbe681bca5017003c274306a

Contents?: true

Size: 1.45 KB

Versions: 36

Compression:

Stored size: 1.45 KB

Contents

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')
    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)
        defaults = []
        defaults << :"hyrax.select_type.#{object_name}.#{key}"
        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

36 entries across 36 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.9.5 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.9.4 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.9.3 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.9.2 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.9.1 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.9.0 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.8.0 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.7.2 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.7.1 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.7.0 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.6.0 app/presenters/hyrax/select_type_presenter.rb
hyrax-3.0.0.pre.rc1 app/presenters/hyrax/select_type_presenter.rb
hyrax-3.0.0.pre.beta3 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.5.1 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.5.0 app/presenters/hyrax/select_type_presenter.rb
hyrax-3.0.0.pre.beta2 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.4.1 app/presenters/hyrax/select_type_presenter.rb
hyrax-3.0.0.pre.beta1 app/presenters/hyrax/select_type_presenter.rb
hyrax-2.4.0 app/presenters/hyrax/select_type_presenter.rb