discussion 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +16 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/discussion/application.js +1 -0
  5. data/app/assets/javascripts/discussion/discussion.js +28 -0
  6. data/app/assets/stylesheets/discussion/application.css +13 -0
  7. data/app/assets/stylesheets/discussion/threads.css +4 -0
  8. data/app/assets/stylesheets/scaffold.css +56 -0
  9. data/app/controllers/discussion/application_controller.rb +4 -0
  10. data/app/controllers/discussion/comments_controller.rb +100 -0
  11. data/app/controllers/discussion/threads_controller.rb +128 -0
  12. data/app/helpers/discussion/application_helper.rb +9 -0
  13. data/app/helpers/discussion/comments_helper.rb +20 -0
  14. data/app/helpers/discussion/threads_helper.rb +52 -0
  15. data/app/models/discussion/comment.rb +54 -0
  16. data/app/models/discussion/comment_read.rb +27 -0
  17. data/app/models/discussion/concerns.rb +24 -0
  18. data/app/models/discussion/thread.rb +69 -0
  19. data/app/models/discussion/thread_read.rb +9 -0
  20. data/app/models/thread_sweeper.rb +23 -0
  21. data/app/views/discussion/comments/_form.html.erb +1 -0
  22. data/app/views/discussion/comments/_list_with_form.html.erb +10 -0
  23. data/app/views/discussion/comments/_view.html.erb +3 -0
  24. data/app/views/discussion/comments/create.js.erb +2 -0
  25. data/app/views/discussion/comments/index.js.erb +2 -0
  26. data/app/views/discussion/threads/_form.html.erb +16 -0
  27. data/app/views/discussion/threads/_index.html.erb +5 -0
  28. data/app/views/discussion/threads/_list.html.erb +40 -0
  29. data/app/views/discussion/threads/_view.html.erb +13 -0
  30. data/app/views/discussion/threads/create.js.erb +2 -0
  31. data/app/views/discussion/threads/index.html.erb +3 -0
  32. data/app/views/discussion/threads/index.js.erb +2 -0
  33. data/app/views/discussion/threads/list.html.erb +1 -0
  34. data/app/views/discussion/threads/new.html.erb +1 -0
  35. data/app/views/discussion/threads/new.js.erb +2 -0
  36. data/app/views/discussion/threads/show.html.erb +1 -0
  37. data/app/views/discussion/threads/show.js.erb +2 -0
  38. data/config/routes.rb +5 -0
  39. data/db/migrate/20130501074817_create_discussion_threads.rb +14 -0
  40. data/db/migrate/20130501075956_create_discussion_concerns.rb +13 -0
  41. data/db/migrate/20130501080150_create_discussion_comments.rb +15 -0
  42. data/db/migrate/20130501080604_create_discussion_comment_reads.rb +11 -0
  43. data/db/migrate/20130502121352_create_discussion_thread_reads.rb +13 -0
  44. data/db/migrate/20130509100700_add_topic_to_threads.rb +9 -0
  45. data/lib/discussion.rb +15 -0
  46. data/lib/discussion/engine.rb +10 -0
  47. data/lib/discussion/version.rb +3 -0
  48. data/lib/generators/discussion/USAGE +15 -0
  49. data/lib/generators/discussion/discussion_generator.rb +26 -0
  50. data/lib/tasks/discussion_tasks.rake +4 -0
  51. data/test/discussion_test.rb +7 -0
  52. data/test/dummy/README.rdoc +261 -0
  53. data/test/dummy/Rakefile +7 -0
  54. data/test/dummy/app/assets/javascripts/application.js +4 -0
  55. data/test/dummy/app/assets/javascripts/assignments.js +2 -0
  56. data/test/dummy/app/assets/stylesheets/application.css +28 -0
  57. data/test/dummy/app/assets/stylesheets/assignments.css +4 -0
  58. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  59. data/test/dummy/app/controllers/application_controller.rb +8 -0
  60. data/test/dummy/app/controllers/assignments_controller.rb +2 -0
  61. data/test/dummy/app/helpers/application_helper.rb +8 -0
  62. data/test/dummy/app/helpers/assignments_helper.rb +2 -0
  63. data/test/dummy/app/models/assignment.rb +5 -0
  64. data/test/dummy/app/models/user.rb +9 -0
  65. data/test/dummy/app/views/assignments/_form.html.erb +29 -0
  66. data/test/dummy/app/views/assignments/edit.html.erb +6 -0
  67. data/test/dummy/app/views/assignments/index.html.erb +27 -0
  68. data/test/dummy/app/views/assignments/new.html.erb +5 -0
  69. data/test/dummy/app/views/assignments/show.html.erb +32 -0
  70. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  71. data/test/dummy/app/views/layouts/discussion/application.html.erb +14 -0
  72. data/test/dummy/config.ru +4 -0
  73. data/test/dummy/config/application.rb +58 -0
  74. data/test/dummy/config/boot.rb +10 -0
  75. data/test/dummy/config/database.yml +25 -0
  76. data/test/dummy/config/environment.rb +5 -0
  77. data/test/dummy/config/environments/development.rb +52 -0
  78. data/test/dummy/config/environments/production.rb +67 -0
  79. data/test/dummy/config/environments/test.rb +37 -0
  80. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  81. data/test/dummy/config/initializers/inflections.rb +15 -0
  82. data/test/dummy/config/initializers/mime_types.rb +5 -0
  83. data/test/dummy/config/initializers/secret_token.rb +7 -0
  84. data/test/dummy/config/initializers/session_store.rb +8 -0
  85. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  86. data/test/dummy/config/locales/en.yml +5 -0
  87. data/test/dummy/config/routes.rb +9 -0
  88. data/test/dummy/custom_plan.rb +11 -0
  89. data/test/dummy/db/development.sqlite3 +0 -0
  90. data/test/dummy/db/migrate/20120624033524_devise_create_users.rb +53 -0
  91. data/test/dummy/db/migrate/20130501154800_create_discussion_threads.discussion.rb +15 -0
  92. data/test/dummy/db/migrate/20130501154801_create_discussion_concerns.discussion.rb +14 -0
  93. data/test/dummy/db/migrate/20130501154802_create_discussion_comments.discussion.rb +16 -0
  94. data/test/dummy/db/migrate/20130501154803_create_discussion_comment_reads.discussion.rb +12 -0
  95. data/test/dummy/db/migrate/20130502144148_create_discussion_thread_reads.discussion.rb +14 -0
  96. data/test/dummy/db/migrate/20130509101316_create_assignments.rb +12 -0
  97. data/test/dummy/db/migrate/20130509101334_add_topic_to_threads.discussion.rb +10 -0
  98. data/test/dummy/db/schema.rb +104 -0
  99. data/test/dummy/db/seed.rb +28 -0
  100. data/test/dummy/db/test.sqlite3 +0 -0
  101. data/test/dummy/log/development.log +9981 -0
  102. data/test/dummy/public/404.html +26 -0
  103. data/test/dummy/public/422.html +26 -0
  104. data/test/dummy/public/500.html +25 -0
  105. data/test/dummy/public/favicon.ico +0 -0
  106. data/test/dummy/script/rails +6 -0
  107. data/test/dummy/spec/controllers/assignments_controller_spec.rb +160 -0
  108. data/test/dummy/spec/helpers/assignments_helper_spec.rb +15 -0
  109. data/test/dummy/spec/models/assignment_spec.rb +5 -0
  110. data/test/dummy/spec/requests/assignments_spec.rb +11 -0
  111. data/test/dummy/spec/routing/assignments_routing_spec.rb +35 -0
  112. data/test/dummy/spec/views/assignments/edit.html.erb_spec.rb +22 -0
  113. data/test/dummy/spec/views/assignments/index.html.erb_spec.rb +26 -0
  114. data/test/dummy/spec/views/assignments/new.html.erb_spec.rb +22 -0
  115. data/test/dummy/spec/views/assignments/show.html.erb_spec.rb +19 -0
  116. data/test/dummy/tmp/cache/34A/041/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjquery.js%3Fbody%3D1 +0 -0
  117. data/test/dummy/tmp/cache/458/621/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fscaffold.css%3Fbody%3D1 +0 -0
  118. data/test/dummy/tmp/cache/4FB/6C1/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fjquery_ujs.js%3Fbody%3D1 +0 -0
  119. data/test/dummy/tmp/cache/53E/311/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fapplication.js%3Fbody%3D1 +0 -0
  120. data/test/dummy/tmp/cache/556/F41/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fassignments.js%3Fbody%3D1 +0 -0
  121. data/test/dummy/tmp/cache/5AA/581/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fapplication.css%3Fbody%3D1 +0 -0
  122. data/test/dummy/tmp/cache/5C2/331/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fassignments.css%3Fbody%3D1 +0 -0
  123. data/test/dummy/tmp/cache/9A9/BB0/total_unread_thread_by_6 +1 -0
  124. data/test/dummy/tmp/cache/9CF/491/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fdiscussion%2Fdiscussion.js%3Fbody%3D1 +0 -0
  125. data/test/dummy/tmp/cache/A1F/311/http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fdiscussion%2Fapplication.js%3Fbody%3D1 +0 -0
  126. data/test/dummy/tmp/cache/A44/EA0/2898ba2093d346f7463a4396e46d4bd73590fd60 +25 -0
  127. data/test/dummy/tmp/cache/A53/930/8ab0f4219a7b2c19044a090115a45e76e43b268e +6 -0
  128. data/test/dummy/tmp/cache/A91/340/3f3d2d8955322f325af6db2238355fa07007ebd9 +5 -0
  129. data/test/dummy/tmp/cache/A9B/580/326f111948a98b94ce79f7ead20a6a8f6134316a +17 -0
  130. data/test/dummy/tmp/cache/ACB/1C0/61e9711fd55eccdf62882cb8d127b22664f7023f +4 -0
  131. data/test/dummy/tmp/cache/ACB/C60/2d70f6e0b599912c0a0a476f7d1d873d16fc587a +15 -0
  132. data/test/dummy/tmp/cache/AEF/AF0/24b5ae4d0aa3c3e6f7898cc323c8434330bf6c48 +20 -0
  133. data/test/dummy/tmp/cache/AF9/0E0/96b52cbbdd9b2500e89198a5d9ac461e490d2d27 +30 -0
  134. data/test/dummy/tmp/cache/B06/3F0/da9f60ff5af114f8058d98986d9c2350fd2df114 +9599 -0
  135. data/test/dummy/tmp/cache/B1C/810/9e06e1eec0d1350714a34d137eb4e4e93df71d7b +19 -0
  136. data/test/dummy/tmp/cache/B21/980/93de869eb331c65cb1c7a282ae089ee1b9111fd1 +25 -0
  137. data/test/dummy/tmp/cache/B27/910/da39a3ee5e6b4b0d3255bfef95601890afd80709 +0 -0
  138. data/test/dummy/tmp/cache/B30/970/7c338ed2840d2bf55f9f5e4eed04f66c80840eb3 +4 -0
  139. data/test/dummy/tmp/cache/B52/020/723598e1e44b35d4f2dca9ba0d3d1fa86fb63c81 +17 -0
  140. data/test/dummy/tmp/cache/B69/300/03c05703ee2f7ecbe9331dabc80cb14364ae1cd4 +14 -0
  141. data/test/dummy/tmp/cache/B72/C30/6c7fd8edb7af04528edf3f4c189f498ef511349e +20 -0
  142. data/test/dummy/tmp/cache/B8A/9B0/8446a97c4cbd4f1c6650b6dda8f7381cacfe5f31 +57 -0
  143. data/test/dummy/tmp/cache/BDA/810/586d7c0cfc531f2d9bffa4afa518cdde00e640a5 +25 -0
  144. data/test/dummy/tmp/cache/BE1/FA0/cef8de7e145c5aba7808de00a8b78750bfeba3b4 +30 -0
  145. data/test/dummy/tmp/cache/C0F/F10/853eabd960e1d1c97f280dfde98cda31aceda31c +401 -0
  146. data/test/dummy/tmp/cache/C41/FC0/b5dff9ef4aa8e34a09fbc8bc024f3ddd59d711ba +17 -0
  147. data/test/dummy/tmp/cache/assets/C80/A60/sprockets%2F3d71727f9a9628e5ea4071de13513523 +0 -0
  148. data/test/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
  149. data/test/dummy/tmp/cache/assets/CBB/080/sprockets%2F2d799cd88730be6f8d442356020b671f +0 -0
  150. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  151. data/test/dummy/tmp/cache/assets/CE3/D10/sprockets%2F966d9544f2171c807e5dd194302de1cc +0 -0
  152. data/test/dummy/tmp/cache/assets/CEE/900/sprockets%2Fa62a39d06b7d4de441784b9974f92e52 +0 -0
  153. data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
  154. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  155. data/test/dummy/tmp/cache/assets/D34/9E0/sprockets%2F11dabe8b1273c07cacd98060623de865 +0 -0
  156. data/test/dummy/tmp/cache/assets/D40/4E0/sprockets%2F441fdbbb1185dcb64934067f3a64f85e +0 -0
  157. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  158. data/test/dummy/tmp/cache/assets/D59/650/sprockets%2F0e15e6c08b5d2c6fc092a5a804f1a4a2 +0 -0
  159. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  160. data/test/dummy/tmp/cache/assets/D69/160/sprockets%2Fd50935d69817529b1cb6e6cadc111aec +0 -0
  161. data/test/dummy/tmp/cache/assets/D6C/290/sprockets%2Fedf363ea932d74107ecad71304e3c69d +0 -0
  162. data/test/dummy/tmp/cache/assets/D6D/870/sprockets%2F0b22785b6eb9daa3c9480e70771b6bed +0 -0
  163. data/test/dummy/tmp/cache/assets/D81/A20/sprockets%2F7fe1c5ae586747d5bba86892a2df7f42 +0 -0
  164. data/test/dummy/tmp/cache/assets/D92/C00/sprockets%2Fdd4af168d08e874f3d9c8e2d1f7d9898 +0 -0
  165. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  166. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  167. data/test/dummy/zeus.json +23 -0
  168. data/test/functional/discussion/threads_controller_test.rb +51 -0
  169. data/test/integration/navigation_test.rb +10 -0
  170. data/test/test_helper.rb +15 -0
  171. data/test/unit/discussion/comment_read_test.rb +9 -0
  172. data/test/unit/discussion/comment_test.rb +9 -0
  173. data/test/unit/discussion/concerns_test.rb +9 -0
  174. data/test/unit/discussion/thread_read_test.rb +9 -0
  175. data/test/unit/discussion/thread_test.rb +9 -0
  176. data/test/unit/helpers/discussion/threads_helper_test.rb +6 -0
  177. metadata +491 -0
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
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.
@@ -0,0 +1,16 @@
1
+ Discussion By [Ashrafuzzaman](http://www.ashrafuzzaman.com).
2
+
3
+ Discussion is a thread discussion and comment solution. It:
4
+
5
+ * Is a rails mountable engine, so mount it to your app and run it
6
+ * Create discussion or comment on any model
7
+ * Add your own layout
8
+ * Bult in ajaxified options
9
+ * Built in filter with ransack and pagination with kaminary
10
+
11
+ ## Installation
12
+
13
+
14
+ ## License
15
+ MIT License. Copyright 2009-2013 [Ashrafuzzaman](http://www.ashrafuzzaman.com).
16
+ You are not granted rights or licenses to the trademarks of the Discussion, including without limitation the Discussion name.
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Discussion'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,28 @@
1
+ var Disussion = {
2
+ loadComments: function (url, contrinerId) {
3
+ $ = jQuery;
4
+ $('#' + contrinerId).trigger('loading_comments');
5
+ $.ajax({
6
+ url: url,
7
+ dataType: 'script',
8
+ data: {contrinerId: contrinerId},
9
+ type: 'GET'
10
+ }).done(function () {
11
+ $('#' + contrinerId).trigger('loaded_comments');
12
+ console.log($('#' + contrinerId));
13
+ });
14
+ },
15
+ loadThreads: function (url, contrinerId) {
16
+ $ = jQuery;
17
+ $('#' + contrinerId).trigger('loading_threads');
18
+ $.ajax({
19
+ url: url,
20
+ dataType: 'script',
21
+ data: {contrinerId: contrinerId},
22
+ type: 'GET'
23
+ }).done(function () {
24
+ $('#' + contrinerId).trigger('loaded_threads');
25
+ console.log($('#' + contrinerId));
26
+ });
27
+ }
28
+ }
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,4 @@
1
+ module Discussion
2
+ class ApplicationController < ::ApplicationController
3
+ end
4
+ end
@@ -0,0 +1,100 @@
1
+ require_dependency "discussion/application_controller"
2
+
3
+ module Discussion
4
+ class CommentsController < InheritedResources::Base
5
+ layout Discussion.layout
6
+ respond_to :html, :xml, :json, :js
7
+
8
+ before_filter :load_comment, only: [:edit, :update, :destroy]
9
+
10
+ def index
11
+ @comments = collection
12
+ respond_with(@comments)
13
+ @comments.each { |c| c.read_by!(current_user) }
14
+ end
15
+
16
+ def new
17
+ build_resource
18
+ respond_with(@comment)
19
+ end
20
+
21
+ def edit
22
+ end
23
+
24
+ def create
25
+ build_resource
26
+ respond_to do |format|
27
+ if @comment.save
28
+ format.html { redirect_to :back }
29
+ format.js { collection }
30
+ format.json { render json: @comment, status: :created, location: @comment }
31
+ else
32
+ format.html { render action: "new" }
33
+ format.json { render json: @comment.errors, status: :unprocessable_entity }
34
+ end
35
+ end
36
+ end
37
+
38
+ def update
39
+ respond_to do |format|
40
+ if @comment.update_attributes(params[:comment])
41
+ format.html { redirect_to @comment, notice: 'comment was successfully updated.' }
42
+ format.json { head :no_content }
43
+ else
44
+ format.html { render action: "edit" }
45
+ format.json { render json: @comment.errors, status: :unprocessable_entity }
46
+ end
47
+ end
48
+ end
49
+
50
+ def destroy
51
+ @comment.destroy
52
+ respond_to do |format|
53
+ format.html { redirect_to :back }
54
+ format.js { collection }
55
+ format.json { head :no_content }
56
+ end
57
+ end
58
+
59
+ protected
60
+
61
+ def commentable
62
+ return @commentable if @commentable
63
+ params.each do |name, value|
64
+ if name =~ /(.+)_id$/
65
+ klass = $1 == 'thread' ? Discussion::Thread : $1.classify.constantize
66
+ @commentable = klass.find(value)
67
+ return @commentable
68
+ end
69
+ end
70
+ nil
71
+ end
72
+
73
+ def commentable?
74
+ commentable.present?
75
+ end
76
+
77
+ def comment_builder
78
+ commentable? ? commentable.comments : comment
79
+ end
80
+
81
+ def load_comment
82
+ @comment = comment_builder.find(params[:id])
83
+ end
84
+
85
+ def redirect_to_list
86
+ redirect_to commentable? ? main_app.polymorphic_url([@commentable, :comments]) : comments_path
87
+ end
88
+
89
+ def build_resource
90
+ @comment = comment_builder.new(params[:comment])
91
+ @commentable = @comment.commentable
92
+ @comment.author = current_user
93
+ @comment
94
+ end
95
+
96
+ def collection
97
+ @comments = comment_builder.order_by_recent.includes(:author)
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,128 @@
1
+ require_dependency "discussion/application_controller"
2
+
3
+ module Discussion
4
+ class ThreadsController < ApplicationController
5
+ layout Discussion.layout
6
+ respond_to :html, :xml, :json, :js
7
+ cache_sweeper :thread_sweeper
8
+
9
+ before_filter :load_thread, only: [:show, :edit, :update, :destroy]
10
+
11
+ def index
12
+ @threads = collection
13
+ respond_with(@threads)
14
+ end
15
+
16
+ def list
17
+ @threads = collection
18
+ respond_with(@threads)
19
+ end
20
+
21
+ def show
22
+ mark_thread_as_read
23
+ mark_all_thread_comments_as_read
24
+
25
+ respond_with(@thread)
26
+ end
27
+
28
+ def new
29
+ build_resource
30
+ respond_with(@thread)
31
+ end
32
+
33
+ def edit
34
+ end
35
+
36
+ def create
37
+ build_resource
38
+ respond_to do |format|
39
+ if @thread.save
40
+ mark_thread_as_read
41
+ format.html { redirect_to_list }
42
+ format.js { collection }
43
+ format.json { render json: @thread, status: :created, location: @thread }
44
+ else
45
+ format.html { render action: "new" }
46
+ format.json { render json: @thread.errors, status: :unprocessable_entity }
47
+ end
48
+ end
49
+ end
50
+
51
+ def update
52
+ respond_to do |format|
53
+ if @thread.update_attributes(params[:thread])
54
+ format.html { redirect_to @thread, notice: 'Thread was successfully updated.' }
55
+ format.json { head :no_content }
56
+ else
57
+ format.html { render action: "edit" }
58
+ format.json { render json: @thread.errors, status: :unprocessable_entity }
59
+ end
60
+ end
61
+ end
62
+
63
+ def destroy
64
+ @thread.destroy
65
+ respond_to do |format|
66
+ format.html { redirect_to_list }
67
+ format.js { collection }
68
+ format.json { head :no_content }
69
+ end
70
+ end
71
+
72
+ protected
73
+
74
+ def threadable
75
+ return @threadable if @threadable
76
+ params.each do |name, value|
77
+ if name =~ /(.+)_id$/
78
+ @threadable = $1.classify.constantize.find(value)
79
+ return @threadable
80
+ end
81
+ end
82
+ nil
83
+ end
84
+
85
+ def threadable?
86
+ threadable.present?
87
+ end
88
+
89
+ def thread_builder
90
+ threadable? ? threadable.threads : Thread
91
+ end
92
+
93
+ def load_thread
94
+ @thread = thread_builder.find(params[:id])
95
+ end
96
+
97
+ def redirect_to_list
98
+ redirect_to threadable? ? main_app.polymorphic_url([@threadable, :threads]) : threads_path
99
+ end
100
+
101
+ def build_resource
102
+ @thread = thread_builder.new(params[:thread])
103
+ @thread.initiator = current_user
104
+ @thread.comments.each { |m| m.author ||= current_user }
105
+ @thread
106
+ end
107
+
108
+ def collection
109
+ @threads = thread_builder.order_by_recent.includes(:initiator)
110
+ if params[:sent_item] == 'true'
111
+ @threads = @threads.by_initiator(current_user)
112
+ else
113
+ @threads = @threads.concerns_with(current_user)
114
+ end
115
+ @threads = @threads.page(params[:page])
116
+ @search = @threads.search(params[:q])
117
+ @threads = @search.result
118
+ end
119
+
120
+ def mark_thread_as_read
121
+ @thread.thread_reads.by(current_user).each { |tr| tr.update_attributes(read: true) }
122
+ end
123
+
124
+ def mark_all_thread_comments_as_read
125
+ @thread.comments.each { |m| m.read_by!(current_user) if m.persisted? }
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,9 @@
1
+ module Discussion
2
+ module ApplicationHelper
3
+ def method_missing(method, *args, &block)
4
+ main_app.send(method, *args, &block)
5
+ rescue NoMethodError
6
+ super
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module Discussion
2
+ module CommentsHelper
3
+ def load_comments_for(commentable, options={})
4
+ remote = options[:remote] || false
5
+ comments_container_id = "comments-#{Time.now.to_i}"
6
+ if remote
7
+ <<-EOF.html_safe
8
+ <div id='#{comments_container_id}' class="comments_container">Loading comments ...</div>
9
+ <script type='text/javascript'>
10
+ Disussion.loadComments('#{polymorphic_url([commentable, :comments])}', '#{comments_container_id}');
11
+ </script>
12
+ EOF
13
+ else
14
+ content_tag :div, id: comments_container_id do
15
+ render :partial => "discussion/comments/list_with_form", locals: {commentable: commentable, contriner_id: comments_container_id}
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end