padrino-admin 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/padrino-admin/adapters.rb +2 -0
- data/lib/padrino-admin/adapters/ar.rb +33 -18
- data/lib/padrino-admin/adapters/dm.rb +16 -10
- data/lib/padrino-admin/ext_js/column_store.rb +2 -4
- data/lib/padrino-admin/ext_js/config.rb +1 -1
- data/lib/padrino-admin/generators/admin_app.rb +32 -13
- data/lib/padrino-admin/helpers/view.rb +1 -1
- data/padrino-admin.gemspec +8 -9
- metadata +4 -5
- data/lib/padrino-admin/generators/templates/models/account.rb.tt +0 -8
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.3
|
@@ -9,28 +9,16 @@ module Padrino
|
|
9
9
|
base.send :include, Padrino::Admin::Adapters::Base
|
10
10
|
base.send :include, InstanceMethods
|
11
11
|
base.extend ClassMethods
|
12
|
-
|
13
|
-
named_scope :ext_search, lambda { |params|
|
14
|
-
conditions = nil
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
filters = params[:fields].split(",").collect { |f| "#{f} LIKE ?" }.compact
|
18
|
-
conditions = [filters.join(" OR ")].concat((1..filters.size).collect { "%#{params[:query]}%" })
|
19
|
-
end
|
14
|
+
module InstanceMethods
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
params.symbolize_keys!
|
25
|
-
order = params[:sort].blank? && params[:dir].blank? ? nil : "#{params[:sort]} #{params[:dir]}"
|
26
|
-
{ :order => order, :limit => params[:limit], :offset => params[:start] }
|
27
|
-
}
|
16
|
+
# Method for get only fields with errors
|
17
|
+
def errors_keys
|
18
|
+
errors.map { |k,v| k.to_sym }.uniq
|
28
19
|
end
|
29
20
|
end
|
30
|
-
|
31
|
-
module InstanceMethods
|
32
|
-
end
|
33
|
-
|
21
|
+
|
34
22
|
module ClassMethods
|
35
23
|
# Transforms attribute key names into a more humane format, such as "First name" instead of "first_name". Example:
|
36
24
|
# Person.human_attribute_name("first_name") # => "First name"
|
@@ -53,6 +41,33 @@ module Padrino
|
|
53
41
|
columns
|
54
42
|
end
|
55
43
|
|
44
|
+
def ext_search(params, query={})
|
45
|
+
|
46
|
+
# We build a base struct for have some good results
|
47
|
+
result = ExtSearch.new(0, [])
|
48
|
+
|
49
|
+
# We need a basic query
|
50
|
+
query = {}
|
51
|
+
|
52
|
+
# Search conditions
|
53
|
+
if params[:query].present? && params[:fields].present?
|
54
|
+
filters = params[:fields].split(",").collect { |f| "#{f} LIKE ?" }.compact
|
55
|
+
query[:conditions] = [filters.join(" OR ")].concat((1..filters.size).collect { "%#{params[:query]}%" })
|
56
|
+
end
|
57
|
+
|
58
|
+
result.count = count(query)
|
59
|
+
|
60
|
+
# Order conditions
|
61
|
+
query[:order] = params[:sort].present? && params[:dir].to_s =~ /^(asc|desc)$/i ? "#{params[:sort]} #{params[:dir]}" : nil
|
62
|
+
|
63
|
+
# Now time to limit/offset it
|
64
|
+
query[:limit] = params[:limit].to_i if params[:limit].to_i > 0
|
65
|
+
query[:offset] = params[:offset].to_i if params[:start].to_i > 0
|
66
|
+
|
67
|
+
result.records = all(query)
|
68
|
+
result
|
69
|
+
end
|
70
|
+
|
56
71
|
end
|
57
72
|
end
|
58
73
|
|
@@ -27,6 +27,12 @@ module Padrino
|
|
27
27
|
def update_attributes(attributes = {})
|
28
28
|
update(attributes)
|
29
29
|
end
|
30
|
+
|
31
|
+
# Method for get only fields with errors
|
32
|
+
def errors_keys
|
33
|
+
errors.keys
|
34
|
+
end
|
35
|
+
|
30
36
|
end
|
31
37
|
|
32
38
|
module ClassMethods
|
@@ -74,7 +80,11 @@ module Padrino
|
|
74
80
|
#
|
75
81
|
# In this example we search in columns name, surname, company the string daddye and then we order by
|
76
82
|
# column +name+
|
77
|
-
def ext_search(params)
|
83
|
+
def ext_search(params, query={})
|
84
|
+
|
85
|
+
# We build a base struct for have some good results
|
86
|
+
result = ExtSearch.new(0, [])
|
87
|
+
|
78
88
|
# We need a basic query
|
79
89
|
query = {}
|
80
90
|
|
@@ -85,13 +95,8 @@ module Padrino
|
|
85
95
|
query[:conditions] = [fields.join(" OR ")].concat(1.upto(fields.length).collect { "%#{params[:query]}%" })
|
86
96
|
end
|
87
97
|
|
88
|
-
# Now we can perform a
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
def ext_paginate(params)
|
93
|
-
# We need a basic query
|
94
|
-
query = {}
|
98
|
+
# Now we can perform a count
|
99
|
+
result.count = count(query)
|
95
100
|
|
96
101
|
# First we need to sort our record
|
97
102
|
if params[:sort].present? && params[:dir].to_s =~ /^(asc|desc)$/i
|
@@ -100,10 +105,11 @@ module Padrino
|
|
100
105
|
|
101
106
|
# Now time to limit/offset it
|
102
107
|
query[:limit] = params[:limit].to_i if params[:limit].to_i > 0
|
103
|
-
query[:offset] = params[:offset].to_i if params[:
|
108
|
+
query[:offset] = params[:offset].to_i if params[:start].to_i > 0
|
104
109
|
|
105
110
|
# Now we can perform ording/limiting
|
106
|
-
all(query)
|
111
|
+
result.records = all(query)
|
112
|
+
result
|
107
113
|
end
|
108
114
|
end
|
109
115
|
end
|
@@ -90,10 +90,8 @@ module Padrino
|
|
90
90
|
# Some can tell me that this method made two identical queries one for count one for paginate.
|
91
91
|
# We don't use the select count because in some circumstances require much time than select *.
|
92
92
|
params[:limit] ||= 50
|
93
|
-
collection = @model.
|
94
|
-
|
95
|
-
collection_paginated = collection.ext_paginate(params)
|
96
|
-
{ :results => store_data_from(collection_paginated), :count => collection_count }.to_json
|
93
|
+
collection = @model.ext_search(params, options)
|
94
|
+
{ :results => store_data_from(collection.records), :count => collection.count }.to_json
|
97
95
|
end
|
98
96
|
|
99
97
|
private
|
@@ -16,7 +16,7 @@ module Padrino
|
|
16
16
|
|
17
17
|
desc "Description:\n\n\tpadrino-gen controller generates a new Padrino Admin"
|
18
18
|
|
19
|
-
class_option :root, :aliases => '-r', :default =>
|
19
|
+
class_option :root, :aliases => '-r', :default => ".", :type => :string
|
20
20
|
class_option :path, :aliases => '-p', :type => :string, :default => "admin"
|
21
21
|
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
22
22
|
|
@@ -25,23 +25,42 @@ module Padrino
|
|
25
25
|
if in_app_root?(options[:root])
|
26
26
|
@app_path = options[:path]
|
27
27
|
@orm = fetch_component_choice(:orm, options[:root]).to_sym rescue :datamapper
|
28
|
+
supported_orm = [:datamapper, :activerecord]
|
29
|
+
skip_migration = case @orm
|
30
|
+
when :activerecord then false
|
31
|
+
when :sequel then false
|
32
|
+
else true
|
33
|
+
end
|
28
34
|
|
29
|
-
|
35
|
+
unless supported_orm.include?(@orm)
|
36
|
+
say "<= A the moment we only support #{supported_orm.join(" or ")}. Sorry!"
|
37
|
+
raise SystemExit
|
38
|
+
end
|
30
39
|
|
31
40
|
self.behavior = :revoke if options[:destroy]
|
32
41
|
directory("app/", File.join(options[:path]))
|
33
|
-
|
42
|
+
|
43
|
+
Padrino::Generators::Model.dup.start([
|
44
|
+
"account", "name:string", "surname:string", "email:string", "crypted_password:string", "salt:string", "role:string",
|
45
|
+
"-r=#{options[:root]}", "-s=#{skip_migration}", "-d=#{options[:destroy]}"
|
46
|
+
])
|
47
|
+
|
34
48
|
template "templates/db/seeds.rb.tt", app_root_path("/db/seeds.rb")
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
49
|
+
|
50
|
+
if options[:destroy] || !File.read(app_root_path("config/apps.rb")).include?("Padrino.mount(\"Admin\").to(\"/#{@app_path}\")")
|
51
|
+
append_file app_root_path("config/apps.rb"), "\nPadrino.mount(\"Admin\").to(\"/#{@app_path}\")"
|
52
|
+
end
|
53
|
+
|
54
|
+
unless options[:destroy]
|
55
|
+
say ""
|
56
|
+
say "Your admin now is installed, now follow this steps:"
|
57
|
+
say ""
|
58
|
+
say " - edit your config/database.rb"
|
59
|
+
say " - run padrino rake -T and run db creation according to your orm"
|
60
|
+
say " - run padrino rake seed"
|
61
|
+
say ""
|
62
|
+
say "That's all"
|
63
|
+
end
|
45
64
|
else
|
46
65
|
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and exit unless in_app_root?
|
47
66
|
end
|
@@ -32,7 +32,7 @@ module Padrino
|
|
32
32
|
end
|
33
33
|
message = escape_javascript(options.include?(:message) ? options[:message] : locale.t(:body))
|
34
34
|
error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, escape_javascript(msg)) } }.join
|
35
|
-
error_highlighter = objects.map {|object| object.
|
35
|
+
error_highlighter = objects.map {|object| object.errors_keys.map{ |k| "$('#{object.class.to_s.downcase}_#{k}').addClassName('x-form-invalid');" } }.join("\n")
|
36
36
|
|
37
37
|
contents = ''
|
38
38
|
contents << content_tag(:p, message) if message.present?
|
data/padrino-admin.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-admin}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-15}
|
13
13
|
s.description = %q{Admin View for Padrino applications}
|
14
14
|
s.email = %q{nesquena@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -306,7 +306,6 @@ Gem::Specification.new do |s|
|
|
306
306
|
"lib/padrino-admin/generators/app/views/sessions/new.haml",
|
307
307
|
"lib/padrino-admin/generators/templates/controller.rb.tt",
|
308
308
|
"lib/padrino-admin/generators/templates/db/seeds.rb.tt",
|
309
|
-
"lib/padrino-admin/generators/templates/models/account.rb.tt",
|
310
309
|
"lib/padrino-admin/generators/templates/views/_form.haml.tt",
|
311
310
|
"lib/padrino-admin/generators/templates/views/edit.haml.tt",
|
312
311
|
"lib/padrino-admin/generators/templates/views/grid.js.erb.tt",
|
@@ -345,8 +344,8 @@ Gem::Specification.new do |s|
|
|
345
344
|
|
346
345
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
347
346
|
s.add_runtime_dependency(%q<json_pure>, [">= 1.2.0"])
|
348
|
-
s.add_runtime_dependency(%q<padrino-core>, ["= 0.6.
|
349
|
-
s.add_runtime_dependency(%q<padrino-gen>, ["= 0.6.
|
347
|
+
s.add_runtime_dependency(%q<padrino-core>, ["= 0.6.3"])
|
348
|
+
s.add_runtime_dependency(%q<padrino-gen>, ["= 0.6.3"])
|
350
349
|
s.add_runtime_dependency(%q<tilt>, [">= 0.4"])
|
351
350
|
s.add_development_dependency(%q<haml>, [">= 2.2.1"])
|
352
351
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
@@ -355,8 +354,8 @@ Gem::Specification.new do |s|
|
|
355
354
|
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
356
355
|
else
|
357
356
|
s.add_dependency(%q<json_pure>, [">= 1.2.0"])
|
358
|
-
s.add_dependency(%q<padrino-core>, ["= 0.6.
|
359
|
-
s.add_dependency(%q<padrino-gen>, ["= 0.6.
|
357
|
+
s.add_dependency(%q<padrino-core>, ["= 0.6.3"])
|
358
|
+
s.add_dependency(%q<padrino-gen>, ["= 0.6.3"])
|
360
359
|
s.add_dependency(%q<tilt>, [">= 0.4"])
|
361
360
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
362
361
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
@@ -366,8 +365,8 @@ Gem::Specification.new do |s|
|
|
366
365
|
end
|
367
366
|
else
|
368
367
|
s.add_dependency(%q<json_pure>, [">= 1.2.0"])
|
369
|
-
s.add_dependency(%q<padrino-core>, ["= 0.6.
|
370
|
-
s.add_dependency(%q<padrino-gen>, ["= 0.6.
|
368
|
+
s.add_dependency(%q<padrino-core>, ["= 0.6.3"])
|
369
|
+
s.add_dependency(%q<padrino-gen>, ["= 0.6.3"])
|
371
370
|
s.add_dependency(%q<tilt>, [">= 0.4"])
|
372
371
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
373
372
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2010-01-
|
15
|
+
date: 2010-01-15 00:00:00 +01:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
requirements:
|
34
34
|
- - "="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 0.6.
|
36
|
+
version: 0.6.3
|
37
37
|
version:
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: padrino-gen
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - "="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.6.
|
46
|
+
version: 0.6.3
|
47
47
|
version:
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: tilt
|
@@ -404,7 +404,6 @@ files:
|
|
404
404
|
- lib/padrino-admin/generators/app/views/sessions/new.haml
|
405
405
|
- lib/padrino-admin/generators/templates/controller.rb.tt
|
406
406
|
- lib/padrino-admin/generators/templates/db/seeds.rb.tt
|
407
|
-
- lib/padrino-admin/generators/templates/models/account.rb.tt
|
408
407
|
- lib/padrino-admin/generators/templates/views/_form.haml.tt
|
409
408
|
- lib/padrino-admin/generators/templates/views/edit.haml.tt
|
410
409
|
- lib/padrino-admin/generators/templates/views/grid.js.erb.tt
|