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

This commit is contained in:
joshua stein 2012-09-06 13:44:42 -05:00
parent d986952870
commit c093431898
5 changed files with 35 additions and 7 deletions

View file

@ -116,6 +116,11 @@ private
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 file

@ -25,6 +25,7 @@ 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?
@ -32,6 +33,15 @@ class User < ActiveRecord::Base
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

View file

@ -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>

View file

@ -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 file

@ -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 @@ ActiveRecord::Schema.define(:version => 20120902143549) do
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