Module: CoreLinkHelper
- Defined in:
- app/helpers/core_link_helper.rb
Overview
common link generation helpers
Instance Method Summary collapse
-
#action_link_tag(condition, path, options = {}) ⇒ Object
Show a list of things if the condition is true.
-
#action_list_tag(condition, path, options = {}) ⇒ Object
Show a list of things in a pull down list if the condition is true.
-
#add_link_button(path, options) ⇒ Object
Add the ‘Add` button.
-
#add_link_tag(klass, path, options = {}) ⇒ Object
Add a thingy.
-
#confirmation_data(options, data, default = nil) ⇒ Object
See if there is any confirmation and add it to the data element.
-
#copy_tag(text_to_copy, title: "Copy to clipboard", classes: [], text: '') ⇒ String
abstract
HTML with the copy button.
-
#copy_text_tag(copy_text, options = {}) ⇒ Object
Create a text element that is easy to copy.
-
#create_link_tag(obj, path, options = {}) ⇒ Object
Create a thingy.
-
#create_list_tag(obj, path, options = {}) ⇒ Object
Create a thingy in a pull-down list.
-
#delete_button_tag(obj, path, options = {}) ⇒ Object
Delete an thingy.
-
#delete_link_tag(obj, path, options = {}) ⇒ Object
Delete an thingy.
-
#delete_list_tag(obj, path, options = {}) ⇒ Object
Delete a thingy in a pull down list.
-
#demote_link_tag(obj, path, options = {}) ⇒ Object
Demote a publishable kb object.
-
#demote_list_tag(obj, path, options = {}) ⇒ Object
Demote a publishable kb object in a pull down list.
-
#download_tag(url, options = {}) ⇒ Object
Generate a download link with the download icon.
-
#edit_class_link_tag(klass, path) ⇒ Object
Edit a page.
-
#edit_link_tag(obj, path, options = {}) ⇒ Object
Edit a thingy.
-
#edit_list_tag(obj, path, options = {}) ⇒ Object
Edit a thingy in a pull down list.
-
#favorite_tag(favorite, options = {}) ⇒ Object
Add a favorite tag.
-
#form_cancel_button_tag(path, name = 'cancel') ⇒ Object
Form cancel button.
-
#form_submit_button_tag(condition = true, options = {}) ⇒ Object
Form submit button.
- #icon_name(options, default = nil) ⇒ Object
-
#info_link_tag(obj, path, options = {}) ⇒ Object
Details of a thingy.
-
#info_list_tag(obj, path, options = {}) ⇒ Object
Details of a thingy in a pull down list.
-
#link_tag(title, path, options = {}) ⇒ Object
Generic link tag.
-
#materialize_icon(name, options = {}) ⇒ Object
Add a material icon by name.
-
#notification_link_tag(obj, path, options = {}) ⇒ Object
Send notification.
-
#notification_list_tag(obj, path, options = {}) ⇒ Object
Send notification in a pull down list.
-
#promote_link_tag(obj, path, options = {}) ⇒ Object
Promote a publishable kb object.
-
#promote_list_tag(obj, path, options = {}) ⇒ Object
Promote a publishable kb object in a pull down list.
-
#replay_button_tag(obj, path, options = {}) ⇒ Object
Restart a thingy.
-
#replay_link_tag(obj, path, options = {}) ⇒ Object
Restart a thingy.
-
#replay_list_tag(obj, path, options = {}) ⇒ Object
Restart a thingy.
-
#table_action_button(action_id, icon_name = 'more_horiz') ⇒ Object
Add the table action button and setup the drop down.
- #tooltip_data(options, data, default = nil) ⇒ Object
Instance Method Details
#action_link_tag(condition, path, options = {}) ⇒ Object
Show a list of things if the condition is true.
209 210 211 212 213 214 215 216 217 218 219 |
# File 'app/helpers/core_link_helper.rb', line 209 def action_link_tag(condition, path, = {}) return unless condition data = {} confirmation_data(, data) link_classes = tooltip_data(, data) content_tag(:a, href: path, class: link_classes.join(' '), data: data) do concat(materialize_icon(icon_name(, 'directions_run'), )) concat([:label]) if [: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
196 197 198 199 200 201 202 203 204 |
# File 'app/helpers/core_link_helper.rb', line 196 def action_list_tag(condition, path, = {}) return unless condition raise('Label Required') if [:label].blank? content_tag(:li) do action_link_tag(condition, path, ) end end |
#add_link_button(path, options) ⇒ Object
Add the ‘Add` button
396 397 398 399 400 401 402 403 404 405 406 |
# File 'app/helpers/core_link_helper.rb', line 396 def (path, ) [:title] ||= t('ui_form.actions.add') [:icon] ||= 'add' content_tag(:a, href: path, class: 'btn-floating btn-large right', style: 'padding: 0;margin: 0px 15px', title: [:title]) do concat(content_tag(:i, class: 'material-icons') { [:icon] }) end end |
#add_link_tag(klass, path, options = {}) ⇒ Object
Add a thingy
385 386 387 388 389 390 391 |
# File 'app/helpers/core_link_helper.rb', line 385 def add_link_tag(klass, path, = {}) return unless can?(:create, klass) content_tag(:div, class: 'fixed-action-btn horizontal') do concat((path, )) end end |
#confirmation_data(options, data, default = nil) ⇒ Object
See if there is any confirmation and add it to the data element
443 444 445 446 447 448 449 450 |
# File 'app/helpers/core_link_helper.rb', line 443 def confirmation_data(, data, default = nil) confirm = [:confirm] || [:confirmation] || default if confirm.present? data[:confirm] = confirm data[:turbo_confirm] = confirm end data end |
#copy_tag(text_to_copy, title: "Copy to clipboard", classes: [], text: '') ⇒ String
Setup a copy text
Returns HTML with the copy button.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/core_link_helper.rb', line 21 def copy_tag(text_to_copy, title: "Copy to clipboard", classes: [], text: '') classes += %w[copy-text ms-1] content_tag(:a, title: title, class: classes.join(' '), data: { copy_text: text_to_copy, bs_toggle: 'tooltip'}) do concat(svg_icon(:copy_icon, classes: %w[copy-icon])) concat(svg_icon(:copy_success, classes: %w[success-icon text-success d-none])) concat(svg_icon(:copy_error, classes: %w[error-icon text-error d-none])) concat(content_tag(:span, text)) end end |
#copy_text_tag(copy_text, options = {}) ⇒ Object
Create a text element that is easy to copy
37 38 39 40 41 42 43 44 |
# File 'app/helpers/core_link_helper.rb', line 37 def copy_text_tag(copy_text, = {}) [:icon_name] ||= 'content_copy' content_tag(:a, class: 'copy', href: '#', data: { 'clipboard-text' => copy_text }, onclick: 'return false;') do concat(content_tag(:i, class: 'material-icons') do [:icon_name] end) end end |
#create_link_tag(obj, path, options = {}) ⇒ Object
Create a thingy
279 280 281 282 283 284 285 286 287 288 289 |
# File 'app/helpers/core_link_helper.rb', line 279 def create_link_tag(obj, path, = {}) return unless can? :create, obj data = {} confirmation_data(, data, t('links.creation_confirmation', name: obj.class.to_s.underscore.humanize)) link_classes = tooltip_data(, data) content_tag(:a, href: path, class: link_classes, data: data) do concat(materialize_icon(icon_name(, 'add'), )) concat([:label]) if [:label].present? end end |
#create_list_tag(obj, path, options = {}) ⇒ Object
Create a thingy in a pull-down list
267 268 269 270 271 272 273 274 |
# File 'app/helpers/core_link_helper.rb', line 267 def create_list_tag(obj, path, = {}) return unless can? :create, obj [:label] ||= I18n.t('ui_form.actions.create') content_tag(:li) do create_link_tag(obj, path, ) end end |
#delete_button_tag(obj, path, options = {}) ⇒ Object
Delete an thingy
251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'app/helpers/core_link_helper.rb', line 251 def (obj, path, = {}) return unless can? :destroy, obj data = { method: :delete, turbo_method: :delete } confirmation_data(, data, t('links.deletion_confirmation', name: obj.class.to_s.underscore.humanize)) link_classes = tooltip_data(, data) %w[btn red].each { |c| link_classes << c unless link_classes.include?(c) } content_tag(:a, class: link_classes, href: path, data: data) do concat(materialize_icon(icon_name(, 'delete'), )) concat([:label]) if [:label].present? end end |
#delete_link_tag(obj, path, options = {}) ⇒ Object
Delete an thingy
236 237 238 239 240 241 242 243 244 245 246 |
# File 'app/helpers/core_link_helper.rb', line 236 def delete_link_tag(obj, path, = {}) return unless can? :destroy, obj data = { method: :delete, turbo_method: :delete } confirmation_data(, data, t('links.deletion_confirmation', name: obj.class.to_s.underscore.humanize)) link_classes = tooltip_data(, data, I18n.t('ui_form.actions.delete')) content_tag(:a, href: path, class: link_classes, data: data) do concat(materialize_icon(icon_name(, 'delete'), )) concat([:label]) if [:label].present? end end |
#delete_list_tag(obj, path, options = {}) ⇒ Object
Delete a thingy in a pull down list
224 225 226 227 228 229 230 231 |
# File 'app/helpers/core_link_helper.rb', line 224 def delete_list_tag(obj, path, = {}) return unless can? :destroy, obj [:label] ||= I18n.t('ui_form.actions.delete') content_tag(:li) do delete_link_tag(obj, path, ) end end |
#demote_link_tag(obj, path, options = {}) ⇒ Object
Demote a publishable kb object
358 359 360 361 362 363 364 365 366 367 |
# File 'app/helpers/core_link_helper.rb', line 358 def demote_link_tag(obj, path, = {}) return unless can? :demote, obj content_tag(:a, href: path) do concat(content_tag(:i, class: 'material-icons') do 'file_download' end) concat([:label]) if [:label].present? end end |
#demote_list_tag(obj, path, options = {}) ⇒ Object
Demote a publishable kb object in a pull down list
346 347 348 349 350 351 352 353 |
# File 'app/helpers/core_link_helper.rb', line 346 def demote_list_tag(obj, path, = {}) return unless can? :demote, obj [:label] ||= I18n.t('links.demote') content_tag(:li) do demote_link_tag(obj, path, ) end end |
#download_tag(url, options = {}) ⇒ Object
Generate a download link with the download icon
10 11 12 13 14 |
# File 'app/helpers/core_link_helper.rb', line 10 def download_tag(url, = {}) content_tag(:a, href: url) do concat(materialize_icon([:download_icon_name] || 'cloud_download')) end end |
#edit_class_link_tag(klass, path) ⇒ Object
Edit a page
372 373 374 375 376 377 378 379 380 |
# File 'app/helpers/core_link_helper.rb', line 372 def edit_class_link_tag(klass, path) return unless can?(:edit, klass) content_tag(:div, class: 'fixed-action-btn horizontal') do concat(content_tag(:a, href: path, class: 'btn-floating btn-large right', style: 'padding: 0;margin: 0px 15px') do concat(content_tag(:i, class: 'material-icons') { 'edit' }) end) end end |
#edit_link_tag(obj, path, options = {}) ⇒ Object
Edit a thingy
112 113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/core_link_helper.rb', line 112 def edit_link_tag(obj, path, = {}) return unless can? :edit, obj data = {} link_classes = tooltip_data(, data, 'Edit') content_tag(:a, href: path, class: link_classes.join(' '), data: data) do concat(materialize_icon(icon_name(, 'edit'), )) concat([:label]) if [:label].present? end end |
#edit_list_tag(obj, path, options = {}) ⇒ Object
Edit a thingy in a pull down list
100 101 102 103 104 105 106 107 |
# File 'app/helpers/core_link_helper.rb', line 100 def edit_list_tag(obj, path, = {}) return unless can? :edit, obj [:label] ||= I18n.t('ui_form.actions.edit') content_tag(:li) do edit_link_tag(obj, path, ) end end |
#favorite_tag(favorite, options = {}) ⇒ Object
Add a favorite tag
62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/core_link_helper.rb', line 62 def favorite_tag(favorite, = {}) data = {} link_classes = tooltip_data(, data, I18n.t('ui_form.actions.favorite')) link_classes += %w[material-icons pointer favorite] content_tag(:i, class: link_classes.join(' '), data: data, id: favorite.id.to_s, type: favorite.favorite_type) { concat(icon_name(, 'favorite_border')) } end |
#form_cancel_button_tag(path, name = 'cancel') ⇒ Object
Form cancel button
411 412 413 414 415 416 |
# File 'app/helpers/core_link_helper.rb', line 411 def (path, name = 'cancel') = { class: 'btn-large waves-effect waves-light secondary', href: path } content_tag(:a, ) do concat(t("ui_form.actions.#{name}")) end end |
#form_submit_button_tag(condition = true, options = {}) ⇒ Object
Form submit button
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'app/helpers/core_link_helper.rb', line 421 def (condition = true, = {}) return unless condition = { class: 'btn-large waves-effect waves-light', type: :submit } if [:action].present? [:name] = [:name] || 'button_action' [:value] = [:action] end [:class] += ' disabled' if [:disabled] [:class] += ' disabled' if [:disabled] = [:text] || t('ui_form.actions.save') = [:icon] || 'save' content_tag(:button, ) do concat() concat(content_tag(:i, class: 'material-icons right') { }) end end |
#icon_name(options, default = nil) ⇒ Object
462 463 464 |
# File 'app/helpers/core_link_helper.rb', line 462 def icon_name(, default = nil) [:icon] || [:icon_name] || default end |
#info_link_tag(obj, path, options = {}) ⇒ Object
Details of a thingy
181 182 183 184 185 186 187 188 189 190 191 |
# File 'app/helpers/core_link_helper.rb', line 181 def info_link_tag(obj, path, = {}) return unless can? :read, obj data = {} confirmation_data(, data) link_classes = tooltip_data(, data) content_tag(:a, href: path, class: link_classes, data: data) do concat(materialize_icon(icon_name(, 'info'), )) concat([:label]) if [:label].present? end end |
#info_list_tag(obj, path, options = {}) ⇒ Object
Details of a thingy in a pull down list
171 172 173 174 175 176 |
# File 'app/helpers/core_link_helper.rb', line 171 def info_list_tag(obj, path, = {}) [:label] ||= I18n.t('ui_form.actions.info') content_tag(:li) do info_link_tag(obj, path, ) end end |
#link_tag(title, path, options = {}) ⇒ Object
Generic link tag
87 88 89 90 91 92 93 94 95 |
# File 'app/helpers/core_link_helper.rb', line 87 def link_tag(title, path, = {}) data = {} link_classes = tooltip_data(, data) confirmation_data(, data) content_tag(:a, href: path, class: link_classes, data: data) do concat(materialize_icon(icon_name(), )) concat(title) end end |
#materialize_icon(name, options = {}) ⇒ Object
Add a material icon by name
76 77 78 79 80 81 82 |
# File 'app/helpers/core_link_helper.rb', line 76 def materialize_icon(name, = {}) return if name.blank? classes = %w[material-icons] classes += [:classes] if [:classes].present? content_tag(:i, class: classes.join(' '), title: [:title]) { name } end |
#notification_link_tag(obj, path, options = {}) ⇒ Object
Send notification
306 307 308 309 310 311 312 313 314 315 |
# File 'app/helpers/core_link_helper.rb', line 306 def notification_link_tag(obj, path, = {}) return unless can? :manage, obj content_tag(:a, href: path) do concat(content_tag(:i, class: 'material-icons') do [:icon_name] || 'email' end) concat([:label]) if [:label].present? end end |
#notification_list_tag(obj, path, options = {}) ⇒ Object
Send notification in a pull down list
294 295 296 297 298 299 300 301 |
# File 'app/helpers/core_link_helper.rb', line 294 def notification_list_tag(obj, path, = {}) return unless can? :manage, obj [:label] ||= I18n.t('customer_account_users.index.reset_password') content_tag(:li) do notification_link_tag(obj, path, ) end end |
#promote_link_tag(obj, path, options = {}) ⇒ Object
Promote a publishable kb object
332 333 334 335 336 337 338 339 340 341 |
# File 'app/helpers/core_link_helper.rb', line 332 def promote_link_tag(obj, path, = {}) return unless can? :promote, obj content_tag(:a, href: path) do concat(content_tag(:i, class: 'material-icons') do 'file_upload' end) concat([:label]) if [:label].present? end end |
#promote_list_tag(obj, path, options = {}) ⇒ Object
Promote a publishable kb object in a pull down list
320 321 322 323 324 325 326 327 |
# File 'app/helpers/core_link_helper.rb', line 320 def promote_list_tag(obj, path, = {}) return unless can? :promote, obj [:label] ||= I18n.t('links.promote') content_tag(:li) do promote_link_tag(obj, path, ) end end |
#replay_button_tag(obj, path, options = {}) ⇒ Object
Restart a thingy
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'app/helpers/core_link_helper.rb', line 154 def (obj, path, = {}) return unless can? :edit, obj data = {} [:icon_name] ||= 'replay' confirmation_data(, data, t('links.replay_confirmation', name: obj.class.to_s.underscore.humanize)) link_classes = tooltip_data(, data) link_classes << 'btn' unless link_classes.include?('btn') content_tag(:a, href: path, data: data, class: link_classes) do concat(materialize_icon(icon_name(), )) concat([:label]) if [:label].present? end end |
#replay_link_tag(obj, path, options = {}) ⇒ Object
Restart a thingy
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/helpers/core_link_helper.rb', line 126 def replay_link_tag(obj, path, = {}) return unless can? :edit, obj data = {} [:icon_name] ||= 'replay' confirmation_data(, data, t('links.replay_confirmation', name: obj.class.to_s.underscore.humanize)) link_classes = tooltip_data(, data) content_tag(:a, href: path, data: data, class: link_classes.join(' ')) do concat(materialize_icon(icon_name(), )) concat([:label]) if [:label].present? end end |
#replay_list_tag(obj, path, options = {}) ⇒ Object
Restart a thingy
142 143 144 145 146 147 148 149 |
# File 'app/helpers/core_link_helper.rb', line 142 def replay_list_tag(obj, path, = {}) return unless can? :edit, obj [:label] ||= I18n.t('ui_form.actions.replay') content_tag(:li) do replay_link_tag(obj, path, ) end end |
#table_action_button(action_id, icon_name = 'more_horiz') ⇒ Object
Add the table action button and setup the drop down
49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/core_link_helper.rb', line 49 def (action_id, icon_name = 'more_horiz') datum = { target: action_id, constrainWidth: false, gutter: 28, alignment: 'right' } content_tag(:a, class: 'dropdown-trigger', data: datum) do concat(materialize_icon(icon_name)) end end |
#tooltip_data(options, data, default = nil) ⇒ Object
452 453 454 455 456 457 458 459 460 |
# File 'app/helpers/core_link_helper.rb', line 452 def tooltip_data(, data, default = nil) link_classes = Array.wrap([:link_classes]) || [] tooltip = [:tooltip] || default if tooltip.present? link_classes << 'tooltipped' data[:tooltip] = tooltip end link_classes end |