Add category selection for subscription

This commit is contained in:
Bernie Chiu 2013-11-20 17:01:51 +08:00
parent 9933db4fb5
commit cb78427866
6 changed files with 38 additions and 23 deletions

View File

@ -11,11 +11,13 @@ class Panel::Feed::BackEnd::FeedsController < OrbitBackendController
end
def new
@feed = AnnouncementFeed.new
@feed = AnnouncementFeed.new
@categories = BulletinCategory.all
end
def edit
@feed = AnnouncementFeed.find(params[:id])
@categories = BulletinCategory.all
end
def create

View File

@ -4,5 +4,6 @@ class AnnouncementFeed
field :link, type: String
field :name, type: String
field :category
end

View File

@ -1,22 +1,30 @@
<legend><h3 style="margin-left: 10px;"><%= t('feed.channel') %></h3></legend>
<fieldset style="margin-left: -50px;">
<div class="control-group">
<label class="control-label" for="inputName"><%= t('feed.enter') + " RSS " + t('feed.name')%>:</label>
<div class="controls">
<%= f.text_field :name, :class => 'span4', :placeholder => 'RSS ' + t('feed.name'), :id => "inputName" %>
<div class="control-group">
<label class="control-label" for="inputName"><%= t('feed.enter') + " RSS " + t('feed.name')%>:</label>
<div class="controls">
<%= f.text_field :name, :class => 'span4', :placeholder => 'RSS ' + t('feed.name'), :id => "inputName" %>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputURL"><%= t('feed.enter') + " RSS URL" %>:</label>
<div class="controls">
<%= f.text_field :link, :class => 'span4', :placeholder => 'RSS URL', :id => "inputURL"%>
<div class="control-group">
<label class="control-label" for="inputURL"><%= t('feed.enter') + " RSS URL" %>:</label>
<div class="controls">
<%= f.text_field :link, :class => 'span4', :placeholder => 'RSS URL', :id => "inputURL" %>
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<%= f.submit t("submit"), :class => "btn btn-primary" %>
<div class="control-group">
<label class="control-label" for="inputURL"><%= t('feed.choose') %>:</label>
<div class="controls">
<%= f.select(:category, options_for_select([["#{t('feed.all')}", "all"]] +
@categories.all.collect {|c| [ c.title, c.title ] })) %>
</div>
</div>
<div class="control-group">
<div class="controls">
<%= f.submit t("submit"), :class => "btn btn-primary" %>
</div>
</div>
</div>
</fieldset>

View File

@ -1,6 +1,8 @@
en:
feed:
feed: Rss
all: All
choose: Choose a Category
feed: RSS
channel: Announcement Rss
new: New
edit: Edit

View File

@ -1,6 +1,8 @@
zh_tw:
feed:
feed: Rss
all: 全部
choose: 選擇訂閱類別
feed: RSS
channel: 公告RSS訂閱
new: 新增
edit: 編輯

View File

@ -2,20 +2,20 @@
require 'rss'
require 'mongo'
# Change this according to local DB
DB_BASE_NAME = "production_0"
DB_NAME = "production_0"
# Create a hash rss site list from mongodb
db = Mongo::Connection.new("localhost", 27017).db("#{DB_BASE_NAME}")
db = Mongo::Connection.new("localhost", 27017).db("#{DB_NAME}")
SITES = Hash[ db["announcement_feeds"].find().entries.collect {|f| [ f["name"], f["link"] ]} ]
CATEGORIES = db["announcement_feeds"].find().entries.map {|f| f["category"] }
yesterday = Time.now - 86400
two_weeks_ago = Time.new - 60 * 60 * 24 * 14
recent_feed = {}
SITES.each do |name, url|
SITES.each_with_index do |(name, url), i|
open("http://#{url}/panel/announcement/front_end/bulletins.rss?inner=true") do |rss|
# Giving 'false' parameter is for skipping irregular format of the RSS
@ -24,7 +24,7 @@ SITES.each do |name, url|
feed.items.each do |item|
category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
if item.pubDate > two_weeks_ago
if item.pubDate > yesterday && (CATEGORIES[i] == category || CATEGORIES[i] == "all")
recent_feed[item.title.strip] = { date: item.pubDate, description: item.description.gsub("\r\n", '<br/>').strip,
link: item.link, category: category, source: name }
end
@ -51,7 +51,7 @@ def get_category_id(category, categories, coll_cat)
end
def get_mongo_and_categories
db = Mongo::Connection.new("localhost", 27017).db("#{DB_BASE_NAME}")
db = Mongo::Connection.new("localhost", 27017).db("#{DB_NAME}")
coll_bulletin = db["bulletins"]
coll_cat = db["bulletin_categories"]