Skip to content

Commit

Permalink
Merge pull request #405 from sul-dlss/edit-in-place-home
Browse files Browse the repository at this point in the history
Add edit in place to home page
  • Loading branch information
cbeer committed Feb 28, 2014
2 parents d31d7ad + c59e66a commit 262bad4
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 56 deletions.
2 changes: 1 addition & 1 deletion app/controllers/spotlight/home_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class HomePagesController < Spotlight::PagesController

def edit
add_breadcrumb t(:'spotlight.curation.sidebar.feature_pages'), exhibit_feature_pages_path(@exhibit)
add_breadcrumb @page.title_or_default, [:edit, @exhibit, @page]
add_breadcrumb @page.title, [:edit, @exhibit, @page]
super
end

Expand Down
5 changes: 4 additions & 1 deletion app/controllers/spotlight/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def start_new_search_session?
end

def update_all_page_params
params.require(:exhibit).permit("#{page_collection_name}_attributes" => [:id, :published, :title, :weight, :display_sidebar, :parent_page_id ])
params.require(:exhibit).permit(
"#{page_collection_name}_attributes" => [:id, :published, :title, :weight, :display_sidebar, :parent_page_id ],
"home_pages_attributes" => [:id, :title, :display_title]
)
end

def human_name
Expand Down
3 changes: 3 additions & 0 deletions app/helpers/spotlight/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ def multi_up_item_grid_caption(block, document)
end
end
end
def disable_save_pages_button?
page_collection_name == "about_pages" && @pages.empty?
end
end
end
1 change: 1 addition & 0 deletions app/models/spotlight/exhibit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Spotlight::Exhibit < ActiveRecord::Base
accepts_nested_attributes_for :searches
accepts_nested_attributes_for :about_pages
accepts_nested_attributes_for :feature_pages
accepts_nested_attributes_for :home_pages
accepts_nested_attributes_for :contacts
accepts_nested_attributes_for :contact_emails
accepts_nested_attributes_for :roles, allow_destroy: true, reject_if: proc {|attr| attr['user_key'].blank?}
Expand Down
9 changes: 7 additions & 2 deletions app/models/spotlight/home_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@ class HomePage < Spotlight::Page
before_save :publish
before_create :default_content

def title_or_default
title.present? ? title : I18n.t('spotlight.pages.index.home_pages.title')
def should_display_title?
display_title
end

private
def self.default_content_text
"This is placeholder content for the exhibit homepage. Curators of this exhibit can edit this page to customize it for the exhibit."
end

def self.default_title_text
"Exhibit Home"
end

def publish
self.display_sidebar = true
self.published = true
end

def default_content
self.title = Spotlight::HomePage.default_title_text
self.content = {
"data" => [
{"type" => "text",
Expand Down
11 changes: 5 additions & 6 deletions app/models/spotlight/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ def top_level_page_or_self
parent_page || self
end

# Subclasses may override this if they have a default
def title_or_default
title
end

def should_generate_new_friendly_id?
title_changed?
end


def should_display_title?
title.present?
end

end
end
2 changes: 1 addition & 1 deletion app/views/spotlight/dashboards/_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tr>
<td>
<h4 class="panel-title"><%= page.title_or_default %></h4>
<h4 class="panel-title"><%= page.title %></h4>
<div class="page-links">
<%= exhibit_view_link page, :class => 'btn btn-link' %> &middot;
<%= exhibit_edit_link page, :class => 'btn btn-link' %>
Expand Down
30 changes: 20 additions & 10 deletions app/views/spotlight/feature_pages/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
<div class="home_page">
<h3><%= t('spotlight.pages.index.feature_pages.home_pages_header') %></h3>
<div class="panel panel-default">
<div class="panel-heading page">
<div class="main">
<h3 class="panel-title"><%= current_exhibit.home_page.title_or_default %></h3>
<div class="page-links">
<%= exhibit_view_link @exhibit.home_page, class: 'btn btn-link' %> &middot;
<%= exhibit_edit_link @exhibit.home_page, class: 'btn btn-link' %>
<%= f.fields_for "home_pages" do |p| %>
<% page = p.object %>
<div class="home_page">
<h3><%= t('spotlight.pages.index.feature_pages.home_pages_header') %></h3>
<div class="panel panel-default">
<div class="panel-heading page">
<div class="main">
<%= p.hidden_field :id, value: page.id , class: 'form-control input-sm' %>
<h3 class="panel-title">
<a href="#edit-in-place" class="field-label"><%= page.title %></a>
<%= p.hidden_field :title, value: page.title , class: 'form-control input-sm' %>
</h3>
<div class="col-sm-9 page-links">
<%= exhibit_view_link page, class: 'btn btn-link' %> &middot;
<%= exhibit_edit_link page, class: 'btn btn-link' %>
</div>
<div class="col-sm-3 display-sidebar-control">
<%= p.check_box :display_title, label: t('spotlight.administration.display_title') %>
</div>
</div>
</div>
</div>
</div>
</div>
<% end %>
4 changes: 2 additions & 2 deletions app/views/spotlight/pages/_order_pages.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= curation_page_title t(:"spotlight.pages.index.#{page_collection_name}.header") %>
<%= bootstrap_form_for @exhibit, url: polymorphic_path([:update_all, @exhibit, page_collection_name]), style: :horizontal, right: "col-sm-10", html: {:'data-form-observer' => true} do |f| %>

<%= render partial: 'header' %>
<%= render partial: 'header', locals: {f: f} %>
<h3><%= t :'.pages_header' %></h3>
<p><%= t :'.instructions' %></p>
<div class="panel-group dd <%= page_collection_name %>_admin" id="nested-pages">
Expand All @@ -15,7 +15,7 @@
</div>
<div class="form-actions pull-right">
<div class="primary-actions">
<%= button_tag action_label(page_collection_name, :update_all), class: "btn btn-primary", disabled: @pages.empty? %>
<%= button_tag action_label(page_collection_name, :update_all), class: "btn btn-primary", disabled: disable_save_pages_button? %>
</div>
</div>
<%- end -%>
Expand Down
4 changes: 2 additions & 2 deletions app/views/spotlight/pages/_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<%= f.hidden_field :id %>
<%= f.hidden_field :weight, data: {property: "weight"} %>
<h3 class="panel-title">
<a href="#edit-in-place" class="field-label"><%= page.title_or_default %></a>
<%= f.hidden_field :title, value: page.title_or_default , class: 'form-control input-sm' %>
<a href="#edit-in-place" class="field-label"><%= page.title %></a>
<%= f.hidden_field :title, value: page.title , class: 'form-control input-sm' %>
</h3>
<div class="row">
<div class="page-links col-sm-9">
Expand Down
2 changes: 1 addition & 1 deletion app/views/spotlight/pages/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="<%= 'col-md-9' if @page.display_sidebar? %>">
<div class="clearfix">
<%= exhibit_edit_link @page, class: 'edit-button pull-right btn btn-primary' if can? :edit, @page %>
<% if @page.title.present? %>
<% if @page.should_display_title? %>
<h1 class="page-title">
<%= @page.title %>
</h1>
Expand Down
1 change: 1 addition & 0 deletions config/locales/spotlight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ en:
settings:
header: "Settings"
show_sidebar: "Show sidebar"
display_title: "Show title"
contact_forms:
new:
header: "Report a problem"
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20131119213142_create_spotlight_pages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def change
t.timestamps
t.integer :parent_page_id
t.boolean :display_sidebar
t.boolean :display_title
end
add_index :spotlight_pages, :exhibit_id
add_index :spotlight_pages, :parent_page_id
Expand Down
46 changes: 45 additions & 1 deletion spec/features/home_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "spec_helper"
describe "Home page" do
let(:exhibit_curator) { FactoryGirl.create(:exhibit_curator) }
let(:exhibit) { Spotlight::Exhibit.default }
before {login_as exhibit_curator}
it "should exist by default on exhibits" do
visit '/'
Expand All @@ -22,6 +23,49 @@
end
fill_in "home_page_title", with: "New Home Page Title"
click_button "Save changes"
expect(page).to have_selector ".page-title", text: "New Home Page Title"
expect(page).to have_content("Page was successfully updated.")

within '.dropdown-menu' do
click_link 'Dashboard'
end
click_link "Feature pages"
expect(page).to have_content "New Home Page Title"
expect(page).to have_selector ".panel-title a", text: "New Home Page Title"
end
it "should allow users to edit the display_title attribute" do
visit '/'
within '.dropdown-menu' do
click_link 'Dashboard'
end

click_link "Feature pages"

# Choose to display the home page title
within(".home_page") do
check "Show title"
end
click_button "Save changes"

visit spotlight.exhibit_home_page_path(exhibit, exhibit.home_page)

# Verify the home page title is being displayed
expect(page).to have_css("h1.page-title", text: exhibit.home_page.title)

within '.dropdown-menu' do
click_link 'Dashboard'
end

click_link "Feature pages"

# Choose to not display the home page title
within(".home_page") do
uncheck "Show title"
end
click_button "Save changes"

visit spotlight.exhibit_home_page_path(exhibit, exhibit.home_page)

# Verify the home page title is not being displayed
expect(page).not_to have_css("h1.page-title", text: exhibit.home_page.title)
end
end
28 changes: 28 additions & 0 deletions spec/features/javascript/feature_page_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,32 @@
expect(page).not_to have_content("Feature pages were successfully updated.")
expect(page).to have_css("h1 small", text: "Feature Pages")
end
it "should be able to update home page titles" do
visit '/'
click_link exhibit_curator.email
within '.dropdown-menu' do
click_link 'Dashboard'
end

click_link "Feature pages"

within(".home_page") do
within("h3.panel-title") do
expect(page).to have_content(exhibit.home_page.title)
expect(page).to have_css("input", visible: false)
click_link(exhibit.home_page.title)
expect(page).to have_css("input", visible: true)
find("input").set("New Home Page Title")
end
end
click_button "Save changes"

expect(page).to have_content("Feature pages were successfully updated.")

within(".home_page") do
within("h3.panel-title") do
expect(page).to have_content("New Home Page Title")
end
end
end
end
9 changes: 3 additions & 6 deletions spec/features/javascript/multi_up_item_grid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@
click_button "Save changes"
expect(page).to have_content("Page was successfully updated.")

within("[data-id='#{feature_page.id}']") do
click_link "View"
end
visit spotlight.exhibit_feature_page_path(exhibit, feature_page)

expect(page).to have_css("[data-id='dq287tq6352']")
expect(page).to have_css("[data-id='jp266yb7109']")
expect(page).not_to have_css("[data-id='zv316zr9542']")
Expand Down Expand Up @@ -103,10 +102,8 @@

expect(page).to have_content("Page was successfully updated.")

visit spotlight.exhibit_feature_page_path(exhibit, feature_page)

within("[data-id='#{feature_page.id}']") do
click_link "View"
end
expect(page).to have_css(".caption", text: "Latin")
end
end
17 changes: 17 additions & 0 deletions spec/helpers/spotlight/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ module Spotlight
expect(helper.should_render_record_thumbnail_title?(titled_document, {'show-title' => false})).to be_false
end
end
describe "disable_save_pages_button?" do
it "should return true if there are no pages and we are on the about pages page" do
helper.should_receive(:page_collection_name).and_return("about_pages")
assign(:pages, [])
expect(helper.disable_save_pages_button?).to be_true
end
it "should return false if there are about pages" do
helper.should_receive(:page_collection_name).and_return("about_pages")
assign(:pages, [{}])
expect(helper.disable_save_pages_button?).to be_false
end
it "should return false if on the feature pages page" do
helper.should_receive(:page_collection_name).and_return("feature_pages")
assign(:pages, [])
expect(helper.disable_save_pages_button?).to be_false
end
end
describe "item grid helpers" do
describe "block objects" do
let(:block1) { {'item-grid-id_0' => "abc", 'item-grid-id_1' => "cba", 'item-grid-display_0' => false, 'item-grid-display_1' => false} }
Expand Down
27 changes: 13 additions & 14 deletions spec/models/spotlight/home_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
it "should be published" do
expect(home_page.published).to be_true
end
describe "title" do
it "should include default text" do
expect(home_page.title).to eq Spotlight::HomePage.default_title_text
end
end
describe "should_display_title?" do
it "should return the display_title attribute" do
home_page.display_title = true
expect(home_page.should_display_title?).to be_true
home_page.display_title = false
expect(home_page.should_display_title?).to be_false
end
end
describe "content" do
it "should include default text" do
expect(home_page.content).to match /#{Spotlight::HomePage.default_content_text}/
Expand All @@ -20,18 +33,4 @@
expect(json["data"].first["data"]["text"]).to eq Spotlight::HomePage.default_content_text
end
end
describe "title_or_default" do
describe "when present" do
subject { FactoryGirl.build(:home_page, title: "Home Page Title") }
its(:title_or_default) { should eq "Home Page Title" }
end
describe "when blank" do
subject { FactoryGirl.build(:home_page, title: "") }
its(:title_or_default) { should eq "Exhibit Home" }
end
describe "when nil" do
subject { FactoryGirl.build(:home_page, title: nil) }
its(:title_or_default) { should eq "Exhibit Home" }
end
end
end
12 changes: 7 additions & 5 deletions spec/models/spotlight/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@

end
end

describe "title_or_default" do
subject { FactoryGirl.build(:about_page, title: 'my title') }
it "should return the title" do
expect(subject.title_or_default).to eq 'my title'
describe "should_display_title?" do
let(:page) { FactoryGirl.create(:feature_page) }
it "should return if the title is present or not" do
expect(page.title).not_to be_blank
expect(page.should_display_title?).to be_true
page.title = ""
expect(page.should_display_title?).to be_false
end
end
end
Loading

0 comments on commit 262bad4

Please sign in to comment.