add combined flag+appeal listing for posts #262

This commit is contained in:
r888888888
2015-07-28 15:45:01 -07:00
parent 1c81c303d6
commit f483d0e7a8
7 changed files with 151 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
class PostEventsController < ApplicationController
before_filter :member_only
def index
@events = PostEvent.find_for_post(params[:post_id])
end
end

44
app/models/post_event.rb Normal file
View File

@@ -0,0 +1,44 @@
class PostEvent
class Instance
attr_reader :creator_id, :reason, :is_resolved, :created_at, :type
def initialize(row)
@creator_id = row["creator_id"].to_i
@reason = row["reason"]
@is_resolved = (row["is_resolved"] == "t")
@created_at = row["created_at"].to_time
@type = row["type"]
end
def creator
User.find(creator_id)
end
def type_name
if appeal?
"appeal"
else
"flag"
end
end
def appeal?
type == "a"
end
def flag?
type == "f"
end
end
QUERY = <<-EOS
(SELECT post_flags.creator_id, post_flags.reason, post_flags.is_resolved, post_flags.created_at, 'f' as type FROM post_flags WHERE post_flags.post_id = ?)
UNION
(SELECT post_appeals.creator_id, post_appeals.reason, 't' AS is_resolved, post_appeals.created_at, 'a' as type FROM post_appeals WHERE post_appeals.post_id = ?)
ORDER BY created_at
EOS
def self.find_for_post(post_id)
ActiveRecord::Base.select_all_sql(QUERY, post_id, post_id).map {|x| Instance.new(x)}
end
end

View File

@@ -0,0 +1,38 @@
<div id="c-post-flags">
<div id="a-index">
<h1>Flags &amp; Appeals</h1>
<table width="100%" class="striped">
<thead>
<tr>
<th width="5%">Type</th>
<th width="10%">Creator</th>
<th>Reason</th>
<th width="5%">Resolved?</th>
<th width="15%">Date</th>
</tr>
</thead>
<tbody>
<% @events.each do |event| %>
<tr class="resolved-<%= event.is_resolved %>">
<td><%= event.type_name %></td>
<td><%= link_to_user event.creator %></td>
<td><%= format_text event.reason %></td>
<td>
<% if event.is_resolved %>
yes
<% else %>
no
<% end %>
</td>
<td><%= compact_time event.created_at %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<% content_for(:page_title) do %>
Events - <%= Danbooru.config.app_name %>
<% end %>

View File

@@ -26,8 +26,7 @@
<ul>
<li><%= fast_link_to "Tags", post_versions_path(:search => {:post_id => @post.id}) %></li>
<li><%= fast_link_to "Notes", note_versions_path(:search => {:post_id => @post.id}) %></li>
<li><%= fast_link_to "Flags", post_flags_path(:search => {:post_id => @post.id}) %></li>
<li><%= fast_link_to "Appeals", post_appeals_path(:search => {:post_id => @post.id}) %></li>
<li><%= fast_link_to "Flags & Appeals", post_events_path(@post.id) %></li>
<li><%= fast_link_to "Commentary", artist_commentary_versions_path(:search => {:post_id => @post.id}) %></li>
</ul>
</section>