Sha256: 88d072ffb00cd71a6063cf25607ab07337e0f9531a6c6aeb90bd5cdb851c22e3

Contents?: true

Size: 1.13 KB

Versions: 29

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true
module Hyrax
  # Presents the list of work type options that a user may choose from when deciding to
  # create a new work
  class SelectTypeListPresenter
    # @param current_user [User]
    def initialize(current_user)
      @current_user = current_user
    end

    class_attribute :row_presenter
    self.row_presenter = SelectTypePresenter

    # @return [Boolean] are there many differnt types to choose?
    def many?
      authorized_models.size > 1
    end

    def authorized_models
      return [] unless @current_user
      @authorized_models ||= Hyrax::QuickClassificationQuery.new(@current_user).authorized_models
    end

    # Return or yield the first model in the list. This is used when the list
    # only has a single element.
    #
    # @yieldparam [Class] model a model class
    # @return [Class] a model class
    def first_model
      yield(authorized_models.first) if block_given?
      authorized_models.first
    end

    # @yieldparam [SelectTypePresenter] presenter a presenter for the item
    def each
      authorized_models.each { |model| yield row_presenter.new(model) }
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

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