Module: Spree::Admin::NavigationHelper
- Defined in:
- app/helpers/spree/admin/navigation_helper.rb
Instance Method Summary collapse
- #button(text, icon_name = nil, button_type = 'submit', options = {}) ⇒ Object
- #button_link_to(text, url, html_options = {}) ⇒ Object
-
#collapse_sidebar_link ⇒ Object
sidebar are used on order edit, product edit, user overview etc.
- #configurations_menu_item(link_text, url, description = '') ⇒ Object
- #configurations_sidebar_menu_item(link_text, url, options = {}) ⇒ Object
- #icon(icon_name) ⇒ Object
-
#klass_for(name) ⇒ Object
finds class for a given symbol / string.
- #link_to_clone(resource, options = {}) ⇒ Object
- #link_to_delete(resource, options = {}) ⇒ Object
- #link_to_edit(resource, options = {}) ⇒ Object
- #link_to_edit_url(url, options = {}) ⇒ Object
- #link_to_new(resource) ⇒ Object
- #link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
-
#main_menu_item(text, url: nil, icon: nil) ⇒ Object
Single main menu item.
-
#main_menu_tree(text, icon: nil, sub_menu: nil, url: '#') ⇒ Object
Main menu tree menu.
- #main_part_classes ⇒ Object
-
#per_page_dropdown ⇒ Object
the per_page_dropdown is used on index pages like orders, products, promotions etc.
-
#per_page_dropdown_params ⇒ Object
helper method to create proper url to apply per page filtering fixes github.com/spree/spree/issues/6888.
-
#tab(*args) ⇒ Object
Make an admin tab that coveres one or more resources supplied by symbols Option hash may follow.
- #wrapper_classes ⇒ Object
Instance Method Details
#button(text, icon_name = nil, button_type = 'submit', options = {}) ⇒ Object
168 169 170 171 172 173 174 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 168 def (text, icon_name = nil, = 'submit', ={}) if icon_name icon = content_tag(:span, '', class: "icon icon-#{icon_name}") text.insert(0, icon + ' ') end (text.html_safe, .merge(type: , class: "btn btn-primary #{[:class]}")) end |
#button_link_to(text, url, html_options = {}) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 176 def (text, url, = {}) if ([:method] && [:method].to_s.downcase != 'get' && ![:remote]) form_tag(url, method: .delete(:method)) do (text, .delete(:icon), nil, ) end else if ['data-update'].nil? && [:remote] object_name, action = url.split('/')[-2..-1] ['data-update'] = [action, object_name.singularize].join('_') end .delete('data-update') unless ['data-update'] [:class] = [:class] ? "btn #{[:class]}" : "btn btn-default" if [:icon] icon = content_tag(:span, '', class: "icon icon-#{[:icon]}") text.insert(0, icon + ' ') end link_to(text.html_safe, url, ) end end |
#collapse_sidebar_link ⇒ Object
sidebar are used on order edit, product edit, user overview etc. this link is shown so a user can collapse the sidebar
65 66 67 68 69 70 71 72 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 65 def content_tag :div, class: "collapse-sidebar" do link_to "javascript:;", class: "js-collapse-sidebar" do content_tag(:span, nil, class: "icon icon-chevron-right") + content_tag(:span, "Collapse sidebar", class: "text") end end end |
#configurations_menu_item(link_text, url, description = '') ⇒ Object
202 203 204 205 206 207 208 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 202 def (link_text, url, description = '') %(<tr> <td>#{link_to(link_text, url)}</td> <td>#{description}</td> </tr> ).html_safe end |
#configurations_sidebar_menu_item(link_text, url, options = {}) ⇒ Object
210 211 212 213 214 215 216 217 218 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 210 def (link_text, url, = {}) is_active = url.ends_with?(controller.controller_name) || url.ends_with?("#{controller.controller_name}/edit") || url.ends_with?("#{controller.controller_name.singularize}/edit") .merge!(class: is_active ? 'active' : nil) content_tag(:li, ) do link_to(link_text, url) end end |
#icon(icon_name) ⇒ Object
164 165 166 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 164 def icon(icon_name) icon_name ? content_tag(:i, '', class: icon_name) : '' end |
#klass_for(name) ⇒ Object
finds class for a given symbol / string
Example : :products returns Spree::Product :my_products returns MyProduct if MyProduct is defined :my_products returns My::Product if My::Product is defined if cannot constantize it returns nil This will allow us to use cancan abilities on tab
110 111 112 113 114 115 116 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 110 def klass_for(name) model_name = name.to_s ["Spree::#{model_name.classify}", model_name.classify, model_name.gsub('_', '/').classify].find do |t| t.safe_constantize end.try(:safe_constantize) end |
#link_to_clone(resource, options = {}) ⇒ Object
118 119 120 121 122 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 118 def link_to_clone(resource, ={}) [:data] = { action: 'clone' } [:class] = "btn btn-primary btn-sm" link_to_with_icon('clone', Spree.t(:clone), clone_object_url(resource), ) end |
#link_to_delete(resource, options = {}) ⇒ Object
143 144 145 146 147 148 149 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 143 def link_to_delete(resource, ={}) url = [:url] || object_url(resource) name = [:name] || Spree.t(:delete) [:class] = "btn btn-danger btn-sm delete-resource" [:data] = { confirm: Spree.t(:are_you_sure), action: 'remove' } link_to_with_icon 'delete', name, url, end |
#link_to_edit(resource, options = {}) ⇒ Object
130 131 132 133 134 135 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 130 def link_to_edit(resource, ={}) url = [:url] || edit_object_url(resource) [:data] = { action: 'edit' } [:class] = "btn btn-primary btn-sm" link_to_with_icon('edit', Spree.t(:edit), url, ) end |
#link_to_edit_url(url, options = {}) ⇒ Object
137 138 139 140 141 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 137 def link_to_edit_url(url, ={}) [:data] = { action: 'edit' } [:class] = "btn btn-primary btn-sm" link_to_with_icon('edit', Spree.t(:edit), url, ) end |
#link_to_new(resource) ⇒ Object
124 125 126 127 128 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 124 def link_to_new(resource) [:data] = { action: 'new' } [:class] = "btn btn-success btn-sm" link_to_with_icon('plus', Spree.t(:new), edit_object_url(resource)) end |
#link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 151 def link_to_with_icon(icon_name, text, url, = {}) [:class] = ([:class].to_s + " icon-link with-tip action-#{icon_name}").strip [:class] += ' no-text' if [:no_text] [:title] = text if [:no_text] text = [:no_text] ? '' : raw("<span class='text'>#{text}</span>") .delete(:no_text) if icon_name icon = content_tag(:span, '', class: "icon icon-#{icon_name}") text.insert(0, icon + ' ') end link_to(text.html_safe, url, ) end |
#main_menu_item(text, url: nil, icon: nil) ⇒ Object
Single main menu item
47 48 49 50 51 52 53 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 47 def text, url: nil, icon: nil link_to url, :'data-toggle' => "collapse", :'data-parent' => '#sidebar' do content_tag(:span, nil, class: "icon icon-#{icon}") + content_tag(:span, " #{text}", class: 'text') + content_tag(:span, nil, class: "icon icon-chevron-left pull-right") end end |
#main_menu_tree(text, icon: nil, sub_menu: nil, url: '#') ⇒ Object
Main menu tree menu
56 57 58 59 60 61 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 56 def text, icon: nil, sub_menu: nil, url: '#' content_tag :li, class: 'sidebar-menu-item' do (text, url: url, icon: icon) + render(partial: "spree/admin/shared/sub_menu/#{}") end end |
#main_part_classes ⇒ Object
220 221 222 223 224 225 226 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 220 def main_part_classes if ['sidebar-minimized'] == 'true' return 'col-sm-12 col-md-12 sidebar-collapsed' else return 'col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2' end end |
#per_page_dropdown ⇒ Object
the per_page_dropdown is used on index pages like orders, products, promotions etc. this method generates the select_tag
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 76 def per_page_dropdown # there is a config setting for admin_products_per_page, only for the orders page if @products && per_page_default = Spree::Config.admin_products_per_page = [] 5.times do |amount| << (amount + 1) * Spree::Config.admin_products_per_page end else per_page_default = 15 = %w{5 15 30 45 60} end select_tag(:per_page, (, params['per_page'] || per_page_default), { class: "form-control pull-right js-per-page-select" }) end |
#per_page_dropdown_params ⇒ Object
helper method to create proper url to apply per page filtering fixes github.com/spree/spree/issues/6888
95 96 97 98 99 100 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 95 def per_page_dropdown_params args = params.clone args.delete(:page) args.delete(:per_page) args end |
#tab(*args) ⇒ Object
Make an admin tab that coveres one or more resources supplied by symbols Option hash may follow. Valid options are
* :label to override link text, otherwise based on the first resource name (translated)
* :route to override automatically determining the default route
* :match_path as an alternative way to control when the tab is active, /products would match /admin/products, /admin/products/5/variants etc.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 9 def tab(*args) = { label: args.first.to_s } # Return if resource is found and user is not allowed to :admin return '' if klass = klass_for([:label]) and cannot?(:admin, klass) if args.last.is_a?(Hash) = .merge(args.pop) end [:route] ||= "admin_#{args.first}" destination_url = [:url] || spree.send("#{[:route]}_path") titleized_label = Spree.t([:label], default: [:label], scope: [:admin, :tab]).titleize css_classes = ['sidebar-menu-item'] if [:icon] link = link_to_with_icon([:icon], titleized_label, destination_url) else link = link_to(titleized_label, destination_url) end selected = if [:match_path].is_a? Regexp request.fullpath =~ [:match_path] elsif [:match_path] request.fullpath.starts_with?("#{spree.admin_path}#{[:match_path]}") else args.include?(controller.controller_name.to_sym) end css_classes << 'selected' if selected if [:css_class] css_classes << [:css_class] end content_tag('li', link, class: css_classes.join(' ')) end |
#wrapper_classes ⇒ Object
228 229 230 231 232 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 228 def wrapper_classes if ['sidebar-minimized'] == 'true' return 'sidebar-minimized' end end |