Skip to content

Commit

Permalink
testability/nil safety in repositories/header_navbar.html.erb (DLC-1157)
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Sep 26, 2024
1 parent 11cf1cf commit 6bfddcc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/dcv/sites/configured_layouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def subsite_palette

def subsite_styles
return [subsite_layout] unless Dcv::Sites::Constants::PORTABLE_LAYOUTS.include?(subsite_layout)
["#{subsite_layout}-#{subsite_palette}"]
subsite_layout == Site::LAYOUT_REPOSITORIES ? ["#{Site::LAYOUT_GALLERY}-#{subsite_palette}"] : ["#{subsite_layout}-#{subsite_palette}"]
end

def signature_image_path
Expand Down
6 changes: 5 additions & 1 deletion app/helpers/subsite_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module SubsiteHelper
def active_site_palette
(@subsite.layout == 'custom') ? 'custom' : controller.subsite_palette
(@subsite&.layout == 'custom') ? 'custom' : controller.subsite_palette
end

def active_site_js
(controller.subsite_layout == Site::LAYOUT_REPOSITORIES) ? 'gallery' : controller.subsite_layout
end

def map_search_settings_for_subsite
Expand Down
27 changes: 27 additions & 0 deletions app/views/layouts/repositories.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<%= render partial: 'shared/head_includes' %>
<%= stylesheet_link_tag *Array(subsite_styles) %>
<script>
window.CULh_feedback_url = '<%= t("feedback.#{@subsite&.slug}", default: t('feedback.default'))%>';
</script>
</head>
<body class="<%= render_body_class %> dcv <%= render_subsite_body_classes %> <%= params[:action] %>">

<%= render :partial => 'shared/topnavbar' %>

<div id="outer-wrapper" class="container-fluid p-0">
<%= render partial: 'header_navbar' %>
<%= render partial: 'shared/modal' %>

<div id="main-container" class="container">
<%= render :partial=>'shared/flash_msg', layout: 'shared/flash_messages' %>
<%= render partial: 'shared/alert' %>
<%= yield %>
</div>
</div><!--/#outer-wrapper-->
<%= render Dcv::FooterComponent.new(subsite: @subsite, repository_id: params[:repository_id]) %>
</body>
</html>
12 changes: 6 additions & 6 deletions app/views/repositories/_header_navbar.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<%
repository_key = params[:repository_id]
template_key = repository_key.downcase
template_key.gsub!("-","")
template_key = repository_key&.downcase
template_key&.gsub!("-","")
%>
<% if current_page?(repository_url(repository_key)) or current_page?(repository_reading_room_url(repository_id: repository_key)) %>
<% if repository_key && (current_page?(repository_url(repository_key)) or current_page?(repository_reading_room_url(repository_id: repository_key))) %>
<nav class="navbar navbar-expand d-flex flex-column" id="site-banner">
<h1>Columbia University Libraries Digital Collections</h1>
<h2><%= repository_physical_location(repository_key) %></h2>
</nav>
<% else %>
<% elsif repository_key %>
<nav class="navbar navbar-expand d-flex flex-md-row flex-sm-column" id="site-banner">
<a href="<%= repository_path(repository_key) %>" id="site-title" class="navbar-brand text-lg-left"><%= repository_physical_location(repository_key) %></a>
<%= render Dcv::SearchBar::RepositoriesComponent.new(
Expand All @@ -17,9 +17,9 @@ template_key.gsub!("-","")
params: search_state.params_for_search.except(:qt),
autocomplete_path: search_action_path(action: :suggest),
content_availability: 'onsite'
) -%>
) if params[:repository_id] -%>
</nav>
<% end %><%= render "reading_room/#{template_key}/secondary_nav" %>
<% end %><%= render("reading_room/#{template_key}/secondary_nav") if template_key %>
<% if controller.reading_room_client? -%>
<div class="note">This workstation provides access to content that can only be viewed on-site in the reading room.</div>
<% end -%>
4 changes: 2 additions & 2 deletions app/views/shared/_head_includes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ DLC VERSION: <%= IO.read(Rails.root.to_s+'/VERSION') %> -->
<script>
window.DCV = window.DCV || {};
DCV.subsite_key = '<%= subsite_key %>';
DCV.subsite_layout = '<%= subsite_layout %>';
DCV.subsite_layout = '<%= active_site_js %>';
</script>
<% end %>
<%- js_packs = ["application", "dcv"].concat(Array(subsite_layout)).uniq %>
<%- js_packs = ["application", "dcv"].concat(Array(active_site_js)).uniq %>
<%- if params[:action] == 'synchronizer' %>
<%- js_packs << 'ohsynchronizer' %>
<%- else -%>
Expand Down

0 comments on commit 6bfddcc

Please sign in to comment.