mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 07:43:39 +08:00
5fc93b95cc
This commit contains a few improvements: * Use LinkTo instead of a button with a weird action referencing the controller to navigate to the filtered settings for a plugin * Add an AdminPlugin model with tracked properties and use that when toggling the setting on/off and in the templates * Make it so the Settings button for a plugin navigates to the correct site setting category instead of always just going to the generic "plugins" one if possible
37 lines
774 B
JavaScript
37 lines
774 B
JavaScript
import { inject as service } from "@ember/service";
|
|
import Controller from "@ember/controller";
|
|
|
|
export default class AdminPluginsController extends Controller {
|
|
@service router;
|
|
|
|
get adminRoutes() {
|
|
return this.allAdminRoutes.filter((route) =>
|
|
this.routeExists(route.full_location)
|
|
);
|
|
}
|
|
|
|
get brokenAdminRoutes() {
|
|
return this.allAdminRoutes.filter(
|
|
(route) => !this.routeExists(route.full_location)
|
|
);
|
|
}
|
|
|
|
get allAdminRoutes() {
|
|
return this.model
|
|
.filter((plugin) => plugin?.enabled)
|
|
.map((plugin) => {
|
|
return plugin.adminRoute;
|
|
})
|
|
.filter(Boolean);
|
|
}
|
|
|
|
routeExists(routeName) {
|
|
try {
|
|
this.router.urlFor(routeName);
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|