Module: RailsAdmin::Main::HancockHelper
- Defined in:
- app/helpers/rails_admin/main/hancock_helper.rb
Instance Method Summary collapse
- #hancock_main_navigation ⇒ Object
- #hancock_rails_admin_form_for(*args, &block) ⇒ Object
- #ordered_nodes_stack(nodes_stack = nil, node_model_names = nil) ⇒ Object
Instance Method Details
#hancock_main_navigation ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/rails_admin/main/hancock_helper.rb', line 35 def nodes_stack = RailsAdmin::Config.visible_models(controller: controller) node_model_names = nodes_stack.collect { |c| c.abstract_model.model_name } _ordered_nodes_stack = ordered_nodes_stack(nodes_stack, node_model_names) _ordered_nodes_stack.collect do |, nodes| nodes = nodes.select { |n| n.parent.nil? || !n.parent.to_s.in?(node_model_names) } li_stack = nodes_stack, nodes label = || t('admin.misc.navigation') %(<li class='dropdown-header'>#{capitalize_first_letter label}</li>#{li_stack}) if li_stack.present? end.join.html_safe end |
#hancock_rails_admin_form_for(*args, &block) ⇒ Object
5 6 7 8 9 10 |
# File 'app/helpers/rails_admin/main/hancock_helper.rb', line 5 def hancock_rails_admin_form_for(*args, &block) = args..reverse_merge(builder: RailsAdmin::Hancock::FormBuilder) ([:html] ||= {})[:novalidate] ||= !RailsAdmin::Config.browser_validations form_for(*(args << ), &block) << after_nested_form_callbacks end |
#ordered_nodes_stack(nodes_stack = nil, node_model_names = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/rails_admin/main/hancock_helper.rb', line 12 def ordered_nodes_stack(nodes_stack = nil, node_model_names = nil) _controller = (defined?(controller) ? controller : self) nodes_stack ||= RailsAdmin::Config.visible_models(controller: _controller) node_model_names ||= nodes_stack.collect { |c| c.abstract_model.model_name } _order_array = _controller._current_user. if _controller._current_user and _controller._current_user.respond_to?(:navigation_labels) _order_array ||= Hancock.config. _order_array = _order_array.clone.reverse ret = {} grouped_nodes_stack = nodes_stack.group_by(&:navigation_label) = grouped_nodes_stack.keys .sort! do |label_1, label_2| label_1_index = _order_array.index(label_1) || -1 label_2_index = _order_array.index(label_2) || -1 label_2_index <=> label_1_index end .each do |label| ret[label] = grouped_nodes_stack[label] end ret end |