Skip to content

Commit

Permalink
Fix link to user's works on dashboard (#6373)
Browse files Browse the repository at this point in the history
  • Loading branch information
abelemlih authored Oct 20, 2023
1 parent e4f7409 commit 9061589
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
13 changes: 13 additions & 0 deletions app/helpers/hyrax/dashboard_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ def number_of_works(user = current_user)
'n/a'
end

def link_to_works(user = current_user)
state = Blacklight::SearchState.new(params, CatalogController.blacklight_config)
facet_type = if Hyrax.config.use_valkyrie?
state.add_facet_params('generic_type_si', 'Work')
else
state.add_facet_params('generic_type_sim', 'Work')
end
facet_depositor = state.add_facet_params('depositor_ssim', user.to_s)
state = Hash.new {}
state["f"] = facet_type["f"].merge(facet_depositor["f"])
link_to(t("hyrax.dashboard.stats.works"), main_app.search_catalog_path(state))
end

# @param user [User]
# @return [Integer] number of FileSets the user deposited
def number_of_files(user = current_user)
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/users/_vitals.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="list-group-item">
<span class="badge dark-text"><%= number_of_works(user) %></span>
<span class="fa fa-upload" aria-hidden="true"></span> <%= link_to_field('', '', t("hyrax.dashboard.stats.works"), {generic_type: "Work", depositor: user.to_s}) %>
<span class="fa fa-upload" aria-hidden="true"></span> <%= link_to_works(user) %>

<ul class="views-downloads-dashboard list-unstyled">
<li><span class="badge badge-optional dark-text"><%= user.total_file_views %></span> <%= t("hyrax.dashboard.stats.file_views").pluralize(user.total_file_views) %></li>
Expand Down
23 changes: 23 additions & 0 deletions spec/helpers/hyrax/dashboard_helper_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@
end
end

describe "#link_to_works" do
let(:user1) { User.new(email: "abc@test") }
let(:user2) { User.new(email: "abc@test.123") }

before do
create_models("GenericWork", user1, user2)
end

context 'when valkyrie is not used' do
it "generates a link to the user's works" do
expect(Hyrax.config).to receive(:use_valkyrie?).and_return(false)
expect(helper.link_to_works(user1)).to include 'generic_type_sim%5D%5B%5D=Work'
end
end

context 'when valkyrie is used' do
it "generates a link to the user's works" do
expect(Hyrax.config).to receive(:use_valkyrie?).and_return(true)
expect(helper.link_to_works(user1)).to include 'generic_type_si%5D%5B%5D=Work'
end
end
end

describe "#number_of_files" do
let(:user1) { User.new(email: "abc@test") }
let(:user2) { User.new(email: "abc@test.123") }
Expand Down

0 comments on commit 9061589

Please sign in to comment.