adminpanel 2.0.1 → 2.1.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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/Gemfile +6 -3
  4. data/README.md +6 -26
  5. data/adminpanel.gemspec +6 -3
  6. data/app/assets/javascripts/adminpanel/bootstrap-wysihtml5-4pre.js +9579 -0
  7. data/app/assets/javascripts/adminpanel/bootstrap-wysihtml5.js +9 -9
  8. data/app/assets/javascripts/adminpanel/realm.js +12 -8
  9. data/app/assets/javascripts/adminpanel/spinner.js.coffee +11 -0
  10. data/app/assets/javascripts/adminpanel/wysiwyg.js.coffee +3 -0
  11. data/app/assets/javascripts/application-admin.js +1 -0
  12. data/app/assets/stylesheets/adminpanel/{bootstrap.css → bootstrap.css.erb} +2 -2
  13. data/app/assets/stylesheets/adminpanel/{theme.css → theme.css.erb} +6 -6
  14. data/app/controllers/adminpanel/analytics_controller.rb +2 -1
  15. data/app/controllers/adminpanel/application_controller.rb +1 -0
  16. data/app/controllers/adminpanel/auths_controller.rb +8 -0
  17. data/app/controllers/adminpanel/categories_controller.rb +1 -1
  18. data/app/controllers/adminpanel/galleries_controller.rb +3 -11
  19. data/app/controllers/adminpanel/sections_controller.rb +5 -14
  20. data/app/controllers/adminpanel/users_controller.rb +1 -1
  21. data/app/controllers/concerns/adminpanel/facebook_actions.rb +64 -0
  22. data/app/controllers/concerns/adminpanel/galleryzable_actions.rb +12 -14
  23. data/app/controllers/concerns/adminpanel/rest_actions.rb +2 -2
  24. data/app/helpers/adminpanel/adminpanel_form_builder.rb +20 -2
  25. data/app/helpers/adminpanel/shared_pages_helper.rb +13 -0
  26. data/app/models/adminpanel/auth.rb +34 -0
  27. data/app/models/adminpanel/section.rb +1 -2
  28. data/app/models/adminpanel/user.rb +1 -2
  29. data/app/models/concerns/adminpanel/base.rb +10 -34
  30. data/app/models/concerns/adminpanel/facebook.rb +27 -0
  31. data/app/views/adminpanel/sections/edit.html.erb +0 -5
  32. data/app/views/adminpanel/sections/index.html.erb +1 -3
  33. data/app/views/layouts/_side_menu.html.erb +5 -4
  34. data/app/views/shared/_create_remote_resource_button.html.erb +23 -0
  35. data/app/views/shared/_fb_icon_button.html.erb +26 -0
  36. data/app/views/shared/_fb_publish_modal.html.erb +40 -0
  37. data/app/views/shared/_form_fields.html.erb +6 -50
  38. data/app/views/shared/_modal.html.erb +1 -1
  39. data/app/views/shared/create_belongs_to.js.erb +1 -1
  40. data/app/views/shared/create_has_many.js.erb +1 -1
  41. data/app/views/shared/fb_choose_page.html.erb +47 -0
  42. data/app/views/shared/index.html.erb +2 -0
  43. data/app/views/shared/show.html.erb +2 -0
  44. data/config/initializers/pluralization_es.rb +3 -0
  45. data/config/locales/es.yml +69 -60
  46. data/config/routes.rb +8 -1
  47. data/lib/adminpanel.rb +1 -0
  48. data/lib/adminpanel/engine.rb +4 -1
  49. data/lib/adminpanel/version.rb +1 -1
  50. data/lib/generators/adminpanel/gallery/gallery_generator.rb +2 -2
  51. data/lib/generators/adminpanel/initialize/initialize_generator.rb +2 -3
  52. data/lib/generators/adminpanel/initialize/templates/ability.rb +1 -1
  53. data/lib/generators/adminpanel/initialize/templates/adminpanel_setup.rb +6 -2
  54. data/lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb +11 -0
  55. data/lib/generators/adminpanel/resource/resource_generator.rb +112 -130
  56. data/lib/generators/adminpanel/resource/templates/controller.rb +4 -1
  57. data/lib/generators/adminpanel/resource/templates/resource.rb +4 -1
  58. data/lib/tasks/adminpanel/adminpanel.rake +6 -2
  59. data/spec/dummy/app/controllers/adminpanel/salesmen_controller.rb +9 -0
  60. data/spec/dummy/app/models/adminpanel/category.rb +1 -0
  61. data/spec/dummy/app/models/adminpanel/mug.rb +2 -2
  62. data/spec/dummy/app/models/adminpanel/product.rb +4 -6
  63. data/spec/dummy/app/models/adminpanel/salesman.rb +35 -0
  64. data/spec/dummy/config/initializers/adminpanel_setup.rb +2 -1
  65. data/spec/dummy/db/schema.rb +13 -0
  66. data/spec/features/shared_pages/edit_spec.rb +48 -0
  67. data/spec/features/shared_pages/index_spec.rb +50 -0
  68. data/spec/features/shared_pages/new_spec.rb +128 -0
  69. data/spec/features/shared_pages/show_spec.rb +30 -0
  70. data/spec/generators/gallery_generator_spec.rb +1 -1
  71. data/spec/generators/resource_generator_spec.rb +36 -11
  72. data/spec/spec_helper.rb +12 -13
  73. data/spec/support/capybara_matchers.rb +17 -0
  74. data/spec/support/factories.rb +1 -1
  75. data/spec/support/helper_methods.rb +0 -18
  76. data/spec/support/shared_connection.rb +10 -0
  77. metadata +100 -21
  78. data/app/assets/javascripts/adminpanel/bootstrap-wysihtml5-3.min.js +0 -261
  79. data/app/assets/javascripts/adminpanel/medium-editor.js +0 -703
  80. data/app/assets/javascripts/adminpanel/wysiwyg.js +0 -5
  81. data/app/assets/stylesheets/adminpanel/medium-editor.css.scss +0 -1
  82. data/app/views/shared/_init_editor.html.erb +0 -27
  83. data/lib/generators/adminpanel/resource/templates/migration.rb +0 -13
  84. data/spec/features/shared_pages_spec.rb +0 -128
@@ -3,7 +3,10 @@ module Adminpanel
3
3
 
4
4
  private
5
5
  def <%= lower_singularized_name %>_params
6
- params.require(:<%= lower_singularized_name%>).permit(<%= symbolized_attributes %>)
6
+ params.require(:<%= lower_singularized_name%>).permit(
7
+ <%= indent("{ #{gallery_name.pluralize}_attributes: [:id, :file, :_destroy] }", 10) + ',' if has_gallery? %>
8
+ <%= indent(symbolized_attributes, 10) %>
9
+ )
7
10
  end
8
11
  end
9
12
  end
@@ -3,9 +3,12 @@ module Adminpanel
3
3
  include Adminpanel::Base
4
4
 
5
5
  <%= associations if has_associations? -%>
6
+ <%= get_gallery if has_gallery? -%>
6
7
 
7
8
  def self.form_attributes
8
- [<%= adminpanel_form_attributes %>
9
+ [
10
+ <%= indent(get_attribute_hash, 8) + ',' %>
11
+ <%= indent(file_field_form_hash, 8) if has_gallery? %>
9
12
  ]
10
13
  end
11
14
 
@@ -168,7 +168,7 @@ private
168
168
  "Adminpanel::Section.new(\n" +
169
169
  "\t:name => \"#{section.name}\",\n" +
170
170
  "\t:has_description => #{section.has_description},\n" +
171
- "\t:description => \"#{section.description}\",\n" +
171
+ "\t:description => \"#{escape_double_quotes(section.description)}\",\n" +
172
172
  "\t:key => \"#{section.key}\",\n" +
173
173
  "\t:page => \"#{section.page}\",\n" +
174
174
  "\t:has_image => #{section.has_image}\n" +
@@ -177,11 +177,15 @@ private
177
177
 
178
178
  def creation_command_category(category)
179
179
  "Adminpanel::Category.new(\n" +
180
- "\t:name => \"#{category.name}\",\n" +
180
+ "\t:name => \"#{escape_double_quotes(category.name)}\",\n" +
181
181
  "\t:model => \"#{category.model}\"\n" +
182
182
  ").save\n"
183
183
  end
184
184
 
185
+ def escape_double_quotes(string)
186
+ string.gsub('"', '\\"')
187
+ end
188
+
185
189
  def change_dates(instance)
186
190
  date = rand(Date.parse('2010-01-01')..Date.today)
187
191
  instance.update_attribute(:created_at, date)
@@ -0,0 +1,9 @@
1
+ module Adminpanel
2
+ class SalesmenController < Adminpanel::ApplicationController
3
+
4
+ private
5
+ def salesman_params
6
+ params.require(:salesman).permit(:name, :product_id)
7
+ end
8
+ end
9
+ end
@@ -2,6 +2,7 @@ module Adminpanel
2
2
  class Category < ActiveRecord::Base
3
3
  include Adminpanel::Base
4
4
  validates_presence_of :model
5
+ validates_presence_of :name
5
6
 
6
7
  has_many :categorizations
7
8
  has_many :products, :through => :categorizations, :dependent => :destroy
@@ -1,8 +1,8 @@
1
1
  module Adminpanel
2
2
  class Mug < ActiveRecord::Base
3
3
  include Adminpanel::Base
4
-
5
-
4
+ validates_presence_of :name
5
+
6
6
  def self.form_attributes
7
7
  [
8
8
  {
@@ -1,7 +1,7 @@
1
1
  module Adminpanel
2
2
  class Product < ActiveRecord::Base
3
3
  include Adminpanel::Base
4
-
4
+
5
5
  has_many :categorizations
6
6
  has_many :categories, :through => :categorizations
7
7
  mount_images :photos
@@ -18,7 +18,6 @@ module Adminpanel
18
18
  {
19
19
  'name' => {
20
20
  'type' => 'text_field',
21
- 'name' => 'name',
22
21
  'label' => 'name',
23
22
  'placeholder' => 'name'}
24
23
  },
@@ -31,22 +30,21 @@ module Adminpanel
31
30
  {
32
31
  'photos' => {
33
32
  'type' => 'adminpanel_file_field',
34
- 'name' => 'photo',
35
33
  'label' => 'photo',
36
34
  'placeholder' => 'photo'}
37
35
  },
38
36
  {
39
37
  'description' => {
40
38
  'type' => 'wysiwyg_field',
41
- 'name' => 'description',
42
39
  'label' => 'description',
43
- 'placeholder' => 'description'}
40
+ 'placeholder' => 'description'
41
+ }
44
42
  },
45
43
  ]
46
44
  end
47
45
 
48
46
  def self.display_name
49
- "Product"
47
+ "Producto"
50
48
  end
51
49
 
52
50
  def self.icon
@@ -0,0 +1,35 @@
1
+ module Adminpanel
2
+ class Salesman < ActiveRecord::Base
3
+ include Adminpanel::Base
4
+
5
+ belongs_to :product
6
+
7
+ def self.form_attributes
8
+ [
9
+ {
10
+ 'name' => {
11
+ 'type' => 'text_field',
12
+ 'label' => 'name',
13
+ 'placeholder' => 'name'
14
+ }
15
+ },
16
+ {
17
+ 'product_id' => {
18
+ 'type' => 'belongs_to',
19
+ 'model' => 'Adminpanel::Product',
20
+ 'label' => 'product',
21
+ 'placeholder' => 'product'
22
+ }
23
+ },
24
+ ]
25
+ end
26
+
27
+ def self.display_name
28
+ 'Agente' #singular
29
+ end
30
+
31
+ # def self.icon
32
+ # "truck" # fa-{icon}
33
+ # end
34
+ end
35
+ end
@@ -18,6 +18,7 @@ Adminpanel.setup do |config|
18
18
  :categories,
19
19
  :products,
20
20
  :users,
21
- :mugs
21
+ :mugs,
22
+ :salesmen
22
23
  ]
23
24
  end
@@ -51,6 +51,13 @@ ActiveRecord::Schema.define do
51
51
  t.datetime :created_at, :null => false
52
52
  t.datetime :updated_at, :null => false
53
53
  end
54
+ create_table :adminpanel_auths do |t|
55
+ t.string :name
56
+ t.string :key
57
+ t.string :value
58
+ t.datetime :created_at, :null => false
59
+ t.datetime :updated_at, :null => false
60
+ end
54
61
  create_table :adminpanel_categorizations do |t|
55
62
  t.integer :product_id
56
63
  t.integer :category_id
@@ -68,6 +75,12 @@ ActiveRecord::Schema.define do
68
75
  t.datetime :created_at, :null => false
69
76
  t.datetime :updated_at, :null => false
70
77
  end
78
+ create_table :adminpanel_salesmen do |t|
79
+ t.string :name
80
+ t.integer :product_id
81
+ t.datetime :created_at, :null => false
82
+ t.datetime :updated_at, :null => false
83
+ end
71
84
  create_table :adminpanel_sections do |t|
72
85
  t.string :name
73
86
  t.text :description
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Shared edit', js: true do
4
+ subject { page }
5
+
6
+ let(:user) { get_user }
7
+
8
+ before do
9
+ Adminpanel::User.delete_all
10
+ visit adminpanel.signin_path
11
+ valid_signin_as_admin(user)
12
+ end
13
+
14
+ after do
15
+ Adminpanel::User.delete_all
16
+ end
17
+
18
+ context 'edit' do
19
+ let!(:product) { FactoryGirl.create(:product) }
20
+ let!(:category){ FactoryGirl.create(:category) }
21
+
22
+ before do
23
+ product.category_ids = [category.id]
24
+ visit adminpanel.edit_product_path(product)
25
+ end
26
+
27
+ it { should have_link('Agregar Categoria') }
28
+
29
+ it { should have_content('Test Category') }
30
+
31
+ it { should have_title(I18n.t('action.update') + " " + Adminpanel::Product.display_name) }
32
+
33
+ describe "with invalid information" do
34
+ before do
35
+ fill_in "product_name", with: ""
36
+ fill_in "product_price", with: ""
37
+ click_button('Guardar Product')
38
+ end
39
+
40
+ it 'should have an error alert' do
41
+ should have_content('Producto no pudo guardarse debido a')
42
+ end
43
+
44
+ it { should have_title(I18n.t('action.update') + " " + Adminpanel::Product.display_name) }
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Shared index' do
4
+ subject { page }
5
+
6
+ let(:user) { get_user }
7
+
8
+ before do
9
+ Adminpanel::User.delete_all
10
+ visit adminpanel.signin_path
11
+ valid_signin_as_admin(user)
12
+ end
13
+
14
+ after do
15
+ Adminpanel::User.delete_all
16
+ end
17
+
18
+ context 'mugs#index excluding every rest action with configurtions but index' do
19
+ before do
20
+ Adminpanel::Mug.create
21
+ visit adminpanel.mugs_path
22
+ end
23
+
24
+ after do
25
+ Adminpanel::Mug.delete_all
26
+ end
27
+
28
+ it 'should not have create mug button' do
29
+ should_not have_link('a', href:'/adminpanel/tazas/new')
30
+ end
31
+ it 'should not have show or destroy button' do
32
+ should_not have_link('a', href:'/adminpanel/tazas/1')
33
+ end
34
+ it 'should not have edit button' do
35
+ should_not have_link('a', href:'/adminpanel/tazas/1/edit')
36
+ end
37
+ end
38
+
39
+
40
+ context 'index' do
41
+ let!(:product) { FactoryGirl.create(:product) }
42
+ before do
43
+ visit adminpanel.products_path
44
+ end
45
+
46
+ it { should have_link(Adminpanel::Product.display_name, adminpanel.new_product_path)}
47
+ it { should have_link('i', adminpanel.product_path(product)) }
48
+ it { should have_link('i', adminpanel.edit_product_path(product)) }
49
+ end
50
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Shared new', js: true do
4
+ subject { page }
5
+
6
+ let(:user) { get_user }
7
+
8
+ before do
9
+ Adminpanel::User.delete_all
10
+ visit adminpanel.signin_path
11
+ valid_signin_as_admin(user)
12
+ visit adminpanel.new_product_path
13
+ end
14
+
15
+ after do
16
+ Adminpanel::User.delete_all
17
+ end
18
+
19
+
20
+ describe 'when submtting with invalid information' do
21
+ before do
22
+ click_button('Agregar Producto')
23
+ end
24
+
25
+ it { should have_title("#{I18n.t('action.create')} #{Adminpanel::Product.display_name}") }
26
+
27
+ it 'should have validation alert' do
28
+ should have_content('Producto no pudo guardarse debido a')
29
+ end
30
+ end
31
+
32
+ describe 'when submitting with valid information' do
33
+ before do
34
+ fill_in 'product_name', :with => 'product name'
35
+ fill_in 'product_price', :with => '855.5'
36
+ page.execute_script(
37
+ %Q(
38
+ $('#product_description').data('wysihtml5').editor.setValue('que pepsi');
39
+ )
40
+ ) # to fill the wysiwyg editor
41
+
42
+ click_button('Agregar Producto')
43
+ end
44
+
45
+ it { should have_content(I18n.t("action.save_success"))}
46
+ it { should have_title('Ver Producto')}
47
+ end
48
+
49
+ describe 'when clicking create remote category link (has_many through)' do
50
+ before do
51
+ click_link('Agregar Categoria')
52
+ end
53
+
54
+ it 'the modal should have the correct title' do
55
+ sleep 1
56
+ find('#modal-title').text.should eq('Agregar Categoria')
57
+ end
58
+
59
+ it 'should show the cateogry form in a modal' do
60
+ should have_content('Agregar Categoria')
61
+ end
62
+
63
+ context 'when submitting the remote (checkboxes) category form' do
64
+ describe 'with valid information' do
65
+ before do
66
+ fill_in 'category_name', with: 'remote category'
67
+ click_button 'Agregar Categoria'
68
+ end
69
+
70
+ it 'should have the created category in the checkboxes options' do
71
+ should have_content 'remote category'
72
+ end
73
+ end
74
+
75
+ describe 'with invalid information' do
76
+ before do
77
+ click_button 'Agregar Categoria'
78
+ end
79
+
80
+ it 'should have the errors' do
81
+ should have_content I18n.t('errors', model: 'Categoria', count: 1)
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ context 'new salesman' do
88
+ before do
89
+ visit adminpanel.new_salesman_path
90
+ end
91
+
92
+ describe 'when clicking the create remote product link (belongs_to)' do
93
+ before do
94
+ click_link 'Agregar Producto'
95
+ sleep 1
96
+ end
97
+
98
+ it 'the modal should have the correct title' do
99
+ find('#modal-title').text.should eq('Agregar Producto')
100
+ end
101
+
102
+ context 'submitting the remote (select) product form' do
103
+ describe 'with valid information' do
104
+ before do
105
+ fill_in 'product_name', with: 'remote product'
106
+ fill_in 'product_description', with: 'remote description lorem'
107
+ fill_in 'product_price', with: '12.3'
108
+ click_button 'Agregar Producto'
109
+ end
110
+
111
+ it 'should have the created product in the select options' do
112
+ should have_xpath "//option[contains(text(), 'remote product' )]"
113
+ end
114
+ end
115
+
116
+ describe 'with invalid information' do
117
+ before do
118
+ click_button 'Agregar Producto'
119
+ end
120
+
121
+ it 'should have the errors' do
122
+ should have_content I18n.t('errors', model: 'Producto', count: 3)
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Shared show', js: true do
4
+ subject { page }
5
+
6
+ let(:user) { get_user }
7
+ let!(:category){ FactoryGirl.create(:category) }
8
+ let!(:product) { FactoryGirl.create(:product) }
9
+ let!(:photo) { FactoryGirl.create(:photo) }
10
+
11
+ before do
12
+ Adminpanel::User.delete_all
13
+ visit adminpanel.signin_path
14
+ valid_signin_as_admin(user)
15
+ product.category_ids = [category.id]
16
+ photo.product_id = product.id
17
+ visit adminpanel.product_path(product)
18
+ end
19
+
20
+ after do
21
+ Adminpanel::User.delete_all
22
+ end
23
+
24
+ it { page.should have_selector('div', text: product.name) }
25
+ it { page.should have_selector('div', text: product.price) }
26
+ it { page.should have_selector('div', text: product.description) }
27
+ it { should have_content("#{I18n.t("gallery.container")}: #{Adminpanel::Product.display_name}")}
28
+ it { should have_content("#{category.name}")}
29
+ it { should have_link('i', adminpanel.edit_product_path(product)) }
30
+ end