Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 20:02:54 +01:00
IMPROVE: Add additional data to submission serialiser
Dieser Commit ist enthalten in:
Ursprung
543b676f53
Commit
55b92f4256
2 geänderte Dateien mit 28 neuen und 6 gelöschten Zeilen
|
@ -32,7 +32,8 @@ class CustomWizard::Wizard
|
|||
:actions,
|
||||
:action_ids,
|
||||
:user,
|
||||
:submissions
|
||||
:submissions,
|
||||
:template
|
||||
|
||||
attr_reader :all_step_ids
|
||||
|
||||
|
@ -79,6 +80,7 @@ class CustomWizard::Wizard
|
|||
|
||||
@actions = attrs['actions'] || []
|
||||
@action_ids = @actions.map { |a| a['id'] }
|
||||
@template = attrs
|
||||
end
|
||||
|
||||
def cast_bool(val)
|
||||
|
|
|
@ -1,13 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
class CustomWizard::SubmissionSerializer < ApplicationSerializer
|
||||
attributes :id,
|
||||
:username,
|
||||
:user,
|
||||
:fields,
|
||||
:submitted_at
|
||||
|
||||
def username
|
||||
object.user.present? ?
|
||||
object.user.username :
|
||||
I18n.t('admin.wizard.submission.no_user', user_id: object.user_id)
|
||||
has_one :user, serializer: ::BasicUserSerializer, embed: :objects
|
||||
|
||||
def include_user?
|
||||
object.user.present?
|
||||
end
|
||||
|
||||
def fields
|
||||
@fields ||= begin
|
||||
result = {}
|
||||
|
||||
object.wizard.template['steps'].each do |step|
|
||||
step['fields'].each do |field|
|
||||
if value = object.fields[field['id']]
|
||||
result[field['id']] = {
|
||||
value: value,
|
||||
type: field['type'],
|
||||
label: field['label']
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Laden …
In neuem Issue referenzieren