-
Notifications
You must be signed in to change notification settings - Fork 65
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 #607 from sul-dlss/exhibit-specific-labels
Settable and Sortable Navigation Links
- Loading branch information
Showing
19 changed files
with
230 additions
and
34 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,26 @@ | ||
Spotlight.onLoad(function(){ | ||
$('#nested-navigation').nestable({maxDepth: 1}); | ||
updateWeightsAndRelationships($('#nested-navigation')); | ||
addRestoreDefaultBehavior(); | ||
}); | ||
|
||
function addRestoreDefaultBehavior(){ | ||
$("[data-behavior='restore-default']").each(function(){ | ||
var hidden = $("[data-default-value]", $(this)); | ||
var value = $($("[data-in-place-edit-target]", $(this)).data('in-place-edit-target'), $(this)); | ||
var button = $("[data-restore-default]", $(this)); | ||
hidden.on('blur', function(){ | ||
if( $(this).val() == $(this).data('default-value') ) { | ||
button.addClass('hidden'); | ||
} else { | ||
button.removeClass('hidden'); | ||
} | ||
}); | ||
button.on('click', function(e){ | ||
e.preventDefault(); | ||
hidden.val(hidden.data('default-value')); | ||
value.text(hidden.data('default-value')); | ||
button.hide(); | ||
}); | ||
}); | ||
} |
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
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
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,20 @@ | ||
module Spotlight | ||
class MainNavigation < ActiveRecord::Base | ||
belongs_to :exhibit | ||
default_scope -> { order("weight ASC") } | ||
scope :browse, -> { where(nav_type: "browse").take } | ||
scope :about, -> { where(nav_type: "about").take } | ||
|
||
def label_or_default | ||
if label.present? | ||
label | ||
else | ||
default_label | ||
end | ||
end | ||
|
||
def default_label | ||
I18n.t(:"spotlight.main_navigation.#{nav_type}") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% if current_exhibit.main_about_page %> | ||
<li class="<%= "active" if on_about_page? %>"><%= link_to navigation.label_or_default, [spotlight, current_exhibit, current_exhibit.main_about_page] %></li> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% if current_exhibit.has_browse_categories? %> | ||
<li class="<%= "active" if on_browse_page? %>"><%= link_to navigation.label_or_default, spotlight.exhibit_browse_index_path(current_exhibit) %></li> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<% published_top_level_feature_pages = current_exhibit.feature_pages.published.at_top_level -%> | ||
<% if published_top_level_feature_pages.present? %> | ||
<% if published_top_level_feature_pages.many? %> | ||
<li class="dropdown"> | ||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><%= navigation.label_or_default %> <b class="caret"></b></a> | ||
<ul class="dropdown-menu"> | ||
<% published_top_level_feature_pages.each do |page| %> | ||
<li><%= link_to page.title, [spotlight, page.exhibit, page] %></li> | ||
<% end %> | ||
</ul> | ||
</li> | ||
<% else %> | ||
<li class="<%= "active" if current_page?(url_for([spotlight, published_top_level_feature_pages.first.exhibit, published_top_level_feature_pages.first])) %>"><%= link_to published_top_level_feature_pages.first.title, [spotlight, published_top_level_feature_pages.first.exhibit, published_top_level_feature_pages.first] %></li> | ||
<% 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
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
12 changes: 12 additions & 0 deletions
12
db/migrate/20140403180324_create_spotlight_main_navigations.rb
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,12 @@ | ||
class CreateSpotlightMainNavigations < ActiveRecord::Migration | ||
def change | ||
create_table :spotlight_main_navigations do |t| | ||
t.string :label | ||
t.integer :weight, default: 20 | ||
t.string :nav_type | ||
t.references :exhibit | ||
t.timestamps | ||
end | ||
add_index :spotlight_main_navigations, :exhibit_id | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
|
||
describe "Main navigation labels are settable" do | ||
let!(:exhibit) { FactoryGirl.create(:exhibit) } | ||
let!(:about) { FactoryGirl.create(:about_page, exhibit: exhibit, published: true) } | ||
before do | ||
about_nav = exhibit.main_navigations.about | ||
about_nav.label = "New About Label" | ||
about_nav.save | ||
browse_nav = exhibit.main_navigations.browse | ||
browse_nav.label = "New Browse Label" | ||
browse_nav.save | ||
search = exhibit.searches.first | ||
search.on_landing_page = true | ||
search.save | ||
exhibit.reload | ||
end | ||
|
||
it "should have the configured about and browse navigation labels" do | ||
visit spotlight.exhibit_path(exhibit) | ||
expect(page).to have_css(".navbar-nav li", text: "New About Label") | ||
expect(page).to have_css(".navbar-nav li", text: "New Browse Label") | ||
end | ||
it "should have the configured about page label in the sidebar" do | ||
visit spotlight.exhibit_about_page_path(exhibit, about) | ||
expect(page).to have_css("#sidebar h4", text: "New About Label") | ||
end | ||
it "should have the configured about page label visible in the breadcrumb" do | ||
visit spotlight.exhibit_about_page_path(exhibit, about) | ||
expect(page).to have_css(".breadcrumb li", text: "New About Label") | ||
end | ||
it "should have the configured browse page label visible in the breadcrumb of the browse index page" do | ||
visit spotlight.exhibit_browse_index_path(exhibit, exhibit.searches.first) | ||
expect(page).to have_content("New Browse Label") | ||
expect(page).to have_css(".breadcrumb li", text: "New Browse Label") | ||
end | ||
it "should have the configured browse page label visible in the breadcrumb of the browse show page" do | ||
visit spotlight.exhibit_browse_path(exhibit, exhibit.searches.first) | ||
expect(page).to have_content("New Browse Label") | ||
expect(page).to have_css(".breadcrumb li", text: "New Browse Label") | ||
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
Oops, something went wrong.