0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-29 12:20:27 +01:00
discourse-custom-wizard/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6

59 Zeilen
1,7 KiB
Text

import DiscourseURL from "discourse/lib/url";
2021-09-24 11:58:42 +02:00
import { withPluginApi } from "discourse/lib/plugin-api";
import CustomWizardNotice from "../models/custom-wizard-notice";
import { A } from "@ember/array";
2017-11-22 10:34:21 +01:00
export default {
name: "custom-wizard-edits",
initialize(container) {
const siteSettings = container.lookup("site-settings:main");
2021-04-12 08:12:20 +02:00
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]);
};
2021-09-24 11:58:42 +02:00
withPluginApi("0.8.36", (api) => {
2021-10-19 14:49:06 +02:00
api.modifyClass("route:admin-dashboard", {
2021-09-24 11:58:42 +02:00
afterModel() {
2021-10-19 14:49:06 +02:00
return CustomWizardNotice.list().then((result) => {
2021-09-24 11:58:42 +02:00
if (result && result.length) {
2021-10-19 14:49:06 +02:00
this.set(
"notices",
A(result.map((n) => CustomWizardNotice.create(n)))
);
2021-09-24 11:58:42 +02:00
}
2021-10-19 14:49:06 +02:00
});
2021-09-24 11:58:42 +02:00
},
2021-10-05 14:54:06 +02:00
setupController(controller) {
2021-09-24 11:58:42 +02:00
if (this.notices) {
2021-10-19 14:49:06 +02:00
let pluginStatusConnectionError = this.notices.filter(
(n) => n.type === "plugin_status_connection_error"
)[0];
let pluginStatusWarning = this.notices.filter(
(n) => n.type === "plugin_status_warning"
)[0];
2021-09-24 11:58:42 +02:00
2021-10-05 14:54:06 +02:00
if (pluginStatusConnectionError || pluginStatusWarning) {
2021-10-19 14:49:06 +02:00
controller.set(
"customWizardImportantNotice",
pluginStatusConnectionError || pluginStatusWarning
);
2021-09-24 11:58:42 +02:00
}
}
this._super(...arguments);
2021-10-19 14:49:06 +02:00
},
2021-09-24 11:58:42 +02:00
});
});
},
2017-11-22 10:34:21 +01:00
};