mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 05:53:55 +08:00
57ededb770
Having the admin sidebar code in an instance initializer is not ideal because: * It runs during app boot which may not even be necessary based on site settings * It makes it hard for plugins to register additional links in time without resorting to before/after initializer gymnastics This PR moves the admin sidebar into a lib and creates the panel in custom-sections.js, then the sections and links are loaded when the main sidebar component is rendered, which leaves plugins enough time to add additional links in an initializer. --------- Co-authored-by: David Taylor <david@taylorhq.com>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
import { inject as service } from "@ember/service";
|
|
import { ADMIN_PANEL, MAIN_PANEL } from "discourse/lib/sidebar/panels";
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
|
import I18n from "discourse-i18n";
|
|
|
|
export default class AdminRoute extends DiscourseRoute {
|
|
@service sidebarState;
|
|
@service siteSettings;
|
|
@service currentUser;
|
|
|
|
titleToken() {
|
|
return I18n.t("admin_title");
|
|
}
|
|
|
|
activate() {
|
|
if (
|
|
this.siteSettings.userInAnyGroups(
|
|
"admin_sidebar_enabled_groups",
|
|
this.currentUser
|
|
)
|
|
) {
|
|
this.sidebarState.setPanel(ADMIN_PANEL);
|
|
this.sidebarState.setSeparatedMode();
|
|
this.sidebarState.hideSwitchPanelButtons();
|
|
}
|
|
|
|
this.controllerFor("application").setProperties({
|
|
showTop: false,
|
|
});
|
|
}
|
|
|
|
deactivate(transition) {
|
|
this.controllerFor("application").set("showTop", true);
|
|
|
|
if (
|
|
this.siteSettings.userInAnyGroups(
|
|
"admin_sidebar_enabled_groups",
|
|
this.currentUser
|
|
)
|
|
) {
|
|
if (!transition?.to.name.startsWith("admin")) {
|
|
this.sidebarState.setPanel(MAIN_PANEL);
|
|
}
|
|
}
|
|
}
|
|
}
|