diff --git a/assets/javascripts/discourse/connectors/admin-menu/wizards-nav-button.hbs b/assets/javascripts/discourse/connectors/admin-menu/wizards-nav-button.hbs index 5424f713..5398e27d 100644 --- a/assets/javascripts/discourse/connectors/admin-menu/wizards-nav-button.hbs +++ b/assets/javascripts/discourse/connectors/admin-menu/wizards-nav-button.hbs @@ -1,3 +1,3 @@ {{#if currentUser.admin}} - {{nav-item route='adminWizards' label='admin.wizard.nav'}} + {{nav-item route='adminWizards' label='admin.wizard.nav_label'}} {{/if}} diff --git a/assets/javascripts/discourse/controllers/admin-wizard-submissions.js.es6 b/assets/javascripts/discourse/controllers/admin-wizard-submissions.js.es6 new file mode 100644 index 00000000..57b0ab57 --- /dev/null +++ b/assets/javascripts/discourse/controllers/admin-wizard-submissions.js.es6 @@ -0,0 +1,6 @@ +import Controller from "@ember/controller"; +import { fmt } from "discourse/lib/computed"; + +export default Controller.extend({ + downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download") +}); \ No newline at end of file diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index 38768eb6..2e1decb4 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -198,8 +198,6 @@ CustomWizard.reopenClass({ submissions(wizardId) { return ajax(`/admin/wizards/submissions/${wizardId}`, { type: "GET" - }).then(result => { - return result.submissions; }); }, diff --git a/assets/javascripts/discourse/routes/admin-wizard-submissions.js.es6 b/assets/javascripts/discourse/routes/admin-wizard-submissions.js.es6 index 95d72ec3..b1f6b226 100644 --- a/assets/javascripts/discourse/routes/admin-wizard-submissions.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizard-submissions.js.es6 @@ -2,29 +2,54 @@ import CustomWizard from '../models/custom-wizard'; import DiscourseRoute from "discourse/routes/discourse"; export default DiscourseRoute.extend({ + beforeModel() { + const param = this.paramsFor('adminWizardSubmissions').wizard_id; + const wizards = this.modelFor('admin-wizards-submissions'); + + if (wizards.length && (param === 'first')) { + const wizard = wizards.get(`${param}Object`); + if (wizard) { + this.transitionTo('adminWizardSubmissions', wizard.id.dasherize()); + } + } + }, + model(params) { - return CustomWizard.submissions(params.wizard_id); + const wizardId = params.wizard_id; + if (wizardId && wizardId !== 'new') { + return CustomWizard.submissions(params.wizard_id); + } else { + return {}; + } }, setupController(controller, model) { - let fields = []; - model.forEach((s) => { - Object.keys(s).forEach((k) => { - if (fields.indexOf(k) < 0) { - fields.push(k); - } + if (model.submissions) { + let fields = []; + model.submissions.forEach((s) => { + Object.keys(s).forEach((k) => { + if (fields.indexOf(k) < 0) { + fields.push(k); + } + }); }); - }); - let submissions = []; - model.forEach((s) => { - let submission = {}; - fields.forEach((f) => { - submission[f] = s[f]; + let submissions = []; + model.submissions.forEach((s) => { + let submission = {}; + fields.forEach((f) => { + submission[f] = s[f]; + }); + submissions.push(submission); }); - submissions.push(submission); - }); + + console.log(model.id) - controller.setProperties({ submissions, fields }); + controller.setProperties({ + wizard: model.wizard, + submissions, + fields + }); + } } }); diff --git a/assets/javascripts/discourse/routes/admin-wizards-custom-index.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions-index.js.es6 similarity index 67% rename from assets/javascripts/discourse/routes/admin-wizards-custom-index.js.es6 rename to assets/javascripts/discourse/routes/admin-wizards-submissions-index.js.es6 index e01f87c6..6bfca635 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-custom-index.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions-index.js.es6 @@ -2,6 +2,6 @@ import DiscourseRoute from "discourse/routes/discourse"; export default DiscourseRoute.extend({ redirect() { - this.transitionTo('adminWizard', 'first'); + this.transitionTo('adminWizardSubmissions', 'first'); } }); diff --git a/assets/javascripts/discourse/templates/admin-wizard-submissions.hbs b/assets/javascripts/discourse/templates/admin-wizard-submissions.hbs index ec8a55ff..1265db8a 100644 --- a/assets/javascripts/discourse/templates/admin-wizard-submissions.hbs +++ b/assets/javascripts/discourse/templates/admin-wizard-submissions.hbs @@ -1,3 +1,14 @@ +