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

46 Zeilen
1,3 KiB
Ruby

2021-03-11 17:30:15 +11:00
# frozen_string_literal: true
2020-04-13 22:17:22 +10:00
class CustomWizard::AdminSubmissionsController < CustomWizard::AdminController
2020-04-15 10:46:44 +10:00
skip_before_action :preload_json, :check_xhr, only: [:download]
2020-11-03 11:24:20 +11:00
before_action :find_wizard, except: [:index]
2024-10-16 14:18:23 +02:00
requires_plugin "discourse-custom-wizard"
2021-03-11 17:30:15 +11:00
2020-04-13 22:17:22 +10: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 22:17:22 +10:00
end
2021-03-11 17:30:15 +11:00
2020-04-13 22:17:22 +10:00
def show
2020-11-03 11:24:20 +11: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 11:24:20 +11:00
)
2020-04-13 22:17:22 +10:00
end
2021-03-11 17:30:15 +11: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 22:17:22 +10:00
end
2021-06-23 16:15:17 +10:00
protected
2021-03-11 17:30:15 +11:00
2021-07-14 14:04:19 +08:00
def submission_list
CustomWizard::Submission.list(@wizard, page: params[:page].to_i)
2020-04-13 22:17:22 +10:00
end
2021-03-11 17:30:15 +11:00
end