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

37 Zeilen
1 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
2021-07-14 08:04:19 +02:00
send_data submission_list.submissions.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