adminpanel 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -12,7 +12,7 @@ gem "rails-i18n", "~> 3.0.0"
12
12
  gem "inherited_resources", "~> 1.3.1"
13
13
  gem "google-api-client", "~> 0.7.1"
14
14
 
15
- group :test do
15
+ group :test do
16
16
  gem "bundler", "~> 1.3"
17
17
  gem "activerecord", "3.2.12"
18
18
  gem "rake", "~> 10.1.1"
@@ -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.#{object.class.model_name}.#{field}") %>
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
- <%= content_tag(:i, nil, :class => @model.icon) %>
19
- <h5>
20
- <%= @model.display_name %>
21
- </h5>
22
- </div>
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>
@@ -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
- Adminpanel::User:
12
- email: "Correo electrónico"
13
- password_digest: "Confirmar contraseña"
14
- name: "Nombre"
15
- password: "Contraseña"
16
- password_confirmation: "Confirmar contraseña"
17
- Adminpanel::Section:
18
- description: "Descripción"
19
- file: "Imagen"
20
- Adminpanel::Gallery:
21
- file: "Imagen"
22
- Adminpanel::Category:
23
- name: "Nombre"
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
- models:
40
- adminpanel/category:
41
- attributes:
42
- name:
43
- blank: "no puede estar vacío"
44
- adminpanel/user:
45
- attributes:
46
- password_digest:
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"
@@ -1,3 +1,3 @@
1
1
  module Adminpanel
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -4,17 +4,17 @@ module Adminpanel
4
4
  module Generators
5
5
  class ResourceGenerator < Rails::Generators::Base
6
6
 
7
- source_root File.expand_path("../templates", __FILE__)
8
- argument :resource_name, :type => :string, :default => "Resource"
9
- argument :fields, :type => :hash, :default => "name:string"
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
- Time.now.utc.strftime("%Y%m%d%H%M%S")
13
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
14
14
  end
15
15
 
16
16
  def create_model
17
- template 'resource.rb', "app/models/adminpanel/#{lower_name}.rb"
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 |field, type|
34
- if type != "belongs_to"
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
- attributes = ""
75
- fields.each do |field, type|
76
- if type == "images"
77
- attributes = attributes + ":images_attributes, "
78
- elsif type == "belongs_to"
79
- attributes = "#{attributes}:#{belongs_to_field(field)}, "
80
- elsif type == "has_many" || type == "has_many_through"
81
- if field.split(",").second == nil
82
- attributes = "#{attributes}:#{has_many_field(field)}, "
83
- else
84
- model_name = models_in_parameter(field).first
85
- attributes = "#{attributes}:#{has_many_field(model_name)}, "
86
- end
87
- else
88
- attributes = attributes + ":#{field}, "
89
- end
90
- end
91
- 2.times do
92
- attributes.chop! #to remove the last white space and the last ","
93
- end
94
- attributes
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 |field, type|
100
- if type == "string" || type == "float"
101
- form_hash = form_hash + "\n\t\t\t\t{\"#{field}\" => {\"type\" => \"text_field\", \"name\" => \"#{field}\", \"label\" => \"#{field}\", \"placeholder\" => \"#{field}\"}},"
102
- elsif type == "text" || type == "wysiwyg"
103
- form_hash = form_hash + "\n\t\t\t\t{\"#{field}\" => {\"type\" => \"wysiwyg_field\", \"name\" => \"#{field}\", \"label\" => \"#{field}\", \"placeholder\" => \"#{field}\"}},"
104
- elsif type == "integer"
105
- form_hash = form_hash + "\n\t\t\t\t{\"#{field}\" => {\"type\" => \"number_field\", \"name\" => \"#{field}\", \"label\" => \"#{field}\", \"placeholder\" => \"#{field}\"}},"
106
- elsif type == "datepicker"
107
- form_hash = form_hash + "\n\t\t\t\t{\"#{field}\" => {\"type\" => \"datepicker\", \"name\" => \"#{field}\", \"label\" => \"#{field}\", \"placeholder\" => \"#{field}\"}},"
108
- elsif type == "images"
109
- form_hash = form_hash + "\n\t\t\t\t{\"#{field}\" => {\"type\" => \"adminpanel_file_field\", \"name\" => \"#{field}\"}},"
110
- elsif type == "belongs_to"
111
- form_hash = form_hash + "\n\t\t\t\t{\"#{belongs_to_field(field)}\" => {\"type\" => \"belongs_to\", \"model\" => \"Adminpanel\:\:#{resource_class_name(field)}\", \"name\" => \"#{belongs_to_field(field)}\"}},"
112
- elsif type == "has_many" || type == "has_many_through"
113
- if models_in_parameter(field).second.nil?
114
- through_model = field
115
- else
116
- through_model = models_in_parameter(field).first
117
- end
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 |field, type|
141
- if type == "images" || type == "belongs_to" || type == "has_many" || type == "has_many_through"
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 |field, type|
151
- if type == "belongs_to"
152
- association = "#{association}#{belongs_to_association(field)}"
153
- elsif type == "images"
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 type == "has_many" || type == "has_many_through"
156
- association = "#{association}#{has_many_association(field)}"
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