0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-14 22:02:53 +01:00
discourse-custom-wizard/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6

68 Zeilen
1,9 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";
2021-11-01 14:52:29 +01:00
import { isPresent } from "@ember/utils";
2021-09-24 11:58:42 +02:00
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-11-17 13:48:11 +01:00
api.modifyClass("route:admin-dashboard", {
2021-11-01 14:52:29 +01:00
setupController(controller) {
this._super(...arguments);
controller.loadCriticalNotices();
controller.subscribe();
2021-11-17 13:48:11 +01:00
},
2021-11-01 14:52:29 +01:00
});
2021-11-17 13:48:11 +01:00
api.modifyClass("controller:admin-dashboard", {
2021-11-01 14:52:29 +01:00
criticalNotices: A(),
unsubscribe() {
this.messageBus.unsubscribe("/custom-wizard/notices");
},
subscribe() {
this.unsubscribe();
this.messageBus.subscribe("/custom-wizard/notices", (data) => {
if (isPresent(data.active_notice_count)) {
this.loadCriticalNotices();
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-11-01 14:52:29 +01:00
loadCriticalNotices() {
CustomWizardNotice.list({
2021-11-17 13:48:11 +01:00
type: ["connection_error", "warning"],
archetype: "plugin_status",
visible: true,
}).then((result) => {
2021-11-01 14:52:29 +01:00
if (result.notices && result.notices.length) {
2021-11-17 13:48:11 +01:00
const criticalNotices = A(
result.notices.map((n) => CustomWizardNotice.create(n))
);
this.set("customWizardCriticalNotices", criticalNotices);
2021-09-24 11:58:42 +02:00
}
2021-11-01 14:52:29 +01:00
});
2021-11-17 13:48:11 +01:00
},
2021-09-24 11:58:42 +02:00
});
});
},
2017-11-22 10:34:21 +01:00
};