Sha256: 2016f0fa193ea825e2e42404b7a23e4daff7950fcaedc24493116c02349b3ee0

Contents?: true

Size: 1023 Bytes

Versions: 14

Compression:

Stored size: 1023 Bytes

Contents

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

    VISIBILITY_LABEL_CLASS = {
      authenticated: "badge-info",
      embargo: "badge-warning",
      lease: "badge-warning",
      open: "badge-success",
      restricted: "badge-danger"
    }.freeze

    # @param visibility [String] the current visibility
    def initialize(visibility)
      @visibility = visibility
    end

    # Draws a span tag with styles for a bootstrap label
    def render
      tag.span(text, class: "badge #{dom_label_class}")
    end

    private

    def dom_label_class
      VISIBILITY_LABEL_CLASS.fetch(@visibility&.to_sym, 'badge-info')
    end

    def text
      if registered?
        Institution.name
      else
        visibility_key = @visibility || 'unknown'
        I18n.t("hyrax.visibility.#{visibility_key}.text")
      end
    end

    def registered?
      @visibility == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/presenters/hyrax/permission_badge.rb
hyrax-5.0.4 app/presenters/hyrax/permission_badge.rb
hyrax-5.0.3 app/presenters/hyrax/permission_badge.rb
hyrax-5.0.2 app/presenters/hyrax/permission_badge.rb
hyrax-5.0.1 app/presenters/hyrax/permission_badge.rb
hyrax-5.0.0 app/presenters/hyrax/permission_badge.rb
hyrax-5.0.0.rc3 app/presenters/hyrax/permission_badge.rb
hyrax-5.0.0.rc2 app/presenters/hyrax/permission_badge.rb
hyrax-5.0.0.rc1 app/presenters/hyrax/permission_badge.rb
hyrax-4.0.0 app/presenters/hyrax/permission_badge.rb
hyrax-4.0.0.rc3 app/presenters/hyrax/permission_badge.rb
hyrax-4.0.0.rc2 app/presenters/hyrax/permission_badge.rb
hyrax-4.0.0.rc1 app/presenters/hyrax/permission_badge.rb
hyrax-4.0.0.beta2 app/presenters/hyrax/permission_badge.rb