adminpanel 2.0.1 → 2.1.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.
- 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
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
<%= content_tag(:i, nil, class: "fa fa-#{@model.icon}") %>
|
|
14
14
|
<h5><%= @model.display_name.humanize %>
|
|
15
15
|
<%= render 'shared/edit_icon_button', resource: resource, resource_name: @model.display_name %>
|
|
16
|
+
|
|
17
|
+
<%= render 'shared/fb_icon_button', resource: resource, resource_name: @model.display_name %>
|
|
16
18
|
</h5>
|
|
17
19
|
</div>
|
|
18
20
|
<div class="widget-body">
|
data/config/locales/es.yml
CHANGED
|
@@ -1,64 +1,66 @@
|
|
|
1
1
|
es:
|
|
2
2
|
model:
|
|
3
|
-
Analytic: 'Google
|
|
4
|
-
Gallery:
|
|
5
|
-
Categories:
|
|
3
|
+
Analytic: 'Google Analytics'
|
|
4
|
+
Gallery: 'Galería de Inicio'
|
|
5
|
+
Categories: 'Categorías'
|
|
6
6
|
attributes:
|
|
7
|
-
adminproject_id:
|
|
8
|
-
brief:
|
|
9
|
-
body:
|
|
10
|
-
category_id:
|
|
11
|
-
client_id:
|
|
12
|
-
description:
|
|
13
|
-
email:
|
|
14
|
-
file:
|
|
15
|
-
group_id:
|
|
16
|
-
name:
|
|
17
|
-
password:
|
|
18
|
-
password_confirmation:
|
|
19
|
-
password_digest:
|
|
20
|
-
username:
|
|
7
|
+
adminproject_id: 'Proyecto'
|
|
8
|
+
brief: 'Pequeña descripción'
|
|
9
|
+
body: 'Contenido'
|
|
10
|
+
category_id: 'Categoría'
|
|
11
|
+
client_id: 'Cliente'
|
|
12
|
+
description: 'Descripción'
|
|
13
|
+
email: 'Correo electrónico'
|
|
14
|
+
file: 'Imagen'
|
|
15
|
+
group_id: 'Rol de usuario'
|
|
16
|
+
name: 'Nombre'
|
|
17
|
+
password: 'Contraseña'
|
|
18
|
+
password_confirmation: 'Confirmar contraseña'
|
|
19
|
+
password_digest: 'Confirmar contraseña'
|
|
20
|
+
username: 'Nombre de usuario'
|
|
21
21
|
errors:
|
|
22
|
-
one:
|
|
23
|
-
other:
|
|
22
|
+
one: '%{model} no pudo guardarse debido a 1 error'
|
|
23
|
+
other: '%{model} no pudo guardarse debido a %{count} errores'
|
|
24
24
|
activerecord:
|
|
25
25
|
errors:
|
|
26
26
|
messages:
|
|
27
27
|
not_phone: 'no es un teléfono (10 números)'
|
|
28
28
|
blank: "no puede estar vacío"
|
|
29
|
-
confirmation:
|
|
30
|
-
invalid:
|
|
31
|
-
not_a_number:
|
|
32
|
-
taken:
|
|
33
|
-
too_long:
|
|
34
|
-
too_short:
|
|
29
|
+
confirmation: 'Deben ser iguales'
|
|
30
|
+
invalid: 'no es un correo'
|
|
31
|
+
not_a_number: 'tienen que ser sólo números'
|
|
32
|
+
taken: 'ya está en uso'
|
|
33
|
+
too_long: 'es muy larga'
|
|
34
|
+
too_short: 'es muy corta, mínimo 6 caracteres'
|
|
35
35
|
time:
|
|
36
36
|
formats:
|
|
37
|
-
short:
|
|
38
|
-
estimate:
|
|
39
|
-
Add Image:
|
|
37
|
+
short: '%d de %B de %Y'
|
|
38
|
+
estimate: '%Y-%m-%d'
|
|
39
|
+
Add Image: 'Agregar Imagen'
|
|
40
40
|
wysiwyg:
|
|
41
|
-
description:
|
|
42
|
-
Panel title:
|
|
43
|
-
actions:
|
|
41
|
+
description: 'Escriba la descripción aquí'
|
|
42
|
+
Panel title: 'Panel Administrativo'
|
|
43
|
+
actions: 'Acciones'
|
|
44
44
|
action:
|
|
45
|
-
add:
|
|
46
|
-
create:
|
|
47
|
-
close:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
add: 'Agregar'
|
|
46
|
+
create: 'Crear'
|
|
47
|
+
close: 'Cerrar'
|
|
48
|
+
delete: 'Eliminar'
|
|
49
|
+
delete confirmation: 'Estás seguro que desea eliminar?'
|
|
50
|
+
publish: 'Publicar'
|
|
51
|
+
share: 'Compartir %{model} en Facebook'
|
|
52
|
+
show: 'Ver'
|
|
53
|
+
submitting: 'Enviando...'
|
|
54
|
+
save: 'Guardar'
|
|
55
|
+
save_success: 'Se ha guardado con éxito'
|
|
56
|
+
update: 'Actualizar'
|
|
57
|
+
view: 'Ver'
|
|
56
58
|
is_true: 'Sí'
|
|
57
59
|
is_false: 'No'
|
|
58
60
|
authentication:
|
|
59
|
-
welcome:
|
|
60
|
-
signin_error:
|
|
61
|
-
signin_success:
|
|
61
|
+
welcome: 'Bienvenido! Inicia Sesión'
|
|
62
|
+
signin_error: 'Correo y/o Contraseña incorrecta.'
|
|
63
|
+
signin_success: 'Bienvenido!'
|
|
62
64
|
not_authorized: 'No tienes permisos para acceder'
|
|
63
65
|
gallery:
|
|
64
66
|
container: 'Imágenes'
|
|
@@ -66,28 +68,35 @@ es:
|
|
|
66
68
|
success: 'La imagen ha sido guardada'
|
|
67
69
|
deleted: 'La imagen ha sido eliminada'
|
|
68
70
|
moved : "Se ha actualizado la posición de la galería"
|
|
69
|
-
not-moved:
|
|
70
|
-
image:
|
|
71
|
-
position:
|
|
72
|
-
action:
|
|
71
|
+
not-moved: 'No se pudo mover la Imagen'
|
|
72
|
+
image: 'Imagen'
|
|
73
|
+
position: 'Posición'
|
|
74
|
+
action: 'Acción'
|
|
73
75
|
user:
|
|
74
|
-
new:
|
|
75
|
-
success:
|
|
76
|
+
new: 'Agregar Usuario'
|
|
77
|
+
success: 'El usuario ha sido guardado'
|
|
76
78
|
section:
|
|
77
|
-
name:
|
|
78
|
-
description:
|
|
79
|
-
edit:
|
|
80
|
-
default:
|
|
81
|
-
image:
|
|
79
|
+
name: 'Nombre'
|
|
80
|
+
description: 'Descripción'
|
|
81
|
+
edit: 'Editar Sección'
|
|
82
|
+
default: 'Sin Sección'
|
|
83
|
+
image: 'Imagen'
|
|
82
84
|
session:
|
|
83
|
-
password:
|
|
84
|
-
email:
|
|
85
|
+
password: 'Contraseña'
|
|
86
|
+
email: 'Correo electrónico'
|
|
85
87
|
other:
|
|
86
|
-
add :
|
|
87
|
-
no description:
|
|
88
|
+
add : 'Agregar %{model}'
|
|
89
|
+
no description: 'No tiene descripción aún'
|
|
88
90
|
routes:
|
|
89
91
|
new: 'nuevo'
|
|
90
92
|
edit: 'editar'
|
|
91
93
|
show: 'ver'
|
|
92
94
|
signout: 'cerrar-sesion'
|
|
93
95
|
signin: 'iniciar-sesion'
|
|
96
|
+
fb:
|
|
97
|
+
posted: 'Publicado en el muro de %{user}'
|
|
98
|
+
not-posted: 'Hubo un error, no fue publicado en ningún muro, por favor intenta otra vez.'
|
|
99
|
+
pages: 'Publiar como %{name}'
|
|
100
|
+
page-select: 'Selecciona una cuenta para la publicación'
|
|
101
|
+
message: 'Mensaje de la publicación'
|
|
102
|
+
saved-token: 'Se guardó el token de Facebook con éxito, ya puede publicar con la cuenta de Facebook'
|
data/config/routes.rb
CHANGED
|
@@ -21,6 +21,7 @@ Adminpanel::Engine.routes.draw do
|
|
|
21
21
|
resources :analytics, resources_parameters(resource).merge(
|
|
22
22
|
{ only: [:index] }.merge(rest_path_names)
|
|
23
23
|
)
|
|
24
|
+
get :save_fb_access, to:'analytics#save_fb_access', as: 'fb_callback'
|
|
24
25
|
else
|
|
25
26
|
if !get_gallery_children(resource).nil?
|
|
26
27
|
# make the resources gallery routes
|
|
@@ -33,7 +34,13 @@ Adminpanel::Engine.routes.draw do
|
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
# normal resource
|
|
36
|
-
resources resource, resources_parameters(resource).merge(rest_path_names)
|
|
37
|
+
resources resource, resources_parameters(resource).merge(rest_path_names) do
|
|
38
|
+
member do
|
|
39
|
+
get :fb_choose_page, as: 'fb_choose_page', path: 'publicar-a-pagina-en-fb'
|
|
40
|
+
post :fb_save_token, as: 'fb_save_token', path: 'guardar-token'
|
|
41
|
+
post 'fb_publish/:configuration_id', to: "#{resource}#fb_publish", as: 'fb_publish', path: 'publicar-a-facebook'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
37
44
|
end
|
|
38
45
|
end
|
|
39
46
|
|
data/lib/adminpanel.rb
CHANGED
data/lib/adminpanel/engine.rb
CHANGED
|
@@ -5,7 +5,10 @@ module Adminpanel
|
|
|
5
5
|
|
|
6
6
|
class << self
|
|
7
7
|
mattr_accessor :analytics_profile_id, :analytics_key_path, :analytics_key_filename,
|
|
8
|
-
:displayable_resources
|
|
8
|
+
:displayable_resources, :fb_app_id, :fb_app_secret
|
|
9
|
+
|
|
10
|
+
self.fb_app_id = nil
|
|
11
|
+
self.fb_app_secret = nil
|
|
9
12
|
self.analytics_profile_id = nil
|
|
10
13
|
self.analytics_key_path = "config/analytics"
|
|
11
14
|
self.analytics_key_filename = nil
|
data/lib/adminpanel/version.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Adminpanel
|
|
|
16
16
|
def generate_migration
|
|
17
17
|
migration_template(
|
|
18
18
|
'gallery_migration.rb',
|
|
19
|
-
"db/migrate/create_adminpanel_#{lower_name.pluralize}
|
|
19
|
+
"db/migrate/create_adminpanel_#{lower_name.pluralize}.rb"
|
|
20
20
|
)
|
|
21
21
|
puts "don't forget to add the form_field, the relationship and #{lower_name}s_attributes it to the permited params"
|
|
22
22
|
end
|
|
@@ -29,7 +29,7 @@ module Adminpanel
|
|
|
29
29
|
def lower_name
|
|
30
30
|
"#{reference_name}file"
|
|
31
31
|
end
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
def class_name
|
|
34
34
|
"#{lower_name.capitalize}"
|
|
35
35
|
end
|
|
@@ -31,7 +31,7 @@ module Adminpanel
|
|
|
31
31
|
:default => false,
|
|
32
32
|
:desc => 'Skip cancan\'s ability.rb'
|
|
33
33
|
|
|
34
|
-
def
|
|
34
|
+
def create_initializer
|
|
35
35
|
if !options[:'skip-setup']
|
|
36
36
|
copy_file 'adminpanel_setup.rb', 'config/initializers/adminpanel_setup.rb'
|
|
37
37
|
end
|
|
@@ -43,9 +43,8 @@ module Adminpanel
|
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def
|
|
46
|
+
def create_category
|
|
47
47
|
if !options[:'skip-category']
|
|
48
|
-
# puts "including category files"
|
|
49
48
|
copy_file "category_template.rb", 'app/models/adminpanel/category.rb'
|
|
50
49
|
migration_template 'create_adminpanel_categories_table.rb', 'db/migrate/create_adminpanel_categories_table.rb'
|
|
51
50
|
end
|
|
@@ -10,12 +10,16 @@ Adminpanel.setup do |config|
|
|
|
10
10
|
# # Path to the key file, defaults to config/analytics
|
|
11
11
|
# config.analytics_key_path = "config/analytics"
|
|
12
12
|
|
|
13
|
+
# # Facebook app id
|
|
14
|
+
# config.fb_app_id = '1234'
|
|
15
|
+
# # Facebook app secret *MAKE SURE TO DON'T SHARE THIS SECRET*
|
|
16
|
+
# config.fb_app_secret = '1234'
|
|
17
|
+
|
|
13
18
|
# # This are the modules that are going to be displayed and order that are going to be displayed
|
|
14
19
|
config.displayable_resources = [
|
|
15
20
|
:analytics,
|
|
16
21
|
:users,
|
|
17
22
|
:galleries,
|
|
18
|
-
:sections
|
|
19
|
-
:categories
|
|
23
|
+
:sections
|
|
20
24
|
]
|
|
21
25
|
end
|
|
@@ -42,6 +42,16 @@ class CreateAdminpanelTables < ActiveRecord::Migration
|
|
|
42
42
|
t.timestamps
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
create_table :adminpanel_auths do |t|
|
|
46
|
+
t.string :name
|
|
47
|
+
t.string :key
|
|
48
|
+
t.string :value
|
|
49
|
+
t.datetime :created_at, :null => false
|
|
50
|
+
t.datetime :updated_at, :null => false
|
|
51
|
+
end
|
|
52
|
+
add_index :adminpanel_auths, [:name]
|
|
53
|
+
add_index :adminpanel_auths, [:key]
|
|
54
|
+
|
|
45
55
|
create_table :adminpanel_sections do |t|
|
|
46
56
|
t.string :name
|
|
47
57
|
t.boolean :has_description
|
|
@@ -53,5 +63,6 @@ class CreateAdminpanelTables < ActiveRecord::Migration
|
|
|
53
63
|
end
|
|
54
64
|
|
|
55
65
|
add_index :adminpanel_sections, [:key]
|
|
66
|
+
add_index :adminpanel_sections, [:page]
|
|
56
67
|
end
|
|
57
68
|
end
|
|
@@ -5,8 +5,24 @@ module Adminpanel
|
|
|
5
5
|
class ResourceGenerator < ActiveRecord::Generators::Base
|
|
6
6
|
source_root File.expand_path("../templates", __FILE__)
|
|
7
7
|
desc "Generate the resource files necessary to use a model"
|
|
8
|
+
class_option :'include-gallery',
|
|
9
|
+
:type => :boolean,
|
|
10
|
+
:aliases => '-g',
|
|
11
|
+
:default => true,
|
|
12
|
+
:desc => 'Creates the gallery for this resource'
|
|
8
13
|
|
|
9
|
-
argument :fields, :type => :array, :default => "
|
|
14
|
+
argument :fields, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]"
|
|
15
|
+
|
|
16
|
+
def change_fields_aliases
|
|
17
|
+
fields.each do |attribute|
|
|
18
|
+
type = attribute.split(':').second
|
|
19
|
+
case type
|
|
20
|
+
when 'wysiwyg'
|
|
21
|
+
fields.delete(attribute)
|
|
22
|
+
fields << attribute.split(':').first + ':' + 'text'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
10
26
|
|
|
11
27
|
def generate_model
|
|
12
28
|
template 'resource.rb', "app/models/adminpanel/#{lower_singularized_name}.rb"
|
|
@@ -19,27 +35,54 @@ module Adminpanel
|
|
|
19
35
|
end
|
|
20
36
|
|
|
21
37
|
def generate_migrations
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
parameters = fields
|
|
39
|
+
parameters.delete_if{ |pair| pair.split(':').second == 'has_many' }
|
|
40
|
+
invoke :migration, ["create_adminpanel_#{pluralized_name}", parameters]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def generate_gallery
|
|
44
|
+
if has_gallery?
|
|
45
|
+
invoke 'adminpanel:gallery', [lower_singularized_name]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def add_resource_to_config
|
|
50
|
+
if setup_is_found?
|
|
51
|
+
inject_into_file 'config/initializers/adminpanel_setup.rb',
|
|
52
|
+
after: 'config.displayable_resources = [' do
|
|
53
|
+
indent "\n:#{pluralized_name},", 4
|
|
54
|
+
end
|
|
55
|
+
end
|
|
26
56
|
end
|
|
27
57
|
|
|
28
58
|
def print_messages
|
|
29
|
-
puts "don't forget to
|
|
59
|
+
puts "don't forget to restart your server"
|
|
30
60
|
end
|
|
31
61
|
|
|
32
62
|
private
|
|
63
|
+
|
|
64
|
+
def setup_is_found?
|
|
65
|
+
if Dir.exists?('config') && Dir.exists?('config/initializers') && File.exists?('config/initializers/adminpanel_setup.rb')
|
|
66
|
+
true
|
|
67
|
+
else
|
|
68
|
+
false
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
33
72
|
def is_a_resource?
|
|
34
73
|
fields.each do |attribute|
|
|
35
74
|
assign_attributes_variables(attribute)
|
|
36
|
-
if @attr_type !=
|
|
75
|
+
if @attr_type != 'belongs_to'
|
|
37
76
|
return true
|
|
38
77
|
end
|
|
39
78
|
end
|
|
40
79
|
false
|
|
41
80
|
end
|
|
42
81
|
|
|
82
|
+
def has_gallery?
|
|
83
|
+
options[:'include-gallery']
|
|
84
|
+
end
|
|
85
|
+
|
|
43
86
|
def gallery_name
|
|
44
87
|
"#{lower_singularized_name}file"
|
|
45
88
|
end
|
|
@@ -68,147 +111,100 @@ module Adminpanel
|
|
|
68
111
|
"#{resource.singularize.capitalize}"
|
|
69
112
|
end
|
|
70
113
|
|
|
71
|
-
def models_in_parameter(field)
|
|
72
|
-
models = []
|
|
73
|
-
field.split(",").each do |member|
|
|
74
|
-
models << member.downcase.pluralize
|
|
75
|
-
end
|
|
76
|
-
models
|
|
77
|
-
end
|
|
78
|
-
|
|
79
114
|
def assign_attributes_variables(attribute)
|
|
115
|
+
@attr_field = attribute.split(":").first
|
|
80
116
|
if attribute.split(":").second.nil?
|
|
81
|
-
@attr_field = attribute
|
|
82
117
|
@attr_type = "string"
|
|
83
118
|
else
|
|
84
|
-
@attr_field = attribute.split(":").first
|
|
85
119
|
@attr_type = attribute.split(":").second
|
|
86
120
|
end
|
|
87
121
|
end
|
|
88
122
|
|
|
89
123
|
def symbolized_attributes
|
|
90
|
-
|
|
91
|
-
|
|
124
|
+
fields.map do |attribute|
|
|
125
|
+
assign_attributes_variables(attribute)
|
|
126
|
+
case @attr_type
|
|
127
|
+
when 'belongs_to'
|
|
128
|
+
':' + belongs_to_field(@attr_field)
|
|
129
|
+
when 'has_many'
|
|
130
|
+
':' + has_many_field(@attr_field)
|
|
131
|
+
else
|
|
132
|
+
":#{attribute.split(':').first}"
|
|
133
|
+
end
|
|
134
|
+
end.join(",\n")
|
|
135
|
+
end
|
|
92
136
|
|
|
137
|
+
def get_attribute_hash
|
|
138
|
+
fields.map do |attribute|
|
|
93
139
|
assign_attributes_variables(attribute)
|
|
140
|
+
send(@attr_type + '_form_hash')
|
|
141
|
+
end.join(", \n")
|
|
142
|
+
end
|
|
94
143
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
attr_string = "#{attr_string}:#{belongs_to_field(@attr_field)}, "
|
|
99
|
-
elsif @attr_type == 'has_many' || @attr_type == 'has_many_through'
|
|
100
|
-
if @attr_field.split(',').second == nil
|
|
101
|
-
attr_string = "#{attr_string}:#{has_many_field(@attr_field)}, "
|
|
102
|
-
else
|
|
103
|
-
model_name = models_in_parameter(@attr_field).first
|
|
104
|
-
attr_string = "#{attr_string} {:#{has_many_field(model_name)} => []}, "
|
|
105
|
-
end
|
|
106
|
-
else
|
|
107
|
-
attr_string = attr_string + ":#{@attr_field}, "
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
2.times do
|
|
111
|
-
attr_string.chop! #to remove the last white space and the last ","
|
|
112
|
-
end
|
|
113
|
-
attr_string
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def adminpanel_form_attributes
|
|
117
|
-
form_hash = ""
|
|
118
|
-
fields.each do |attribute|
|
|
144
|
+
def string_form_hash
|
|
145
|
+
attribute_hash(@attr_field, 'text_field')
|
|
146
|
+
end
|
|
119
147
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
when 'string', 'float'
|
|
123
|
-
form_hash = form_hash + "#{attribute_hash('text_field')}"
|
|
124
|
-
when 'text', 'wysiwyg'
|
|
125
|
-
form_hash = form_hash + "#{attribute_hash('wysiwyg_field')}"
|
|
126
|
-
when 'integer'
|
|
127
|
-
form_hash = form_hash + "#{attribute_hash('number_field')}"
|
|
128
|
-
when 'boolean'
|
|
129
|
-
form_hash = form_hash + "#{attribute_hash('boolean')}"
|
|
130
|
-
when 'datepicker'
|
|
131
|
-
form_hash = form_hash + "#{attribute_hash('datepicker')}"
|
|
132
|
-
when 'images'
|
|
133
|
-
form_hash = form_hash + "#{file_field_hash}"
|
|
134
|
-
when 'belongs_to'
|
|
135
|
-
form_hash = form_hash + "#{belongs_to_attribute_hash(belongs_to_field(@attr_field))}"
|
|
136
|
-
when 'has_many', 'has_many_through'
|
|
137
|
-
if models_in_parameter(@attr_field).second.nil?
|
|
138
|
-
through_model = @attr_field
|
|
139
|
-
else
|
|
140
|
-
through_model = models_in_parameter(@attr_field).first
|
|
141
|
-
end
|
|
142
|
-
through_model = resource_class_name(through_model)
|
|
143
|
-
# form_hash = form_hash + "#{relational_attribute_hash('belongs_to')}"
|
|
144
|
-
form_hash = form_hash + has_many_attribute_hash(has_many_field(through_model), through_model)
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
form_hash
|
|
148
|
+
def float_form_hash
|
|
149
|
+
attribute_hash(@attr_field, 'text_field')
|
|
148
150
|
end
|
|
149
151
|
|
|
150
|
-
def
|
|
151
|
-
|
|
152
|
-
"#{label_type}," +
|
|
153
|
-
"#{placeholder_type}}\n\t\t\t},"
|
|
152
|
+
def text_form_hash
|
|
153
|
+
attribute_hash(@attr_field ,'wysiwyg_field')
|
|
154
154
|
end
|
|
155
155
|
|
|
156
|
-
def
|
|
157
|
-
|
|
158
|
-
"#{label_type}," +
|
|
159
|
-
"#{placeholder_type}}\n\t\t\t},"
|
|
156
|
+
def integer_form_hash
|
|
157
|
+
attribute_hash(@attr_field, 'number_field')
|
|
160
158
|
end
|
|
161
159
|
|
|
162
|
-
def
|
|
163
|
-
|
|
164
|
-
"#{model_type(resource_class_name(@attr_field))}," +
|
|
165
|
-
"#{label_type}," +
|
|
166
|
-
"#{placeholder_type}}\n\t\t\t},"
|
|
160
|
+
def boolean_form_hash
|
|
161
|
+
attribute_hash(@attr_field, 'boolean')
|
|
167
162
|
end
|
|
168
163
|
|
|
169
|
-
def
|
|
170
|
-
|
|
171
|
-
"#{model_type(through_model)}," +
|
|
172
|
-
"#{label_type}," +
|
|
173
|
-
"#{placeholder_type}}\n\t\t\t},"
|
|
164
|
+
def datepicker_form_hash
|
|
165
|
+
attribute_hash(@attr_field, 'datepicker')
|
|
174
166
|
end
|
|
175
167
|
|
|
176
|
-
def
|
|
177
|
-
|
|
168
|
+
def file_field_form_hash
|
|
169
|
+
attribute_hash(gallery_name.pluralize, 'adminpanel_file_field')
|
|
178
170
|
end
|
|
179
171
|
|
|
180
|
-
def
|
|
181
|
-
|
|
172
|
+
def belongs_to_form_hash
|
|
173
|
+
attribute_hash(belongs_to_field(@attr_field), 'belongs_to', resource_class_name(@attr_field))
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def has_many_form_hash
|
|
177
|
+
attribute_hash(has_many_field(resource_class_name(@attr_field)), 'has_many', 'has_many model')
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def attribute_hash(name, type, model = '')
|
|
181
|
+
if model != ''
|
|
182
|
+
model = model_type(model) + ",\n"
|
|
183
|
+
end
|
|
184
|
+
"{\n" +
|
|
185
|
+
indent("'#{name}'" + " => {\n", 2) +
|
|
186
|
+
indent(form_type(type), 4) + ",\n" +
|
|
187
|
+
indent(label_type, 4) + ",\n" +
|
|
188
|
+
indent(placeholder_type, 4) + ",\n" +
|
|
189
|
+
indent(model, 4) +
|
|
190
|
+
indent("}\n", 2) +
|
|
191
|
+
'}'
|
|
182
192
|
end
|
|
183
193
|
|
|
184
194
|
def form_type(type)
|
|
185
|
-
"
|
|
195
|
+
"'type' => '#{type}'"
|
|
186
196
|
end
|
|
187
197
|
|
|
188
198
|
def label_type
|
|
189
|
-
"
|
|
199
|
+
"'label' => '#{@attr_field}'"
|
|
190
200
|
end
|
|
191
201
|
|
|
192
202
|
def placeholder_type
|
|
193
|
-
"
|
|
203
|
+
"'placeholder' => '#{@attr_field}'"
|
|
194
204
|
end
|
|
195
205
|
|
|
196
206
|
def model_type(type)
|
|
197
|
-
"
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def migration_string(field, type)
|
|
201
|
-
if type == "datepicker"
|
|
202
|
-
"t.string :#{field}"
|
|
203
|
-
elsif type == "wysiwyg"
|
|
204
|
-
"t.text :#{field}"
|
|
205
|
-
elsif type == "belongs_to"
|
|
206
|
-
"t.integer :#{belongs_to_field(field)}"
|
|
207
|
-
elsif type == "images" || type == "has_many" || type == "has_many_through"
|
|
208
|
-
""# no need for an association here.
|
|
209
|
-
else
|
|
210
|
-
"t.#{type} :#{field}"
|
|
211
|
-
end
|
|
207
|
+
"'model' => 'Adminpanel::#{type}'"
|
|
212
208
|
end
|
|
213
209
|
|
|
214
210
|
def has_associations?
|
|
@@ -227,8 +223,6 @@ module Adminpanel
|
|
|
227
223
|
assign_attributes_variables(attribute)
|
|
228
224
|
if @attr_type == "belongs_to"
|
|
229
225
|
association = "#{association}#{belongs_to_association(@attr_field)}"
|
|
230
|
-
elsif @attr_type == "images"
|
|
231
|
-
association = "#{association}#{image_association}"
|
|
232
226
|
elsif @attr_type == "has_many" || @attr_type == "has_many_through"
|
|
233
227
|
association = "#{association}#{has_many_association(@attr_field)}"
|
|
234
228
|
end
|
|
@@ -242,28 +236,16 @@ module Adminpanel
|
|
|
242
236
|
end
|
|
243
237
|
|
|
244
238
|
def has_many_association(field)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
":dependent => :destroy\n\t\t"
|
|
250
|
-
else
|
|
251
|
-
return "has_many :#{models_in_parameter(field).second}\n\t\t" +
|
|
252
|
-
"has_many :#{models_in_parameter(field).first}, " +
|
|
253
|
-
":through => :#{models_in_parameter(field).second}, " +
|
|
254
|
-
":dependent => :destroy\n\t\t"
|
|
255
|
-
end
|
|
239
|
+
return "# has_many :categorizations\n\t\t" +
|
|
240
|
+
"# has_many :#{@attr_field}, " +
|
|
241
|
+
":through => :categorizations, " +
|
|
242
|
+
":dependent => :destroy\n\t\t"
|
|
256
243
|
end
|
|
257
244
|
|
|
258
|
-
def
|
|
259
|
-
generate_gallery
|
|
245
|
+
def get_gallery
|
|
260
246
|
return "\n\t\tmount_images :#{gallery_name.pluralize}\n"
|
|
261
247
|
end
|
|
262
248
|
|
|
263
|
-
def generate_gallery
|
|
264
|
-
generate 'adminpanel:gallery', lower_singularized_name
|
|
265
|
-
end
|
|
266
|
-
|
|
267
249
|
end
|
|
268
250
|
end
|
|
269
251
|
end
|