docbrown/app/views/admin/shared/_nested_sidebar.html.erb
Ridhwana 320eb86dc2
RFC 50: Interaction tweaks (take two) (#13576)
* feat: add the collapse style css + a script for the intercepting the bootstrap event

* chore: remove old code

* Add some guards for missing elements and simplify show/hide collapse interaction

* Update app/assets/stylesheets/admin.scss

Co-authored-by: rhymes <rhymes@hey.com>

Co-authored-by: rhymes <rhymes@hey.com>
2021-04-30 13:01:55 +02:00

54 lines
2.5 KiB
Text

<% menu_items.each do |group_name, group| %>
<li>
<% if group[:children].length == 1 %>
<% if group[:children][0][:visible] %>
<a class="crayons-link crayons-link--block <%= "crayons-link--current" if deduced_scope(request) == group[:children][0][:controller] %>"
href="/admin/<%= group[:children][0][:controller] %>"
aria-current="<%= "page" if deduced_controller(request) == group[:children][0][:controller] %>"
data-action="click->sidebar#expandDropdown">
<%= inline_svg_tag(group[:svg], aria_hidden: true, class: "dropdown-icon crayons-icon") %>
<%= display_name(group_name) %>
</a>
<% end %>
<% else %>
<button class="crayons-link crayons-link--block cursor-pointer <%= "crayons-link--current" if deduced_scope(request) == group_name.to_s %>"
id="<%= group_name %>_button"
data-toggle="collapse"
data-target="#<%= group_name %>"
aria-expanded="<%= (deduced_scope(request) == group_name.to_s).to_s %>"
aria-controls="<%= group_name %>"
data-action="click->sidebar#expandDropdown">
<%= inline_svg_tag(group[:svg], aria_hidden: true, class: "dropdown-icon crayons-icon") %>
<%= display_name(group_name) %>
</button>
<ul id="<%= group_name %>"
data-sidebar-target="submenu"
class="js-menu-activator <%= deduced_scope(request) == group_name.to_s ? "collapse show" : "collapse" %>"
data-target-href="/admin/<%= group_name %>/<%= group[:children][0][:controller] %>">
<% group[:children].each do |item| %>
<% if item[:visible] %>
<li>
<a class="crayons-link crayons-link--block ml-7 <%= "fw-bold" if deduced_controller(request) == item[:controller].to_s %>"
href="/admin/<%= group_name %>/<%= item[:controller] %>"
aria-current="<%= "page" if deduced_controller(request) == item[:controller].to_s %>">
<%= item[:name].to_s.titleize %>
</a>
</li>
<% end %>
<% end %>
</ul>
<% end %>
</li>
<% end %>
<script>
$('.js-menu-activator').on('show.bs.collapse', function (event) {
const destinationPath = event.target.getAttribute('data-target-href');
const subMenu = document.querySelector(`a[href='${destinationPath}']`);
if (destinationPath && subMenu) {
window.location.href = destinationPath;
subMenu.classList.add('fw-bold');
}
})
</script>