adminpanel 1.2.8 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/adminpanel.gemspec +2 -2
- data/app/controllers/adminpanel/{pages_controller.rb → analytics_controller.rb} +11 -6
- data/app/controllers/adminpanel/application_controller.rb +5 -6
- data/app/controllers/adminpanel/galleries_controller.rb +23 -23
- data/app/controllers/adminpanel/sections_controller.rb +5 -1
- data/app/controllers/adminpanel/sessions_controller.rb +7 -3
- data/app/helpers/adminpanel/application_helper.rb +7 -3
- data/app/helpers/adminpanel/rest_actions_helper.rb +20 -0
- data/app/helpers/adminpanel/router_helper.rb +2 -32
- data/app/helpers/adminpanel/shared_pages_helper.rb +8 -8
- data/app/models/adminpanel/analytic.rb +12 -0
- data/app/models/adminpanel/gallery.rb +48 -43
- data/app/models/adminpanel/section.rb +6 -2
- data/app/models/adminpanel/user.rb +4 -0
- data/app/views/adminpanel/{pages → analytics}/index.html.erb +0 -0
- data/app/views/adminpanel/sessions/new.html.erb +1 -1
- data/app/views/layouts/_side_menu.html.erb +7 -89
- data/app/views/shared/_gallery_entries.html.erb +11 -0
- data/app/views/shared/gallery_entries.js.erb +1 -0
- data/app/views/shared/show.html.erb +21 -9
- data/config/routes.rb +28 -22
- data/lib/adminpanel/active_record/adminpanel_extension.rb +63 -4
- data/lib/adminpanel/engine.rb +7 -2
- data/lib/adminpanel/version.rb +1 -1
- data/lib/generators/adminpanel/gallery/gallery_generator.rb +1 -1
- data/lib/generators/adminpanel/gallery/templates/gallery_template.rb +6 -0
- data/lib/generators/adminpanel/gallery/templates/uploader.rb +2 -2
- data/lib/generators/adminpanel/initialize/initialize_generator.rb +23 -7
- data/lib/generators/adminpanel/initialize/templates/adminpanel_setup.rb +8 -3
- data/lib/generators/adminpanel/initialize/templates/category_template.rb +22 -9
- data/lib/generators/adminpanel/resource/resource_generator.rb +8 -4
- data/lib/tasks/adminpanel/adminpanel.rake +9 -23
- data/spec/dummy/.gitignore +1 -0
- data/spec/dummy/app/models/adminpanel/category.rb +3 -3
- data/spec/dummy/app/models/adminpanel/product.rb +3 -3
- data/spec/dummy/config/initializers/adminpanel_setup.rb +22 -0
- data/spec/features/galleries_pages_spec.rb +3 -28
- data/spec/generators/gallery_generator_spec.rb +40 -44
- data/spec/generators/initialize_generator_spec.rb +46 -19
- data/spec/generators/resource_generator_spec.rb +101 -129
- data/spec/spec_helper.rb +1 -2
- data/spec/tasks/adminpanel_rake_spec.rb +4 -4
- metadata +21 -14
data/Gemfile
CHANGED
data/adminpanel.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 1.3"
|
32
32
|
spec.add_development_dependency "activerecord", "~> 3.2.12"
|
33
|
-
spec.add_development_dependency "rake"
|
33
|
+
spec.add_development_dependency "rake", '10.1.1'
|
34
34
|
spec.add_development_dependency "sqlite3"
|
35
35
|
spec.add_development_dependency "factory_girl", "2.6.4"
|
36
36
|
spec.add_development_dependency "rspec", "~> 2.14.0"
|
@@ -38,5 +38,5 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency "capybara", "1.1.4"
|
39
39
|
spec.add_development_dependency "nokogiri", "1.5.9"
|
40
40
|
spec.add_development_dependency "rubyzip", "0.9.9"
|
41
|
-
spec.add_development_dependency "
|
41
|
+
spec.add_development_dependency "ammeter", "0.2.9"
|
42
42
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Adminpanel
|
2
|
-
class
|
3
|
-
|
2
|
+
class AnalyticsController < Adminpanel::ApplicationController
|
3
|
+
|
4
4
|
skip_before_filter :set_model
|
5
5
|
|
6
6
|
API_VERSION = 'v3'
|
@@ -46,13 +46,13 @@ module Adminpanel
|
|
46
46
|
startDate = DateTime.now.prev_month.strftime("%Y-%m-%d")
|
47
47
|
endDate = DateTime.now.strftime("%Y-%m-%d")
|
48
48
|
|
49
|
-
@visitCount = client.execute(:api_method => analytics.data.ga.get, :parameters => {
|
50
|
-
'ids' => "ga:" + profileID,
|
49
|
+
@visitCount = client.execute(:api_method => analytics.data.ga.get, :parameters => {
|
50
|
+
'ids' => "ga:" + profileID,
|
51
51
|
'start-date' => startDate,
|
52
52
|
'end-date' => endDate,
|
53
53
|
'dimensions' => "ga:day,ga:month",
|
54
54
|
'metrics' => "ga:visits",
|
55
|
-
'sort' => "ga:month,ga:day"
|
55
|
+
'sort' => "ga:month,ga:day"
|
56
56
|
})
|
57
57
|
|
58
58
|
@visits = @visitCount.data.rows.collect do |r|
|
@@ -60,7 +60,12 @@ module Adminpanel
|
|
60
60
|
end
|
61
61
|
|
62
62
|
@visitDates = @visitCount.data.rows.collect { |r| "#{r[0]}/#{r[1]}" }
|
63
|
+
|
63
64
|
end
|
65
|
+
respond_to do |format|
|
66
|
+
format.html
|
67
|
+
format.json {render :json => {:visit_count => @visitCount, :visits => @visits, :visit_dates => @visitDates }}
|
68
|
+
end
|
64
69
|
end
|
65
70
|
end
|
66
|
-
end
|
71
|
+
end
|
@@ -6,11 +6,10 @@ module Adminpanel
|
|
6
6
|
|
7
7
|
include SessionsHelper
|
8
8
|
include RestActionsHelper
|
9
|
-
include RouterHelper
|
10
9
|
|
11
10
|
layout "admin"
|
12
11
|
|
13
|
-
before_filter :signed_in_user, :set_model
|
12
|
+
before_filter :signed_in_user, :set_model
|
14
13
|
|
15
14
|
|
16
15
|
def signed_in_user
|
@@ -26,8 +25,8 @@ module Adminpanel
|
|
26
25
|
super
|
27
26
|
end
|
28
27
|
|
29
|
-
def get_menu_elements
|
30
|
-
|
31
|
-
end
|
28
|
+
# def get_menu_elements
|
29
|
+
# @menu_items = menu_items
|
30
|
+
# end
|
32
31
|
end
|
33
|
-
end
|
32
|
+
end
|
@@ -8,9 +8,9 @@ module Adminpanel
|
|
8
8
|
@gallery = Gallery.find(params[:id])
|
9
9
|
end
|
10
10
|
|
11
|
-
def edit
|
12
|
-
|
13
|
-
end
|
11
|
+
# def edit
|
12
|
+
# @gallery = Gallery.find(params[:id])
|
13
|
+
# end
|
14
14
|
|
15
15
|
def create
|
16
16
|
@gallery = Gallery.new(params[:gallery])
|
@@ -29,15 +29,15 @@ module Adminpanel
|
|
29
29
|
else
|
30
30
|
flash[:warning] = t("gallery.not-moved")
|
31
31
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
format.js do
|
37
|
-
@galleries = Gallery.all
|
38
|
-
render :locals => { :galleries => @galleries }
|
39
|
-
end
|
32
|
+
respond_to do |format|
|
33
|
+
format.html do
|
34
|
+
redirect_to galleries_path
|
40
35
|
end
|
36
|
+
format.js do
|
37
|
+
@galleries = Gallery.all
|
38
|
+
render :locals => { :galleries => @galleries }
|
39
|
+
end
|
40
|
+
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def move_worst
|
@@ -47,15 +47,15 @@ module Adminpanel
|
|
47
47
|
else
|
48
48
|
flash[:warning] = t("gallery.not-moved")
|
49
49
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
format.js do
|
55
|
-
@galleries = Gallery.all
|
56
|
-
render :locals => { :galleries => @galleries }
|
57
|
-
end
|
50
|
+
respond_to do |format|
|
51
|
+
format.html do
|
52
|
+
redirect_to galleries_path
|
58
53
|
end
|
54
|
+
format.js do
|
55
|
+
@galleries = Gallery.all
|
56
|
+
render :locals => { :galleries => @galleries }
|
57
|
+
end
|
58
|
+
end
|
59
59
|
end
|
60
60
|
|
61
61
|
def destroy
|
@@ -74,8 +74,8 @@ module Adminpanel
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
def new
|
78
|
-
|
79
|
-
end
|
77
|
+
# def new
|
78
|
+
# @gallery = Gallery.new
|
79
|
+
# end
|
80
80
|
end
|
81
|
-
end
|
81
|
+
end
|
@@ -16,6 +16,10 @@ module Adminpanel
|
|
16
16
|
|
17
17
|
def edit
|
18
18
|
@section = Section.find(params[:id])
|
19
|
+
respond_to do |format|
|
20
|
+
format.html
|
21
|
+
format.json {render :json => {:section => @section }}
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
def update
|
@@ -43,4 +47,4 @@ module Adminpanel
|
|
43
47
|
@sections = Section.all
|
44
48
|
end
|
45
49
|
end
|
46
|
-
end
|
50
|
+
end
|
@@ -5,16 +5,20 @@ module Adminpanel
|
|
5
5
|
skip_before_filter :signed_in_user, :set_model
|
6
6
|
|
7
7
|
def new
|
8
|
+
respond_to do |format|
|
9
|
+
format.html
|
10
|
+
format.json { render :json => {:session => @session }}
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def create
|
11
15
|
user = User.find_by_email(params[:session][:email].downcase)
|
12
16
|
if user && user.authenticate(params[:session][:password])
|
13
17
|
sign_in user
|
14
|
-
flash[:success] = t("authentication.signin success")
|
18
|
+
flash[:success] = I18n.t("authentication.signin success")
|
15
19
|
redirect_to root_url
|
16
20
|
else
|
17
|
-
flash.now[:error] = t("authentication.signin error")
|
21
|
+
flash.now[:error] = I18n.t("authentication.signin error")
|
18
22
|
render 'new'
|
19
23
|
end
|
20
24
|
end
|
@@ -24,4 +28,4 @@ module Adminpanel
|
|
24
28
|
redirect_to signin_path
|
25
29
|
end
|
26
30
|
end
|
27
|
-
end
|
31
|
+
end
|
@@ -21,8 +21,8 @@ module Adminpanel
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def is_current_section?(
|
25
|
-
|
24
|
+
def is_current_section?(display_name)
|
25
|
+
display_name == params[:controller].classify.constantize.display_name ? 'active' : nil
|
26
26
|
end
|
27
27
|
|
28
28
|
def section_is_login(section_name)
|
@@ -42,7 +42,11 @@ module Adminpanel
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def route_symbol(model_name)
|
45
|
-
model_name.
|
45
|
+
model_name.pluralize.downcase
|
46
|
+
end
|
47
|
+
|
48
|
+
def symbol_class(symbol)
|
49
|
+
"adminpanel/#{symbol.to_s}".classify.constantize
|
46
50
|
end
|
47
51
|
|
48
52
|
def main_root_path
|
@@ -60,6 +60,26 @@ module Adminpanel
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
def move_better
|
64
|
+
respond_to do |format|
|
65
|
+
format.js do
|
66
|
+
resource = @model.find(params[:id])
|
67
|
+
resource.move_to_better_position
|
68
|
+
render 'shared/gallery_entries', :locals => { :collection => @model.where(@model.relation_field.to_sym => resource.send(@model.relation_field)) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def move_worst
|
74
|
+
respond_to do |format|
|
75
|
+
format.js do
|
76
|
+
resource = @model.find(params[:id])
|
77
|
+
resource.move_to_worst_position
|
78
|
+
render 'shared/gallery_entries', :locals => { :collection => @model.where(@model.relation_field.to_sym => resource.send(@model.relation_field)) }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
63
83
|
private
|
64
84
|
|
65
85
|
def set_collections
|
@@ -1,37 +1,7 @@
|
|
1
1
|
module Adminpanel
|
2
2
|
module RouterHelper
|
3
|
-
def
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
def find_resources
|
8
|
-
resources_path
|
9
|
-
if File.directory?(resources_path)
|
10
|
-
files = Dir.entries(resources_path).collect do |f|
|
11
|
-
unless default_controllers.include?(f)
|
12
|
-
file_path = "#{resources_path}#{f}"
|
13
|
-
File.file?(file_path) ? file_path.sub!(resources_path, '').sub!('_controller.rb', '') : nil
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
files.compact!
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def menu_items
|
22
|
-
@menu ||= adminpanel_resources.each.collect { |resource| resource.classify }
|
23
|
-
end
|
24
|
-
|
25
|
-
def default_controllers
|
26
|
-
["application_controller.rb", "sessions_controller.rb", "galleries_controller.rb", "users_controller.rb", "sections_controller.rb", "pages_controller.rb"]
|
27
|
-
end
|
28
|
-
|
29
|
-
def resources_path
|
30
|
-
route = "#{Rails.root.to_s}/app/controllers/adminpanel/"
|
31
|
-
if !File.directory?(route)
|
32
|
-
Dir.mkdir(route)
|
33
|
-
end
|
34
|
-
route
|
3
|
+
def acts_as_a_gallery?(resource)
|
4
|
+
"adminpanel/#{resource}_controller".classify.constantize.resource_class.act_as_a_gallery?
|
35
5
|
end
|
36
6
|
end
|
37
7
|
end
|
@@ -2,14 +2,14 @@ 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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
if association.klass.to_s == parent_model
|
6
|
+
if !resource.send(association.name).nil?
|
7
|
+
return resource.send(association.name).name
|
8
|
+
else
|
9
|
+
return "N/A"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def pluralize_model(class_name)
|
@@ -6,43 +6,43 @@ module Adminpanel
|
|
6
6
|
|
7
7
|
mount_uploader :file, Adminpanel::GalleryUploader
|
8
8
|
validates_presence_of :file
|
9
|
-
before_create :set_position
|
10
|
-
before_destroy :rearrange_positions
|
11
9
|
|
10
|
+
act_as_a_gallery
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
def move_to_better_position
|
13
|
+
if self.position > 1
|
14
|
+
conflicting_gallery = Gallery.find_by_position(position - 1)
|
15
|
+
self.update_attribute(:position, self.position - 1)
|
16
|
+
conflicting_gallery.update_attribute(
|
17
|
+
:position, conflicting_gallery.position + 1
|
18
|
+
)
|
19
|
+
true
|
20
|
+
else
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
15
24
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def move_to_worst_position
|
26
|
+
records = self.class.count
|
27
|
+
if self.position < records
|
28
|
+
conflicting_gallery = Gallery.find_by_position(position + 1)
|
29
|
+
update_attribute(:position, self.position + 1)
|
30
|
+
conflicting_gallery.update_attribute(
|
31
|
+
:position, conflicting_gallery.position - 1
|
32
|
+
)
|
33
|
+
true
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
28
38
|
|
29
|
-
def move_to_worst_position
|
30
|
-
records = Gallery.count
|
31
|
-
if position < records
|
32
|
-
conflicting_gallery = Gallery.find_by_position(position + 1)
|
33
|
-
update_attribute(:position, position + 1)
|
34
|
-
conflicting_gallery.update_attribute(
|
35
|
-
:position, conflicting_gallery.position - 1
|
36
|
-
)
|
37
|
-
true
|
38
|
-
else
|
39
|
-
false
|
40
|
-
end
|
41
|
-
end
|
42
39
|
|
43
40
|
def self.form_attributes
|
44
41
|
[
|
45
|
-
{'file' => {
|
42
|
+
{'file' => {
|
43
|
+
'type' => 'file_field',
|
44
|
+
'name' => 'Archivo' }
|
45
|
+
}
|
46
46
|
]
|
47
47
|
end
|
48
48
|
|
@@ -50,22 +50,27 @@ module Adminpanel
|
|
50
50
|
"Galería"
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
unarranged_galleries.each do |gallery|
|
57
|
-
gallery.update_attribute(:position, gallery.position - 1)
|
58
|
-
end
|
53
|
+
def self.icon
|
54
|
+
'icon-picture'
|
55
|
+
end
|
59
56
|
|
60
|
-
|
57
|
+
private
|
58
|
+
def rearrange_positions
|
59
|
+
unarranged_galleries = Gallery.where("position > ?", self.position)
|
60
|
+
unarranged_galleries.each do |gallery|
|
61
|
+
gallery.update_attribute(:position, gallery.position - 1)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
61
65
|
|
62
66
|
def set_position
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
last_record = Gallery.last
|
68
|
+
if last_record.nil?
|
69
|
+
self.position = 1
|
70
|
+
else
|
71
|
+
self.position = last_record.position + 1
|
72
|
+
end
|
69
73
|
end
|
74
|
+
|
70
75
|
end
|
71
76
|
end
|