Implement a read flag, mark unread items in the ui

+ unread count
This commit is contained in:
Aaron Mueller 2013-01-10 22:21:23 +01:00
parent c24799fed2
commit a4c8be72a7
14 changed files with 43 additions and 18 deletions

View File

@ -2,10 +2,11 @@
* Handle relative URLs in Atom feed.
(http://www.rfc1149.net/blog/2010/12/27/feed-and-relative-links/)
* Update a single feed manually and mark the new feeds in the db
* Rake task to update all feeds at once
* Detect an RSS link in a given website URL
* Add an optional manual title to the imported feed
* Collapse the opened item again
* Make the UI consistend (read/unread items)
=== Low priority
@ -16,4 +17,3 @@
=== Broken feeds with feedzirra
* http://blog.fefe.de/rss.xml

View File

@ -1,5 +1,9 @@
@import "config";
a.unread {
font-weight: bold;
}
li.item {
overflow: auto;

View File

@ -1,7 +1,7 @@
@import "config";
aside {
width: 250px;
width: 350px;
float: left;
ul {

View File

@ -10,6 +10,12 @@ class FeedsController < ApplicationController
render :layout => false
end
def refresh
@feed = Feed.find(params[:id])
@feed.fetch!
redirect_to :action => :show, :notice => "Add the feed"
end
def create
@feed = Feed.import(params[:feed][:url])
redirect_to :action => :index, :notice => "Add the feed"

View File

@ -1,6 +1,7 @@
class ItemsController < ApplicationController
def show
@item = Item.find(params[:id])
@item.read
render :layout => false
end
end

View File

@ -1,5 +1,3 @@
require "pp"
class Feed < ActiveRecord::Base
has_many :items, :dependent => :destroy
has_many :errors, :dependent => :destroy

View File

@ -1,11 +1,14 @@
class Item < ActiveRecord::Base
belongs_to :feed
validates_presence_of :title, :author, :content
validates_uniqueness_of :url
default_scope order("published_at DESC")
scope :recent, limit(10)
scope :unread, where(:read_at => nil)
#attr_accessible :read_at
def self.create_from_feed_entry!(feed_entry)
feed_entry.sanitize!
@ -19,6 +22,10 @@ class Item < ActiveRecord::Base
)
end
def read
update_attribute(:read_at, Time.now)
end
def <=>(other)
self.published_at <=> other.published_at
end

View File

@ -1,9 +1,14 @@
<ul id="feed_list">
<% @feeds.each do |feed| %>
<% unread_count = feed.items.unread.size %>
<li>
(<%= link_to "del", feed_path(feed), :remote => true, :method => :delete, :class => "delete_feed button", :confirm => "Delete this feed?" %>,
<%= link_to "err", errors_feed_path(feed), :remote => true, :class => "button", :update => "feed_content" %>)
<%= link_to feed.title, feed_path(feed), :remote => true, :update => "feed_content" %>
(<%= link_to "del", feed_path(feed), :remote => true, :method => :delete, :class => "delete_feed button", :confirm => "Delete this feed?" %>,
<%= link_to "err", errors_feed_path(feed), :remote => true, :class => "button", :update => "feed_content" %>,
<%= link_to "up", refresh_feed_path(feed), :remote => true, :class => "button", :method => :post, :update => "feed_content" %>)
<% r = unread_count.zero? ? "read" : "unread" %>
<%= link_to feed.title, feed_path(feed), :remote => true, :update => "feed_content", :class => r %>
[<%= unread_count %>]
</li>
<% end %>
</ul>

View File

@ -3,7 +3,8 @@
<ul>
<% @feed.items.each do |item| %>
<li class="item">
<%= link_to raw(item.title), item_path(item), :remote => true %>
<% r = item.read_at.nil? ? "unread" : "read" %>
<%= link_to raw(item.title), item_path(item), :remote => true, :class => r %>
<em class="date_published"><%= time_ago_in_words(item.published_at) %></em> <em class="author">by <%= item.author %></em>
<article></article>
</li>

View File

@ -1,3 +1,3 @@
<p>
<%= raw @item.content %>
</p>
</p>

View File

@ -17,6 +17,7 @@ FeedFu::Application.routes.draw do
get :import
end
member do
post :refresh
get :errors
end
end

View File

@ -1,9 +1,5 @@
class AddErrorField < ActiveRecord::Migration
def up
def change
add_column :feeds, :has_errors, :boolean, :default => false
end
def down
remove_column :feeds, :has_errors
end
end

View File

@ -0,0 +1,5 @@
class AddReadFlagToItems < ActiveRecord::Migration
def change
add_column :items, :read_at, :timestamp, :default => nil
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130110200633) do
ActiveRecord::Schema.define(:version => 20130110204625) do
create_table "errors", :force => true do |t|
t.integer "feed_id"
@ -38,6 +38,7 @@ ActiveRecord::Schema.define(:version => 20130110200633) do
t.integer "feed_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "read_at"
end
end