2019-02-03 22:25:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Settings::FeaturedTagsController < Settings::BaseController
|
|
|
|
before_action :set_featured_tags, only: :index
|
|
|
|
before_action :set_featured_tag, except: [:index, :create]
|
2020-09-07 11:47:41 -04:00
|
|
|
before_action :set_recently_used_tags, only: :index
|
2019-02-03 22:25:59 -05:00
|
|
|
|
|
|
|
def index
|
|
|
|
@featured_tag = FeaturedTag.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@featured_tag = current_account.featured_tags.new(featured_tag_params)
|
|
|
|
|
|
|
|
if @featured_tag.save
|
2022-10-20 03:15:52 -04:00
|
|
|
ActivityPub::UpdateDistributionWorker.perform_in(3.minutes, current_account.id)
|
2019-02-03 22:25:59 -05:00
|
|
|
redirect_to settings_featured_tags_path
|
|
|
|
else
|
|
|
|
set_featured_tags
|
2020-09-07 11:47:41 -04:00
|
|
|
set_recently_used_tags
|
2019-02-03 22:25:59 -05:00
|
|
|
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@featured_tag.destroy!
|
2022-10-20 03:15:52 -04:00
|
|
|
ActivityPub::UpdateDistributionWorker.perform_in(3.minutes, current_account.id)
|
2019-02-03 22:25:59 -05:00
|
|
|
redirect_to settings_featured_tags_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_featured_tag
|
|
|
|
@featured_tag = current_account.featured_tags.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_featured_tags
|
2019-02-04 18:27:18 -05:00
|
|
|
@featured_tags = current_account.featured_tags.order(statuses_count: :desc).reject(&:new_record?)
|
2019-02-03 22:25:59 -05:00
|
|
|
end
|
|
|
|
|
2020-09-07 11:47:41 -04:00
|
|
|
def set_recently_used_tags
|
|
|
|
@recently_used_tags = Tag.recently_used(current_account).where.not(id: @featured_tags.map(&:id)).limit(10)
|
2019-02-03 22:25:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def featured_tag_params
|
|
|
|
params.require(:featured_tag).permit(:name)
|
|
|
|
end
|
|
|
|
end
|