discourse/app/assets/javascripts/admin/addon/controllers/admin-backups-index.js
Martin Brennan 1446596089
UX: Apply admin interface guidelines to Backups page (#28051)
This commit converts the Backups page in the admin interface
to follow our new admin interface guidelines.

As part of this work, I've also made `AdminPageHeader` and `AdminPageSubheader`
components that can be reused on any admin page for consistency, that handle
the title and action buttons and also breadcrumbs.

Also renamed `AdminPluginFilteredSiteSettings` to `AdminFilteredSiteSettings` since
it can be used generally to show a subset of filtered site settings, not only
settings for a plugin. Not sure if it's ideal to have to define a new route for this
for every config area, but not sure how else to do it right now.
2024-08-20 09:59:43 +10:00

50 lines
1.6 KiB
JavaScript

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";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
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;
@discourseComputed("status.allowRestore", "status.isOperationRunning")
restoreTitle(allowRestore, isOperationRunning) {
if (!allowRestore) {
return "admin.backups.operations.restore.is_disabled";
} else if (isOperationRunning) {
return "admin.backups.operations.is_running";
} else {
return "admin.backups.operations.restore.title";
}
}
@action
async download(backup) {
try {
await ajax(`/admin/backups/${backup.filename}`, { type: "PUT" });
this.dialog.alert(I18n.t("admin.backups.operations.download.alert"));
} catch (err) {
popupAjaxError(err);
}
}
@discourseComputed("status.isOperationRunning")
deleteTitle() {
if (this.status.isOperationRunning) {
return "admin.backups.operations.is_running";
}
return "admin.backups.operations.destroy.title";
}
}