Sha256: f1d23f18ec5e5e7475613ca2a0aa7d197ee618cc764825670b3f2f1d164b1706

Contents?: true

Size: 1.15 KB

Versions: 58

Compression:

Stored size: 1.15 KB

Contents

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 class that decends from ActiveFedora::Base
    # @return [Class] a class that decends from ActiveFedora::Base
    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

58 entries across 58 versions & 2 rubygems

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