2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::TopicsController < Admin::ApplicationController
|
|
|
|
include SendFileUpload
|
|
|
|
include PreviewMarkdown
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
before_action :topic, only: [:edit, :update, :destroy]
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
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
|
2023-03-17 16:20:25 +05:30
|
|
|
redirect_to edit_admin_topic_path(@topic), notice: format(_('Topic %{topic_name} was successfully created.'), topic_name: @topic.name)
|
2021-11-18 22:05:49 +05:30
|
|
|
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-08-13 15:12:31 +05:30
|
|
|
def destroy
|
|
|
|
@topic.destroy!
|
|
|
|
|
|
|
|
redirect_to admin_topics_path,
|
2023-05-27 22:25:52 +05:30
|
|
|
status: :found,
|
|
|
|
notice: format(_('Topic %{topic_name} was successfully removed.'), topic_name: @topic.title_or_name)
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
def merge
|
|
|
|
source_topic = Projects::Topic.find(merge_params[:source_topic_id])
|
|
|
|
target_topic = Projects::Topic.find(merge_params[:target_topic_id])
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
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-27 11:52:29 +05:30
|
|
|
|
|
|
|
message = _('Topic %{source_topic} was successfully merged into topic %{target_topic}.')
|
2023-03-17 16:20:25 +05:30
|
|
|
flash[:toast] = format(message, source_topic: source_topic.name, target_topic: target_topic.name)
|
2022-10-11 01:57:18 +05:30
|
|
|
redirect_to admin_topics_path, status: :found
|
2022-08-27 11:52:29 +05:30
|
|
|
end
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
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-07-16 23:28:13 +05:30
|
|
|
:name,
|
|
|
|
:title
|
2021-11-18 22:05:49 +05:30
|
|
|
]
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
def merge_params
|
|
|
|
params.permit([:source_topic_id, :target_topic_id])
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|