0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6
angusmcleod 084c6f4a7a wip
2021-09-24 17:58:42 +08:00

48 Zeilen
1,4 KiB
JavaScript

import DiscourseURL from "discourse/lib/url";
import { withPluginApi } from "discourse/lib/plugin-api";
import { ajax } from "discourse/lib/ajax";
import CustomWizardNotice from "../models/custom-wizard-notice";
import { A } from "@ember/array";
export default {
name: "custom-wizard-edits",
initialize(container) {
const siteSettings = container.lookup("site-settings:main");
if (!siteSettings.custom_wizard_enabled) {
return;
}
const existing = DiscourseURL.routeTo;
DiscourseURL.routeTo = function (path, opts) {
if (path && path.indexOf("/w/") > -1) {
return (window.location = path);
}
return existing.apply(this, [path, opts]);
};
withPluginApi("0.8.36", (api) => {
api.modifyClass('route:admin-dashboard', {
afterModel() {
return CustomWizardNotice.list().then(result => {
if (result && result.length) {
this.set('notices', A(result.map(n => CustomWizardNotice.create(n))));
}
});
},
setupController(controller, model) {
if (this.notices) {
let warningNotices = this.notices.filter(n => n.type === 'warning');
if (warningNotices.length) {
controller.set('wizardWarningNotice', warningNotices[0]);
}
}
this._super(...arguments);
}
});
});
},
};