Class: Faalis::Dashboard::Models::Sidebar

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TranslationHelper
Defined in:
lib/faalis/dashboard/models/sidebar.rb

Instance Method Summary (collapse)

Constructor Details

- (Sidebar) initialize(title, **options)

Returns a new instance of Sidebar



58
59
60
61
62
63
# File 'lib/faalis/dashboard/models/sidebar.rb', line 58

def initialize(title, **options)
  @title = title
  extract_options(options)
  @tree = RootMenu.new
  @current_node = @tree
end

Instance Method Details

- (Object) children



65
66
67
# File 'lib/faalis/dashboard/models/sidebar.rb', line 65

def children
  @tree
end

- (Object) extract_options(options) (private)



107
108
109
110
111
# File 'lib/faalis/dashboard/models/sidebar.rb', line 107

def extract_options(options)
  @icon  = options.delete(:icon)
  @id    = options.delete(:id)
  @class = options.delete(:class)
end

- (Object) faalis_entries



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/faalis/dashboard/models/sidebar.rb', line 92

def faalis_entries
  menu(t('faalis.dashboard.user_management'),
       icon: 'fa fa-users',
       model: 'Faalis::User') do
    item(I18n.t('faalis.dashboard.users'),
         model: 'Faalis::User',
         url: Faalis::Engine.routes.url_helpers.dashboard_auth_users_path)

    item(I18n.t('faalis.dashboard.groups'),
         model: 'Faalis::Group',
         url: Faalis::Engine.routes.url_helpers.dashboard_auth_groups_path)
  end
end

- (Object) item(name, **options)



87
88
89
90
# File 'lib/faalis/dashboard/models/sidebar.rb', line 87

def item(name, **options)
  item = Item.new(name, options)
  @current_node.add_child item
end


73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/faalis/dashboard/models/sidebar.rb', line 73

def menu(name, **options, &block)
  item = Menu.new(name, options)


  @current_node.add_child item

  prev_node = @current_node
  @current_node = item

  block.call if block_given?

  @current_node = prev_node
end

- (Object) title



69
70
71
# File 'lib/faalis/dashboard/models/sidebar.rb', line 69

def title
  @title || I18n.t('faalis.dashboard.sidebar.title')
end