public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
fix the comment count on the unapproved comment counter on overview

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1203 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Fri Jun 09 20:12:29 -0700 2006
commit  d4b921e2cbd316e0159ebac70991d2970238df0c
tree    3484f19c52d8c8b1e6902972e447406d3ffe0789
parent  8f3fed0d09699729ad6b313f9a03a9380deb929f
...
76
77
78
79
80
81
 
82
83
84
85
86
87
 
88
89
90
...
76
77
78
 
 
 
79
80
81
82
 
 
 
83
84
85
86
0
@@ -76,15 +76,11 @@ class Admin::ArticlesController < Admin::BaseController
0
   # xhr baby
0
   # needs some restful lovin'
0
   def approve
0
- @comment = @article.unapproved_comments.find(params[:comment])
0
- @comment.approved = true
0
- @comment.save
0
+ @comment = @article.unapproved_comments.approve(params[:comment])
0
   end
0
 
0
   def unapprove
0
- @comment = @article.comments.find(params[:comment])
0
- @comment.approved = false
0
- @comment.save
0
+ @comment = @article.comments.unapprove(params[:comment])
0
     render :action => 'approve'
0
   end
0
   
...
9
10
11
12
13
 
 
14
15
16
...
9
10
11
 
 
12
13
14
15
16
0
@@ -9,8 +9,8 @@ class Admin::OverviewController < Admin::BaseController
0
     @users = User.find(:all)
0
     @events, @todays_events, @yesterdays_events = [], [], []
0
     today, yesterday = Time.now.to_date, 1.day.ago.to_date
0
- @articles = @site.articles.find(:all, :include => :all_comments, :conditions => ['all_comments_contents.id is not null and all_comments_contents.approved = ?', false])
0
- @articles.sort! { |x,y| y.comments.size <=> y.comments.size }
0
+ @articles = @site.articles.find(:all, :include => :unapproved_comments, :conditions => ['unapproved_comments_contents.id is not null and unapproved_comments_contents.approved = ?', false])
0
+ @articles.sort! { |x,y| y.unapproved_comments.size <=> y.unapproved_comments.size }
0
     @site.events.find(:all, :order => 'events.created_at DESC', :include => [:article, :user], :limit => 50).each do |event|
0
       case event.created_at.to_date
0
         when today then @todays_events
...
5
6
7
8
 
9
10
11
12
13
14
15
 
16
17
18
...
5
6
7
 
8
9
10
11
12
13
14
 
15
16
17
18
0
@@ -5,14 +5,14 @@ class ApplicationController < ActionController::Base
0
   before_filter :load_site
0
   #before_filter :set_cache_root
0
   helper_method :site
0
- attr_reader :site
0
+ attr_reader :site
0
 
0
   def render_liquid_template_for(template_type, assigns = {})
0
     headers["Content-Type"] ||= 'text/html; charset=utf-8'
0
 
0
     unless assigns['article']
0
       self.cached_references += assigns['articles']
0
- assigns['articles'] = assigns['articles'].collect { |a| a.to_liquid }
0
+ assigns['articles'] = assigns['articles'].collect &:to_liquid
0
     end
0
     
0
     assigns.update 'site' => site.to_liquid
...
1
 
 
2
3
4
...
15
16
17
 
 
 
 
18
19
20
...
1
2
3
4
5
6
...
17
18
19
20
21
22
23
24
25
26
0
@@ -1,4 +1,6 @@
0
 module Admin::ArticlesHelper
0
+ FILTER_TYPES = %w(approved unapproved) unless const_defined?(:FILTER_TYPES)
0
+
0
   def status_icon
0
     @status_icon ||= { :unpublished => %w(orange bstop.gif),
0
                        :pending => %w(yellow document.gif),
0
@@ -15,6 +17,10 @@ module Admin::ArticlesHelper
0
     article.published? ? article.published_at.to_s(:long) : "not published"
0
   end
0
 
0
+ def valid_filter?(filter = params[:filter])
0
+ FILTER_TYPES.include? filter
0
+ end
0
+
0
   # Buttons like draft_button_tag, save_button_tag
0
   # set the name attr of the submit so we can tell which one they clicked on.
0
   [:draft, :save, :create].each do |button|
...
17
18
19
20
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
23
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
26
27
...
17
18
19
 
 
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
0
@@ -17,11 +17,39 @@ class Article < Content
0
   has_many :sections, :through => :assigned_sections, :order => 'sections.name'
0
   has_many :events, :order => 'created_at desc'
0
   with_options :order => 'created_at',:class_name => 'Comment' do |comment|
0
- comment.has_many :comments, :conditions => ['contents.approved = ?', true]
0
- comment.has_many :unapproved_comments, :conditions => ['contents.approved = ?', false]
0
+ comment.has_many :comments, :conditions => ['contents.approved = ?', true] do
0
+ def unapprove(id)
0
+ returning find(id) do |comment|
0
+ comment.approved = false
0
+ comment.save
0
+ end
0
+ end
0
+ end
0
+ comment.has_many :unapproved_comments, :conditions => ['contents.approved = ?', false] do
0
+ def approve(id)
0
+ returning find(id) do |comment|
0
+ comment.approved = true
0
+ comment.save
0
+ end
0
+ end
0
+ end
0
     comment.has_many :all_comments
0
   end
0
-
0
+
0
+ class << self
0
+ def approve
0
+ comment = @article.unapproved_comments.find(params[:comment])
0
+ comment.approved = true
0
+ comment.save
0
+ end
0
+
0
+ def unapprove
0
+ comment = @article.comments.find(params[:comment])
0
+ comment.approved = false
0
+ comment.save
0
+ end
0
+ end
0
+
0
   class << self
0
     def find_by_permalink(year, month, day, permalink, options = {})
0
       from, to = Time.delta(year, month, day)
...
1
2
3
 
4
5
6
...
11
12
13
14
 
15
16
17
...
1
2
3
4
5
6
7
...
12
13
14
 
15
16
17
18
0
@@ -1,6 +1,7 @@
0
 <!-- begin action nav -->
0
 <div class="round" id="page-nav">
0
   <ul id="act-nav">
0
+ <li><%= link_to 'Edit', :id => @article, :action => 'edit' %></li>
0
     <li><%= link_to 'All Comments', :filter => nil %></li>
0
     <li><%= link_to 'Unapproved Comments', :filter => :unapproved %></li>
0
     <li><%= link_to 'Approved Comments', :filter => :approved %></li>
0
@@ -11,7 +12,7 @@
0
 </div>
0
 <!-- /end action nav -->
0
 
0
-<h2>Comments for '<%=h @article.title %>'</h2>
0
+<h2><%= "#{params[:filter].humanize} " if valid_filter? %>Comments for '<%=h @article.title %>'</h2>
0
 
0
 <% @comments.each do |comment| -%>
0
 <div id="comment-<%= comment.id %>">
...
42
43
44
45
 
46
47
48
...
42
43
44
 
45
46
47
48
0
@@ -42,7 +42,7 @@
0
     <h3>Comments Needing Moderation</h3>
0
     <ul class="slist">
0
     <% @articles.each do |article| -%>
0
- <li><%= link_to "<strong>(#{article.comments.size})</strong> #{h(article.title)}", :controller => 'articles', :action => 'comments', :id => article.id, :filter => :unapproved %></li>
0
+ <li><%= link_to "<strong>(#{article.unapproved_comments.size})</strong> #{h(article.title)}", :controller => 'articles', :action => 'comments', :id => article.id, :filter => :unapproved %></li>
0
     <% end -%>
0
     </ul>
0
   </div>
...
79
80
81
82
 
83
84
85
...
79
80
81
 
82
83
84
85
0
@@ -79,7 +79,7 @@
0
     <script type="text/javascript" language="javascript" charset="utf-8">
0
     // <![CDATA[
0
      //new Asset.Manager();
0
- new Control.Resizer('main', 'sbar', {handle: 'sbar-handle'});
0
+ //new Control.Resizer('main', 'sbar', {handle: 'sbar-handle'});
0
     // ]]>
0
     </script>
0
   </body>

Comments

    No one has commented yet.