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

33 Zeilen
988 B
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),
submissions: ActiveModel::ArraySerializer.new(ordered_submissions, each_serializer: CustomWizard::SubmissionSerializer)
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
send_data ordered_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
def ordered_submissions
CustomWizard::Submission.list(@wizard, order_by: 'id')
2020-04-13 14:17:22 +02:00
end
2021-03-11 07:30:15 +01:00
end