0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

Remove meta keys from fields attribute and update submissions ui to handle new submission structure

Dieser Commit ist enthalten in:
angusmcleod 2021-07-12 15:53:58 +08:00
Ursprung 20c8ec1202
Commit 56f58414b3
2 geänderte Dateien mit 21 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -1,17 +1,25 @@
import CustomWizard from "../models/custom-wizard"; import CustomWizard from "../models/custom-wizard";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
const excludedMetaFields = [
'route_to',
'redirect_on_complete',
'redirect_to'
];
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
model(params) { model(params) {
return CustomWizard.submissions(params.wizardId); return CustomWizard.submissions(params.wizardId);
}, },
setupController(controller, model) { setupController(controller, model) {
if (model.submissions) { if (model && model.submissions) {
let fields = []; let fields = [
'username'
];
model.submissions.forEach((s) => { model.submissions.forEach((s) => {
Object.keys(s).forEach((k) => { Object.keys(s.fields).forEach((k) => {
if (fields.indexOf(k) < 0) { if (!excludedMetaFields.includes(k) && fields.indexOf(k) < 0) {
fields.push(k); fields.push(k);
} }
}); });
@ -19,9 +27,13 @@ export default DiscourseRoute.extend({
let submissions = []; let submissions = [];
model.submissions.forEach((s) => { model.submissions.forEach((s) => {
let submission = {}; let submission = {
fields.forEach((f) => { username: s.username
submission[f] = s[f]; };
Object.keys(s.fields).forEach((f) => {
if (fields.includes(f)) {
submission[f] = s.fields[f];
}
}); });
submissions.push(submission); submissions.push(submission);
}); });

Datei anzeigen

@ -29,7 +29,8 @@ class CustomWizard::Submission
data = (data || {}).with_indifferent_access data = (data || {}).with_indifferent_access
@id = data['id'] || SecureRandom.hex(12) @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| META.each do |attr|
send("#{attr}=", data[attr]) if data[attr] send("#{attr}=", data[attr]) if data[attr]