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"
|
2016-11-15 17:34:00 +01:00
|
|
|
@title = I18n.t 'controllers.filters_controller.filterstitle'
|
2012-09-07 16:18:15 +02:00
|
|
|
|
2014-02-21 17:51:48 +01:00
|
|
|
@tags = Tag.active.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-02-05 23:02:12 +01:00
|
|
|
tags_param = params[:tags]
|
2014-02-21 17:51:48 +01:00
|
|
|
new_tags = tags_param.blank? ? [] :
|
|
|
|
Tag.active.where(:tag => tags_param).to_a
|
2014-01-09 07:44:03 +01:00
|
|
|
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
|
|
|
|
|
2016-11-23 17:39:59 +01:00
|
|
|
flash[:success] = I18n.t 'controllers.filters_controller.flashfilterupdate'
|
2014-01-09 07:44:03 +01:00
|
|
|
|
|
|
|
redirect_to filters_path
|
2012-07-04 05:24:18 +02:00
|
|
|
end
|
|
|
|
end
|