0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-24 10:20:28 +01:00
discourse-custom-wizard/app/controllers/custom_wizard/admin/submissions.rb

46 Zeilen
1,3 KiB
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
2020-04-13 14:17:22 +02:00
class CustomWizard::AdminSubmissionsController < CustomWizard::AdminController
2020-04-15 02:46:44 +02:00
skip_before_action :preload_json, :check_xhr, only: [:download]
2020-11-03 01:24:20 +01:00
before_action :find_wizard, except: [:index]
2024-10-16 14:18:23 +02:00
requires_plugin "discourse-custom-wizard"
2021-03-11 07:30:15 +01:00
2020-04-13 14:17:22 +02:00
def index
2024-10-16 13:52:03 +02:00
render json:
ActiveModel::ArraySerializer.new(
CustomWizard::Wizard.list(current_user),
each_serializer: CustomWizard::BasicWizardSerializer,
)
2020-04-13 14:17:22 +02:00
end
2021-03-11 07:30:15 +01:00
2020-04-13 14:17:22 +02:00
def show
2020-11-03 01:24:20 +01:00
render_json_dump(
wizard: CustomWizard::BasicWizardSerializer.new(@wizard, root: false),
2024-10-16 13:52:03 +02:00
submissions:
ActiveModel::ArraySerializer.new(
submission_list.submissions,
each_serializer: CustomWizard::SubmissionSerializer,
),
total: submission_list.total,
2020-11-03 01:24:20 +01:00
)
2020-04-13 14:17:22 +02:00
end
2021-03-11 07:30:15 +01:00
def download
2024-10-16 13:52:03 +02:00
content =
ActiveModel::ArraySerializer.new(
CustomWizard::Submission.list(@wizard).submissions,
each_serializer: CustomWizard::SubmissionSerializer,
)
send_data content.to_json,
2024-10-16 13:52:03 +02:00
filename: "#{Discourse.current_hostname}-wizard-submissions-#{@wizard.name}.json",
content_type: "application/json",
disposition: "attachment"
2020-04-13 14:17:22 +02:00
end
2021-06-23 08:15:17 +02:00
protected
2021-03-11 07:30:15 +01:00
2021-07-14 08:04:19 +02:00
def submission_list
CustomWizard::Submission.list(@wizard, page: params[:page].to_i)
2020-04-13 14:17:22 +02:00
end
2021-03-11 07:30:15 +01:00
end