adminpanel 2.4.3 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/README.md +16 -16
  4. data/adminpanel.gemspec +9 -8
  5. data/app/assets/javascripts/adminpanel/application.js +4 -0
  6. data/app/assets/javascripts/adminpanel/bootstrap-wysihtml5.js +2 -4
  7. data/app/assets/javascripts/adminpanel/sortable.js.coffee +27 -0
  8. data/app/assets/stylesheets/adminpanel/application.css +1 -0
  9. data/app/assets/stylesheets/adminpanel/sortable.css.scss.erb +13 -0
  10. data/app/controllers/adminpanel/application_controller.rb +0 -1
  11. data/app/controllers/adminpanel/sessions_controller.rb +5 -2
  12. data/app/controllers/concerns/adminpanel/rest_actions.rb +24 -22
  13. data/app/controllers/concerns/adminpanel/sortable_actions.rb +3 -20
  14. data/app/helpers/adminpanel/breadcrumbs_helper.rb +6 -5
  15. data/app/helpers/adminpanel/router_helper.rb +9 -3
  16. data/app/helpers/adminpanel/shared_pages_helper.rb +1 -1
  17. data/app/models/concerns/adminpanel/base.rb +34 -11
  18. data/app/models/concerns/adminpanel/sitemap.rb +0 -1
  19. data/app/models/concerns/adminpanel/sortable.rb +33 -30
  20. data/app/models/concerns/adminpanel/sortable_gallery.rb +90 -0
  21. data/app/views/adminpanel/form/_adminpanel_file_field.html.erb +1 -1
  22. data/app/views/adminpanel/templates/index.html.erb +41 -13
  23. data/app/views/adminpanel/templates/show.html.erb +33 -13
  24. data/config/initializers/adminpanel/carrierwave_mini_magick_quality.rb +11 -0
  25. data/config/locales/en.yml +3 -7
  26. data/config/locales/es.yml +1 -8
  27. data/config/routes.rb +6 -8
  28. data/lib/adminpanel.rb +9 -8
  29. data/lib/adminpanel/version.rb +1 -1
  30. data/lib/generators/adminpanel/custom_errors/custom_errors_generator.rb +37 -0
  31. data/lib/generators/adminpanel/custom_errors/templates/errors_controller.rb +14 -0
  32. data/lib/generators/adminpanel/custom_errors/templates/show.html.erb +1 -0
  33. data/lib/generators/adminpanel/gallery/templates/gallery_template.rb +8 -3
  34. data/lib/generators/adminpanel/gallery/templates/uploader.rb +4 -1
  35. data/lib/generators/adminpanel/initialize/initialize_generator.rb +0 -12
  36. data/lib/generators/adminpanel/initialize/templates/adminpanel_setup.rb +1 -2
  37. data/lib/generators/adminpanel/resource/resource_generator.rb +29 -8
  38. data/lib/generators/adminpanel/resource/resource_generator_helper.rb +34 -7
  39. data/lib/generators/adminpanel/resource/templates/adminpanel_resource_template.rb +7 -2
  40. data/lib/tasks/adminpanel/adminpanel.rake +19 -61
  41. data/test/dummy/app/models/adminpanel/file_resourcefile.rb +1 -1
  42. data/test/dummy/app/models/adminpanel/gallery.rb +9 -4
  43. data/test/dummy/app/models/adminpanel/galleryfile.rb +2 -2
  44. data/test/dummy/app/models/adminpanel/photo.rb +1 -1
  45. data/test/dummy/app/models/adminpanel/product.rb +0 -4
  46. data/test/dummy/config/initializers/adminpanel_setup.rb +1 -1
  47. data/test/dummy/test/fixtures/adminpanel/galleryfiles.yml +24 -0
  48. data/test/features/shared/concerns/sortable_gallery_ui_test.rb +25 -0
  49. data/test/features/shared/concerns/sortable_test.rb +4 -4
  50. data/test/features/shared/form/{belongs_to_non_category_modal_test.rb → belongs_to_remote_test.rb} +1 -1
  51. data/test/features/shared/form/{has_many_through_non_category_modal_test.rb → has_many_through_remote_test.rb} +1 -1
  52. data/test/generators/dump_generator_test.rb +1 -13
  53. data/test/generators/gallery_generator_test.rb +1 -1
  54. data/test/generators/initialize_generator_test.rb +1 -9
  55. data/test/generators/resource_generator_test.rb +21 -1
  56. data/test/helpers/router_helper_test.rb +0 -4
  57. data/test/models/adminpanel/sortable_gallery_unit_test.rb +118 -0
  58. data/test/models/adminpanel/sortable_unit_test.rb +75 -0
  59. data/test/tasks/adminpanel_rake_test.rb +1 -1
  60. metadata +86 -85
  61. data/app/assets/images/adminpanel/loguito.png +0 -0
  62. data/app/controllers/adminpanel/categories_controller.rb +0 -52
  63. data/app/controllers/concerns/adminpanel/galleryzable_actions.rb +0 -34
  64. data/app/models/concerns/adminpanel/galleryzation.rb +0 -78
  65. data/app/views/adminpanel/categories/_categories_table.html.erb +0 -48
  66. data/app/views/adminpanel/categories/_category_form.html.erb +0 -33
  67. data/app/views/adminpanel/categories/create.js.erb +0 -6
  68. data/app/views/adminpanel/categories/index.html.erb +0 -63
  69. data/app/views/adminpanel/categories/new.js.erb +0 -5
  70. data/app/views/adminpanel/icons/_move_to_better.html.erb +0 -17
  71. data/app/views/adminpanel/icons/_move_to_worst.html.erb +0 -18
  72. data/app/views/adminpanel/shared/_gallery_entries.html.erb +0 -11
  73. data/app/views/adminpanel/shared/_index_records.html.erb +0 -32
  74. data/app/views/adminpanel/templates/gallery_entries.js.erb +0 -1
  75. data/app/views/adminpanel/templates/index_records.js.erb +0 -1
  76. data/lib/generators/adminpanel/initialize/templates/category_template.rb +0 -45
  77. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_categories_table.rb +0 -11
  78. data/test/features/categories/categories_index_test.rb +0 -31
  79. data/test/features/shared/concerns/galleryzable_test.rb +0 -22
  80. data/test/features/shared/form/belongs_to_category_modal_test.rb +0 -35
  81. data/test/features/shared/form/has_many_through_category_modal_test.rb +0 -35
  82. data/test/models/adminpanel/galleryzable_test.rb +0 -28
@@ -0,0 +1,11 @@
1
+ module CarrierWave
2
+ module MiniMagick
3
+ def quality(percentage)
4
+ manipulate! do |img|
5
+ img.quality(percentage.to_s)
6
+ img = yield(img) if block_given?
7
+ img
8
+ end
9
+ end
10
+ end
11
+ end
@@ -10,7 +10,6 @@ en:
10
10
  adminproject_id: 'Proyect'
11
11
  brief: 'Brief Description'
12
12
  body: 'Body'
13
- category_id: 'Category'
14
13
  client_id: 'Client'
15
14
  description: 'Description'
16
15
  email: 'Email'
@@ -69,10 +68,10 @@ en:
69
68
  submitting: 'Submitting...'
70
69
  save: 'Save %{resource}'
71
70
  save_success: 'Has been saved successfully'
72
- update: 'Update %{name}'
71
+ update: 'Update %{resource}'
73
72
  delete: 'Delete'
74
73
  view: 'View'
75
- delete confirmation: "Are you sure you wan't to delete?"
74
+ delete_confirmation: "Are you sure you wan't to delete?"
76
75
  is_true: 'Yes'
77
76
  is_false: 'No'
78
77
  authentication:
@@ -115,10 +114,7 @@ en:
115
114
  retweet: 'retweet'
116
115
  comment: 'comment'
117
116
  publish: 'publish-to-%{location}'
118
- move_to_better: 'add-priority'
119
- move_to_worst: 'remove-priority'
120
- move_gallery_to_better: 'add-priority-gallery'
121
- move_gallery_to_worst: 'remove-priority-gallery'
117
+ move_to_position: 'move-position'
122
118
  new: 'new'
123
119
  edit: 'edit'
124
120
  show: 'show'
@@ -5,7 +5,6 @@ es:
5
5
  model:
6
6
  Analytic: 'Analytics'
7
7
  Categories: 'Categorías'
8
- Category: 'Categoría'
9
8
  Role: 'Rol'
10
9
  User: 'Usuario'
11
10
  Permission: 'Permisos'
@@ -14,7 +13,6 @@ es:
14
13
  adminproject_id: 'Proyecto'
15
14
  brief: 'Pequeña descripción'
16
15
  body: 'Contenido'
17
- category_id: 'Categoría'
18
16
  client_id: 'Cliente'
19
17
  description: 'Descripción'
20
18
  email: 'Correo electrónico'
@@ -73,8 +71,7 @@ es:
73
71
  delete_confirmation: 'Estás seguro que desea eliminar %{resource}?'
74
72
  delete: 'Eliminar'
75
73
  details: 'Detalles de la foto'
76
- move_to_better: 'Mejorar %{resource} de posición'
77
- move_to_worst: 'Bajar %{resource} de posición'
74
+ move_to_position: 'cambiar-posicion'
78
75
  is_false: 'No'
79
76
  is_true: 'Sí'
80
77
  publish: 'Publicar'
@@ -126,10 +123,6 @@ es:
126
123
  retweet: 'retweet'
127
124
  comment: 'comentar'
128
125
  publish: 'publicar-a-%{location}'
129
- move_to_better: 'subir-prioridad'
130
- move_to_worst: 'bajar-prioridad'
131
- move_gallery_to_better: 'subir-prioridad-galeria'
132
- move_gallery_to_worst: 'bajar-prioridad-galeria'
133
126
  facebook_page: 'pagina-en-facebook'
134
127
  new: 'nuevo'
135
128
  edit: 'editar'
data/config/routes.rb CHANGED
@@ -21,12 +21,11 @@ Adminpanel::Engine.routes.draw do
21
21
  end
22
22
  end
23
23
  else
24
- if get_gallery_children(resource)
25
- # include galleryzation concern
26
- resources get_gallery_children(resource).to_sym, only: [:index] do
24
+ if gallery_is_sortable?(resource)
25
+ # included sortable_gallery
26
+ resources sortable_gallery(resource), only: [:index] do
27
27
  member do
28
- put :move_gallery_better, as: 'move_gallery_to_better', path: I18n.t('routes.move_gallery_to_better')
29
- put :move_gallery_worst, as: 'move_gallery_to_worst', path: I18n.t('routes.move_gallery_to_worst')
28
+ put :move_to_position, as: 'move_to_position', path: I18n.t('routes.move_to_position')
30
29
  end
31
30
  end
32
31
  end
@@ -40,10 +39,9 @@ Adminpanel::Engine.routes.draw do
40
39
  end
41
40
  end
42
41
 
43
- if is_sortable?(resource)
42
+ if resource_is_sortable?(resource)
44
43
  # include sortable concern
45
- put :move_to_better, as: 'move_to_better', path: I18n.t('routes.move_to_better')
46
- put :move_to_worst, as: 'move_to_worst', path: I18n.t('routes.move_to_worst')
44
+ put :move_to_position, as: 'move_to_position', path: I18n.t('routes.move_to_position')
47
45
  end
48
46
 
49
47
  if has_fb_share?(resource)
data/lib/adminpanel.rb CHANGED
@@ -1,18 +1,19 @@
1
- require 'adminpanel/version'
2
1
  require 'adminpanel/engine'
2
+ require 'adminpanel/version'
3
+ require 'cancancan'
3
4
  require 'carrierwave'
4
5
  require 'carrierwave/orm/activerecord'
5
- require 'google/api_client'
6
- require 'cancancan'
6
+ require 'coffee-rails'
7
7
  require 'font-awesome-rails'
8
+ require 'google/api_client'
9
+ require 'instagram'
10
+ require 'jquery-rails'
11
+ require 'jquery-ui-rails'
8
12
  require 'koala'
9
- require 'twitter'
10
13
  require 'omniauth-twitter'
11
- require 'jquery-rails'
12
- require 'instagram'
13
- require 'turbolinks'
14
- require 'coffee-rails'
15
14
  require 'sass'
15
+ require 'turbolinks'
16
+ require 'twitter'
16
17
 
17
18
  module Adminpanel
18
19
  end
@@ -1,3 +1,3 @@
1
1
  module Adminpanel
2
- VERSION = '2.4.3'
2
+ VERSION = '2.5.0'
3
3
  end
@@ -0,0 +1,37 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module Adminpanel
4
+ class CustomErrorsGenerator < ActiveRecord::Generators::Base
5
+ desc 'Generate ErrorsController, template and configure the app to show our errors'
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :name, type: :string, default: 'default', require: false
8
+
9
+ def copy_errors_controller
10
+ copy_file 'errors_controller.rb', 'app/controllers/errors_controller.rb'
11
+ end
12
+
13
+ def copy_errors_template
14
+ copy_file 'show.html.erb', 'app/views/errors/show.html.erb'
15
+ end
16
+
17
+ def inject_errors_into_routes
18
+ inject_into_file 'config/routes.rb', before: "\nend\n" do
19
+ "\n get \"(errors)/:status\", to: \"errors#show\", constraints: { status: /\d{3}/ }"
20
+ end
21
+ end
22
+
23
+ def inject_error_handling_app_in_configuration
24
+ inject_into_file 'config/application.rb', after: 'class Application < Rails::Application' do
25
+ "\n config.exceptions_app = -> (env) { ErrorsController.action(:show).call(env) }"
26
+ end
27
+ end
28
+
29
+ def print_messages
30
+ puts "The generator tried it's best to insert into config/routes.rb"
31
+ puts ' get "(errors)/:status", to: "errors#show", constraints: { status: /\d{3}/ }'
32
+ puts 'and into config/application.rb'
33
+ puts ' config.exceptions_app = -> (env) { ErrorsController.action(:show).call(env) }'
34
+ puts 'Make sure those lines are actually there. You can customize your messages in app/controllers/errors_controller.rb and in app/views/errors/show.html.erb'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ class ErrorsController < ActionController::Base
2
+ # layout to show with your errors. make sure it's not that fancy because we're
3
+ # handling errors.
4
+ layout 'application'
5
+
6
+ def show
7
+ @exception = env['action_dispatch.exception']
8
+ @status = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
9
+
10
+ # @response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
11
+ # response contains the error name ex: 404 => "not found"
12
+ render status: @status
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ <h1><%= @status %> :'(</h1>
@@ -1,12 +1,13 @@
1
1
  module Adminpanel
2
2
  class <%= class_name %> < ActiveRecord::Base
3
- # include Adminpanel::Base # required for galleryzation
4
- # include Adminpanel::Galleryzation
3
+ include Adminpanel::Base
4
+ # include Adminpanel::SortableGallery
5
5
 
6
- # belongs_to :<%= reference_name %>
6
+ belongs_to :<%= reference_name %>
7
7
 
8
8
  mount_uploader :file, <%= class_name %>Uploader
9
9
 
10
+ before_destroy :remove_attachment
10
11
 
11
12
  # def self.relation_field
12
13
  # '<%= reference_name %>_id'
@@ -16,5 +17,9 @@ module Adminpanel
16
17
  # '<%= class_name %>'
17
18
  # end
18
19
 
20
+ private
21
+ def remove_attachment
22
+ self.remove_file!
23
+ end
19
24
  end
20
25
  end
@@ -15,6 +15,9 @@ module Adminpanel
15
15
  # Process files as they are uploaded:
16
16
  # process resize_to_fill: [1366, 768]
17
17
 
18
+ # 70 as a good default, make sure you know what's your priority
19
+ process quality: 70
20
+
18
21
  # THE THUMB VERSION IS NECESSARY BY ADMINPANEL, DON'T REMOVE IT!!!!
19
22
  version :thumb do
20
23
  process resize_to_limit: [80, 80]
@@ -25,7 +28,7 @@ module Adminpanel
25
28
  # process reside_and_pad: [120, 900]
26
29
  # end
27
30
 
28
- # EXAMPLE:
31
+ # EXAMPLE:
29
32
  # original 300 x 300 (this is a square, thanks)
30
33
  # _________________
31
34
  # | |
@@ -4,11 +4,6 @@ module Adminpanel
4
4
  desc 'Generate the migrations necessary to start the gem'
5
5
  source_root File.expand_path("../templates", __FILE__)
6
6
  argument :name, type: :string, default: 'default', require: false
7
- class_option :'skip-category',
8
- type: :boolean,
9
- aliases: '-c',
10
- default: false,
11
- desc: 'Skip category skeleton and migration for it if true'
12
7
  class_option :'skip-section-uploader',
13
8
  type: :boolean,
14
9
  aliases: '-u',
@@ -31,13 +26,6 @@ module Adminpanel
31
26
  end
32
27
  end
33
28
 
34
- def create_category
35
- if !options[:'skip-category']
36
- copy_file 'category_template.rb', 'app/models/adminpanel/category.rb'
37
- migration_template 'create_adminpanel_categories_table.rb', 'db/migrate/create_adminpanel_categories_table.rb'
38
- end
39
- end
40
-
41
29
  def create_section_uploader
42
30
  if !options[:'skip-section-uploader']
43
31
  copy_file 'section_uploader.rb', 'app/uploaders/adminpanel/section_uploader.rb'
@@ -48,8 +48,7 @@ Adminpanel.setup do |config|
48
48
  :users,
49
49
  :roles,
50
50
  :permissions,
51
- # :auths,
52
- #:categories,
51
+ #:auths,
53
52
  :sections
54
53
  ]
55
54
  end
@@ -7,16 +7,18 @@ module Adminpanel
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
  desc 'Generate the resource files necessary to use a model'
9
9
  class_option :'skip-gallery',
10
- :type => :boolean,
11
- :default => true,
12
- :desc => 'Choose if we shoud create the gallery for this resource, default: true (skip gallery)'
10
+ type: :boolean,
11
+ default: true,
12
+ desc: 'Choose if we shoud create the gallery for this resource, default: true (skip gallery)'
13
13
 
14
- argument :fields, :type => :array, :default => [], :banner => 'field[:type][:index] field[:type][:index]'
14
+ argument :fields,
15
+ type: :array,
16
+ default: [],
17
+ banner: 'field[:type][:index] field[:type][:index]'
15
18
 
16
19
  def change_fields_aliases
17
20
  fields.each do |attribute|
18
- type = attribute.split(':').second
19
- case type
21
+ case attribute.split(':').second
20
22
  when 'wysiwyg'
21
23
  fields.delete(attribute)
22
24
  fields << attribute.split(':').first + ':' + 'text'
@@ -35,8 +37,17 @@ module Adminpanel
35
37
  end
36
38
 
37
39
  def generate_migration
38
- parameters = fields
39
- parameters.delete_if{ |pair| pair.split(':').second == 'has_many' }
40
+ parameters = fields.dup
41
+ parameters.delete_if do |pair|
42
+ pair.split(':').second == 'has_many'
43
+ end
44
+ parameters.each do |attribute|
45
+ case attribute.split(':').second
46
+ when 'file'
47
+ parameters.delete(attribute)
48
+ parameters << attribute.split(':').first + ':' + 'string'
49
+ end
50
+ end
40
51
  parameters << 'created_at:datetime' << 'updated_at:datetime'
41
52
  invoke :migration, ["create_adminpanel_#{pluralized_name}", parameters]
42
53
  end
@@ -47,6 +58,16 @@ module Adminpanel
47
58
  end
48
59
  end
49
60
 
61
+ def generate_files_uploaders
62
+ fields.each do |attribute|
63
+ assign_attributes_variables(attribute)
64
+ case @attr_type
65
+ when 'file'
66
+ template '../../gallery/templates/uploader.rb', "app/uploaders/adminpanel/#{class_name.underscore}_uploader.rb"
67
+ end
68
+ end
69
+ end
70
+
50
71
  def add_resource_to_config
51
72
  if setup_is_found? && is_a_resource?
52
73
  inject_into_file 'config/initializers/adminpanel_setup.rb',
@@ -8,6 +8,17 @@ module Adminpanel
8
8
  end
9
9
  end
10
10
 
11
+ def needs_name?
12
+ fields.each do |attribute|
13
+ return false if attribute.split(':').first == 'name'
14
+ end
15
+ true
16
+ end
17
+
18
+ def class_name
19
+ "#{resource_name}_#{@attr_field}".camelize
20
+ end
21
+
11
22
  def belongs_to_field(resource)
12
23
  "#{resource.singularize.downcase}_id"
13
24
  end
@@ -96,6 +107,10 @@ module Adminpanel
96
107
  attribute_hash(@attr_field, 'number_field')
97
108
  end
98
109
 
110
+ def file_form_hash
111
+ attribute_hash(@attr_field, 'file_field')
112
+ end
113
+
99
114
  def boolean_form_hash
100
115
  attribute_hash(@attr_field, 'boolean')
101
116
  end
@@ -147,7 +162,12 @@ module Adminpanel
147
162
  def has_associations?
148
163
  fields.each do |attribute|
149
164
  assign_attributes_variables(attribute)
150
- if @attr_type == "images" || @attr_type == "belongs_to" || @attr_type == "has_many" || @attr_type == "has_many_through"
165
+ if( @attr_type == 'images' ||
166
+ @attr_type == 'belongs_to' ||
167
+ @attr_type == 'has_many' ||
168
+ @attr_type == 'has_many_through' ||
169
+ @attr_type == 'file' ||
170
+ has_gallery? )
151
171
  return true
152
172
  end
153
173
  end
@@ -158,13 +178,20 @@ module Adminpanel
158
178
  association = ""
159
179
  fields.each do |attribute|
160
180
  assign_attributes_variables(attribute)
161
- if @attr_type == "belongs_to"
181
+ case @attr_type
182
+ when 'belongs_to'
162
183
  association = "#{association}#{belongs_to_association(@attr_field)}"
163
- elsif @attr_type == "has_many" || @attr_type == "has_many_through"
184
+ when 'has_many' || 'has_many_through'
164
185
  association = "#{association}#{has_many_association(@attr_field)}"
186
+ when 'file'
187
+ association = "#{association}#{file_assocation(@attr_field)}"
165
188
  end
189
+ end
166
190
 
191
+ if has_gallery?
192
+ association = "#{association}mount_images :#{gallery_name.pluralize}\n\t\t"
167
193
  end
194
+
168
195
  association
169
196
  end
170
197
 
@@ -175,12 +202,12 @@ module Adminpanel
175
202
  def has_many_association(field)
176
203
  return "# has_many :#{@attr_field.downcase}zations\n\t\t" +
177
204
  "# has_many :#{@attr_field.pluralize.downcase}, " +
178
- ":through => :#{@attr_field.downcase}zations, " +
179
- ":dependent => :destroy\n\t\t"
205
+ "through: :#{@attr_field.downcase}zations, " +
206
+ "dependent: :destroy\n\t\t"
180
207
  end
181
208
 
182
- def get_gallery
183
- return "\n\t\tmount_images :#{gallery_name.pluralize}\n"
209
+ def file_assocation(field)
210
+ return "mount_uploader :#{field}, #{class_name}Uploader\n\t\t"
184
211
  end
185
212
 
186
213
  end
@@ -1,9 +1,14 @@
1
1
  module Adminpanel
2
- class <%= camelized_resource %> < ActiveRecord::Base
2
+ class <%= camelized_resource -%> < ActiveRecord::Base
3
3
  include Adminpanel::Base
4
4
 
5
5
  <%= associations if has_associations? -%>
6
- <%= get_gallery if has_gallery? -%>
6
+
7
+ <% if needs_name? -%>
8
+ def name
9
+ self.id.to_s
10
+ end
11
+ <% end -%>
7
12
 
8
13
  def self.form_attributes
9
14
  [