tournament 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/History.txt +15 -0
  2. data/Manifest.txt +241 -2
  3. data/README.txt +152 -12
  4. data/Rakefile +9 -6
  5. data/bin/benchmark_pool +0 -0
  6. data/bin/gui.rb +3 -1
  7. data/bin/picker +0 -0
  8. data/bin/pool +139 -15
  9. data/lib/tournament/bracket.rb +33 -50
  10. data/lib/tournament/entry.rb +3 -0
  11. data/lib/tournament/pool.rb +144 -93
  12. data/lib/tournament/scoring_strategy.rb +69 -0
  13. data/lib/tournament/webgui_installer.rb +109 -0
  14. data/tasks/ann.rake +19 -14
  15. data/tasks/bones.rake +6 -25
  16. data/tasks/gem.rake +46 -36
  17. data/tasks/git.rake +41 -0
  18. data/tasks/jamis.rb +589 -0
  19. data/tasks/notes.rake +28 -0
  20. data/tasks/post_load.rake +18 -11
  21. data/tasks/{doc.rake → rdoc.rake} +12 -9
  22. data/tasks/rubyforge.rake +12 -12
  23. data/tasks/setup.rb +121 -80
  24. data/tasks/spec.rake +12 -13
  25. data/tasks/svn.rake +15 -11
  26. data/tasks/test.rake +6 -6
  27. data/test/test_tournament.rb +8 -0
  28. data/test/test_webgui_installer.rb +64 -0
  29. data/webgui/README +256 -0
  30. data/webgui/Rakefile +10 -0
  31. data/webgui/app/controllers/admin_controller.rb +61 -0
  32. data/webgui/app/controllers/application.rb +25 -0
  33. data/webgui/app/controllers/entry_controller.rb +97 -0
  34. data/webgui/app/controllers/pool_controller.rb +4 -0
  35. data/webgui/app/controllers/reports_controller.rb +7 -0
  36. data/webgui/app/controllers/sessions_controller.rb +43 -0
  37. data/webgui/app/controllers/teams_controller.rb +75 -0
  38. data/webgui/app/controllers/users_controller.rb +57 -0
  39. data/webgui/app/helpers/admin_helper.rb +2 -0
  40. data/webgui/app/helpers/application_helper.rb +3 -0
  41. data/webgui/app/helpers/entry_helper.rb +2 -0
  42. data/webgui/app/helpers/pool_helper.rb +2 -0
  43. data/webgui/app/helpers/reports_helper.rb +2 -0
  44. data/webgui/app/helpers/sessions_helper.rb +2 -0
  45. data/webgui/app/helpers/teams_helper.rb +2 -0
  46. data/webgui/app/helpers/users_helper.rb +93 -0
  47. data/webgui/app/models/entry.rb +42 -0
  48. data/webgui/app/models/pool.rb +141 -0
  49. data/webgui/app/models/region.rb +3 -0
  50. data/webgui/app/models/role.rb +4 -0
  51. data/webgui/app/models/seeding.rb +4 -0
  52. data/webgui/app/models/team.rb +6 -0
  53. data/webgui/app/models/user.rb +98 -0
  54. data/webgui/app/models/user_mailer.rb +25 -0
  55. data/webgui/app/views/admin/bracket.html.erb +3 -0
  56. data/webgui/app/views/admin/entries.html.erb +25 -0
  57. data/webgui/app/views/admin/index.html.erb +17 -0
  58. data/webgui/app/views/admin/pool.html.erb +53 -0
  59. data/webgui/app/views/entry/index.html.erb +16 -0
  60. data/webgui/app/views/entry/print.erb +1 -0
  61. data/webgui/app/views/entry/print.html.erb +1 -0
  62. data/webgui/app/views/entry/show.html.erb +1 -0
  63. data/webgui/app/views/layouts/bracket.html.erb +37 -0
  64. data/webgui/app/views/layouts/default.html.erb +62 -0
  65. data/webgui/app/views/layouts/print.html.erb +12 -0
  66. data/webgui/app/views/layouts/report.html.erb +38 -0
  67. data/webgui/app/views/pool/index.html.erb +36 -0
  68. data/webgui/app/views/reports/_report.html.erb +11 -0
  69. data/webgui/app/views/reports/show.html.erb +12 -0
  70. data/webgui/app/views/sessions/new.html.erb +21 -0
  71. data/webgui/app/views/shared/_admins.html.erb +8 -0
  72. data/webgui/app/views/shared/_bracket.html.erb +1296 -0
  73. data/webgui/app/views/teams/choose.html.erb +57 -0
  74. data/webgui/app/views/user_mailer/activation.erb +3 -0
  75. data/webgui/app/views/user_mailer/signup_notification.erb +8 -0
  76. data/webgui/app/views/users/_user_bar.html.erb +8 -0
  77. data/webgui/app/views/users/new.html.erb +19 -0
  78. data/webgui/config/boot.rb +109 -0
  79. data/webgui/config/database.yml +22 -0
  80. data/webgui/config/environment.rb +78 -0
  81. data/webgui/config/environments/development.rb +29 -0
  82. data/webgui/config/environments/production.rb +24 -0
  83. data/webgui/config/environments/test.rb +22 -0
  84. data/webgui/config/initializers/inflections.rb +10 -0
  85. data/webgui/config/initializers/mime_types.rb +5 -0
  86. data/webgui/config/initializers/new_rails_defaults.rb +17 -0
  87. data/webgui/config/initializers/pool.rb +33 -0
  88. data/webgui/config/initializers/site_keys.rb +38 -0
  89. data/webgui/config/locales/en.yml +5 -0
  90. data/webgui/config/routes.rb +56 -0
  91. data/webgui/db/development.sqlite3 +0 -0
  92. data/webgui/db/migrate/20090216015836_create_entries.rb +13 -0
  93. data/webgui/db/migrate/20090217001611_add_tie_break_to_entry.rb +9 -0
  94. data/webgui/db/migrate/20090217004039_create_users.rb +23 -0
  95. data/webgui/db/migrate/20090217014940_relate_entry_and_user.rb +10 -0
  96. data/webgui/db/migrate/20090218024350_create_roles.rb +17 -0
  97. data/webgui/db/migrate/20090218024657_add_postition_to_roles.rb +9 -0
  98. data/webgui/db/migrate/20090218025240_add_admin_role.rb +10 -0
  99. data/webgui/db/migrate/20090225022928_create_pools.rb +16 -0
  100. data/webgui/db/migrate/20090225030346_associate_pool_and_entry.rb +9 -0
  101. data/webgui/db/migrate/20090225072358_change_pool_data_column.rb +9 -0
  102. data/webgui/db/migrate/20090225072849_add_completed_to_entries.rb +9 -0
  103. data/webgui/db/migrate/20090225074149_add_pool_id_index_to_entries.rb +9 -0
  104. data/webgui/db/migrate/20090225084414_add_user_id_to_pool.rb +9 -0
  105. data/webgui/db/migrate/20090226021913_add_active_to_pools.rb +9 -0
  106. data/webgui/db/migrate/20090226142240_rename_bracket_column_to_data.rb +9 -0
  107. data/webgui/db/migrate/20090301014710_create_teams.rb +84 -0
  108. data/webgui/db/migrate/20090301025902_add_more_teams.rb +16 -0
  109. data/webgui/db/migrate/20090301041526_create_seedings.rb +16 -0
  110. data/webgui/db/migrate/20090301090511_create_regions.rb +14 -0
  111. data/webgui/db/migrate/teams.txt +347 -0
  112. data/webgui/db/pool.yml +408 -0
  113. data/webgui/db/schema.rb +91 -0
  114. data/webgui/db/test.sqlite3 +0 -0
  115. data/webgui/doc/README_FOR_APP +5 -0
  116. data/webgui/lib/authenticated_system.rb +189 -0
  117. data/webgui/lib/authenticated_test_helper.rb +11 -0
  118. data/webgui/lib/form_object.rb +70 -0
  119. data/webgui/lib/pdf_helper.rb +47 -0
  120. data/webgui/lib/prince.rb +74 -0
  121. data/webgui/lib/saves_picks.rb +23 -0
  122. data/webgui/lib/tasks/admin.rake +10 -0
  123. data/webgui/public/404.html +30 -0
  124. data/webgui/public/422.html +30 -0
  125. data/webgui/public/500.html +33 -0
  126. data/webgui/public/dispatch.cgi +10 -0
  127. data/webgui/public/dispatch.fcgi +24 -0
  128. data/webgui/public/dispatch.rb +10 -0
  129. data/webgui/public/favicon.ico +0 -0
  130. data/webgui/public/images/2009FinalFour.png +0 -0
  131. data/webgui/public/images/rails.png +0 -0
  132. data/webgui/public/javascripts/application.js +2 -0
  133. data/webgui/public/javascripts/bracket.js +73 -0
  134. data/webgui/public/javascripts/controls.js +963 -0
  135. data/webgui/public/javascripts/dragdrop.js +973 -0
  136. data/webgui/public/javascripts/effects.js +1128 -0
  137. data/webgui/public/javascripts/prototype.js +4320 -0
  138. data/webgui/public/robots.txt +5 -0
  139. data/webgui/public/stylesheets/bracket-print.css +39 -0
  140. data/webgui/public/stylesheets/bracket.css +125 -0
  141. data/webgui/public/stylesheets/main.css +144 -0
  142. data/webgui/public/stylesheets/prince.css +6 -0
  143. data/webgui/public/stylesheets/prince_landscape.css +1 -0
  144. data/webgui/script/about +4 -0
  145. data/webgui/script/console +3 -0
  146. data/webgui/script/dbconsole +3 -0
  147. data/webgui/script/destroy +3 -0
  148. data/webgui/script/generate +3 -0
  149. data/webgui/script/performance/benchmarker +3 -0
  150. data/webgui/script/performance/profiler +3 -0
  151. data/webgui/script/performance/request +3 -0
  152. data/webgui/script/plugin +3 -0
  153. data/webgui/script/process/inspector +3 -0
  154. data/webgui/script/process/reaper +3 -0
  155. data/webgui/script/process/spawner +3 -0
  156. data/webgui/script/runner +3 -0
  157. data/webgui/script/server +3 -0
  158. data/webgui/test/fixtures/entries.yml +10 -0
  159. data/webgui/test/fixtures/pools.yml +14 -0
  160. data/webgui/test/fixtures/regions.yml +11 -0
  161. data/webgui/test/fixtures/roles.yml +11 -0
  162. data/webgui/test/fixtures/roles_users.yml +3 -0
  163. data/webgui/test/fixtures/seedings.yml +12 -0
  164. data/webgui/test/fixtures/teams.yml +3051 -0
  165. data/webgui/test/fixtures/users.yml +44 -0
  166. data/webgui/test/functional/admin_controller_test.rb +8 -0
  167. data/webgui/test/functional/entry_controller_test.rb +27 -0
  168. data/webgui/test/functional/pool_controller_test.rb +8 -0
  169. data/webgui/test/functional/reports_controller_test.rb +8 -0
  170. data/webgui/test/functional/sessions_controller_test.rb +82 -0
  171. data/webgui/test/functional/teams_controller_test.rb +216 -0
  172. data/webgui/test/functional/users_controller_test.rb +88 -0
  173. data/webgui/test/performance/browsing_test.rb +9 -0
  174. data/webgui/test/test_helper.rb +38 -0
  175. data/webgui/test/unit/entry_test.rb +8 -0
  176. data/webgui/test/unit/pool_test.rb +8 -0
  177. data/webgui/test/unit/region_test.rb +8 -0
  178. data/webgui/test/unit/role_test.rb +8 -0
  179. data/webgui/test/unit/seeding_test.rb +8 -0
  180. data/webgui/test/unit/team_test.rb +10 -0
  181. data/webgui/test/unit/user_mailer_test.rb +31 -0
  182. data/webgui/test/unit/user_test.rb +109 -0
  183. data/webgui/vendor/plugins/auto_complete/README +23 -0
  184. data/webgui/vendor/plugins/auto_complete/Rakefile +22 -0
  185. data/webgui/vendor/plugins/auto_complete/init.rb +2 -0
  186. data/webgui/vendor/plugins/auto_complete/lib/auto_complete.rb +47 -0
  187. data/webgui/vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb +143 -0
  188. data/webgui/vendor/plugins/auto_complete/test/auto_complete_test.rb +67 -0
  189. data/webgui/vendor/plugins/enumerations_mixin/ATTENTION +15 -0
  190. data/webgui/vendor/plugins/enumerations_mixin/LICENSE +20 -0
  191. data/webgui/vendor/plugins/enumerations_mixin/README_ENUMERATIONS +163 -0
  192. data/webgui/vendor/plugins/enumerations_mixin/init.rb +21 -0
  193. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/acts/enumerated.rb +177 -0
  194. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/aggregations/has_enumerated.rb +60 -0
  195. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/virtual_enumerations.rb +68 -0
  196. data/webgui/vendor/plugins/enumerations_mixin/virtual_enumerations_sample.rb +76 -0
  197. data/webgui/vendor/plugins/restful_authentication/.gitignore +21 -0
  198. data/webgui/vendor/plugins/restful_authentication/CHANGELOG +68 -0
  199. data/webgui/vendor/plugins/restful_authentication/README.textile +224 -0
  200. data/webgui/vendor/plugins/restful_authentication/Rakefile +32 -0
  201. data/webgui/vendor/plugins/restful_authentication/TODO +15 -0
  202. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/USAGE +1 -0
  203. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/authenticated_generator.rb +478 -0
  204. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/lib/insert_routes.rb +54 -0
  205. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/_model_partial.html.erb +8 -0
  206. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/activation.erb +3 -0
  207. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_system.rb +189 -0
  208. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_test_helper.rb +22 -0
  209. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/controller.rb +43 -0
  210. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/helper.rb +2 -0
  211. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/login.html.erb +16 -0
  212. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/mailer.rb +25 -0
  213. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/migration.rb +26 -0
  214. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model.rb +83 -0
  215. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_controller.rb +85 -0
  216. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper.rb +93 -0
  217. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper_spec.rb +158 -0
  218. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/observer.rb +11 -0
  219. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup.html.erb +19 -0
  220. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup_notification.erb +8 -0
  221. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/site_keys.rb +38 -0
  222. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/access_control_spec.rb +90 -0
  223. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb +102 -0
  224. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb +139 -0
  225. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/users_controller_spec.rb +198 -0
  226. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/fixtures/users.yml +60 -0
  227. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/helpers/users_helper_spec.rb +141 -0
  228. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/models/user_spec.rb +290 -0
  229. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories.rb +22 -0
  230. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories_helper.rb +81 -0
  231. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_navigation_steps.rb +49 -0
  232. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_resource_steps.rb +179 -0
  233. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_response_steps.rb +171 -0
  234. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/user_steps.rb +153 -0
  235. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/accounts.story +186 -0
  236. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/sessions.story +134 -0
  237. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/functional_test.rb +82 -0
  238. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/mailer_test.rb +31 -0
  239. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/model_functional_test.rb +93 -0
  240. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/unit_test.rb +164 -0
  241. data/webgui/vendor/plugins/restful_authentication/init.rb +1 -0
  242. data/webgui/vendor/plugins/restful_authentication/install.rb +1 -0
  243. data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb +82 -0
  244. data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_password.rb +64 -0
  245. data/webgui/vendor/plugins/restful_authentication/lib/authentication.rb +40 -0
  246. data/webgui/vendor/plugins/restful_authentication/lib/authorization/aasm_roles.rb +63 -0
  247. data/webgui/vendor/plugins/restful_authentication/lib/authorization/stateful_roles.rb +62 -0
  248. data/webgui/vendor/plugins/restful_authentication/lib/authorization.rb +14 -0
  249. data/webgui/vendor/plugins/restful_authentication/lib/trustification/email_validation.rb +20 -0
  250. data/webgui/vendor/plugins/restful_authentication/lib/trustification.rb +14 -0
  251. data/webgui/vendor/plugins/restful_authentication/notes/AccessControl.txt +2 -0
  252. data/webgui/vendor/plugins/restful_authentication/notes/Authentication.txt +5 -0
  253. data/webgui/vendor/plugins/restful_authentication/notes/Authorization.txt +154 -0
  254. data/webgui/vendor/plugins/restful_authentication/notes/RailsPlugins.txt +78 -0
  255. data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.graffle +0 -0
  256. data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.png +0 -0
  257. data/webgui/vendor/plugins/restful_authentication/notes/SecurityPatterns.txt +163 -0
  258. data/webgui/vendor/plugins/restful_authentication/notes/Tradeoffs.txt +126 -0
  259. data/webgui/vendor/plugins/restful_authentication/notes/Trustification.txt +49 -0
  260. data/webgui/vendor/plugins/restful_authentication/rails/init.rb +3 -0
  261. data/webgui/vendor/plugins/restful_authentication/restful-authentication.gemspec +33 -0
  262. data/webgui/vendor/plugins/restful_authentication/tasks/auth.rake +33 -0
  263. metadata +288 -8
  264. data/tasks/annotations.rake +0 -22
@@ -0,0 +1,93 @@
1
+ module UsersHelper
2
+
3
+ #
4
+ # Use this to wrap view elements that the user can't access.
5
+ # !! Note: this is an *interface*, not *security* feature !!
6
+ # You need to do all access control at the controller level.
7
+ #
8
+ # Example:
9
+ # <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> |
10
+ # <%= if_authorized?(:edit, @user) do link_to('Edit this user', edit_user_path) end %> |
11
+ # <%= if_authorized?(:destroy, @user) do link_to 'Destroy', @user, :confirm => 'Are you sure?', :method => :delete end %>
12
+ #
13
+ #
14
+ def if_authorized?(action, resource, &block)
15
+ if authorized?(action, resource)
16
+ yield action, resource
17
+ end
18
+ end
19
+
20
+ #
21
+ # Link to user's page ('users/1')
22
+ #
23
+ # By default, their login is used as link text and link title (tooltip)
24
+ #
25
+ # Takes options
26
+ # * :content_text => 'Content text in place of user.login', escaped with
27
+ # the standard h() function.
28
+ # * :content_method => :user_instance_method_to_call_for_content_text
29
+ # * :title_method => :user_instance_method_to_call_for_title_attribute
30
+ # * as well as link_to()'s standard options
31
+ #
32
+ # Examples:
33
+ # link_to_user @user
34
+ # # => <a href="/users/3" title="barmy">barmy</a>
35
+ #
36
+ # # if you've added a .name attribute:
37
+ # content_tag :span, :class => :vcard do
38
+ # (link_to_user user, :class => 'fn n', :title_method => :login, :content_method => :name) +
39
+ # ': ' + (content_tag :span, user.email, :class => 'email')
40
+ # end
41
+ # # => <span class="vcard"><a href="/users/3" title="barmy" class="fn n">Cyril Fotheringay-Phipps</a>: <span class="email">barmy@blandings.com</span></span>
42
+ #
43
+ # link_to_user @user, :content_text => 'Your user page'
44
+ # # => <a href="/users/3" title="barmy" class="nickname">Your user page</a>
45
+ #
46
+ def link_to_user(user, options={})
47
+ raise "Invalid user" unless user
48
+ options.reverse_merge! :content_method => :login, :title_method => :login, :class => :nickname
49
+ content_text = options.delete(:content_text)
50
+ content_text ||= user.send(options.delete(:content_method))
51
+ options[:title] ||= user.send(options.delete(:title_method))
52
+ link_to h(content_text), user_path(user), options
53
+ end
54
+
55
+ #
56
+ # Link to login page using remote ip address as link content
57
+ #
58
+ # The :title (and thus, tooltip) is set to the IP address
59
+ #
60
+ # Examples:
61
+ # link_to_login_with_IP
62
+ # # => <a href="/login" title="169.69.69.69">169.69.69.69</a>
63
+ #
64
+ # link_to_login_with_IP :content_text => 'not signed in'
65
+ # # => <a href="/login" title="169.69.69.69">not signed in</a>
66
+ #
67
+ def link_to_login_with_IP content_text=nil, options={}
68
+ ip_addr = request.remote_ip
69
+ content_text ||= ip_addr
70
+ options.reverse_merge! :title => ip_addr
71
+ if tag = options.delete(:tag)
72
+ content_tag tag, h(content_text), options
73
+ else
74
+ link_to h(content_text), login_path, options
75
+ end
76
+ end
77
+
78
+ #
79
+ # Link to the current user's page (using link_to_user) or to the login page
80
+ # (using link_to_login_with_IP).
81
+ #
82
+ def link_to_current_user(options={})
83
+ if current_user
84
+ link_to_user current_user, options
85
+ else
86
+ content_text = options.delete(:content_text) || 'not signed in'
87
+ # kill ignored options from link_to_user
88
+ [:content_method, :title_method].each{|opt| options.delete(opt)}
89
+ link_to_login_with_IP content_text, options
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,42 @@
1
+ class Entry < ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :pool
4
+ validates_uniqueness_of :name
5
+ validates_presence_of :tie_break
6
+ validates_presence_of :user_id
7
+
8
+ # Override bracket to resolve the db blob to an object
9
+ def bracket
10
+ unless @bracket
11
+ if self[:data]
12
+ @bracket = Marshal.load(self[:data])
13
+ end
14
+ @bracket ||= Tournament::Bracket.new(self.pool.pool.tournament_entry.picks.teams)
15
+ end
16
+ @bracket
17
+ end
18
+
19
+ def reset
20
+ @bracket = Tournament::Bracket.new(self.pool.pool.tournament_entry.picks.teams)
21
+ end
22
+
23
+ def before_save
24
+ if @bracket
25
+ logger.debug("MARSHALLING BRACKET: #{@bracket.inspect}")
26
+ self[:data] = Marshal.dump(@bracket)
27
+ logger.debug("DONE MARSHALLING BRACKET")
28
+ end
29
+ end
30
+
31
+ def after_save
32
+ if self.bracket.complete? && self.user_id != self.pool.user_id
33
+ self.pool.pool.update_entry(self.tournament_entry)
34
+ self.pool.save!
35
+ end
36
+ end
37
+
38
+ def tournament_entry
39
+ @tournament_entry ||= Tournament::Entry.new(self.name, self.bracket, self.tie_break)
40
+ end
41
+
42
+ end
@@ -0,0 +1,141 @@
1
+
2
+ class Pool < ActiveRecord::Base
3
+ attr_accessor :fee, :scoring_strategy
4
+ attr_reader :payouts
5
+ validates_uniqueness_of :name
6
+ before_save :marshal_pool
7
+ belongs_to :user
8
+ has_many :entries
9
+ has_many :user_entries, :class_name => 'Entry', :conditions => ['user_id != ?', '#{user_id}']
10
+ has_many :pending_entries, :class_name => 'Entry', :conditions => ['completed = ? and user_id != ?', false, '#{user_id}']
11
+ has_one :tournament_entry, :class_name => 'Entry', :conditions => {:user_id => '#{user_id}'}
12
+ has_many :seedings
13
+ has_many :teams, :through => :seedings
14
+ has_many :regions, :order => 'position'
15
+
16
+ # Class for collecting payout info from edit pool form
17
+ class PayoutData < FormObject
18
+ attr_accessor :rank, :payout, :kind
19
+ validates_presence_of :rank
20
+ validates_presence_of :payout
21
+ validates_presence_of :kind
22
+ validates_numericality_of :payout
23
+ validates_format_of :rank, :with => /\A[L\d]\Z/
24
+ def payout_before_type_cast
25
+ @payout
26
+ end
27
+ def _delete
28
+ false
29
+ end
30
+ end
31
+
32
+ # True if the number of teams in the pool is 64
33
+ def ready?
34
+ return teams.size == 64
35
+ end
36
+
37
+ def region_seedings
38
+ reg_ret = self.regions.inject([]) do |arr, r|
39
+ arr[r.position] = [r.name, Array.new(16)]
40
+ arr
41
+ end
42
+ (0..3).each {|n| reg_ret[n] ||= ['', Array.new(16)]}
43
+
44
+ self.seedings.each_with_index do |t, idx|
45
+ region = reg_ret.find {|name, teams| name == t.region} || reg_ret.find {|name, teams| name.blank?}
46
+ region[0] = t.region
47
+ region[1][t.seed-1] = t.team
48
+ end
49
+ return reg_ret
50
+ end
51
+
52
+ def entries_for(user)
53
+ entries.find_all_by_user_id(user.id)
54
+ end
55
+
56
+ def initialize_tournament_pool
57
+ if self.ready?
58
+ @pool = Tournament::Pool.new
59
+ @pool.scoring_strategy = FormObject.class_get(@scoring_strategy || 'Tournament::ScoringStrategy::Basic').new
60
+ region_counter = 0
61
+ self.region_seedings.each do |region_name, seedings|
62
+ # Reorder ... #TODO: Configuration?
63
+ seedings = [1,16,8,9,5,12,4,13,6,11,3,14,7,10,2,15].map {|seed| [seedings[seed-1], seed] }
64
+ @pool.add_region(region_name,
65
+ seedings.map { |t, seed| Tournament::Team.new(t.name, t.short_name, seed) },
66
+ region_counter)
67
+ region_counter += 1
68
+ end
69
+ # Resolve the bracket
70
+ @pool.tournament_entry.bracket
71
+ else
72
+ @pool = Tournament::Pool.new
73
+ end
74
+ end
75
+
76
+ def pool
77
+ unless @pool
78
+ if self[:data]
79
+ @pool = Marshal.load(self[:data])
80
+ else
81
+ initialize_tournament_pool
82
+ end
83
+ end
84
+ @pool
85
+ end
86
+
87
+ def payouts=(new_payouts)
88
+ @payouts = []
89
+ new_payouts.each do |idx, hash|
90
+ idx = idx.to_i
91
+ next if hash['payout'].blank? && hash['rank'].blank?
92
+ next if hash['_delete'] == '1'
93
+ amount = hash['payout'].to_i
94
+ rank = hash['rank'] == 'L' ? hash['rank'] : hash['rank'].to_i
95
+ @payouts[idx] = PayoutData.new(:rank => rank, :payout => amount, :kind => hash['kind'])
96
+ end
97
+ @payouts.compact!
98
+ end
99
+
100
+ def marshal_pool
101
+ logger.debug("Before saving pool: AR Pool scoring strategy = #{@scoring_strategy.inspect}")
102
+ if @scoring_strategy
103
+ ss_obj =FormObject.class_get(@scoring_strategy).new
104
+ self.pool.scoring_strategy = ss_obj
105
+ end
106
+ self.pool.entry_fee = @fee
107
+ self.pool.payouts.clear
108
+ if @payouts
109
+ @payouts.each do |po|
110
+ next unless po.kind && po.rank && po.payout
111
+ amount = po.kind == '$' ? -po.payout : po.payout
112
+ rank = po.rank == 'L' ? :last : po.rank
113
+ self.pool.set_payout(rank, amount)
114
+ end
115
+ end
116
+ self[:data] = Marshal.dump(@pool)
117
+ end
118
+
119
+ def after_initialize
120
+ @payouts = []
121
+ return unless self.pool
122
+ self.fee = self.pool.entry_fee
123
+ self.scoring_strategy = self.pool.scoring_strategy.class.name
124
+ self.pool.payouts.each do |rank, payout|
125
+ next unless rank && payout
126
+ rank = rank == :last ? 'L' : rank.to_s
127
+ kind = payout < 0 ? '$' : '%'
128
+ payout = payout.abs
129
+ @payouts << PayoutData.new(:rank => rank, :payout => payout, :kind => kind)
130
+ end
131
+ @payouts << PayoutData.new
132
+ end
133
+
134
+ def accepting_entries?
135
+ return ready? && Time.now < starts_at
136
+ end
137
+
138
+ def self.active_pools
139
+ Pool.find(:all, :conditions => ['active = ?', true])
140
+ end
141
+ end
@@ -0,0 +1,3 @@
1
+ class Region < ActiveRecord::Base
2
+ belongs_to :pool
3
+ end
@@ -0,0 +1,4 @@
1
+ class Role < ActiveRecord::Base
2
+ acts_as_enumerated :order => 'position asc'
3
+ has_and_belongs_to_many :users
4
+ end
@@ -0,0 +1,4 @@
1
+ class Seeding < ActiveRecord::Base
2
+ belongs_to :team
3
+ belongs_to :pool
4
+ end
@@ -0,0 +1,6 @@
1
+ class Team < ActiveRecord::Base
2
+ validates_uniqueness_of :name
3
+ validates_uniqueness_of :short_name
4
+ has_many :seedings
5
+ has_many :pools, :through => :seedings
6
+ end
@@ -0,0 +1,98 @@
1
+ require 'digest/sha1'
2
+
3
+ class User < ActiveRecord::Base
4
+ include Authentication
5
+ include Authentication::ByPassword
6
+ include Authentication::ByCookieToken
7
+
8
+ has_many :entries
9
+ has_many :pools
10
+ has_and_belongs_to_many :roles
11
+
12
+ validates_presence_of :login
13
+ validates_length_of :login, :within => 3..40
14
+ validates_uniqueness_of :login
15
+ validates_format_of :login, :with => Authentication.login_regex, :message => Authentication.bad_login_message
16
+
17
+ validates_format_of :name, :with => Authentication.name_regex, :message => Authentication.bad_name_message, :allow_nil => true
18
+ validates_length_of :name, :maximum => 100
19
+
20
+ validates_presence_of :email
21
+ validates_length_of :email, :within => 6..100 #r@a.wk
22
+ validates_uniqueness_of :email
23
+ validates_format_of :email, :with => Authentication.email_regex, :message => Authentication.bad_email_message
24
+
25
+ before_create :make_activation_code
26
+
27
+ # HACK HACK HACK -- how to do attr_accessible from here?
28
+ # prevents a user from submitting a crafted form that bypasses activation
29
+ # anything else you want your user to change should be added here.
30
+ attr_accessible :login, :email, :name, :password, :password_confirmation
31
+
32
+ # Return all users with admin role
33
+ def self.admin_users
34
+ Role[:admin].users
35
+ end
36
+
37
+ def self.create_admin_user(options = {})
38
+ [:login, :email, :name, :password].each do |attr_name|
39
+ raise "create_admin_user needs key #{attr_name.inspect} in options hash" unless options[attr_name]
40
+ end
41
+ options[:password_confirmation] = options[:password]
42
+ u = new(options)
43
+ u.activated_at = Time.now
44
+ u.roles << Role[:admin]
45
+ u.save!
46
+ end
47
+
48
+ # Returns true if user has the given role
49
+ def has_role?(role)
50
+ return roles.include?(Role[role])
51
+ end
52
+
53
+ # Activates the user in the database.
54
+ def activate!
55
+ @activated = true
56
+ self.activated_at = Time.now.utc
57
+ self.activation_code = nil
58
+ save(false)
59
+ end
60
+
61
+ # Returns true if the user has just been activated.
62
+ def recently_activated?
63
+ @activated
64
+ end
65
+
66
+ def active?
67
+ # the existence of an activation code means they have not activated yet
68
+ activation_code.nil?
69
+ end
70
+
71
+ # Authenticates a user by their login name and unencrypted password. Returns the user or nil.
72
+ #
73
+ # uff. this is really an authorization, not authentication routine.
74
+ # We really need a Dispatch Chain here or something.
75
+ # This will also let us return a human error message.
76
+ #
77
+ def self.authenticate(login, password)
78
+ return nil if login.blank? || password.blank?
79
+ u = find :first, :conditions => ['login = ? and activated_at IS NOT NULL', login] # need to get the salt
80
+ u && u.authenticated?(password) ? u : nil
81
+ end
82
+
83
+ def login=(value)
84
+ write_attribute :login, (value ? value.downcase : nil)
85
+ end
86
+
87
+ def email=(value)
88
+ write_attribute :email, (value ? value.downcase : nil)
89
+ end
90
+
91
+ protected
92
+
93
+ def make_activation_code
94
+ self.activation_code = self.class.make_token
95
+ end
96
+
97
+
98
+ end
@@ -0,0 +1,25 @@
1
+ class UserMailer < ActionMailer::Base
2
+ def signup_notification(user, activation_url)
3
+ setup_email(user)
4
+ @subject += 'Please activate your new account'
5
+
6
+ #@body[:url] = "#{TOURNAMENT_FQ_WEBROOT}/activate/#{user.activation_code}"
7
+ @body[:url] = activation_url
8
+
9
+ end
10
+
11
+ def activation(user, home_url)
12
+ setup_email(user)
13
+ @subject += 'Your account has been activated!'
14
+ @body[:url] = home_url
15
+ end
16
+
17
+ protected
18
+ def setup_email(user)
19
+ @recipients = "#{user.email}"
20
+ @from = ADMIN_EMAIL
21
+ @subject = "[#{TOURNAMENT_TITLE}] "
22
+ @sent_on = Time.now
23
+ @body[:user] = user
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ <h1>Tournament Bracket</h1>
2
+ <%= render :partial => 'shared/bracket'%>
3
+
@@ -0,0 +1,25 @@
1
+ <h1>User Entries in <%=@pool.name%></h1>
2
+ <% if @pool.user_entries.size > 0 -%>
3
+ <table border="0" cellspacing="0" cellpadding="3">
4
+ <tr class="entryTableHead">
5
+ <th>User</th>
6
+ <th>Entry Name</th>
7
+ <th>Completed?</th>
8
+ </tr>
9
+ <% @pool.user_entries.each do |entry| -%>
10
+ <tr class="<%= cycle("entryTableEven", "entryTableOdd")%>">
11
+ <td><%=entry.user.login%></td>
12
+ <td><%=link_to entry.name, :controller => 'entry', :action => 'show', :id => entry.id%></td>
13
+ <td><%=entry.completed%></td>
14
+ </tr>
15
+ <% end -%>
16
+ </tr>
17
+ </table>
18
+ <% else -%>
19
+ <p>
20
+ <i>There are no user entries in this pool.</i>
21
+ </p>
22
+ <% end -%>
23
+ <p>
24
+ &nbsp;
25
+ </p>
@@ -0,0 +1,17 @@
1
+ <h1>Pools</h1>
2
+ <% if @pools.size %>
3
+ <table border="0">
4
+ <tr>
5
+ <td><b>Name</b></td>
6
+ <td><b>Starts</b></td>
7
+ </tr>
8
+ <% @pools.each do |p| -%>
9
+ <tr>
10
+ <td><%=link_to p.name, :action => 'pool', :id => p.id%></td>
11
+ <td><%=p.starts_at.to_formatted_s(:short)%></td>
12
+ </tr>
13
+ <% end %>
14
+ </table>
15
+ <% end %>
16
+
17
+ <%= link_to "Create a new pool", :action => 'pool' %>
@@ -0,0 +1,53 @@
1
+ <h1>Pool Administration</h1>
2
+ <% form_for 'pool', @pool, :url => {:controller => 'admin', :action => 'pool', :id => @pool.id} do |f| -%>
3
+ <table border="0" width="100%">
4
+ <tr><td>Number of submitted entries</td><td><%=@pool.user_entries.size - @pool.pending_entries.size%></td></tr>
5
+ <tr><td>Number of pending entries</td><td><%=@pool.pending_entries.size%></td></tr>
6
+ <tr>
7
+ <td><%=f.label 'name'%></td>
8
+ <td><%=f.text_field 'name', :size => 40, :maxlength => 128%></td>
9
+ </tr>
10
+ <tr>
11
+ <td><%=f.label 'starts_at'%></td>
12
+ <td><%=f.date_select 'starts_at'%></td>
13
+ </tr>
14
+ <tr>
15
+ <td><%=f.label 'active'%></td>
16
+ <td><%=f.check_box 'active'%></td>
17
+ </tr>
18
+ <tr>
19
+ <td><%=f.label 'fee'%></td>
20
+ <td>$<%=f.text_field 'fee', :size => 5, :maxlength => 3%></td>
21
+ </tr>
22
+ <tr>
23
+ <td><%=f.label 'scoring_strategy'%></td>
24
+ <td>
25
+ <% @available_scoring_strategies.each do |s| -%>
26
+ <%=f.radio_button 'scoring_strategy', s.class.name %> <em><%= s.name %></em>: <%= s.description%>
27
+ <br/>
28
+ <% end -%>
29
+ </td>
30
+ </tr>
31
+ <tr>
32
+ <td>
33
+ Payouts
34
+ </td>
35
+ <td>
36
+ <table border="0">
37
+ <tr><td><b>Rank</b></td><td><b>Amount</b></td><td><b>Kind</b></td><td><b>Delete?</b></td></tr>
38
+ <% @pool.payouts.each_with_index do |po, idx| -%>
39
+ <% f.fields_for 'payouts', po do |payout_fields| -%>
40
+ <tr>
41
+ <td><%= payout_fields.text_field 'rank', :size => 2, :maxlength => 5, :index => idx%></td>
42
+ <td><%= payout_fields.text_field 'payout', :size => 5, :maxlength => 10, :index => idx%></td>
43
+ <td><%= payout_fields.select 'kind', ['%', '$'], {}, :index => idx%></td>
44
+ <td><%= payout_fields.check_box :_delete, :index => idx %></td>
45
+ </tr>
46
+ <% end -%>
47
+ <% end -%>
48
+ </table>
49
+ </td>
50
+ </tr>
51
+ </table>
52
+ <%= submit_tag 'Save'%>
53
+ <% end -%>
@@ -0,0 +1,16 @@
1
+ <h1><%=@pool.name%> Entries For <%=current_user.login%></h1>
2
+
3
+ <% if @entries.empty? %>
4
+ <p>
5
+ You have no entries.
6
+ </p>
7
+ <% else %>
8
+ <ul>
9
+ <% @entries.each do |entry| %>
10
+ <li><%= link_to entry.name, :action => 'show', :id => entry.id %> <% if entry.completed %><span class="entryCompleted">COMPLETED</span><%else%><span class="entryPending">PENDING</span><%end%></li>
11
+ <% end %>
12
+ </ul>
13
+ <% end %>
14
+ <p>
15
+ <%= link_to 'Create a new entry', :action => 'new', :id => @pool.id %>
16
+ </p>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'shared/bracket', :locals => {:editable => false} %>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'shared/bracket', :locals => {:editable => false} %>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'shared/bracket' %>
@@ -0,0 +1,37 @@
1
+ <html>
2
+ <head>
3
+ <title><%=TOURNAMENT_TITLE%></title>
4
+ <%= javascript_include_tag 'prototype' %>
5
+ <%= javascript_include_tag 'bracket' %>
6
+ <%= stylesheet_link_tag 'main' %>
7
+ <%= stylesheet_link_tag 'bracket' %>
8
+ </head>
9
+ <body>
10
+ <div id="wrap">
11
+ <div id="nav">
12
+ <ul>
13
+ <li><%= link_to "Home", :controller => 'pool', :action => 'index'%></li>
14
+ <li><%= link_to "Entries", :controller => 'entry', :action => 'index', :id => @entry.pool.id%></li>
15
+ <li><%= link_to "Print", :controller => 'entry', :action => (PdfHelper.prince_available? ? 'pdf' : 'print'), :id => @entry.id%></li>
16
+ </ul>
17
+ </div>
18
+ <div id="messages">
19
+ <% if flash[:info] %>
20
+ <div id="info"><%= flash[:info] %></div>
21
+ <% end %>
22
+ <% if flash[:notice] %>
23
+ <div id="notice"><%= flash[:notice] %></div>
24
+ <% end %>
25
+ <% if flash[:error] %>
26
+ <div id="error"><%= flash[:error] %></div>
27
+ <% end %>
28
+ </div>
29
+ <div id="main2">
30
+ <%= yield %>
31
+ </div>
32
+ <div id="footer">
33
+ <%= render :partial => 'shared/admins' %>
34
+ </div>
35
+ </div>
36
+ </body>
37
+ </html>
@@ -0,0 +1,62 @@
1
+ <html>
2
+ <head>
3
+ <title><%=TOURNAMENT_TITLE%></title>
4
+ <%= stylesheet_link_tag 'main' %>
5
+ </head>
6
+ <body>
7
+ <div id="wrap">
8
+ <div id="nav">
9
+ <ul>
10
+ <li><%= link_to "Home", :controller => 'pool', :action => 'index'%></li>
11
+ <% if session[:user_id] -%>
12
+ <li><%= link_to "Logout", :controller => 'sessions', :action => 'destroy'%></li>
13
+ <% else -%>
14
+ <li><%= link_to "Login", :controller => 'sessions', :action => 'new'%></li>
15
+ <li><%= link_to "Signup", :controller => 'users', :action => 'new'%></li>
16
+ <% end -%>
17
+ </ul>
18
+ </div>
19
+ <div id="messages">
20
+ <% if flash[:info] %>
21
+ <div id="info"><%= flash[:info] %></div>
22
+ <% end %>
23
+ <% if flash[:notice] %>
24
+ <div id="notice"><%= flash[:notice] %></div>
25
+ <% end %>
26
+ <% if flash[:error] %>
27
+ <div id="error"><%= flash[:error] %></div>
28
+ <% end %>
29
+ </div>
30
+ <div id="main">
31
+ <%= yield %>
32
+ </div>
33
+ <div id="sidebar">
34
+ <% if session[:user_id] -%>
35
+ <ul>
36
+ <li>Logged in: <%= current_user.login %></li>
37
+ </ul>
38
+ <% if current_user.roles.include?(Role[:admin]) %>
39
+ <p>
40
+ <small>ADMIN</small>
41
+ </p>
42
+ <ul>
43
+ <li> <%= link_to 'All Pools', :controller => 'admin', :action => 'index' %></li>
44
+ <% if @pool -%>
45
+ <li> <%= link_to 'Pool', :controller => 'admin', :action => 'pool', :id => @pool.id %></li>
46
+ <li> <%= link_to 'Teams', :controller => 'teams', :action => 'choose', :id => @pool.id %></li>
47
+ <% if @pool.ready? %>
48
+ <li> <%= link_to 'Tournament Bracket', :controller => 'admin', :action => 'bracket', :id => @pool.id %></li>
49
+ <li> <%= link_to 'All Entries', :controller => 'admin', :action => 'entries', :id => @pool.id%></li>
50
+ <li> <%= link_to 'Reports', :controller => 'reports', :action => 'show', :id => @pool.id%></li>
51
+ <% end -%>
52
+ <% end -%>
53
+ </ul>
54
+ <% end -%>
55
+ <% end -%>
56
+ </div>
57
+ <div id="footer">
58
+ <%= render :partial => 'shared/admins' %>
59
+ </div>
60
+ </div>
61
+ </body>
62
+ </html>
@@ -0,0 +1,12 @@
1
+ <html>
2
+ <head>
3
+ <title><%=TOURNAMENT_TITLE%></title>
4
+ <%= javascript_include_tag 'prototype' %>
5
+ <%= javascript_include_tag 'bracket' %>
6
+ <%= stylesheet_link_tag 'main' %>
7
+ <%= stylesheet_link_tag 'bracket' %>
8
+ </head>
9
+ <body>
10
+ <%= yield %>
11
+ </body>
12
+ </html>