merb-admin 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/Gemfile +21 -23
  2. data/Gemfile.lock +107 -89
  3. data/LICENSE +20 -20
  4. data/README.rdoc +54 -54
  5. data/Rakefile +11 -11
  6. data/app/controllers/application.rb +6 -6
  7. data/app/controllers/main.rb +191 -191
  8. data/app/helpers/application_helper.rb +64 -64
  9. data/app/helpers/main_helper.rb +167 -167
  10. data/app/views/layout/_message.html.erb +10 -10
  11. data/app/views/layout/dashboard.html.erb +34 -34
  12. data/app/views/layout/form.html.erb +48 -48
  13. data/app/views/layout/list.html.erb +42 -42
  14. data/app/views/main/_belongs_to.html.erb +29 -29
  15. data/app/views/main/_big_decimal.html.erb +12 -12
  16. data/app/views/main/_boolean.html.erb +7 -7
  17. data/app/views/main/_date.html.erb +12 -12
  18. data/app/views/main/_datetime.html.erb +12 -12
  19. data/app/views/main/_float.html.erb +12 -12
  20. data/app/views/main/_has_many.html.erb +16 -16
  21. data/app/views/main/_has_one.html.erb +30 -30
  22. data/app/views/main/_integer.html.erb +12 -12
  23. data/app/views/main/_properties.html.erb +18 -18
  24. data/app/views/main/_string.html.erb +15 -15
  25. data/app/views/main/_text.html.erb +11 -11
  26. data/app/views/main/_time.html.erb +12 -12
  27. data/app/views/main/_timestamp.html.erb +12 -12
  28. data/app/views/main/delete.html.erb +28 -28
  29. data/app/views/main/edit.html.erb +19 -19
  30. data/app/views/main/index.html.erb +22 -22
  31. data/app/views/main/list.html.erb +93 -93
  32. data/app/views/main/new.html.erb +16 -16
  33. data/config/init.rb +31 -30
  34. data/config/router.rb +4 -4
  35. data/lib/abstract_model.rb +84 -84
  36. data/lib/active_record_support.rb +151 -147
  37. data/lib/datamapper_support.rb +145 -141
  38. data/lib/generic_support.rb +13 -13
  39. data/lib/merb-admin.rb +100 -100
  40. data/lib/merb-admin/merbtasks.rb +103 -103
  41. data/lib/merb-admin/slicetasks.rb +168 -174
  42. data/lib/merb-admin/spectasks.rb +55 -55
  43. data/lib/merb-admin/version.rb +3 -3
  44. data/lib/sequel_support.rb +282 -275
  45. data/merb-admin.gemspec +42 -41
  46. data/public/javascripts/CollapsedFieldsets.js +85 -85
  47. data/public/javascripts/DateTimeShortcuts.js +255 -255
  48. data/public/javascripts/RelatedObjectLookups.js +96 -96
  49. data/public/javascripts/SelectBox.js +111 -111
  50. data/public/javascripts/SelectFilter2.js +113 -113
  51. data/public/javascripts/actions.js +39 -39
  52. data/public/javascripts/calendar.js +143 -143
  53. data/public/javascripts/core.js +176 -176
  54. data/public/javascripts/dateparse.js +233 -233
  55. data/public/javascripts/getElementsBySelector.js +167 -167
  56. data/public/javascripts/i18n.js +33 -33
  57. data/public/javascripts/ordering.js +137 -137
  58. data/public/javascripts/timeparse.js +94 -94
  59. data/public/javascripts/urlify.js +140 -140
  60. data/public/stylesheets/base.css +746 -746
  61. data/public/stylesheets/changelists.css +269 -269
  62. data/public/stylesheets/dashboard.css +24 -24
  63. data/public/stylesheets/forms.css +327 -327
  64. data/public/stylesheets/global.css +142 -142
  65. data/public/stylesheets/ie.css +50 -50
  66. data/public/stylesheets/layout.css +29 -29
  67. data/public/stylesheets/login.css +54 -54
  68. data/public/stylesheets/master.css +1 -1
  69. data/public/stylesheets/patch-iewin.css +7 -7
  70. data/public/stylesheets/rtl.css +206 -206
  71. data/public/stylesheets/widgets.css +506 -506
  72. data/spec/controllers/main_spec.rb +25 -25
  73. data/spec/migrations/activerecord/001_create_divisions_migration.rb +13 -13
  74. data/spec/migrations/activerecord/002_create_drafts_migration.rb +19 -19
  75. data/spec/migrations/activerecord/003_create_leagues_migration.rb +12 -12
  76. data/spec/migrations/activerecord/004_create_players_migration.rb +19 -19
  77. data/spec/migrations/activerecord/005_create_teams_migration.rb +22 -22
  78. data/spec/migrations/sequel/001_create_divisions_migration.rb +15 -15
  79. data/spec/migrations/sequel/002_create_drafts_migration.rb +21 -21
  80. data/spec/migrations/sequel/003_create_leagues_migration.rb +14 -14
  81. data/spec/migrations/sequel/004_create_players_migration.rb +21 -21
  82. data/spec/migrations/sequel/005_create_teams_migration.rb +24 -24
  83. data/spec/models/activerecord/division.rb +7 -7
  84. data/spec/models/activerecord/draft.rb +11 -11
  85. data/spec/models/activerecord/league.rb +6 -6
  86. data/spec/models/activerecord/player.rb +8 -8
  87. data/spec/models/activerecord/team.rb +13 -13
  88. data/spec/models/datamapper/division.rb +12 -12
  89. data/spec/models/datamapper/draft.rb +18 -18
  90. data/spec/models/datamapper/league.rb +11 -11
  91. data/spec/models/datamapper/player.rb +20 -20
  92. data/spec/models/datamapper/team.rb +22 -22
  93. data/spec/models/sequel/division.rb +15 -15
  94. data/spec/models/sequel/draft.rb +19 -19
  95. data/spec/models/sequel/league.rb +14 -14
  96. data/spec/models/sequel/player.rb +18 -18
  97. data/spec/models/sequel/team.rb +21 -21
  98. data/spec/requests/main_spec.rb +873 -763
  99. data/spec/spec_helper.rb +111 -113
  100. metadata +40 -26
data/Gemfile CHANGED
@@ -1,23 +1,21 @@
1
- source 'http://rubygems.org'
2
-
3
- merb_gems_version = '~> 1.1'
4
-
5
- gem 'merb-assets', merb_gems_version
6
- gem 'merb-helpers', merb_gems_version
7
- gem 'merb-slices', merb_gems_version
8
- gem 'builder'
9
- gem 'json'
10
-
11
- group :test do
12
- gem 'activerecord', '~> 2.3', :require => 'active_record'
13
- gem 'dm-core', '~> 1.0'
14
- gem 'dm-aggregates', '~> 1.0'
15
- gem 'dm-types', '~> 1.0'
16
- gem 'dm-migrations', '~> 1.0'
17
- gem 'dm-sqlite-adapter', '~> 1.0'
18
- gem 'dm-validations', '~> 1.0'
19
- gem 'rspec'
20
- gem 'sequel', '~> 3.6.0'
21
- gem 'sqlite3-ruby', :require => 'sqlite3'
22
- gem 'webrat'
23
- end
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # Bundle gems for the local environment. Make sure to
6
+ # put test-only gems in this group so their generators
7
+ # and rake tasks are available in test mode:
8
+ group :test do
9
+ gem 'activerecord', '~> 2.3', :require => 'active_record'
10
+ gem 'dm-core', '~> 1.0'
11
+ gem 'dm-aggregates', '~> 1.0'
12
+ gem 'dm-types', '~> 1.0'
13
+ gem 'dm-migrations', '~> 1.0'
14
+ gem 'dm-sqlite-adapter', '~> 1.0'
15
+ gem 'dm-validations', '~> 1.0'
16
+ gem 'thin', '~> 1.2'
17
+ gem 'rspec', '~> 1.3'
18
+ gem 'sequel', '~> 3.16'
19
+ gem 'sqlite3-ruby', '~> 1.3', :require => 'sqlite3'
20
+ gem 'webrat', '~> 0.7'
21
+ end
@@ -1,89 +1,107 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- abstract (1.0.0)
5
- activerecord (2.3.9)
6
- activesupport (= 2.3.9)
7
- activesupport (2.3.9)
8
- addressable (2.2.1)
9
- builder (2.1.2)
10
- data_objects (0.10.2)
11
- addressable (~> 2.1)
12
- dm-aggregates (1.0.2)
13
- dm-core (~> 1.0.2)
14
- dm-core (1.0.2)
15
- addressable (~> 2.2)
16
- extlib (~> 0.9.15)
17
- dm-do-adapter (1.0.2)
18
- data_objects (~> 0.10.2)
19
- dm-core (~> 1.0.2)
20
- dm-migrations (1.0.2)
21
- dm-core (~> 1.0.2)
22
- dm-sqlite-adapter (1.0.2)
23
- dm-do-adapter (~> 1.0.2)
24
- do_sqlite3 (~> 0.10.2)
25
- dm-types (1.0.2)
26
- dm-core (~> 1.0.2)
27
- fastercsv (~> 1.5.3)
28
- json_pure (~> 1.4)
29
- stringex (~> 1.1.0)
30
- uuidtools (~> 2.1.1)
31
- dm-validations (1.0.2)
32
- dm-core (~> 1.0.2)
33
- do_sqlite3 (0.10.2)
34
- data_objects (= 0.10.2)
35
- erubis (2.6.6)
36
- abstract (>= 1.0.0)
37
- extlib (0.9.15)
38
- fastercsv (1.5.3)
39
- json (1.4.6)
40
- json_pure (1.4.6)
41
- merb-assets (1.1.3)
42
- merb-core (~> 1.1.3)
43
- merb-core (1.1.3)
44
- bundler
45
- erubis (>= 2.6.2)
46
- extlib (>= 0.9.13)
47
- mime-types (>= 1.16)
48
- rack
49
- rake
50
- merb-helpers (1.1.3)
51
- merb-core (~> 1.1.3)
52
- merb-slices (1.1.3)
53
- merb-core (~> 1.1.3)
54
- mime-types (1.16)
55
- nokogiri (1.4.3.1)
56
- rack (1.2.1)
57
- rack-test (0.5.4)
58
- rack (>= 1.0)
59
- rake (0.8.7)
60
- rspec (1.3.0)
61
- sequel (3.6.0)
62
- sqlite3-ruby (1.3.1)
63
- stringex (1.1.0)
64
- uuidtools (2.1.1)
65
- webrat (0.7.1)
66
- nokogiri (>= 1.2.0)
67
- rack (>= 1.0)
68
- rack-test (>= 0.5.3)
69
-
70
- PLATFORMS
71
- ruby
72
-
73
- DEPENDENCIES
74
- activerecord (~> 2.3)
75
- builder
76
- dm-aggregates (~> 1.0)
77
- dm-core (~> 1.0)
78
- dm-migrations (~> 1.0)
79
- dm-sqlite-adapter (~> 1.0)
80
- dm-types (~> 1.0)
81
- dm-validations (~> 1.0)
82
- json
83
- merb-assets (~> 1.1)
84
- merb-helpers (~> 1.1)
85
- merb-slices (~> 1.1)
86
- rspec
87
- sequel (~> 3.6.0)
88
- sqlite3-ruby
89
- webrat
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ merb-admin (0.8.6)
5
+ builder (~> 2.1)
6
+ json (~> 1.4)
7
+ merb-assets (~> 1.1)
8
+ merb-helpers (~> 1.1)
9
+ merb-slices (~> 1.1)
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ abstract (1.0.0)
15
+ activerecord (2.3.9)
16
+ activesupport (= 2.3.9)
17
+ activesupport (2.3.9)
18
+ addressable (2.2.1)
19
+ builder (2.1.2)
20
+ daemons (1.1.0)
21
+ data_objects (0.10.2)
22
+ addressable (~> 2.1)
23
+ dm-aggregates (1.0.2)
24
+ dm-core (~> 1.0.2)
25
+ dm-core (1.0.2)
26
+ addressable (~> 2.2)
27
+ extlib (~> 0.9.15)
28
+ dm-do-adapter (1.0.2)
29
+ data_objects (~> 0.10.2)
30
+ dm-core (~> 1.0.2)
31
+ dm-migrations (1.0.2)
32
+ dm-core (~> 1.0.2)
33
+ dm-sqlite-adapter (1.0.2)
34
+ dm-do-adapter (~> 1.0.2)
35
+ do_sqlite3 (~> 0.10.2)
36
+ dm-types (1.0.2)
37
+ dm-core (~> 1.0.2)
38
+ fastercsv (~> 1.5.3)
39
+ json_pure (~> 1.4)
40
+ stringex (~> 1.1.0)
41
+ uuidtools (~> 2.1.1)
42
+ dm-validations (1.0.2)
43
+ dm-core (~> 1.0.2)
44
+ do_sqlite3 (0.10.2)
45
+ data_objects (= 0.10.2)
46
+ erubis (2.6.6)
47
+ abstract (>= 1.0.0)
48
+ eventmachine (0.12.10)
49
+ extlib (0.9.15)
50
+ fastercsv (1.5.3)
51
+ json (1.4.6)
52
+ json_pure (1.4.6)
53
+ merb-assets (1.1.3)
54
+ merb-core (~> 1.1.3)
55
+ merb-core (1.1.3)
56
+ bundler
57
+ erubis (>= 2.6.2)
58
+ extlib (>= 0.9.13)
59
+ mime-types (>= 1.16)
60
+ rack
61
+ rake
62
+ merb-helpers (1.1.3)
63
+ merb-core (~> 1.1.3)
64
+ merb-slices (1.1.3)
65
+ merb-core (~> 1.1.3)
66
+ mime-types (1.16)
67
+ nokogiri (1.4.3.1)
68
+ rack (1.2.1)
69
+ rack-test (0.5.6)
70
+ rack (>= 1.0)
71
+ rake (0.8.7)
72
+ rspec (1.3.0)
73
+ sequel (3.16.0)
74
+ sqlite3-ruby (1.3.1)
75
+ stringex (1.1.0)
76
+ thin (1.2.7)
77
+ daemons (>= 1.0.9)
78
+ eventmachine (>= 0.12.6)
79
+ rack (>= 1.0.0)
80
+ uuidtools (2.1.1)
81
+ webrat (0.7.1)
82
+ nokogiri (>= 1.2.0)
83
+ rack (>= 1.0)
84
+ rack-test (>= 0.5.3)
85
+
86
+ PLATFORMS
87
+ ruby
88
+
89
+ DEPENDENCIES
90
+ activerecord (~> 2.3)
91
+ builder (~> 2.1)
92
+ dm-aggregates (~> 1.0)
93
+ dm-core (~> 1.0)
94
+ dm-migrations (~> 1.0)
95
+ dm-sqlite-adapter (~> 1.0)
96
+ dm-types (~> 1.0)
97
+ dm-validations (~> 1.0)
98
+ json (~> 1.4)
99
+ merb-admin!
100
+ merb-assets (~> 1.1)
101
+ merb-helpers (~> 1.1)
102
+ merb-slices (~> 1.1)
103
+ rspec (~> 1.3)
104
+ sequel (~> 3.16)
105
+ sqlite3-ruby (~> 1.3)
106
+ thin (~> 1.2)
107
+ webrat (~> 0.7)
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2010 Erik Michaels-Ober
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2010 Erik Michaels-Ober
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,54 +1,54 @@
1
- = MerbAdmin
2
- ==== MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data.
3
- It currently offers the features listed here[http://sferik.tadalist.com/lists/1352791/public].
4
-
5
- Take it for a test drive with sample data here[http://merb-admin.heroku.com/].
6
- == Screenshots
7
- http://github.com/sferik/merb-admin/raw/master/screenshots/list.png
8
- http://github.com/sferik/merb-admin/raw/master/screenshots/edit.png
9
- == Installation
10
- $ gem install merb-admin
11
- In your app, add the following dependency to <tt>Gemfile</tt>:
12
- gem "merb-admin"
13
- Add the following route to <tt>config/router.rb</tt>:
14
- add_slice(:merb_admin, :path_prefix => "admin")
15
- Then, run the following rake task:
16
- $ rake slices:merb-admin:install
17
- == Configuration (optional)
18
- If you're feeling crafty, you can set a couple configuration options in <tt>config/init.rb</tt>:
19
- Merb::BootLoader.before_app_loads do
20
- Merb::Slices::config[:merb_admin][:app_name] = "My App"
21
- Merb::Slices::config[:merb_admin][:per_page] = 100
22
- Merb::Slices::config[:merb_admin][:excluded_models] = ["Top", "Secret"]
23
- end
24
- == Usage
25
- Start the server:
26
- $ merb
27
- You should now be able to administer your site at http://localhost:4000/admin.
28
- == WARNING
29
- MerbAdmin does not implement any authorization scheme. Make sure to apply authorization logic before deploying to production!
30
- == Contributing
31
- In the spirit of {free software}[http://www.fsf.org/licensing/essays/free-sw.html], people of all abilities are encouraged to help improve MerbAdmin.
32
-
33
- There are many ways to contribute:
34
- * by reporting bugs
35
- * by suggesting new features
36
- * by writing documentation
37
- * by writing specifications
38
- * by writing code (no patch is too small: fix typos in comments or inconsistent whitespace)
39
- * by refactoring code
40
- * by reviewing patches
41
- * financially[http://pledgie.com/campaigns/5428]
42
-
43
- All contributors will be added to the credits below and will receive the respect and gratitude of the author.
44
- == Contact
45
- If you are interested in contributing to MerbAdmin, please contact Erik Michaels-Ober via email[mailto:sferik@gmail.com], GitHub[http://github.com/sferik/], or Twitter[http://twitter.com/sferik].
46
- == Credits
47
- Many thanks to:
48
- * {Wilson Miner}[http://www.wilsonminer.com] for contributing the stylesheets and javascripts from Django[http://www.djangoproject.com]
49
- * {Aaron Wheeler}[http://fightinjoe.com/] for contributing libraries from {Merb AutoScaffold}[http://github.com/fightinjoe/merb-autoscaffold]
50
- * {Lori Holden}[http://loriholden.com/] for contributing the merb-pagination[http://github.com/lholden/merb-pagination] helper
51
- * {Jacques Crocker}[http://merbjedi.com] for adding support for {namespaced models}[http://github.com/merbjedi/merb-admin/commit/8139e2241038baf9b72452056fcdc7c340d79275]
52
- * {Jeremy Evans}[http://code.jeremyevans.net] and {Pavel Kunc}[http://www.merboutpost.com] for reviewing the {patch}[http://github.com/sferik/merb-admin/commit/061fa28f652fc9214e9cf480d66870140181edef] to add Sequel[http://sequel.rubyforge.org/] support
53
- * {Jonah Honeyman}[http://twitter.com/jonuts] for fixing a bug[http://github.com/sferik/merb-admin/commit/9064d10382eadd1ed7a882ef40e2c6a65edfef2c] and adding the {:excluded_models option}[http://github.com/sferik/merb-admin/commit/f6157d1c471dd85162481d6926578164be1b9673]
54
- Also, thanks to beer[http://www.21st-amendment.com].
1
+ = MerbAdmin
2
+ ==== MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data.
3
+ It currently offers the features listed here[http://sferik.tadalist.com/lists/1352791/public].
4
+
5
+ Take it for a test drive with sample data here[http://merb-admin.heroku.com/].
6
+ == Screenshots
7
+ http://github.com/sferik/merb-admin/raw/master/screenshots/list.png
8
+ http://github.com/sferik/merb-admin/raw/master/screenshots/edit.png
9
+ == Installation
10
+ $ gem install merb-admin
11
+ In your app, add the following dependency to <tt>Gemfile</tt>:
12
+ gem "merb-admin"
13
+ Add the following route to <tt>config/router.rb</tt>:
14
+ add_slice(:merb_admin, :path_prefix => "admin")
15
+ Then, run the following rake task:
16
+ $ rake slices:merb-admin:install
17
+ == Configuration (optional)
18
+ If you're feeling crafty, you can set a couple configuration options in <tt>config/init.rb</tt>:
19
+ Merb::BootLoader.before_app_loads do
20
+ Merb::Slices::config[:merb_admin][:app_name] = "My App"
21
+ Merb::Slices::config[:merb_admin][:per_page] = 100
22
+ Merb::Slices::config[:merb_admin][:excluded_models] = ["Top", "Secret"]
23
+ end
24
+ == Usage
25
+ Start the server:
26
+ $ merb
27
+ You should now be able to administer your site at http://localhost:4000/admin.
28
+ == WARNING
29
+ MerbAdmin does not implement any authorization scheme. Make sure to apply authorization logic before deploying to production!
30
+ == Contributing
31
+ In the spirit of {free software}[http://www.fsf.org/licensing/essays/free-sw.html], people of all abilities are encouraged to help improve MerbAdmin.
32
+
33
+ There are many ways to contribute:
34
+ * by reporting bugs
35
+ * by suggesting new features
36
+ * by writing documentation
37
+ * by writing specifications
38
+ * by writing code (no patch is too small: fix typos in comments or inconsistent whitespace)
39
+ * by refactoring code
40
+ * by reviewing patches
41
+ * financially[http://pledgie.com/campaigns/5428]
42
+
43
+ All contributors will be added to the credits below and will receive the respect and gratitude of the author.
44
+ == Contact
45
+ If you are interested in contributing to MerbAdmin, please contact Erik Michaels-Ober via email[mailto:sferik@gmail.com], GitHub[http://github.com/sferik/], or Twitter[http://twitter.com/sferik].
46
+ == Credits
47
+ Many thanks to:
48
+ * {Wilson Miner}[http://www.wilsonminer.com] for contributing the stylesheets and javascripts from Django[http://www.djangoproject.com]
49
+ * {Aaron Wheeler}[http://fightinjoe.com/] for contributing libraries from {Merb AutoScaffold}[http://github.com/fightinjoe/merb-autoscaffold]
50
+ * {Lori Holden}[http://loriholden.com/] for contributing the merb-pagination[http://github.com/lholden/merb-pagination] helper
51
+ * {Jacques Crocker}[http://merbjedi.com] for adding support for {namespaced models}[http://github.com/merbjedi/merb-admin/commit/8139e2241038baf9b72452056fcdc7c340d79275]
52
+ * {Jeremy Evans}[http://code.jeremyevans.net] and {Pavel Kunc}[http://www.merboutpost.com] for reviewing the {patch}[http://github.com/sferik/merb-admin/commit/061fa28f652fc9214e9cf480d66870140181edef] to add Sequel[http://sequel.rubyforge.org/] support
53
+ * {Jonah Honeyman}[http://twitter.com/jonuts] for fixing a bug[http://github.com/sferik/merb-admin/commit/9064d10382eadd1ed7a882ef40e2c6a65edfef2c] and adding the {:excluded_models option}[http://github.com/sferik/merb-admin/commit/f6157d1c471dd85162481d6926578164be1b9673]
54
+ Also, thanks to beer[http://www.21st-amendment.com].
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
- require 'rubygems'
2
- require 'merb-core'
3
- require 'merb-core/tasks/merb'
4
- require 'spec/rake/spectask'
5
- require 'merb-core/test/tasks/spectasks'
6
- require 'bundler'
7
-
8
- Bundler::GemHelper.install_tasks
9
-
10
- desc 'Run specs'
11
- task :default => 'spec'
1
+ require 'rubygems'
2
+ require 'merb-core'
3
+ require 'merb-core/tasks/merb'
4
+ require 'spec/rake/spectask'
5
+ require 'merb-core/test/tasks/spectasks'
6
+ require 'bundler'
7
+
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ desc 'Run specs'
11
+ task :default => 'spec'
@@ -1,6 +1,6 @@
1
- class MerbAdmin::Application < Merb::Controller
2
- include Merb::MerbAdmin::ApplicationHelper
3
-
4
- controller_for_slice
5
-
6
- end
1
+ class MerbAdmin::Application < Merb::Controller
2
+ include Merb::MerbAdmin::ApplicationHelper
3
+
4
+ controller_for_slice
5
+
6
+ end
@@ -1,191 +1,191 @@
1
- require File.join( File.dirname(__FILE__), '..', '..', 'lib', 'abstract_model' )
2
-
3
- class MerbAdmin::Main < MerbAdmin::Application
4
- include Merb::MerbAdmin::MainHelper
5
-
6
- before :get_model, :exclude => ['index']
7
- before :get_object, :only => ['edit', 'update', 'delete', 'destroy']
8
- before :get_attributes, :only => ['create', 'update']
9
-
10
- def index
11
- @abstract_models = MerbAdmin::AbstractModel.all
12
- render(:layout => 'dashboard')
13
- end
14
-
15
- def list
16
- options = {}
17
- options.merge!(get_sort_hash)
18
- options.merge!(get_sort_reverse_hash)
19
- options.merge!(get_query_hash(options))
20
- options.merge!(get_filter_hash(options))
21
- per_page = MerbAdmin[:per_page]
22
- if params[:all]
23
- options.merge!(:limit => per_page * 2)
24
- @objects = @abstract_model.all(options).reverse
25
- else
26
- @current_page = (params[:page] || 1).to_i
27
- options.merge!(:page => @current_page, :per_page => per_page)
28
- @page_count, @objects = @abstract_model.paginated(options)
29
- options.delete(:page)
30
- options.delete(:per_page)
31
- options.delete(:offset)
32
- options.delete(:limit)
33
- end
34
- @record_count = @abstract_model.count(options)
35
- render(:layout => 'list')
36
- end
37
-
38
- def new
39
- @object = @abstract_model.new
40
- render(:layout => 'form')
41
- end
42
-
43
- def create
44
- @object = @abstract_model.new(@attributes)
45
- if @object.save && update_all_associations
46
- redirect_on_success
47
- else
48
- render_error(:new)
49
- end
50
- end
51
-
52
- def edit
53
- render(:layout => 'form')
54
- end
55
-
56
- def update
57
- if @object.update_attributes(@attributes) && update_all_associations
58
- redirect_on_success
59
- else
60
- render_error(:edit)
61
- end
62
- end
63
-
64
- def delete
65
- render(:layout => 'form')
66
- end
67
-
68
- def destroy
69
- if @object.destroy
70
- redirect(url(:merb_admin_list, :model_name => @abstract_model.to_param), :message => {:notice => "#{@abstract_model.pretty_name} was successfully destroyed"})
71
- else
72
- raise BadRequest
73
- end
74
- end
75
-
76
- private
77
-
78
- def get_model
79
- model_name = to_model_name(params[:model_name])
80
- @abstract_model = MerbAdmin::AbstractModel.new(model_name)
81
- @properties = @abstract_model.properties
82
- end
83
-
84
- def get_object
85
- @object = @abstract_model.get(params[:id])
86
- raise NotFound unless @object
87
- end
88
-
89
- def get_sort_hash
90
- sort = params[:sort]
91
- sort ? {:sort => sort} : {}
92
- end
93
-
94
- def get_sort_reverse_hash
95
- sort_reverse = params[:sort_reverse]
96
- sort_reverse ? {:sort_reverse => sort_reverse == "true"} : {}
97
- end
98
-
99
- def get_query_hash(options)
100
- query = params[:query]
101
- return {} unless query
102
- statements = []
103
- values = []
104
- conditions = options[:conditions] || [""]
105
-
106
- @properties.select{|property| property[:type] == :string}.each do |property|
107
- statements << "(#{property[:name]} LIKE ?)"
108
- values << "%#{query}%"
109
- end
110
-
111
- conditions[0] += " AND " unless conditions == [""]
112
- conditions[0] += statements.join(" OR ")
113
- conditions += values
114
- conditions != [""] ? {:conditions => conditions} : {}
115
- end
116
-
117
- def get_filter_hash(options)
118
- filter = params[:filter]
119
- return {} unless filter
120
- statements = []
121
- values = []
122
- conditions = options[:conditions] || [""]
123
-
124
- filter.each_pair do |key, value|
125
- @properties.select{|property| property[:type] == :boolean && property[:name] == key.to_sym}.each do |property|
126
- statements << "(#{key} = ?)"
127
- values << (value == "true")
128
- end
129
- end
130
-
131
- conditions[0] += " AND " unless conditions == [""]
132
- conditions[0] += statements.join(" AND ")
133
- conditions += values
134
- conditions != [""] ? {:conditions => conditions} : {}
135
- end
136
-
137
- def get_attributes
138
- @attributes = params[@abstract_model.to_param] || {}
139
- # Delete fields that are blank
140
- @attributes.each do |key, value|
141
- @attributes[key] = nil if value.blank?
142
- end
143
- end
144
-
145
- def update_all_associations
146
- @abstract_model.associations.each do |association|
147
- ids = (params[:associations] || {}).delete(association[:name])
148
- case association[:type]
149
- when :has_one
150
- update_association(association, ids)
151
- when :has_many
152
- update_associations(association, ids.to_a)
153
- end
154
- end
155
- end
156
-
157
- def update_association(association, id = nil)
158
- associated_model = MerbAdmin::AbstractModel.new(association[:child_model])
159
- if object = associated_model.get(id)
160
- object.update_attributes(association[:child_key].first => @object.id)
161
- end
162
- end
163
-
164
- def update_associations(association, ids = [])
165
- @object.send(association[:name]).clear
166
- ids.each do |id|
167
- update_association(association, id)
168
- end
169
- @object.save
170
- end
171
-
172
- def redirect_on_success
173
- param = @abstract_model.to_param
174
- pretty_name = @abstract_model.pretty_name
175
- action = params[:action]
176
- if params[:_continue]
177
- redirect(url(:merb_admin_edit, :model_name => param, :id => @object.id), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
178
- elsif params[:_add_another]
179
- redirect(url(:merb_admin_new, :model_name => param), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
180
- else
181
- redirect(url(:merb_admin_list, :model_name => param), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
182
- end
183
- end
184
-
185
- def render_error(template)
186
- action = params[:action]
187
- message[:error] = "#{@abstract_model.pretty_name} failed to be #{action}d"
188
- render(template, :layout => 'form')
189
- end
190
-
191
- end
1
+ require File.join( File.dirname(__FILE__), '..', '..', 'lib', 'abstract_model' )
2
+
3
+ class MerbAdmin::Main < MerbAdmin::Application
4
+ include Merb::MerbAdmin::MainHelper
5
+
6
+ before :get_model, :exclude => ['index']
7
+ before :get_object, :only => ['edit', 'update', 'delete', 'destroy']
8
+ before :get_attributes, :only => ['create', 'update']
9
+
10
+ def index
11
+ @abstract_models = MerbAdmin::AbstractModel.all
12
+ render(:layout => 'dashboard')
13
+ end
14
+
15
+ def list
16
+ options = {}
17
+ options.merge!(get_sort_hash)
18
+ options.merge!(get_sort_reverse_hash)
19
+ options.merge!(get_query_hash(options))
20
+ options.merge!(get_filter_hash(options))
21
+ per_page = MerbAdmin[:per_page]
22
+ if params[:all]
23
+ options.merge!(:limit => per_page * 2)
24
+ @objects = @abstract_model.all(options).reverse
25
+ else
26
+ @current_page = (params[:page] || 1).to_i
27
+ options.merge!(:page => @current_page, :per_page => per_page)
28
+ @page_count, @objects = @abstract_model.paginated(options)
29
+ options.delete(:page)
30
+ options.delete(:per_page)
31
+ options.delete(:offset)
32
+ options.delete(:limit)
33
+ end
34
+ @record_count = @abstract_model.count(options)
35
+ render(:layout => 'list')
36
+ end
37
+
38
+ def new
39
+ @object = @abstract_model.new
40
+ render(:layout => 'form')
41
+ end
42
+
43
+ def create
44
+ @object = @abstract_model.new(@attributes)
45
+ if @object.save && update_all_associations
46
+ redirect_on_success
47
+ else
48
+ render_error(:new)
49
+ end
50
+ end
51
+
52
+ def edit
53
+ render(:layout => 'form')
54
+ end
55
+
56
+ def update
57
+ if @object.update_attributes(@attributes) && update_all_associations
58
+ redirect_on_success
59
+ else
60
+ render_error(:edit)
61
+ end
62
+ end
63
+
64
+ def delete
65
+ render(:layout => 'form')
66
+ end
67
+
68
+ def destroy
69
+ if @object.destroy
70
+ redirect(url(:merb_admin_list, :model_name => @abstract_model.to_param), :message => {:notice => "#{@abstract_model.pretty_name} was successfully destroyed"})
71
+ else
72
+ raise BadRequest
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def get_model
79
+ model_name = to_model_name(params[:model_name])
80
+ @abstract_model = MerbAdmin::AbstractModel.new(model_name)
81
+ @properties = @abstract_model.properties
82
+ end
83
+
84
+ def get_object
85
+ @object = @abstract_model.get(params[:id])
86
+ raise NotFound unless @object
87
+ end
88
+
89
+ def get_sort_hash
90
+ sort = params[:sort]
91
+ sort ? {:sort => sort} : {}
92
+ end
93
+
94
+ def get_sort_reverse_hash
95
+ sort_reverse = params[:sort_reverse]
96
+ sort_reverse ? {:sort_reverse => sort_reverse == "true"} : {}
97
+ end
98
+
99
+ def get_query_hash(options)
100
+ query = params[:query]
101
+ return {} unless query
102
+ statements = []
103
+ values = []
104
+ conditions = options[:conditions] || [""]
105
+
106
+ @properties.select{|property| property[:type] == :string}.each do |property|
107
+ statements << "(#{property[:name]} LIKE ?)"
108
+ values << "%#{query}%"
109
+ end
110
+
111
+ conditions[0] += " AND " unless conditions == [""]
112
+ conditions[0] += statements.join(" OR ")
113
+ conditions += values
114
+ conditions != [""] ? {:conditions => conditions} : {}
115
+ end
116
+
117
+ def get_filter_hash(options)
118
+ filter = params[:filter]
119
+ return {} unless filter
120
+ statements = []
121
+ values = []
122
+ conditions = options[:conditions] || [""]
123
+
124
+ filter.each_pair do |key, value|
125
+ @properties.select{|property| property[:type] == :boolean && property[:name] == key.to_sym}.each do |property|
126
+ statements << "(#{key} = ?)"
127
+ values << (value == "true")
128
+ end
129
+ end
130
+
131
+ conditions[0] += " AND " unless conditions == [""]
132
+ conditions[0] += statements.join(" AND ")
133
+ conditions += values
134
+ conditions != [""] ? {:conditions => conditions} : {}
135
+ end
136
+
137
+ def get_attributes
138
+ @attributes = params[@abstract_model.to_param] || {}
139
+ # Delete fields that are blank
140
+ @attributes.each do |key, value|
141
+ @attributes[key] = nil if value.blank?
142
+ end
143
+ end
144
+
145
+ def update_all_associations
146
+ @abstract_model.associations.each do |association|
147
+ ids = (params[:associations] || {}).delete(association[:name])
148
+ case association[:type]
149
+ when :has_one
150
+ update_association(association, ids)
151
+ when :has_many
152
+ update_associations(association, ids.to_a)
153
+ end
154
+ end
155
+ end
156
+
157
+ def update_association(association, id = nil)
158
+ associated_model = MerbAdmin::AbstractModel.new(association[:child_model])
159
+ if object = associated_model.get(id)
160
+ object.update_attributes(association[:child_key].first => @object.id)
161
+ end
162
+ end
163
+
164
+ def update_associations(association, ids = [])
165
+ @object.send(association[:name]).clear
166
+ ids.each do |id|
167
+ update_association(association, id)
168
+ end
169
+ @object.save
170
+ end
171
+
172
+ def redirect_on_success
173
+ param = @abstract_model.to_param
174
+ pretty_name = @abstract_model.pretty_name
175
+ action = params[:action]
176
+ if params[:_continue]
177
+ redirect(url(:merb_admin_edit, :model_name => param, :id => @object.id), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
178
+ elsif params[:_add_another]
179
+ redirect(url(:merb_admin_new, :model_name => param), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
180
+ else
181
+ redirect(url(:merb_admin_list, :model_name => param), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
182
+ end
183
+ end
184
+
185
+ def render_error(template)
186
+ action = params[:action]
187
+ message[:error] = "#{@abstract_model.pretty_name} failed to be #{action}d"
188
+ render(template, :layout => 'form')
189
+ end
190
+
191
+ end