Sha256: 87550ea2aa3dca33c5f4441e49f7a5d1faeb92994c23583930dfca807aaa17bb

Contents?: true

Size: 1.37 KB

Versions: 14

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true
module Hyrax
  module DashboardHelperBehavior
    def on_the_dashboard?
      params[:controller].match(%r{^hyrax/dashboard|hyrax/my})
    end

    # @param user [User]
    # @param where [Hash] applied as the where clause when querying the Hyrax::WorkRelation
    # @return [Integer] number of works matching the where that the user deposited
    # @see Hyrax::WorkRelation
    def number_of_works(user = current_user, where: { generic_type_sim: "Work" })
      field_pairs = field_pairs(user)
      field_pairs.merge!(where)
      Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs).count
    rescue RSolr::Error::ConnectionRefused
      'n/a'
    end

    # @param user [User]
    # @return [Integer] number of FileSets the user deposited
    def number_of_files(user = current_user)
      Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs(user)).count
    rescue RSolr::Error::ConnectionRefused
      'n/a'
    end

    # @param user [User]
    # @return [Integer] number of Collections the user created
    def number_of_collections(user = current_user)
      Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs(user)).count
    rescue RSolr::Error::ConnectionRefused
      'n/a'
    end

    private

    def field_pairs(user)
      { DepositSearchBuilder.depositor_field => user.user_key }
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hyrax-3.6.0 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-4.0.0 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-4.0.0.rc3 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-4.0.0.rc2 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-4.0.0.rc1 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-3.5.0 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-4.0.0.beta2 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-3.4.2 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-4.0.0.beta1 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-3.4.1 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-3.4.0 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-3.3.0 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-3.2.0 app/helpers/hyrax/dashboard_helper_behavior.rb
hyrax-3.1.0 app/helpers/hyrax/dashboard_helper_behavior.rb