Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #343 from izwick-schachter/autoflag-rss
Added RSS feed for autoflagged posts
- Loading branch information
Showing
13 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
class RSSController < ApplicationController | ||
def autoflagged | ||
@posts = Post.order('created_at DESC').paginate(page: params[:page], per_page: 50) | ||
@posts = @posts.where(site: params[:site]) if params[:site].present? | ||
if params[:deleted].present? | ||
@posts = if params[:deleted].casecmp('true') == 0 || params[:deleted] == '1' | ||
@posts.where.not(deleted_at: nil) | ||
else | ||
@posts.where(deleted_at: nil) | ||
end | ||
end | ||
if params[:from_date].present? | ||
@posts = @posts.where('`posts`.`created_at` > ?', DateTime.strptime(params[:from_date], '%s')) | ||
end | ||
if params[:to_date].present? | ||
@posts = @posts.where('`posts`.`created_at` < ?', DateTime.strptime(params[:to_date], '%s')) | ||
end | ||
if params[:feedback_type].present? | ||
@posts = @posts.includes(:feedbacks).where(feedbacks: { feedback_type: params[:feedback_type] }) | ||
end | ||
respond_to do |format| | ||
format.html | ||
format.rss { render layout: false } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ def index | |
format.json do | ||
render json: @results | ||
end | ||
format.rss { render :search, layout: false } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
module RSSHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<table class="table" id="posts-index-table"> | ||
<tbody> | ||
<% posts.each do |post| %> | ||
<%= render "posts/post", :post => post %> | ||
<% end %> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h1>Autoflagged Posts</h1> | ||
|
||
<%= render 'posts/table', posts: @posts %> | ||
|
||
<div class="text-center"> | ||
<%= will_paginate @posts, renderer: BootstrapPagination::Rails %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
xml.instruct! :xml, version: '1.0' | ||
xml.rss version: '2.0' do | ||
xml.channel do | ||
xml.title 'Autoflagged Posts' | ||
xml.description 'Posts which have been autoflagged by Charcoal HQ' | ||
xml.link root_url | ||
|
||
@posts.each do |post| | ||
xml.item do | ||
xml.title post.title | ||
xml.description post.body | ||
xml.pubDate post.created_at.iso8601 | ||
xml.link url_for(controller: 'posts', action: 'show', id: post.id) | ||
xml.link url_for(controller: 'posts', action: 'show', id: post.id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
xml.instruct! :xml, version: '1.0' | ||
xml.rss version: '2.0' do | ||
xml.channel do | ||
xml.title 'Search Results' | ||
xml.link root_url | ||
|
||
@results.each do |post| | ||
xml.item do | ||
xml.title post.title | ||
xml.description post.body | ||
xml.pubDate post.created_at.iso8601 | ||
xml.link url_for(controller: 'posts', action: 'show', id: post.id) | ||
xml.link url_for(controller: 'posts', action: 'show', id: post.id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class RSSControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |