-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1443 from mlibrary/breadcrumbs-with-parent
Resolves #1384, modify breadcrumbs for child publisher's views
- Loading branch information
Showing
6 changed files
with
143 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module BreadcrumbsHelper | ||
def breadcrumbs | ||
crumbs = if @presenter.present? && @presenter.class == Hyrax::FileSetPresenter | ||
breadcrumbs_for_file_set(@presenter.monograph_presenter.subdomain, @presenter) | ||
elsif @monograph_presenter.present? | ||
breadcrumbs_for_monograph(@monograph_presenter.subdomain, @monograph_presenter) | ||
end | ||
crumbs || [] | ||
end | ||
|
||
private | ||
|
||
def breadcrumbs_for_monograph(subdomain, presenter) | ||
press = Press.where(subdomain: subdomain)&.first | ||
return [] if press.blank? | ||
|
||
crumbs = possible_parent(press) | ||
crumbs << { href: "", text: presenter.page_title, class: "active" } | ||
end | ||
|
||
def breadcrumbs_for_file_set(subdomain, presenter) | ||
press = Press.where(subdomain: subdomain)&.first | ||
return [] if press.blank? | ||
|
||
crumbs = possible_parent(press) | ||
crumbs << { href: main_app.monograph_catalog_path(presenter.monograph_id), text: presenter.monograph.page_title, class: "" } | ||
crumbs << { href: "", text: presenter.page_title, class: "active" } | ||
end | ||
|
||
def possible_parent(press) | ||
crumbs = [] | ||
if press.parent_id.present? | ||
parent = Press.find(press.parent_id) | ||
crumbs << { href: "/#{parent.subdomain}", text: translate('monograph_catalog.index.home'), class: "" } | ||
crumbs << { href: "/#{press.subdomain}", text: press.name, class: "" } | ||
else | ||
crumbs << { href: "/#{press.subdomain}", text: translate('monograph_catalog.index.home'), class: "" } | ||
end | ||
crumbs | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="row"> | ||
<nav class="breadcrumbs col-sm-12"> | ||
<ol class="breadcrumb"> | ||
<% breadcrumbs.each do |crumb| %> | ||
<%= content_tag(:li, crumb[:href].blank? ? crumb[:text] : content_tag(:a, crumb[:text], href: crumb[:href]), class: crumb[:class]) %> | ||
<% end %> | ||
</ol> | ||
</nav> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe BreadcrumbsHelper do | ||
let!(:press) { create(:press, subdomain: "blue", name: "Blue Press") } | ||
let(:monograph_presenter) { Hyrax::MonographPresenter.new(SolrDocument.new(id: 1, | ||
title_tesim: ["Monograph Title"], | ||
press_tesim: "blue", | ||
has_model_ssim: ['Monograph']), nil) } | ||
|
||
describe "when on a monograph catalog page" do | ||
context "with no parent press" do | ||
it "returns the right breadcrumbs" do | ||
@monograph_presenter = monograph_presenter | ||
expect(breadcrumbs).to match_array([{ href: "/blue", | ||
text: "Home", | ||
class: "" }, | ||
{ href: "", | ||
text: "Monograph Title", | ||
class: "active" }]) | ||
end | ||
end | ||
|
||
context "with a parent press" do | ||
let(:parent) { create(:press, subdomain: "maize", name: "Maize Press") } | ||
it "returns the right breadcrumbs" do | ||
@monograph_presenter = monograph_presenter | ||
press.parent_id = parent.id | ||
press.save! | ||
expect(breadcrumbs).to match_array([{ href: "/maize", | ||
text: "Home", | ||
class: "" }, | ||
{ href: "/blue", | ||
text: "Blue Press", | ||
class: "" }, | ||
{ href: "", | ||
text: "Monograph Title", | ||
class: "active" }]) | ||
end | ||
end | ||
end | ||
|
||
describe "when on a file_set/asset page" do | ||
let(:file_set_presenter) { Hyrax::FileSetPresenter.new(SolrDocument.new(id: 2, | ||
title_tesim: ["FileSet Title"], | ||
has_model_ssim: ["FileSet"], | ||
monograph_id_ssim: 1), nil) } | ||
context "with no parent press" do | ||
it "returns the right breadcrumbs" do | ||
@presenter = file_set_presenter | ||
@presenter.monograph_presenter = monograph_presenter | ||
expect(breadcrumbs).to match_array([{ href: "/blue", | ||
text: "Home", | ||
class: "" }, | ||
{ href: "/concern/monographs/1", | ||
text: "Monograph Title", | ||
class: "" }, | ||
{ href: "", | ||
text: "FileSet Title", | ||
class: "active" }]) | ||
end | ||
end | ||
|
||
context "with a parent press" do | ||
let(:parent) { create(:press, subdomain: "maize", name: "Maize Press") } | ||
it "returns the right breadcrumbs" do | ||
@presenter = file_set_presenter | ||
@presenter.monograph_presenter = monograph_presenter | ||
press.parent_id = parent.id | ||
press.save! | ||
expect(breadcrumbs).to match_array([{ href: "/maize", | ||
text: "Home", | ||
class: "" }, | ||
{ href: "/blue", | ||
text: "Blue Press", | ||
class: "" }, | ||
{ href: "/concern/monographs/1", | ||
text: "Monograph Title", | ||
class: "" }, | ||
{ href: "", | ||
text: "FileSet Title", | ||
class: "active" }]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters