Sha256: 14fa11ffd5974d1ea982871e82a8c9a727e3a370c72e2836148146d08581f639

Contents?: true

Size: 1.54 KB

Versions: 66

Compression:

Stored size: 1.54 KB

Contents

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

    def initialize(solr_document)
      @solr_document = solr_document
    end

    # Draws a span tag with styles for a bootstrap label
    def render
      content_tag(:span, link_title, title: link_title, class: "label #{dom_label_class}")
    end

    private

      def dom_label_class
        if open_access_with_embargo?
          'label-warning'
        elsif open_access?
          'label-success'
        elsif registered?
          'label-info'
        else
          'label-danger'
        end
      end

      def link_title
        if open_access_with_embargo?
          'Open Access with Embargo'
        elsif open_access?
          'Open Access'
        elsif registered?
          I18n.translate('curation_concerns.institution_name')
        else
          'Private'
        end
      end

      def open_access_with_embargo?
        if @open_access_with_embargo.nil?
          @open_access_with_embargo = open_access? && embargo?
        end
        @open_access_with_embargo
      end

      def open_access?
        @open_access = @solr_document.visibility == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC if @open_access.nil?
        @open_access
      end

      def registered?
        @registered = @solr_document.visibility == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED if @registered.nil?
        @registered
      end

      def embargo?
        @solr_document.embargo_release_date.present?
      end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.7.7 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-2.0.0 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-2.0.0.rc2 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.7.6 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.7.5 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.7.4 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.7.3 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.7.2 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-2.0.0.rc1 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.7.1 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.7.0 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.7.0.beta1 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.6.3 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.6.2 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.6.1 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.6.0 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.5.0 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.4.0 app/presenters/curation_concerns/permission_badge.rb
curation_concerns-1.3.3 app/presenters/curation_concerns/permission_badge.rb