Sha256: d4e799e7d4915675bd19e2ea9fa40408cc4c45b3cb48d577d1c2fbd736f7be04

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

module Sufia
  # 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 ||= CurationConcerns::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

7 entries across 7 versions & 1 rubygems

Version Path
sufia-7.4.1 app/presenters/sufia/select_type_list_presenter.rb
sufia-7.4.0 app/presenters/sufia/select_type_list_presenter.rb
sufia-7.3.1 app/presenters/sufia/select_type_list_presenter.rb
sufia-7.3.0 app/presenters/sufia/select_type_list_presenter.rb
sufia-7.3.0.rc3 app/presenters/sufia/select_type_list_presenter.rb
sufia-7.3.0.rc2 app/presenters/sufia/select_type_list_presenter.rb
sufia-7.3.0.rc1 app/presenters/sufia/select_type_list_presenter.rb