adminpanel 2.5.3 → 2.5.4

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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -13
  3. data/adminpanel.gemspec +2 -1
  4. data/app/controllers/concerns/adminpanel/rest_actions.rb +17 -42
  5. data/app/controllers/concerns/adminpanel/sortable_actions.rb +2 -10
  6. data/app/helpers/adminpanel/adminpanel_form_builder.rb +23 -28
  7. data/app/helpers/adminpanel/shared_pages_helper.rb +14 -10
  8. data/app/models/adminpanel/analytic.rb +10 -2
  9. data/app/models/adminpanel/permission.rb +4 -3
  10. data/app/models/adminpanel/role.rb +5 -3
  11. data/app/models/adminpanel/user.rb +4 -4
  12. data/app/models/concerns/adminpanel/base.rb +1 -2
  13. data/app/models/concerns/adminpanel/friendly.rb +28 -0
  14. data/app/views/adminpanel/form/_checkbox.html.erb +45 -0
  15. data/app/views/adminpanel/form/_select.html.erb +35 -0
  16. data/app/views/adminpanel/shared/_create_remote_resource_button.html.erb +4 -7
  17. data/app/views/adminpanel/templates/{create_has_many.js.erb → checkbox.js.erb} +1 -1
  18. data/app/views/adminpanel/templates/{create_belongs_to.js.erb → option_for_select.js.erb} +1 -1
  19. data/config/locales/es.yml +1 -2
  20. data/config/routes.rb +1 -1
  21. data/lib/adminpanel.rb +1 -0
  22. data/lib/adminpanel/version.rb +1 -1
  23. data/lib/generators/adminpanel/resource/resource_generator.rb +6 -0
  24. data/lib/generators/adminpanel/resource/resource_generator_helper.rb +25 -24
  25. data/lib/tasks/adminpanel/adminpanel.rake +2 -6
  26. data/test/dummy/app/models/adminpanel/department.rb +9 -7
  27. data/test/dummy/app/models/adminpanel/item.rb +8 -6
  28. data/test/dummy/app/models/adminpanel/mug.rb +1 -1
  29. data/test/dummy/app/models/adminpanel/product.rb +14 -2
  30. data/test/dummy/app/models/adminpanel/salesman.rb +16 -15
  31. data/test/dummy/app/models/adminpanel/test_object.rb +4 -3
  32. data/test/dummy/db/schema.rb +1 -0
  33. data/test/dummy/test/fixtures/adminpanel/products.yml +3 -1
  34. data/test/features/shared/concerns/friendly_test.rb +21 -0
  35. data/test/features/shared/form/checkbox_test.rb +39 -0
  36. data/test/features/shared/form/enum_field_test.rb +25 -0
  37. data/test/features/shared/form/has_many_through_remote_test.rb +0 -1
  38. data/test/features/shared/form/{remote_resource_modal_test.rb → modal_contents_test.rb} +2 -2
  39. data/test/features/shared/form/resource_field_test.rb +33 -0
  40. data/test/features/shared/form/select_test.rb +42 -0
  41. data/test/generators/resource_generator_test.rb +9 -6
  42. data/test/helpers/shared_pages_helper_test.rb +40 -16
  43. metadata +41 -36
  44. checksums.yaml.gz.sig +0 -3
  45. data.tar.gz.sig +0 -0
  46. data/app/assets/fonts/.DS_Store +0 -0
  47. data/app/assets/fonts/.keep +0 -0
  48. data/app/assets/stylesheets/adminpanel/fullcalendar.print.css +0 -61
  49. data/app/views/adminpanel/form/_belongs_to.html.erb +0 -21
  50. data/app/views/adminpanel/form/_has_many.html.erb +0 -19
  51. data/test/dummy/app/helpers/application_helper.rb +0 -2
  52. metadata.gz.sig +0 -0
@@ -0,0 +1,45 @@
1
+ <%
2
+ block = properties['options']
3
+ args = properties.except('options')
4
+ collection = block.call(@resource_instance)
5
+ if collection.class.to_s.demodulize == 'ActiveRecord_Relation'
6
+ id_method = :id
7
+ label_method = :name
8
+ else
9
+ # collection is an array of arrays:
10
+ # [
11
+ # [123, value],
12
+ # [456, value]
13
+ # ...
14
+ # ]
15
+ id_method = :first
16
+ label_method = :last
17
+ end
18
+ %>
19
+ <div class="control-group">
20
+ <div class="control-label">
21
+ <%= properties['label'] %>
22
+ </div>
23
+ <%= hidden_field_tag("#{class_name_downcase(f.object)}[#{relationship_ids(properties["model"])}][]", nil) %>
24
+ <div class="controls" id="<%= attribute.gsub('_ids', '') %>-relation">
25
+ <%= f.collection_check_boxes(
26
+ attribute,
27
+ collection,
28
+ id_method,
29
+ label_method
30
+ ) %>
31
+ </div>
32
+ </div>
33
+
34
+ <% if !is_modal &&
35
+ (
36
+ properties['remote_resource'].nil? ||
37
+ properties['remote_resource']
38
+ ) %>
39
+ <!-- if not making resource from other form so we don't have to manage
40
+ infinite nested forms and relations -->
41
+ <%= render(
42
+ 'adminpanel/shared/create_remote_resource_button',
43
+ remote_model: attribute.gsub('_ids', '')
44
+ ) %>
45
+ <% end %>
@@ -0,0 +1,35 @@
1
+ <%
2
+ block = properties['options']
3
+ args = properties.except('options')
4
+ collection = block.call(f.object)
5
+ if collection.class.to_s.demodulize == 'ActiveRecord_Relation'
6
+ id_method = :id
7
+ label_method = :name
8
+ else
9
+ id_method = :first
10
+ label_method = :last
11
+ end
12
+ collection = options_from_collection_for_select(
13
+ collection,
14
+ id_method,
15
+ label_method,
16
+ @resource_instance.send(attribute)
17
+ )
18
+ %>
19
+ <%= f.select attribute, collection, { include_blank: true }, args %>
20
+
21
+ <% if !is_modal &&
22
+ (
23
+ properties['remote_resource'].nil? ||
24
+ properties['remote_resource']
25
+ ) %>
26
+ <!-- if rendering the form inside a modal, so we don't have to
27
+ manage infinited nested forms and if it's supposed to be
28
+ created in relation model -->
29
+
30
+ <%= render(
31
+ 'adminpanel/shared/create_remote_resource_button',
32
+ belongs_request: true,
33
+ remote_model: attribute.gsub('_id', '')
34
+ ) %>
35
+ <% end %>
@@ -1,19 +1,16 @@
1
- <!-- Button to create a new of remote resource if it's supposed to be
2
- created in relation model -->
3
- <% demodulized_remote_model_name = remote_resource_name.classify.constantize.model_name.to_s.demodulize.underscore %>
4
1
  <%=
5
2
  link_to(
6
3
  I18n.t('other.add',
7
- :model => remote_resource_name.classify.constantize.display_name
4
+ model: "adminpanel/#{remote_model}".classify.constantize.display_name
8
5
  ),
9
6
  polymorphic_path(
10
- [:new, :"#{demodulized_remote_model_name}"],
7
+ [:new, :"#{remote_model}"],
11
8
  model: @model.display_name,
12
9
  model_name: @model.name.demodulize.downcase,
13
- belongs_request: defined? belongs_request
10
+ belongs_request: defined?(belongs_request)
14
11
  ),
15
12
  class: 'btn btn-info',
16
- id: "#{demodulized_remote_model_name}-modal-link",
13
+ id: "#{remote_model}-modal-link",
17
14
  :'data-target' => "#remote-form-modal",
18
15
  :'data-toggle' => 'modal',
19
16
  remote: true
@@ -1,5 +1,5 @@
1
1
  var model_name = "<%= params[:model_name] %>";
2
2
  var new_model = "<%= @model.name.demodulize.downcase %>";
3
- row = '<label class="checkbox"><input checked="checked" id="' + model_name + '_' + new_model + '_ids_" name="' + model_name + '[' + new_model + '_ids][]" type="checkbox" value="<%= resource.id %>"><%= resource.name %></label>';
3
+ row = '<label class="checkbox"><input checked="checked" id="' + model_name + '_' + new_model + '_ids_" name="' + model_name + '[' + new_model + '_ids][]" type="checkbox" value="<%= @resource_instance.id %>"><%= @resource_instance.name %></label>';
4
4
  $("#" + new_model + "-relation").append(row);
5
5
  $("#remote-form-modal").modal('toggle');
@@ -1,5 +1,5 @@
1
1
  var model_name = "<%= params[:model_name] %>";
2
2
  var new_model = "<%= @model.name.demodulize.downcase %>";
3
- var option = '<option value="<%= resource.id %>" selected="selected"><%= resource.name %></option>';
3
+ var option = '<option value="<%= @resource_instance.id %>" selected="selected"><%= @resource_instance.name %></option>';
4
4
  $("#" + model_name + "_" + new_model + "_id").append(option);
5
5
  $("#remote-form-modal").modal('toggle');
@@ -3,8 +3,7 @@ es:
3
3
  form:
4
4
  server_file: 'El archivo en el servidor es: %{file}'
5
5
  model:
6
- Analytic: 'Analytics'
7
- Categories: 'Categorías'
6
+ Analytic: 'Google Analytics'
8
7
  Role: 'Rol'
9
8
  User: 'Usuario'
10
9
  Permission: 'Permisos'
data/config/routes.rb CHANGED
@@ -5,7 +5,7 @@ Adminpanel::Engine.routes.draw do
5
5
  Adminpanel.displayable_resources.each do |resource|
6
6
  case resource
7
7
  when :analytics
8
- resources :analytics, resources_parameters(resource).merge({ only: [:index] }) do
8
+ resources :analytics, only: [:index] do
9
9
  collection do
10
10
  get :google, to: 'analytics#google', path: 'google'
11
11
 
data/lib/adminpanel.rb CHANGED
@@ -4,6 +4,7 @@ require 'cancancan'
4
4
  require 'carrierwave'
5
5
  require 'carrierwave/orm/activerecord'
6
6
  require 'coffee-rails'
7
+ require 'friendly_id'
7
8
  require 'font-awesome-rails'
8
9
  require 'google/api_client'
9
10
  require 'instagram'
@@ -1,3 +1,3 @@
1
1
  module Adminpanel
2
- VERSION = '2.5.3'
2
+ VERSION = '2.5.4'
3
3
  end
@@ -23,6 +23,12 @@ module Adminpanel
23
23
  when 'wysiwyg'
24
24
  fields_to_delete << attribute
25
25
  fields << attribute.split(':').first + ':' + 'text'
26
+ when 'belongs_to'
27
+ fields_to_delete << attribute
28
+ fields << attribute.split(':').first + ':' + 'select'
29
+ when 'has_many'
30
+ fields_to_delete << attribute
31
+ fields << attribute.split(':').first + ':' + 'checkbox'
26
32
  end
27
33
  end
28
34
  fields_to_delete.each do |field|
@@ -19,11 +19,11 @@ module Adminpanel
19
19
  "#{resource_name}_#{@attr_field}".camelize
20
20
  end
21
21
 
22
- def belongs_to_field(resource)
22
+ def select_field(resource)
23
23
  "#{resource.singularize.downcase}_id"
24
24
  end
25
25
 
26
- def has_many_field(resource)
26
+ def checkbox_field(resource)
27
27
  "#{resource.singularize.downcase}_ids"
28
28
  end
29
29
 
@@ -43,7 +43,7 @@ module Adminpanel
43
43
  def is_a_resource?
44
44
  fields.each do |attribute|
45
45
  assign_attributes_variables(attribute)
46
- if @attr_type != 'belongs_to'
46
+ if @attr_type != 'select'
47
47
  return true
48
48
  end
49
49
  end
@@ -74,11 +74,11 @@ module Adminpanel
74
74
  fields.map do |attribute|
75
75
  assign_attributes_variables(attribute)
76
76
  case @attr_type
77
- when 'belongs_to'
78
- ':' + belongs_to_field(@attr_field)
79
- when 'has_many'
80
- "{ #{has_many_field(@attr_field)}: [] }"
81
- else
77
+ when 'select'
78
+ ":#{select_field(@attr_field)}"
79
+ when 'checkbox'
80
+ "{ #{checkbox_field(@attr_field)}: [] }"
81
+ else
82
82
  ":#{attribute.split(':').first}"
83
83
  end
84
84
  end.join(",\n")
@@ -123,12 +123,12 @@ module Adminpanel
123
123
  attribute_hash(gallery_name.pluralize, 'adminpanel_file_field')
124
124
  end
125
125
 
126
- def belongs_to_form_hash
127
- attribute_hash(belongs_to_field(@attr_field), 'belongs_to', resource_class_name(@attr_field))
126
+ def select_form_hash
127
+ attribute_hash(select_field(@attr_field), 'select', resource_class_name(@attr_field))
128
128
  end
129
129
 
130
- def has_many_form_hash
131
- attribute_hash(has_many_field(resource_class_name(@attr_field.downcase.singularize + 's')), 'has_many', @attr_field.capitalize.singularize)
130
+ def checkbox_form_hash
131
+ attribute_hash(checkbox_field(resource_class_name(@attr_field.downcase.singularize + 's')), 'checkbox', @attr_field.capitalize.singularize)
132
132
  end
133
133
 
134
134
  def attribute_hash(name, type, model = '')
@@ -155,17 +155,18 @@ module Adminpanel
155
155
  "'placeholder' => '#{@attr_field}'"
156
156
  end
157
157
 
158
- def model_type(type)
159
- "'model' => 'Adminpanel::#{type}'"
158
+ def model_type(model_name)
159
+ "'options' => Proc.new { |object|\n" +
160
+ indent("Adminpanel::#{model_name}.all\n", 2) +
161
+ '}'
160
162
  end
161
163
 
162
164
  def has_associations?
163
165
  fields.each do |attribute|
164
166
  assign_attributes_variables(attribute)
165
167
  if( @attr_type == 'images' ||
166
- @attr_type == 'belongs_to' ||
167
- @attr_type == 'has_many' ||
168
- @attr_type == 'has_many_through' ||
168
+ @attr_type == 'select' ||
169
+ @attr_type == 'checkbox' ||
169
170
  @attr_type == 'file' ||
170
171
  has_gallery? )
171
172
  return true
@@ -179,10 +180,10 @@ module Adminpanel
179
180
  fields.each do |attribute|
180
181
  assign_attributes_variables(attribute)
181
182
  case @attr_type
182
- when 'belongs_to'
183
- association = "#{association}#{belongs_to_association(@attr_field)}"
184
- when 'has_many' || 'has_many_through'
185
- association = "#{association}#{has_many_association(@attr_field)}"
183
+ when 'select'
184
+ association = "#{association}#{select_association(@attr_field)}"
185
+ when 'checkbox'
186
+ association = "#{association}#{checkbox_association(@attr_field)}"
186
187
  when 'file'
187
188
  association = "#{association}#{file_assocation(@attr_field)}"
188
189
  end
@@ -195,11 +196,11 @@ module Adminpanel
195
196
  association
196
197
  end
197
198
 
198
- def belongs_to_association(field)
199
+ def select_association(field)
199
200
  "belongs_to :#{field.singularize.downcase}\n\t\t"
200
201
  end
201
202
 
202
- def has_many_association(field)
203
+ def checkbox_association(field)
203
204
  return "# has_many :#{@attr_field.downcase}zations\n\t\t" +
204
205
  "# has_many :#{@attr_field.pluralize.downcase}, " +
205
206
  "through: :#{@attr_field.downcase}zations, " +
@@ -207,7 +208,7 @@ module Adminpanel
207
208
  end
208
209
 
209
210
  def file_assocation(field)
210
- return "mount_uploader :#{field}, #{class_name}Uploader\n\t\t"
211
+ "mount_uploader :#{field}, #{class_name}Uploader\n\t\t"
211
212
  end
212
213
 
213
214
  end
@@ -95,12 +95,8 @@ namespace :adminpanel do
95
95
  value = Faker::Internet.url
96
96
  when 'id' #assign field_id it to a random instance of Adminpanel::field
97
97
  field = field.downcase.singularize
98
- if field != 'category'
99
- value = "adminpanel/#{field}".classify.constantize.order('RAND()').first.id
100
- else
101
- value = "adminpanel/#{field}".classify.constantize.of_model(@model.display_name).order('RAND()').first.id
102
- end
103
- field = "#{field}_id"
98
+ value = "adminpanel/#{field}".classify.constantize.order('RAND()').first.id
99
+ field = "#{field}_id"
104
100
 
105
101
  when 'email' #generates a random email
106
102
  value = Faker::Internet.email
@@ -5,24 +5,26 @@ module Adminpanel
5
5
  belongs_to :category
6
6
 
7
7
  has_many :items
8
- has_many :product, :through => :items, :dependent => :destroy
8
+ has_many :product, through: :items, dependent: :destroy
9
9
 
10
10
  def self.form_attributes
11
11
  [
12
12
  {
13
13
  'category_id' => {
14
- 'type' => 'belongs_to',
15
- 'label' => 'category',
14
+ 'type' => 'select',
16
15
  'placeholder' => 'category',
17
- 'model' => 'Adminpanel::Category',
16
+ 'options' => Proc.new { |object|
17
+ Adminpanel::Category.all
18
+ }
18
19
  }
19
20
  },
20
21
  {
21
22
  'product_ids' => {
22
- 'type' => 'has_many',
23
- 'label' => 'product',
23
+ 'type' => 'checkbox',
24
24
  'placeholder' => 'product',
25
- 'model' => 'Adminpanel::Product',
25
+ 'options' => Proc.new { |object|
26
+ Adminpanel::Product.all
27
+ }
26
28
  }
27
29
  },
28
30
  {
@@ -9,18 +9,20 @@ module Adminpanel
9
9
  [
10
10
  {
11
11
  'product_id' => {
12
- 'type' => 'belongs_to',
13
- 'label' => 'product',
12
+ 'type' => 'select',
14
13
  'placeholder' => 'product',
15
- 'model' => 'Adminpanel::Product',
14
+ 'options' => Proc.new {|object|
15
+ Adminpanel::Product.all {|o| [o.id, o.name] }
16
+ }
16
17
  }
17
18
  },
18
19
  {
19
20
  'category_id' => {
20
- 'type' => 'belongs_to',
21
- 'label' => 'category',
21
+ 'type' => 'select',
22
22
  'placeholder' => 'category',
23
- 'model' => 'Adminpanel::Category',
23
+ 'options' => Proc.new {|object|
24
+ Adminpanel::Category.all {|o| [o.id, o.name] }
25
+ }
24
26
  }
25
27
  },
26
28
 
@@ -36,7 +36,7 @@ module Adminpanel
36
36
  # end
37
37
 
38
38
  def self.routes_options
39
- { except:[:new, :create, :edit, :update, :destroy, :show], path:'tazas'}
39
+ { except: [:new, :create, :edit, :update, :destroy, :show], path:'tazas'}
40
40
  end
41
41
  end
42
42
  end
@@ -3,6 +3,7 @@ module Adminpanel
3
3
  include Adminpanel::Base
4
4
  include Adminpanel::Facebook
5
5
  include Adminpanel::Twitter
6
+ include Adminpanel::Friendly
6
7
 
7
8
  has_many :categorizations
8
9
  has_many :categories, through: :categorizations
@@ -12,9 +13,21 @@ module Adminpanel
12
13
  validates_presence_of :price
13
14
  validates_presence_of :description
14
15
 
16
+ def supername
17
+ "Super#{name}"
18
+ end
19
+
15
20
  def self.form_attributes
16
21
  [
17
- {"category_ids" => {"type" => "has_many", "model" => "Adminpanel::Category", "name" => "category_ids"}},
22
+ {
23
+ "category_ids" => {
24
+ "type" => "checkbox",
25
+ "options" => Proc.new {|object|
26
+ Adminpanel::Category.all
27
+ }
28
+ }
29
+ },
30
+
18
31
  {
19
32
  'name' => {
20
33
  'type' => 'text_field',
@@ -24,7 +37,6 @@ module Adminpanel
24
37
  {
25
38
  'price' => {
26
39
  'type' => 'text_field',
27
- 'name' => 'price'
28
40
  }
29
41
  },
30
42
  {
@@ -8,21 +8,22 @@ module Adminpanel
8
8
 
9
9
  def self.form_attributes
10
10
  [
11
- {
12
- 'name' => {
13
- 'type' => 'text_field',
14
- 'label' => 'name',
15
- 'placeholder' => 'name'
16
- }
17
- },
18
- {
19
- 'product_id' => {
20
- 'type' => 'belongs_to',
21
- 'model' => 'Adminpanel::Product',
22
- 'label' => 'product',
23
- 'placeholder' => 'product'
24
- }
25
- },
11
+ {
12
+ 'name' => {
13
+ 'type' => 'text_field',
14
+ 'label' => 'name',
15
+ 'placeholder' => 'name'
16
+ }
17
+ },
18
+ {
19
+ 'product_id' => {
20
+ 'type' => 'select',
21
+ 'label' => 'product_id',
22
+ 'options' => Proc.new { |object|
23
+ Adminpanel::Product.all.map {|o| [o.id, o.supername]}
24
+ }
25
+ }
26
+ },
26
27
  ]
27
28
  end
28
29