Skip to content

Commit 3f96ec5

Browse files
committed
Add quality-of-life improvement to view a single nav item at a time with its children
1 parent 2ca37ac commit 3f96ec5

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

app/controllers/better_together/navigation_items_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def index
1717

1818
def show
1919
authorize @navigation_item
20+
render 'better_together/navigation_areas/show'
2021
end
2122

2223
def new

app/models/better_together/navigation_item.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def title=(arg, options = {}, locale: I18n.locale)
160160
super(arg, locale: locale, **options)
161161
end
162162

163+
def to_s
164+
title
165+
end
166+
163167
def url
164168
fallback_url = '#'
165169

app/views/better_together/navigation_areas/show.html.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<p><strong><%= resource_class.human_attribute_name(:visible) %>:</strong> <%= @navigation_area.visible ? 'Yes' : 'No' %></p>
1616
<p><strong><%= resource_class.human_attribute_name(:slug) %>:</strong> <%= @navigation_area.slug %></p>
1717

18+
<% if @navigation_item&.child? %>
19+
<p><strong><%= resource_class.human_attribute_name(:parent) %>:</strong> <%= link_to @navigation_item.parent, [@navigation_area, @navigation_item.parent] %></p>
20+
<% end %>
1821
<h2><%= BetterTogether::NavigationItem.model_name.human.pluralize %></h2>
19-
<%= render partial: 'better_together/navigation_items/navigation_items_table', locals: { navigation_items: @navigation_area.navigation_items.top_level.positioned, navigation_area: @navigation_area } %>
22+
<%= render partial: 'better_together/navigation_items/navigation_items_table', locals: { navigation_items: (@navigation_item ? [ @navigation_item ] :@navigation_area.navigation_items.top_level.positioned), navigation_area: @navigation_area } %>
2023
</div>

app/views/better_together/navigation_items/_navigation_item_row.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<% if item.child? %>
44
<i class="fas fa-arrow-turn-up fa-rotate-90 me-2"></i>
55
<% end %>
6-
<%= item.title %>
6+
<%= link_to item.title, [item.navigation_area, item], class: 'text-decoration-none' %>
77
</td>
88
<td><%= item.item_type %></td>
99
<td><%= item.url %></td>

0 commit comments

Comments
 (0)