diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index f04ce6a..03fe0d7 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -30,7 +30,7 @@ class Admin::AnnouncementsController < OrbitAdminController end def feed - @table_feed_fields = ["announcement.feed_name", :tags] + @table_feed_fields = ["announcement.feed_name", :tags, "announcement.rssfeed"] @feeds = BulletinFeed.all.asc(:created_at) end diff --git a/app/controllers/announcement_feeds_controller.rb b/app/controllers/announcement_feeds_controller.rb index 5f47a10..68d0f75 100644 --- a/app/controllers/announcement_feeds_controller.rb +++ b/app/controllers/announcement_feeds_controller.rb @@ -1,7 +1,50 @@ +require "rss" class AnnouncementFeedsController < ApplicationController - + include Admin::AnnouncementsHelper def feed uid = params[:uid] + anns = get_announcements(uid) + render :json => anns.to_json + end + + def rssfeed + uid = params[:uid] + @bf = BulletinFeed.find_by(:uid => uid) rescue nil + if !@bf.nil? + tags = @bf.tag_ids + if !tags.empty? + @announcements = Bulletin.can_display.is_approved.filter_by_tags(tags) + end + end + respond_to do |format| + format.html {redirect_to "/xhr/announcements/rssfeed/#{@bf.uid}.rss"} + format.rss + end + end + + def feeds + feeds = [] + BulletinFeed.all.each do |bf| + feed = {} + feed["title_translations"] = bf.title_translations + feed["uid"] = bf.uid + feed["url"] = "#{request.base_url}/xhr/announcements/feed/#{bf.uid}" + feed["xml_url"] = "#{request.base_url}/xhr/announcements/rssfeed/#{bf.uid}.rss" + feed["tags"] = [] + bf.tag_ids.each do |t| + tag = Tag.find(t) + d = {} + d["name_translations"] = tag.name_translations + feed["tags"] << d + end + feeds << feed + end + render :json => {"feeds" => feeds}.to_json + end + + private + + def get_announcements(uid) bf = BulletinFeed.find_by(:uid => uid) rescue nil if !bf.nil? tags = bf.tag_ids @@ -57,28 +100,11 @@ class AnnouncementFeedsController < ApplicationController end all_anns << a end - render :json => {"announcements" => all_anns, "tags" => tag_names}.to_json + { + "announcements" => all_anns, + "tags" => tag_names + } end - - def feeds - feeds = [] - BulletinFeed.all.each do |bf| - feed = {} - feed["title_translations"] = bf.title_translations - feed["uid"] = bf.uid - feed["url"] = "#{request.base_url}/xhr/announcements/feed/#{bf.uid}" - feed["tags"] = [] - bf.tag_ids.each do |t| - tag = Tag.find(t) - d = {} - d["name_translations"] = tag.name_translations - feed["tags"] << d - end - feeds << feed - end - render :json => {"feeds" => feeds}.to_json - end - end diff --git a/app/views/admin/announcements/_feed.html.erb b/app/views/admin/announcements/_feed.html.erb index f08181d..5c92dcd 100644 --- a/app/views/admin/announcements/_feed.html.erb +++ b/app/views/admin/announcements/_feed.html.erb @@ -31,4 +31,7 @@ +