From 56f58414b3e24f398a525824760e8934c9a102b3 Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Mon, 12 Jul 2021 15:53:58 +0800 Subject: [PATCH] Remove meta keys from fields attribute and update submissions ui to handle new submission structure --- .../admin-wizards-submissions-show.js.es6 | 26 ++++++++++++++----- lib/custom_wizard/submission.rb | 3 ++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 index abcaeb9e..7d8e2cf5 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 @@ -1,17 +1,25 @@ import CustomWizard from "../models/custom-wizard"; import DiscourseRoute from "discourse/routes/discourse"; +const excludedMetaFields = [ + 'route_to', + 'redirect_on_complete', + 'redirect_to' +]; + export default DiscourseRoute.extend({ model(params) { return CustomWizard.submissions(params.wizardId); }, setupController(controller, model) { - if (model.submissions) { - let fields = []; + if (model && model.submissions) { + let fields = [ + 'username' + ]; model.submissions.forEach((s) => { - Object.keys(s).forEach((k) => { - if (fields.indexOf(k) < 0) { + Object.keys(s.fields).forEach((k) => { + if (!excludedMetaFields.includes(k) && fields.indexOf(k) < 0) { fields.push(k); } }); @@ -19,9 +27,13 @@ export default DiscourseRoute.extend({ let submissions = []; model.submissions.forEach((s) => { - let submission = {}; - fields.forEach((f) => { - submission[f] = s[f]; + let submission = { + username: s.username + }; + Object.keys(s.fields).forEach((f) => { + if (fields.includes(f)) { + submission[f] = s.fields[f]; + } }); submissions.push(submission); }); diff --git a/lib/custom_wizard/submission.rb b/lib/custom_wizard/submission.rb index a1f93d82..e50cb259 100644 --- a/lib/custom_wizard/submission.rb +++ b/lib/custom_wizard/submission.rb @@ -29,7 +29,8 @@ class CustomWizard::Submission data = (data || {}).with_indifferent_access @id = data['id'] || SecureRandom.hex(12) - @fields = data.except(META + ['id']) || {} + non_field_keys = META + ['id'] + @fields = data.except(*non_field_keys) || {} META.each do |attr| send("#{attr}=", data[attr]) if data[attr]