merb-admin 0.8.1 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.gitignore +29 -27
  2. data/Gemfile +24 -22
  3. data/Gemfile.lock +86 -0
  4. data/LICENSE +20 -20
  5. data/README.rdoc +54 -58
  6. data/Rakefile +11 -44
  7. data/app/controllers/application.rb +6 -6
  8. data/app/controllers/main.rb +191 -191
  9. data/app/helpers/application_helper.rb +64 -64
  10. data/app/helpers/main_helper.rb +167 -167
  11. data/app/models/.gitkeep +0 -0
  12. data/app/views/layout/_message.html.erb +10 -10
  13. data/app/views/layout/dashboard.html.erb +34 -34
  14. data/app/views/layout/form.html.erb +48 -48
  15. data/app/views/layout/list.html.erb +42 -42
  16. data/app/views/main/_belongs_to.html.erb +29 -29
  17. data/app/views/main/_big_decimal.html.erb +12 -12
  18. data/app/views/main/_boolean.html.erb +7 -7
  19. data/app/views/main/_date.html.erb +12 -12
  20. data/app/views/main/_datetime.html.erb +12 -12
  21. data/app/views/main/_float.html.erb +12 -12
  22. data/app/views/main/_has_many.html.erb +16 -16
  23. data/app/views/main/_has_one.html.erb +30 -30
  24. data/app/views/main/_integer.html.erb +12 -12
  25. data/app/views/main/_properties.html.erb +18 -18
  26. data/app/views/main/_string.html.erb +15 -15
  27. data/app/views/main/_text.html.erb +11 -11
  28. data/app/views/main/_time.html.erb +12 -12
  29. data/app/views/main/_timestamp.html.erb +12 -12
  30. data/app/views/main/delete.html.erb +28 -28
  31. data/app/views/main/edit.html.erb +19 -19
  32. data/app/views/main/index.html.erb +22 -22
  33. data/app/views/main/list.html.erb +93 -93
  34. data/app/views/main/new.html.erb +16 -16
  35. data/config/init.rb +30 -0
  36. data/config/router.rb +4 -0
  37. data/lib/abstract_model.rb +84 -86
  38. data/lib/active_record_support.rb +147 -147
  39. data/lib/datamapper_support.rb +139 -140
  40. data/lib/generic_support.rb +13 -13
  41. data/lib/merb-admin.rb +99 -99
  42. data/lib/merb-admin/merbtasks.rb +103 -103
  43. data/lib/merb-admin/slicetasks.rb +174 -174
  44. data/lib/merb-admin/spectasks.rb +55 -55
  45. data/lib/merb-admin/version.rb +3 -0
  46. data/lib/sequel_support.rb +275 -275
  47. data/merb-admin.gemspec +42 -232
  48. data/public/javascripts/CollapsedFieldsets.js +85 -85
  49. data/public/javascripts/DateTimeShortcuts.js +255 -255
  50. data/public/javascripts/RelatedObjectLookups.js +96 -96
  51. data/public/javascripts/SelectBox.js +111 -111
  52. data/public/javascripts/SelectFilter2.js +113 -113
  53. data/public/javascripts/actions.js +39 -39
  54. data/public/javascripts/calendar.js +143 -143
  55. data/public/javascripts/core.js +176 -176
  56. data/public/javascripts/dateparse.js +233 -233
  57. data/public/javascripts/getElementsBySelector.js +167 -167
  58. data/public/javascripts/i18n.js +33 -33
  59. data/public/javascripts/ordering.js +137 -137
  60. data/public/javascripts/timeparse.js +94 -94
  61. data/public/javascripts/urlify.js +140 -140
  62. data/public/stylesheets/base.css +746 -746
  63. data/public/stylesheets/changelists.css +269 -269
  64. data/public/stylesheets/dashboard.css +24 -24
  65. data/public/stylesheets/forms.css +327 -327
  66. data/public/stylesheets/global.css +142 -142
  67. data/public/stylesheets/ie.css +50 -50
  68. data/public/stylesheets/layout.css +29 -29
  69. data/public/stylesheets/login.css +54 -54
  70. data/public/stylesheets/master.css +1 -1
  71. data/public/stylesheets/patch-iewin.css +7 -7
  72. data/public/stylesheets/rtl.css +206 -206
  73. data/public/stylesheets/widgets.css +506 -506
  74. data/screenshots/create.png +0 -0
  75. data/screenshots/delete.png +0 -0
  76. data/screenshots/edit.png +0 -0
  77. data/screenshots/index.png +0 -0
  78. data/screenshots/list.png +0 -0
  79. data/screenshots/new.png +0 -0
  80. data/spec/controllers/main_spec.rb +25 -25
  81. data/spec/migrations/activerecord/001_create_divisions_migration.rb +13 -13
  82. data/spec/migrations/activerecord/002_create_drafts_migration.rb +19 -19
  83. data/spec/migrations/activerecord/003_create_leagues_migration.rb +12 -12
  84. data/spec/migrations/activerecord/004_create_players_migration.rb +19 -20
  85. data/spec/migrations/activerecord/005_create_teams_migration.rb +22 -22
  86. data/spec/migrations/sequel/001_create_divisions_migration.rb +15 -15
  87. data/spec/migrations/sequel/002_create_drafts_migration.rb +21 -21
  88. data/spec/migrations/sequel/003_create_leagues_migration.rb +14 -14
  89. data/spec/migrations/sequel/004_create_players_migration.rb +21 -22
  90. data/spec/migrations/sequel/005_create_teams_migration.rb +24 -24
  91. data/spec/models/activerecord/division.rb +7 -7
  92. data/spec/models/activerecord/draft.rb +11 -11
  93. data/spec/models/activerecord/league.rb +6 -6
  94. data/spec/models/activerecord/player.rb +8 -8
  95. data/spec/models/activerecord/team.rb +13 -13
  96. data/spec/models/datamapper/division.rb +12 -12
  97. data/spec/models/datamapper/draft.rb +18 -18
  98. data/spec/models/datamapper/league.rb +11 -11
  99. data/spec/models/datamapper/player.rb +20 -21
  100. data/spec/models/datamapper/team.rb +22 -22
  101. data/spec/models/sequel/division.rb +15 -15
  102. data/spec/models/sequel/draft.rb +19 -19
  103. data/spec/models/sequel/league.rb +14 -14
  104. data/spec/models/sequel/player.rb +18 -18
  105. data/spec/models/sequel/team.rb +21 -21
  106. data/spec/requests/main_spec.rb +763 -763
  107. data/spec/spec_helper.rb +113 -112
  108. metadata +247 -41
  109. data/VERSION +0 -1
data/.gitignore CHANGED
@@ -1,27 +1,29 @@
1
- *.db
2
- *.sqlite
3
- *.sqlite3
4
- *~
5
- .#*
6
- .DS_Store
7
- .hg/*
8
- .hgignore
9
- .svn/*
10
- TAGS
11
- TODO
12
- bin/*
13
- coverage/*
14
- doc/*
15
- gems/
16
- !gems/cache/
17
- log/*
18
- merb_profile_results
19
- pkg/*
20
- schema/*.db
21
- schema/*.sqlite
22
- schema/*.sqlite3
23
- schema/*_structure.sql
24
- schema/schema.rb
25
- src/*
26
- tmp/*
27
- *.sw[p|o]
1
+ !gems/cache/
2
+ *.db
3
+ *.gem
4
+ *.sqlite
5
+ *.sqlite3
6
+ *.sw[p|o]
7
+ *~
8
+ .#*
9
+ .DS_Store
10
+ .bundle
11
+ .hg/*
12
+ .hgignore
13
+ .svn/*
14
+ TAGS
15
+ TODO
16
+ bin/*
17
+ coverage/*
18
+ doc/*
19
+ gems/
20
+ log/*
21
+ merb_profile_results
22
+ pkg/*
23
+ schema/*.db
24
+ schema/*.sqlite
25
+ schema/*.sqlite3
26
+ schema/*_structure.sql
27
+ schema/schema.rb
28
+ src/*
29
+ tmp/*
data/Gemfile CHANGED
@@ -1,22 +1,24 @@
1
- # dependencies are generated using a strict version, don't forget to edit the dependency versions when upgrading.
2
- merb_gems_version = "1.1.0"
3
-
4
- # If you did disable json for Merb, comment out this line.
5
- # If you want use json gem just change it.
6
- # Don't use json gem version lower than 1.1.7! Older versions has security bug!
7
- gem "json_pure", ">= 1.1.7", :require => "json"
8
- gem "merb-core", merb_gems_version
9
- gem "builder", "~> 2.1"
10
-
11
- group :test do
12
- gem "activerecord", "~> 2.3", :require => "active_record"
13
- gem "dm-core", "~> 0.10"
14
- gem "dm-aggregates", "~> 0.10"
15
- gem "dm-validations", "~> 0.10"
16
- gem "data_objects", "~> 0.10"
17
- gem "do_sqlite3", "~> 0.10"
18
- gem "rspec", "~> 1.3"
19
- gem "sequel", "~> 3.10"
20
- gem "sqlite3-ruby", "~> 1.2", :require => "sqlite3"
21
- gem "webrat", "~> 0.7"
22
- end
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', '~> 0.10'
14
+ gem 'dm-aggregates', '~> 0.10'
15
+ gem 'dm-types', '~> 0.10'
16
+ gem 'dm-migrations', '~> 0.10'
17
+ gem 'dm-validations', '~> 0.10'
18
+ gem 'data_objects', '~> 0.10'
19
+ gem 'do_sqlite3', '~> 0.10'
20
+ gem 'rspec'
21
+ gem 'sequel', '~> 3.6.0'
22
+ gem 'sqlite3-ruby', :require => 'sqlite3'
23
+ gem 'webrat'
24
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,86 @@
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
+ bcrypt-ruby (2.1.2)
10
+ builder (2.1.2)
11
+ data_objects (0.10.2)
12
+ addressable (~> 2.1)
13
+ dm-aggregates (0.10.2)
14
+ dm-core (~> 0.10.2)
15
+ dm-core (0.10.2)
16
+ addressable (~> 2.1)
17
+ extlib (~> 0.9.14)
18
+ dm-migrations (0.10.2)
19
+ dm-core (~> 0.10.2)
20
+ dm-types (0.10.2)
21
+ bcrypt-ruby (~> 2.1.2)
22
+ dm-core (~> 0.10.2)
23
+ fastercsv (~> 1.5.0)
24
+ json_pure (~> 1.2.0)
25
+ stringex (~> 1.1.0)
26
+ uuidtools (~> 2.1.1)
27
+ dm-validations (0.10.2)
28
+ dm-core (~> 0.10.2)
29
+ do_sqlite3 (0.10.2)
30
+ data_objects (= 0.10.2)
31
+ erubis (2.6.6)
32
+ abstract (>= 1.0.0)
33
+ extlib (0.9.15)
34
+ fastercsv (1.5.3)
35
+ json (1.4.6)
36
+ json_pure (1.2.4)
37
+ merb-assets (1.1.3)
38
+ merb-core (~> 1.1.3)
39
+ merb-core (1.1.3)
40
+ bundler
41
+ erubis (>= 2.6.2)
42
+ extlib (>= 0.9.13)
43
+ mime-types (>= 1.16)
44
+ rack
45
+ rake
46
+ merb-helpers (1.1.3)
47
+ merb-core (~> 1.1.3)
48
+ merb-slices (1.1.3)
49
+ merb-core (~> 1.1.3)
50
+ mime-types (1.16)
51
+ nokogiri (1.4.3.1)
52
+ rack (1.2.1)
53
+ rack-test (0.5.4)
54
+ rack (>= 1.0)
55
+ rake (0.8.7)
56
+ rspec (1.3.0)
57
+ sequel (3.6.0)
58
+ sqlite3-ruby (1.3.1)
59
+ stringex (1.1.0)
60
+ uuidtools (2.1.1)
61
+ webrat (0.7.1)
62
+ nokogiri (>= 1.2.0)
63
+ rack (>= 1.0)
64
+ rack-test (>= 0.5.3)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ activerecord (~> 2.3)
71
+ builder
72
+ data_objects (~> 0.10)
73
+ dm-aggregates (~> 0.10)
74
+ dm-core (~> 0.10)
75
+ dm-migrations (~> 0.10)
76
+ dm-types (~> 0.10)
77
+ dm-validations (~> 0.10)
78
+ do_sqlite3 (~> 0.10)
79
+ json
80
+ merb-assets (~> 1.1)
81
+ merb-helpers (~> 1.1)
82
+ merb-slices (~> 1.1)
83
+ rspec
84
+ sequel (~> 3.6.0)
85
+ sqlite3-ruby
86
+ webrat
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2009 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) 2009 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.
data/README.rdoc CHANGED
@@ -1,58 +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
-
7
- The status of the latest build is available here[http://runcoderun.com/sferik/merb-admin].
8
-
9
- Various code metrics are available here[http://devver.net/caliper/project?repo=git://github.com/sferik/merb-admin.git].
10
- == Screenshots
11
- http://github.com/sferik/merb-admin/raw/master/screenshots/list.png
12
- http://github.com/sferik/merb-admin/raw/master/screenshots/edit.png
13
- == Installation
14
- $ gem install merb-admin -s http://gemcutter.org
15
- In your app, add the following dependency to <tt>config/dependencies.rb</tt>:
16
- dependency "merb-admin", "0.8.1"
17
- Add the following route to <tt>config/router.rb</tt>:
18
- add_slice(:merb_admin, :path_prefix => "admin")
19
- Then, run the following rake task:
20
- $ rake slices:merb-admin:install
21
- == Configuration (optional)
22
- If you're feeling crafty, you can set a couple configuration options in <tt>config/init.rb</tt>:
23
- Merb::BootLoader.before_app_loads do
24
- Merb::Slices::config[:merb_admin][:app_name] = "My App"
25
- Merb::Slices::config[:merb_admin][:per_page] = 100
26
- Merb::Slices::config[:merb_admin][:excluded_models] = ["Top", "Secret"]
27
- end
28
- == Usage
29
- Start the server:
30
- $ merb
31
- You should now be able to administer your site at http://localhost:4000/admin.
32
- == WARNING
33
- MerbAdmin does not implement any authorization scheme. Make sure to apply authorization logic before deploying to production!
34
- == Contributing
35
- 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.
36
-
37
- There are many ways to contribute:
38
- * by reporting bugs
39
- * by suggesting new features
40
- * by writing documentation
41
- * by writing specifications
42
- * by writing code (no patch is too small: fix typos in comments or inconsistent whitespace)
43
- * by refactoring code
44
- * by reviewing patches
45
- * financially[http://pledgie.com/campaigns/5428]
46
-
47
- All contributors will be added to the credits below and will receive the respect and gratitude of the author.
48
- == Contact
49
- 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].
50
- == Credits
51
- Many thanks to:
52
- * {Wilson Miner}[http://www.wilsonminer.com] for contributing the stylesheets and javascripts from Django[http://www.djangoproject.com]
53
- * {Aaron Wheeler}[http://fightinjoe.com/] for contributing libraries from {Merb AutoScaffold}[http://github.com/fightinjoe/merb-autoscaffold]
54
- * {Lori Holden}[http://loriholden.com/] for contributing the merb-pagination[http://github.com/lholden/merb-pagination] helper
55
- * {Jacques Crocker}[http://merbjedi.com] for adding support for {namespaced models}[http://github.com/merbjedi/merb-admin/commit/8139e2241038baf9b72452056fcdc7c340d79275]
56
- * {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
57
- * {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]
58
- 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 -s http://gemcutter.org
11
+ In your app, add the following dependency to <tt>config/dependencies.rb</tt>:
12
+ dependency "merb-admin", "0.8.3"
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,44 +1,11 @@
1
- require "rubygems"
2
- require "merb-core"
3
- require "merb-core/tasks/merb"
4
-
5
- GEM_NAME = "merb-admin"
6
- AUTHOR = "Erik Michaels-Ober"
7
- EMAIL = "sferik@gmail.com"
8
- HOMEPAGE = "http://github.com/sferik/merb-admin"
9
- SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
10
- MERB_GEM_VERSION = "1.1"
11
-
12
- begin
13
- require 'jeweler'
14
- Jeweler::Tasks.new do |gemspec|
15
- gemspec.name = GEM_NAME
16
- gemspec.summary = SUMMARY
17
- gemspec.description = gemspec.summary
18
- gemspec.author = AUTHOR
19
- gemspec.email = EMAIL
20
- gemspec.homepage = HOMEPAGE
21
- gemspec.files.exclude("config/*", "screenshots/*")
22
- gemspec.add_dependency("merb-slices", "~> #{MERB_GEM_VERSION}")
23
- gemspec.add_dependency("merb-assets", "~> #{MERB_GEM_VERSION}")
24
- gemspec.add_dependency("merb-helpers", "~> #{MERB_GEM_VERSION}")
25
- gemspec.add_dependency("builder", "~> 2.1")
26
- gemspec.add_development_dependency("rspec", "~> 1.3")
27
- gemspec.post_install_message = <<-POST_INSTALL_MESSAGE
28
- #{"*" * 80}
29
-
30
- WARNING: MerbAdmin does not implement any authorization scheme.
31
- Make sure to apply authorization logic before deploying to production!
32
-
33
- #{"*" * 80}
34
- POST_INSTALL_MESSAGE
35
- end
36
- Jeweler::GemcutterTasks.new
37
- rescue LoadError
38
- puts "Jeweler not available. Install it with: gem install jeweler"
39
- end
40
-
41
- require "spec/rake/spectask"
42
- require "merb-core/test/tasks/spectasks"
43
- desc "Default: run spec examples"
44
- 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