1
0
Fork 0

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 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);
});

Datei anzeigen

@ -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]