2023-08-03 22:19:33 +08:00
|
|
|
import Controller from "@ember/controller";
|
2023-08-28 08:48:59 +08:00
|
|
|
import { action } from "@ember/object";
|
2024-03-07 01:05:11 +08:00
|
|
|
import { service } from "@ember/service";
|
2024-10-11 07:26:10 +08:00
|
|
|
import { adminRouteValid } from "discourse/lib/admin-utilities";
|
2023-08-03 22:19:33 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2023-10-11 02:38:59 +08:00
|
|
|
import SiteSetting from "admin/models/site-setting";
|
2023-08-03 22:19:33 +08:00
|
|
|
|
|
|
|
export default class AdminPluginsIndexController extends Controller {
|
|
|
|
@service session;
|
2024-08-30 12:53:36 +08:00
|
|
|
@service adminPluginNavManager;
|
|
|
|
@service router;
|
2023-08-03 22:19:33 +08:00
|
|
|
|
|
|
|
@action
|
|
|
|
async togglePluginEnabled(plugin) {
|
|
|
|
const oldValue = plugin.enabled;
|
|
|
|
const newValue = !oldValue;
|
2023-08-28 08:48:59 +08:00
|
|
|
|
2023-08-03 22:19:33 +08:00
|
|
|
try {
|
2023-08-28 08:48:59 +08:00
|
|
|
plugin.enabled = newValue;
|
|
|
|
await SiteSetting.update(plugin.enabledSetting, newValue);
|
2023-08-03 22:19:33 +08:00
|
|
|
this.session.requiresRefresh = true;
|
|
|
|
} catch (e) {
|
2023-08-28 08:48:59 +08:00
|
|
|
plugin.enabled = oldValue;
|
2023-08-03 22:19:33 +08:00
|
|
|
popupAjaxError(e);
|
|
|
|
}
|
|
|
|
}
|
2024-08-30 12:53:36 +08:00
|
|
|
|
|
|
|
// NOTE: See also AdminPluginsController, there is some duplication here
|
|
|
|
// while we convert plugins to use_new_show_route
|
|
|
|
get adminRoutes() {
|
2024-10-11 07:26:10 +08:00
|
|
|
return this.allAdminRoutes.filter((route) =>
|
|
|
|
adminRouteValid(this.router, route)
|
|
|
|
);
|
2024-08-30 12:53:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
get allAdminRoutes() {
|
|
|
|
return this.model
|
|
|
|
.filter((plugin) => plugin?.enabled && plugin?.adminRoute)
|
|
|
|
.map((plugin) => {
|
|
|
|
return Object.assign(plugin.adminRoute, { plugin_id: plugin.id });
|
|
|
|
});
|
|
|
|
}
|
2023-08-03 22:19:33 +08:00
|
|
|
}
|