Module: BiovisionHelper
- Defined in:
- app/helpers/biovision_helper.rb
Overview
Helper methods for common cases
Instance Method Summary collapse
- #admin_entity_link(entity, handler: nil, **options) ⇒ Object
-
#admin_priority_icons(entity) ⇒ Object
deprecated
Deprecated.
use #entity_priority_icons
-
#admin_toggle_block(entity) ⇒ Object
deprecated
Deprecated.
use #entity_toggle
- #back_icon(path, title = t(:back), options = {}) ⇒ Object
- #create_button(path, text = t(:create)) ⇒ Object
- #create_icon(path, title = t(:create), options = {}) ⇒ Object
- #destroy_button(path, text = t(:delete)) ⇒ Object
- #destroy_icon(path, title = t(:delete), options = {}) ⇒ Object
- #edit_button(path, text = t(:edit)) ⇒ Object
- #edit_icon(path, title = t(:edit), options = {}) ⇒ Object
- #email_link(email, options = {}) ⇒ Object
- #entity_link(entity, **options) ⇒ Object
- #gear_icon(path, title = t(:view_settings), options = {}) ⇒ Object
- #icon_with_link(source, path, title, options = {}) ⇒ Object
- #my_entity_link(entity, **options) ⇒ Object
- #my_home_link(options = {}) ⇒ Object
- #phone_link(phone, options = {}) ⇒ Object
- #return_icon(path, title = t(:back), options = {}) ⇒ Object
- #world_icon(path, title = t(:view_as_visitor), options = {}) ⇒ Object
Instance Method Details
#admin_entity_link(entity, handler: nil, **options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/biovision_helper.rb', line 8 def admin_entity_link(entity, handler: nil, **) return '∅' if entity.nil? component = (handler || component_handler) text = .delete(:text) { component.text_for_link(entity) } if handler.nil? || handler.permit?('view', entity) href = component.entity_link(entity, :admin) link_to(text, href, ) else text end end |
#admin_priority_icons(entity) ⇒ Object
Deprecated.
use #entity_priority_icons
161 162 163 |
# File 'app/helpers/biovision_helper.rb', line 161 def admin_priority_icons(entity) render(partial: 'shared/admin/priority', locals: { entity: entity }) end |
#admin_toggle_block(entity) ⇒ Object
Deprecated.
use #entity_toggle
167 168 169 |
# File 'app/helpers/biovision_helper.rb', line 167 def admin_toggle_block(entity) render(partial: 'shared/admin/toggle', locals: { entity: entity }) end |
#back_icon(path, title = t(:back), options = {}) ⇒ Object
83 84 85 |
# File 'app/helpers/biovision_helper.rb', line 83 def back_icon(path, title = t(:back), = {}) icon_with_link('biovision/icons/back.svg', path, title, ) end |
#create_button(path, text = t(:create)) ⇒ Object
124 125 126 |
# File 'app/helpers/biovision_helper.rb', line 124 def (path, text = t(:create)) link_to(text, path, class: 'button button-save') end |
#create_icon(path, title = t(:create), options = {}) ⇒ Object
76 77 78 |
# File 'app/helpers/biovision_helper.rb', line 76 def create_icon(path, title = t(:create), = {}) icon_with_link('biovision/icons/create.svg', path, title, ) end |
#destroy_button(path, text = t(:delete)) ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'app/helpers/biovision_helper.rb', line 137 def (path, text = t(:delete)) path = "/admin/#{path.class.table_name}/#{path.id}" if path.is_a? ApplicationRecord = { class: 'button button-danger', data: { confirm: t(:are_you_sure) }, method: :delete } link_to(text, path, ) end |
#destroy_icon(path, title = t(:delete), options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/biovision_helper.rb', line 105 def destroy_icon(path, title = t(:delete), = {}) path = "/admin/#{path.class.table_name}/#{path.id}" if path.is_a? ApplicationRecord default = { class: 'danger', data: { confirm: t(:are_you_sure) }, method: :delete, } icon_with_link('biovision/icons/destroy.svg', path, title, default.merge()) end |
#edit_button(path, text = t(:edit)) ⇒ Object
130 131 132 133 |
# File 'app/helpers/biovision_helper.rb', line 130 def (path, text = t(:edit)) path = "/admin/#{path.class.table_name}/#{path.id}/edit" if path.is_a? ApplicationRecord link_to(text, path, class: 'button button-secondary') end |
#edit_icon(path, title = t(:edit), options = {}) ⇒ Object
97 98 99 100 |
# File 'app/helpers/biovision_helper.rb', line 97 def edit_icon(path, title = t(:edit), = {}) path = "/admin/#{path.class.table_name}/#{path.id}/edit" if path.is_a? ApplicationRecord icon_with_link('biovision/icons/edit.svg', path, title, ) end |
#email_link(email, options = {}) ⇒ Object
155 156 157 |
# File 'app/helpers/biovision_helper.rb', line 155 def email_link(email, = {}) link_to(email, "mailto:#{email}", ) end |
#entity_link(entity, **options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'app/helpers/biovision_helper.rb', line 36 def entity_link(entity, **) return '' if entity.nil? return '' if entity.respond_to?(:visible?) && !entity.visible? handler = Biovision::Components::BaseComponent[] text = .delete(:text) { handler.text_for_link(entity) } href = handler.entity_link(entity) link_to(text, href, ) end |
#gear_icon(path, title = t(:view_settings), options = {}) ⇒ Object
68 69 70 71 |
# File 'app/helpers/biovision_helper.rb', line 68 def gear_icon(path, title = t(:view_settings), = {}) path = "/admin/#{path.class.table_name}/#{path.id}" if path.is_a? ApplicationRecord icon_with_link('biovision/icons/gear.svg', path, title, ) end |
#icon_with_link(source, path, title, options = {}) ⇒ Object
118 119 120 |
# File 'app/helpers/biovision_helper.rb', line 118 def icon_with_link(source, path, title, = {}) link_to(image_tag(source, alt: title), path, ) end |
#my_entity_link(entity, **options) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/biovision_helper.rb', line 24 def my_entity_link(entity, **) return '∅' if entity.nil? handler = Biovision::Components::BaseComponent[] text = .delete(:text) { handler.text_for_link(entity) } href = handler.entity_link(entity, :my) link_to(text, href, ) end |
#my_home_link(options = {}) ⇒ Object
48 49 50 |
# File 'app/helpers/biovision_helper.rb', line 48 def my_home_link( = {}) link_to(t('my.index.index.nav_text'), my_path, ) end |
#phone_link(phone, options = {}) ⇒ Object
149 150 151 |
# File 'app/helpers/biovision_helper.rb', line 149 def phone_link(phone, = {}) link_to(phone, "tel:#{phone.gsub(/[^+0-9]/, '')}", ) end |
#return_icon(path, title = t(:back), options = {}) ⇒ Object
90 91 92 |
# File 'app/helpers/biovision_helper.rb', line 90 def return_icon(path, title = t(:back), = {}) icon_with_link('biovision/icons/return.svg', path, title, ) end |
#world_icon(path, title = t(:view_as_visitor), options = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/biovision_helper.rb', line 55 def world_icon(path, title = t(:view_as_visitor), = {}) if path.is_a? ApplicationRecord return '' if path.respond_to?(:visible?) && !path.visible? table_name = path.class.table_name path = path.respond_to?(:world_url) ? path.world_url : "/#{table_name}/#{path.id}" end icon_with_link('biovision/icons/world.svg', path, title, ) end |