rails_admin_sort_embedded 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,118 @@
1
+ module RailsAdminSortEmbedded
2
+ module Helper
3
+ def rails_admin_sort_embedded(tree, opts= {})
4
+ tree = tree.to_a.sort_by { |m| m.order }
5
+ roots = tree#.select{|elem| elem.parent_id.nil?}
6
+ id = "ns_#{rand(100_000_000..999_999_999)}"
7
+ tree_config = {update_url: sort_embedded_path(model_name: @abstract_model),
8
+ embedded_field: opts[:embedded_field],
9
+ embedded_model: @abstract_model.model.new.send(opts[:embedded_field]).new.class.to_s}.to_json
10
+ content_tag(:ol, rails_admin_sort_embedded_builder(roots, tree), id: id, class: 'dd-list rails_admin_sort_embedded', 'data-config' => tree_config)
11
+ end
12
+
13
+
14
+ private
15
+
16
+ def rails_admin_sort_embedded_builder(nodes, tree)
17
+ nodes.map do |node|
18
+ li_classes = 'dd-item dd3-item'
19
+
20
+ content_tag :li, class: li_classes, :'data-id' => node.id do
21
+ output = content_tag :div, 'drag', class: 'dd-handle dd3-handle'
22
+ output+= content_tag :div, class: 'dd3-content clearfix' do
23
+ content = ''.html_safe
24
+
25
+ # toggle_fields.each do |tf|
26
+ # if node.respond_to?(tf) && respond_to?(:toggle_path)
27
+ # content += case node.enabled
28
+ # when nil
29
+ # g_link(node, '✘', 0, 'label-danger', tf) + g_link(node, '✓', 1, 'label-success', tf)
30
+ # when false
31
+ # g_link(node, '✘', 1, 'label-danger', tf)
32
+ # when true
33
+ # g_link(node, '&#x2713', 0, 'label-success', tf)
34
+ # else
35
+ # %{<span class="label">-</span>}
36
+ # end.html_safe
37
+ # end
38
+ # end
39
+
40
+ content += content_tag :span, @model_config.with(object: node).object_label
41
+
42
+ # content += link_to @model_config.with(object: node).object_label, edit_path(@abstract_model, node.id)
43
+ # content += extra_fields(node)
44
+ #
45
+ # content += content_tag(:div, action_links(node), class: 'pull-right links')
46
+
47
+ sort_embedded_thumbnail_fields.each do |mth|
48
+ if node.respond_to?(mth)
49
+ img = if sort_embedded_paperclip?
50
+ node.send(mth).url(sort_embedded_thumbnail_size)
51
+ elsif sort_embedded_carrierwave?
52
+ node.send(mth, sort_embedded_thumbnail_size)
53
+ else
54
+ nil
55
+ end
56
+ content += image_tag(img, style: "max-height: 40px; max-width: 100px;", class: 'pull-right')
57
+ end
58
+ end
59
+ content
60
+ end
61
+
62
+ # children = tree.select{|elem| elem.parent_id == node.id}
63
+ # output = content_tag(:div, output)
64
+ # if children.any?
65
+ # output += content_tag(:ol, rails_admin_sort_embedded_builder(children, tree), class: 'dd-list')
66
+ # end
67
+
68
+ output
69
+ end
70
+ end.join.html_safe
71
+ end
72
+
73
+
74
+ def sort_embedded_g_link(node, fv, on, badge, meth)
75
+ link_to(
76
+ fv.html_safe,
77
+ toggle_path(model_name: @abstract_model, id: node.id, method: meth, on: on.to_s),
78
+ class: 'js-tree-toggle label ' + badge,
79
+ )
80
+ end
81
+
82
+ def sort_embedded_extra_fields(node)
83
+ "".html_safe
84
+ end
85
+
86
+ def sort_embedded_sort_embedded_fields
87
+ @sort_conf.options[:fields]
88
+ end
89
+ def sort_embedded_fields
90
+ @sort_conf.options[:fields]
91
+ end
92
+
93
+ # def max_depth
94
+ # @sort_conf.options[:max_depth] || '0'
95
+ # end
96
+ # def toggle_fields
97
+ # @sort_conf.options[:toggle_fields]
98
+ # end
99
+ def sort_embedded_thumbnail_fields
100
+ @sort_conf.options[:thumbnail_fields]
101
+ end
102
+ def sort_embedded_paperclip?
103
+ @sort_conf.options[:thumbnail_gem] == :paperclip
104
+ end
105
+ def sort_embedded_carrierwave?
106
+ @sort_conf.options[:thumbnail_gem] == :carrierwave
107
+ end
108
+ def sort_embedded_thumbnail_size
109
+ @sort_conf.options[:thumbnail_size]
110
+ end
111
+
112
+ def sort_embedded_action_links(model)
113
+ content_tag :ul, class: 'inline actions' do
114
+ menu_for :member, @abstract_model, model, true
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,9 @@
1
+ module RailsAdmin
2
+ module Config
3
+ class Model
4
+ register_instance_option :sort_embedded do
5
+ nil
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminSortEmbedded
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_admin_sort_embedded/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rails_admin_sort_embedded"
8
+ gem.version = RailsAdminSortEmbedded::VERSION
9
+ gem.authors = ["Gleb Tv", "Alexander Kiseliev"]
10
+ gem.email = ["glebtv@gmail.com", "i43ack@gmail.com"]
11
+ gem.description = %q{Rails adm/rain sort for embedded collections based on nested set}
12
+ gem.summary = %q{Interface for editing a sorted embedded collections for rails_admin}
13
+ gem.homepage = "https://github.com/ack43/rails_admin_sort_embedded"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "rails_admin", '~> 0.6.6'
21
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_sort_embedded
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Gleb Tv
8
+ - Alexander Kiseliev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails_admin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.6.6
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.6.6
28
+ description: Rails adm/rain sort for embedded collections based on nested set
29
+ email:
30
+ - glebtv@gmail.com
31
+ - i43ack@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - ".ruby-gemset"
38
+ - ".ruby-version"
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - app/assets/javascripts/rails_admin/jquery.mjs.nestedSortable.js
44
+ - app/assets/javascripts/rails_admin/rails_admin_sort_embedded.js.coffee
45
+ - app/assets/stylesheets/rails_admin/rails_admin_sort_embedded.css.scss
46
+ - app/views/rails_admin/main/sort_embedded.html.haml
47
+ - config/locales/en.nested_set.yml
48
+ - config/locales/es.nested_set.yml
49
+ - config/locales/ru.nested_set.yml
50
+ - lib/rails_admin_sort_embedded.rb
51
+ - lib/rails_admin_sort_embedded/action.rb
52
+ - lib/rails_admin_sort_embedded/configuration.rb
53
+ - lib/rails_admin_sort_embedded/engine.rb
54
+ - lib/rails_admin_sort_embedded/helper.rb
55
+ - lib/rails_admin_sort_embedded/model.rb
56
+ - lib/rails_admin_sort_embedded/version.rb
57
+ - rails_admin_sort_embedded.gemspec
58
+ homepage: https://github.com/ack43/rails_admin_sort_embedded
59
+ licenses: []
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Interface for editing a sorted embedded collections for rails_admin
81
+ test_files: []