Skip to content

Commit

Permalink
better view for comments index page to show spams in a tab
Browse files Browse the repository at this point in the history
  • Loading branch information
arashm committed Mar 7, 2014
1 parent 32c293d commit 5f39c95
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 63 deletions.
10 changes: 10 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def index

respond_to do |format|
format.html # index.html.erb
format.js
end
end

Expand Down Expand Up @@ -106,6 +107,15 @@ def destroy
end
end

def spams
@comments = Comment.unapproved.includes(:story).order("created_at DESC").page params[:page]

respond_to do |format|
format.html { render :action => :index }
format.js
end
end

# DELETE /comments/destroy_spams
def destroy_spams
Comment.unapproved.destroy_all
Expand Down
63 changes: 63 additions & 0 deletions app/views/comments/_short_comment.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<% if request.path == comments_spams_path %>
<div>
<%= link_to t('.destroy_spams'), comments_destroy_spams_path, id: 'destroy_spams', method: :delete %>
</div>
<% end %>
<table class="table table-striped">
<thead>
<tr>
<th style="width:20%"><%= t('.from') %></th>
<th><%= t('.comment') %></th>
<th style="width:15%"><%= t('.in_response') %></th>
<th><%=t '.actions', :default => t("helpers.actions") %></th>
</tr>
</thead>
<tbody>
<% @comments.each do |comment| %>
<tr <%= "class=spam" if !comment.approved? %> >
<td>
<%= image_tag avatar_url(comment, 32), class: 'pull-right img-polaroid clearfix', style: 'margin:5px' %>
<%= content_tag :b, comment.name %>
<br />
<%= comment.email %>
<br />
<%= comment.user_ip %>
</td>
<td>
<small>
<%= content_tag :span,
link_to(t('.sent') + to_jalali(comment.created_at),
story_path(comment.story, :anchor => "comment_#{comment.id}")),
class: 'muted'
%>
</small>
<%= content_tag :p, sanitize(RedCloth.new(comment.content, [:filter_html, :filter_styles]).to_html) %>
</td>
<td><%= link_to comment.story.title, story_path(comment.story) %></td>
<td>
<% if comment.approved? %>
<%= link_to t('.spam',
:default => t("helpers.links.spam")),
mark_as_spam_story_comment_path(comment.story, comment),
:method => :put %>
<% else %>
<%= link_to t('.not_spam',
:default => t("helpers.links.not_spam")),
mark_as_not_spam_story_comment_path(comment.story, comment),
:method => :put %>
<% end %>
<span>|</span>
<%= link_to t('.edit',
:default => t("helpers.links.edit")),
edit_story_comment_path(comment.story, comment) %>
<span>|</span>
<%= link_to t('.destroy',
:default => t("helpers.links.destroy")),
story_comment_path(comment.story, comment),
:method => :delete,
data: { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) } %>
</td>
</tr>
<% end %>
</tbody>
</table>
72 changes: 11 additions & 61 deletions app/views/comments/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,17 @@
<h1><%=t '.title', :default => "مدیریت پیام‌ها" %></h1>
<% end %>

<div>
<%= link_to t('.destroy_spams') + "(#{Comment.unapproved.size.to_farsi})", comments_destroy_spams_path, id: 'destroy_spams', method: :delete %>
</div>
<ul class='nav nav-tabs'>
<li id='comments_li' class='active'>
<%= link_to 'دیدگاه‌ها', comments_path, remote: true %>
</li>

<table class="table table-striped">
<thead>
<tr>
<th style="width:20%"><%= t('.from') %></th>
<th><%= t('.comment') %></th>
<th style="width:15%"><%= t('.in_response') %></th>
<th><%=t '.actions', :default => t("helpers.actions") %></th>
</tr>
</thead>
<tbody>
<% @comments.each do |comment| %>
<tr <%= "class=spam" if !comment.approved? %> >
<td>
<%= image_tag avatar_url(comment, 32), class: 'pull-right img-polaroid clearfix', style: 'margin:5px' %>
<%= content_tag :b, comment.name %>
<br />
<%= comment.email %>
<br />
<%= comment.user_ip %>
</td>
<td>
<small>
<%= content_tag :span,
link_to(t('.sent') + to_jalali(comment.created_at),
story_path(comment.story, :anchor => "comment_#{comment.id}")),
class: 'muted'
%>
</small>
<%= content_tag :p, sanitize(RedCloth.new(comment.content, [:filter_html, :filter_styles]).to_html) %>
</td>
<td><%= link_to comment.story.title, story_path(comment.story) %></td>
<td>
<% if comment.approved? %>
<%= link_to t('.spam',
:default => t("helpers.links.spam")),
mark_as_spam_story_comment_path(comment.story, comment),
:method => :put %>
<% else %>
<%= link_to t('.not_spam',
:default => t("helpers.links.not_spam")),
mark_as_not_spam_story_comment_path(comment.story, comment),
:method => :put %>
<% end %>
<span>|</span>
<%= link_to t('.edit',
:default => t("helpers.links.edit")),
edit_story_comment_path(comment.story, comment) %>
<span>|</span>
<%= link_to t('.destroy',
:default => t("helpers.links.destroy")),
story_comment_path(comment.story, comment),
:method => :delete,
data: { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) } %>
</td>
</tr>
<% end %>
</tbody>
</table>
<li id='spams_li'>
<%= link_to "اسپم‌ها(#{Comment.unapproved.size.to_farsi})", comments_spams_path, remote: true %>
</li>

</ul>
<div id='comments-body'>
<%= render partial: 'short_comment' %>
</div>
<%= paginate @comments %>
3 changes: 3 additions & 0 deletions app/views/comments/index.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$("li.active").removeAttr('class')
$("#comments_li").addClass('active')
$("#comments-body").html('<%= j render partial: 'short_comment' %>')
3 changes: 3 additions & 0 deletions app/views/comments/spams.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$("li.active").removeAttr('class')
$("#spams_li").addClass('active')
$("#comments-body").html('<%= j render partial: 'short_comment' %>')
4 changes: 2 additions & 2 deletions config/locales/fa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fa:

comments:
title: 'دیدگاه‌ها'
index:
short_comment:
title: 'مدیریت دیدگاه‌ها'
from: 'نویسنده'
comment: 'دیدگاه'
Expand All @@ -306,7 +306,7 @@ fa:
show:
title: 'نمایش دیدگاه'
edit:
title: 'نمایش دیدگاه'
title: 'ویرایش دیدگاه'
new:
title: 'دیدگاه جدید'

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
end

get "/comments" => "comments#index"
get "/comments/spams" => "comments#spams"
delete "/comments/destroy_spams" => 'comments#destroy_spams'

get "/:permalink" => "pages#show", as: "page_by_permalink"
Expand Down

0 comments on commit 5f39c95

Please sign in to comment.