diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0e35405..61cc546 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -38,6 +38,14 @@ module ApplicationHelper end end + def nav_sidebar(scope_name, current_tab_name, options) + tag.div class: 'list-group' do + options.each do |(k, v)| + concat nav_sidebar_item scope_name, current_tab_name, k, *v + end + end + end + def nav_tabs_list(scope_name, current_tab_name, format, options) tag.ul class: NAV_TABS_LIST_HTML_CLASS[format] do options.each do |(k, v)| @@ -61,4 +69,18 @@ module ApplicationHelper end end end + + def nav_sidebar_item(scope_name, current_tab_name, tab_name, policy, url) + if policy + link_to translate(tab_name, scope: [:nav_tabs, scope_name]), + url, + class: 'list-group-item list-group-item-action ' \ + "#{:active if current_tab_name == tab_name}" + else + link_to translate(tab_name, scope: [:nav_tabs, scope_name]), + url, + class: 'list-group-item list-group-item-action disabled', + 'aria-disabled': true + end + end end diff --git a/app/views/settings/_nav_sidebar.html.erb b/app/views/settings/_nav_sidebar.html.erb index 0bca5aa..a9b161a 100644 --- a/app/views/settings/_nav_sidebar.html.erb +++ b/app/views/settings/_nav_sidebar.html.erb @@ -1,15 +1,12 @@ -
- <% if policy(%i[settings profile]).edit? %> - <%= link_to translate(:profile, scope: %i[nav_tabs settings]), - edit_settings_profile_path, - class: 'list-group-item list-group-item-action ' \ - "#{:active if tab == :profile}" %> - <% end %> - - <% if policy(%i[users registration]).edit? %> - <%= link_to translate(:credentials, scope: %i[nav_tabs settings]), - edit_user_registration_path, - class: 'list-group-item list-group-item-action ' \ - "#{:active if tab == :credentials}" %> - <% end %> -
+<%= nav_sidebar( + :settings, + tab, + profile: [ + policy(%i[settings profile]).edit?, + edit_settings_profile_path, + ], + credentials: [ + policy(%i[users registration]).edit?, + edit_user_registration_path, + ], +) %>