Module: BiovisionHelper

Defined in:
app/helpers/biovision_helper.rb

Overview

Helper methods for common cases

Instance Method Summary collapse

Instance Method Details

Parameters:



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, **options)
  return '' if entity.nil?

  component = (handler || Biovision::Components::BaseComponent[])
  text = options.delete(:text) { component.text_for_link(entity) }

  if handler.nil? || handler.permit?('view', entity)
    href = component.entity_link(entity, :admin)
    link_to(text, href, options)
  else
    text
  end
end

#back_icon(path, title = t(:back), options = {}) ⇒ Object

Parameters:

  • path (String)
  • title (String) (defaults to: t(:back))
  • options (Hash) (defaults to: {})


80
81
82
# File 'app/helpers/biovision_helper.rb', line 80

def back_icon(path, title = t(:back), options = {})
  icon_with_link('biovision/icons/back.svg', path, title, options)
end

#create_button(path, text = t(:create)) ⇒ Object

Parameters:

  • path (String)
  • text (String) (defaults to: t(:create))


121
122
123
# File 'app/helpers/biovision_helper.rb', line 121

def create_button(path, text = t(:create))
  link_to(text, path, class: 'button button-save')
end

#create_icon(path, title = t(:create), options = {}) ⇒ Object

Parameters:

  • path (String)
  • title (String) (defaults to: t(:create))
  • options (Hash) (defaults to: {})


73
74
75
# File 'app/helpers/biovision_helper.rb', line 73

def create_icon(path, title = t(:create), options = {})
  icon_with_link('biovision/icons/create.svg', path, title, options)
end

#destroy_button(path, text = t(:delete)) ⇒ Object

Parameters:

  • path (String|ApplicationRecord)
  • text (String) (defaults to: t(:delete))


134
135
136
137
138
139
140
141
142
# File 'app/helpers/biovision_helper.rb', line 134

def destroy_button(path, text = t(:delete))
  path = "/admin/#{path.class.table_name}/#{path.id}" if path.is_a? ApplicationRecord
  options = {
    class: 'button button-danger',
    data: { confirm: t(:are_you_sure) },
    method: :delete
  }
  link_to(text, path, options)
end

#destroy_icon(path, title = t(:delete), options = {}) ⇒ Object

Parameters:

  • path (String|ApplicationRecord)
  • title (String) (defaults to: t(:delete))
  • options (Hash) (defaults to: {})


102
103
104
105
106
107
108
109
110
# File 'app/helpers/biovision_helper.rb', line 102

def destroy_icon(path, title = t(:delete), options = {})
  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(options))
end

#edit_button(path, text = t(:edit)) ⇒ Object

Parameters:

  • path (String|ApplicationRecord)
  • text (String) (defaults to: t(:edit))


127
128
129
130
# File 'app/helpers/biovision_helper.rb', line 127

def edit_button(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

Parameters:

  • path (String|ApplicationRecord)
  • title (String) (defaults to: t(:edit))
  • options (Hash) (defaults to: {})


94
95
96
97
# File 'app/helpers/biovision_helper.rb', line 94

def edit_icon(path, title = t(:edit), options = {})
  path = "/admin/#{path.class.table_name}/#{path.id}/edit" if path.is_a? ApplicationRecord
  icon_with_link('biovision/icons/edit.svg', path, title, options)
end

Parameters:

  • email (String)
  • options (Hash) (defaults to: {})


152
153
154
# File 'app/helpers/biovision_helper.rb', line 152

def email_link(email, options = {})
  link_to(email, "mailto:#{email}", options)
end

Parameters:

  • entity (ApplicationRecord)
  • options (Hash)


36
37
38
39
40
41
42
43
44
# File 'app/helpers/biovision_helper.rb', line 36

def entity_link(entity, **options)
  return '' if entity.nil?

  handler = Biovision::Components::BaseComponent[]
  text = options.delete(:text) { handler.text_for_link(entity) }
  href = handler.entity_link(entity)

  link_to(text, href, options)
end

#gear_icon(path, title = t(:view_settings), options = {}) ⇒ Object

Parameters:

  • path (String|ApplicationRecord)
  • title (String) (defaults to: t(:view_settings))
  • options (Hash) (defaults to: {})


65
66
67
68
# File 'app/helpers/biovision_helper.rb', line 65

def gear_icon(path, title = t(:view_settings), options = {})
  path = "/admin/#{path.class.table_name}/#{path.id}" if path.is_a? ApplicationRecord
  icon_with_link('biovision/icons/gear.svg', path, title, options)
end

Parameters:

  • path (String|ApplicationRecord)
  • title (String)
  • options (Hash) (defaults to: {})


115
116
117
# File 'app/helpers/biovision_helper.rb', line 115

def icon_with_link(source, path, title, options = {})
  link_to(image_tag(source, alt: title), path, options)
end

Parameters:

  • entity (ApplicationRecord)
  • options (Hash)


24
25
26
27
28
29
30
31
32
# File 'app/helpers/biovision_helper.rb', line 24

def my_entity_link(entity, **options)
  return '' if entity.nil?

  handler = Biovision::Components::BaseComponent[]
  text = options.delete(:text) { handler.text_for_link(entity) }
  href = handler.entity_link(entity, :my)

  link_to(text, href, options)
end

Parameters:

  • options (Hash) (defaults to: {})


47
48
49
# File 'app/helpers/biovision_helper.rb', line 47

def my_home_link(options = {})
  link_to(t('my.index.index.nav_text'), my_path, options)
end

Parameters:

  • phone (String)
  • options (Hash) (defaults to: {})


146
147
148
# File 'app/helpers/biovision_helper.rb', line 146

def phone_link(phone, options = {})
  link_to(phone, "tel:#{phone.gsub(/[^+0-9]/, '')}", options)
end

#return_icon(path, title = t(:back), options = {}) ⇒ Object

Parameters:

  • path (String)
  • title (String) (defaults to: t(:back))
  • options (Hash) (defaults to: {})


87
88
89
# File 'app/helpers/biovision_helper.rb', line 87

def return_icon(path, title = t(:back), options = {})
  icon_with_link('biovision/icons/return.svg', path, title, options)
end

#world_icon(path, title = t(:view_as_visitor), options = {}) ⇒ Object

Parameters:

  • path (String|ApplicationRecord)
  • title (String) (defaults to: t(:view_as_visitor))
  • options (Hash) (defaults to: {})


54
55
56
57
58
59
60
# File 'app/helpers/biovision_helper.rb', line 54

def world_icon(path, title = t(:view_as_visitor), options = {})
  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, options)
end