Skip to content

Commit

Permalink
Merge pull request #1029 from projecthydra-labs/split_pages_from_cont…
Browse files Browse the repository at this point in the history
…ent_blocks_406

Split page-type content blocks into new controller and route
  • Loading branch information
mjgiarlo committed May 24, 2017
2 parents fbb3b81 + 1320ca6 commit de27154
Show file tree
Hide file tree
Showing 21 changed files with 334 additions and 95 deletions.
3 changes: 2 additions & 1 deletion app/controllers/hyrax/admin/features_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class FeaturesController < Flipflop::FeaturesController
def index
add_breadcrumb t(:'hyrax.controls.home'), root_path
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
add_breadcrumb t(:'hyrax.admin.sidebar.settings'), hyrax.admin_features_path
add_breadcrumb t(:'hyrax.admin.sidebar.configuration'), '#'
add_breadcrumb t(:'hyrax.admin.sidebar.technical'), hyrax.admin_features_path
super
end
end
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/hyrax/content_blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ContentBlocksController < ApplicationController
def edit
add_breadcrumb t(:'hyrax.controls.home'), root_path
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
add_breadcrumb t(:'hyrax.admin.sidebar.configuration'), '#'
add_breadcrumb t(:'hyrax.admin.sidebar.content_blocks'), hyrax.edit_content_blocks_path
end

Expand All @@ -22,9 +23,7 @@ def update
protected

def permitted_params
params.require(:content_block).permit(:about_page,
:help_page,
:marketing_text,
params.require(:content_block).permit(:marketing_text,
:announcement_text,
:featured_researcher)
end
Expand Down
42 changes: 40 additions & 2 deletions app/controllers/hyrax/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
module Hyrax
# Shows the about and help page
class PagesController < ApplicationController
helper Hyrax::ContentBlockHelper
load_and_authorize_resource class: ContentBlock, except: :show
layout :pages_layout

layout 'homepage'
helper Hyrax::ContentBlockHelper

def show
@page = ContentBlock.find_or_create_by(name: params[:id])
end

def edit
add_breadcrumb t(:'hyrax.controls.home'), root_path
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
add_breadcrumb t(:'hyrax.admin.sidebar.configuration'), '#'
add_breadcrumb t(:'hyrax.admin.sidebar.pages'), hyrax.edit_pages_path
end

def update
respond_to do |format|
if @page.update(value: update_value_from_params)
format.html { redirect_to hyrax.edit_pages_path, notice: t(:'hyrax.pages.updated') }
else
format.html { render :edit }
end
end
end

protected

def permitted_params
params.require(:content_block).permit(:about_page, :help_page)
end

# When a request comes to the controller, it will be for one and
# only one of the content blocks. Params always looks like:
# {'about_page' => 'Here is an awesome about page!'}
# So reach into permitted params and pull out the first value.
def update_value_from_params
permitted_params.values.first
end

private

def pages_layout
action_name == 'show' ? 'homepage' : 'dashboard'
end
end
end
2 changes: 1 addition & 1 deletion app/presenters/hyrax/menu_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(view_context)
# Returns true if the current controller happens to be one of the controllers that deals
# with settings. This is used to keep the parent section on the sidebar open.
def settings_section?
%w[appearances content_blocks features].include?(controller_name)
%w[appearances content_blocks features pages].include?(controller_name)
end

# @param options [Hash, String] a hash or string representing the path. Hash is prefered as it
Expand Down
46 changes: 4 additions & 42 deletions app/views/hyrax/content_blocks/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<div class="panel panel-default tabs">
<ul class="nav nav-tabs" role="tablist">
<li class="active">
<a href="#about_page" role="tab" data-toggle="tab"><%= t(:'hyrax.content_blocks.tabs.about_page') %></a>
</li>
<li>
<a href="#help_page" role="tab" data-toggle="tab"><%= t(:'hyrax.content_blocks.tabs.help_page') %></a>
</li>
<li>
<a href="#announcement_text" role="tab" data-toggle="tab"><%= t(:'hyrax.content_blocks.tabs.announcement_text') %></a>
</li>
Expand All @@ -17,29 +11,13 @@
</li>
</ul>
<div class="tab-content">
<div id="about_page" class="tab-pane active">
<div id="announcement_text" class="tab-pane active">
<div class="panel panel-default labels">
<%= simple_form_for ContentBlock.about_page, url: hyrax.content_block_path(ContentBlock.about_page) do |f| %>
<div class="panel-body">
<div class="field form-group">
<%= f.label :about_page %><br>
<%= f.text_area :about_page, value: f.object.value, class: 'form-control tinymce', rows: 20, cols: 120 %>
</div>
</div>
<div class="panel-footer">
<%= link_to t(:'hyrax.content_blocks.cancel'), hyrax.admin_admin_sets_path, class: 'btn btn-default pull-right'%>
<%= f.button :submit, class: 'btn btn-primary pull-right'%>
</div>
<% end %>
</div>
</div>
<div id="help_page" class="tab-pane">
<div class="panel panel-default labels">
<%= simple_form_for ContentBlock.help_page, url: hyrax.content_block_path(ContentBlock.help_page) do |f| %>
<%= simple_form_for ContentBlock.announcement_text, url: hyrax.content_block_path(ContentBlock.announcement_text) do |f| %>
<div class="panel-body">
<div class="field form-group">
<%= f.label :help_page %><br>
<%= f.text_area :help_page, value: f.object.value, class: 'form-control tinymce', rows: 20, cols: 120 %>
<%= f.label :announcement_text %><br>
<%= f.text_area :announcement_text, value: f.object.value, class: 'form-control tinymce', rows: 20, cols: 120 %>
</div>
</div>
<div class="panel-footer">
Expand All @@ -65,22 +43,6 @@
<% end %>
</div>
</div>
<div id="announcement_text" class="tab-pane">
<div class="panel panel-default labels">
<%= simple_form_for ContentBlock.announcement_text, url: hyrax.content_block_path(ContentBlock.announcement_text) do |f| %>
<div class="panel-body">
<div class="field form-group">
<%= f.label :announcement_text %><br>
<%= f.text_area :announcement_text, value: f.object.value, class: 'form-control tinymce', rows: 20, cols: 120 %>
</div>
</div>
<div class="panel-footer">
<%= link_to t(:'hyrax.content_blocks.cancel'), hyrax.admin_admin_sets_path, class: 'btn btn-default pull-right'%>
<%= f.button :submit, class: 'btn btn-primary pull-right'%>
</div>
<% end %>
</div>
</div>
<div id="featured_researcher" class="tab-pane">
<div class="panel panel-default labels">
<%= simple_form_for ContentBlock.featured_researcher, url: hyrax.content_block_path(ContentBlock.featured_researcher) do |f| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/content_blocks/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% content_for :page_header do %>
<h1><span class="fa fa-file-text-o"></span> <%= t(:'hyrax.admin.sidebar.content_blocks') %></h1>
<h1><span class="fa fa-square-o"></span> <%= t(:'hyrax.admin.sidebar.content_blocks') %></h1>
<% end %>

<div class="row">
Expand Down
5 changes: 4 additions & 1 deletion app/views/hyrax/dashboard/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@
<% end %>
<% end %>
<% if can?(:manage, Hyrax::Feature) %>
<%= menu.nav_link(hyrax.edit_pages_path) do %>
<span class="fa fa-file-text-o"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.pages') %></span>
<% end %>
<%= menu.nav_link(hyrax.edit_content_blocks_path) do %>
<span class="fa fa-file-text-o"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.content_blocks') %></span>
<span class="fa fa-square-o"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.content_blocks') %></span>
<% end %>
<%= menu.nav_link(hyrax.admin_features_path) do %>
<span class="fa fa-wrench"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.technical') %></span>
Expand Down
44 changes: 44 additions & 0 deletions app/views/hyrax/pages/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div class="panel panel-default tabs">
<ul class="nav nav-tabs" role="tablist">
<li class="active">
<a href="#about_page" role="tab" data-toggle="tab"><%= t(:'hyrax.pages.tabs.about_page') %></a>
</li>
<li>
<a href="#help_page" role="tab" data-toggle="tab"><%= t(:'hyrax.pages.tabs.help_page') %></a>
</li>
</ul>
<div class="tab-content">
<div id="about_page" class="tab-pane active">
<div class="panel panel-default labels">
<%= simple_form_for ContentBlock.about_page, url: hyrax.page_path(ContentBlock.about_page) do |f| %>
<div class="panel-body">
<div class="field form-group">
<%= f.label :about_page %><br>
<%= f.text_area :about_page, value: f.object.value, class: 'form-control tinymce', rows: 20, cols: 120 %>
</div>
</div>
<div class="panel-footer">
<%= link_to t(:'hyrax.pages.cancel'), hyrax.admin_admin_sets_path, class: 'btn btn-default pull-right'%>
<%= f.button :submit, class: 'btn btn-primary pull-right'%>
</div>
<% end %>
</div>
</div>
<div id="help_page" class="tab-pane">
<div class="panel panel-default labels">
<%= simple_form_for ContentBlock.help_page, url: hyrax.page_path(ContentBlock.help_page) do |f| %>
<div class="panel-body">
<div class="field form-group">
<%= f.label :help_page %><br>
<%= f.text_area :help_page, value: f.object.value, class: 'form-control tinymce', rows: 20, cols: 120 %>
</div>
</div>
<div class="panel-footer">
<%= link_to t(:'hyrax.pages.cancel'), hyrax.admin_admin_sets_path, class: 'btn btn-default pull-right'%>
<%= f.button :submit, class: 'btn btn-primary pull-right'%>
</div>
<% end %>
</div>
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions app/views/hyrax/pages/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% content_for :page_header do %>
<h1><span class="fa fa-file-text-o"></span> <%= t(:'hyrax.admin.sidebar.pages') %></h1>
<% end %>

<div class="row">
<div class="col-md-12">
<%= render 'form' %>
</div>
</div>
9 changes: 7 additions & 2 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ en:
configuration: "Configuration"
content_blocks: "Content Blocks"
notifications: "Notifications"
pages: "Pages"
profile: "Profile"
repository_objects: "Repository Contents"
settings: "Settings"
Expand Down Expand Up @@ -358,10 +359,8 @@ en:
content_blocks:
cancel: "Cancel"
tabs:
about_page: "About Page"
announcement_text: "Announcement Text"
featured_researcher: "Featured Researcher"
help_page: "Help Page"
marketing_text: "Marketing Text"
updated: "Content blocks updated."
controls:
Expand Down Expand Up @@ -535,6 +534,12 @@ en:
single: "has been saved."
subject: "Batch upload complete"
title: "Files uploaded successfully"
pages:
cancel: "Cancel"
tabs:
about_page: "About Page"
help_page: "Help Page"
updated: "Pages updated."
passive_consent_to_agreement: "By saving this work I agree to the"
search:
button:
Expand Down
9 changes: 7 additions & 2 deletions config/locales/hyrax.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ es:
configuration: "Configuración"
content_blocks: "Bloques de Contenido"
notifications: "Notificaciones"
pages: "Páginas"
profile: "Perfil"
repository_objects: "Contenido del repositorio"
settings: "Ajustes"
Expand Down Expand Up @@ -358,10 +359,8 @@ es:
content_blocks:
cancel: "Cancelar"
tabs:
about_page: "Acerca de la Página"
announcement_text: "Texto del Anuncio"
featured_researcher: "Investigador Destacado"
help_page: "Página de Ayuda"
marketing_text: "Texto de Marketing"
updated: "Bloques de contenido actualizados."
controls:
Expand Down Expand Up @@ -535,6 +534,12 @@ es:
single: "ha sido guardado."
subject: "Carga en lote completa"
title: "Archivos cargados satisfactoriamente"
pages:
cancel: "Cancelar"
tabs:
about_page: "Acerca de la Página"
help_page: "Página de Ayuda"
updated: "Páginas actualizadas."
passive_consent_to_agreement: "Al salvar este trabajo yo acepto a"
search:
button:
Expand Down
9 changes: 7 additions & 2 deletions config/locales/hyrax.zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ zh:
configuration: "配置"
content_blocks: "内容块"
notifications: "通知"
pages: "网页"
profile: "个人资料"
repository_objects: "储存库内容"
settings: "设置"
Expand Down Expand Up @@ -360,10 +361,8 @@ zh:
content_blocks:
cancel: "取消"
tabs:
about_page: "关于页面"
announcement_text: "公告文字"
featured_researcher: "特色研究员"
help_page: "帮助页面"
marketing_text: "营销文字"
updated: "内容块已更新。"
controls:
Expand Down Expand Up @@ -535,6 +534,12 @@ zh:
single: "已保存。"
subject: "批量上传完成"
title: "文件上传成功"
pages:
cancel: "取消"
tabs:
about_page: "关于页面"
help_page: "帮助页面"
updated: "页面更新。"
passive_consent_to_agreement: "保存这件作品表明我同意"
search:
button:
Expand Down
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@
get :edit
end
end
resources :pages, only: [] do
member do
patch :update
end
collection do
get :edit
end
end
get 'about' => 'pages#show', id: 'about_page'
get 'help' => 'pages#show', id: 'help_page'

Expand Down
4 changes: 4 additions & 0 deletions spec/controllers/hyrax/admin/features_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
end

it "is successful" do
expect(controller).to receive(:add_breadcrumb).with('Home', root_path)
expect(controller).to receive(:add_breadcrumb).with('Administration', dashboard_path)
expect(controller).to receive(:add_breadcrumb).with('Configuration', '#')
expect(controller).to receive(:add_breadcrumb).with('Technical', admin_features_path)
get :index
expect(response).to be_success
end
Expand Down

0 comments on commit de27154

Please sign in to comment.