mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-15 10:16:46 +08:00
This creates a reusable filter component for admin areas that includes a text filter and dropdown. The component accepts an array to filter, an array of searchable property names, and optional dropdown values. An additional option is available if you'd like the default dropdown value to be something other than "all." It looks like this: <img width="2204" height="876" alt="image" src="https://github.com/user-attachments/assets/48693634-6752-4078-8639-42fb1ac77679" /> The dropdown is optional, without it: <img width="1756" height="900" alt="image" src="https://github.com/user-attachments/assets/ea9a7ae6-ae86-4cd8-8b99-4afc082f2ce5" /> When there are no matching filters, it provides a reset button: <img width="2188" height="394" alt="image" src="https://github.com/user-attachments/assets/9e59218e-8040-41db-ba81-1dc2628429bb" /> I'll use this to replace occurrences of similar filters, we've added a couple to the AI plugin.
75 lines
2 KiB
JavaScript
75 lines
2 KiB
JavaScript
import Controller from "@ember/controller";
|
|
import { action } from "@ember/object";
|
|
import { service } from "@ember/service";
|
|
import { adminRouteValid } from "discourse/lib/admin-utilities";
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
import { i18n } from "discourse-i18n";
|
|
import SiteSetting from "admin/models/site-setting";
|
|
|
|
export default class AdminPluginsIndexController extends Controller {
|
|
@service session;
|
|
@service adminPluginNavManager;
|
|
@service router;
|
|
|
|
get searchableProps() {
|
|
return ["nameTitleized", "author", "about"];
|
|
}
|
|
|
|
get dropdownOptions() {
|
|
return [
|
|
{ value: "all", label: i18n("admin.plugins.filters.all") },
|
|
{
|
|
value: "enabled",
|
|
label: i18n("admin.plugins.filters.enabled"),
|
|
filterFn: (item) => item.enabled,
|
|
},
|
|
{
|
|
value: "disabled",
|
|
label: i18n("admin.plugins.filters.disabled"),
|
|
filterFn: (item) => !item.enabled,
|
|
},
|
|
{
|
|
value: "preinstalled",
|
|
label: i18n("admin.plugins.filters.preinstalled"),
|
|
filterFn: (item) =>
|
|
item.url?.includes("/discourse/discourse/tree/main/plugins/"),
|
|
},
|
|
];
|
|
}
|
|
|
|
@action
|
|
async togglePluginEnabled(plugin) {
|
|
const oldValue = plugin.enabled;
|
|
const newValue = !oldValue;
|
|
|
|
try {
|
|
plugin.enabled = newValue;
|
|
await SiteSetting.update(plugin.enabledSetting, newValue);
|
|
this.session.requiresRefresh = true;
|
|
} catch (e) {
|
|
plugin.enabled = oldValue;
|
|
popupAjaxError(e);
|
|
}
|
|
}
|
|
|
|
// NOTE: See also AdminPluginsController, there is some duplication here
|
|
// while we convert plugins to use_new_show_route
|
|
get adminRoutes() {
|
|
return this.allAdminRoutes.filter((route) =>
|
|
adminRouteValid(this.router, route)
|
|
);
|
|
}
|
|
|
|
get allAdminRoutes() {
|
|
return this.model
|
|
.filter(
|
|
(plugin) =>
|
|
plugin?.enabled &&
|
|
plugin?.adminRoute &&
|
|
!plugin?.adminRoute?.auto_generated
|
|
)
|
|
.map((plugin) => {
|
|
return Object.assign(plugin.adminRoute, { plugin_id: plugin.id });
|
|
});
|
|
}
|
|
}
|