1
0
Fork 0

Improve sidebar

This commit is contained in:
Alex Kotov 2019-08-15 12:17:22 +05:00
parent fd3c447dda
commit a66a6baa0b
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 34 additions and 15 deletions

View file

@ -38,6 +38,14 @@ module ApplicationHelper
end end
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) def nav_tabs_list(scope_name, current_tab_name, format, options)
tag.ul class: NAV_TABS_LIST_HTML_CLASS[format] do tag.ul class: NAV_TABS_LIST_HTML_CLASS[format] do
options.each do |(k, v)| options.each do |(k, v)|
@ -61,4 +69,18 @@ module ApplicationHelper
end end
end 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 end

View file

@ -1,15 +1,12 @@
<div class="list-group"> <%= nav_sidebar(
<% if policy(%i[settings profile]).edit? %> :settings,
<%= link_to translate(:profile, scope: %i[nav_tabs settings]), tab,
profile: [
policy(%i[settings profile]).edit?,
edit_settings_profile_path, edit_settings_profile_path,
class: 'list-group-item list-group-item-action ' \ ],
"#{:active if tab == :profile}" %> credentials: [
<% end %> policy(%i[users registration]).edit?,
<% if policy(%i[users registration]).edit? %>
<%= link_to translate(:credentials, scope: %i[nav_tabs settings]),
edit_user_registration_path, edit_user_registration_path,
class: 'list-group-item list-group-item-action ' \ ],
"#{:active if tab == :credentials}" %> ) %>
<% end %>
</div>