discourse/app/assets/javascripts/admin/addon/controllers/admin-backups-index.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.8 KiB
JavaScript
Raw Normal View History

import Controller, { inject as controller } from "@ember/controller";
import { action } from "@ember/object";
import { alias, equal } from "@ember/object/computed";
import { service } from "@ember/service";
2016-07-01 01:55:44 +08:00
import { ajax } from "discourse/lib/ajax";
import { i18n, setting } from "discourse/lib/computed";
import discourseComputed from "discourse-common/utils/decorators";
import I18n from "discourse-i18n";
export default class AdminBackupsIndexController extends Controller {
@service dialog;
@controller adminBackups;
@alias("adminBackups.model") status;
@i18n("admin.backups.upload.label") uploadLabel;
@setting("backup_location") backupLocation;
@equal("backupLocation", "local") localBackupStorage;
2014-02-13 12:35:46 +08:00
@discourseComputed("status.allowRestore", "status.isOperationRunning")
restoreTitle(allowRestore, isOperationRunning) {
if (!allowRestore) {
2015-03-27 01:05:27 +08:00
return "admin.backups.operations.restore.is_disabled";
} else if (isOperationRunning) {
2015-03-27 01:05:27 +08:00
return "admin.backups.operations.is_running";
2014-02-13 12:35:46 +08:00
} else {
2015-03-27 01:05:27 +08:00
return "admin.backups.operations.restore.title";
2014-02-13 12:35:46 +08:00
}
}
2014-02-13 12:35:46 +08:00
@action
toggleReadOnlyMode() {
if (!this.site.get("isReadOnly")) {
this.dialog.yesNoConfirm({
message: I18n.t("admin.backups.read_only.enable.confirm"),
didConfirm: () => {
this.set("currentUser.hideReadOnlyAlert", true);
this._toggleReadOnlyMode(true);
},
});
} else {
this._toggleReadOnlyMode(false);
}
}
2014-02-13 12:35:46 +08:00
@action
download(backup) {
const link = backup.get("filename");
ajax(`/admin/backups/${link}`, { type: "PUT" }).then(() =>
this.dialog.alert(I18n.t("admin.backups.operations.download.alert"))
);
}
2014-02-13 12:35:46 +08:00
2015-03-27 01:05:27 +08:00
_toggleReadOnlyMode(enable) {
2016-07-01 01:55:44 +08:00
ajax("/admin/backups/readonly", {
2014-02-13 12:35:46 +08:00
type: "PUT",
data: { enable },
}).then(() => this.site.set("isReadOnly", enable));
}
}