Add category selection for subscription
This commit is contained in:
parent
9933db4fb5
commit
cb78427866
|
@ -11,11 +11,13 @@ class Panel::Feed::BackEnd::FeedsController < OrbitBackendController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@feed = AnnouncementFeed.new
|
@feed = AnnouncementFeed.new
|
||||||
|
@categories = BulletinCategory.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@feed = AnnouncementFeed.find(params[:id])
|
@feed = AnnouncementFeed.find(params[:id])
|
||||||
|
@categories = BulletinCategory.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -4,5 +4,6 @@ class AnnouncementFeed
|
||||||
|
|
||||||
field :link, type: String
|
field :link, type: String
|
||||||
field :name, type: String
|
field :name, type: String
|
||||||
|
field :category
|
||||||
|
|
||||||
end
|
end
|
|
@ -1,22 +1,30 @@
|
||||||
<legend><h3 style="margin-left: 10px;"><%= t('feed.channel') %></h3></legend>
|
<legend><h3 style="margin-left: 10px;"><%= t('feed.channel') %></h3></legend>
|
||||||
<fieldset style="margin-left: -50px;">
|
<fieldset style="margin-left: -50px;">
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label" for="inputName"><%= t('feed.enter') + " RSS " + t('feed.name')%>:</label>
|
<label class="control-label" for="inputName"><%= t('feed.enter') + " RSS " + t('feed.name')%>:</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.text_field :name, :class => 'span4', :placeholder => 'RSS ' + t('feed.name'), :id => "inputName" %>
|
<%= f.text_field :name, :class => 'span4', :placeholder => 'RSS ' + t('feed.name'), :id => "inputName" %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label" for="inputURL"><%= t('feed.enter') + " RSS URL" %>:</label>
|
<label class="control-label" for="inputURL"><%= t('feed.enter') + " RSS URL" %>:</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.text_field :link, :class => 'span4', :placeholder => 'RSS URL', :id => "inputURL"%>
|
<%= f.text_field :link, :class => 'span4', :placeholder => 'RSS URL', :id => "inputURL" %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="controls">
|
<label class="control-label" for="inputURL"><%= t('feed.choose') %>:</label>
|
||||||
<%= f.submit t("submit"), :class => "btn btn-primary" %>
|
<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>
|
||||||
</div>
|
|
||||||
</fieldset>
|
</fieldset>
|
|
@ -1,6 +1,8 @@
|
||||||
en:
|
en:
|
||||||
feed:
|
feed:
|
||||||
feed: Rss
|
all: All
|
||||||
|
choose: Choose a Category
|
||||||
|
feed: RSS
|
||||||
channel: Announcement Rss
|
channel: Announcement Rss
|
||||||
new: New
|
new: New
|
||||||
edit: Edit
|
edit: Edit
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
zh_tw:
|
zh_tw:
|
||||||
feed:
|
feed:
|
||||||
feed: Rss
|
all: 全部
|
||||||
|
choose: 選擇訂閱類別
|
||||||
|
feed: RSS
|
||||||
channel: 公告RSS訂閱
|
channel: 公告RSS訂閱
|
||||||
new: 新增
|
new: 新增
|
||||||
edit: 編輯
|
edit: 編輯
|
||||||
|
|
|
@ -2,20 +2,20 @@
|
||||||
require 'rss'
|
require 'rss'
|
||||||
require 'mongo'
|
require 'mongo'
|
||||||
|
|
||||||
|
|
||||||
# Change this according to local DB
|
# Change this according to local DB
|
||||||
DB_BASE_NAME = "production_0"
|
DB_NAME = "production_0"
|
||||||
|
|
||||||
# Create a hash rss site list from mongodb
|
# 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"] ]} ]
|
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
|
yesterday = Time.now - 86400
|
||||||
two_weeks_ago = Time.new - 60 * 60 * 24 * 14
|
two_weeks_ago = Time.new - 60 * 60 * 24 * 14
|
||||||
|
|
||||||
recent_feed = {}
|
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|
|
open("http://#{url}/panel/announcement/front_end/bulletins.rss?inner=true") do |rss|
|
||||||
|
|
||||||
# Giving 'false' parameter is for skipping irregular format of the 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|
|
feed.items.each do |item|
|
||||||
category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
|
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,
|
recent_feed[item.title.strip] = { date: item.pubDate, description: item.description.gsub("\r\n", '<br/>').strip,
|
||||||
link: item.link, category: category, source: name }
|
link: item.link, category: category, source: name }
|
||||||
end
|
end
|
||||||
|
@ -51,7 +51,7 @@ def get_category_id(category, categories, coll_cat)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_mongo_and_categories
|
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_bulletin = db["bulletins"]
|
||||||
coll_cat = db["bulletin_categories"]
|
coll_cat = db["bulletin_categories"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue