diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index e8427334..e52feec4 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -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) diff --git a/serializers/custom_wizard/submission_serializer.rb b/serializers/custom_wizard/submission_serializer.rb index 992deacb..f9cc7230 100644 --- a/serializers/custom_wizard/submission_serializer.rb +++ b/serializers/custom_wizard/submission_serializer.rb @@ -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