Module: Para::TreeHelper

Defined in:
app/helpers/para/tree_helper.rb

Instance Method Summary collapse

Instance Method Details

#actions(resource) ⇒ Object



11
12
13
# File 'app/helpers/para/tree_helper.rb', line 11

def actions(resource)
  edit_button(resource) + delete_button(resource)
end

#delete_button(resource) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/para/tree_helper.rb', line 29

def delete_button(resource)
  link_to(
    component.relation_path(resource),
    data: {
      'turbo-method': :delete,
      'turbo-confirm': ::I18n.t('para.list.delete_confirmation')
    },
    class: 'btn btn-sm btn-icon-danger btn-shadow hint--left',
    aria: {
      label: ::I18n.t('para.shared.destroy')
    }
  ) do
    (:i, '', class: 'fa fa-times')
  end
end

#edit_button(resource) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/para/tree_helper.rb', line 15

def edit_button(resource)
  link_to(
    component.relation_path(
      resource, action: :edit, return_to: view.request.fullpath
    ),
    class: 'btn btn-sm btn-icon-primary btn-shadow hint--left',
    aria: {
      label: ::I18n.t('para.shared.edit')
    }
  ) do
    (:i, '', class: 'fa fa-pencil')
  end
end

#max_depth_for(model) ⇒ Object



7
8
9
# File 'app/helpers/para/tree_helper.rb', line 7

def max_depth_for(model)
  model.max_depth || Para.config.default_tree_max_depth
end

#needs_placeholder?(node) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'app/helpers/para/tree_helper.rb', line 3

def needs_placeholder?(node)
  node.children.empty? && node.depth < max_depth_for(node.class)
end