hancock_cms_catalog 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +57 -0
  8. data/Rakefile +1 -0
  9. data/app/assets/javascripts/hancock/catalog.coffee +3 -0
  10. data/app/assets/javascripts/hancock/catalog/init.coffee +2 -0
  11. data/app/assets/stylesheets/hancock/catalog.sass +0 -0
  12. data/app/controllers/concerns/hancock/catalog/decorators/categories.rb +29 -0
  13. data/app/controllers/concerns/hancock/catalog/decorators/items.rb +29 -0
  14. data/app/controllers/hancock/catalog/categories_controller.rb +7 -0
  15. data/app/controllers/hancock/catalog/items_controller.rb +7 -0
  16. data/app/models/concerns/hancock/catalog/decorators/category.rb +53 -0
  17. data/app/models/concerns/hancock/catalog/decorators/category_image.rb +52 -0
  18. data/app/models/concerns/hancock/catalog/decorators/item.rb +52 -0
  19. data/app/models/concerns/hancock/catalog/decorators/item_image.rb +52 -0
  20. data/app/models/hancock/catalog/category.rb +11 -0
  21. data/app/models/hancock/catalog/category_image.rb +16 -0
  22. data/app/models/hancock/catalog/item.rb +11 -0
  23. data/app/models/hancock/catalog/item_image.rb +16 -0
  24. data/app/views/hancock/catalog/categories/index.html.slim +39 -0
  25. data/app/views/hancock/catalog/categories/show.html.slim +98 -0
  26. data/app/views/hancock/catalog/items/index.html.slim +38 -0
  27. data/app/views/hancock/catalog/items/show.html.slim +43 -0
  28. data/bin/console +14 -0
  29. data/bin/setup +7 -0
  30. data/config/locales/hancock.catalog.ru.yml +23 -0
  31. data/config/locales/ru.kaminari.yml +17 -0
  32. data/hancock_cms_catalog.gemspec +39 -0
  33. data/lib/generators/hancock/catalog/config/config_generator.rb +13 -0
  34. data/lib/generators/hancock/catalog/config/templates/hancock_catalog.erb +38 -0
  35. data/lib/generators/hancock/catalog/controllers/all_generator.rb +28 -0
  36. data/lib/generators/hancock/catalog/controllers/category_generator.rb +43 -0
  37. data/lib/generators/hancock/catalog/controllers/decorators_generator.rb +24 -0
  38. data/lib/generators/hancock/catalog/controllers/item_generator.rb +43 -0
  39. data/lib/generators/hancock/catalog/controllers/templates/categories_controller.erb +10 -0
  40. data/lib/generators/hancock/catalog/controllers/templates/items_controller.erb +10 -0
  41. data/lib/generators/hancock/catalog/models/all_generator.rb +38 -0
  42. data/lib/generators/hancock/catalog/models/category_generator.rb +43 -0
  43. data/lib/generators/hancock/catalog/models/category_image_generator.rb +43 -0
  44. data/lib/generators/hancock/catalog/models/decorators_generator.rb +24 -0
  45. data/lib/generators/hancock/catalog/models/item_generator.rb +34 -0
  46. data/lib/generators/hancock/catalog/models/item_image_generator.rb +43 -0
  47. data/lib/generators/hancock/catalog/models/templates/category.erb +54 -0
  48. data/lib/generators/hancock/catalog/models/templates/category_image.erb +53 -0
  49. data/lib/generators/hancock/catalog/models/templates/item.erb +56 -0
  50. data/lib/generators/hancock/catalog/models/templates/item_image.erb +53 -0
  51. data/lib/generators/hancock/catalog/views/for_generator.rb +57 -0
  52. data/lib/generators/hancock/catalog/views/views_generator.rb +33 -0
  53. data/lib/hancock/catalog/admin.rb +4 -0
  54. data/lib/hancock/catalog/admin/category.rb +175 -0
  55. data/lib/hancock/catalog/admin/category_image.rb +37 -0
  56. data/lib/hancock/catalog/admin/item.rb +133 -0
  57. data/lib/hancock/catalog/admin/item_image.rb +37 -0
  58. data/lib/hancock/catalog/configuration.rb +75 -0
  59. data/lib/hancock/catalog/controllers/categories.rb +91 -0
  60. data/lib/hancock/catalog/controllers/items.rb +61 -0
  61. data/lib/hancock/catalog/engine.rb +7 -0
  62. data/lib/hancock/catalog/models/category.rb +85 -0
  63. data/lib/hancock/catalog/models/category_image.rb +18 -0
  64. data/lib/hancock/catalog/models/item.rb +92 -0
  65. data/lib/hancock/catalog/models/item_image.rb +18 -0
  66. data/lib/hancock/catalog/models/mongoid/category.rb +37 -0
  67. data/lib/hancock/catalog/models/mongoid/category_image.rb +18 -0
  68. data/lib/hancock/catalog/models/mongoid/item.rb +39 -0
  69. data/lib/hancock/catalog/models/mongoid/item_image.rb +18 -0
  70. data/lib/hancock/catalog/routes.rb +79 -0
  71. data/lib/hancock/catalog/version.rb +5 -0
  72. data/lib/hancock_cms_catalog.rb +47 -0
  73. data/release.sh +6 -0
  74. metadata +178 -0
@@ -0,0 +1,53 @@
1
+ class <%= camelcased_class_name %> < Hancock::Catalog::ItemImage
2
+ embedded_in :item, class_name: "<%= camelcased_item_class_name %>"
3
+ alias :<%= underscored_class_name %> :item
4
+
5
+ def self.find(id)
6
+ find_through(<%= camelcased_item_class_name %>, 'item_images', id)
7
+ end
8
+
9
+ # # after_save :image_auto_rails_admin_jcrop
10
+ # def image_auto_rails_admin_jcrop
11
+ # auto_rails_admin_jcrop(:image) # or nil for cancel autocrop
12
+ # end
13
+
14
+ # # hancock_cms_attached_file(:image)
15
+ # def image_styles
16
+ # super
17
+ # end
18
+
19
+ # def image_jcrop_options
20
+ # super
21
+ # end
22
+
23
+
24
+ ############# rails_admin ##############
25
+ def self.rails_admin_add_fields
26
+ [] #super
27
+ end
28
+
29
+ def self.rails_admin_add_config(config)
30
+ #super(config)
31
+ end
32
+
33
+ def self.admin_can_user_defined_actions
34
+ [].freeze
35
+ end
36
+ def self.admin_cannot_user_defined_actions
37
+ [].freeze
38
+ end
39
+ def self.manager_can_user_defined_actions
40
+ [].freeze
41
+ end
42
+ def self.manager_cannot_user_defined_actions
43
+ [].freeze
44
+ end
45
+ def self.rails_admin_user_defined_visible_actions
46
+ [].freeze
47
+ end
48
+
49
+ rails_admin(&Hancock::Catalog::Admin::ItemImage.config(nil, rails_admin_add_fields) { |config|
50
+ rails_admin_add_config(config)
51
+ })
52
+
53
+ end
@@ -0,0 +1,57 @@
1
+ require 'rails/generators'
2
+
3
+ module Hancock::Catalog::Views
4
+ class ForGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../../../../app/views/hancock/catalog', __FILE__)
6
+ argument :class_name, type: :string
7
+ argument :views_args, type: :array, default: []
8
+
9
+ desc 'Hancock::Catalog Views generator'
10
+ def for
11
+ (views_args == ['all'] ? permitted_file_views : ((views_args & permitted_path_views).map { |v| permitted_file_views(v) }.flatten)).each do |v|
12
+ if v.index('items')
13
+ res_v = "#{underscored_pluralized_class_name}/#{v.gsub(/.*\//, "")}"
14
+ else
15
+ res_v = "#{underscored_singularized_class_name}_categories/#{v.gsub(/.*\//, "")}"
16
+ end
17
+ copy_file "#{v}.html.slim", "app/views/#{res_v}.html.slim"
18
+ end
19
+ end
20
+
21
+ private
22
+ def permitted_views
23
+ [
24
+ 'categories', 'items',
25
+ 'categories/index', 'categories/show',
26
+ 'items/index', 'items/show'
27
+ ]
28
+ end
29
+
30
+ def permitted_file_views(path = '')
31
+ # permitted_views.reject { |v| v.index("#{path}/").nil? }
32
+ permitted_views.reject { |v| v.index("/").nil? }
33
+ end
34
+
35
+ def permitted_path_views
36
+ permitted_views.select { |v| v.index('/').nil? }
37
+ end
38
+
39
+
40
+ def camelcased_class_name
41
+ class_name.camelcase
42
+ end
43
+
44
+ def underscored_class_name
45
+ camelcased_class_name.underscore
46
+ end
47
+
48
+ def underscored_pluralized_class_name
49
+ underscored_class_name.pluralize
50
+ end
51
+
52
+ def underscored_singularized_class_name
53
+ underscored_class_name.singularize
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,33 @@
1
+ require 'rails/generators'
2
+
3
+ module Hancock::Catalog
4
+ class ViewsGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../../../../app/views/hancock/catalog', __FILE__)
6
+ argument :views_args, type: :array, default: []
7
+
8
+ desc 'Hancock::Catalog Config generator'
9
+ def views
10
+ (views_args == ['all'] ? permitted_file_views : ((views_args & permitted_path_views).map { |v| permitted_file_views(v) }.flatten)).each do |v|
11
+ copy_file "#{v}.html.slim", "app/views/hancock/catalog/#{v}.html.slim"
12
+ end
13
+ end
14
+
15
+ private
16
+ def permitted_views
17
+ [
18
+ 'categories', 'items',
19
+ 'categories/index', 'categories/show',
20
+ 'items/index', 'items/show'
21
+ ]
22
+ end
23
+
24
+ def permitted_file_views(path = '')
25
+ permitted_views.reject { |v| v.index("#{path}/").nil? }
26
+ end
27
+
28
+ def permitted_path_views
29
+ permitted_views.select { |v| v.index('/').nil? }
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ module Hancock::Catalog
2
+ module Admin
3
+ end
4
+ end
@@ -0,0 +1,175 @@
1
+ module Hancock::Catalog
2
+ module Admin
3
+ module Category
4
+ def self.config(nav_label = nil, fields = {})
5
+ if nav_label.is_a?(Hash)
6
+ nav_label, fields = nav_label[:nav_label], nav_label
7
+ elsif nav_label.is_a?(Array)
8
+ nav_label, fields = nil, nav_label
9
+ end
10
+
11
+ Proc.new {
12
+ navigation_label(!nav_label.blank? ? nav_label : I18n.t("hancock.catalog"))
13
+
14
+ list do
15
+ scopes [:sorted, :enabled, nil]
16
+
17
+ field :enabled, :toggle do
18
+ searchable false
19
+ end
20
+ field :name do
21
+ searchable true
22
+ end
23
+ if Hancock::Catalog.config.pages_support and Hancock::Catalog.configuration.can_connect_category_with_pages
24
+ field :connected_pages, :hancock_connectable
25
+ end
26
+ field :add_item do
27
+ pretty_value do
28
+ _model = bindings[:object].item_class.rails_admin_model
29
+ bindings[:view].link_to(
30
+ 'Добавить товар',
31
+ bindings[:view].new_path(model_name: _model, "#{_model}[category_ids][]": bindings[:object]._id.to_s),
32
+ class: 'label label-info'
33
+ )
34
+ end
35
+ visible do
36
+ bindings[:controller].action_name == 'index'
37
+ end
38
+ formatted_value {}
39
+ end
40
+
41
+ group :content, &Hancock::Admin.content_block
42
+ if Hancock::Catalog.config.cache_support
43
+ group :caching, &Hancock::Cache::Admin.caching_block
44
+ end
45
+ end
46
+
47
+ edit do
48
+ field :enabled, :toggle
49
+ field :name
50
+
51
+ if Hancock::Catalog.config.pages_support and Hancock::Catalog.configuration.can_connect_category_with_pages
52
+ group :connected_pages do
53
+ active false
54
+ field :connected_pages, :hancock_connectable do
55
+ read_only do
56
+ !bindings[:view].current_user.admin?
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ group :URL, &Hancock::Admin.url_block
63
+ # group :URL do
64
+ # active false
65
+ # field :slugs, :hancock_slugs
66
+ # field :text_slug
67
+ # end
68
+
69
+ if Hancock::Catalog.config.gallery_support
70
+ group :image, &Hancock::Gallery::Admin.images_block(:category_images)
71
+ # group :image do
72
+ # active false
73
+ # field :image, :hancock_image
74
+ # field :category_images
75
+ # end
76
+ end
77
+
78
+
79
+ group :content, &Hancock::Admin.content_block
80
+ # group :content do
81
+ # active false
82
+ # field :excerpt, :hancock_html
83
+ # field :content, :hancock_html
84
+ # end
85
+
86
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
87
+
88
+ if Hancock::Catalog.config.seo_support
89
+ group :seo_n_sitemap, &Hancock::Seo::Admin.seo_n_sitemap_block
90
+ # group :seo do
91
+ # active false
92
+ # field :seo
93
+ # end
94
+ # group :sitemap_data do
95
+ # active false
96
+ # field :sitemap_data
97
+ # end
98
+ end
99
+
100
+ if Hancock::Catalog.config.cache_support
101
+ group :caching, &Hancock::Cache::Admin.caching_block
102
+ end
103
+
104
+ group :items do
105
+ active false
106
+ field :items do
107
+ read_only true
108
+ help 'Список товаров'
109
+
110
+ pretty_value do
111
+ bindings[:object].items.to_a.map { |i|
112
+ route = (bindings[:view] || bindings[:controller])
113
+ model_name = i.rails_admin_model
114
+ route.link_to(i.name, route.rails_admin.show_path(model_name: model_name, id: i.id), title: i.name)
115
+ }.join("<br>").html_safe
116
+ end
117
+ end
118
+ end
119
+ if Hancock::Catalog.config.insertions_support
120
+ group :insertions, &Hancock::Admin.insertions_block
121
+ end
122
+ end
123
+
124
+ show do
125
+ field :name
126
+ field :slugs, :hancock_slugs
127
+ field :text_slug
128
+ field :enabled
129
+ field :image
130
+ field :excerpt
131
+ field :content
132
+
133
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
134
+
135
+ field :items do
136
+ read_only true
137
+
138
+ pretty_value do
139
+ bindings[:object].items.to_a.map { |i|
140
+ route = (bindings[:view] || bindings[:controller])
141
+ model_name = i.rails_admin_model
142
+ route.link_to(i.name, route.rails_admin.show_path(model_name: model_name, id: i.id), title: i.name)
143
+ }.join("<br>").html_safe
144
+ end
145
+ end
146
+
147
+ if Hancock::Catalog.config.insertions_support
148
+ group :insertions, &Hancock::Admin.insertions_block
149
+ end
150
+ end
151
+
152
+ nested_set({max_depth: 2, scopes: []})
153
+
154
+ sort_embedded(
155
+ {
156
+ fields: [:category_images]
157
+ }
158
+ )
159
+
160
+ if defined?(RailsAdminMultipleFileUpload)
161
+ multiple_file_upload(
162
+ {
163
+ fields: [:category_images]
164
+ }
165
+ )
166
+ end
167
+
168
+ if block_given?
169
+ yield self
170
+ end
171
+ }
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,37 @@
1
+ module Hancock::Catalog
2
+ module Admin
3
+ module CategoryImage
4
+ def self.config(nav_label = nil, fields = {})
5
+ if nav_label.is_a?(Hash)
6
+ nav_label, fields = nav_label[:nav_label], nav_label
7
+ elsif nav_label.is_a?(Array)
8
+ nav_label, fields = nil, nav_label
9
+ end
10
+ nav_label ||= I18n.t('hancock.catalog')
11
+
12
+ if Hancock::Catalog.config.gallery_support
13
+ if Hancock::Catalog.mongoid?
14
+ if block_given?
15
+ Hancock::Gallery::Admin::EmbeddedImage.config(nav_label, fields) do |config|
16
+ yield config
17
+ end
18
+ else
19
+ Hancock::Gallery::Admin::EmbeddedImage.config(nav_label, fields)
20
+ end
21
+
22
+ else
23
+ if block_given?
24
+ Hancock::Gallery::Admin::Image.config(nav_label, fields) do |config|
25
+ yield config
26
+ end
27
+ else
28
+ Hancock::Gallery::Admin::Image.config(nav_label,fields)
29
+ end
30
+ end #if Hancock::Catalog.mongoid?
31
+ end #if Hancock::Catalog.config.gallery_support
32
+
33
+ end #def self.config(fields = {})
34
+
35
+ end #module CategoryImage
36
+ end #module Admin
37
+ end #module Hancock::Catalog
@@ -0,0 +1,133 @@
1
+ module Hancock::Catalog
2
+ module Admin
3
+ module Item
4
+ def self.config(nav_label = nil, fields = {})
5
+ if nav_label.is_a?(Hash)
6
+ nav_label, fields = nav_label[:nav_label], nav_label
7
+ elsif nav_label.is_a?(Array)
8
+ nav_label, fields = nil, nav_label
9
+ end
10
+
11
+ Proc.new {
12
+ navigation_label(!nav_label.blank? ? nav_label : I18n.t("hancock.catalog"))
13
+
14
+ list do
15
+ scopes [:sorted, :enabled, nil]
16
+
17
+ field :enabled, :toggle do
18
+ searchable false
19
+ end
20
+ field :name do
21
+ searchable true
22
+ end
23
+ field :categories do
24
+ # searchable :name
25
+ end
26
+ if Hancock::Catalog.config.pages_support and Hancock::Catalog.configuration.can_connect_items_with_pages
27
+ field :connected_pages, :hancock_connectable
28
+ end
29
+
30
+ group :content, &Hancock::Admin.content_block
31
+ if Hancock::Catalog.config.cache_support
32
+ group :caching, &Hancock::Cache::Admin.caching_block
33
+ end
34
+ end
35
+
36
+ edit do
37
+ field :enabled, :toggle
38
+ field :name
39
+ if Hancock::Catalog.config.pages_support and Hancock::Catalog.configuration.can_connect_items_with_pages
40
+ group :connected_pages do
41
+ active false
42
+ field :connected_pages, :hancock_connectable do
43
+ read_only do
44
+ !bindings[:view].current_user.admin?
45
+ end
46
+ end
47
+ end
48
+ end
49
+ group :categories, &Hancock::Admin.categories_block
50
+ # group :categories do
51
+ # active false
52
+ # field :main_category do
53
+ # inline_add false
54
+ # inline_edit false
55
+ # end
56
+ # field :categories, :hancock_multiselect
57
+ # end
58
+ field :price, :string
59
+ # field :price, :money_field
60
+
61
+ group :URL, &Hancock::Admin.url_block
62
+ # group :URL do
63
+ # active false
64
+ # field :slugs, :hancock_slugs
65
+ # field :text_slug
66
+ # end
67
+
68
+ if Hancock::Catalog.config.gallery_support
69
+ group :image, &Hancock::Gallery::Admin.images_block(:item_images)
70
+ # group :image do
71
+ # active false
72
+ # field :image, :hancock_image
73
+ # field :item_images
74
+ # end
75
+ end
76
+
77
+
78
+ group :content, &Hancock::Admin.content_block
79
+ # group :content do
80
+ # active false
81
+ # field :excerpt, :hancock_html
82
+ # field :content, :hancock_html
83
+ # end
84
+
85
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
86
+
87
+ if Hancock::Catalog.config.seo_support
88
+ group :seo_n_sitemap, &Hancock::Seo::Admin.seo_n_sitemap_block
89
+ end
90
+ # if Hancock::Catalog.config.seo_support
91
+ # group :seo do
92
+ # active false
93
+ # field :seo
94
+ # end
95
+ # group :sitemap_data do
96
+ # active false
97
+ # field :sitemap_data
98
+ # end
99
+ # end
100
+
101
+ if Hancock::Catalog.config.cache_support
102
+ group :caching, &Hancock::Cache::Admin.caching_block
103
+ end
104
+
105
+ if Hancock::Catalog.config.insertions_support
106
+ group :insertions, &Hancock::Admin.insertions_block
107
+ end
108
+ end
109
+
110
+ nested_set({max_depth: 1, scopes: []})
111
+
112
+ sort_embedded(
113
+ {
114
+ fields: [:item_images]
115
+ }
116
+ )
117
+
118
+ if defined?(RailsAdminMultipleFileUpload)
119
+ multiple_file_upload(
120
+ {
121
+ fields: [:item_images]
122
+ }
123
+ )
124
+ end
125
+
126
+ if block_given?
127
+ yield self
128
+ end
129
+ }
130
+ end
131
+ end
132
+ end
133
+ end