2024-03-07 01:05:11 +08:00
|
|
|
import { service } from "@ember/service";
|
2024-03-20 07:20:06 +08:00
|
|
|
import { MAIN_PANEL } from "discourse/lib/sidebar/panels";
|
2023-10-19 12:23:41 +08:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
|
|
|
import I18n from "discourse-i18n";
|
|
|
|
|
|
|
|
export default class AdminRoute extends DiscourseRoute {
|
|
|
|
@service siteSettings;
|
|
|
|
@service currentUser;
|
|
|
|
@service sidebarState;
|
2024-03-20 07:20:06 +08:00
|
|
|
@service adminSidebarStateManager;
|
2023-10-19 12:23:41 +08:00
|
|
|
|
|
|
|
titleToken() {
|
|
|
|
return I18n.t("admin_title");
|
|
|
|
}
|
|
|
|
|
|
|
|
activate() {
|
2024-02-09 10:52:22 +08:00
|
|
|
if (!this.currentUser.use_admin_sidebar) {
|
2023-10-19 12:23:41 +08:00
|
|
|
return DiscourseURL.redirectTo("/admin");
|
|
|
|
}
|
|
|
|
|
2024-03-20 07:20:06 +08:00
|
|
|
this.adminSidebarStateManager.maybeForceAdminSidebar({
|
|
|
|
onlyIfAlreadyActive: false,
|
|
|
|
});
|
2023-10-19 12:23:41 +08:00
|
|
|
|
|
|
|
this.controllerFor("application").setProperties({
|
|
|
|
showTop: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-02 08:34:37 +08:00
|
|
|
deactivate(transition) {
|
2023-10-19 12:23:41 +08:00
|
|
|
this.controllerFor("application").set("showTop", true);
|
2024-03-20 07:20:06 +08:00
|
|
|
if (this.adminSidebarStateManager.currentUserUsingAdminSidebar) {
|
|
|
|
if (!transition?.to.name.startsWith("admin")) {
|
|
|
|
this.sidebarState.setPanel(MAIN_PANEL);
|
|
|
|
}
|
2023-11-02 08:34:37 +08:00
|
|
|
}
|
2023-10-19 12:23:41 +08:00
|
|
|
}
|
|
|
|
}
|