adminpanel 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +6 -3
- data/README.md +6 -26
- data/adminpanel.gemspec +6 -3
- data/app/assets/javascripts/adminpanel/bootstrap-wysihtml5-4pre.js +9579 -0
- data/app/assets/javascripts/adminpanel/bootstrap-wysihtml5.js +9 -9
- data/app/assets/javascripts/adminpanel/realm.js +12 -8
- data/app/assets/javascripts/adminpanel/spinner.js.coffee +11 -0
- data/app/assets/javascripts/adminpanel/wysiwyg.js.coffee +3 -0
- data/app/assets/javascripts/application-admin.js +1 -0
- data/app/assets/stylesheets/adminpanel/{bootstrap.css → bootstrap.css.erb} +2 -2
- data/app/assets/stylesheets/adminpanel/{theme.css → theme.css.erb} +6 -6
- data/app/controllers/adminpanel/analytics_controller.rb +2 -1
- data/app/controllers/adminpanel/application_controller.rb +1 -0
- data/app/controllers/adminpanel/auths_controller.rb +8 -0
- data/app/controllers/adminpanel/categories_controller.rb +1 -1
- data/app/controllers/adminpanel/galleries_controller.rb +3 -11
- data/app/controllers/adminpanel/sections_controller.rb +5 -14
- data/app/controllers/adminpanel/users_controller.rb +1 -1
- data/app/controllers/concerns/adminpanel/facebook_actions.rb +64 -0
- data/app/controllers/concerns/adminpanel/galleryzable_actions.rb +12 -14
- data/app/controllers/concerns/adminpanel/rest_actions.rb +2 -2
- data/app/helpers/adminpanel/adminpanel_form_builder.rb +20 -2
- data/app/helpers/adminpanel/shared_pages_helper.rb +13 -0
- data/app/models/adminpanel/auth.rb +34 -0
- data/app/models/adminpanel/section.rb +1 -2
- data/app/models/adminpanel/user.rb +1 -2
- data/app/models/concerns/adminpanel/base.rb +10 -34
- data/app/models/concerns/adminpanel/facebook.rb +27 -0
- data/app/views/adminpanel/sections/edit.html.erb +0 -5
- data/app/views/adminpanel/sections/index.html.erb +1 -3
- data/app/views/layouts/_side_menu.html.erb +5 -4
- data/app/views/shared/_create_remote_resource_button.html.erb +23 -0
- data/app/views/shared/_fb_icon_button.html.erb +26 -0
- data/app/views/shared/_fb_publish_modal.html.erb +40 -0
- data/app/views/shared/_form_fields.html.erb +6 -50
- data/app/views/shared/_modal.html.erb +1 -1
- data/app/views/shared/create_belongs_to.js.erb +1 -1
- data/app/views/shared/create_has_many.js.erb +1 -1
- data/app/views/shared/fb_choose_page.html.erb +47 -0
- data/app/views/shared/index.html.erb +2 -0
- data/app/views/shared/show.html.erb +2 -0
- data/config/initializers/pluralization_es.rb +3 -0
- data/config/locales/es.yml +69 -60
- data/config/routes.rb +8 -1
- data/lib/adminpanel.rb +1 -0
- data/lib/adminpanel/engine.rb +4 -1
- data/lib/adminpanel/version.rb +1 -1
- data/lib/generators/adminpanel/gallery/gallery_generator.rb +2 -2
- data/lib/generators/adminpanel/initialize/initialize_generator.rb +2 -3
- data/lib/generators/adminpanel/initialize/templates/ability.rb +1 -1
- data/lib/generators/adminpanel/initialize/templates/adminpanel_setup.rb +6 -2
- data/lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb +11 -0
- data/lib/generators/adminpanel/resource/resource_generator.rb +112 -130
- data/lib/generators/adminpanel/resource/templates/controller.rb +4 -1
- data/lib/generators/adminpanel/resource/templates/resource.rb +4 -1
- data/lib/tasks/adminpanel/adminpanel.rake +6 -2
- data/spec/dummy/app/controllers/adminpanel/salesmen_controller.rb +9 -0
- data/spec/dummy/app/models/adminpanel/category.rb +1 -0
- data/spec/dummy/app/models/adminpanel/mug.rb +2 -2
- data/spec/dummy/app/models/adminpanel/product.rb +4 -6
- data/spec/dummy/app/models/adminpanel/salesman.rb +35 -0
- data/spec/dummy/config/initializers/adminpanel_setup.rb +2 -1
- data/spec/dummy/db/schema.rb +13 -0
- data/spec/features/shared_pages/edit_spec.rb +48 -0
- data/spec/features/shared_pages/index_spec.rb +50 -0
- data/spec/features/shared_pages/new_spec.rb +128 -0
- data/spec/features/shared_pages/show_spec.rb +30 -0
- data/spec/generators/gallery_generator_spec.rb +1 -1
- data/spec/generators/resource_generator_spec.rb +36 -11
- data/spec/spec_helper.rb +12 -13
- data/spec/support/capybara_matchers.rb +17 -0
- data/spec/support/factories.rb +1 -1
- data/spec/support/helper_methods.rb +0 -18
- data/spec/support/shared_connection.rb +10 -0
- metadata +100 -21
- data/app/assets/javascripts/adminpanel/bootstrap-wysihtml5-3.min.js +0 -261
- data/app/assets/javascripts/adminpanel/medium-editor.js +0 -703
- data/app/assets/javascripts/adminpanel/wysiwyg.js +0 -5
- data/app/assets/stylesheets/adminpanel/medium-editor.css.scss +0 -1
- data/app/views/shared/_init_editor.html.erb +0 -27
- data/lib/generators/adminpanel/resource/templates/migration.rb +0 -13
- 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(
|
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
|
-
[
|
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)
|
@@ -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
|
-
"
|
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
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -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
|