Module: MenusHelper
- Defined in:
- app/helpers/menus_helper.rb
Instance Method Summary collapse
- #breadcrumbs_component(limit = 20) ⇒ Object
- #construct_all_menu ⇒ Object
- #construct_menu(menus) ⇒ Object
- #construct_menu_group(menu_group_id) ⇒ Object
- #menu_item(menu) ⇒ Object
- #static_menu(options = {}, title_options = {}, icon_options = {}) ⇒ Object
- #static_menu_li(options = {}) ⇒ Object
Instance Method Details
#breadcrumbs_component(limit = 20) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/menus_helper.rb', line 60 def limit=20 results = [] results << (link_to icon('home', t('home')), '/', title: t('home')) @parent_object = nil if @parent_resources.present? @parent_resources.reverse!.each_with_index do |pr, i| begin if i > 0 results << (link_to t("#{pr.singularize}"), {controller: pr, action: 'index', (@parent_resources[i - 1].singularize + '_id') => instance_variable_get("@#{@parent_resources[i - 1].singularize}").id}) else results << (link_to t("#{pr.singularize}"), {controller: pr, action: 'index'}) end rescue results << t("#{pr.singularize}") end pr_id = params[(pr.singularize + '_id').to_sym] parent_object = pr_id.present? ? pr.classify.constantize.find(pr_id) : instance_variable_get("@#{pr.singularize}") results << {parent_object: @parent_object, resource: pr, current: (link_to parent_object.to_s, {controller: pr, action: 'show', id: parent_object}) + (link_to (' <b class="caret"></b>').html_safe, '#', "data-toggle" => 'dropdown', class: 'dropdown-toggle')} @parent_object = parent_object end end if params[:id] if @parent_resources.present? results << (link_to t("#{controller_name.singularize}"), {controller: controller_name, action: 'index', (@parent_resources.last.singularize + '_id') => instance_variable_get("@#{@parent_resources.last.singularize}").id}) else begin results << (link_to t("#{controller_name.singularize}"), {controller: controller_name, action: 'index'}) rescue results << t("#{controller_name.singularize}") end end current_object = controller_name.classify.constantize.find(params[:id]) results << {parent_object: @parent_object, resource: controller_name, current: (link_to current_object.to_s, {controller: controller_name, action: 'show', id: current_object}) + (link_to (' <b class="caret"></b>').html_safe, '#', "data-toggle" => 'dropdown', class: 'dropdown-toggle')} elsif !controller_name.eql?('home') results << t("#{controller_name.singularize}") end result = (render 'rich_table_component/component/breadcrumbs', breadcrumbs: results, limit: limit) @parent_resources = nil result end |
#construct_all_menu ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/menus_helper.rb', line 3 def result = "" Menu.roots.each do || if current_user.present? result << '<div class="component menu menu_component grid_3 alpha omega"><div class="component_content">' result << ( .sorted_tree) result << '</div></div>' end end sanitize result end |
#construct_menu(menus) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/menus_helper.rb', line 30 def () result = "" .keep_if{|| (.roles & current_user.roles).present?} if .length > 0 root_depth = [0].depth curr_depth = root_depth - 1 .each do || if .depth > curr_depth result << '<ul class="parent_' + (.depth - root_depth).to_s + '">' elsif .depth < curr_depth result << '</ul></li>' * (curr_depth - .depth) else # same level result << '</li>' end result << '<li class="child_' + (.depth - root_depth).to_s + '">' result << () curr_depth = .depth end result << '</li></ul>' * (curr_depth - [0].depth + 1) end sanitize result end |
#construct_menu_group(menu_group_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/menus_helper.rb', line 16 def () result = "" if(Menu.exists?()) = Menu.find().sorted_tree .keep_if{|| (.roles & current_user.roles).present?} if current_user.present? && .present? result << '<div class="component menu menu_component grid_3 alpha omega"><div class="component_content">' result << ( ) result << '</div></div>' end end sanitize result end |
#menu_item(menu) ⇒ Object
55 56 57 |
# File 'app/helpers/menus_helper.rb', line 55 def () link_to t(.name), (.url.start_with?("'") ? eval("User.send(:sanitize_sql_array, [#{.url}])") : .url), class: ('menu_item ' + (.url == request.original_fullpath ? 'current_menu_item' : '')) end |
#static_menu(options = {}, title_options = {}, icon_options = {}) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/helpers/menus_helper.rb', line 104 def ( = {}, = {}, = {}) case when Hash = [:menu] _title = [:title] _icon = [:icon] else = _title = _icon = end result = "" sub_result = (menus: , title: _title) unless sub_result.length < 50 # list is not empty #result << '<div class="grid_3 alpha omega">' if _title.present? result << ' <li class="dropdown">' result << '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' + _title + '<b class="caret"></b></a>' end result << sub_result if _title.present? result << ' </li>' end #result << '</div>' end result.html_safe end |
#static_menu_li(options = {}) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/helpers/menus_helper.rb', line 136 def ( = {}) = [:menus] level = [:level].presence || 0 title = [:title] ability = [:ability] result = "" if .present? result << '<ul class="dropdown-menu parent_' + level.to_s + '">' if title.present? .compact.each do || subresult = "" subresult << '<li class="child_' + level.to_s + '">' case when Array subresult << ( menus: , level: (level + 1)).presence || "" when Hash subresult << (link_to [:label], [:url], class: 'menu_item') else subresult << end subresult << '</li>' if .class == Hash && [:ability].present? unless can?([:ability].keys.first, [:ability].values.first) subresult = "" end end if ability.present? unless can?(ability.keys.first, ability.values.first) subresult = "" end end result << subresult end result << '</ul>' if title.present? result end end |