discourse/app/assets/javascripts/admin/routes/admin_backups_route.js

158 lines
4.6 KiB
JavaScript
Raw Normal View History

2014-02-12 23:35:46 -05:00
Discourse.AdminBackupsRoute = Discourse.Route.extend({
LOG_CHANNEL: "/admin/backups/logs",
activate: function() {
Discourse.MessageBus.subscribe(this.LOG_CHANNEL, this._processLogMessage.bind(this));
},
_processLogMessage: function(log) {
if (log.message === "[STARTED]") {
this.controllerFor("adminBackups").set("isOperationRunning", true);
this.controllerFor("adminBackupsLogs").clear();
} else if (log.message === "[FAILED]") {
this.controllerFor("adminBackups").set("isOperationRunning", false);
bootbox.alert(I18n.t("admin.backups.operations.failed", { operation: log.operation }));
} else if (log.message === "[SUCCESS]") {
Discourse.User.currentProp("hideReadOnlyAlert", false);
2014-02-12 23:35:46 -05:00
this.controllerFor("adminBackups").set("isOperationRunning", false);
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: function() {
return PreloadStore.getAndRemove("operations_status", function() {
return Discourse.ajax("/admin/backups/status.json");
}).then(function (status) {
2014-02-21 19:41:01 -05:00
return Discourse.BackupStatus.create({
2014-02-12 23:35:46 -05:00
isOperationRunning: status.is_operation_running,
canRollback: status.can_rollback
2014-02-12 23:35:46 -05:00
});
});
},
deactivate: function() {
Discourse.MessageBus.unsubscribe(this.LOG_CHANNEL);
},
actions: {
/**
Starts a backup and redirect the user to the logs tab
@method startBackup
**/
startBackup: function() {
2014-08-20 12:48:56 -04:00
Discourse.Route.showModal(this, 'admin_start_backup');
this.controllerFor('modal').set('modalClass', 'start-backup-modal');
},
backupStarted: function () {
this.modelFor("adminBackups").set("isOperationRunning", true);
this.transitionTo("admin.backups.logs");
this.send("closeModal");
2014-02-12 23:35:46 -05:00
},
/**
Destroys a backup
@method destroyBackup
2014-03-18 21:19:20 -04:00
@param {Discourse.Backup} backup the backup to destroy
2014-02-12 23:35:46 -05:00
**/
destroyBackup: function(backup) {
var self = this;
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);
});
}
}
);
},
/**
Start a restore and redirect the user to the logs tab
@method startRestore
2014-03-18 21:19:20 -04:00
@param {Discourse.Backup} backup the backup to restore
2014-02-12 23:35:46 -05:00
**/
startRestore: function(backup) {
var self = this;
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-12 23:35:46 -05:00
backup.restore().then(function() {
self.controllerFor("adminBackupsLogs").clear();
2014-02-21 19:41:01 -05:00
self.modelFor("adminBackups").set("isOperationRunning", true);
2014-02-12 23:35:46 -05:00
self.transitionTo("admin.backups.logs");
});
}
}
);
},
/**
Cancels the current operation
@method cancelOperation
**/
cancelOperation: function() {
var self = this;
bootbox.confirm(
I18n.t("admin.backups.operations.cancel.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) {
Discourse.Backup.cancel().then(function() {
self.controllerFor("adminBackups").set("isOperationRunning", false);
});
}
}
);
},
/**
Rollback to previous working state
@method rollback
**/
rollback: function() {
bootbox.confirm(
I18n.t("admin.backups.operations.rollback.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) { Discourse.Backup.rollback(); }
}
);
},
2014-02-21 19:41:01 -05:00
uploadSuccess: function(filename) {
var self = this;
bootbox.alert(I18n.t("admin.backups.upload.success", { filename: filename }), function() {
Discourse.Backup.find().then(function (backups) {
self.controllerFor("adminBackupsIndex").set("model", backups);
});
});
},
uploadError: function(filename, message) {
bootbox.alert(I18n.t("admin.backups.upload.error", { filename: filename, message: message }));
}
2014-02-12 23:35:46 -05:00
}
});