2012-07-04 05:24:18 +02:00
|
|
|
class FiltersController < ApplicationController
|
2013-08-05 09:16:33 +02:00
|
|
|
before_filter :authenticate_user
|
2012-07-04 05:24:18 +02:00
|
|
|
|
|
|
|
def index
|
2012-09-07 16:18:15 +02:00
|
|
|
@cur_url = "/filters"
|
2012-09-20 17:56:54 +02:00
|
|
|
@title = "Filtered Tags"
|
2012-09-07 16:18:15 +02:00
|
|
|
|
2014-01-24 20:53:10 +01:00
|
|
|
@tags = Tag.all_with_story_counts_for(@user)
|
2014-01-09 07:44:03 +01:00
|
|
|
|
2013-08-05 09:16:33 +02:00
|
|
|
if @user
|
2014-01-09 07:44:03 +01:00
|
|
|
@filtered_tags = @user.tag_filter_tags.to_a
|
2013-08-05 09:16:33 +02:00
|
|
|
else
|
2014-01-09 07:44:03 +01:00
|
|
|
@filtered_tags = tags_filtered_by_cookie.to_a
|
2013-08-05 09:16:33 +02:00
|
|
|
end
|
2012-07-04 05:24:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-01-09 07:44:03 +01:00
|
|
|
tags_param = params.permit(:tags => [])[:tags]
|
|
|
|
new_tags = tags_param.blank? ? [] : Tag.where(:tag => tags_param).to_a
|
|
|
|
new_tags.keep_if {|t| t.valid_for? @user }
|
2012-07-04 05:24:18 +02:00
|
|
|
|
2013-08-05 09:16:33 +02:00
|
|
|
if @user
|
2014-01-09 07:44:03 +01:00
|
|
|
@user.tag_filter_tags = new_tags
|
2013-08-05 09:16:33 +02:00
|
|
|
else
|
2014-01-09 07:44:03 +01:00
|
|
|
cookies.permanent[TAG_FILTER_COOKIE] = new_tags.map(&:tag).join(",")
|
2012-07-04 05:24:18 +02:00
|
|
|
end
|
|
|
|
|
2013-08-05 09:16:33 +02:00
|
|
|
flash[:success] = "Your filters have been updated."
|
2014-01-09 07:44:03 +01:00
|
|
|
|
|
|
|
redirect_to filters_path
|
2012-07-04 05:24:18 +02:00
|
|
|
end
|
|
|
|
end
|