adminpanel 1.2.12 → 2.0.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 +7 -0
- data/.travis.yml +3 -4
- data/Gemfile +22 -20
- data/README.md +12 -9
- data/adminpanel.gemspec +29 -28
- data/app/assets/fonts/.keep +0 -0
- data/app/assets/javascripts/adminpanel/images_form.js +5 -2
- data/app/assets/javascripts/adminpanel/imagesloaded.js +5 -2
- data/app/assets/javascripts/adminpanel/tables.js +6 -3
- data/app/assets/javascripts/application-admin.js +2 -1
- data/app/assets/stylesheets/adminpanel/{_clearfix.css.scss → _clearfix.css} +0 -0
- data/app/assets/stylesheets/adminpanel/bootstrap.css +2 -2
- data/app/assets/stylesheets/adminpanel/medium-editor.css.scss +1 -1
- data/app/assets/stylesheets/application-admin.css +2 -1
- data/app/controllers/adminpanel/application_controller.rb +28 -21
- data/app/controllers/adminpanel/categories_controller.rb +16 -5
- data/app/controllers/adminpanel/galleries_controller.rb +11 -5
- data/app/controllers/adminpanel/sections_controller.rb +14 -0
- data/app/controllers/adminpanel/users_controller.rb +10 -80
- data/app/controllers/concerns/adminpanel/galleryzable_actions.rb +33 -0
- data/app/controllers/concerns/adminpanel/rest_actions.rb +109 -0
- data/app/helpers/adminpanel/application_helper.rb +0 -1
- data/app/helpers/adminpanel/custom_form_builder.rb +12 -13
- data/app/helpers/adminpanel/router_helper.rb +11 -2
- data/app/helpers/adminpanel/shared_pages_helper.rb +0 -1
- data/app/models/adminpanel/analytic.rb +3 -2
- data/app/models/adminpanel/gallery.rb +8 -4
- data/app/models/adminpanel/group.rb +1 -1
- data/app/models/adminpanel/image.rb +1 -2
- data/app/models/adminpanel/section.rb +19 -10
- data/app/models/adminpanel/user.rb +11 -3
- data/app/models/concerns/adminpanel/base.rb +149 -0
- data/app/models/concerns/adminpanel/galleryzation.rb +66 -0
- data/app/models/contact.rb +16 -9
- data/app/views/adminpanel/analytics/index.html.erb +2 -1
- data/app/views/adminpanel/categories/_categories_table.html.erb +6 -7
- data/app/views/adminpanel/categories/_category_form.html.erb +2 -2
- data/app/views/adminpanel/categories/create.js.erb +2 -2
- data/app/views/adminpanel/categories/index.html.erb +1 -1
- data/app/views/adminpanel/galleries/_galleries_table.html.erb +7 -7
- data/app/views/adminpanel/galleries/index.html.erb +6 -5
- data/app/views/adminpanel/sections/_sections_table.html.erb +2 -2
- data/app/views/adminpanel/sections/edit.html.erb +5 -3
- data/app/views/adminpanel/sections/show.html.erb +3 -3
- data/app/views/adminpanel/sessions/new.html.erb +1 -1
- data/app/views/layouts/_side_menu.html.erb +2 -2
- data/app/views/layouts/_top_bar.html.erb +3 -3
- data/app/views/layouts/admin-login.html.erb +0 -1
- data/app/views/layouts/admin.html.erb +3 -3
- data/app/views/shared/_delete_icon_button.html.erb +16 -0
- data/app/views/shared/_edit_icon_button.html.erb +14 -0
- data/app/views/shared/_error_messages.html.erb +1 -1
- data/app/views/shared/_form_fields.html.erb +15 -13
- data/app/views/shared/_gallery_entries.html.erb +2 -2
- data/app/views/shared/_init_editor.html.erb +5 -2
- data/app/views/shared/_new_resource_button.html.erb +18 -0
- data/app/views/shared/_remote_form_fields.html.erb +1 -1
- data/app/views/shared/_show_icon_button.html.erb +14 -0
- data/app/views/shared/edit.html.erb +3 -3
- data/app/views/shared/index.html.erb +13 -48
- data/app/views/shared/new.html.erb +3 -3
- data/app/views/shared/show.html.erb +5 -5
- data/config/initializers/pluralization_es.rb +16 -0
- data/config/locales/en.yml +89 -0
- data/config/locales/es.yml +4 -4
- data/config/routes.rb +15 -16
- data/lib/adminpanel.rb +8 -8
- data/lib/adminpanel/version.rb +1 -1
- data/lib/generators/adminpanel/gallery/gallery_generator.rb +12 -8
- data/lib/generators/adminpanel/gallery/templates/gallery_template.rb +2 -3
- data/lib/generators/adminpanel/initialize/templates/category_template.rb +2 -3
- data/lib/generators/adminpanel/resource/resource_generator.rb +24 -18
- data/lib/generators/adminpanel/resource/templates/controller.rb +5 -0
- data/lib/generators/adminpanel/resource/templates/resource.rb +3 -3
- data/lib/tasks/adminpanel/adminpanel.rake +43 -90
- data/spec/dummy/app/controllers/adminpanel/mugs_controller.rb +9 -0
- data/spec/dummy/app/controllers/adminpanel/products_controller.rb +12 -0
- data/spec/dummy/app/models/ability.rb +1 -1
- data/spec/dummy/app/models/adminpanel/categorization.rb +1 -2
- data/spec/dummy/app/models/adminpanel/category.rb +18 -19
- data/spec/dummy/app/models/adminpanel/mug.rb +37 -0
- data/spec/dummy/app/models/adminpanel/photo.rb +3 -3
- data/spec/dummy/app/models/adminpanel/product.rb +2 -2
- data/spec/dummy/config/application.rb +2 -11
- data/spec/dummy/config/database.yml +0 -6
- data/spec/dummy/config/environments/development.rb +11 -23
- data/spec/dummy/config/environments/production.rb +40 -32
- data/spec/dummy/config/environments/test.rb +13 -18
- data/spec/dummy/config/initializers/adminpanel_setup.rb +2 -1
- data/spec/dummy/config/locales/.keep +0 -0
- data/spec/dummy/db/schema.rb +68 -2
- data/spec/features/authentication_pages_spec.rb +15 -15
- data/spec/features/galleries_pages_spec.rb +30 -22
- data/spec/features/section_pages_spec.rb +15 -18
- data/spec/features/shared_pages_spec.rb +97 -127
- data/spec/generators/gallery_generator_spec.rb +2 -3
- data/spec/generators/resource_generator_spec.rb +20 -3
- data/spec/models/gallery_spec.rb +2 -2
- data/spec/models/section_spec.rb +8 -15
- data/spec/models/user_spec.rb +23 -39
- data/spec/spec_helper.rb +9 -1
- data/spec/support/factories.rb +52 -0
- data/spec/support/helper_methods.rb +25 -5
- data/spec/tasks/adminpanel_rake_spec.rb +11 -10
- metadata +361 -353
- data/app/assets/fonts/FontAwesome.otf +0 -0
- data/app/assets/fonts/fontawesome-webfont.eot +0 -0
- data/app/assets/fonts/fontawesome-webfont.svg +0 -255
- data/app/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/app/assets/fonts/fontawesome-webfont.woff +0 -0
- data/app/assets/stylesheets/adminpanel/colorpicker.css +0 -7
- data/app/assets/stylesheets/adminpanel/elfinder.min.css +0 -59
- data/app/assets/stylesheets/adminpanel/font-awesome.min.css +0 -34
- data/app/helpers/adminpanel/pluralizations_helper.rb +0 -25
- data/app/helpers/adminpanel/rest_actions_helper.rb +0 -128
- data/app/views/adminpanel/galleries/delete.html.erb +0 -2
- data/app/views/adminpanel/galleries/edit.html.erb +0 -19
- data/app/views/adminpanel/galleries/new.html.erb +0 -18
- data/app/views/adminpanel/galleries/show.html.erb +0 -18
- data/app/views/adminpanel/galleries/update.html.erb +0 -2
- data/lib/adminpanel/active_record/adminpanel_extension.rb +0 -187
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/support/define_factory_models.rb +0 -45
- data/spec/support/submit_forms_without_button.rb +0 -17
- data/spec/support/test_database.rb +0 -76
- data/spec/uploaders/gallery_uploader_spec.rb +0 -37
- data/spec/uploaders/image_uploader_spec.rb +0 -31
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
ActiveSupport::Inflector.inflections(:es) do |inflect|
|
|
2
|
+
inflect.plural(/$/, 's')
|
|
3
|
+
inflect.plural(/([^aeéiou])$/i, '\1es')
|
|
4
|
+
inflect.plural(/([aeiou]s)$/i, '\1')
|
|
5
|
+
inflect.plural(/z$/i, 'ces')
|
|
6
|
+
inflect.plural(/á([sn])$/i, 'a\1es')
|
|
7
|
+
inflect.plural(/é([sn])$/i, 'e\1es')
|
|
8
|
+
inflect.plural(/í([sn])$/i, 'i\1es')
|
|
9
|
+
inflect.plural(/ó([sn])$/i, 'o\1es')
|
|
10
|
+
inflect.plural(/ú([sn])$/i, 'u\1es')
|
|
11
|
+
|
|
12
|
+
inflect.singular(/s$/, '')
|
|
13
|
+
inflect.singular(/es$/, '')
|
|
14
|
+
|
|
15
|
+
inflect.irregular('el', 'los')
|
|
16
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
en:
|
|
2
|
+
model:
|
|
3
|
+
Analytics: "Google Analytics"
|
|
4
|
+
Gallery: "Gallery"
|
|
5
|
+
Categories: "Categories"
|
|
6
|
+
attributes:
|
|
7
|
+
adminproject_id: "Proyect"
|
|
8
|
+
brief: "Brief Description"
|
|
9
|
+
body: "Body"
|
|
10
|
+
category_id: "Category"
|
|
11
|
+
client_id: "Client"
|
|
12
|
+
description: "Description"
|
|
13
|
+
email: "Email"
|
|
14
|
+
file: "File"
|
|
15
|
+
group_id: "Group"
|
|
16
|
+
name: "Name"
|
|
17
|
+
password: "Password"
|
|
18
|
+
password_confirmation: "Confirm password"
|
|
19
|
+
password_digest: "Confirm password"
|
|
20
|
+
username: "Nombre de usuario"
|
|
21
|
+
errors:
|
|
22
|
+
one: "%{model} can't be saved, 1 error"
|
|
23
|
+
other: "%{model} can't be saved, %{count} errors"
|
|
24
|
+
activerecord:
|
|
25
|
+
errors:
|
|
26
|
+
messages:
|
|
27
|
+
not_phone: "isn't a phone (10 numbers)"
|
|
28
|
+
blank: "can't be blank"
|
|
29
|
+
confirmation: "Must be the same"
|
|
30
|
+
invalid: "isn't an email"
|
|
31
|
+
not_a_number: "not a number"
|
|
32
|
+
taken: "alredy in use"
|
|
33
|
+
too_long: "too long"
|
|
34
|
+
too_short: "too short, minimum is 6 characters"
|
|
35
|
+
time:
|
|
36
|
+
formats:
|
|
37
|
+
graphic: "%Y-%m-%d %H:%M:%S"
|
|
38
|
+
long: "%d/%m/%Y %l:%M:%S %p"
|
|
39
|
+
short: "%d de %B de %Y"
|
|
40
|
+
estimate: "%Y-%m-%d"
|
|
41
|
+
Add Image: "Add Image"
|
|
42
|
+
Write description here: "Write descrition here..."
|
|
43
|
+
Gallery: "Gallery"
|
|
44
|
+
Panel title: "Panel Administrativo CoDN"
|
|
45
|
+
actions: "Actions"
|
|
46
|
+
action:
|
|
47
|
+
add: "Add"
|
|
48
|
+
create: "Create"
|
|
49
|
+
close: "Close"
|
|
50
|
+
show: "Show"
|
|
51
|
+
submitting: "Submitting..."
|
|
52
|
+
save: "Save"
|
|
53
|
+
save_success: "Has been saved successfully"
|
|
54
|
+
update: "Update"
|
|
55
|
+
delete: "Delete"
|
|
56
|
+
view: "View"
|
|
57
|
+
delete confirmation: "Are you sure you wan't to delete?"
|
|
58
|
+
is_true: 'Yes'
|
|
59
|
+
is_false: 'No'
|
|
60
|
+
authentication:
|
|
61
|
+
welcome: "Welcome! Please, submit your credentials"
|
|
62
|
+
signin_error: "Email and/or Password wrong."
|
|
63
|
+
signin_success: "Welcome!"
|
|
64
|
+
not_authorized: "You don't have access to that"
|
|
65
|
+
gallery:
|
|
66
|
+
new: "Add Image"
|
|
67
|
+
success: "Image has been saved"
|
|
68
|
+
deleted: "Image has been deleted"
|
|
69
|
+
moved : "Gallery position has been updated"
|
|
70
|
+
not-moved: "Image wasn't able to move"
|
|
71
|
+
image: "Image"
|
|
72
|
+
position: "Position"
|
|
73
|
+
action: "Action"
|
|
74
|
+
user:
|
|
75
|
+
new: "Add User"
|
|
76
|
+
success: "User has been saved"
|
|
77
|
+
section:
|
|
78
|
+
name: "Name"
|
|
79
|
+
description: "Description"
|
|
80
|
+
edit: "Edit Section"
|
|
81
|
+
default: "Without Section"
|
|
82
|
+
image: "Image"
|
|
83
|
+
session:
|
|
84
|
+
password: "Password"
|
|
85
|
+
email: "Email"
|
|
86
|
+
other:
|
|
87
|
+
add : "Add %{model}"
|
|
88
|
+
choose: "Chooose related %{model}"
|
|
89
|
+
no description: "Don't have a description yet"
|
data/config/locales/es.yml
CHANGED
|
@@ -6,6 +6,7 @@ es:
|
|
|
6
6
|
attributes:
|
|
7
7
|
adminproject_id: "Proyecto"
|
|
8
8
|
brief: "Pequeña descripción"
|
|
9
|
+
body: "Contenido"
|
|
9
10
|
category_id: "Categoría"
|
|
10
11
|
client_id: "Cliente"
|
|
11
12
|
description: "Descripción"
|
|
@@ -23,6 +24,7 @@ es:
|
|
|
23
24
|
activerecord:
|
|
24
25
|
errors:
|
|
25
26
|
messages:
|
|
27
|
+
not_phone: 'no es un teléfono (10 números)'
|
|
26
28
|
blank: "no puede estar vacío"
|
|
27
29
|
confirmation: "Deben ser iguales"
|
|
28
30
|
invalid: "no es un correo"
|
|
@@ -38,7 +40,6 @@ es:
|
|
|
38
40
|
estimate: "%Y-%m-%d"
|
|
39
41
|
Add Image: "Agregar Imagen"
|
|
40
42
|
Write description here: "Escriba la descripción aquí"
|
|
41
|
-
Gallery: "Galería"
|
|
42
43
|
Panel title: "Panel Administrativo"
|
|
43
44
|
actions: "Acciones"
|
|
44
45
|
action:
|
|
@@ -61,6 +62,7 @@ es:
|
|
|
61
62
|
signin_success: "Bienvenido!"
|
|
62
63
|
not_authorized: 'No tienes permisos para acceder'
|
|
63
64
|
gallery:
|
|
65
|
+
name: 'Galeria'
|
|
64
66
|
new: "Agregar Imagen"
|
|
65
67
|
success: "La imagen ha sido guardada"
|
|
66
68
|
deleted: "La imagen ha sido eliminada"
|
|
@@ -83,7 +85,5 @@ es:
|
|
|
83
85
|
email: "Correo electrónico"
|
|
84
86
|
other:
|
|
85
87
|
add : "Agregar %{model}"
|
|
86
|
-
choose: "Selecciona %{model}
|
|
88
|
+
choose: "Selecciona las relaciones con %{model}"
|
|
87
89
|
no description: "No tiene descripción aún"
|
|
88
|
-
key:
|
|
89
|
-
telephone: 'Teléfono'
|
data/config/routes.rb
CHANGED
|
@@ -5,37 +5,36 @@ Adminpanel::Engine.routes.draw do
|
|
|
5
5
|
Adminpanel.displayable_resources.each do |resource|
|
|
6
6
|
case resource
|
|
7
7
|
when :sections
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
resources :users
|
|
8
|
+
# sections cannot be created or destroyed
|
|
9
|
+
resources :sections, resources_parameters(resource).merge({:except => [:new, :create, :destroy] })
|
|
11
10
|
when :galleries
|
|
12
|
-
resources
|
|
11
|
+
# galleries gallery is different from normal resources galleries
|
|
12
|
+
resources :galleries, resources_parameters(resource) do
|
|
13
13
|
member do
|
|
14
|
-
put :move_better, :as =>
|
|
15
|
-
put :move_worst, :as =>
|
|
14
|
+
put :move_better, :as => 'move_to_better'
|
|
15
|
+
put :move_worst, :as => 'move_to_worst'
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
|
-
when :categories
|
|
19
|
-
resources :categories
|
|
20
18
|
when :analytics
|
|
21
|
-
resources :analytics, :only => [:index]
|
|
19
|
+
resources :analytics, resources_parameters(resource).merge({:only => [:index]})
|
|
22
20
|
else
|
|
23
|
-
if !
|
|
24
|
-
resources
|
|
25
|
-
resources
|
|
21
|
+
if !gallery_children(resource).nil?
|
|
22
|
+
# make the resources gallery routes
|
|
23
|
+
resources gallery_children(resource).to_sym, :only => [:index] do
|
|
26
24
|
member do
|
|
27
25
|
put :move_better, :as => 'move_to_better'
|
|
28
26
|
put :move_worst, :as => 'move_to_worst'
|
|
29
27
|
end
|
|
30
28
|
end
|
|
31
|
-
else
|
|
32
|
-
resources resource
|
|
33
29
|
end
|
|
30
|
+
|
|
31
|
+
# normal resource
|
|
32
|
+
resources resource, resources_parameters(resource)
|
|
34
33
|
end
|
|
35
34
|
end
|
|
36
35
|
|
|
37
36
|
root :to => "#{Adminpanel.displayable_resources.first}#index"
|
|
38
37
|
resources :sessions, :only => [:new, :create, :destroy]
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
delete '/signout', :to => 'sessions#destroy', :as => "signout"
|
|
39
|
+
get '/signin', :to => 'sessions#new', :as => "signin"
|
|
41
40
|
end
|
data/lib/adminpanel.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require '
|
|
1
|
+
require 'adminpanel/version'
|
|
2
|
+
require 'adminpanel/engine'
|
|
3
|
+
require 'inherited_resources'
|
|
4
|
+
require 'carrierwave'
|
|
5
|
+
require 'carrierwave/orm/activerecord'
|
|
6
|
+
require 'google/api_client'
|
|
7
|
+
require 'cancancan'
|
|
8
|
+
require 'font-awesome-rails'
|
|
9
9
|
|
|
10
10
|
module Adminpanel
|
|
11
11
|
end
|
data/lib/adminpanel/version.rb
CHANGED
|
@@ -5,17 +5,20 @@ module Adminpanel
|
|
|
5
5
|
source_root File.expand_path("../templates", __FILE__)
|
|
6
6
|
desc "Generate the resource files necessary to use a model"
|
|
7
7
|
|
|
8
|
-
def
|
|
8
|
+
def generate_model
|
|
9
9
|
template 'gallery_template.rb', "app/models/adminpanel/#{lower_name}.rb"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def
|
|
12
|
+
def generate_uploader
|
|
13
13
|
template 'uploader.rb', "app/uploaders/adminpanel/#{lower_name}_uploader.rb"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def
|
|
17
|
-
migration_template
|
|
18
|
-
|
|
16
|
+
def generate_migration
|
|
17
|
+
migration_template(
|
|
18
|
+
'gallery_migration.rb',
|
|
19
|
+
"db/migrate/create_adminpanel_#{lower_name.pluralize}_table.rb"
|
|
20
|
+
)
|
|
21
|
+
puts "don't forget to add the form_field, the relationship and #{lower_name}s_attributes it to the permited params"
|
|
19
22
|
end
|
|
20
23
|
|
|
21
24
|
private
|
|
@@ -23,13 +26,14 @@ module Adminpanel
|
|
|
23
26
|
name.singularize.downcase
|
|
24
27
|
end
|
|
25
28
|
|
|
29
|
+
def lower_name
|
|
30
|
+
"#{reference_name}file"
|
|
31
|
+
end
|
|
32
|
+
|
|
26
33
|
def class_name
|
|
27
34
|
"#{lower_name.capitalize}"
|
|
28
35
|
end
|
|
29
36
|
|
|
30
|
-
def lower_name
|
|
31
|
-
"#{name.singularize.downcase}file"
|
|
32
|
-
end
|
|
33
37
|
end
|
|
34
38
|
end
|
|
35
39
|
end
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
module Adminpanel
|
|
2
2
|
class <%= class_name %> < ActiveRecord::Base
|
|
3
|
-
|
|
3
|
+
# include Adminpanel::Galleryzation
|
|
4
4
|
|
|
5
5
|
mount_uploader :file, <%= class_name %>Uploader
|
|
6
6
|
|
|
7
|
-
# act_as_a_gallery
|
|
8
7
|
|
|
9
8
|
# def self.relation_field
|
|
10
|
-
# '
|
|
9
|
+
# '<%= reference_name %>_id'
|
|
11
10
|
# end
|
|
12
11
|
|
|
13
12
|
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
module Adminpanel
|
|
2
2
|
class Category < ActiveRecord::Base
|
|
3
|
-
attr_accessible :name, :model #, :product_ids
|
|
4
3
|
|
|
5
4
|
validates_presence_of :model
|
|
6
5
|
validates_presence_of :name
|
|
@@ -32,11 +31,11 @@ module Adminpanel
|
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
def self.display_name
|
|
35
|
-
"
|
|
34
|
+
"Categoria" #singular
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
def self.icon
|
|
39
|
-
"
|
|
38
|
+
"bookmark" #fa-{icon}
|
|
40
39
|
end
|
|
41
40
|
|
|
42
41
|
default_scope { order("model ASC")}
|
|
@@ -8,20 +8,26 @@ module Adminpanel
|
|
|
8
8
|
|
|
9
9
|
argument :fields, :type => :array, :default => "name:string"
|
|
10
10
|
|
|
11
|
-
def
|
|
12
|
-
template 'resource.rb', "app/models/adminpanel/#{
|
|
11
|
+
def generate_model
|
|
12
|
+
template 'resource.rb', "app/models/adminpanel/#{lower_singularized_name}.rb"
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def
|
|
15
|
+
def generate_controller
|
|
16
16
|
if is_a_resource?
|
|
17
17
|
template "controller.rb", "app/controllers/adminpanel/#{pluralized_name}_controller.rb"
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def
|
|
22
|
-
migration_template
|
|
21
|
+
def generate_migrations
|
|
22
|
+
migration_template(
|
|
23
|
+
'migration.rb',
|
|
24
|
+
"db/migrate/create_#{pluralized_name}_table.rb"
|
|
25
|
+
)
|
|
23
26
|
end
|
|
24
27
|
|
|
28
|
+
def print_messages
|
|
29
|
+
puts "don't forget to add :#{pluralized_name} to adminpanel_setup.rb"
|
|
30
|
+
end
|
|
25
31
|
|
|
26
32
|
private
|
|
27
33
|
def is_a_resource?
|
|
@@ -35,19 +41,19 @@ module Adminpanel
|
|
|
35
41
|
end
|
|
36
42
|
|
|
37
43
|
def gallery_name
|
|
38
|
-
"#{
|
|
44
|
+
"#{lower_singularized_name}file"
|
|
39
45
|
end
|
|
40
46
|
|
|
41
|
-
def
|
|
47
|
+
def lower_singularized_name
|
|
42
48
|
name.singularize.downcase
|
|
43
49
|
end
|
|
44
50
|
|
|
45
51
|
def capitalized_resource
|
|
46
|
-
|
|
52
|
+
lower_singularized_name.capitalize
|
|
47
53
|
end
|
|
48
54
|
|
|
49
55
|
def pluralized_name
|
|
50
|
-
"#{
|
|
56
|
+
"#{lower_singularized_name.pluralize}"
|
|
51
57
|
end
|
|
52
58
|
|
|
53
59
|
def belongs_to_field(resource)
|
|
@@ -81,21 +87,21 @@ module Adminpanel
|
|
|
81
87
|
end
|
|
82
88
|
|
|
83
89
|
def symbolized_attributes
|
|
84
|
-
attr_string =
|
|
90
|
+
attr_string = ''
|
|
85
91
|
fields.each do |attribute|
|
|
86
92
|
|
|
87
93
|
assign_attributes_variables(attribute)
|
|
88
94
|
|
|
89
|
-
if @attr_type ==
|
|
90
|
-
attr_string = attr_string + ":#{gallery_name.pluralize}_attributes, "
|
|
91
|
-
elsif @attr_type ==
|
|
95
|
+
if @attr_type == 'images'
|
|
96
|
+
attr_string = attr_string + "{:#{gallery_name.pluralize}_attributes => [:id, :file, :_destroy]}, "
|
|
97
|
+
elsif @attr_type == 'belongs_to'
|
|
92
98
|
attr_string = "#{attr_string}:#{belongs_to_field(@attr_field)}, "
|
|
93
|
-
elsif @attr_type ==
|
|
94
|
-
if @attr_field.split(
|
|
99
|
+
elsif @attr_type == 'has_many' || @attr_type == 'has_many_through'
|
|
100
|
+
if @attr_field.split(',').second == nil
|
|
95
101
|
attr_string = "#{attr_string}:#{has_many_field(@attr_field)}, "
|
|
96
102
|
else
|
|
97
103
|
model_name = models_in_parameter(@attr_field).first
|
|
98
|
-
attr_string = "#{attr_string}:#{has_many_field(model_name)}, "
|
|
104
|
+
attr_string = "#{attr_string} {:#{has_many_field(model_name)} => []}, "
|
|
99
105
|
end
|
|
100
106
|
else
|
|
101
107
|
attr_string = attr_string + ":#{@attr_field}, "
|
|
@@ -184,7 +190,7 @@ module Adminpanel
|
|
|
184
190
|
end
|
|
185
191
|
|
|
186
192
|
def placeholder_type
|
|
187
|
-
"\n\t\t\t\t\t'placeholder' => '#{@attr_field}'"
|
|
193
|
+
"\n\t\t\t\t\t'placeholder' => '#{@attr_field}'\n\t\t\t\t"
|
|
188
194
|
end
|
|
189
195
|
|
|
190
196
|
def model_type(type)
|
|
@@ -255,7 +261,7 @@ module Adminpanel
|
|
|
255
261
|
end
|
|
256
262
|
|
|
257
263
|
def generate_gallery
|
|
258
|
-
generate
|
|
264
|
+
generate 'adminpanel:gallery', lower_singularized_name
|
|
259
265
|
end
|
|
260
266
|
|
|
261
267
|
end
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
module Adminpanel
|
|
2
2
|
class <%= pluralized_name.capitalize %>Controller < Adminpanel::ApplicationController
|
|
3
|
+
|
|
4
|
+
private
|
|
5
|
+
def <%= lower_singularized_name %>_params
|
|
6
|
+
params.require(:<%= lower_singularized_name%>).permit(<%= symbolized_attributes %>)
|
|
7
|
+
end
|
|
3
8
|
end
|
|
4
9
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Adminpanel
|
|
2
2
|
class <%= capitalized_resource %> < ActiveRecord::Base
|
|
3
|
-
|
|
3
|
+
include Adminpanel::Base
|
|
4
4
|
|
|
5
5
|
<%= associations if has_associations? -%>
|
|
6
6
|
|
|
@@ -10,11 +10,11 @@ module Adminpanel
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def self.display_name
|
|
13
|
-
|
|
13
|
+
'<%= capitalized_resource %>' #singular
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
# def self.icon
|
|
17
|
-
# "
|
|
17
|
+
# "truck" # fa-{icon}
|
|
18
18
|
# end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
namespace :adminpanel do
|
|
2
2
|
desc "Interact with adminpanel models :D"
|
|
3
3
|
|
|
4
|
-
task :section, [:
|
|
4
|
+
task :section, [:name, :section, :type] => :environment do |t, args|
|
|
5
5
|
args.with_defaults(:section => "home", :name => "greeting", :type => "")
|
|
6
6
|
puts "Creating #{args[:name]} in #{args[:section]} section"
|
|
7
7
|
|
|
@@ -35,8 +35,8 @@ namespace :adminpanel do
|
|
|
35
35
|
8.times do
|
|
36
36
|
password = password + "#{characters.sample}"
|
|
37
37
|
end
|
|
38
|
-
puts "Creating/overwriting
|
|
39
|
-
user = Adminpanel::User.find_by_email('
|
|
38
|
+
puts "Creating/overwriting webmaster@codn.com with password #{password}"
|
|
39
|
+
user = Adminpanel::User.find_by_email('webmaster@codn.com')
|
|
40
40
|
if !user.nil?
|
|
41
41
|
user.delete
|
|
42
42
|
end
|
|
@@ -47,8 +47,8 @@ namespace :adminpanel do
|
|
|
47
47
|
group.save
|
|
48
48
|
end
|
|
49
49
|
Adminpanel::User.new(
|
|
50
|
-
:email => '
|
|
51
|
-
:name => '
|
|
50
|
+
:email => 'webmaster@codn.com',
|
|
51
|
+
:name => 'Webmaster',
|
|
52
52
|
:password => password,
|
|
53
53
|
:password_confirmation => password,
|
|
54
54
|
:group_id => group.id
|
|
@@ -90,15 +90,13 @@ namespace :adminpanel do
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
task :populate, [:times, :model, :attributes] => :environment do |t, args|
|
|
93
|
+
require 'faker'
|
|
93
94
|
puts "Generating #{args[:times]} records of #{args[:model]}"
|
|
94
95
|
|
|
95
96
|
@model = "adminpanel/#{args[:model]}".classify.constantize
|
|
96
97
|
|
|
97
98
|
attributes = args[:attributes].split(" ")
|
|
98
99
|
|
|
99
|
-
init_variables
|
|
100
|
-
|
|
101
|
-
has_image = false
|
|
102
100
|
args[:times].to_i.times do |time|
|
|
103
101
|
instance = @model.new
|
|
104
102
|
attributes.each do |attribute|
|
|
@@ -106,39 +104,52 @@ namespace :adminpanel do
|
|
|
106
104
|
type = attribute.split(":").second
|
|
107
105
|
|
|
108
106
|
case type
|
|
109
|
-
when
|
|
110
|
-
value =
|
|
111
|
-
|
|
112
|
-
when "category" || "category_name" #generate a category name
|
|
113
|
-
value = @things.sample.pluralize
|
|
107
|
+
when 'name' #generate a name
|
|
108
|
+
value = Faker::Name.name
|
|
114
109
|
|
|
115
|
-
when '
|
|
116
|
-
value =
|
|
110
|
+
when 'category' || 'category_name' #generate a category name
|
|
111
|
+
value = Faker::Commerce.product_name
|
|
117
112
|
|
|
118
|
-
when
|
|
119
|
-
value =
|
|
113
|
+
when 'lorem' || 'description' #large paragraph.
|
|
114
|
+
value = Faker::Lorem.paragraph([*1..10].sample)
|
|
120
115
|
|
|
121
|
-
when
|
|
122
|
-
value = [*1..
|
|
116
|
+
when 'number' #generate a number
|
|
117
|
+
value = [*1..7000].sample
|
|
123
118
|
|
|
124
|
-
when
|
|
119
|
+
when 'url' #generate an url
|
|
120
|
+
value = Faker::Internet.url
|
|
121
|
+
when 'id' #assign field_id it to a random instance of Adminpanel::field
|
|
125
122
|
field = field.downcase.singularize
|
|
126
123
|
if field != 'category'
|
|
127
|
-
value = "adminpanel/#{field}".classify.constantize.order(
|
|
124
|
+
value = "adminpanel/#{field}".classify.constantize.order('RAND()').first.id
|
|
128
125
|
else
|
|
129
|
-
value = "adminpanel/#{field}".classify.constantize.of_model(@model.display_name).order(
|
|
126
|
+
value = "adminpanel/#{field}".classify.constantize.of_model(@model.display_name).order('RAND()').first.id
|
|
130
127
|
end
|
|
131
128
|
field = "#{field}_id"
|
|
132
129
|
|
|
133
|
-
when
|
|
134
|
-
value =
|
|
130
|
+
when 'email' #generates a random email
|
|
131
|
+
value = Faker::Internet.email
|
|
132
|
+
|
|
133
|
+
when 'lat_mid'
|
|
134
|
+
value = float_random(21.046929, 20.903954)
|
|
135
|
+
when 'lng_mid'
|
|
136
|
+
value = float_random(-89.699819, -89.567296)
|
|
135
137
|
|
|
136
|
-
|
|
137
|
-
value =
|
|
138
|
+
when 'lat'
|
|
139
|
+
value = Faker::Address.latitude
|
|
140
|
+
when 'lng'
|
|
141
|
+
value = Faker::Address.longitude
|
|
142
|
+
|
|
143
|
+
when 'image' || 'images'
|
|
144
|
+
3.times do
|
|
145
|
+
instance.send("#{@model.name.demodulize.downcase}files").build
|
|
146
|
+
end
|
|
147
|
+
else #no type || not found
|
|
148
|
+
value = Faker::Lorem.words([*1..6].sample).join(' ') #lorem random short sentence
|
|
138
149
|
|
|
139
150
|
end
|
|
140
151
|
|
|
141
|
-
if(type !=
|
|
152
|
+
if(type != 'image')
|
|
142
153
|
instance.send("#{field}=", value)
|
|
143
154
|
end
|
|
144
155
|
end
|
|
@@ -146,7 +157,6 @@ namespace :adminpanel do
|
|
|
146
157
|
instance.save(:validate => false)
|
|
147
158
|
|
|
148
159
|
change_dates(instance)
|
|
149
|
-
|
|
150
160
|
end
|
|
151
161
|
|
|
152
162
|
end
|
|
@@ -172,70 +182,13 @@ private
|
|
|
172
182
|
").save\n"
|
|
173
183
|
end
|
|
174
184
|
|
|
175
|
-
def generate_lorem
|
|
176
|
-
value = "#{@lorem.sample}"
|
|
177
|
-
[*60..80].sample.times do
|
|
178
|
-
value = "#{value} #{@lorem.sample}"
|
|
179
|
-
end
|
|
180
|
-
"#{value}."
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def generate_lorem_name
|
|
184
|
-
value = "#{@lorem.sample}"
|
|
185
|
-
[*0..3].sample.times do
|
|
186
|
-
value = "#{value} #{@lorem.sample}"
|
|
187
|
-
end
|
|
188
|
-
"#{value.titleize}."
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def generate_email
|
|
192
|
-
"#{@names.sample.first}#{@l_names.sample}@#{@domains.sample}"
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
def generate_name
|
|
196
|
-
"#{@prefixes.sample} #{@names.sample} #{@l_names.sample}"
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
def generate_thing
|
|
200
|
-
"#{@adjective_denominations} #{@things.sample}"
|
|
201
|
-
end
|
|
202
|
-
|
|
203
185
|
def change_dates(instance)
|
|
204
|
-
date = rand(
|
|
186
|
+
date = rand(Date.parse('2010-01-01')..Date.today)
|
|
205
187
|
instance.update_attribute(:created_at, date)
|
|
206
188
|
instance.update_attribute(:updated_at, date)
|
|
207
189
|
end
|
|
208
190
|
|
|
209
|
-
def
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
@lorem = %W[Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
|
|
214
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
|
|
215
|
-
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
|
|
216
|
-
ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
|
|
217
|
-
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
|
|
218
|
-
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
|
|
219
|
-
est laborum. Sed dapibus condimentum tempor. Curabitur tortor libero,
|
|
220
|
-
malesuada ac varius at, adipiscing non ante. Ut at neque vitae massa
|
|
221
|
-
volutpat bibendum a vel purus. Cras adipiscing accumsan placerat. Praesent
|
|
222
|
-
rhoncus pellentesque felis, vel faucibus ipsum convallis dictum. Donec
|
|
223
|
-
congue vitae risus quis sagittis. Interdum et malesuada fames ac ante
|
|
224
|
-
ipsum primis in faucibus. Suspendisse rhoncus tortor ut urna eleifend
|
|
225
|
-
molestie. Phasellus in viverra tortor. Pellentesque sagittis tortor tortor,
|
|
226
|
-
at auctor risus elementum non. Morbi sagittis ante tincidunt congue
|
|
227
|
-
fermentum. Quisque ac tellus in lacus interdum ultrices. Mauris ornare
|
|
228
|
-
justo nec sapien tempor, sit amet dapibus massa tincidunt. Interdum et
|
|
229
|
-
malesuada fames ac ante ipsum primis in faucibus. Nullam sodales ac mauris
|
|
230
|
-
eget egestas. Maecenas rhoncus ac metus quis condimentum. Vestibulum
|
|
231
|
-
consequat lacus nulla, eu varius leo consectetur vitae. Pellentesque vitae
|
|
232
|
-
sem mauris. Suspendisse ornare, dui eget elementum aliquam, augue neque
|
|
233
|
-
condimentum leo, nec ullamcorper lectus massa quis nibh. Etiam id egestas
|
|
234
|
-
mauris, eget eleifend enim.
|
|
235
|
-
]
|
|
236
|
-
@domains = %W[codn.com gmail.com hotmail.com codn.mx codn.com.mx]
|
|
237
|
-
@adjective_denominations = %W[Nice Pretty Good Ugly Expensive Cheap Useful]
|
|
238
|
-
@things = %W[T-shirt Cellphone Laptop iPhone Android Beer Belt Headphone
|
|
239
|
-
Apple\ TV iMac Macbook\ pro iPod\ touch Github's\ octocat Mug Template
|
|
240
|
-
]
|
|
241
|
-
end
|
|
191
|
+
def float_random(min_number, max_number)
|
|
192
|
+
width = max_number - min_number
|
|
193
|
+
return (rand*width)+min_number
|
|
194
|
+
end
|