forked from fixin.me/fixin.me
Allow specifying navigation tab for controllers
This commit is contained in:
parent
965cb76f1d
commit
aa83f17a4c
@ -7,6 +7,7 @@ class ApplicationController < ActionController::Base
|
||||
# used, or custom layout method needs to be defined.
|
||||
|
||||
helper_method :current_user_disguised?
|
||||
helper_method :current_tab
|
||||
|
||||
before_action :authenticate_user!
|
||||
|
||||
@ -42,6 +43,16 @@ class ApplicationController < ActionController::Base
|
||||
new_user_session_path
|
||||
end
|
||||
|
||||
class << self
|
||||
attr_reader :navigation_menu_tab
|
||||
def navigation_tab(name)
|
||||
@navigation_menu_tab = name.to_s
|
||||
end
|
||||
end
|
||||
def current_tab
|
||||
self.class.navigation_menu_tab || controller_name
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rescue_turbo(exception)
|
||||
|
@ -1,4 +1,6 @@
|
||||
class Units::DefaultsController < ApplicationController
|
||||
navigation_tab :units
|
||||
|
||||
before_action except: :index do
|
||||
raise AccessForbidden unless current_user.at_least(:admin)
|
||||
end
|
||||
|
@ -67,15 +67,16 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
def navigation_menu
|
||||
menu_items = [
|
||||
#[".test", "weight-kilogram", units_path, :restricted],
|
||||
[".units", "weight-kilogram", units_path, :restricted, 'right'],
|
||||
[".users", "account-multiple-outline", users_path, :admin],
|
||||
menu_tabs = [
|
||||
['units', "weight-kilogram", :restricted, 'right'],
|
||||
['users', "account-multiple-outline", :admin],
|
||||
]
|
||||
|
||||
menu_items.map do |label, image, path, status, css_class|
|
||||
menu_tabs.map do |name, image, status, css_class|
|
||||
if current_user.at_least(status)
|
||||
image_tab_to t(label), image, path, class: "tab #{css_class}", current: :active
|
||||
link_to svg_tag("pictograms/#{image}") + t(".#{name}"),
|
||||
{controller: "/#{name}", action: "index"},
|
||||
class: class_names('tab', css_class, active: name == current_tab)
|
||||
end
|
||||
end.join.html_safe
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user