mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 02:23:44 +08:00
70f7c0ee6f
This commit changes the API for registering the plugin config page nav configuration from a server-side to a JS one; there is no need for it to be server-side. It also makes some changes to allow for 2 different ways of displaying navigation for plugin pages, depending on complexity: * TOP - This is the best mode for simple plugins without a lot of different custom configuration pages, and it reuses the grey horizontal nav bar already used for admins. * SIDEBAR - This is better for more complex plugins; likely this won't be used in the near future, but it's readily available if needed There is a new AdminPluginConfigNavManager service too to manage which plugin the admin is actively viewing, otherwise we would have trouble hiding the main plugin nav for admins when viewing a single plugin.
45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
import Controller from "@ember/controller";
|
|
import { service } from "@ember/service";
|
|
|
|
export default class AdminPluginsController extends Controller {
|
|
@service adminPluginNavManager;
|
|
@service router;
|
|
|
|
get adminRoutes() {
|
|
return this.allAdminRoutes.filter((route) => this.routeExists(route));
|
|
}
|
|
|
|
get brokenAdminRoutes() {
|
|
return this.allAdminRoutes.filter((route) => !this.routeExists(route));
|
|
}
|
|
|
|
get allAdminRoutes() {
|
|
return this.model
|
|
.filter((plugin) => plugin?.enabled)
|
|
.map((plugin) => {
|
|
return plugin.adminRoute;
|
|
})
|
|
.filter(Boolean);
|
|
}
|
|
|
|
get showTopNav() {
|
|
return (
|
|
!this.adminPluginNavManager.currentPlugin ||
|
|
this.adminPluginNavManager.isSidebarMode
|
|
);
|
|
}
|
|
|
|
routeExists(route) {
|
|
try {
|
|
if (route.use_new_show_route) {
|
|
this.router.urlFor(route.full_location, route.location);
|
|
} else {
|
|
this.router.urlFor(route.full_location);
|
|
}
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|