Permalink
Browse files

allow tags to be filtered by default for new and non-logged-in users

  • Loading branch information...
jcs committed Sep 6, 2012
1 parent d986952 commit c0934318988214615d104dece39f4e5c9e5eaed7
@@ -116,6 +116,11 @@ def _find_stories_for_user_and_tag_and_newest_and_by_user(user, tag = nil,
conds[0] += " AND taggings.tag_id NOT IN (SELECT tag_id FROM " <<
"tag_filters WHERE user_id = ?)"
conds.push @user.id
else
# for logged-out users, filter defaults
conds[0] += " AND taggings.tag_id NOT IN (SELECT id FROM " <<
"tags WHERE filtered_by_default = ?)"
conds.push true
end
stories = Story.find(
View
@@ -25,13 +25,23 @@ class User < ActiveRecord::Base
:pushover_device, :email_messages, :pushover_messages
before_save :check_session_token
after_create :create_default_tag_filters
def check_session_token
if self.session_token.blank?
self.session_token = Utils.random_str(60)
end
end
def create_default_tag_filters
Tag.where(:filtered_by_default => true).each do |t|
tf = TagFilter.new
tf.tag_id = t.id
tf.user_id = self.id
tf.save
end
end
def unread_message_count
Keystore.value_for("user:#{self.id}:unread_messages").to_i
end
@@ -4,15 +4,16 @@
</div>
<p>
To hide stories tagged with certain tags, check them below.
To hide stories from the home page that have been tagged with certain tags,
check them below.
</p>
<%= form_tag "/filters", :method => :post do %>
<table class="data zebra" cellspacing=0 width="75%">
<tr>
<th width="10%">Hide</th>
<th width="7%">Hide</th>
<th width="15%">Tag</th>
<th width="75%">Description</th>
<th width="78%">Description</th>
</tr>
<% Tag.all(:order => :tag).each do |tag| %>
<tr>
@@ -21,7 +22,10 @@
"checked" : "" %>></td>
<td><a href="/t/<%= tag.tag %>" class="tag tag_<%= tag.tag %>"><%=
tag.tag %></a></td>
<td><%= tag.description %></td>
<td><%= tag.description %>
<% if tag.filtered_by_default? %>
<em>(Filtered by default)</em>
<% end %></td>
</tr>
<% end %>
</table>
@@ -0,0 +1,8 @@
class DefaultFilteredTags < ActiveRecord::Migration
def up
add_column :tags, :filtered_by_default, :boolean, :default => false
end
def down
end
end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120902143549) do
ActiveRecord::Schema.define(:version => 20120906183346) do
create_table "comments", :force => true do |t|
t.datetime "created_at", :null => false
@@ -112,8 +112,9 @@
add_index "taggings", ["story_id", "tag_id"], :name => "story_id_tag_id", :unique => true
create_table "tags", :force => true do |t|
t.string "tag", :limit => 25, :default => "", :null => false
t.string "description", :limit => 100
t.string "tag", :limit => 25, :default => "", :null => false
t.string "description", :limit => 100
t.boolean "filtered_by_default", :default => false
end
add_index "tags", ["tag"], :name => "tag", :unique => true

0 comments on commit c093431

Please sign in to comment.