Module: ZenAdmin::ApplicationHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/zen_admin/application_helper.rb
Instance Method Summary collapse
- #current_sort_direction(field_name) ⇒ Object
- #menu_item_visible?(item, user) ⇒ Boolean
-
#rails_blob_path(*args, **options) ⇒ Object
Delegate Active Storage helpers to main_app to fix Action Text rendering in engine.
- #rails_blob_url(*args, **options) ⇒ Object
- #rails_representation_path(*args, **options) ⇒ Object
- #rails_representation_url(*args, **options) ⇒ Object
- #rails_storage_proxy_path(*args, **options) ⇒ Object
- #rails_storage_proxy_url(*args, **options) ⇒ Object
- #sort_url(field_name) ⇒ Object
- #zen_highlight(text, phrases) ⇒ Object
Instance Method Details
#current_sort_direction(field_name) ⇒ Object
30 31 32 33 34 |
# File 'app/helpers/zen_admin/application_helper.rb', line 30 def current_sort_direction(field_name) current_sorts = params[:sort].to_s.split(',').map { |s| s.split(':') } pair = current_sorts.find { |col, dir| col == field_name.to_s } pair ? pair[1] : nil end |
#menu_item_visible?(item, user) ⇒ Boolean
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/zen_admin/application_helper.rb', line 66 def (item, user) case item[:type] when :resource user.can?("#{item[:object].name}:index") when :link item[:object][:permission].blank? || user.can?(item[:object][:permission]) when :group # A group is visible if ANY of its children are visible item[:items].any? { |sub_item| (sub_item, user) } else false end end |
#rails_blob_path(*args, **options) ⇒ Object
Delegate Active Storage helpers to main_app to fix Action Text rendering in engine
37 38 39 |
# File 'app/helpers/zen_admin/application_helper.rb', line 37 def rails_blob_path(*args, **) main_app.rails_blob_path(*args, **) end |
#rails_blob_url(*args, **options) ⇒ Object
41 42 43 |
# File 'app/helpers/zen_admin/application_helper.rb', line 41 def rails_blob_url(*args, **) main_app.rails_blob_url(*args, **) end |
#rails_representation_path(*args, **options) ⇒ Object
45 46 47 |
# File 'app/helpers/zen_admin/application_helper.rb', line 45 def rails_representation_path(*args, **) main_app.rails_representation_path(*args, **) end |
#rails_representation_url(*args, **options) ⇒ Object
49 50 51 |
# File 'app/helpers/zen_admin/application_helper.rb', line 49 def rails_representation_url(*args, **) main_app.rails_representation_url(*args, **) end |
#rails_storage_proxy_path(*args, **options) ⇒ Object
53 54 55 |
# File 'app/helpers/zen_admin/application_helper.rb', line 53 def rails_storage_proxy_path(*args, **) main_app.rails_storage_proxy_path(*args, **) end |
#rails_storage_proxy_url(*args, **options) ⇒ Object
57 58 59 |
# File 'app/helpers/zen_admin/application_helper.rb', line 57 def rails_storage_proxy_url(*args, **) main_app.rails_storage_proxy_url(*args, **) end |
#sort_url(field_name) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/zen_admin/application_helper.rb', line 3 def sort_url(field_name) current_sorts = params[:sort].to_s.split(',').map { |s| s.split(':') } found = false new_sorts = [] current_sorts.each do |col, dir| if col == field_name.to_s found = true if dir == 'asc' new_sorts << [col, 'desc'] end else new_sorts << [col, dir] end end unless found new_sorts.unshift([field_name.to_s, 'asc']) end sort_param = new_sorts.map { |cd| cd.join(':') }.join(',') query_params = request.query_parameters.merge(sort: sort_param) query_params.delete(:sort) if sort_param.blank? "#{request.path}?#{query_params.to_query}" end |
#zen_highlight(text, phrases) ⇒ Object
61 62 63 64 |
# File 'app/helpers/zen_admin/application_helper.rb', line 61 def zen_highlight(text, phrases) return text if phrases.blank? || text.blank? || !text.is_a?(String) highlight(text, phrases, highlighter: '<mark class="p-0 bg-warning">\\1</mark>') end |