discourse/app/assets/javascripts/admin/routes/admin-backups.js.es6

136 lines
4.1 KiB
Plaintext
Raw Normal View History

import showModal from 'discourse/lib/show-modal';
import BackupStatus from 'admin/models/backup-status';
import Backup from 'admin/models/backup';
const LOG_CHANNEL = "/admin/backups/logs";
2014-02-13 12:35:46 +08:00
export default Discourse.Route.extend({
2014-02-13 12:35:46 +08:00
activate() {
this.messageBus.subscribe(LOG_CHANNEL, this._processLogMessage.bind(this));
2014-02-13 12:35:46 +08:00
},
_processLogMessage(log) {
2014-02-13 12:35:46 +08:00
if (log.message === "[STARTED]") {
this.controllerFor("adminBackups").set("model.isOperationRunning", true);
2014-02-13 12:35:46 +08:00
this.controllerFor("adminBackupsLogs").clear();
} else if (log.message === "[FAILED]") {
this.controllerFor("adminBackups").set("model.isOperationRunning", false);
2014-02-13 12:35:46 +08:00
bootbox.alert(I18n.t("admin.backups.operations.failed", { operation: log.operation }));
} else if (log.message === "[SUCCESS]") {
Discourse.User.currentProp("hideReadOnlyAlert", false);
this.controllerFor("adminBackups").set("model.isOperationRunning", false);
2014-02-13 12:35:46 +08:00
if (log.operation === "restore") {
// redirect to homepage when the restore is done (session might be lost)
window.location.pathname = Discourse.getURL("/");
}
} else {
this.controllerFor("adminBackupsLogs").pushObject(Em.Object.create(log));
}
},
model() {
2014-02-13 12:35:46 +08:00
return PreloadStore.getAndRemove("operations_status", function() {
return Discourse.ajax("/admin/backups/status.json");
}).then(status => {
return BackupStatus.create({
2014-02-13 12:35:46 +08:00
isOperationRunning: status.is_operation_running,
canRollback: status.can_rollback,
allowRestore: status.allow_restore
2014-02-13 12:35:46 +08:00
});
});
},
deactivate() {
this.messageBus.unsubscribe(LOG_CHANNEL);
2014-02-13 12:35:46 +08:00
},
actions: {
startBackup() {
2015-03-14 19:46:46 +08:00
showModal('modals/admin-start-backup');
2014-08-21 00:48:56 +08:00
this.controllerFor('modal').set('modalClass', 'start-backup-modal');
},
backupStarted() {
2015-08-14 18:40:18 +08:00
this.controllerFor("adminBackups").set("isOperationRunning", true);
2014-08-21 00:48:56 +08:00
this.transitionTo("admin.backups.logs");
this.send("closeModal");
2014-02-13 12:35:46 +08:00
},
destroyBackup(backup) {
const self = this;
2014-02-13 12:35:46 +08:00
bootbox.confirm(
I18n.t("admin.backups.operations.destroy.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) {
backup.destroy().then(function() {
self.controllerFor("adminBackupsIndex").removeObject(backup);
});
}
}
);
},
startRestore(backup) {
const self = this;
2014-02-13 12:35:46 +08:00
bootbox.confirm(
I18n.t("admin.backups.operations.restore.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) {
Discourse.User.currentProp("hideReadOnlyAlert", true);
2014-02-13 12:35:46 +08:00
backup.restore().then(function() {
self.controllerFor("adminBackupsLogs").clear();
2015-08-14 18:40:18 +08:00
self.controllerFor("adminBackups").set("model.isOperationRunning", true);
2014-02-13 12:35:46 +08:00
self.transitionTo("admin.backups.logs");
});
}
}
);
},
cancelOperation() {
const self = this;
2014-02-13 12:35:46 +08:00
bootbox.confirm(
I18n.t("admin.backups.operations.cancel.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) {
Backup.cancel().then(function() {
self.controllerFor("adminBackups").set("model.isOperationRunning", false);
2014-02-13 12:35:46 +08:00
});
}
}
);
},
rollback() {
2014-02-13 12:35:46 +08:00
bootbox.confirm(
I18n.t("admin.backups.operations.rollback.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) { Backup.rollback(); }
2014-02-13 12:35:46 +08:00
}
);
},
2014-02-22 08:41:01 +08:00
uploadSuccess(filename) {
const self = this;
2014-02-22 08:41:01 +08:00
bootbox.alert(I18n.t("admin.backups.upload.success", { filename: filename }), function() {
Backup.find().then(function (backups) {
2014-02-22 08:41:01 +08:00
self.controllerFor("adminBackupsIndex").set("model", backups);
});
});
},
uploadError(filename, message) {
2014-02-22 08:41:01 +08:00
bootbox.alert(I18n.t("admin.backups.upload.error", { filename: filename, message: message }));
}
2014-02-13 12:35:46 +08:00
}
});