diff --git a/app/assets/javascripts/admin/addon/controllers/admin-plugins-index.js b/app/assets/javascripts/admin/addon/controllers/admin-plugins-index.js
new file mode 100644
index 00000000000..611fb70c783
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/controllers/admin-plugins-index.js
@@ -0,0 +1,25 @@
+import Controller from "@ember/controller";
+import { action, set } from "@ember/object";
+import { inject as service } from "@ember/service";
+import SiteSetting from "admin/models/site-setting";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+
+export default class AdminPluginsIndexController extends Controller {
+ @service session;
+
+ @action
+ async togglePluginEnabled(plugin) {
+ const enabledSettingName = plugin.enabled_setting;
+
+ const oldValue = plugin.enabled;
+ const newValue = !oldValue;
+ try {
+ set(plugin, "enabled", newValue);
+ await SiteSetting.update(enabledSettingName, newValue);
+ this.session.requiresRefresh = true;
+ } catch (e) {
+ set(plugin, "enabled", oldValue);
+ popupAjaxError(e);
+ }
+ }
+}
diff --git a/app/assets/javascripts/admin/addon/templates/plugins-index.hbs b/app/assets/javascripts/admin/addon/templates/plugins-index.hbs
index c02746557af..239f2a2f06c 100644
--- a/app/assets/javascripts/admin/addon/templates/plugins-index.hbs
+++ b/app/assets/javascripts/admin/addon/templates/plugins-index.hbs
@@ -31,7 +31,7 @@
href={{plugin.url}}
rel="noopener noreferrer"
target="_blank"
- >{{plugin.name}}
+ >{{plugin.name}} {{d-icon "external-link-alt"}}
{{else}}
{{plugin.name}}
{{/if}}
@@ -48,13 +48,12 @@
{{i18n "admin.plugins.enabled"}}
{{#if plugin.enabled_setting}}
- {{#if plugin.enabled}}
- {{i18n "admin.plugins.is_enabled"}}
- {{else}}
- {{i18n "admin.plugins.not_enabled"}}
- {{/if}}
+
{{else}}
- {{i18n "admin.plugins.is_enabled"}}
+
{{/if}}
|
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-plugins-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-plugins-test.js
index 3a326ce86d3..8fd0f356726 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-plugins-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-plugins-test.js
@@ -1,9 +1,5 @@
-import {
- acceptance,
- exists,
- query,
-} from "discourse/tests/helpers/qunit-helpers";
-import { visit } from "@ember/test-helpers";
+import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
acceptance("Admin - Plugins", function (needs) {
@@ -35,26 +31,39 @@ acceptance("Admin - Plugins", function (needs) {
],
})
);
+
+ server.put("/admin/site_settings/testplugin_enabled", () =>
+ helper.response()
+ );
});
- test("shows plugin list", async function (assert) {
+ test("shows plugin list and can toggle state", async function (assert) {
await visit("/admin/plugins");
- const table = query("table.admin-plugins");
- assert.strictEqual(
- table.querySelector("tr .plugin-name .name").innerText,
- "some-test-plugin",
- "displays the plugin in the table"
- );
- assert.true(
- exists(".admin-plugins .admin-container .alert-error"),
- "displays an error for unknown routes"
- );
+ assert
+ .dom("table.admin-plugins tr .plugin-name .name")
+ .hasText("some-test-plugin", "displays the plugin in the table");
- assert.strictEqual(
- table.querySelector("tr .version a.commit-hash").href,
- "https://github.com/username/some-test-plugin/commit/1234567890abcdef",
- "displays a commit hash with a link to commit url"
- );
+ assert
+ .dom(".admin-plugins .admin-container .alert-error")
+ .exists("shows an error for unknown routes");
+
+ assert
+ .dom("table.admin-plugins tr .version a.commit-hash")
+ .hasAttribute(
+ "href",
+ "https://github.com/username/some-test-plugin/commit/1234567890abcdef",
+ "displays a commit hash with a link to commit url"
+ );
+
+ const toggleSelector = "table.admin-plugins tr .col-enabled button";
+ assert
+ .dom(toggleSelector)
+ .hasAttribute("aria-checked", "true", "displays the plugin as enabled");
+
+ await click(toggleSelector);
+ assert
+ .dom(toggleSelector)
+ .hasAttribute("aria-checked", "false", "displays the plugin as enabled");
});
});
diff --git a/plugins/styleguide/assets/javascripts/discourse/components/sections/atoms/02-buttons.hbs b/plugins/styleguide/assets/javascripts/discourse/components/sections/atoms/02-buttons.hbs
index 9dc95bfb005..3d1c17d458d 100644
--- a/plugins/styleguide/assets/javascripts/discourse/components/sections/atoms/02-buttons.hbs
+++ b/plugins/styleguide/assets/javascripts/discourse/components/sections/atoms/02-buttons.hbs
@@ -162,4 +162,14 @@
(fn (mut @dummy.toggleSwitchState) (not @dummy.toggleSwitchState))
}}
/>
+
+
\ No newline at end of file
diff --git a/plugins/styleguide/assets/stylesheets/styleguide.scss b/plugins/styleguide/assets/stylesheets/styleguide.scss
index 1d57edd61d6..9d41477e7a9 100644
--- a/plugins/styleguide/assets/stylesheets/styleguide.scss
+++ b/plugins/styleguide/assets/stylesheets/styleguide.scss
@@ -195,6 +195,10 @@
margin-right: 0.5em;
margin-bottom: 0.5em;
}
+
+ .d-toggle-switch {
+ display: inline-block;
+ }
}
.icons-examples,
|