2018-12-06 16:36:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class TagsController < BaseController
|
2024-07-29 15:49:44 +00:00
|
|
|
before_action :set_tag, except: [:index]
|
|
|
|
|
|
|
|
PER_PAGE = 20
|
|
|
|
|
|
|
|
def index
|
|
|
|
authorize :tag, :index?
|
|
|
|
|
|
|
|
@tags = filtered_tags.page(params[:page]).per(PER_PAGE)
|
|
|
|
end
|
2018-12-06 16:36:11 +00:00
|
|
|
|
2019-08-05 17:54:29 +00:00
|
|
|
def show
|
|
|
|
authorize @tag, :show?
|
2021-11-25 12:07:38 +00:00
|
|
|
|
|
|
|
@time_period = (6.days.ago.to_date...Time.now.utc.to_date)
|
2018-12-06 16:36:11 +00:00
|
|
|
end
|
|
|
|
|
2019-08-05 17:54:29 +00:00
|
|
|
def update
|
|
|
|
authorize @tag, :update?
|
|
|
|
|
|
|
|
if @tag.update(tag_params.merge(reviewed_at: Time.now.utc))
|
2019-08-07 08:01:55 +00:00
|
|
|
redirect_to admin_tag_path(@tag.id), notice: I18n.t('admin.tags.updated_msg')
|
2019-08-05 17:54:29 +00:00
|
|
|
else
|
2022-07-13 13:03:28 +00:00
|
|
|
@time_period = (6.days.ago.to_date...Time.now.utc.to_date)
|
|
|
|
|
2019-08-05 17:54:29 +00:00
|
|
|
render :show
|
|
|
|
end
|
2018-12-06 16:36:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_tag
|
|
|
|
@tag = Tag.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2019-08-05 17:54:29 +00:00
|
|
|
def tag_params
|
2022-07-13 13:03:28 +00:00
|
|
|
params.require(:tag).permit(:name, :display_name, :trendable, :usable, :listable)
|
2018-12-06 16:36:11 +00:00
|
|
|
end
|
2024-07-29 15:49:44 +00:00
|
|
|
|
|
|
|
def filtered_tags
|
|
|
|
TagFilter.new(filter_params.with_defaults(order: 'newest')).results
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_params
|
|
|
|
params.slice(:page, *TagFilter::KEYS).permit(:page, *TagFilter::KEYS)
|
|
|
|
end
|
2018-12-06 16:36:11 +00:00
|
|
|
end
|
|
|
|
end
|