Sha256: 45891a933a299673091319772566dd5c5743b6739cd8f7f0138d44bd2a96a67c

Contents?: true

Size: 961 Bytes

Versions: 48

Compression:

Stored size: 961 Bytes

Contents

module Hyrax
  class PermissionBadge
    include ActionView::Helpers::TagHelper

    VISIBILITY_LABEL_CLASS = {
      authenticated: "label-info",
      embargo: "label-warning",
      lease: "label-warning",
      open: "label-success",
      restricted: "label-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
      content_tag(:span, text, class: "label #{dom_label_class}")
    end

    private

      def dom_label_class
        VISIBILITY_LABEL_CLASS.fetch(@visibility.to_sym)
      end

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

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

Version data entries

48 entries across 48 versions & 1 rubygems

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