adminpanel 1.2.4 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/stylesheets/adminpanel/theme.css +46 -41
- data/app/controllers/adminpanel/categories_controller.rb +71 -0
- data/app/controllers/adminpanel/users_controller.rb +69 -69
- data/app/helpers/adminpanel/application_helper.rb +2 -1
- data/app/helpers/adminpanel/class_definitions_helper.rb +10 -0
- data/app/helpers/adminpanel/custom_form_builder.rb +23 -24
- data/app/helpers/adminpanel/pluralizations_helper.rb +21 -0
- data/app/helpers/adminpanel/rest_actions_helper.rb +42 -34
- data/app/helpers/adminpanel/router_helper.rb +30 -26
- data/app/models/adminpanel/gallery.rb +6 -2
- data/app/models/adminpanel/image.rb +1 -1
- data/app/models/adminpanel/user.rb +15 -1
- data/app/views/adminpanel/categories/_categories_table.html.erb +48 -0
- data/app/views/adminpanel/categories/_category_form.html.erb +14 -0
- data/app/views/adminpanel/categories/index.html.erb +55 -0
- data/app/views/adminpanel/categories/new.js.erb +1 -0
- data/app/views/layouts/_side_menu.html.erb +91 -22
- data/app/views/shared/_error_messages.html.erb +3 -3
- data/app/views/shared/_form_fields.html.erb +14 -13
- data/app/views/shared/index.html.erb +1 -1
- data/config/locales/es.yml +5 -10
- data/config/routes.rb +20 -9
- data/lib/adminpanel/active_record_extension.rb +52 -8
- data/lib/adminpanel/engine.rb +4 -2
- data/lib/adminpanel/version.rb +1 -1
- data/lib/generators/adminpanel/initialize/initialize_generator.rb +20 -6
- data/lib/generators/adminpanel/initialize/templates/adminpanel_setup.rb +16 -0
- data/lib/generators/adminpanel/initialize/templates/category_template.rb +32 -0
- data/lib/generators/adminpanel/initialize/templates/create_adminpanel_categories_table.rb +11 -0
- data/lib/generators/adminpanel/resource/resource_generator.rb +1 -1
- data/lib/tasks/adminpanel/adminpanel.rake +4 -4
- data/spec/dummy/app/controllers/adminpanel/categories_controller.rb +1 -1
- data/spec/dummy/app/models/adminpanel/categorization.rb +5 -5
- data/spec/dummy/app/models/adminpanel/category.rb +9 -9
- data/spec/generators/initialize_generator_spec.rb +34 -0
- data/spec/generators/{resource_spec.rb → resource_generator_spec.rb} +0 -0
- data/spec/models/user_spec.rb +3 -3
- metadata +18 -19
- data/app/helpers/adminpanel/images_helper.rb +0 -10
- data/app/views/adminpanel/users/_user_form.html.erb +0 -21
- data/app/views/adminpanel/users/edit.html.erb +0 -6
- data/app/views/adminpanel/users/index.html.erb +0 -49
- data/app/views/adminpanel/users/new.html.erb +0 -6
- data/app/views/adminpanel/users/show.html.erb +0 -21
- data/config/locales/en.yml +0 -5
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/features/user_pages_spec.rb +0 -48
- data/spec/generators/initialize_spec.rb +0 -9
@@ -3,6 +3,7 @@ module Adminpanel
|
|
3
3
|
include SessionsHelper
|
4
4
|
include BreadcrumbsHelper
|
5
5
|
include SharedPagesHelper
|
6
|
+
include PluralizationsHelper
|
6
7
|
|
7
8
|
def custom_form_for(name, *args, &block)
|
8
9
|
options = args.extract_options!
|
@@ -52,4 +53,4 @@ module Adminpanel
|
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
55
|
-
end
|
56
|
+
end
|
@@ -9,9 +9,8 @@ module Adminpanel
|
|
9
9
|
options = args.extract_options!
|
10
10
|
|
11
11
|
options.reverse_merge! :class => "span7"
|
12
|
-
|
13
|
-
|
14
|
-
options.delete(:label)
|
12
|
+
label = options['label']
|
13
|
+
options.delete('label')
|
15
14
|
|
16
15
|
@template.content_tag :div, :class => "control-group" do
|
17
16
|
@template.content_tag(:label, label, :class => "control-label") +
|
@@ -43,15 +42,15 @@ module Adminpanel
|
|
43
42
|
@template.content_tag(:div, :class => "controls") do
|
44
43
|
if self.object.send(name).nil?
|
45
44
|
@template.content_tag(
|
46
|
-
:div,
|
47
|
-
self.object.send(name),
|
45
|
+
:div,
|
46
|
+
self.object.send(name),
|
48
47
|
:id => name,
|
49
48
|
"data-placeholder" => I18n.t("Write description here")
|
50
49
|
)
|
51
50
|
else
|
52
51
|
@template.content_tag(
|
53
|
-
:div,
|
54
|
-
self.object.send(name).html_safe,
|
52
|
+
:div,
|
53
|
+
self.object.send(name).html_safe,
|
55
54
|
:id => name,
|
56
55
|
"data-placeholder" => I18n.t("Write description here")
|
57
56
|
)
|
@@ -78,12 +77,12 @@ module Adminpanel
|
|
78
77
|
|
79
78
|
def checkbox(checkbox_object, form_object_name, relationship)
|
80
79
|
@template.content_tag(
|
81
|
-
:label,
|
80
|
+
:label,
|
82
81
|
@template.check_box_tag(
|
83
|
-
"#{form_object_name}[#{relationship}][]",
|
84
|
-
checkbox_object.id,
|
82
|
+
"#{form_object_name}[#{relationship}][]",
|
83
|
+
checkbox_object.id,
|
85
84
|
self.object.send(relationship).include?(checkbox_object.id)
|
86
|
-
) + checkbox_object.name,
|
85
|
+
) + checkbox_object.name,
|
87
86
|
:class => "checkbox"
|
88
87
|
)
|
89
88
|
end
|
@@ -92,7 +91,7 @@ module Adminpanel
|
|
92
91
|
options = args.extract_options!
|
93
92
|
|
94
93
|
options.reverse_merge! :class => "span7"
|
95
|
-
options.reverse_merge! :label => name
|
94
|
+
# options.reverse_merge! :label => name
|
96
95
|
options.reverse_merge! :include_blank => "(Seleccione por favor)";
|
97
96
|
label = options[:label]
|
98
97
|
options.delete(:label)
|
@@ -121,9 +120,9 @@ module Adminpanel
|
|
121
120
|
options = args.extract_options!
|
122
121
|
|
123
122
|
options.reverse_merge! :class => "span7"
|
124
|
-
options.reverse_merge! :label => name
|
125
|
-
label = options[
|
126
|
-
options.delete(
|
123
|
+
# options.reverse_merge! :label => name
|
124
|
+
label = options['label']
|
125
|
+
options.delete('label')
|
127
126
|
|
128
127
|
@template.content_tag :div, :class => "control-group" do
|
129
128
|
@template.content_tag(:label, label, :class => "control-label") +
|
@@ -165,10 +164,10 @@ module Adminpanel
|
|
165
164
|
@template.content_tag :div, :class => "control-group" do
|
166
165
|
@template.content_tag(:label, label, :class => "control-label") +
|
167
166
|
@template.content_tag(
|
168
|
-
:div,
|
167
|
+
:div,
|
169
168
|
@template.content_tag(
|
170
169
|
:div,
|
171
|
-
text_field_original(name, *args << options) +
|
170
|
+
text_field_original(name, *args << options) +
|
172
171
|
@template.content_tag(
|
173
172
|
:span,
|
174
173
|
@template.content_tag(
|
@@ -176,7 +175,7 @@ module Adminpanel
|
|
176
175
|
nil,
|
177
176
|
:class => "icon-th"
|
178
177
|
),
|
179
|
-
:class => "add-on"
|
178
|
+
:class => "add-on"
|
180
179
|
),
|
181
180
|
{
|
182
181
|
:class => "input-append date span5 datepicker datepicker-basic",
|
@@ -185,7 +184,7 @@ module Adminpanel
|
|
185
184
|
:date => options[:value]
|
186
185
|
}
|
187
186
|
}
|
188
|
-
),
|
187
|
+
),
|
189
188
|
:class => "controls"
|
190
189
|
)
|
191
190
|
end
|
@@ -211,8 +210,8 @@ module Adminpanel
|
|
211
210
|
:div,
|
212
211
|
@template.content_tag(:span, symbol, :class => "add-on") +
|
213
212
|
text_field_original(name, *args << options),
|
214
|
-
:class => "input-prepend"
|
215
|
-
),
|
213
|
+
:class => "input-prepend"
|
214
|
+
),
|
216
215
|
:class => "controls"
|
217
216
|
)
|
218
217
|
end
|
@@ -238,11 +237,11 @@ module Adminpanel
|
|
238
237
|
:div,
|
239
238
|
text_field_original(name, *args << options) +
|
240
239
|
@template.content_tag(:span, symbol, :class => "add-on"),
|
241
|
-
:class => "input-append"
|
242
|
-
),
|
240
|
+
:class => "input-append"
|
241
|
+
),
|
243
242
|
:class => "controls"
|
244
243
|
)
|
245
244
|
end
|
246
245
|
end
|
247
246
|
end
|
248
|
-
end
|
247
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Adminpanel
|
2
|
+
module PluralizationsHelper
|
3
|
+
|
4
|
+
def pluralize_es(string)
|
5
|
+
pluralized_string = ""
|
6
|
+
string.split.each do |word|
|
7
|
+
case(word.last)
|
8
|
+
when 'a', 'e', 'i', 'o', 'u', 'c'
|
9
|
+
pluralized_string = "#{pluralized_string}#{word}s "
|
10
|
+
when 'b', 'r'
|
11
|
+
pluralized_string = "#{pluralized_string}#{word}es "
|
12
|
+
when 'z'
|
13
|
+
pluralized_string = "#{pluralized_string}#{word.chop}ces "
|
14
|
+
else
|
15
|
+
pluralized_string = "#{pluralized_string}#{word} "
|
16
|
+
end
|
17
|
+
end
|
18
|
+
pluralized_string.chop
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Adminpanel
|
2
2
|
module RestActionsHelper
|
3
3
|
def index
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
index! do |format|
|
5
|
+
format.html { render "shared/index" }
|
6
|
+
end
|
7
7
|
end
|
8
8
|
|
9
9
|
def show
|
@@ -14,44 +14,44 @@ module Adminpanel
|
|
14
14
|
|
15
15
|
def new
|
16
16
|
set_collections
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
new! do |format|
|
18
|
+
format.html { render "shared/new" }
|
19
|
+
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def create
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
create! do |success, failure|
|
24
|
+
success.html do
|
25
|
+
flash.now[:success] = I18n.t("action.save_success")
|
26
|
+
render "shared/index"
|
27
|
+
end
|
28
|
+
failure.html do
|
29
29
|
set_collections
|
30
|
-
|
30
|
+
render "shared/new"
|
31
31
|
end
|
32
|
-
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def edit
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
edit! do |format|
|
37
|
+
format.html do
|
38
|
+
set_collections
|
39
|
+
render "shared/edit"
|
40
|
+
end
|
41
|
+
end
|
42
42
|
end
|
43
43
|
|
44
44
|
def update
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
update! do |success, failure|
|
46
|
+
success.html do
|
47
|
+
flash.now[:success] = I18n.t("action.save_success")
|
48
|
+
render "shared/index"
|
49
|
+
end
|
50
|
+
failure.html do
|
51
|
+
set_collections
|
52
|
+
render "shared/edit"
|
53
|
+
end
|
54
|
+
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def destroy
|
@@ -64,12 +64,20 @@ module Adminpanel
|
|
64
64
|
|
65
65
|
def set_collections
|
66
66
|
@collections = {}
|
67
|
-
|
68
|
-
@collections.merge!({"#{class_variable}" => class_variable.find(:all)})
|
69
|
-
end
|
67
|
+
set_belongs_to_collections
|
70
68
|
@model.has_many_relationships.each do |class_variable|
|
71
69
|
@collections.merge!({"#{class_variable}" => class_variable.find(:all)})
|
72
70
|
end
|
73
71
|
end
|
72
|
+
|
73
|
+
def set_belongs_to_collections
|
74
|
+
@model.belongs_to_relationships.each do |class_variable|
|
75
|
+
if class_variable.respond_to?("of_model")
|
76
|
+
@collections.merge!({"#{class_variable}" => class_variable.of_model(@model.display_name)})
|
77
|
+
else
|
78
|
+
@collections.merge!({"#{class_variable}" => class_variable.find(:all)})
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
74
82
|
end
|
75
|
-
end
|
83
|
+
end
|
@@ -1,33 +1,37 @@
|
|
1
1
|
module Adminpanel
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def find_resources
|
8
|
-
resources_path
|
9
|
-
if File.directory?(resources_path)
|
10
|
-
files = Dir.entries(resources_path).collect do |f|
|
11
|
-
unless default_controllers.include?(f)
|
12
|
-
file_path = "#{resources_path}#{f}"
|
13
|
-
File.file?(file_path) ? file_path.sub!(resources_path, '').sub!('_controller.rb', '') : nil
|
14
|
-
end
|
15
|
-
end
|
2
|
+
module RouterHelper
|
3
|
+
def adminpanel_resources
|
4
|
+
@files ||= find_resources
|
5
|
+
end
|
16
6
|
|
17
|
-
|
18
|
-
|
7
|
+
def find_resources
|
8
|
+
resources_path
|
9
|
+
if File.directory?(resources_path)
|
10
|
+
files = Dir.entries(resources_path).collect do |f|
|
11
|
+
unless default_controllers.include?(f)
|
12
|
+
file_path = "#{resources_path}#{f}"
|
13
|
+
File.file?(file_path) ? file_path.sub!(resources_path, '').sub!('_controller.rb', '') : nil
|
14
|
+
end
|
19
15
|
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
files.compact!
|
18
|
+
end
|
19
|
+
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
def menu_items
|
22
|
+
@menu ||= adminpanel_resources.each.collect { |resource| resource.classify }
|
23
|
+
end
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
def default_controllers
|
26
|
+
["application_controller.rb", "sessions_controller.rb", "galleries_controller.rb", "users_controller.rb", "sections_controller.rb", "pages_controller.rb"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def resources_path
|
30
|
+
route = "#{Rails.root.to_s}/app/controllers/adminpanel/"
|
31
|
+
if !File.directory?(route)
|
32
|
+
Dir.mkdir(route)
|
33
|
+
end
|
34
|
+
route
|
32
35
|
end
|
33
|
-
end
|
36
|
+
end
|
37
|
+
end
|
@@ -40,6 +40,10 @@ module Adminpanel
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
def self.display_name
|
44
|
+
"Galería"
|
45
|
+
end
|
46
|
+
|
43
47
|
private
|
44
48
|
def rearrange_positions
|
45
49
|
unarranged_galleries = Gallery.where("position > ?", position)
|
@@ -48,7 +52,7 @@ module Adminpanel
|
|
48
52
|
end
|
49
53
|
|
50
54
|
end
|
51
|
-
|
55
|
+
|
52
56
|
def set_position
|
53
57
|
last_record = Gallery.last
|
54
58
|
if last_record.nil?
|
@@ -58,4 +62,4 @@ module Adminpanel
|
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
61
|
-
end
|
65
|
+
end
|
@@ -28,9 +28,23 @@ module Adminpanel
|
|
28
28
|
roles.any? { |r| r.name.underscore.to_sym == role_sym }
|
29
29
|
end
|
30
30
|
|
31
|
+
def self.form_attributes
|
32
|
+
[
|
33
|
+
{"name" => {"type" => "text_field", "name" => "Nombre", 'label' => "Nombre", "placeholder" => "Nombre"}},
|
34
|
+
{"email" => {"type" => "text_field", "name" => "Correo", 'label' => 'Correo', 'placeholder' => 'Correo'}},
|
35
|
+
{"password" => {"type" => "password_field", "name" => "Contrasena", 'label' => I18n.t('model.attributes.password'), "placeholder" => I18n.t('model.attributes.password'), 'show' => 'false'}},
|
36
|
+
{"password_confirmation" => {"type" => "password_field", "name" => "Confirmacion de contrasena", 'placeholder' => I18n.t('model.attributes.password_confirmation'), 'label' => I18n.t('model.attributes.password_confirmation'), 'show' => 'false'}},
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.display_name
|
41
|
+
"Usuario"
|
42
|
+
|
43
|
+
end
|
44
|
+
|
31
45
|
private
|
32
46
|
def create_remember_token
|
33
47
|
self.remember_token = SecureRandom.base64.tr("+/", "-_")
|
34
48
|
end
|
35
49
|
end
|
36
|
-
end
|
50
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<div class="row-fluid">
|
2
|
+
<%=
|
3
|
+
link_to(
|
4
|
+
content_tag(:div,
|
5
|
+
content_tag(
|
6
|
+
:i,
|
7
|
+
nil,
|
8
|
+
:class => 'icon-plus-sign icon-2x') +
|
9
|
+
content_tag(
|
10
|
+
:span,
|
11
|
+
I18n.t("action.create") + " #{@model.display_name} de #{model}",
|
12
|
+
nil
|
13
|
+
),
|
14
|
+
:class => "btn btn-box span2"),
|
15
|
+
{
|
16
|
+
:controller => params[:controller],
|
17
|
+
:action => "new",
|
18
|
+
:"model" => model
|
19
|
+
},
|
20
|
+
:"data-target" => '#example_modal',
|
21
|
+
:"data-toggle" => 'modal',
|
22
|
+
:remote => true
|
23
|
+
)
|
24
|
+
%>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<br/>
|
28
|
+
|
29
|
+
<table class="table table-striped table-bordered">
|
30
|
+
<tr>
|
31
|
+
<th><%= t("category.name") %></th>
|
32
|
+
<th><%= t("actions") %></th>
|
33
|
+
</tr>
|
34
|
+
<% categories.each do |category| %>
|
35
|
+
<tr>
|
36
|
+
<td><%= link_to category.name, category_path(category) %></td>
|
37
|
+
<td>
|
38
|
+
<%= link_to content_tag(:i, nil, :class => 'icon-pencil'), edit_category_path(category), :title => "Editar" %>
|
39
|
+
<%= link_to content_tag(:i, nil, :class => 'icon-remove'),
|
40
|
+
[category],
|
41
|
+
:title => "Editar",
|
42
|
+
:method => :delete,
|
43
|
+
:data => { :confirm => "Eliminar #{category.name}?"} %>
|
44
|
+
</td>
|
45
|
+
</tr>
|
46
|
+
<% end %>
|
47
|
+
|
48
|
+
</table>
|