2021-03-28 11:06:49 +02:00
|
|
|
import CustomWizard from "../models/custom-wizard";
|
2020-03-21 18:30:11 +01:00
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
2017-10-22 05:37:58 +02:00
|
|
|
|
2021-07-12 10:01:52 +02:00
|
|
|
const excludedMetaFields = ["route_to", "redirect_on_complete", "redirect_to"];
|
2021-07-12 09:53:58 +02:00
|
|
|
|
2020-03-21 18:30:11 +01:00
|
|
|
export default DiscourseRoute.extend({
|
2017-10-05 02:36:46 +02:00
|
|
|
model(params) {
|
2020-04-13 14:17:22 +02:00
|
|
|
return CustomWizard.submissions(params.wizardId);
|
2017-10-05 02:36:46 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
2021-07-12 09:53:58 +02:00
|
|
|
if (model && model.submissions) {
|
2021-07-12 10:01:52 +02:00
|
|
|
let fields = ["username"];
|
2020-04-12 01:27:16 +02:00
|
|
|
model.submissions.forEach((s) => {
|
2021-07-12 09:53:58 +02:00
|
|
|
Object.keys(s.fields).forEach((k) => {
|
|
|
|
if (!excludedMetaFields.includes(k) && fields.indexOf(k) < 0) {
|
2020-04-12 01:27:16 +02:00
|
|
|
fields.push(k);
|
|
|
|
}
|
|
|
|
});
|
2017-11-01 10:50:03 +01:00
|
|
|
});
|
2017-10-30 07:24:51 +01:00
|
|
|
|
2020-04-12 01:27:16 +02:00
|
|
|
let submissions = [];
|
|
|
|
model.submissions.forEach((s) => {
|
2021-07-12 09:53:58 +02:00
|
|
|
let submission = {
|
2021-07-12 10:01:52 +02:00
|
|
|
username: s.username,
|
2021-07-12 09:53:58 +02:00
|
|
|
};
|
|
|
|
Object.keys(s.fields).forEach((f) => {
|
|
|
|
if (fields.includes(f)) {
|
|
|
|
submission[f] = s.fields[f];
|
|
|
|
}
|
2020-04-12 01:27:16 +02:00
|
|
|
});
|
|
|
|
submissions.push(submission);
|
2017-11-01 10:50:03 +01:00
|
|
|
});
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-12 01:27:16 +02:00
|
|
|
controller.setProperties({
|
|
|
|
wizard: model.wizard,
|
|
|
|
submissions,
|
2021-03-28 11:06:49 +02:00
|
|
|
fields,
|
2020-04-12 01:27:16 +02:00
|
|
|
});
|
|
|
|
}
|
2021-03-28 11:06:49 +02:00
|
|
|
},
|
2017-10-05 02:36:46 +02:00
|
|
|
});
|