adminpanel 2.6.1 → 3.0.0

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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/adminpanel.gemspec +6 -6
  4. data/app/assets/images/adminpanel/magnifier.png +0 -0
  5. data/app/assets/javascripts/adminpanel/bootstrap-data-confirm.coffee.erb +142 -0
  6. data/app/assets/javascripts/adminpanel/dom-filter.coffee +15 -0
  7. data/app/assets/javascripts/adminpanel/dropzone.js +1728 -0
  8. data/app/assets/javascripts/adminpanel/filter-side-menu.coffee +4 -0
  9. data/app/assets/javascripts/adminpanel/gallery.js.coffee.erb +79 -0
  10. data/app/assets/javascripts/adminpanel/realm.js +0 -3
  11. data/app/assets/stylesheets/adminpanel/_search-input.scss.erb +11 -0
  12. data/app/assets/stylesheets/adminpanel/bootstrap.css.erb +1 -1
  13. data/app/assets/stylesheets/adminpanel/dropzone.css +515 -0
  14. data/app/assets/stylesheets/adminpanel/theme.css.scss.erb +1 -1
  15. data/app/controllers/adminpanel/analytics_controller.rb +7 -51
  16. data/app/controllers/adminpanel/application_controller.rb +1 -0
  17. data/app/controllers/adminpanel/roles_controller.rb +4 -1
  18. data/app/controllers/adminpanel/sections_controller.rb +1 -7
  19. data/app/controllers/concerns/adminpanel/facebook_actions.rb +3 -0
  20. data/app/controllers/concerns/adminpanel/gallery_actions.rb +31 -0
  21. data/app/controllers/concerns/adminpanel/rest_actions.rb +4 -1
  22. data/app/helpers/adminpanel/analytics_helper.rb +8 -18
  23. data/app/helpers/adminpanel/application_helper.rb +10 -2
  24. data/app/helpers/adminpanel/router_helper.rb +6 -2
  25. data/app/helpers/adminpanel/shared_pages_helper.rb +5 -3
  26. data/app/models/adminpanel/analytic.rb +4 -0
  27. data/app/models/adminpanel/image.rb +31 -0
  28. data/app/models/adminpanel/sectionfile.rb +1 -3
  29. data/app/models/concerns/adminpanel/base.rb +51 -7
  30. data/app/models/concerns/adminpanel/sortable_gallery.rb +12 -17
  31. data/app/views/adminpanel/analytics/_header.html.erb +1 -1
  32. data/app/views/adminpanel/form/_adminpanel_file_field.html.erb +27 -23
  33. data/app/views/adminpanel/icons/_delete.html.erb +1 -0
  34. data/app/views/adminpanel/sections/edit.html.erb +1 -12
  35. data/app/views/adminpanel/shared/_form_fields.html.erb +1 -0
  36. data/app/views/adminpanel/templates/destroy.js.erb +3 -0
  37. data/app/views/adminpanel/templates/index.html.erb +4 -4
  38. data/app/views/adminpanel/templates/show.html.erb +57 -52
  39. data/app/views/layouts/adminpanel/_side_menu.html.erb +18 -3
  40. data/config/initializers/adminpanel/assets.rb +4 -0
  41. data/config/locales/en.yml +24 -9
  42. data/config/locales/es.yml +18 -33
  43. data/config/routes.rb +10 -5
  44. data/lib/adminpanel/version.rb +1 -1
  45. data/lib/generators/adminpanel/gallery/gallery_generator.rb +0 -8
  46. data/lib/generators/adminpanel/gallery/templates/gallery_template.rb +7 -18
  47. data/lib/generators/adminpanel/gallery/templates/uploader.rb +1 -1
  48. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb +9 -5
  49. data/lib/generators/adminpanel/resource/resource_generator.rb +12 -16
  50. data/lib/generators/adminpanel/resource/resource_generator_helper.rb +23 -16
  51. data/test/dummy/.gitignore +2 -2
  52. data/test/dummy/app/controllers/adminpanel/products_controller.rb +1 -1
  53. data/test/dummy/app/models/adminpanel/galleryfile.rb +1 -13
  54. data/test/dummy/app/models/adminpanel/photo.rb +2 -9
  55. data/test/dummy/app/models/adminpanel/product.rb +1 -0
  56. data/test/dummy/config/initializers/carrierwave.rb +5 -0
  57. data/test/dummy/db/schema.rb +10 -18
  58. data/test/dummy/test/fixtures/adminpanel/galleries.yml +3 -3
  59. data/test/dummy/test/fixtures/adminpanel/images.yml +60 -0
  60. data/test/dummy/test/fixtures/adminpanel/products.yml +2 -2
  61. data/test/dummy/test/fixtures/{dog fries.png → attachments/dog-fries.png} +0 -0
  62. data/test/dummy/test/fixtures/attachments/hipster.jpg +0 -0
  63. data/test/dummy/test/fixtures/attachments/thumb_hipster.jpg +0 -0
  64. data/test/features/shared/form/belongs_to_remote_test.rb +1 -4
  65. data/test/features/shared/form/resource_field_test.rb +1 -1
  66. data/test/features/shared/resource/edit_test.rb +2 -5
  67. data/test/features/shared/resource/new_test.rb +5 -2
  68. data/test/features/shared/ui/dropzone_element_generation_test.rb +27 -0
  69. data/test/features/shared/ui/filtering_test.rb +29 -0
  70. data/test/generators/gallery_generator_test.rb +0 -10
  71. data/test/generators/resource_generator_test.rb +30 -6
  72. data/test/helpers/shared_pages_helper_test.rb +22 -43
  73. data/test/models/adminpanel/image_test.rb +31 -0
  74. data/test/models/adminpanel/sortable_gallery_unit_test.rb +8 -8
  75. data/test/support/view_case.rb +2 -2
  76. metadata +53 -43
  77. data/app/assets/images/adminpanel/dialogs.png +0 -0
  78. data/app/assets/images/adminpanel/icons-big.png +0 -0
  79. data/app/assets/images/adminpanel/icons-small.png +0 -0
  80. data/app/assets/images/adminpanel/select2.png +0 -0
  81. data/app/assets/images/adminpanel/select2x2.png +0 -0
  82. data/app/assets/images/adminpanel/toolbar.png +0 -0
  83. data/app/assets/javascripts/adminpanel/jquery.knob.js +0 -652
  84. data/app/assets/javascripts/adminpanel/jquery.masonry.min.js +0 -10
  85. data/app/assets/javascripts/adminpanel/jquery.slimscroll.min.js +0 -14
  86. data/app/views/adminpanel/analytics/_fb_statistic_widget.html.erb +0 -63
  87. data/app/views/adminpanel/analytics/fb.html.erb +0 -106
  88. data/test/dummy/config/carrierwave.rb +0 -6
  89. data/test/dummy/public/favicon.ico +0 -0
  90. data/test/dummy/test/fixtures/adminpanel/galleryfiles.yml +0 -42
  91. data/test/features/shared/ui/max_images_gallery_test.rb +0 -51
data/config/routes.rb CHANGED
@@ -9,8 +9,6 @@ Adminpanel::Engine.routes.draw do
9
9
  collection do
10
10
  get :google, to: 'analytics#google', path: 'google'
11
11
 
12
- get :fb, to:'analytics#fb', path:'facebook'
13
-
14
12
  get :twitter, to:'analytics#twitter', path:'twitter'
15
13
  post 'reply_to_tweet/:id', to: 'analytics#reply_to_tweet', as: 'reply_to', path: "twitter/#{I18n.t('routes.reply')}/:id"
16
14
  post 'favorite_tweet/:id', to: 'analytics#favorite_tweet', as: 'favorite', path: "twitter/#{I18n.t('routes.favorite')}/:id"
@@ -22,10 +20,12 @@ Adminpanel::Engine.routes.draw do
22
20
  end
23
21
  else
24
22
  if gallery_is_sortable?(resource)
23
+ sortable_galleries(resource).each do |sortable_gallery_resource|
25
24
  # included sortable_gallery
26
- resources sortable_gallery(resource), only: [:index] do
27
- member do
28
- put :move_to_position, as: 'move_to_position', path: I18n.t('routes.move_to_position')
25
+ resources sortable_gallery_resource.first.pluralize, only: [:index] do
26
+ member do
27
+ put :move_to_position, as: 'move_to_position', path: I18n.t('routes.move_to_position')
28
+ end
29
29
  end
30
30
  end
31
31
  end
@@ -64,6 +64,11 @@ Adminpanel::Engine.routes.draw do
64
64
  send(request_type, args['path'].to_sym, args['args'])
65
65
  end
66
66
  end
67
+
68
+ if has_gallery?(resource)
69
+ post :add_to_gallery, to: "#{resource}#add_to_gallery", as: 'add_to_gallery', path: I18n.t('routes.add_to_gallery')
70
+ delete :remove_image, to: "#{resource}#remove_image", as: 'remove_image', path: I18n.t('routes.remove_image')
71
+ end
67
72
  end
68
73
  end
69
74
  end
@@ -1,3 +1,3 @@
1
1
  module Adminpanel
2
- VERSION = '2.6.1'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -12,14 +12,6 @@ module Adminpanel
12
12
  template 'uploader.rb', "app/uploaders/adminpanel/#{lower_name}_uploader.rb"
13
13
  end
14
14
 
15
- def generate_migration
16
- migration_template(
17
- 'gallery_migration.rb',
18
- "db/migrate/create_adminpanel_#{lower_name.pluralize}.rb"
19
- )
20
- puts "don't forget to add the form_field, the relationship and #{lower_name}s_attributes it to the permited params"
21
- end
22
-
23
15
  private
24
16
  def reference_name
25
17
  name.singularize.downcase
@@ -1,25 +1,14 @@
1
1
  module Adminpanel
2
- class <%= class_name %> < ActiveRecord::Base
3
- include Adminpanel::Base
2
+ class <%= class_name %> < Image
4
3
  # include Adminpanel::SortableGallery
5
4
 
6
- belongs_to :<%= reference_name %>
7
-
8
5
  mount_uploader :file, <%= class_name %>Uploader
9
-
10
- before_destroy :remove_attachment
11
-
12
- # def self.relation_field
13
- # '<%= reference_name %>_id'
6
+
7
+
8
+ # Warning: This method prevents the file from recreating versions,
9
+ # use it at your own risk delete the original file
10
+ # def remove_original attachment
11
+ # File.delete "#{Rails.root.join('public')}#{file_url}" if file
14
12
  # end
15
-
16
- # def self.display_name
17
- # '<%= class_name %>'
18
- # end
19
-
20
- private
21
- def remove_attachment
22
- self.remove_file!
23
- end
24
13
  end
25
14
  end
@@ -20,7 +20,7 @@ module Adminpanel
20
20
 
21
21
  # THE THUMB VERSION IS NECESSARY BY ADMINPANEL, DON'T REMOVE IT!!!!
22
22
  version :thumb do
23
- process resize_to_limit: [80, 80]
23
+ process resize_to_fill: [120, 120]
24
24
  end
25
25
 
26
26
  # however, you can create your own versions:
@@ -16,7 +16,7 @@ class CreateAdminpanelTables < ActiveRecord::Migration
16
16
  create_permissions
17
17
  create_auths
18
18
  create_sections
19
- create_sectionfiles
19
+ create_images
20
20
  end
21
21
 
22
22
  private
@@ -33,10 +33,14 @@ class CreateAdminpanelTables < ActiveRecord::Migration
33
33
  add_index :adminpanel_users, [:remember_token]
34
34
  end
35
35
 
36
- def create_sectionfiles
37
- create_table :adminpanel_sectionfiles do |t|
38
- t.string :file
39
- t.integer :section_id
36
+ def create_images
37
+ create_table :adminpanel_images do |t|
38
+ t.string :file
39
+ t.integer :model_id
40
+ t.string :model_type
41
+ t.string :type
42
+ t.string :file_size
43
+ t.string :content_type
40
44
  t.timestamps
41
45
  end
42
46
  end
@@ -17,26 +17,21 @@ module Adminpanel
17
17
  banner: 'field[:type][:index] field[:type][:index]'
18
18
 
19
19
  def change_fields_aliases
20
- fields_to_delete = []
20
+ attrs_to_delete = []
21
21
  fields.each do |attribute|
22
22
  case attribute.split(':').second
23
23
  when 'wysiwyg'
24
- fields_to_delete << attribute
24
+ attrs_to_delete << attribute
25
25
  fields << attribute.split(':').first + ':' + 'text'
26
26
  when 'datepicker'
27
- fields_to_delete << attribute
27
+ attrs_to_delete << attribute
28
28
  fields << attribute.split(':').first + ':' + 'date'
29
- when 'belongs_to'
30
- fields_to_delete << attribute
31
- fields << attribute.split(':').first + ':' + 'select'
32
29
  when 'has_many'
33
- fields_to_delete << attribute
30
+ attrs_to_delete << attribute
34
31
  fields << attribute.split(':').first + ':' + 'checkbox'
35
32
  end
36
33
  end
37
- fields_to_delete.each do |field|
38
- fields.delete(field)
39
- end
34
+ attrs_to_delete.each { |f| fields.delete(f) }
40
35
  end
41
36
 
42
37
  def generate_model
@@ -51,17 +46,18 @@ module Adminpanel
51
46
 
52
47
  def generate_migration
53
48
  parameters = fields.dup
54
- parameters.delete_if do |pair|
55
- pair.split(':').second == 'has_many'
56
- end
49
+ parameters.delete_if { |pair| pair.split(':').second == 'checkbox' }
50
+ attrs_to_delete = []
57
51
  parameters.each do |attribute|
58
52
  case attribute.split(':').second
59
- when 'file'
60
- parameters.delete(attribute)
53
+ when 'file', 'image'
54
+ attrs_to_delete << attribute
61
55
  parameters << attribute.split(':').first + ':' + 'string'
62
56
  end
63
57
  end
58
+ attrs_to_delete.each { |a| parameters.delete(a) }
64
59
  parameters << 'created_at:datetime' << 'updated_at:datetime'
60
+
65
61
  invoke :migration, ["create_adminpanel_#{pluralized_name}", parameters]
66
62
  end
67
63
 
@@ -75,7 +71,7 @@ module Adminpanel
75
71
  fields.each do |attribute|
76
72
  assign_attributes_variables(attribute)
77
73
  case @attr_type
78
- when 'file'
74
+ when 'file', 'image'
79
75
  template '../../gallery/templates/uploader.rb', "app/uploaders/adminpanel/#{class_name.underscore}_uploader.rb"
80
76
  end
81
77
  end
@@ -11,7 +11,7 @@ module Adminpanel
11
11
  "#{resource_name}_#{@attr_field}".camelize
12
12
  end
13
13
 
14
- def select_field(resource)
14
+ def belongs_to_field(resource)
15
15
  "#{resource.singularize.downcase}_id"
16
16
  end
17
17
 
@@ -35,7 +35,7 @@ module Adminpanel
35
35
  def is_a_resource?
36
36
  fields.each do |attribute|
37
37
  assign_attributes_variables(attribute)
38
- if @attr_type != 'select'
38
+ if @attr_type != 'belongs_to'
39
39
  return true
40
40
  end
41
41
  end
@@ -66,8 +66,8 @@ module Adminpanel
66
66
  fields.map do |attribute|
67
67
  assign_attributes_variables(attribute)
68
68
  case @attr_type
69
- when 'select'
70
- ":#{select_field(@attr_field)}"
69
+ when 'belongs_to'
70
+ ":#{belongs_to_field(@attr_field)}"
71
71
  when 'checkbox'
72
72
  "{ #{checkbox_field(@attr_field)}: [] }"
73
73
  else
@@ -103,6 +103,10 @@ module Adminpanel
103
103
  attribute_hash(@attr_field, 'file_field')
104
104
  end
105
105
 
106
+ def image_form_hash
107
+ attribute_hash(@attr_field, 'image_field')
108
+ end
109
+
106
110
  def boolean_form_hash
107
111
  attribute_hash(@attr_field, 'boolean')
108
112
  end
@@ -115,12 +119,16 @@ module Adminpanel
115
119
  attribute_hash(gallery_name.pluralize, 'adminpanel_file_field')
116
120
  end
117
121
 
118
- def select_form_hash
119
- attribute_hash(select_field(@attr_field), 'select', resource_class_name(@attr_field))
122
+ def belongs_to_form_hash
123
+ attribute_hash(belongs_to_field(@attr_field), 'select', resource_class_name(@attr_field))
120
124
  end
121
125
 
122
126
  def checkbox_form_hash
123
- attribute_hash(checkbox_field(resource_class_name(@attr_field.downcase.singularize + 's')), 'checkbox', @attr_field.capitalize.singularize)
127
+ attribute_hash(
128
+ checkbox_field(resource_class_name(@attr_field.downcase.singularize + 's')),
129
+ 'checkbox',
130
+ @attr_field.capitalize.singularize
131
+ )
124
132
  end
125
133
 
126
134
  def attribute_hash(name, type, model = '')
@@ -156,11 +164,10 @@ module Adminpanel
156
164
  def has_associations?
157
165
  fields.each do |attribute|
158
166
  assign_attributes_variables(attribute)
159
- if( @attr_type == 'images' ||
160
- @attr_type == 'select' ||
167
+ if( @attr_type == 'belongs_to' ||
161
168
  @attr_type == 'checkbox' ||
162
169
  @attr_type == 'file' ||
163
- has_gallery? )
170
+ has_gallery?)
164
171
  return true
165
172
  end
166
173
  end
@@ -172,12 +179,12 @@ module Adminpanel
172
179
  fields.each do |attribute|
173
180
  assign_attributes_variables(attribute)
174
181
  case @attr_type
175
- when 'select'
176
- association = "#{association}#{select_association(@attr_field)}"
182
+ when 'belongs_to'
183
+ association = "#{association}#{belongs_to_association(@attr_field)}"
177
184
  when 'checkbox'
178
185
  association = "#{association}#{checkbox_association(@attr_field)}"
179
- when 'file'
180
- association = "#{association}#{file_assocation(@attr_field)}"
186
+ when 'image', 'file'
187
+ association = "#{association}#{file_association(@attr_field)}"
181
188
  end
182
189
  end
183
190
 
@@ -188,7 +195,7 @@ module Adminpanel
188
195
  association
189
196
  end
190
197
 
191
- def select_association(field)
198
+ def belongs_to_association(field)
192
199
  "belongs_to :#{field.singularize.downcase}\n\t\t"
193
200
  end
194
201
 
@@ -199,7 +206,7 @@ module Adminpanel
199
206
  "dependent: :destroy\n\t\t"
200
207
  end
201
208
 
202
- def file_assocation(field)
209
+ def file_association(field)
203
210
  "mount_uploader :#{field}, #{class_name}Uploader\n\t\t"
204
211
  end
205
212
 
@@ -6,14 +6,14 @@ capybara-*.html
6
6
  /tmp/test.log
7
7
  /tmp/development.log
8
8
  /db/*.sqlite3
9
- /public/system
9
+ /public/uploads
10
10
  /coverage/
11
11
  /spec/tmp
12
12
  **.orig
13
13
  rerun.txt
14
14
  pickle-email-*.html
15
15
  config/initializers/secret_token.rb
16
- /public/uploads/
16
+ /public/uploads/tmp
17
17
 
18
18
  ## Environment normalisation:
19
19
  /.bundle
@@ -8,7 +8,7 @@ module Adminpanel
8
8
  :name,
9
9
  :category_ids,
10
10
  :description,
11
- :photos_attributes => [:product_id, :file]
11
+ photo_ids: []
12
12
  )
13
13
  end
14
14
 
@@ -1,19 +1,7 @@
1
1
  module Adminpanel
2
- class Galleryfile < ActiveRecord::Base
3
- include Adminpanel::Base
2
+ class Galleryfile < Image
4
3
  include Adminpanel::SortableGallery
5
4
 
6
- belongs_to :gallery
7
-
8
5
  mount_uploader :file, Adminpanel::PhotoUploader
9
-
10
- def self.relation_field
11
- 'gallery_id'
12
- end
13
-
14
- def self.display_name
15
- 'galleryfile'
16
- end
17
-
18
6
  end
19
7
  end
@@ -1,13 +1,6 @@
1
1
  module Adminpanel
2
- class Photo < ActiveRecord::Base
3
- include Adminpanel::Base
2
+ class Photo < Image
4
3
  # include Adminpanel::SortableGallery
5
- mount_uploader :file, PhotoUploader
6
- belongs_to :product
7
-
8
- def self.relation_method
9
- 'product_id'
10
- end
11
-
4
+ mount_uploader :file, Adminpanel::PhotoUploader
12
5
  end
13
6
  end
@@ -7,6 +7,7 @@ module Adminpanel
7
7
 
8
8
  has_many :categorizations
9
9
  has_many :categories, through: :categorizations
10
+
10
11
  mount_images :photos
11
12
 
12
13
  validates_presence_of :name
@@ -0,0 +1,5 @@
1
+ if Rails.env.test?
2
+ CarrierWave.configure do |config|
3
+ config.root = 'test/fixtures/attachments'
4
+ end
5
+ end
@@ -26,18 +26,16 @@ ActiveRecord::Schema.define do
26
26
  t.datetime :created_at, null: false
27
27
  t.datetime :updated_at, null: false
28
28
  end
29
- create_table :adminpanel_galleryfiles do |t|
30
- t.string :file
31
- t.integer :position
32
- t.integer :gallery_id
33
- t.datetime :created_at, null: false
34
- t.datetime :updated_at, null: false
35
- end
36
- create_table :adminpanel_sectionfiles do |t|
37
- t.string :file
38
- t.string :section_id
39
- t.datetime :created_at, null: false
40
- t.datetime :updated_at, null: false
29
+ create_table :adminpanel_images do |t|
30
+ t.string :file
31
+ t.integer :model_id
32
+ t.string :model_type
33
+ t.string :type
34
+ t.string :file_size
35
+ t.string :content_type
36
+ t.integer :position
37
+ t.datetime :created_at, null: false
38
+ t.datetime :updated_at, null: false
41
39
  end
42
40
  create_table :adminpanel_products do |t|
43
41
  t.string :price
@@ -47,12 +45,6 @@ ActiveRecord::Schema.define do
47
45
  t.datetime :created_at, null: false
48
46
  t.datetime :updated_at, null: false
49
47
  end
50
- create_table :adminpanel_photos do |t|
51
- t.string :file
52
- t.text :product_id
53
- t.datetime :created_at, null: false
54
- t.datetime :updated_at, null: false
55
- end
56
48
  create_table :adminpanel_categories do |t|
57
49
  t.string :name
58
50
  t.string :model
@@ -1,15 +1,15 @@
1
1
  one:
2
- file: <%= File.open(Rails.root.join("app/assets/images/hipster.jpg")) %>
2
+ file: <%= File.open(Rails.root.join("test", "fixtures", "attachments", "hipster.jpg")) %>
3
3
  position: 1
4
4
  created_at: <%= Date.today %>
5
5
  updated_at: <%= Date.today %>
6
6
  two:
7
- file: <%= File.open(Rails.root.join("app/assets/images/hipster.jpg")) %>
7
+ file: <%= File.open(Rails.root.join("test", "fixtures", "attachments", "hipster.jpg")) %>
8
8
  position: 2
9
9
  created_at: <%= Date.today %>
10
10
  updated_at: <%= Date.today %>
11
11
  three:
12
- file: <%= File.open(Rails.root.join("app/assets/images/hipster.jpg")) %>
12
+ file: <%= File.open(Rails.root.join("test", "fixtures", "attachments", "hipster.jpg")) %>
13
13
  position: 3
14
14
  created_at: <%= Date.today %>
15
15
  updated_at: <%= Date.today %>