adminpanel 1.2.9 → 1.2.10
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.
- data/Gemfile +1 -0
- data/adminpanel.gemspec +1 -0
- data/app/controllers/adminpanel/analytics_controller.rb +1 -1
- data/app/controllers/adminpanel/application_controller.rb +6 -6
- data/app/controllers/adminpanel/categories_controller.rb +17 -8
- data/app/controllers/adminpanel/galleries_controller.rb +2 -0
- data/app/controllers/adminpanel/sections_controller.rb +2 -0
- data/app/controllers/adminpanel/sessions_controller.rb +2 -2
- data/app/controllers/adminpanel/users_controller.rb +2 -0
- data/app/helpers/adminpanel/custom_form_builder.rb +24 -0
- data/app/helpers/adminpanel/rest_actions_helper.rb +26 -9
- data/app/helpers/adminpanel/shared_pages_helper.rb +2 -1
- data/app/models/adminpanel/group.rb +6 -0
- data/app/models/adminpanel/user.rb +48 -5
- data/app/views/adminpanel/categories/_categories_table.html.erb +3 -2
- data/app/views/adminpanel/categories/_category_form.html.erb +4 -4
- data/app/views/adminpanel/categories/create.js.erb +2 -1
- data/app/views/adminpanel/categories/index.html.erb +1 -1
- data/app/views/adminpanel/categories/new.js.erb +2 -1
- data/app/views/layouts/_side_menu.html.erb +20 -18
- data/app/views/layouts/_top_bar.html.erb +1 -1
- data/app/views/shared/_form_fields.html.erb +57 -5
- data/app/views/shared/_modal.html.erb +8 -0
- data/app/views/shared/_remote_form_fields.html.erb +12 -0
- data/app/views/shared/create_belongs_to.js.erb +5 -0
- data/app/views/shared/create_has_many.js.erb +5 -0
- data/app/views/shared/edit.html.erb +1 -0
- data/app/views/shared/new.html.erb +15 -4
- data/app/views/shared/new.js.erb +2 -0
- data/config/locales/es.yml +5 -3
- data/lib/adminpanel.rb +1 -0
- data/lib/adminpanel/active_record/adminpanel_extension.rb +0 -4
- data/lib/adminpanel/version.rb +1 -1
- data/lib/generators/adminpanel/initialize/initialize_generator.rb +11 -0
- data/lib/generators/adminpanel/initialize/templates/ability.rb +31 -0
- data/lib/generators/adminpanel/initialize/templates/adminpanel_setup.rb +7 -7
- data/lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb +9 -1
- data/lib/tasks/adminpanel/adminpanel.rake +2 -1
- data/spec/dummy/app/models/ability.rb +31 -0
- data/spec/dummy/app/models/adminpanel/category.rb +4 -1
- data/spec/features/authentication_pages_spec.rb +6 -5
- data/spec/features/galleries_pages_spec.rb +3 -1
- data/spec/features/section_pages_spec.rb +2 -1
- data/spec/features/shared_pages_spec.rb +66 -22
- data/spec/generators/gallery_generator_spec.rb +3 -3
- data/spec/generators/resource_generator_spec.rb +3 -3
- data/spec/models/gallery_spec.rb +3 -1
- data/spec/models/section_spec.rb +12 -11
- data/spec/models/user_spec.rb +6 -2
- data/spec/spec_helper.rb +5 -2
- data/spec/support/define_factory_models.rb +6 -0
- data/spec/support/helper_methods.rb +2 -1
- data/spec/support/test_database.rb +7 -0
- data/spec/tasks/adminpanel_rake_spec.rb +1 -0
- metadata +53 -32
- data/spec/dummy/app/controllers/adminpanel/categories_controller.rb +0 -4
- data/spec/models/product_spec.rb +0 -39
data/Gemfile
CHANGED
data/adminpanel.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency "bcrypt-ruby", "~> 3.0.0"
|
27
27
|
spec.add_dependency "rails-i18n", "~> 3.0.0"
|
28
28
|
spec.add_dependency "inherited_resources", "~> 1.3.1"
|
29
|
+
spec.add_dependency "cancan", "~> 1.6.10"
|
29
30
|
spec.add_dependency "google-api-client", "~> 0.7.1"
|
30
31
|
|
31
32
|
spec.add_development_dependency "bundler", "~> 1.3"
|
@@ -7,13 +7,17 @@ module Adminpanel
|
|
7
7
|
include SessionsHelper
|
8
8
|
include RestActionsHelper
|
9
9
|
|
10
|
-
layout
|
10
|
+
layout 'admin'
|
11
11
|
|
12
12
|
before_filter :signed_in_user, :set_model
|
13
13
|
|
14
|
+
rescue_from CanCan::AccessDenied do |exception|
|
15
|
+
sign_out
|
16
|
+
redirect_to signin_path, :alert => I18n.t('authentication.not_authorized')
|
17
|
+
end
|
14
18
|
|
15
19
|
def signed_in_user
|
16
|
-
redirect_to signin_url, :notice => "
|
20
|
+
redirect_to signin_url, :notice => I18n.t("authentication.welcome") unless signed_in?
|
17
21
|
end
|
18
22
|
|
19
23
|
def set_model
|
@@ -24,9 +28,5 @@ module Adminpanel
|
|
24
28
|
sign_out
|
25
29
|
super
|
26
30
|
end
|
27
|
-
|
28
|
-
# def get_menu_elements
|
29
|
-
# @menu_items = menu_items
|
30
|
-
# end
|
31
31
|
end
|
32
32
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Adminpanel
|
2
2
|
class CategoriesController < ApplicationController
|
3
|
+
load_and_authorize_resource
|
4
|
+
|
3
5
|
def index
|
4
6
|
@categories = Category.all
|
5
7
|
end
|
@@ -8,30 +10,37 @@ module Adminpanel
|
|
8
10
|
set_collections
|
9
11
|
new! do |format|
|
10
12
|
format.html { render "shared/new" }
|
11
|
-
format.js
|
13
|
+
format.js do
|
14
|
+
render :locals => {:resource => resource}
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
19
|
|
16
20
|
def create
|
21
|
+
params.merge({:model_name => params[:model_name]}) if params[:model_name].present?
|
22
|
+
params.merge({:model => params[:model]}) if params[:model].present?
|
23
|
+
params.merge({:currentcontroller => params[:currentcontroller]}) if params[:currentcontroller].present?
|
24
|
+
|
17
25
|
create! do |success, failure|
|
18
26
|
success.html do
|
19
|
-
flash
|
20
|
-
# render "shared/index"
|
27
|
+
flash[:success] = I18n.t("action.save_success")
|
21
28
|
redirect_to categories_path
|
22
29
|
end
|
23
30
|
failure.html do
|
24
31
|
set_collections
|
25
32
|
render "shared/new"
|
26
33
|
end
|
27
|
-
|
28
34
|
success.js do
|
29
|
-
|
30
|
-
|
35
|
+
if params[:currentcontroller] == 'adminpanel/categories'
|
36
|
+
render 'create', :locals => {:category => resource}
|
37
|
+
else
|
38
|
+
render 'shared/create_has_many', :locals => {:resource => resource}
|
39
|
+
end
|
31
40
|
end
|
32
41
|
failure.js do
|
33
42
|
set_collections
|
34
|
-
render "new", :locals => {:
|
43
|
+
render "new", :locals => {:resource => resource }
|
35
44
|
|
36
45
|
end
|
37
46
|
end
|
@@ -49,7 +58,7 @@ module Adminpanel
|
|
49
58
|
def update
|
50
59
|
update! do |success, failure|
|
51
60
|
success.html do
|
52
|
-
flash
|
61
|
+
flash[:success] = I18n.t("action.save_success")
|
53
62
|
# render "shared/index"
|
54
63
|
redirect_to categories_path
|
55
64
|
end
|
@@ -15,10 +15,10 @@ module Adminpanel
|
|
15
15
|
user = User.find_by_email(params[:session][:email].downcase)
|
16
16
|
if user && user.authenticate(params[:session][:password])
|
17
17
|
sign_in user
|
18
|
-
flash[:success] = I18n.t("authentication.
|
18
|
+
flash[:success] = I18n.t("authentication.signin_success")
|
19
19
|
redirect_to root_url
|
20
20
|
else
|
21
|
-
flash.now[:error] = I18n.t("authentication.
|
21
|
+
flash.now[:error] = I18n.t("authentication.signin_error")
|
22
22
|
render 'new'
|
23
23
|
end
|
24
24
|
end
|
@@ -123,6 +123,30 @@ module Adminpanel
|
|
123
123
|
)
|
124
124
|
end
|
125
125
|
|
126
|
+
def boolean(name, *args)
|
127
|
+
options = args.extract_options!
|
128
|
+
|
129
|
+
@template.content_tag(
|
130
|
+
:div,
|
131
|
+
@template.content_tag(
|
132
|
+
:div,
|
133
|
+
options['label'],
|
134
|
+
:class => 'control-label') +
|
135
|
+
@template.content_tag(
|
136
|
+
:div,
|
137
|
+
@template.content_tag(
|
138
|
+
:label,
|
139
|
+
check_box(
|
140
|
+
name
|
141
|
+
),
|
142
|
+
:class => 'checkbox'
|
143
|
+
),
|
144
|
+
:class => 'controls'
|
145
|
+
),
|
146
|
+
:class => 'control-group'
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
126
150
|
def select(name, select_options, *args)
|
127
151
|
options = args.extract_options!
|
128
152
|
|
@@ -16,22 +16,39 @@ module Adminpanel
|
|
16
16
|
set_collections
|
17
17
|
new! do |format|
|
18
18
|
format.html { render "shared/new" }
|
19
|
+
format.js { render 'shared/new', :locals => { :resource => resource }}
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
23
|
def create
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
params.merge({:model => params[:model]}) if params[:model].present?
|
25
|
+
params.merge({:model_name => params[:model_name]}) if params[:model_name].present?
|
26
|
+
params.merge({:belongs_request => params[:belongs_request]}) if params[:belongs_request].present?
|
27
|
+
create! do |success, failure|
|
28
|
+
success.html do
|
29
|
+
flash[:success] = I18n.t("action.save_success")
|
30
|
+
redirect_to resource
|
31
|
+
end
|
32
|
+
failure.html do
|
29
33
|
set_collections
|
30
|
-
|
34
|
+
render "shared/new"
|
31
35
|
end
|
32
|
-
|
36
|
+
success.js do
|
37
|
+
flash.now[:success] = I18n.t("action.save_success")
|
38
|
+
if params[:belongs_request]
|
39
|
+
render 'shared/create_belongs_to', :locals => {:resource => resource }
|
40
|
+
else
|
41
|
+
render 'shared/create_has_many', :locals => {:resource => resource }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
failure.js do
|
45
|
+
set_collections
|
46
|
+
render 'shared/new', :locals => {:resource => resource }
|
47
|
+
end
|
48
|
+
end
|
33
49
|
end
|
34
50
|
|
51
|
+
|
35
52
|
def edit
|
36
53
|
edit! do |format|
|
37
54
|
format.html do
|
@@ -44,7 +61,7 @@ module Adminpanel
|
|
44
61
|
def update
|
45
62
|
update! do |success, failure|
|
46
63
|
success.html do
|
47
|
-
flash
|
64
|
+
flash[:success] = I18n.t("action.save_success")
|
48
65
|
render "shared/index"
|
49
66
|
end
|
50
67
|
failure.html do
|
@@ -5,8 +5,9 @@ module Adminpanel
|
|
5
5
|
if association.klass.to_s == parent_model
|
6
6
|
if !resource.send(association.name).nil?
|
7
7
|
return resource.send(association.name).name
|
8
|
+
# return resource.client
|
8
9
|
else
|
9
|
-
return "N/A"
|
10
|
+
return "N/A #{association.klass.to_s}"
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module Adminpanel
|
2
2
|
class User < ActiveRecord::Base
|
3
|
-
attr_accessible :email, :name, :password, :password_confirmation
|
3
|
+
attr_accessible :email, :name, :password, :password_confirmation, :group_id
|
4
4
|
has_secure_password
|
5
|
+
belongs_to :group
|
6
|
+
|
7
|
+
#group validation
|
8
|
+
validates_presence_of :group_id
|
5
9
|
|
6
10
|
#name validations
|
7
11
|
validates_presence_of :name
|
@@ -30,10 +34,49 @@ module Adminpanel
|
|
30
34
|
|
31
35
|
def self.form_attributes
|
32
36
|
[
|
33
|
-
{
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
{
|
38
|
+
'name' => {
|
39
|
+
'type' => 'text_field',
|
40
|
+
'name' => 'Nombre',
|
41
|
+
'label' => 'Nombre',
|
42
|
+
'placeholder' => 'Nombre'
|
43
|
+
}
|
44
|
+
},
|
45
|
+
{
|
46
|
+
'email' => {
|
47
|
+
'type' => 'text_field',
|
48
|
+
'name' => 'Correo',
|
49
|
+
'label' => 'Correo',
|
50
|
+
'placeholder' => 'Correo'
|
51
|
+
}
|
52
|
+
},
|
53
|
+
{
|
54
|
+
'password' => {
|
55
|
+
'type' => 'password_field',
|
56
|
+
'name' => 'Contrasena',
|
57
|
+
'label' => I18n.t('model.attributes.password'),
|
58
|
+
'placeholder' => I18n.t('model.attributes.password'),
|
59
|
+
'show' => 'false'
|
60
|
+
}
|
61
|
+
},
|
62
|
+
{
|
63
|
+
'password_confirmation' => {
|
64
|
+
'type' => 'password_field',
|
65
|
+
'name' => 'Confirmacion de contrasena',
|
66
|
+
'placeholder' => I18n.t('model.attributes.password_confirmation'),
|
67
|
+
'label' => I18n.t('model.attributes.password_confirmation'),
|
68
|
+
'show' => 'false'
|
69
|
+
}
|
70
|
+
},
|
71
|
+
{
|
72
|
+
'group_id' => {
|
73
|
+
'type' => 'belongs_to',
|
74
|
+
'model' => 'Adminpanel::Group',
|
75
|
+
'remote_resource' => false,
|
76
|
+
'placeholder' => I18n.t('model.attributes.group_id'),
|
77
|
+
'label' => I18n.t('model.attributes.group_id')
|
78
|
+
}
|
79
|
+
},
|
37
80
|
]
|
38
81
|
end
|
39
82
|
|
@@ -15,9 +15,10 @@
|
|
15
15
|
{
|
16
16
|
:controller => params[:controller],
|
17
17
|
:action => "new",
|
18
|
-
|
18
|
+
:"model" => model,
|
19
|
+
:currentcontroller => params[:controller]
|
19
20
|
},
|
20
|
-
:"data-target" => '#
|
21
|
+
:"data-target" => '#new-category',
|
21
22
|
:"data-toggle" => 'modal',
|
22
23
|
:remote => true
|
23
24
|
)
|
@@ -1,13 +1,13 @@
|
|
1
|
-
<%= custom_form_for(resource, :remote => true, :html => {:class => "form-horizontal", :id => "
|
1
|
+
<%= custom_form_for(resource, :url => {:action => :create, :model => params[:model], :model_name => params[:model_name], :currentcontroller => params[:currentcontroller]}, :remote => true, :html => {:class => "form-horizontal", :id => "new-category-form"}) do |f| -%>
|
2
2
|
<div class="row-fluid">
|
3
3
|
<div class="modal-body">
|
4
4
|
<%= render 'shared/error_messages', :object => resource %>
|
5
|
-
<%= render 'shared/form_fields', :f => f %>
|
6
|
-
<%= f.hidden_field :model, :value => model %>
|
5
|
+
<%= render 'shared/form_fields', :f => f, :remote_request => true %>
|
6
|
+
<%= f.hidden_field :model, :value => params[:model] %>
|
7
7
|
</div>
|
8
8
|
</div>
|
9
9
|
<div class="modal-footer">
|
10
10
|
<button id="modal-button" class="btn" data-dismiss="modal" aria-hidden="true"><%= I18n.t('action.close') %></button>
|
11
|
-
<%= f.submit t("action.add") + " " + @model.display_name, :disable_with => t("action.submitting"), :id =>"new-
|
11
|
+
<%= f.submit t("action.add") + " " + @model.display_name, :disable_with => t("action.submitting"), :id =>"new-#{@model.name.demodulize}-button" %>
|
12
12
|
</div>
|
13
13
|
<% end -%>
|
@@ -1,4 +1,5 @@
|
|
1
|
-
$("#modal-button").trigger("click");
|
1
|
+
// $("#modal-button").trigger("click");
|
2
|
+
$('#new-category').modal('toggle');
|
2
3
|
row = "<tr><td><%= escape_javascript link_to resource.name, category_path(resource) %></td>";
|
3
4
|
row = row + "<td><%= escape_javascript link_to content_tag(:i, nil, :class => 'icon-pencil'), edit_category_path(category), :title => 'Editar' %> ";
|
4
5
|
row = row + "<%= escape_javascript link_to content_tag(:i, nil, :class => 'icon-remove'),[category], :title => 'Editar', :method => :delete %></td>";
|
@@ -46,7 +46,7 @@
|
|
46
46
|
</div>
|
47
47
|
|
48
48
|
<!-- example modal -->
|
49
|
-
<div id="
|
49
|
+
<div id="new-category" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
50
50
|
<div class="modal-header" id="modal-header">
|
51
51
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
52
52
|
<h3 id="myModalLabel">Crear Categoría</h3>
|
@@ -1 +1,2 @@
|
|
1
|
-
$("#modal-
|
1
|
+
$("#modal-title").html('Agregar <%= @model.display_name %>');
|
2
|
+
$("#modal-container").html('<%= escape_javascript(render "category_form", :resource => resource) %>');
|
@@ -2,34 +2,36 @@
|
|
2
2
|
<div class="sidebar-nav nav-collapse collapse" id="sidebar-navigation">
|
3
3
|
<div class="user_side clearfix">
|
4
4
|
<h5>
|
5
|
-
<%=
|
5
|
+
<%= current_user.name.humanize %>
|
6
6
|
</h5>
|
7
7
|
<%=
|
8
8
|
link_to(
|
9
|
-
|
10
|
-
|
9
|
+
"#{current_user.group.name}",
|
10
|
+
"#"
|
11
11
|
)
|
12
12
|
%>
|
13
13
|
</div>
|
14
14
|
<div class="accordion" id="accordion2">
|
15
15
|
<% Adminpanel.displayable_resources.each do |resource| %>
|
16
16
|
<% resource_class = symbol_class(resource) %>
|
17
|
-
|
18
|
-
<div class="accordion-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
<% if can? :read, resource_class %>
|
18
|
+
<div class="accordion-group">
|
19
|
+
<div class="accordion-heading">
|
20
|
+
<%=
|
21
|
+
link_to(
|
22
|
+
content_tag(
|
23
|
+
:i,
|
24
|
+
nil,
|
25
|
+
:class => resource_class.icon) +
|
26
|
+
content_tag(:span," #{resource_class.display_name}"),
|
27
|
+
[route_symbol(resource.to_s)],
|
28
|
+
:class => "accordion-toggle b_99FFCC
|
29
|
+
#{is_current_section?(resource_class.display_name)}"
|
30
|
+
)
|
31
|
+
%>
|
32
|
+
</div>
|
31
33
|
</div>
|
32
|
-
|
34
|
+
<% end %>
|
33
35
|
<% end %>
|
34
36
|
|
35
37
|
</div>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="navbar-inner">
|
3
3
|
<div class="container-fluid">
|
4
4
|
<div class="logo">
|
5
|
-
<%= link_to image_tag("adminpanel/codn.png", :alt => "logo"), main_root_path %>
|
5
|
+
<%= link_to image_tag("adminpanel/codn.png", :alt => "logo"), main_root_path, :target => '_blank' %>
|
6
6
|
</div>
|
7
7
|
<% if signed_in? %>
|
8
8
|
<a class="btn btn-navbar visible-phone" data-toggle="collapse" data-target=".nav-collapse">
|