mirror of
https://github.com/discourse/discourse.git
synced 2024-12-09 15:33:38 +08:00
914f93b896
* Simplify config nav link generation to always inject the Settings tab * Auto-redirect to the first non-settings config link (if there is one) when the user lands on /admin/plugins/:plugin_id * Add `extras` to admin plugin serializer so plugins can add more data on first load * Add PikadayCalendar page object for system specs, extracted from the CalendarDateTimePicker to make it more generic.
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
import { tracked } from "@glimmer/tracking";
|
|
import Service, { service } from "@ember/service";
|
|
import {
|
|
configNavForPlugin,
|
|
PLUGIN_NAV_MODE_SIDEBAR,
|
|
PLUGIN_NAV_MODE_TOP,
|
|
} from "discourse/lib/admin-plugin-config-nav";
|
|
|
|
export default class AdminPluginNavManager extends Service {
|
|
@service currentUser;
|
|
@tracked currentPlugin;
|
|
|
|
get currentUserUsingAdminSidebar() {
|
|
return this.currentUser?.use_admin_sidebar;
|
|
}
|
|
|
|
get currentConfigNav() {
|
|
const configNav = configNavForPlugin(this.currentPlugin.id);
|
|
const settingsNav = {
|
|
mode: PLUGIN_NAV_MODE_TOP,
|
|
links: [
|
|
{
|
|
label: "admin.plugins.change_settings_short",
|
|
route: "adminPlugins.show.settings",
|
|
},
|
|
],
|
|
};
|
|
|
|
// Not all plugins have a more complex config UI and navigation,
|
|
// in that case only the settings route will be available.
|
|
if (!configNav) {
|
|
return settingsNav;
|
|
}
|
|
|
|
// Automatically inject the settings link.
|
|
if (
|
|
!configNav.links.mapBy("route").includes("adminPlugins.show.settings")
|
|
) {
|
|
configNav.links.unshift(settingsNav.links[0]);
|
|
}
|
|
return configNav;
|
|
}
|
|
|
|
get currentPluginDefaultRoute() {
|
|
const currentConfigNavLinks = this.currentConfigNav.links;
|
|
const linksExceptSettings = currentConfigNavLinks.reject(
|
|
(link) => link.route === "adminPlugins.show.settings"
|
|
);
|
|
|
|
// Some plugins only have the Settings route, if so it's fine to use it as default.
|
|
if (linksExceptSettings.length === 0) {
|
|
return currentConfigNavLinks[0].route;
|
|
}
|
|
|
|
return linksExceptSettings[0].route;
|
|
}
|
|
|
|
get isSidebarMode() {
|
|
return this.currentConfigNav.mode === PLUGIN_NAV_MODE_SIDEBAR;
|
|
}
|
|
|
|
get isTopMode() {
|
|
return this.currentConfigNav.mode === PLUGIN_NAV_MODE_TOP;
|
|
}
|
|
}
|