Revert "DEV: Clean up all message bus subscriptions (#18675)" (#19267)

This reverts commit b0839ccf27.
This commit is contained in:
Jarek Radosz
2022-11-30 17:29:10 +01:00
committed by GitHub
parent 6a389fd15a
commit 49e0fc04f7
21 changed files with 496 additions and 624 deletions

View File

@@ -1,14 +1,14 @@
import Backup from "admin/models/backup";
import Route from "@ember/routing/route";
import { bind } from "discourse-common/utils/decorators";
export default Route.extend({
activate() {
this.messageBus.subscribe("/admin/backups", this.onMessage);
},
deactivate() {
this.messageBus.unsubscribe("/admin/backups", this.onMessage);
this.messageBus.subscribe("/admin/backups", (backups) =>
this.controller.set(
"model",
backups.map((backup) => Backup.create(backup))
)
);
},
model() {
@@ -17,11 +17,7 @@ export default Route.extend({
);
},
@bind
onMessage(backups) {
this.controller.set(
"model",
backups.map((backup) => Backup.create(backup))
);
deactivate() {
this.messageBus.unsubscribe("/admin/backups");
},
});

View File

@@ -10,19 +10,46 @@ import { extractError } from "discourse/lib/ajax-error";
import getURL from "discourse-common/lib/get-url";
import showModal from "discourse/lib/show-modal";
import { inject as service } from "@ember/service";
import { bind } from "discourse-common/utils/decorators";
const LOG_CHANNEL = "/admin/backups/logs";
export default DiscourseRoute.extend({
dialog: service(),
activate() {
this.messageBus.subscribe(LOG_CHANNEL, this.onMessage);
},
deactivate() {
this.messageBus.unsubscribe(LOG_CHANNEL, this.onMessage);
this.messageBus.subscribe(LOG_CHANNEL, (log) => {
if (log.message === "[STARTED]") {
User.currentProp("hideReadOnlyAlert", true);
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
true
);
this.controllerFor("adminBackupsLogs").get("logs").clear();
} else if (log.message === "[FAILED]") {
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
false
);
this.dialog.alert(
I18n.t("admin.backups.operations.failed", {
operation: log.operation,
})
);
} else if (log.message === "[SUCCESS]") {
User.currentProp("hideReadOnlyAlert", false);
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
false
);
if (log.operation === "restore") {
// redirect to homepage when the restore is done (session might be lost)
window.location = getURL("/");
}
} else {
this.controllerFor("adminBackupsLogs")
.get("logs")
.pushObject(EmberObject.create(log));
}
});
},
model() {
@@ -37,31 +64,8 @@ export default DiscourseRoute.extend({
);
},
@bind
onMessage(log) {
if (log.message === "[STARTED]") {
User.currentProp("hideReadOnlyAlert", true);
this.controllerFor("adminBackups").set("model.isOperationRunning", true);
this.controllerFor("adminBackupsLogs").get("logs").clear();
} else if (log.message === "[FAILED]") {
this.controllerFor("adminBackups").set("model.isOperationRunning", false);
this.dialog.alert(
I18n.t("admin.backups.operations.failed", {
operation: log.operation,
})
);
} else if (log.message === "[SUCCESS]") {
User.currentProp("hideReadOnlyAlert", false);
this.controllerFor("adminBackups").set("model.isOperationRunning", false);
if (log.operation === "restore") {
// redirect to homepage when the restore is done (session might be lost)
window.location = getURL("/");
}
} else {
this.controllerFor("adminBackupsLogs")
.get("logs")
.pushObject(EmberObject.create(log));
}
deactivate() {
this.messageBus.unsubscribe(LOG_CHANNEL);
},
actions: {