Added RSS dasboard widget.
This commit is contained in:
parent
6e08d1f3d9
commit
e60163ed30
7 changed files with 99 additions and 10 deletions
22
Gemfile
22
Gemfile
|
@ -22,20 +22,22 @@ gem 'jquery-rails'
|
|||
# Optional support for eco templates
|
||||
gem 'eco'
|
||||
|
||||
gem "omniauth"
|
||||
gem "omniauth-twitter"
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-linkedin"
|
||||
gem "omniauth-google-oauth2"
|
||||
gem 'omniauth'
|
||||
gem 'omniauth-twitter'
|
||||
gem 'omniauth-facebook'
|
||||
gem 'omniauth-linkedin'
|
||||
gem 'omniauth-google-oauth2'
|
||||
|
||||
gem "twitter"
|
||||
gem "koala"
|
||||
gem "mail"
|
||||
gem 'twitter'
|
||||
gem 'koala'
|
||||
gem 'mail'
|
||||
|
||||
gem "mime-types"
|
||||
gem 'mime-types'
|
||||
|
||||
gem 'delayed_job_active_record'
|
||||
gem "daemons"
|
||||
gem 'daemons'
|
||||
|
||||
gem 'simple-rss'
|
||||
|
||||
# To use ActiveModel has_secure_password
|
||||
# gem 'bcrypt-ruby', '~> 3.0.0'
|
||||
|
|
|
@ -127,6 +127,7 @@ GEM
|
|||
railties (~> 3.2.0)
|
||||
sass (>= 3.1.10)
|
||||
tilt (~> 1.3)
|
||||
simple-rss (1.2.3)
|
||||
simple_oauth (0.1.5)
|
||||
sprockets (2.1.2)
|
||||
hike (~> 1.2)
|
||||
|
@ -168,6 +169,7 @@ DEPENDENCIES
|
|||
omniauth-twitter
|
||||
rails (= 3.2.2)
|
||||
sass-rails (~> 3.2.4)
|
||||
simple-rss
|
||||
sqlite3
|
||||
twitter
|
||||
uglifier (>= 1.2.3)
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
$ = jQuery.sub()
|
||||
|
||||
class App.DashboardRss extends App.Controller
|
||||
constructor: ->
|
||||
super
|
||||
# @log 'aaaa', @el
|
||||
|
||||
@items = []
|
||||
|
||||
# get data
|
||||
@ajax = new App.Ajax
|
||||
@ajax.ajax(
|
||||
type: 'GET',
|
||||
url: '/rss_fetch',
|
||||
data: {
|
||||
limit: @limit,
|
||||
url: @url,
|
||||
}
|
||||
processData: true,
|
||||
success: (data, status, xhr) =>
|
||||
@items = data.items || []
|
||||
@render()
|
||||
)
|
||||
|
||||
render: ->
|
||||
html = App.view('dashboard/rss')(
|
||||
head: @head,
|
||||
items: @items
|
||||
)
|
||||
html = $(html)
|
||||
@html html
|
|
@ -31,6 +31,23 @@ class Index extends App.Controller
|
|||
activity_stream: {
|
||||
controller: App.DashboardActivityStream,
|
||||
},
|
||||
rss_atom: {
|
||||
controller: App.DashboardRss,
|
||||
params: {
|
||||
head: 'Heise ATOM',
|
||||
url: 'http://www.heise.de/newsticker/heise-atom.xml',
|
||||
limit: 5,
|
||||
},
|
||||
},
|
||||
# rss_rdf: {
|
||||
# controller: App.DashboardRss,
|
||||
# params: {
|
||||
# head: 'Heise RDF',
|
||||
# url: 'http://www.heise.de/newsticker/heise.rdf',
|
||||
# limit: 5,
|
||||
# },
|
||||
# },
|
||||
|
||||
# recent_viewed: {
|
||||
# controller: App.DashboardRecentViewed,
|
||||
# }
|
||||
|
|
10
app/assets/javascripts/app/views/dashboard/rss.jst.eco
Normal file
10
app/assets/javascripts/app/views/dashboard/rss.jst.eco
Normal file
|
@ -0,0 +1,10 @@
|
|||
<div class="row">
|
||||
<div class="span3">
|
||||
<h2><%= @head %></h2>
|
||||
<ul>
|
||||
<% for item in @items: %>
|
||||
<li><a href="<%= item.link %>" title="<%= item.summary %>" target="_blank"><%= item.title %>"</a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
24
app/controllers/rss_controller.rb
Normal file
24
app/controllers/rss_controller.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class RssController < ApplicationController
|
||||
before_filter :authentication_check
|
||||
|
||||
# GET /rss_fetch
|
||||
def fetch
|
||||
url = params[:url]
|
||||
limit = params[:limit] || 10
|
||||
response = Net::HTTP.get_response( URI.parse(url) )
|
||||
if response.code.to_s != '200'
|
||||
render :json => { :message => "failed to fetch #{url}, code: #{response.code}"}, :status => :unprocessable_entity
|
||||
return
|
||||
end
|
||||
rss = SimpleRSS.parse response.body
|
||||
items = []
|
||||
fetched = 0
|
||||
rss.items.each { |item|
|
||||
items.push item
|
||||
fetched += 1
|
||||
break item if fetched == limit.to_i
|
||||
}
|
||||
render :json => { :items => items }
|
||||
end
|
||||
|
||||
end
|
|
@ -49,6 +49,9 @@ Zammad::Application.routes.draw do
|
|||
# getting_started
|
||||
match '/getting_started', :to => 'getting_started#index'
|
||||
|
||||
# getting_started
|
||||
match '/rss_fetch', :to => 'rss#fetch'
|
||||
|
||||
# sessions
|
||||
resources :sessions, :only => [:create, :destroy, :show]
|
||||
match '/signin', :to => 'sessions#create'
|
||||
|
|
Loading…
Reference in a new issue