padrino-admin 0.6.3 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/README.rdoc +16 -0
  2. data/VERSION +1 -1
  3. data/lib/padrino-admin.rb +24 -5
  4. data/lib/padrino-admin/access_control.rb +75 -29
  5. data/lib/padrino-admin/{ext_js/column_store.rb → column_store.rb} +31 -15
  6. data/lib/padrino-admin/config.rb +36 -0
  7. data/lib/padrino-admin/generators/actions.rb +62 -7
  8. data/lib/padrino-admin/generators/admin_app.rb +27 -26
  9. data/lib/padrino-admin/generators/admin_page.rb +20 -18
  10. data/lib/padrino-admin/generators/admin_uploader.rb +83 -0
  11. data/lib/padrino-admin/generators/app/app.rb.tt +1 -3
  12. data/lib/padrino-admin/generators/app/controllers/accounts.rb +1 -1
  13. data/lib/padrino-admin/generators/app/public/flash/swfupload.swf +0 -0
  14. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/back.gif +0 -0
  15. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/background.png +0 -0
  16. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-content.png +0 -0
  17. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-hd-slate.png +0 -0
  18. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-hd.png +0 -0
  19. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-intro.png +0 -0
  20. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-login.png +0 -0
  21. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-menu-slate.png +0 -0
  22. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg-menu.png +0 -0
  23. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/bg.png +0 -0
  24. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/btn-login.png +0 -0
  25. data/lib/padrino-admin/generators/app/public/images/admin/cancel.gif +0 -0
  26. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/categories.gif +0 -0
  27. data/lib/padrino-admin/generators/app/public/images/admin/close.gif +0 -0
  28. data/lib/padrino-admin/generators/app/public/images/admin/close.png +0 -0
  29. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/delete.gif +0 -0
  30. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/download.gif +0 -0
  31. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/duplicate.gif +0 -0
  32. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/edit.gif +0 -0
  33. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/export.gif +0 -0
  34. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/hd-bg.gif +0 -0
  35. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/image.gif +0 -0
  36. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/loader.gif +0 -0
  37. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/logo-loader.png +0 -0
  38. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/logo-small.png +0 -0
  39. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/new.gif +0 -0
  40. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/no-image.png +0 -0
  41. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/preview.gif +0 -0
  42. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/print.gif +0 -0
  43. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/save.gif +0 -0
  44. data/lib/padrino-admin/generators/app/public/images/{backend → admin}/support.gif +0 -0
  45. data/lib/padrino-admin/generators/app/public/images/admin/up.gif +0 -0
  46. data/lib/padrino-admin/generators/app/public/javascripts/ext.js +4 -1
  47. data/lib/padrino-admin/generators/app/public/javascripts/swfupload.js +4 -0
  48. data/lib/padrino-admin/generators/app/public/stylesheets/admin.css +25 -43
  49. data/lib/padrino-admin/generators/app/public/stylesheets/login.css +3 -3
  50. data/lib/padrino-admin/generators/app/public/stylesheets/standard.css +53 -52
  51. data/lib/padrino-admin/generators/app/views/accounts/_form.haml +1 -0
  52. data/lib/padrino-admin/generators/app/views/base/index.haml +5 -7
  53. data/lib/padrino-admin/generators/app/views/javascripts/admin.js.erb +217 -297
  54. data/lib/padrino-admin/generators/app/views/sessions/new.haml +1 -1
  55. data/lib/padrino-admin/generators/templates/{controller.rb.tt → page/controller.rb.tt} +1 -1
  56. data/lib/padrino-admin/generators/templates/{db → page/db}/seeds.rb.tt +0 -0
  57. data/lib/padrino-admin/generators/templates/{views → page/views}/_form.haml.tt +0 -0
  58. data/lib/padrino-admin/generators/templates/{views → page/views}/edit.haml.tt +0 -0
  59. data/lib/padrino-admin/generators/templates/{views → page/views}/grid.js.erb.tt +1 -1
  60. data/lib/padrino-admin/generators/templates/{views → page/views}/new.haml.tt +0 -0
  61. data/lib/padrino-admin/generators/templates/{views → page/views}/store.jml.tt +0 -0
  62. data/lib/padrino-admin/generators/templates/uploader/controller.rb +24 -0
  63. data/lib/padrino-admin/generators/templates/uploader/lib/uploader.rb +54 -0
  64. data/lib/padrino-admin/generators/templates/uploader/views/grid.js.erb +56 -0
  65. data/lib/padrino-admin/generators/templates/uploader/views/store.jml +10 -0
  66. data/lib/padrino-admin/helpers/authentication.rb +30 -19
  67. data/lib/padrino-admin/helpers/view.rb +172 -35
  68. data/lib/padrino-admin/locale/admin/en.yml +1 -0
  69. data/lib/padrino-admin/middleware/flash_middleware.rb +36 -0
  70. data/lib/padrino-admin/orm.rb +33 -0
  71. data/lib/padrino-admin/orm/abstract.rb +94 -0
  72. data/lib/padrino-admin/{adapters/ar.rb → orm/activerecord.rb} +69 -36
  73. data/lib/padrino-admin/orm/datamapper.rb +214 -0
  74. data/lib/padrino-admin/{adapters/mm.rb → orm/mongomapper.rb} +36 -20
  75. data/lib/padrino-admin/utils/literal.rb +1 -1
  76. data/padrino-admin.gemspec +62 -51
  77. data/test/fixtures/active_record.rb +14 -2
  78. data/test/fixtures/data_mapper.rb +2 -1
  79. data/test/fixtures/mongo_mapper.rb +1 -1
  80. data/test/fixtures/test_column_store.jml +1 -0
  81. data/test/helper.rb +3 -2
  82. data/test/test_access_control.rb +1 -1
  83. data/test/test_active_record.rb +56 -1
  84. data/test/test_column_store.rb +56 -10
  85. data/test/test_data_mapper.rb +67 -1
  86. metadata +58 -47
  87. data/lib/padrino-admin/adapters.rb +0 -108
  88. data/lib/padrino-admin/adapters/dm.rb +0 -147
  89. data/lib/padrino-admin/ext_js/config.rb +0 -186
  90. data/test/fixtures/test_generic.jml +0 -7
  91. data/test/fixtures/test_javascript.jml +0 -81
@@ -6,7 +6,7 @@ class TestDataMapper < Test::Unit::TestCase
6
6
  load_fixture 'data_mapper'
7
7
  end
8
8
 
9
- context 'for datamapper functionality' do
9
+ context 'for datamapper account functionality' do
10
10
 
11
11
  should 'override default new_record? deprecation' do
12
12
  assert Account.new.respond_to?(:new_record?)
@@ -29,4 +29,70 @@ class TestDataMapper < Test::Unit::TestCase
29
29
  assert_equal account_r, account
30
30
  end
31
31
  end
32
+
33
+ context 'for data_mapper functionality' do
34
+
35
+ should 'have some standard methods' do
36
+ account = Account.new
37
+ assert_respond_to account, :new_record?
38
+ assert_respond_to account, :to_param
39
+ assert_respond_to account, :update_attributes
40
+ assert_respond_to Account, :count
41
+ end
42
+
43
+ should 'have category_ids' do
44
+ account = Account.first
45
+ assert_respond_to account, :category_ids
46
+ assert_respond_to account, :category_ids=
47
+ assert_equal [1, 3, 5], account.category_ids
48
+ end
49
+
50
+ should 'have errors_keys' do
51
+ account = Account.new
52
+ account.valid?
53
+ assert_equal [:email, :role, :password, :password_confirmation], account.errors_keys
54
+ end
55
+
56
+ should 'have table name' do
57
+ assert_equal "accounts", Account.table_name
58
+ end
59
+
60
+ should 'have orm defined' do
61
+ assert_equal :datamapper, Account.orm
62
+ end
63
+
64
+ should 'search correctly fields' do
65
+ accounts, categories = {}, {}
66
+
67
+ Account.auto_migrate!
68
+ Category.auto_migrate!
69
+
70
+ %w(gino paoli mario venuti franco).each do |name|
71
+ accounts[name] = Account.create(:email => "#{name}@foo.com", :role => name, :password => "some", :password_confirmation => "some")
72
+ assert_equal [accounts[name]], Account.ext_search(:query => name, :fields => "email,role").records
73
+ accounts
74
+ end
75
+
76
+ %w(rock soul classic rap jazz).each_with_index do |name, i|
77
+ categories[name] = Category.create(:name => name, :account_id => i+1)
78
+ assert_equal [categories[name]], Category.ext_search(:query => name, :fields => "name").records
79
+ accounts
80
+ end
81
+
82
+ # Make sure that our builtin count is correct
83
+ assert_equal 5, Account.ext_search({}).count
84
+ assert_equal 5, Account.ext_search({}).count
85
+
86
+ # Perform some search
87
+ assert_equal [accounts["venuti"]], Account.ext_search(:query => "en", :fields => "email,role").records
88
+ assert_equal [accounts["gino"], accounts["venuti"], accounts["franco"]], Account.ext_search(:query => "n", :fields => "email,role").records
89
+ assert_equal [accounts["venuti"], accounts["franco"]], Account.ext_search(:start => 3, :limit => 2).records
90
+ assert_equal [accounts["paoli"], accounts["venuti"]], Account.ext_search(:start => 3, :limit => 2, :sort => "role", :dir => "asc").records
91
+
92
+ # Perform some extended search
93
+ # TODO: find a way for fix this DM issue.
94
+ assert_equal [accounts["venuti"]], Account.ext_search({ :query => "rap", :fields => "categories.name" }, :links => [Account.relationships[:categories].inverse]).records
95
+ assert_equal [accounts["franco"], accounts["mario"]], Account.ext_search({:start => 3, :limit => 2, :sort => "categories.name", :dir => "desc"}, :links => [Account.relationships[:categories].inverse]).records
96
+ end
97
+ end
32
98
  end
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.3
4
+ version: 0.6.7
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 00:00:00 +01:00
15
+ date: 2010-01-26 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.3
36
+ version: 0.6.7
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.3
46
+ version: 0.6.7
47
47
  version:
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: tilt
@@ -122,15 +122,12 @@ files:
122
122
  - VERSION
123
123
  - lib/padrino-admin.rb
124
124
  - lib/padrino-admin/access_control.rb
125
- - lib/padrino-admin/adapters.rb
126
- - lib/padrino-admin/adapters/ar.rb
127
- - lib/padrino-admin/adapters/dm.rb
128
- - lib/padrino-admin/adapters/mm.rb
129
- - lib/padrino-admin/ext_js/column_store.rb
130
- - lib/padrino-admin/ext_js/config.rb
125
+ - lib/padrino-admin/column_store.rb
126
+ - lib/padrino-admin/config.rb
131
127
  - lib/padrino-admin/generators/actions.rb
132
128
  - lib/padrino-admin/generators/admin_app.rb
133
129
  - lib/padrino-admin/generators/admin_page.rb
130
+ - lib/padrino-admin/generators/admin_uploader.rb
134
131
  - lib/padrino-admin/generators/app/app.rb.tt
135
132
  - lib/padrino-admin/generators/app/controllers/accounts.rb
136
133
  - lib/padrino-admin/generators/app/controllers/base.rb
@@ -139,34 +136,39 @@ files:
139
136
  - lib/padrino-admin/generators/app/public/flash/charts.swf
140
137
  - lib/padrino-admin/generators/app/public/flash/clippy.swf
141
138
  - lib/padrino-admin/generators/app/public/flash/expressinstall.swf
142
- - lib/padrino-admin/generators/app/public/images/backend/back.gif
143
- - lib/padrino-admin/generators/app/public/images/backend/background.png
144
- - lib/padrino-admin/generators/app/public/images/backend/bg-content.png
145
- - lib/padrino-admin/generators/app/public/images/backend/bg-hd-slate.png
146
- - lib/padrino-admin/generators/app/public/images/backend/bg-hd.png
147
- - lib/padrino-admin/generators/app/public/images/backend/bg-intro.png
148
- - lib/padrino-admin/generators/app/public/images/backend/bg-login.png
149
- - lib/padrino-admin/generators/app/public/images/backend/bg-menu-slate.png
150
- - lib/padrino-admin/generators/app/public/images/backend/bg-menu.png
151
- - lib/padrino-admin/generators/app/public/images/backend/bg.png
152
- - lib/padrino-admin/generators/app/public/images/backend/btn-login.png
153
- - lib/padrino-admin/generators/app/public/images/backend/categories.gif
154
- - lib/padrino-admin/generators/app/public/images/backend/delete.gif
155
- - lib/padrino-admin/generators/app/public/images/backend/download.gif
156
- - lib/padrino-admin/generators/app/public/images/backend/duplicate.gif
157
- - lib/padrino-admin/generators/app/public/images/backend/edit.gif
158
- - lib/padrino-admin/generators/app/public/images/backend/export.gif
159
- - lib/padrino-admin/generators/app/public/images/backend/hd-bg.gif
160
- - lib/padrino-admin/generators/app/public/images/backend/image.gif
161
- - lib/padrino-admin/generators/app/public/images/backend/loader.gif
162
- - lib/padrino-admin/generators/app/public/images/backend/logo-loader.png
163
- - lib/padrino-admin/generators/app/public/images/backend/logo-small.png
164
- - lib/padrino-admin/generators/app/public/images/backend/new.gif
165
- - lib/padrino-admin/generators/app/public/images/backend/no-image.png
166
- - lib/padrino-admin/generators/app/public/images/backend/preview.gif
167
- - lib/padrino-admin/generators/app/public/images/backend/print.gif
168
- - lib/padrino-admin/generators/app/public/images/backend/save.gif
169
- - lib/padrino-admin/generators/app/public/images/backend/support.gif
139
+ - lib/padrino-admin/generators/app/public/flash/swfupload.swf
140
+ - lib/padrino-admin/generators/app/public/images/admin/back.gif
141
+ - lib/padrino-admin/generators/app/public/images/admin/background.png
142
+ - lib/padrino-admin/generators/app/public/images/admin/bg-content.png
143
+ - lib/padrino-admin/generators/app/public/images/admin/bg-hd-slate.png
144
+ - lib/padrino-admin/generators/app/public/images/admin/bg-hd.png
145
+ - lib/padrino-admin/generators/app/public/images/admin/bg-intro.png
146
+ - lib/padrino-admin/generators/app/public/images/admin/bg-login.png
147
+ - lib/padrino-admin/generators/app/public/images/admin/bg-menu-slate.png
148
+ - lib/padrino-admin/generators/app/public/images/admin/bg-menu.png
149
+ - lib/padrino-admin/generators/app/public/images/admin/bg.png
150
+ - lib/padrino-admin/generators/app/public/images/admin/btn-login.png
151
+ - lib/padrino-admin/generators/app/public/images/admin/cancel.gif
152
+ - lib/padrino-admin/generators/app/public/images/admin/categories.gif
153
+ - lib/padrino-admin/generators/app/public/images/admin/close.gif
154
+ - lib/padrino-admin/generators/app/public/images/admin/close.png
155
+ - lib/padrino-admin/generators/app/public/images/admin/delete.gif
156
+ - lib/padrino-admin/generators/app/public/images/admin/download.gif
157
+ - lib/padrino-admin/generators/app/public/images/admin/duplicate.gif
158
+ - lib/padrino-admin/generators/app/public/images/admin/edit.gif
159
+ - lib/padrino-admin/generators/app/public/images/admin/export.gif
160
+ - lib/padrino-admin/generators/app/public/images/admin/hd-bg.gif
161
+ - lib/padrino-admin/generators/app/public/images/admin/image.gif
162
+ - lib/padrino-admin/generators/app/public/images/admin/loader.gif
163
+ - lib/padrino-admin/generators/app/public/images/admin/logo-loader.png
164
+ - lib/padrino-admin/generators/app/public/images/admin/logo-small.png
165
+ - lib/padrino-admin/generators/app/public/images/admin/new.gif
166
+ - lib/padrino-admin/generators/app/public/images/admin/no-image.png
167
+ - lib/padrino-admin/generators/app/public/images/admin/preview.gif
168
+ - lib/padrino-admin/generators/app/public/images/admin/print.gif
169
+ - lib/padrino-admin/generators/app/public/images/admin/save.gif
170
+ - lib/padrino-admin/generators/app/public/images/admin/support.gif
171
+ - lib/padrino-admin/generators/app/public/images/admin/up.gif
170
172
  - lib/padrino-admin/generators/app/public/images/ext/default/box/corners-blue.gif
171
173
  - lib/padrino-admin/generators/app/public/images/ext/default/box/corners.gif
172
174
  - lib/padrino-admin/generators/app/public/images/ext/default/box/l-blue.gif
@@ -388,6 +390,7 @@ files:
388
390
  - lib/padrino-admin/generators/app/public/javascripts/effects.js
389
391
  - lib/padrino-admin/generators/app/public/javascripts/ext.js
390
392
  - lib/padrino-admin/generators/app/public/javascripts/prototype.js
393
+ - lib/padrino-admin/generators/app/public/javascripts/swfupload.js
391
394
  - lib/padrino-admin/generators/app/public/stylesheets/admin.css
392
395
  - lib/padrino-admin/generators/app/public/stylesheets/ext.css
393
396
  - lib/padrino-admin/generators/app/public/stylesheets/login.css
@@ -402,17 +405,27 @@ files:
402
405
  - lib/padrino-admin/generators/app/views/javascripts/admin.js.erb
403
406
  - lib/padrino-admin/generators/app/views/javascripts/locale.js.erb
404
407
  - lib/padrino-admin/generators/app/views/sessions/new.haml
405
- - lib/padrino-admin/generators/templates/controller.rb.tt
406
- - lib/padrino-admin/generators/templates/db/seeds.rb.tt
407
- - lib/padrino-admin/generators/templates/views/_form.haml.tt
408
- - lib/padrino-admin/generators/templates/views/edit.haml.tt
409
- - lib/padrino-admin/generators/templates/views/grid.js.erb.tt
410
- - lib/padrino-admin/generators/templates/views/new.haml.tt
411
- - lib/padrino-admin/generators/templates/views/store.jml.tt
408
+ - lib/padrino-admin/generators/templates/page/controller.rb.tt
409
+ - lib/padrino-admin/generators/templates/page/db/seeds.rb.tt
410
+ - lib/padrino-admin/generators/templates/page/views/_form.haml.tt
411
+ - lib/padrino-admin/generators/templates/page/views/edit.haml.tt
412
+ - lib/padrino-admin/generators/templates/page/views/grid.js.erb.tt
413
+ - lib/padrino-admin/generators/templates/page/views/new.haml.tt
414
+ - lib/padrino-admin/generators/templates/page/views/store.jml.tt
415
+ - lib/padrino-admin/generators/templates/uploader/controller.rb
416
+ - lib/padrino-admin/generators/templates/uploader/lib/uploader.rb
417
+ - lib/padrino-admin/generators/templates/uploader/views/grid.js.erb
418
+ - lib/padrino-admin/generators/templates/uploader/views/store.jml
412
419
  - lib/padrino-admin/helpers/authentication.rb
413
420
  - lib/padrino-admin/helpers/view.rb
414
421
  - lib/padrino-admin/locale/admin/en.yml
415
422
  - lib/padrino-admin/locale/extjs/en.yml
423
+ - lib/padrino-admin/middleware/flash_middleware.rb
424
+ - lib/padrino-admin/orm.rb
425
+ - lib/padrino-admin/orm/abstract.rb
426
+ - lib/padrino-admin/orm/activerecord.rb
427
+ - lib/padrino-admin/orm/datamapper.rb
428
+ - lib/padrino-admin/orm/mongomapper.rb
416
429
  - lib/padrino-admin/utils/crypt.rb
417
430
  - lib/padrino-admin/utils/literal.rb
418
431
  - padrino-admin.gemspec
@@ -420,8 +433,6 @@ files:
420
433
  - test/fixtures/data_mapper.rb
421
434
  - test/fixtures/mongo_mapper.rb
422
435
  - test/fixtures/test_column_store.jml
423
- - test/fixtures/test_generic.jml
424
- - test/fixtures/test_javascript.jml
425
436
  - test/helper.rb
426
437
  - test/test_access_control.rb
427
438
  - test/test_active_record.rb
@@ -1,108 +0,0 @@
1
- require 'openssl'
2
- require 'digest/sha1'
3
-
4
- module Padrino
5
- module Admin
6
-
7
- class AdapterError < StandardError; end
8
-
9
- class ExtSearch < Struct.new(:count, :records); end
10
-
11
- module Adapters
12
- # This method it's used for register for the specified ORM the extensions.
13
- def self.register(adapter, klass=nil)
14
- klass ||= Account
15
- case adapter
16
- when :activerecord
17
- ActiveRecord::Base.send(:include, Padrino::Admin::Adapters::Ar::Base)
18
- klass.send(:include, Padrino::Admin::Adapters::Ar::Account)
19
- when :datamapper
20
- DataMapper::Model.descendants.each { |d| d.send(:include, Padrino::Admin::Adapters::Dm::Base) }
21
- klass.send(:include, Padrino::Admin::Adapters::Dm::Account)
22
- # Not yet finished
23
- when :mongomapper
24
- MongoMapper::Document.append_inclusions(Padrino::Admin::Adapters::Mm::Base)
25
- klass.send(:include, Padrino::Admin::Adapters::Mm::Account)
26
- else
27
- raise Padrino::Admin::AdapterError, "The adapter #{adapter.inspect} is not supported, available adapters are: " +
28
- ":activerecord, :datamapper, :mongomapper"
29
- end
30
- end
31
-
32
- # Here standard extension
33
- module Base
34
- def self.included(base)
35
- base.send :include, InstanceMethods
36
- base.extend ClassMethods
37
- end
38
-
39
- module InstanceMethods
40
- end
41
-
42
- module ClassMethods
43
- # This method generate store and column config.
44
- # for lazinies hands instead supply:
45
- #
46
- # Model.column_store("./../views/model/store.jml")
47
- #
48
- # you can:
49
- #
50
- # Model.column_store(options.views, "models/store")
51
- def column_store(*args)
52
- path = File.join(*args)
53
- path = Dir[path + ".{jml,jaml}"].first.to_s if path !~ /(\.jml|\.jaml)$/
54
- config = YAML.load_file(path)
55
- Padrino::ExtJs::ColumnStore.new(self, config)
56
- end
57
- end
58
- end
59
- # Here extension for account
60
- #
61
- # An Account must have these column/fields:
62
- #
63
- # role:: String
64
- # email:: String (used as login)
65
- # crypted_password:: String
66
- # salt:: String
67
- #
68
- # We add to Account model some methods:
69
- #
70
- # Account.authenticate(email, password):: check if exist an account for the given email and return it if password match
71
- # account.password_clean:: return the decrypted password of an Account instance
72
- #
73
- module AccountUtils
74
-
75
- def self.included(base) #:nodoc:
76
- base.extend ClassMethods
77
- base.send :include, InstanceMethods
78
- end
79
-
80
- module ClassMethods
81
- # This method it's for authentication purpose
82
- def authenticate(email, password)
83
- account = first(:conditions => { :email => email }) if email.present?
84
- account && account.password_clean == password ? account : nil
85
- end
86
- end
87
-
88
- module InstanceMethods
89
- # This method it's used for retrive the original password.
90
- def password_clean
91
- crypted_password.decrypt(salt)
92
- end
93
-
94
- private
95
- def generate_password
96
- return if password.blank?
97
- self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{email}--") if new_record?
98
- self.crypted_password = password.encrypt(self.salt)
99
- end
100
-
101
- def password_required
102
- crypted_password.blank? || !password.blank?
103
- end
104
- end
105
- end
106
- end
107
- end
108
- end
@@ -1,147 +0,0 @@
1
- module Padrino
2
- module Admin
3
- module Adapters
4
- module Dm
5
-
6
- # Here basic functions for interact with DataMapper
7
- module Base
8
-
9
- def self.included(base)
10
- base.send :include, Padrino::Admin::Adapters::Base
11
- base.send :include, InstanceMethods
12
- base.extend ClassMethods
13
- end
14
-
15
- module InstanceMethods
16
- # This method allow us to don't see deprecations
17
- def new_record?; new?; end
18
-
19
- # Returns a String, which Padrino uses for constructing an URL to this object.
20
- # The default implementation returns this record‘s id as a String, or nil if this record‘s unsaved.
21
- def to_param
22
- # We can't use alias_method here, because method 'id' optimizes itself on the fly.
23
- (id = self.id) ? id.to_s : nil # Be sure to stringify the id for routes
24
- end
25
-
26
- # Update attributes is deprecated but for compatibility with AR we support them.
27
- def update_attributes(attributes = {})
28
- update(attributes)
29
- end
30
-
31
- # Method for get only fields with errors
32
- def errors_keys
33
- errors.keys
34
- end
35
-
36
- end
37
-
38
- module ClassMethods
39
- attr_accessor :_table_name
40
-
41
- def self_and_descendants #:nodoc:
42
- klass = self
43
- classes = [klass]
44
- while klass != klass.base_class
45
- classes << klass = klass.superclass
46
- end
47
- classes
48
- rescue
49
- # OPTIMIZE this rescue is to fix this test: ./test/cases/reflection_test.rb:56:in `test_human_name_for_column'
50
- # Appearantly the method base_class causes some trouble.
51
- # It now works for sure.
52
- [self]
53
- end
54
-
55
- # Transforms attribute key names into a more humane format, such as "First name" instead of "first_name". Example:
56
- # Person.human_attribute_name("first_name") # => "First name"
57
- # This used to be depricated in favor of humanize, but is now preferred, because it automatically uses the I18n
58
- # module now.
59
- # Specify +options+ with additional translating options.
60
- def human_attribute_name(attribute_key_name, options = {})
61
- defaults = self_and_descendants.map do |klass|
62
- :"#{klass.name.underscore}.#{attribute_key_name}"
63
- end
64
- defaults << options[:default] if options[:default]
65
- defaults.flatten!
66
- defaults << attribute_key_name.to_s.humanize
67
- options[:count] ||= 1
68
- I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => [:model, :attributes]))
69
- end
70
-
71
- # Return the name of the sql table
72
- def table_name
73
- self.name.downcase.pluralize # storage_names[:default] this some times give an error
74
- end
75
-
76
- # Perform a basic fulltext search/ordering for the given columns
77
- #
78
- # +params+ is an hash like that:
79
- # { :sort => "name", :dir => "ASC", :fields=>"name,surname,company", :query => 'daddye' }
80
- #
81
- # In this example we search in columns name, surname, company the string daddye and then we order by
82
- # column +name+
83
- def ext_search(params, query={})
84
-
85
- # We build a base struct for have some good results
86
- result = ExtSearch.new(0, [])
87
-
88
- # We need a basic query
89
- query = {}
90
-
91
- if params[:query].present? && params[:fields].present?
92
- # Here we build some like: ["name LIKE ?", "surname LIKE ?"]
93
- fields = params[:fields].split(",").collect { |f| "#{f.strip.downcase} LIKE ?" }
94
- # Here we build some like: ["name LIKE ? OR surname LIKE ?", "%foo%", "%foo%"]
95
- query[:conditions] = [fields.join(" OR ")].concat(1.upto(fields.length).collect { "%#{params[:query]}%" })
96
- end
97
-
98
- # Now we can perform a count
99
- result.count = count(query)
100
-
101
- # First we need to sort our record
102
- if params[:sort].present? && params[:dir].to_s =~ /^(asc|desc)$/i
103
- query[:order] = [params[:sort].to_s.gsub(/#{table_name}\./i,'').to_sym.send(params[:dir].to_s.downcase)]
104
- end
105
-
106
- # Now time to limit/offset it
107
- query[:limit] = params[:limit].to_i if params[:limit].to_i > 0
108
- query[:offset] = params[:offset].to_i if params[:start].to_i > 0
109
-
110
- # Now we can perform ording/limiting
111
- result.records = all(query)
112
- result
113
- end
114
- end
115
- end
116
-
117
- # Here extension for account for DataMapper
118
- module Account
119
- # Extend our class when included
120
- def self.included(base)
121
- super
122
- base.send :include, Padrino::Admin::Adapters::AccountUtils
123
- base.send :include, DataMapper::Validate
124
- base.send :attr_accessor, :password, :password_confirmation
125
- # Properties
126
- base.property :email, String
127
- base.property :crypted_password, String
128
- base.property :salt, String
129
- base.property :role, String
130
- # Validations
131
- base.validates_present :email, :role
132
- base.validates_present :password, :if => :password_required
133
- base.validates_present :password_confirmation, :if => :password_required
134
- base.validates_length :password, :min => 4, :max => 40, :if => :password_required
135
- base.validates_is_confirmed :password, :if => :password_required
136
- base.validates_length :email, :min => 3, :max => 100
137
- base.validates_is_unique :email, :case_sensitive => false
138
- base.validates_format :email, :with => :email_address
139
- base.validates_format :role, :with => /[A-Za-z]/
140
- # Callbacks
141
- base.before :save, :generate_password
142
- end
143
- end
144
- end
145
- end
146
- end
147
- end