Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-23 01:40:29 +01:00
41 Zeilen
1,2 KiB
Ruby
41 Zeilen
1,2 KiB
Ruby
# frozen_string_literal: true
|
|
class CustomWizard::AdminSubmissionsController < CustomWizard::AdminController
|
|
skip_before_action :preload_json, :check_xhr, only: [:download]
|
|
before_action :find_wizard, except: [:index]
|
|
|
|
def index
|
|
render json: ActiveModel::ArraySerializer.new(
|
|
CustomWizard::Wizard.list(current_user),
|
|
each_serializer: CustomWizard::BasicWizardSerializer
|
|
)
|
|
end
|
|
|
|
def show
|
|
render_json_dump(
|
|
wizard: CustomWizard::BasicWizardSerializer.new(@wizard, root: false),
|
|
submissions: ActiveModel::ArraySerializer.new(
|
|
submission_list.submissions,
|
|
each_serializer: CustomWizard::SubmissionSerializer
|
|
),
|
|
total: submission_list.total
|
|
)
|
|
end
|
|
|
|
def download
|
|
content = ActiveModel::ArraySerializer.new(
|
|
submission_list.submissions,
|
|
each_serializer: CustomWizard::SubmissionSerializer
|
|
)
|
|
|
|
send_data content.to_json,
|
|
filename: "#{Discourse.current_hostname}-wizard-submissions-#{@wizard.name}.json",
|
|
content_type: "application/json",
|
|
disposition: "attachment"
|
|
end
|
|
|
|
protected
|
|
|
|
def submission_list
|
|
CustomWizard::Submission.list(@wizard, page: params[:page].to_i)
|
|
end
|
|
end
|