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
- #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 || Biovision::Components::BaseComponent[]) 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 |
#back_icon(path, title = t(:back), options = {}) ⇒ Object
80 81 82 |
# File 'app/helpers/biovision_helper.rb', line 80 def back_icon(path, title = t(:back), = {}) icon_with_link('biovision/icons/back.svg', path, title, ) end |
#create_button(path, text = t(:create)) ⇒ Object
121 122 123 |
# File 'app/helpers/biovision_helper.rb', line 121 def (path, text = t(:create)) link_to(text, path, class: 'button button-save') end |
#create_icon(path, title = t(:create), options = {}) ⇒ Object
73 74 75 |
# File 'app/helpers/biovision_helper.rb', line 73 def create_icon(path, title = t(:create), = {}) icon_with_link('biovision/icons/create.svg', path, title, ) end |
#destroy_button(path, text = t(:delete)) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'app/helpers/biovision_helper.rb', line 134 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
102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/biovision_helper.rb', line 102 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
127 128 129 130 |
# File 'app/helpers/biovision_helper.rb', line 127 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
94 95 96 97 |
# File 'app/helpers/biovision_helper.rb', line 94 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
152 153 154 |
# File 'app/helpers/biovision_helper.rb', line 152 def email_link(email, = {}) link_to(email, "mailto:#{email}", ) end |
#entity_link(entity, **options) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/biovision_helper.rb', line 36 def entity_link(entity, **) return '' if entity.nil? 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
65 66 67 68 |
# File 'app/helpers/biovision_helper.rb', line 65 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
115 116 117 |
# File 'app/helpers/biovision_helper.rb', line 115 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
47 48 49 |
# File 'app/helpers/biovision_helper.rb', line 47 def my_home_link( = {}) link_to(t('my.index.index.nav_text'), my_path, ) end |
#phone_link(phone, options = {}) ⇒ Object
146 147 148 |
# File 'app/helpers/biovision_helper.rb', line 146 def phone_link(phone, = {}) link_to(phone, "tel:#{phone.gsub(/[^+0-9]/, '')}", ) end |
#return_icon(path, title = t(:back), options = {}) ⇒ Object
87 88 89 |
# File 'app/helpers/biovision_helper.rb', line 87 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
54 55 56 57 58 59 60 |
# File 'app/helpers/biovision_helper.rb', line 54 def world_icon(path, title = t(:view_as_visitor), = {}) if path.is_a? ApplicationRecord 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 |