0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-14 13:52:54 +01:00
discourse-custom-wizard/app/controllers/custom_wizard/admin/submissions.rb

42 Zeilen
1,2 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]
2021-03-11 07:30:15 +01:00
2020-04-13 14:17:22 +02:00
def index
render json: ActiveModel::ArraySerializer.new(
2020-11-03 01:24:20 +01:00
CustomWizard::Wizard.list(current_user),
2020-04-13 14:17:22 +02:00
each_serializer: CustomWizard::BasicWizardSerializer
)
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),
2021-07-14 08:04:19 +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
content = ActiveModel::ArraySerializer.new(
2023-09-15 17:15:31 +02:00
CustomWizard::Submission.list(@wizard).submissions,
each_serializer: CustomWizard::SubmissionSerializer
)
send_data content.to_json,
2020-04-15 02:46:44 +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