Sha256: 66509f8c5ce8b2a0b1f3e802b18bcbd075b94f0429fcc8ff2c6e058d6d0613b7

Contents?: true

Size: 1.35 KB

Versions: 14

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true
module Hyrax
  class WorkflowPresenter
    include ActionView::Helpers::TagHelper

    def initialize(solr_document, current_ability)
      @solr_document = solr_document
      @current_ability = current_ability
    end

    attr_reader :solr_document, :current_ability

    def state
      sipity_entity&.workflow_state_name
    end

    def state_label
      return unless state
      I18n.t("hyrax.workflow.state.#{state}", default: state.humanize)
    end

    # Returns an array of tuples (key, label) appropriate for a radio group
    def actions
      return [] unless sipity_entity && current_ability
      actions = Hyrax::Workflow::PermissionQuery.scope_permitted_workflow_actions_available_for_current_state(entity: sipity_entity, user: current_ability.current_user)
      actions.map { |action| [action.name, action_label(action)] }
    end

    def comments
      return [] unless sipity_entity
      sipity_entity.comments
    end

    def badge
      return unless state
      tag.span(state_label, class: "state state-#{state} label label-primary")
    end

    private

    def action_label(action)
      I18n.t("hyrax.workflow.#{action.workflow.name}.#{action.name}", default: action.name.titleize)
    end

    def sipity_entity
      Sipity::Entity(solr_document)
    rescue PowerConverter::ConversionError
      nil
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hyrax-3.6.0 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.5.0 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.4.2 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.4.1 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.4.0 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.3.0 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.2.0 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.1.0 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.0.2 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.0.1 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.0.0 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.0.0.pre.rc4 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.0.0.pre.rc3 app/presenters/hyrax/workflow_presenter.rb
hyrax-3.0.0.pre.rc2 app/presenters/hyrax/workflow_presenter.rb