Skip to content

Commit 57c39d3

Browse files
committed
add admin console function: delete commenters, delete comments
1 parent 06b21e2 commit 57c39d3

14 files changed

+74
-24
lines changed

TODO

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
- Now
2-
* upload logo
3-
* comment box tips: markdown style
4-
* upload attachment and delete immediately
2+
* upload attachment and delete immediately bug
53

64
- Backend
75
* Editor Tab
8-
* admin panel:
9-
+ upload logo
10-
+ change name and password
11-
+ delete commenter
12-
+ delete blog comments
6+
* admin panel style:
7+
+ user profile setting
8+
+ show accounts list
9+
+ show blog comments list
1310
+ quick modifiy articles' tags
14-
* file upload enhancement
1511

1612
- Frontend
1713
* resume
@@ -25,5 +21,4 @@
2521
* default website favicon
2622

2723
- Bug
28-
* upload attachment and delete immediately
2924
* IE compatiablity

app/controllers/admin.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@
6363
content_type :js
6464
comment = BlogComment.find params[:id]
6565
comment.destroy
66-
"$('div#comments>ul>li##{comment.id}').fadeOut('slow', function(){$(this).remove();});"
66+
if params[:quick]
67+
# delete comment from admin console
68+
"$('tr#comment_#{comment.id}').fadeOut('slow', function(){ $(this).remove();});"
69+
else
70+
# delete comment from blog article
71+
"$('div#comments>ul>li##{comment.id}').fadeOut('slow', function(){$(this).remove();});"
72+
end
6773
end
6874

6975
# attachment related routes: upload, show, delete attachment...
@@ -120,6 +126,15 @@
120126
render 'admin/accounts'
121127
end
122128

129+
delete :account, :map => '/admin/account/:id' do
130+
content_type :js
131+
account = Account.find params[:id]
132+
if account.commenter?
133+
account.destroy
134+
"$('tr#account_#{account.id}').fadeOut('slow', function(){ $(this).remove();});"
135+
end
136+
end
137+
123138
get :blogs, :map => '/admin/blogs' do
124139
@blogs = Blog.order('id DESC').page(params[:page]).per_page(100)
125140
render 'admin/blogs'

app/controllers/home.rb

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
content_type :rss
2828
@blogs = Blog.order('id DESC').limit(20)
2929
render 'home/rss'
30-
# APP_CACHE.fetch("#{CACHE_PREFIX}/rss/all") { render 'home/rss' }
3130
end
3231

3332
# native authentication

app/helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ def ping_search_engine(blog)
7171
APP_CONFIG['site_url'] + '/rss',
7272
blog.cached_tag_list.gsub(/,/, '|'))
7373
rescue Exception => e
74-
logger.error e
74+
logger.error e
7575
end
7676
end

app/views/admin/_attachment.erb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="attachment_<%= attachment.id %>">
2-
<%= attachment.file.url %>
3-
<%= link_to '删除', url(:admin, :attachment, :id => attachment.id), :method => :delete, :remote => true, :confirm => '是否删除附件' %>
4-
<a href="#" onclick="window.parent.$('#blog_content').insertAtCaret('\n![](<%= attachment.file.url %>)\n');return false;">插入</a>
2+
<%= link_to attachment.file.file.identifier, attachment.file.url, :target => '_blank' %>
3+
<%= link_to image_tag('btn_delete.png', :title => '删除附件'), url(:admin, :attachment, :id => attachment.id), :method => :delete, :remote => true, :confirm => '是否删除附件' %>
4+
<a href="#" onclick="window.parent.$('#blog_content').insertAtCaret('\n![](<%= attachment.file.url %>)\n');return false;"><%= image_tag 'btn_sticky.png', :title => '将图片插入编辑器' %></a>
55
</div>

app/views/admin/_form.erb

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
<th valign="top">附件</th>
5252
<td>
5353
<% unless @attachments.blank? %>
54-
<%= partial 'admin/attachment', :collection => @attachments %>
54+
已上传的文件:
55+
<%= partial 'admin/attachment', :collection => @attachments %>
5556
<% end %>
57+
上传新的文件:
5658
<div id="attachment_iframes">
5759
<iframe src="<%= url(:admin, :new_attachment) %>" style="border:0px;height:30px;width:100%;" frameborder="0" border="0" cellspacing="0" allowTransparency="true" scrolling="no" resizable="no"></iframe>
5860
</div>

app/views/admin/accounts.erb

+24-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
accounts.
1+
<table>
2+
<caption>管理员列表: 共<%= @admin_accounts.size %></caption>
3+
<% @admin_accounts.each_with_index do |account, index| %>
4+
<tr>
5+
<td><%= index + 1 %></td>
6+
<td><%= account.name %></td>
7+
<td><%= account.blogs_count %></td>
8+
<td><%= account.comments_count %></td>
9+
<td><%= link_to '编辑', url(:admin, :edit_profile, :id => account.id) %></td>
10+
</tr>
11+
<% end %>
12+
</table>
13+
14+
<table>
15+
<caption>评论者列表: 共<%= @commenters.size %></caption>
16+
<% @commenters.each_with_index do |account, index| %>
17+
<tr id='<%= "account_#{account.id}" %>'>
18+
<td><%= index+1 %></td>
19+
<td><%= commenter_link account %></td>
20+
<td><%= account.comments_count %></td>
21+
<td><%= link_to '删除', url(:admin, :account, :id => account.id), :method => :delete, :remote => true, :confirm => '要删除用户吗?' %></td>
22+
</tr>
23+
<% end %>
24+
</table>

app/views/admin/comments.erb

+13-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
comments
1+
<table>
2+
<caption>评论列表: 共<%= @comments.total_entries %></caption>
3+
<% @comments.each_with_index do |comment, index| %>
4+
<tr id='<%= "comment_#{comment.id}" %>'>
5+
<td><%= index + 1 %></td>
6+
<td><%= commenter_link comment.account %></td>
7+
<td><%= link_to "删除", url(:admin, :comment, :id => comment.id, :quick => true), :method => :delete, :remote => true, :confirm => '要删除评论吗?' %></td>
8+
<td><%= comment.brief_content %></td>
9+
</tr>
10+
<% end %>
11+
</table>
12+
13+
<%= (will_paginate @comments, :previous_label => '前一页', :next_label => '后一页').to_s.html_safe %>

app/views/blog/_comment.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<span class="user_name"><%= commenter_link(comment.account) %></span>
66
<span class="time"><%= time_ago_in_words(comment.created_at) %></span>
77
<% if account_admin? %>
8-
<span><%= link_to "删除", url(:admin, :comment, :id => comment.id), :method => :delete, :remote => true %></span>
8+
<span><%= link_to "删除", url(:admin, :comment, :id => comment.id), :method => :delete, :remote => true, :confirm => '要删除评论吗?' %></span>
99
<% end %>
1010
</div>
1111
<p><%= comment.md_content.html_safe %></p>

app/views/blog/show.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@
4141

4242
<div class="comment clearfix">
4343
<div id="comments">
44-
<h2><span><%= @blog.comments_count %></span>Comment</h2>
44+
<h2><span><%= @blog.comments_count %></span>条评论</h2>
4545
<ul>
4646
<% if @blog.comments_count > 0 %>
4747
<%= partial 'blog/comment', :collection => @blog.comments.reverse %>
4848
<% end %>
4949
</ul>
5050
</div>
5151
<% if @blog.commentable? %>
52-
<h4>Leave a Reply</h4>
5352
<a name="comments"></a>
5453
<div class="relative">
54+
<div style="text-align:right;">[<a href="http://wowubuntu.com/markdown/" target="_blank">评论可以使用Markdown格式</a>]</div>
5555
<% form_for BlogComment.new, url(:blog, :create_comment, :id => @blog.id), :remote => true do |f| %>
5656
<%= f.text_area :content, :class => 'comment' %>
5757
<div id="comment-error-info"></div>

models/account.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ def has_password?(password)
3636
end
3737

3838
def admin?
39-
self.role == "admin"
39+
self.role == 'admin'
40+
end
41+
42+
def commenter?
43+
self.role == 'commenter'
4044
end
4145

4246
def encrypt_cookie_value

models/blog_comment.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def content_cache_key
1818
end
1919

2020
def brief_content
21-
Sanitize.clean(content)
21+
Sanitize.clean(content).truncate(100)
2222
end
2323

2424
def md_content

public/images/btn_delete.png

999 Bytes
Loading

public/images/btn_sticky.png

917 Bytes
Loading

0 commit comments

Comments
 (0)