import Component from "@glimmer/component"; import { concat, fn, hash } from "@ember/helper"; import { on } from "@ember/modifier"; import { action } from "@ember/object"; import { LinkTo } from "@ember/routing"; import { service } from "@ember/service"; import DToggleSwitch from "discourse/components/d-toggle-switch"; import PluginOutlet from "discourse/components/plugin-outlet"; import { popupAjaxError } from "discourse/lib/ajax-error"; import icon from "discourse-common/helpers/d-icon"; import { i18n } from "discourse-i18n"; import SiteSetting from "admin/models/site-setting"; import PluginCommitHash from "./plugin-commit-hash"; export default class AdminPluginsListItem extends Component { @service session; @service currentUser; @service sidebarState; @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 (err) { plugin.enabled = oldValue; popupAjaxError(err); } } get isAdminSearchFiltered() { if (!this.sidebarState.filter) { return false; } return this.args.plugin.nameTitleizedLower.match(this.sidebarState.filter); } get showPluginSettingsButton() { return this.currentUser.admin && this.args.plugin.hasSettings; } get disablePluginSettingsButton() { return ( this.showPluginSettingsButton && this.args.plugin.hasOnlyEnabledSetting ); } get settingsButtonTitle() { if (this.disablePluginSettingsButton) { return i18n("admin.plugins.settings_disabled"); } return ""; } }