solidus_categories 1.2 → 2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.bundle/config +1 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +20 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +45 -0
  7. data/Rakefile +2 -0
  8. data/app/decorators/spree/admin/properties_controller_decorator.rb +61 -0
  9. data/app/helpers/render_nested_options_helper.rb +23 -0
  10. data/app/helpers/render_sortable_tree_helper.rb +62 -0
  11. data/app/helpers/render_tree_helper.rb +45 -0
  12. data/app/helpers/the_sortable_tree_helper.rb +146 -0
  13. data/app/models/spree/property_decorator.rb +7 -0
  14. data/app/overrides/listing_properties.rb +5 -0
  15. data/app/views/spree/admin/_listing_properties.html.erb +10 -0
  16. data/app/views/spree/admin/properties/_editform.html.erb +21 -0
  17. data/app/views/spree/admin/properties/_form.html.erb +24 -0
  18. data/app/views/spree/admin/properties/edit.html.erb +28 -0
  19. data/app/views/spree/admin/properties/manage.html.erb +3 -0
  20. data/app/views/spree/admin/properties/show.html.erb +15 -0
  21. data/bin/console +14 -0
  22. data/bin/setup +8 -0
  23. data/config/locales/en.yml +1918 -0
  24. data/config/routes.rb +15 -0
  25. data/db/20160701150045_add_position_to_spree_properties.rb +5 -0
  26. data/db/20160705145644_add_fields_to_properties.rb +10 -0
  27. data/lib/solidus_categories.rb +5 -0
  28. data/lib/solidus_categories/engine.rb +24 -0
  29. data/lib/solidus_categories/version.rb +3 -0
  30. data/lib/tasks/install.rake +57 -0
  31. data/solidus_categories.gemspec +25 -0
  32. data/vendor/assets/javascripts/spree/backend/all.js +16 -0
  33. data/vendor/assets/javascripts/spree/frontend/all.js +11 -0
  34. data/vendor/assets/stylesheets/.keep +0 -0
  35. data/vendor/assets/stylesheets/spree/backend/all.css +12 -0
  36. data/vendor/assets/stylesheets/spree/frontend/all.css +10 -0
  37. metadata +53 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5abc71aa2fa7491ab6e29530c071c24ba481b26
4
- data.tar.gz: 0c61ddfc642b77c14abdef7b3b85b5f852ce4452
3
+ metadata.gz: 51313054558eb1051cc1be7536e7fe0954fc21fc
4
+ data.tar.gz: 33d3ac6570eb4f8b9bc74a79b42860d2529e8df0
5
5
  SHA512:
6
- metadata.gz: fe56859ade9f6035cba97542336dcc4d53e3edc9435ebd2bb5c5646ce64902e6d2270ad1c3b1cd6a65e05279dd2cff6d39d30072416633bfba317b12462078c1
7
- data.tar.gz: 60de63906e1ecb4f9d6c39784422c408ba46ca0bba06edcf8f03f601fb9017ffc04ca6a860cbfe5cdac28a6cfbf71c8ac63d2c0c15fc0d6a60ed19d6636b3d8e
6
+ metadata.gz: 11347b2d0a2f50949adeb03ee00d01f2fe4b608d7455982ec6ef4884a0baa3e47df22197de4b548bbd5330f586efa24226d42d69bfd7873e6f8c902cf0f84023
7
+ data.tar.gz: 7806e645e7f63e41918571787a4d01cd0777adb6f72af7ca0a39d6328a5d7bbdecd62736315c4ff8ae1ebb13b4ea387a2d89ce0b3d6062214971d724d98ccde8
@@ -0,0 +1 @@
1
+ --- {}
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in catalogs.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ solidus_categories (0.1.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.4.2)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.12)
16
+ rake (~> 10.0)
17
+ solidus_categories!
18
+
19
+ BUNDLED WITH
20
+ 1.12.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 kchiru
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # Solidus Categories
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/Solidus Categories`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'solidus_categories' , :github => 'prasanthiym/solidus_categories'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install solidus_categories
22
+
23
+
24
+ ## Usage
25
+
26
+ Install gem intializers
27
+
28
+ bundle exec rails g solidus_categories:install
29
+
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/solidus_categories. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,61 @@
1
+ Spree::Admin::PropertiesController.class_eval do
2
+ include TheSortableTreeController::Rebuild
3
+
4
+ def index
5
+ if params[:q].present?
6
+ @properties = Spree::Property.where("name LIKE ?","%#{params[:q][:name_cont]}%").nested_set.select('id, name, parent_id').limit(15)
7
+ else
8
+ @properties = Spree::Property.nested_set.select('id, name, parent_id').limit(15)
9
+ end
10
+ end
11
+
12
+ def new
13
+
14
+ end
15
+
16
+ def create
17
+
18
+ @property = Spree::Property.new(property_params)
19
+ if @property.save
20
+ flash[:message] = "Property Successfully Saved"
21
+ redirect_to admin_properties_url
22
+ else
23
+ render :action => "new"
24
+ end
25
+ end
26
+
27
+ def show
28
+
29
+ end
30
+ def manage
31
+ @properties = Spree::Property.nested_set.select('id, name, parent_id').limit(15)
32
+ end
33
+
34
+ def nested_options
35
+ @properties = Spree::Property.nested_set.select('id, name, parent_id').limit(15)
36
+ end
37
+
38
+ def node_manage
39
+ @root = Spree::Property.root
40
+ @properties = @root.self_and_descendants.nested_set.select('id, name, parent_id').limit(15)
41
+ render template: 'spree/properties/manage'
42
+ end
43
+
44
+ protected
45
+
46
+ def sortable_model
47
+ Spree::Property
48
+ end
49
+
50
+ def sortable_collection
51
+ 'properties'
52
+ end
53
+
54
+ private
55
+
56
+ def property_params
57
+ params.require(:property).permit(:name,:presentation,:positition,:lft,:depth,:rgt,:parent_id)
58
+ end
59
+
60
+
61
+ end
@@ -0,0 +1,23 @@
1
+ module RenderNestedOptionsHelper
2
+ class Render
3
+ class << self
4
+ attr_accessor :h, :options
5
+
6
+ def render_node(h, options)
7
+ @h, @options = h, options
8
+
9
+ node = options[:node]
10
+
11
+ this_node = options[:selected] == node
12
+ selected_class = this_node ? ' selected' : nil
13
+ selected = this_node ? " selected='selected'" : nil
14
+
15
+ "
16
+ <option value='#{node[:id]}' class='l_#{ options[:level] }#{selected_class}' #{selected}>#{ node[:name] }</option>
17
+ #{ options[:children] }
18
+ "
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,62 @@
1
+ # DOC:
2
+ # We use Helper Methods for tree building,
3
+ # because it's faster than View Templates and Partials
4
+
5
+ # SECURITY note
6
+ # Prepare your data on server side for rendering
7
+ # or use h.html_escape(node.content)
8
+ # for escape potentially dangerous content
9
+ module RenderSortableTreeHelper
10
+ module Render
11
+ class << self
12
+ attr_accessor :h, :options
13
+
14
+ def render_node(h, options)
15
+ @h, @options = h, options
16
+ node = options[:node]
17
+
18
+ "
19
+ <li data-node-id='#{ node.id }'>
20
+ <div class='item'>
21
+ <i class='handle'></i>
22
+ #{ show_link }
23
+ #{ controls }
24
+ </div>
25
+ #{ children }
26
+ </li>
27
+ "
28
+ end
29
+
30
+ def show_link
31
+ node = options[:node]
32
+ ns = options[:namespace]
33
+ url = h.url_for(:controller => 'admin/properties', :action => :show, :id => node)
34
+ # url = h.url_for(ns + [node])
35
+ title_field = node[:name]
36
+ #p options
37
+ "<h4>#{ h.link_to(title_field, url) }</h4>"
38
+ end
39
+
40
+ def controls
41
+ node = options[:node]
42
+
43
+ edit_path = h.url_for(:controller => 'admin/properties', :action => :edit, :id => node)
44
+ destroy_path = h.url_for(:controller => 'admin/properties', :action => :destroy, :id => node)
45
+
46
+ "
47
+ <div class='controls'>
48
+ #{ h.link_to '', edit_path, :class => :edit }
49
+ #{ h.link_to '', destroy_path, :class => :delete, :method => :delete, :data => { :confirm => 'Are you sure?' } }
50
+ </div>
51
+ "
52
+ end
53
+
54
+ def children
55
+ unless options[:children].blank?
56
+ "<ol class='nested_set'>#{ options[:children] }</ol>"
57
+ end
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,45 @@
1
+ # DOC:
2
+ # We use Helper Methods for tree building,
3
+ # because it's faster than View Templates and Partials
4
+
5
+ # SECURITY note
6
+ # Prepare your data on server side for rendering
7
+ # or use h.html_escape(node.content)
8
+ # for escape potentially dangerous content
9
+ module RenderTreeHelper
10
+ class Render
11
+ class << self
12
+ attr_accessor :h, :options
13
+
14
+ def render_node(h, options)
15
+ @h, @options = h, options
16
+
17
+ node = options[:node]
18
+ "
19
+ <li>
20
+ <div class='item'>
21
+ #{ show_link }
22
+ </div>
23
+ #{ children }
24
+ </li>
25
+ "
26
+ end
27
+
28
+ def show_link
29
+ node = options[:node]
30
+ ns = options[:namespace]
31
+ url = h.url_for(ns + [node])
32
+ title_field = node[:name]
33
+
34
+ "<h4>#{ h.link_to(title_field, url) }</h4>"
35
+ end
36
+
37
+ def children
38
+ unless options[:children].blank?
39
+ "<ol>#{ options[:children] }</ol>"
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,146 @@
1
+ module TheSortableTreeHelper
2
+ # Publicated by MIT
3
+ # Nested Set View Helper
4
+
5
+ # Ilya Zykin, zykin-ilya@ya.ru, Russia [Ivanovo, Saint Petersburg] 2009-2014
6
+ # github.com/the-teacher
7
+
8
+ # Default renderers
9
+ TREE_RENDERERS = {
10
+ :tree => RenderTreeHelper,
11
+ :sortable => RenderSortableTreeHelper,
12
+ :expandable => RenderExpandableTreeHelper,
13
+ :nested_options => RenderNestedOptionsHelper
14
+ }
15
+
16
+ ###############################################
17
+ # Common Base Methods
18
+ ###############################################
19
+
20
+ def define_class_of_elements_of tree
21
+ case
22
+ when tree.is_a?(ActiveRecord::Relation) then tree.name.to_s.underscore.downcase
23
+ when tree.empty? then nil
24
+ else tree.first.class.to_s.underscore.downcase
25
+ end
26
+ end
27
+
28
+ def build_tree_html context, render_module, options = {}
29
+ render_module::Render::render_node(self, options)
30
+ end
31
+
32
+ ###############################################
33
+ # Shortcuts
34
+ ###############################################
35
+
36
+ def just_tree tree, options = {}
37
+ build_server_tree(tree, { :type => :tree }.merge!(options))
38
+ end
39
+
40
+ def sortable_tree tree, options = {}
41
+ build_server_tree(tree, { :type => :sortable }.merge!(options))
42
+ end
43
+
44
+ def nested_options tree, options = {}
45
+ build_server_tree(tree, { :type => :nested_options }.merge!(options))
46
+ end
47
+
48
+ def expandable_tree tree, options = {}
49
+ build_server_tree(tree, { :type => :expandable }.merge!(options))
50
+ end
51
+
52
+ ###############################################
53
+ # Server Side Render Tree Helper
54
+ ###############################################
55
+
56
+ def build_server_tree(tree, options= {})
57
+ result = ''
58
+ tree = Array.wrap tree
59
+ opts = {
60
+ # node and base node params
61
+ :id => :id, # node id field
62
+ :title => :title, # name of title fileld
63
+ :node => nil, # node
64
+
65
+ # base options
66
+ :type => :tree, # tree type
67
+ :root => false, # is it root node?
68
+ :level => 0, # recursion level
69
+ :namespace => [], # :admin
70
+
71
+ # BOOST! hash
72
+ :boost => {}
73
+ }.merge!(options)
74
+
75
+ # Basic vars
76
+ root = opts[:root]
77
+ node = opts[:node]
78
+
79
+ # namespace prepare [Rails require]
80
+ opts[:namespace] = Array.wrap opts[:namespace]
81
+
82
+ # Module with **Render** class
83
+ opts[:render_module] = TREE_RENDERERS[opts[:type]] unless opts[:render_module]
84
+
85
+ # Define tree class
86
+ opts[:klass] = define_class_of_elements_of(tree) unless opts[:klass]
87
+
88
+ # BOOST PATCH (BUILD ONCE)
89
+ # solution of main perfomance problem
90
+ # magick index-hash, which made me happy!
91
+
92
+ # Performance comparison
93
+ # Boost OFF: 8000 nodes, 3 levels => (Views: 176281.9ms | ActiveRecord: 189.8ms)
94
+ # Boost ON: 8000 nodes, 3 levels => (Views: 8987.8ms | ActiveRecord: 141.6ms)
95
+
96
+ if opts[:boost].empty?
97
+ tree.each do |item|
98
+ num = item.parent_id || 0
99
+ opts[:boost][num.to_s] = [] unless opts[:boost][num.to_s]
100
+ opts[:boost][num.to_s].push item
101
+ end
102
+ end
103
+
104
+ unless node
105
+ # RENDER ROOTS
106
+ roots = opts[:boost]['0']
107
+
108
+ # Boost OFF
109
+ # roots = tree.select{ |node| node.parent_id.blank? }
110
+
111
+ # define roots, if it's need
112
+ if roots.nil? && !tree.empty?
113
+ min_parent_id = tree.map(&:parent_id).compact.min
114
+ roots = tree.select{ |elem| elem.parent_id == min_parent_id }
115
+ end
116
+
117
+ # children rendering
118
+ if roots
119
+ roots.each do |root|
120
+ _opts = opts.merge({ :node => root, :root => true, :level => opts[:level].next, :boost => opts[:boost] })
121
+ result << build_server_tree(tree, _opts)
122
+ end
123
+ end
124
+ else
125
+ # RENDER NODE'S CHILDREN
126
+ children_res = ''
127
+ children = opts[:boost][node.id.to_s]
128
+
129
+ # Boost OFF
130
+ # children = tree.select{ |_node| _node.parent_id == node.id }
131
+
132
+ opts.merge!({ :has_children => children.blank? })
133
+
134
+ unless children.nil?
135
+ children.each do |elem|
136
+ _opts = opts.merge({ :node => elem, :root => false, :level => opts[:level].next, :boost => opts[:boost] })
137
+ children_res << build_server_tree(tree, _opts)
138
+ end
139
+ end
140
+
141
+ result << build_tree_html(self, opts[:render_module], opts.merge({ :root => root, :node => node, :children => children_res }))
142
+ end
143
+
144
+ raw result
145
+ end
146
+ end