adminpanel 1.1.0 → 1.2.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.
- data/Gemfile +1 -1
- data/app/models/adminpanel/image.rb +2 -2
- data/app/views/shared/_error_messages.html.erb +2 -2
- data/app/views/shared/index.html.erb +24 -24
- data/config/locales/es.yml +25 -74
- data/lib/adminpanel/version.rb +1 -1
- data/lib/generators/adminpanel/resource/resource_generator.rb +83 -64
- data/lib/generators/adminpanel/resource/templates/controller.rb +3 -3
- data/lib/generators/adminpanel/resource/templates/migration.rb +7 -3
- data/lib/generators/adminpanel/resource/templates/resource.rb +15 -15
- data/lib/tasks/adminpanel/populate.rake +80 -0
- data/spec/dummy/log/test.log +10559 -0
- data/spec/generators/resource_spec.rb +22 -25
- metadata +5 -8
- data/spec/dummy/public/uploads/gallery/file/1/hipster.jpg +0 -0
- data/spec/dummy/public/uploads/gallery/file/1/thumb_hipster.jpg +0 -0
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Adminpanel
|
2
2
|
class Image < ActiveRecord::Base
|
3
3
|
extend ImagesHelper
|
4
|
-
|
4
|
+
|
5
5
|
attr_accessible :file, :foreign_key, :model
|
6
6
|
validates_presence_of :model
|
7
7
|
validates_presence_of :file
|
@@ -12,4 +12,4 @@ module Adminpanel
|
|
12
12
|
mount_uploader :file, Adminpanel::ImageUploader
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<% object.errors.messages.keys.each do |field| %>
|
7
7
|
<% object.errors.messages[field].each do |value| %>
|
8
8
|
<li>
|
9
|
-
<%= t("model.attributes.#{
|
9
|
+
<%= t("model.attributes.#{field}") %>
|
10
10
|
<%= value %>
|
11
11
|
</li>
|
12
12
|
<% end %>
|
@@ -14,4 +14,4 @@
|
|
14
14
|
</ul>
|
15
15
|
</div>
|
16
16
|
</div>
|
17
|
-
<% end %>
|
17
|
+
<% end %>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<% provide(:page_title, @model.display_name) -%>
|
2
2
|
<div class="row-fluid">
|
3
|
-
<%=
|
4
|
-
link_to(
|
3
|
+
<%=
|
4
|
+
link_to(
|
5
5
|
content_tag(:div,
|
6
|
-
content_tag(:i, nil, :class => 'icon-plus-sign icon-2x') + content_tag(:span, I18n.t("action.create") + " #{@model.display_name}", nil),
|
7
|
-
:class => "btn btn-box span2"),
|
6
|
+
content_tag(:i, nil, :class => 'icon-plus-sign icon-2x') + content_tag(:span, I18n.t("action.create") + " #{@model.display_name}", nil),
|
7
|
+
:class => "btn btn-box span2"),
|
8
8
|
{
|
9
9
|
:controller => params[:controller],
|
10
10
|
:action => "new"
|
@@ -15,11 +15,11 @@
|
|
15
15
|
<div class="row-fluid">
|
16
16
|
<div class="widget widget-padding span12">
|
17
17
|
<div class="widget-header">
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
<%= content_tag(:i, nil, :class => @model.icon) %>
|
19
|
+
<h5>
|
20
|
+
<%= @model.display_name %>
|
21
|
+
</h5>
|
22
|
+
</div>
|
23
23
|
<div class="widget-body">
|
24
24
|
<div class="dataTables_wrapper form-inline">
|
25
25
|
<table id="information-table" class="table table-striped table-bordered dataTable">
|
@@ -52,30 +52,30 @@
|
|
52
52
|
<% end %>
|
53
53
|
<% end %>
|
54
54
|
<td>
|
55
|
-
<%=
|
56
|
-
link_to(
|
57
|
-
content_tag(:i, nil, :class => 'icon-zoom-in'),
|
55
|
+
<%=
|
56
|
+
link_to(
|
57
|
+
content_tag(:i, nil, :class => 'icon-zoom-in'),
|
58
58
|
[member],
|
59
59
|
:title => t("action.show")
|
60
60
|
)
|
61
61
|
%>
|
62
|
-
|
63
|
-
<%=
|
64
|
-
link_to(
|
65
|
-
content_tag(:i, nil, :class => 'icon-pencil'),
|
62
|
+
|
63
|
+
<%=
|
64
|
+
link_to(
|
65
|
+
content_tag(:i, nil, :class => 'icon-pencil'),
|
66
66
|
[:edit, member],
|
67
67
|
:title => t("action.update") + " #{@model.display_name}"
|
68
68
|
)
|
69
69
|
%>
|
70
|
-
|
71
|
-
<%=
|
72
|
-
link_to(
|
70
|
+
|
71
|
+
<%=
|
72
|
+
link_to(
|
73
73
|
content_tag(
|
74
|
-
:i,
|
75
|
-
nil,
|
74
|
+
:i,
|
75
|
+
nil,
|
76
76
|
:class => 'icon-remove'
|
77
|
-
),
|
78
|
-
[member],
|
77
|
+
),
|
78
|
+
[member],
|
79
79
|
:title => I18n.t("action.delete"),
|
80
80
|
:id => "resource-delete",
|
81
81
|
:method => :delete,
|
@@ -94,4 +94,4 @@
|
|
94
94
|
</div>
|
95
95
|
</div>
|
96
96
|
</div>
|
97
|
-
</div>
|
97
|
+
</div>
|
data/config/locales/es.yml
CHANGED
@@ -7,85 +7,36 @@ es:
|
|
7
7
|
Adminpanel::Image: "Imagen"
|
8
8
|
Adminpanel::Category: "Categoría"
|
9
9
|
Adminpanel::Client: "Cliente"
|
10
|
+
Adminpanel::Post: "Publicación"
|
11
|
+
Adminpanel::Adminproject: "Proyecto"
|
12
|
+
Adminpanel::Siteproject: "Proyecto"
|
10
13
|
attributes:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
Adminpanel::Product:
|
25
|
-
name: "Nombre"
|
26
|
-
brief: "Pequeña descripción"
|
27
|
-
category_id: "Categoría"
|
28
|
-
Adminpanel::Client:
|
29
|
-
username: "Nombre de usuario"
|
30
|
-
name: "Nombre"
|
31
|
-
password: "Contraseña"
|
32
|
-
password_confirmation: "Confirmar contraseña"
|
33
|
-
password_digest: "Confirmar contraseña"
|
14
|
+
adminproject_id: "Proyecto"
|
15
|
+
brief: "Pequeña descripción"
|
16
|
+
category_id: "Categoría"
|
17
|
+
client_id: "Cliente"
|
18
|
+
adminproject_id: "Proyecto"
|
19
|
+
description: "Descripción"
|
20
|
+
email: "Correo electrónico"
|
21
|
+
file: "Imagen"
|
22
|
+
name: "Nombre"
|
23
|
+
password: "Contraseña"
|
24
|
+
password_confirmation: "Confirmar contraseña"
|
25
|
+
password_digest: "Confirmar contraseña"
|
26
|
+
username: "Nombre de usuario"
|
34
27
|
errors:
|
35
28
|
one: "%{model} no pudo guardarse debido a 1 error"
|
36
29
|
other: "%{model} no pudo guardarse debido a %{count} errores"
|
37
30
|
activerecord:
|
38
31
|
errors:
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
blank: "no puede estar vacío"
|
48
|
-
name:
|
49
|
-
blank: "no puede estar vacío"
|
50
|
-
password:
|
51
|
-
blank: "no puede estar vacío"
|
52
|
-
too_short: "es muy corta, mínimo 6 caracteres"
|
53
|
-
confirmation: "Deben ser iguales"
|
54
|
-
password_confirmation:
|
55
|
-
blank: "no puede estar vacío"
|
56
|
-
email:
|
57
|
-
blank: "no puede estar vacío"
|
58
|
-
invalid: "no es un correo"
|
59
|
-
taken: "ya está en uso"
|
60
|
-
adminpanel/gallery:
|
61
|
-
attributes:
|
62
|
-
file:
|
63
|
-
blank: "no puede estar vacía"
|
64
|
-
adminpanel/section:
|
65
|
-
attributes:
|
66
|
-
description:
|
67
|
-
blank: "no puede estar vacía"
|
68
|
-
too_long: "es muy larga"
|
69
|
-
too_short: "es muy corta"
|
70
|
-
not_a_number: "tienen que ser sólo números"
|
71
|
-
file:
|
72
|
-
blank: "no puede estar vacía"
|
73
|
-
adminpanel/product:
|
74
|
-
attributes:
|
75
|
-
name:
|
76
|
-
blank: "no puede estar vacío"
|
77
|
-
category_id:
|
78
|
-
blank: "no puede estar vacía"
|
79
|
-
brief:
|
80
|
-
blank: "no puede estar vacía"
|
81
|
-
gallery:
|
82
|
-
attributes:
|
83
|
-
description:
|
84
|
-
blank: "no puede estar vacía"
|
85
|
-
file:
|
86
|
-
blank: "no puede estar vacía"
|
87
|
-
name:
|
88
|
-
blank: "no puede estar vacío"
|
32
|
+
messages:
|
33
|
+
blank: "no puede estar vacío"
|
34
|
+
confirmation: "Deben ser iguales"
|
35
|
+
invalid: "no es un correo"
|
36
|
+
not_a_number: "tienen que ser sólo números"
|
37
|
+
taken: "ya está en uso"
|
38
|
+
too_long: "es muy larga"
|
39
|
+
too_short: "es muy corta, mínimo 6 caracteres"
|
89
40
|
time:
|
90
41
|
formats:
|
91
42
|
graphic: "%Y-%m-%d %H:%M:%S"
|
@@ -133,4 +84,4 @@ es:
|
|
133
84
|
password: "Contraseña"
|
134
85
|
email: "Correo electrónico"
|
135
86
|
other:
|
136
|
-
no description: "No tiene descripción aún"
|
87
|
+
no description: "No tiene descripción aún"
|
data/lib/adminpanel/version.rb
CHANGED
@@ -4,17 +4,17 @@ module Adminpanel
|
|
4
4
|
module Generators
|
5
5
|
class ResourceGenerator < Rails::Generators::Base
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
argument :resource_name, :type => :string
|
9
|
+
argument :fields, :type => :array, :default => "name:string"
|
10
10
|
desc "Generate the resource files necessary to use a model"
|
11
11
|
|
12
12
|
def self.next_migration_number(path)
|
13
|
-
|
13
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
14
14
|
end
|
15
15
|
|
16
16
|
def create_model
|
17
|
-
|
17
|
+
template 'resource.rb', "app/models/adminpanel/#{lower_name}.rb"
|
18
18
|
end
|
19
19
|
|
20
20
|
def create_controller
|
@@ -30,8 +30,9 @@ module Adminpanel
|
|
30
30
|
|
31
31
|
private
|
32
32
|
def is_a_resource?
|
33
|
-
fields.each do |
|
34
|
-
|
33
|
+
fields.each do |attribute|
|
34
|
+
assign_attributes_variables(attribute)
|
35
|
+
if @attr_type != "belongs_to"
|
35
36
|
return true
|
36
37
|
end
|
37
38
|
end
|
@@ -70,51 +71,67 @@ module Adminpanel
|
|
70
71
|
models
|
71
72
|
end
|
72
73
|
|
74
|
+
def assign_attributes_variables(attribute)
|
75
|
+
if attribute.split(":").second.nil?
|
76
|
+
@attr_field = attribute
|
77
|
+
@attr_type = "string"
|
78
|
+
else
|
79
|
+
@attr_field = attribute.split(":").first
|
80
|
+
@attr_type = attribute.split(":").second
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
73
84
|
def symbolized_attributes
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
85
|
+
attr_string = ""
|
86
|
+
fields.each do |attribute|
|
87
|
+
|
88
|
+
assign_attributes_variables(attribute)
|
89
|
+
|
90
|
+
if @attr_type == "images"
|
91
|
+
attr_string = attr_string + ":images_attributes, "
|
92
|
+
elsif @attr_type == "belongs_to"
|
93
|
+
attr_string = "#{attr_string}:#{belongs_to_field(@attr_field)}, "
|
94
|
+
elsif @attr_type == "has_many" || @attr_type == "has_many_through"
|
95
|
+
if @attr_field.split(",").second == nil
|
96
|
+
attr_string = "#{attr_string}:#{has_many_field(@attr_field)}, "
|
97
|
+
else
|
98
|
+
model_name = models_in_parameter(@attr_field).first
|
99
|
+
attr_string = "#{attr_string}:#{has_many_field(model_name)}, "
|
100
|
+
end
|
101
|
+
else
|
102
|
+
attr_string = attr_string + ":#{@attr_field}, "
|
103
|
+
end
|
104
|
+
end
|
105
|
+
2.times do
|
106
|
+
attr_string.chop! #to remove the last white space and the last ","
|
107
|
+
end
|
108
|
+
attr_string
|
95
109
|
end
|
96
110
|
|
97
111
|
def adminpanel_form_attributes
|
98
112
|
form_hash = ""
|
99
|
-
fields.each do |
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
113
|
+
fields.each do |attribute|
|
114
|
+
|
115
|
+
assign_attributes_variables(attribute)
|
116
|
+
|
117
|
+
if @attr_type == "string" || @attr_type == "float"
|
118
|
+
form_hash = form_hash + "\n\t\t\t\t{\"#{@attr_field}\" => {\"type\" => \"text_field\", \"name\" => \"#{@attr_field}\", \"label\" => \"#{@attr_field}\", \"placeholder\" => \"#{@attr_field}\"}},"
|
119
|
+
elsif @attr_type == "text" || @attr_type == "wysiwyg"
|
120
|
+
form_hash = form_hash + "\n\t\t\t\t{\"#{@attr_field}\" => {\"type\" => \"wysiwyg_field\", \"name\" => \"#{@attr_field}\", \"label\" => \"#{@attr_field}\", \"placeholder\" => \"#{@attr_field}\"}},"
|
121
|
+
elsif @attr_type == "integer"
|
122
|
+
form_hash = form_hash + "\n\t\t\t\t{\"#{@attr_field}\" => {\"type\" => \"number_field\", \"name\" => \"#{@attr_field}\", \"label\" => \"#{@attr_field}\", \"placeholder\" => \"#{@attr_field}\"}},"
|
123
|
+
elsif @attr_type == "datepicker"
|
124
|
+
form_hash = form_hash + "\n\t\t\t\t{\"#{@attr_field}\" => {\"type\" => \"datepicker\", \"name\" => \"#{@attr_field}\", \"label\" => \"#{@attr_field}\", \"placeholder\" => \"#{@attr_field}\"}},"
|
125
|
+
elsif @attr_type == "images"
|
126
|
+
form_hash = form_hash + "\n\t\t\t\t{\"#{@attr_field}\" => {\"type\" => \"adminpanel_file_field\", \"name\" => \"#{@attr_field}\"}},"
|
127
|
+
elsif @attr_type == "belongs_to"
|
128
|
+
form_hash = form_hash + "\n\t\t\t\t{\"#{belongs_to_field(@attr_field)}\" => {\"@attr_type\" => \"belongs_to\", \"model\" => \"Adminpanel\:\:#{resource_class_name(@attr_field)}\", \"name\" => \"#{belongs_to_field(@attr_field)}\"}},"
|
129
|
+
elsif @attr_type == "has_many" || @attr_type == "has_many_through"
|
130
|
+
if models_in_parameter(@attr_field).second.nil?
|
131
|
+
through_model = @attr_field
|
132
|
+
else
|
133
|
+
through_model = models_in_parameter(@attr_field).first
|
134
|
+
end
|
118
135
|
through_model = resource_class_name(through_model)
|
119
136
|
form_hash = form_hash + "\n\t\t\t\t{\"#{has_many_field(through_model)}\" => {\"type\" => \"has_many\", \"model\" => \"Adminpanel\:\:#{through_model}\", \"name\" => \"#{has_many_field(through_model)}\"}},"
|
120
137
|
end
|
@@ -137,8 +154,9 @@ module Adminpanel
|
|
137
154
|
end
|
138
155
|
|
139
156
|
def has_associations?
|
140
|
-
fields.each do |
|
141
|
-
|
157
|
+
fields.each do |attribute|
|
158
|
+
assign_attributes_variables(attribute)
|
159
|
+
if @attr_type == "images" || @attr_type == "belongs_to" || @attr_type == "has_many" || @attr_type == "has_many_through"
|
142
160
|
return true
|
143
161
|
end
|
144
162
|
end
|
@@ -147,15 +165,16 @@ module Adminpanel
|
|
147
165
|
|
148
166
|
def associations
|
149
167
|
association = ""
|
150
|
-
fields.each do |
|
151
|
-
|
152
|
-
|
153
|
-
|
168
|
+
fields.each do |attribute|
|
169
|
+
assign_attributes_variables(attribute)
|
170
|
+
if @attr_type == "belongs_to"
|
171
|
+
association = "#{association}#{belongs_to_association(@attr_field)}"
|
172
|
+
elsif @attr_type == "images"
|
154
173
|
association = "#{association}#{image_association}"
|
155
|
-
elsif
|
156
|
-
association = "#{association}#{has_many_association(
|
174
|
+
elsif @attr_type == "has_many" || @attr_type == "has_many_through"
|
175
|
+
association = "#{association}#{has_many_association(@attr_field)}"
|
157
176
|
end
|
158
|
-
|
177
|
+
|
159
178
|
end
|
160
179
|
association
|
161
180
|
end
|
@@ -166,24 +185,24 @@ module Adminpanel
|
|
166
185
|
|
167
186
|
def has_many_association(field)
|
168
187
|
if models_in_parameter(field).second.nil?
|
169
|
-
return "has_many :#{models_in_parameter(field).first}\n\t\t" +
|
170
|
-
"has_many :#{models_in_parameter(field).first}, " +
|
171
|
-
":through => :#{models_in_parameter(field).first}ation, " +
|
188
|
+
return "has_many :#{models_in_parameter(field).first}\n\t\t" +
|
189
|
+
"has_many :#{models_in_parameter(field).first}, " +
|
190
|
+
":through => :#{models_in_parameter(field).first}ation, " +
|
172
191
|
":dependent => :destroy\n\t\t"
|
173
192
|
else
|
174
193
|
return "has_many :#{models_in_parameter(field).second}\n\t\t" +
|
175
|
-
"has_many :#{models_in_parameter(field).first}, " +
|
176
|
-
":through => :#{models_in_parameter(field).second}, " +
|
194
|
+
"has_many :#{models_in_parameter(field).first}, " +
|
195
|
+
":through => :#{models_in_parameter(field).second}, " +
|
177
196
|
":dependent => :destroy\n\t\t"
|
178
197
|
end
|
179
198
|
end
|
180
199
|
|
181
200
|
def image_association
|
182
|
-
return "has_many :images, :foreign_key => \"foreign_key\", " +
|
183
|
-
":conditions => { :model => \"#{lower_name}\" } \n\t\t
|
201
|
+
return "has_many :images, :foreign_key => \"foreign_key\", " +
|
202
|
+
":conditions => { :model => \"#{lower_name}\" } \n\t\t" +
|
184
203
|
"accepts_nested_attributes_for :images, :allow_destroy => true\n\t\t" +
|
185
204
|
"#remember to change the association if you change this model display_name\n\t\t"
|
186
205
|
end
|
187
206
|
end
|
188
207
|
end
|
189
|
-
end
|
208
|
+
end
|