2021-10-13 05:11:55 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::TopicsController < Admin::ApplicationController
|
|
|
|
include SendFileUpload
|
|
|
|
include PreviewMarkdown
|
|
|
|
|
2022-06-28 02:09:30 -04:00
|
|
|
before_action :topic, only: [:edit, :update, :destroy]
|
2021-10-13 05:11:55 -04:00
|
|
|
|
|
|
|
feature_category :projects
|
|
|
|
|
|
|
|
def index
|
|
|
|
@topics = Projects::TopicsFinder.new(params: params.permit(:search)).execute.page(params[:page]).without_count
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@topic = Projects::Topic.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@topic = Projects::Topic.new(topic_params)
|
|
|
|
|
|
|
|
if @topic.save
|
|
|
|
redirect_to edit_admin_topic_path(@topic), notice: _('Topic %{topic_name} was successfully created.') % { topic_name: @topic.name }
|
|
|
|
else
|
|
|
|
render "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @topic.update(topic_params)
|
|
|
|
redirect_to edit_admin_topic_path(@topic), notice: _('Topic was successfully updated.')
|
|
|
|
else
|
|
|
|
render "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-28 02:09:30 -04:00
|
|
|
def destroy
|
|
|
|
@topic.destroy!
|
|
|
|
|
|
|
|
redirect_to admin_topics_path,
|
|
|
|
status: :found,
|
|
|
|
notice: _('Topic %{topic_name} was successfully removed.') % { topic_name: @topic.title_or_name }
|
|
|
|
end
|
|
|
|
|
2022-08-11 17:09:14 -04:00
|
|
|
def merge
|
|
|
|
source_topic = Projects::Topic.find(merge_params[:source_topic_id])
|
|
|
|
target_topic = Projects::Topic.find(merge_params[:target_topic_id])
|
|
|
|
|
2022-09-06 02:10:18 -04:00
|
|
|
response = ::Topics::MergeService.new(source_topic, target_topic).execute
|
|
|
|
return render status: :bad_request, json: { type: :alert, message: response.message } if response.error?
|
2022-08-11 17:09:14 -04:00
|
|
|
|
|
|
|
message = _('Topic %{source_topic} was successfully merged into topic %{target_topic}.')
|
2022-08-19 08:11:34 -04:00
|
|
|
flash[:toast] = message % { source_topic: source_topic.name, target_topic: target_topic.name }
|
|
|
|
redirect_to admin_topics_path, status: :found
|
2022-08-11 17:09:14 -04:00
|
|
|
end
|
|
|
|
|
2021-10-13 05:11:55 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def topic
|
|
|
|
@topic ||= Projects::Topic.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def topic_params
|
|
|
|
params.require(:projects_topic).permit(allowed_topic_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_topic_params
|
|
|
|
[
|
|
|
|
:avatar,
|
|
|
|
:description,
|
2022-04-21 14:10:22 -04:00
|
|
|
:name,
|
|
|
|
:title
|
2021-10-13 05:11:55 -04:00
|
|
|
]
|
|
|
|
end
|
2022-08-11 17:09:14 -04:00
|
|
|
|
|
|
|
def merge_params
|
|
|
|
params.permit([:source_topic_id, :target_topic_id])
|
|
|
|
end
|
2021-10-13 05:11:55 -04:00
|
|
|
end
|