Module: CoreLinkHelper

Defined in:
app/helpers/core_link_helper.rb

Overview

common link generation helpers

Instance Method Summary collapse

Instance Method Details

Show a list of things if the condition is true.



162
163
164
165
166
167
168
169
170
171
# File 'app/helpers/core_link_helper.rb', line 162

def action_link_tag(condition, path, options = {})
  return unless condition

  (:a, href: path, class: options[:link_classes]) do
    concat((:i, class: 'material-icons') do
      options[:icon_name] || 'info'
    end)
    concat(options[:label]) if options[:label].present?
  end
end

#action_list_tag(condition, path, options = {}) ⇒ Object

Show a list of things in a pull down list if the condition is true



150
151
152
153
154
155
156
157
# File 'app/helpers/core_link_helper.rb', line 150

def action_list_tag(condition, path, options = {})
  return unless condition
  raise('Label Required') if options[:label].blank?

  (:li) do
    action_link_tag(condition, path, options)
  end
end

Add a thingy



217
218
219
220
221
222
223
224
225
# File 'app/helpers/core_link_helper.rb', line 217

def add_link_tag(klass, path)
  return unless can?(:manage, klass)

  (:div, class: 'fixed-action-btn horizontal') do
    concat((:a, href: path, class: 'btn-floating btn-large right', style: 'padding: 0;margin: 0px 15px') do
      concat((:i, class: 'material-icons') { 'add' })
    end)
  end
end

#copy_tag(copy_text, options = {}) ⇒ Object

Create a copy tag for data to be copied to the clipboard



10
11
12
13
14
15
# File 'app/helpers/core_link_helper.rb', line 10

def copy_tag(copy_text, options = {})
  (:p, class: 'stack-tight') do
    concat(copy_text)
    concat(copy_text_tag(copy_text, options))
  end
end

#copy_text_tag(copy_text, options = {}) ⇒ Object

Create a text element that is easy to copy



20
21
22
23
24
25
26
27
# File 'app/helpers/core_link_helper.rb', line 20

def copy_text_tag(copy_text, options = {})
  options[:icon_name] ||= 'content_copy'
  (:a, class: 'copy', href: '#', data: { 'clipboard-text' => copy_text }, onclick: 'return false;') do
    concat((:i, class: 'material-icons') do
      options[:icon_name]
    end)
  end
end

Delete an thingy



188
189
190
191
192
193
194
195
196
197
198
199
# File 'app/helpers/core_link_helper.rb', line 188

def delete_link_tag(obj, path, options = {})
  return unless can? :delete, obj

  data = { method: :delete,
           confirm: options[:confirm] || t('links.deletion_confirmation', name: obj.class.to_s.underscore.humanize) }
  (:a, href: path, data: data) do
    concat((:i, class: 'material-icons') do
      options[:icon_name] || 'delete'
    end)
    concat(options[:label]) if options[:label].present?
  end
end

#delete_list_tag(obj, path, options = {}) ⇒ Object

Delete a thingy in a pull down list



176
177
178
179
180
181
182
183
# File 'app/helpers/core_link_helper.rb', line 176

def delete_list_tag(obj, path, options = {})
  return unless can? :delete, obj

  options[:label] ||= I18n.t('ui_form.actions.delete')
  (:li) do
    delete_link_tag(obj, path, options)
  end
end

Edit a page



204
205
206
207
208
209
210
211
212
# File 'app/helpers/core_link_helper.rb', line 204

def edit_class_link_tag(klass, path)
  return unless can?(:edit, klass)

  (:div, class: 'fixed-action-btn horizontal') do
    concat((:a, href: path, class: 'btn-floating btn-large right', style: 'padding: 0;margin: 0px 15px') do
      concat((:i, class: 'material-icons') { 'edit' })
    end)
  end
end

Edit an thingy



76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/core_link_helper.rb', line 76

def edit_link_tag(obj, path, options = {})
  return unless can? :edit, obj

  (:a, href: path) do
    concat((:i, class: 'material-icons') do
      'edit'
    end)
    concat(options[:label]) if options[:label].present?
  end
end

#edit_list_tag(obj, path, options = {}) ⇒ Object

Edit a thingy in a pull down list



64
65
66
67
68
69
70
71
# File 'app/helpers/core_link_helper.rb', line 64

def edit_list_tag(obj, path, options = {})
  return unless can? :edit, obj

  options[:label] ||= I18n.t('ui_form.actions.edit')
  (:li) do
    edit_link_tag(obj, path, options)
  end
end

#edit_modal_tag(obj, path, _options = {}) ⇒ Object



87
88
89
90
91
92
93
# File 'app/helpers/core_link_helper.rb', line 87

def edit_modal_tag(obj, path, _options = {})
  return unless can? :edit, obj

  (:a, href: path, class: 'modal-action') do
    concat(I18n.t('ui_form.actions.edit'))
  end
end

#form_cancel_button_tag(path) ⇒ Object

Form cancel button



230
231
232
233
234
235
# File 'app/helpers/core_link_helper.rb', line 230

def form_cancel_button_tag(path)
  options = { class: 'btn-large waves-effect waves-light secondary', href: path }
  (:a, options) do
    concat(t('ui_form.actions.cancel'))
  end
end

#form_submit_button_tag(obj) ⇒ Object

Form submit button



240
241
242
243
244
245
246
247
248
# File 'app/helpers/core_link_helper.rb', line 240

def form_submit_button_tag(obj)
  return unless can? :update, obj

  options = { class: 'btn-large waves-effect waves-light', type: :submit }
  (:button, options) do
    concat(t('ui_form.actions.save'))
    concat((:i, class: 'material-icons right') { 'save' })
  end
end

Details of a thingy



136
137
138
139
140
141
142
143
144
145
# File 'app/helpers/core_link_helper.rb', line 136

def info_link_tag(obj, path, options = {})
  return unless can? :read, obj

  (:a, href: path, class: options[:link_classes]) do
    concat((:i, class: 'material-icons') do
      'info'
    end)
    concat(options[:label]) if options[:label].present?
  end
end

#info_list_tag(obj, path, options = {}) ⇒ Object

Details of a thingy in a pull down list



126
127
128
129
130
131
# File 'app/helpers/core_link_helper.rb', line 126

def info_list_tag(obj, path, options = {})
  options[:label] ||= I18n.t('ui_form.actions.info')
  (:li) do
    info_link_tag(obj, path, options)
  end
end

Generic link tag



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

def link_tag(title, path, options = {})
  (:a, href: path) do
    concat((:i, class: 'material-icons left') { options[:icon_name] }) if options[:icon_name].present?
    concat(title)
  end
end

#materialize_icon(name, options = {}) ⇒ Object

Add a material icon by name



45
46
47
48
49
# File 'app/helpers/core_link_helper.rb', line 45

def materialize_icon(name, options = {})
  classes = %w[material-icons]
  classes += options[:classes] if options[:classes].present?
  (:i, class: classes.join(' '), title: options[:title]) { name }
end

Restart a thingy



98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/core_link_helper.rb', line 98

def replay_link_tag(obj, path, options = {})
  return unless can? :edit, obj

  icon_name = options[:icon_name] || 'replay'
  data = { confirm: options[:confirm] || t('links.replay_confirmation', name: obj.class.to_s.underscore.humanize) }
  (:a, href: path, data: data, class: options[:link_classes]) do
    concat((:i, class: 'material-icons') do
      icon_name
    end)
    concat(options[:label]) if options[:label].present?
  end
end

#replay_list_tag(obj, path, options = {}) ⇒ Object

Restart a thingy



114
115
116
117
118
119
120
121
# File 'app/helpers/core_link_helper.rb', line 114

def replay_list_tag(obj, path, options = {})
  return unless can? :edit, obj

  options[:label] ||= I18n.t('ui_form.actions.replay')
  (:li) do
    replay_link_tag(obj, path, options)
  end
end

#table_action_button(action_id, icon_name = 'more_horiz') ⇒ Object

Add the table action button and setup the drop down



32
33
34
35
36
37
38
39
40
# File 'app/helpers/core_link_helper.rb', line 32

def table_action_button(action_id, icon_name = 'more_horiz')
  datum = { activates: action_id,
            constrainWidth: false,
            gutter: 28,
            alignment: 'right' }
  (:a, class: 'dropdown-button', data: datum) do
    concat(materialize_icon(icon_name))
  end
end