adminpanel 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/README.md +9 -6
- data/Rakefile +1 -1
- data/app/helpers/adminpanel/application_helper.rb +2 -2
- data/app/helpers/adminpanel/custom_form_builder.rb +45 -9
- data/app/helpers/adminpanel/shared_pages_helper.rb +10 -3
- data/app/models/adminpanel/gallery.rb +6 -0
- data/app/models/adminpanel/image.rb +3 -8
- data/app/models/adminpanel/section.rb +16 -6
- data/app/uploaders/adminpanel/image_uploader.rb +2 -2
- data/app/views/adminpanel/categories/_categories_table.html.erb +1 -1
- data/app/views/adminpanel/categories/index.html.erb +9 -8
- data/app/views/adminpanel/galleries/edit.html.erb +3 -10
- data/app/views/adminpanel/galleries/index.html.erb +2 -2
- data/app/views/adminpanel/galleries/new.html.erb +3 -3
- data/app/views/adminpanel/sections/edit.html.erb +11 -15
- data/app/views/shared/_form_fields.html.erb +16 -9
- data/app/views/shared/_image_fields.html.erb +2 -23
- data/app/views/shared/_init_editor.html.erb +12 -12
- data/app/views/shared/show.html.erb +4 -3
- data/config/locales/es.yml +3 -0
- data/lib/adminpanel.rb +1 -1
- data/lib/adminpanel/active_record/adminpanel_extension.rb +142 -0
- data/lib/adminpanel/version.rb +1 -1
- data/lib/generators/adminpanel/gallery/gallery_generator.rb +41 -0
- data/lib/generators/adminpanel/gallery/templates/gallery_migration.rb +11 -0
- data/lib/generators/adminpanel/gallery/templates/gallery_template.rb +8 -0
- data/lib/generators/adminpanel/gallery/templates/uploader.rb +86 -0
- data/lib/generators/adminpanel/initialize/initialize_generator.rb +22 -12
- data/lib/generators/adminpanel/initialize/templates/create_adminpanel_categories_table.rb +1 -1
- data/lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb +3 -4
- data/lib/generators/adminpanel/initialize/templates/section_uploader.rb +86 -0
- data/lib/generators/adminpanel/resource/resource_generator.rb +72 -22
- data/lib/tasks/adminpanel/adminpanel.rake +1 -1
- data/spec/dummy/.gitignore +2 -1
- data/spec/dummy/app/controllers/adminpanel/categories_controller.rb +2 -2
- data/spec/dummy/app/controllers/adminpanel/products_controller.rb +3 -3
- data/spec/dummy/app/models/adminpanel/categorization.rb +17 -17
- data/spec/dummy/app/models/adminpanel/photo.rb +8 -0
- data/spec/dummy/app/models/adminpanel/product.rb +49 -26
- data/spec/dummy/app/uploader/adminpanel/photo_uploader.rb +86 -0
- data/spec/dummy/app/uploader/adminpanel/section_uploader.rb +86 -0
- data/spec/features/section_pages_spec.rb +4 -4
- data/spec/features/shared_pages_spec.rb +15 -15
- data/spec/generators/gallery_generator_spec.rb +53 -0
- data/spec/generators/initialize_generator_spec.rb +19 -12
- data/spec/generators/resource_generator_spec.rb +44 -37
- data/spec/support/define_factory_models.rb +3 -5
- data/spec/support/test_database.rb +8 -3
- data/spec/tasks/adminpanel_rake_spec.rb +5 -5
- metadata +18 -7
- data/app/helpers/adminpanel/class_definitions_helper.rb +0 -10
- data/app/views/adminpanel/sections/_image_fields.html.erb +0 -24
- data/lib/adminpanel/active_record_extension.rb +0 -123
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Adminpanel
|
2
2
|
|
3
|
-
This gem is developed to be a CMS for Ruby 1.8.7 and Rails 3.2.12
|
3
|
+
This gem is developed to be a CMS for Ruby 1.8.7 and Rails 3.2.12
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/adminpanel.png)](http://badge.fury.io/rb/adminpanel@2x)
|
6
6
|
[![Travis CI ](https://api.travis-ci.org/joseramonc/adminpanel.png) ](https://travis-ci.org/joseramonc/adminpanel)
|
@@ -17,11 +17,14 @@ And then execute:
|
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
|
-
In you application.rb
|
20
|
+
In you application.rb
|
21
|
+
|
22
|
+
config.default_locale = :es
|
21
23
|
|
22
|
-
config.i18n.default_locale = :es
|
23
24
|
no other language is currently supported, but pull requests are welcome.
|
24
25
|
|
26
|
+
The create a directory called `adminpanel` under `app/controllers` this is the directory where your admin resources will go.
|
27
|
+
|
25
28
|
Then run:
|
26
29
|
|
27
30
|
rails g adminpanel:initialize
|
@@ -48,13 +51,13 @@ Please make sure that you have (rmagick) ImageMagick -v 2.13.2 installed before
|
|
48
51
|
###Google Analytics Integration
|
49
52
|
|
50
53
|
To take advantage of the Integration with the Google Analytics Service you should add the analytics script to the public side of your application and then create an intializer called when you setup your authentication with Google
|
51
|
-
|
54
|
+
|
52
55
|
# The configuration values you can provide are
|
53
56
|
|
54
57
|
Adminpanel.setup do |config|
|
55
58
|
# You get this from the Google Analytics Dashboard, this configuration is required.
|
56
59
|
config.analytics_profile_id = '12341234'
|
57
|
-
# The next configuration is the file used to establish server to server authentication/authorization
|
60
|
+
# The next configuration is the file used to establish server to server authentication/authorization
|
58
61
|
# you need to download this file from the Google Developers Console
|
59
62
|
# and place it inside your application, this configuration is required.
|
60
63
|
config.analytics_key_filename = '12345ABCDE.p12'
|
@@ -64,7 +67,7 @@ To take advantage of the Integration with the Google Analytics Service you shoul
|
|
64
67
|
|
65
68
|
Currently it only shows the visits from the last week, but more integrations will come.
|
66
69
|
|
67
|
-
For more information about using the Google API visit
|
70
|
+
For more information about using the Google API visit
|
68
71
|
* [Google Analytics API](https://developers.google.com/analytics/devguides/reporting/core/v3/)
|
69
72
|
* [Google API Ruby Client](https://github.com/google/google-api-ruby-client)
|
70
73
|
* [Google OAuth 2.0](https://developers.google.com/accounts/docs/OAuth2)
|
data/Rakefile
CHANGED
@@ -29,11 +29,11 @@ module Adminpanel
|
|
29
29
|
section_name.downcase == 'login'
|
30
30
|
end
|
31
31
|
|
32
|
-
def link_to_add_fields(name, f, association
|
32
|
+
def link_to_add_fields(name, f, association)
|
33
33
|
new_object = f.object.send(association).klass.new
|
34
34
|
id = new_object.object_id
|
35
35
|
fields = f.fields_for(association, new_object, :child_index => id) do |builder|
|
36
|
-
render("shared/"
|
36
|
+
render("shared/image_fields", :f => builder)
|
37
37
|
end
|
38
38
|
link_to(content_tag(:div, content_tag(:button,
|
39
39
|
content_tag(:h6, name, :id => "add-image-button"),
|
@@ -3,7 +3,7 @@ module Adminpanel
|
|
3
3
|
|
4
4
|
alias_method :text_field_original, :text_field
|
5
5
|
alias_method :radio_button_original, :radio_button
|
6
|
-
alias_method :
|
6
|
+
alias_method :parent_file_field, :file_field
|
7
7
|
|
8
8
|
def text_field(name, *args)
|
9
9
|
options = args.extract_options!
|
@@ -18,17 +18,53 @@ module Adminpanel
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def file_field(name, *args)
|
22
22
|
options = args.extract_options!
|
23
|
+
label = options['label']
|
24
|
+
options.delete('label')
|
23
25
|
|
24
|
-
options.reverse_merge! :class => "span7"
|
25
|
-
options.reverse_merge! :label => name
|
26
|
-
label = options[:label]
|
27
|
-
options.delete(:label)
|
28
26
|
|
29
|
-
@template.content_tag :div, :class => "control-group" do
|
27
|
+
image = @template.content_tag :div, :class => "control-group" do
|
30
28
|
@template.content_tag(:label, label, :class => "control-label") +
|
31
|
-
@template.content_tag(:div,
|
29
|
+
@template.content_tag(:div, super(name, *args << options), :class => "controls")
|
30
|
+
end
|
31
|
+
|
32
|
+
if object.new_record?
|
33
|
+
image
|
34
|
+
else
|
35
|
+
thumbnail = @template.content_tag :div, :class => 'control-group' do
|
36
|
+
@template.content_tag :div, :class => 'controls' do
|
37
|
+
@template.image_tag object.send("#{name}_url", :thumb)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
"#{thumbnail}#{image}".html_safe
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def gallery_field(name, *args)
|
46
|
+
options = args.extract_options!
|
47
|
+
label = options['label']
|
48
|
+
options.delete('label')
|
49
|
+
|
50
|
+
@template.content_tag :div, :class => "control-group" do
|
51
|
+
label = @template.content_tag(:label, label, :class => "control-label")
|
52
|
+
input = @template.content_tag :div, :class => "controls" do
|
53
|
+
input = parent_file_field(name, *args << options)
|
54
|
+
hidden_input = hidden_field(:_destroy)
|
55
|
+
delete_button = @template.content_tag(:button, I18n.t("action.delete"), :class => "btn btn-danger remove_fields")
|
56
|
+
|
57
|
+
if object.new_record?
|
58
|
+
"#{input}#{hidden_input}#{delete_button}".html_safe
|
59
|
+
else
|
60
|
+
thumbnail = @template.content_tag :div, :class => 'control-group' do
|
61
|
+
@template.image_tag object.send("#{name}_url", :thumb)
|
62
|
+
end
|
63
|
+
|
64
|
+
"#{thumbnail}#{input}#{hidden_input}#{delete_button}".html_safe
|
65
|
+
end
|
66
|
+
end
|
67
|
+
"#{label}#{input}".html_safe
|
32
68
|
end
|
33
69
|
end
|
34
70
|
|
@@ -91,7 +127,7 @@ module Adminpanel
|
|
91
127
|
options = args.extract_options!
|
92
128
|
|
93
129
|
options.reverse_merge! :class => "span7"
|
94
|
-
|
130
|
+
|
95
131
|
options.reverse_merge! :include_blank => "(Seleccione por favor)";
|
96
132
|
label = options[:label]
|
97
133
|
options.delete(:label)
|
@@ -2,9 +2,9 @@ module Adminpanel
|
|
2
2
|
module SharedPagesHelper
|
3
3
|
def parent_object_name(resource, parent_model)
|
4
4
|
@model.reflect_on_all_associations.each do |association|
|
5
|
-
if association.klass.to_s == parent_model
|
5
|
+
if association.klass.to_s == parent_model
|
6
6
|
if !resource.send(association.name).nil?
|
7
|
-
return resource.send(association.name).name
|
7
|
+
return resource.send(association.name).name
|
8
8
|
else
|
9
9
|
return "N/A"
|
10
10
|
end
|
@@ -28,6 +28,13 @@ module Adminpanel
|
|
28
28
|
class_name.to_s.demodulize.downcase
|
29
29
|
end
|
30
30
|
|
31
|
+
def active_tab(index)
|
32
|
+
if index == 0
|
33
|
+
return "active"
|
34
|
+
else
|
35
|
+
return ""
|
36
|
+
end
|
37
|
+
end
|
31
38
|
|
32
39
|
end
|
33
|
-
end
|
40
|
+
end
|
@@ -1,15 +1,10 @@
|
|
1
1
|
module Adminpanel
|
2
2
|
class Image < ActiveRecord::Base
|
3
|
-
extend ClassDefinitionsHelper
|
4
3
|
|
5
|
-
attr_accessible :file
|
6
|
-
|
4
|
+
attr_accessible :file
|
5
|
+
|
7
6
|
validates_presence_of :file
|
8
7
|
|
9
|
-
|
10
|
-
mount_uploader :file, CustomImageUploader
|
11
|
-
else
|
12
|
-
mount_uploader :file, Adminpanel::ImageUploader
|
13
|
-
end
|
8
|
+
mount_uploader :file, Adminpanel::SectionUploader
|
14
9
|
end
|
15
10
|
end
|
@@ -2,15 +2,14 @@ require 'carrierwave'
|
|
2
2
|
require 'carrierwave/orm/activerecord'
|
3
3
|
module Adminpanel
|
4
4
|
class Section < ActiveRecord::Base
|
5
|
-
attr_accessible :description, :has_image, :key, :page, :name, :has_description,
|
5
|
+
attr_accessible :description, :has_image, :key, :page, :name, :has_description,
|
6
|
+
:images_attributes, :file
|
6
7
|
|
7
|
-
|
8
|
-
accepts_nested_attributes_for :images, :allow_destroy => true
|
8
|
+
mount_images :images
|
9
9
|
|
10
|
-
|
11
|
-
validates_length_of :description, :minimum => 10, :maximum => 10, :on => :update, :if => lambda{|section| section.key == "telephone"}
|
10
|
+
validates_length_of :description, :minimum => 10, :maximum => 10, :on => :update, :if => lambda{|section| section.key == I18n.t('key.telephone')}
|
12
11
|
validates_presence_of :description, :minimum => 9, :on => :update, :if => lambda{|section| section.has_description == true}
|
13
|
-
validates :description, :numericality => { :only_integer => true }, :on => :update, :if => lambda{|section| section.key ==
|
12
|
+
validates :description, :numericality => { :only_integer => true }, :on => :update, :if => lambda{|section| section.key == I18n.t('key.telephone')}
|
14
13
|
validates_presence_of :key
|
15
14
|
validates_presence_of :name
|
16
15
|
validates_presence_of :page
|
@@ -19,6 +18,17 @@ module Adminpanel
|
|
19
18
|
|
20
19
|
scope :of_page, lambda{|page| where(:page => page)}
|
21
20
|
|
21
|
+
def self.form_methods
|
22
|
+
[
|
23
|
+
{'description' => {'name' => 'Descripcion'}},
|
24
|
+
{'name' => {'name' => 'name'}},
|
25
|
+
{'key' => {'name' => 'key'}},
|
26
|
+
{'page' => {'name' => 'page'}},
|
27
|
+
# {'key' => {'name' => 'key'}},
|
28
|
+
]
|
29
|
+
|
30
|
+
end
|
31
|
+
|
22
32
|
def simple_name
|
23
33
|
"Section"
|
24
34
|
end
|
@@ -28,7 +28,7 @@ module Adminpanel
|
|
28
28
|
# end
|
29
29
|
|
30
30
|
# Process files as they are uploaded:
|
31
|
-
process :resize_to_fill => [1366, 768]
|
31
|
+
# process :resize_to_fill => [1366, 768]
|
32
32
|
#
|
33
33
|
# def scale(width, height)
|
34
34
|
# # do something
|
@@ -55,4 +55,4 @@ module Adminpanel
|
|
55
55
|
# end
|
56
56
|
|
57
57
|
end
|
58
|
-
end
|
58
|
+
end
|
@@ -7,15 +7,16 @@
|
|
7
7
|
<% current_page = "no-page" %>
|
8
8
|
<% @categories.each_with_index do |category, index| %>
|
9
9
|
<% if current_page != category.model %>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
<li class = "<%= active_tab(index) %>">
|
11
|
+
<%=
|
12
|
+
link_to(
|
13
|
+
(pluralize_es(category.model.capitalize)),
|
14
|
+
"#tab#{index}",
|
15
|
+
"data-toggle" => "tab"
|
16
|
+
)
|
17
|
+
%>
|
18
|
+
</li>
|
17
19
|
<% current_page = category.model %>
|
18
|
-
<% end %>
|
19
20
|
<% end %>
|
20
21
|
<% end %>
|
21
22
|
</ul>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% provide(:page_title, "Editar") %>
|
2
|
-
<% breadcrumb_add(t("Gallery"), galleries_path) %>
|
2
|
+
<% breadcrumb_add(t("model.Gallery"), galleries_path) %>
|
3
3
|
<% breadcrumb_add('Imagen', gallery_path(@gallery)) %>
|
4
4
|
<div class="row-fluid">
|
5
5
|
<div class = "widget widget-padding span12">
|
@@ -8,14 +8,7 @@
|
|
8
8
|
<div class = "widget-forms clearfix">
|
9
9
|
<%= custom_form_for(@gallery, :url => gallery_path(@gallery), :html => {:class => "form-horizontal"}) do |f| %>
|
10
10
|
<%= render 'shared/error_messages', :object => @gallery %>
|
11
|
-
|
12
|
-
<div class="controls">
|
13
|
-
<div class="control-group">
|
14
|
-
<%= image_tag @gallery.file_url(:thumb) %>
|
15
|
-
</div>
|
16
|
-
</div>
|
17
|
-
<% end %>
|
18
|
-
<%= f.adminpanel_file_field :file, :label => "Imagen" -%>
|
11
|
+
<%= f.gallery_field :file %>
|
19
12
|
</div>
|
20
13
|
</div>
|
21
14
|
<div class = "widget-footer">
|
@@ -23,4 +16,4 @@
|
|
23
16
|
</div>
|
24
17
|
<% end -%>
|
25
18
|
</div>
|
26
|
-
</div>
|
19
|
+
</div>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= provide(:page_title, t("model.
|
1
|
+
<%= provide(:page_title, t("model.Gallery")) %>
|
2
2
|
<div class="row-fluid">
|
3
3
|
<%=
|
4
4
|
link_to(
|
@@ -25,7 +25,7 @@
|
|
25
25
|
<div class="widget widget-padding span12">
|
26
26
|
<div class="widget-header">
|
27
27
|
<i class="icon-picture"></i>
|
28
|
-
<h5><%= t("model.
|
28
|
+
<h5><%= t("model.Gallery") %></h5>
|
29
29
|
</div>
|
30
30
|
<div class="widget-body">
|
31
31
|
<div class="dataTables_wrapper form-inline">
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% provide(:page_title, t("gallery.new")) %>
|
2
|
-
<% breadcrumb_add(t("model.
|
2
|
+
<% breadcrumb_add(t("model.Gallery"), galleries_path) %>
|
3
3
|
<div class="row-fluid">
|
4
4
|
<div class = "widget widget-padding span12">
|
5
5
|
<div class = "widget-header"><i class = "icon-picture"></i><h5>Imagen</h5></div>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<div class = "widget-forms clearfix">
|
8
8
|
<%= custom_form_for(@gallery, :url => galleries_path, :html => {:class => "form-horizontal"}) do |f| %>
|
9
9
|
<%= render 'shared/error_messages', :object => @gallery %>
|
10
|
-
<%= f.
|
10
|
+
<%= f.file_field :file, :label => "Imagen" -%>
|
11
11
|
</div>
|
12
12
|
</div>
|
13
13
|
<div class = "widget-footer">
|
@@ -15,4 +15,4 @@
|
|
15
15
|
</div>
|
16
16
|
<% end -%>
|
17
17
|
</div>
|
18
|
-
</div>
|
18
|
+
</div>
|
@@ -10,27 +10,23 @@
|
|
10
10
|
<%= render 'shared/error_messages', :object => @section %>
|
11
11
|
|
12
12
|
<% if @section.has_description %>
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
<%= content_tag(:div, @section.description.html_safe, :class => "editable", "data-placeholder" => t("Write description here")) %>
|
21
|
-
<% end %>
|
22
|
-
</div>
|
23
|
-
</div>
|
13
|
+
<%= f.hidden_field 'description', :id => "description-field", :value => @section.description %>
|
14
|
+
<%= f.wysiwyg_field 'description', 'label' => I18n.t('section.description'), :name => 'description' %>
|
15
|
+
<%= content_for :scripts do %>
|
16
|
+
<script type="text/javascript">
|
17
|
+
<%= render "shared/init_editor", :field_var => 'description', :label => 'description' %>
|
18
|
+
</script>
|
19
|
+
<% end %>
|
24
20
|
<% else %>
|
25
|
-
<%= f.text_field
|
21
|
+
<%= f.text_field 'description', :label => t("section.description") %>
|
26
22
|
<% end %>
|
27
23
|
|
28
24
|
<% if @section.has_image %>
|
29
25
|
<%= f.fields_for :images do |builder| %>
|
30
|
-
<%= render 'image_fields', :f => builder
|
26
|
+
<%= render 'shared/image_fields', :f => builder %>
|
31
27
|
<% end -%>
|
32
28
|
|
33
|
-
<%= link_to_add_fields "Agregar Imagen", f, :images
|
29
|
+
<%= link_to_add_fields "Agregar Imagen", f, :images %>
|
34
30
|
<% end %>
|
35
31
|
</div>
|
36
32
|
</div>
|
@@ -39,4 +35,4 @@
|
|
39
35
|
</div>
|
40
36
|
<% end -%>
|
41
37
|
</div>
|
42
|
-
</div>
|
38
|
+
</div>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
<% if properties["type"] == "wysiwyg_field" %>
|
5
5
|
<% type = properties["type"] %>
|
6
|
-
<% args = properties.except("type"
|
6
|
+
<% args = properties.except("type") %>
|
7
7
|
<%= f.hidden_field attribute, :id => "#{attribute}-field", :value => resource.send(attribute) %>
|
8
8
|
<%= f.send(type, attribute, args) %>
|
9
9
|
<%= content_for :scripts do %>
|
@@ -13,10 +13,10 @@
|
|
13
13
|
<% end %>
|
14
14
|
|
15
15
|
<% elsif properties["type"] == "adminpanel_file_field" %>
|
16
|
-
<%= f.fields_for
|
17
|
-
<%= render 'shared/image_fields', :f => builder
|
16
|
+
<%= f.fields_for(attribute) do |builder| %>
|
17
|
+
<%= render 'shared/image_fields', :f => builder %>
|
18
18
|
<% end -%>
|
19
|
-
<%= link_to_add_fields t("Add Image"), f,
|
19
|
+
<%= link_to_add_fields t("Add Image"), f, attribute %>
|
20
20
|
|
21
21
|
<% elsif properties["type"] == "belongs_to" %>
|
22
22
|
<% args = properties.except("type", "name", "model") %>
|
@@ -24,11 +24,18 @@
|
|
24
24
|
<%= f.select(attribute, (@collections["#{properties["model"]}"].collect{|resource| [resource.name, resource.id]}), args) %>
|
25
25
|
|
26
26
|
<% elsif properties["type"] == "has_many" %>
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
<%#= f.checkbox(collection, relationship) %>
|
28
|
+
<div class="control-group">
|
29
|
+
<div class="control-label">
|
30
|
+
<%= I18n.t('other.choose', :model => pluralize_es(properties["model"].classify.constantize.display_name)) %>
|
31
|
+
</div>
|
32
|
+
<%= hidden_field_tag("#{class_name_downcase(f.object)}[#{relationship_ids(properties["model"])}][]", nil) %>
|
33
|
+
<div class="controls">
|
34
|
+
<% @collections["#{properties["model"]}"].each do |resource| %>
|
35
|
+
<%= f.checkbox(resource, class_name_downcase(f.object) ,relationship_ids(properties["model"])) %>
|
36
|
+
<% end %>
|
37
|
+
</div>
|
38
|
+
</div>
|
32
39
|
|
33
40
|
<% else %>
|
34
41
|
<% type = properties["type"] %>
|