Sha256: 2c7a3371fd806e2a7cf1f299722b0ddf569e19c5b2aa44234f8fec37bdac14e3

Contents?: true

Size: 1.16 KB

Versions: 57

Compression:

Stored size: 1.16 KB

Contents

module Hyrax
  module Admin
    class RepositoryObjectPresenter
      include Blacklight::SearchHelper

      def as_json(*)
        counts.map do |k, v|
          { label: I18n.translate(k, scope: 'hyrax.admin.stats.repository_objects.series'),
            value: v }
        end
      end

      private

        delegate :blacklight_config, to: CatalogController

        def counts
          translation = { 'false' => :published, 'true' => :unpublished, nil => :unknown }
          raw_count = Hash[*results.to_a.flatten]
          @counts ||= raw_count.each_with_object({}) { |(k, v), o| o[translation[k]] = v }
        end

        def search_builder
          Stats::WorkStatusSearchBuilder.new(self)
        end

        # results come from Solr in an array where the first item is the status and
        # the second item is the count
        # @example
        #   [ "true", 55, "false", 205, nil, 11 ]
        # @return [#each] an enumerable object of tuples (status and count)
        def results
          facet_results = repository.search(search_builder)
          facet_results.facet_fields[IndexesWorkflow.suppressed_field].each_slice(2)
        end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

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