* 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>
54 lines
2.5 KiB
Text
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>
|