Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace AF.where in dashboard_helper_behavior #4929

Merged
merged 1 commit into from
May 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions app/helpers/hyrax/dashboard_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,40 @@ def on_the_dashboard?

# @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" })
where_clause = where.merge(DepositSearchBuilder.depositor_field => user.user_key)
Hyrax::WorkRelation.new.where(where_clause).count
field_pairs = field_pairs(user)
field_pairs.merge!(where)
count(Hyrax::SolrQueryBuilderService.construct_query(field_pairs))
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)
::FileSet.where(DepositSearchBuilder.depositor_field => user.user_key).count
count(Hyrax::SolrQueryBuilderService.construct_query_for_model(::FileSet, field_pairs(user)))
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)
::Collection.where(DepositSearchBuilder.depositor_field => user.user_key).count
count(Hyrax::SolrQueryBuilderService.construct_query_for_model(::Collection, field_pairs(user)))
rescue RSolr::Error::ConnectionRefused
'n/a'
end

private

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

def count(query)
Hyrax::SolrService.count(query)
end
end
end