Module: RailsAdminNestedSet::Helper
- Defined in:
- lib/rails_admin_nested_set/helper.rb
Instance Method Summary collapse
- #action_links(model) ⇒ Object
- #carrierwave? ⇒ Boolean
- #extra_fields(node) ⇒ Object
- #g_link(node, fv, on, badge, meth) ⇒ Object
- #max_depth ⇒ Object
- #paperclip? ⇒ Boolean
- #rails_admin_nested_set(tree, opts = {}) ⇒ Object
- #rails_admin_nested_set_builder(nodes, tree) ⇒ Object
- #thumbnail_fields ⇒ Object
- #thumbnail_size ⇒ Object
- #toggle_fields ⇒ Object
Instance Method Details
#action_links(model) ⇒ Object
105 106 107 108 109 |
# File 'lib/rails_admin_nested_set/helper.rb', line 105 def action_links(model) content_tag :ul, class: 'inline actions' do :member, @abstract_model, model, true end end |
#carrierwave? ⇒ Boolean
98 99 100 |
# File 'lib/rails_admin_nested_set/helper.rb', line 98 def carrierwave? @nested_set_conf.[:thumbnail_gem] == :carrierwave end |
#extra_fields(node) ⇒ Object
26 27 28 |
# File 'lib/rails_admin_nested_set/helper.rb', line 26 def extra_fields(node) "".html_safe end |
#g_link(node, fv, on, badge, meth) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rails_admin_nested_set/helper.rb', line 18 def g_link(node, fv, on, badge, meth) link_to( fv.html_safe, toggle_path(model_name: @abstract_model, id: node.id, method: meth, on: on.to_s), class: 'js-tree-toggle label ' + badge, ) end |
#max_depth ⇒ Object
86 87 88 |
# File 'lib/rails_admin_nested_set/helper.rb', line 86 def max_depth @nested_set_conf.[:max_depth] || '0' end |
#paperclip? ⇒ Boolean
95 96 97 |
# File 'lib/rails_admin_nested_set/helper.rb', line 95 def paperclip? @nested_set_conf.[:thumbnail_gem] == :paperclip end |
#rails_admin_nested_set(tree, opts = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rails_admin_nested_set/helper.rb', line 3 def rails_admin_nested_set(tree, opts= {}) tree = tree.to_a.sort_by { |m| m.lft } roots = tree.select{|elem| elem.parent_id.nil?} id = "ns_#{rand(100_000_000..999_999_999)}" tree_config = { max_depth: max_depth, update_url: nested_set_path(model_name: @abstract_model) }.to_json content_tag(:ol, rails_admin_nested_set_builder(roots, tree), { id: id, class: 'dd-list rails_admin_nested_set', 'data-config' => tree_config }) end |
#rails_admin_nested_set_builder(nodes, tree) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rails_admin_nested_set/helper.rb', line 30 def rails_admin_nested_set_builder(nodes, tree) nodes.map do |node| li_classes = 'dd-item dd3-item' content_tag :li, class: li_classes, :'data-id' => node.id do output = content_tag :div, 'drag', class: 'dd-handle dd3-handle' output+= content_tag :div, class: 'dd3-content clearfix' do content = ''.html_safe toggle_fields.each do |tf| if node.respond_to?(tf) && respond_to?(:toggle_path) content += case node.enabled when nil g_link(node, '✘', 0, 'label-danger', tf) + g_link(node, '✓', 1, 'label-success', tf) when false g_link(node, '✘', 1, 'label-danger', tf) when true g_link(node, '✓', 0, 'label-success', tf) else %{<span class="label">-</span>} end.html_safe end end content += link_to @model_config.with(object: node).object_label, edit_path(@abstract_model, node.id) content += extra_fields(node) content += content_tag(:div, action_links(node), class: 'pull-right links') thumbnail_fields.each do |mth| if node.respond_to?(mth) img = if paperclip? node.send(mth).url(thumbnail_size) elsif carrierwave? node.send(mth, thumbnail_size) else nil end content += image_tag(img, style: "max-height: 40px; max-width: 100px;", class: 'pull-right') end end content end children = tree.select{|elem| elem.parent_id == node.id} output = content_tag(:div, output) if children.any? output += content_tag(:ol, rails_admin_nested_set_builder(children, tree), class: 'dd-list') end output end end.join.html_safe end |
#thumbnail_fields ⇒ Object
92 93 94 |
# File 'lib/rails_admin_nested_set/helper.rb', line 92 def thumbnail_fields @nested_set_conf.[:thumbnail_fields] end |
#thumbnail_size ⇒ Object
101 102 103 |
# File 'lib/rails_admin_nested_set/helper.rb', line 101 def thumbnail_size @nested_set_conf.[:thumbnail_size] end |
#toggle_fields ⇒ Object
89 90 91 |
# File 'lib/rails_admin_nested_set/helper.rb', line 89 def toggle_fields @nested_set_conf.[:toggle_fields] end |