From bb63eaad03ae1c50ce6ed747e8fca139a6c3e3ab Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 31 Oct 2022 13:21:56 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20descriptive?= =?UTF-8?q?=20names=20to=20event=20subscriptions=20(#4568)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/plugins/eventmanager/__init__.py | 4 +++- .../plugins/eventmanager/static/js/events.js | 1 + .../templates/eventmanager_settings.jinja2 | 11 +++++++++-- src/octoprint/schema/config/events.py | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/octoprint/plugins/eventmanager/__init__.py b/src/octoprint/plugins/eventmanager/__init__.py index 667c783b3..f631d6ecc 100644 --- a/src/octoprint/plugins/eventmanager/__init__.py +++ b/src/octoprint/plugins/eventmanager/__init__.py @@ -17,7 +17,9 @@ class EventManagerPlugin( } events = self._settings.global_get(["events"]) if events: - my_settings["subscriptions"] = events.get("subscriptions", []) + my_settings["subscriptions"] = sorted( + events.get("subscriptions", []), key=(lambda x: x["event"]) + ) return my_settings def on_settings_save(self, data): diff --git a/src/octoprint/plugins/eventmanager/static/js/events.js b/src/octoprint/plugins/eventmanager/static/js/events.js index f30e4972f..9a51ff31d 100644 --- a/src/octoprint/plugins/eventmanager/static/js/events.js +++ b/src/octoprint/plugins/eventmanager/static/js/events.js @@ -16,6 +16,7 @@ $(function () { return { event: ko.observable(""), command: ko.observable(""), + name: ko.observable(""), type: ko.observable(""), enabled: ko.observable(true), debug: ko.observable(false) diff --git a/src/octoprint/plugins/eventmanager/templates/eventmanager_settings.jinja2 b/src/octoprint/plugins/eventmanager/templates/eventmanager_settings.jinja2 index 27408c35d..c0d41b6bd 100644 --- a/src/octoprint/plugins/eventmanager/templates/eventmanager_settings.jinja2 +++ b/src/octoprint/plugins/eventmanager/templates/eventmanager_settings.jinja2 @@ -4,7 +4,7 @@
{{ _('Event') }}
-
{{ _('Command') }}
+
{{ _('Name') }}
@@ -12,7 +12,7 @@
-
+
@@ -32,6 +32,13 @@
+ +
+ +
+ +
+
diff --git a/src/octoprint/schema/config/events.py b/src/octoprint/schema/config/events.py index ae8652a5d..249476e9e 100644 --- a/src/octoprint/schema/config/events.py +++ b/src/octoprint/schema/config/events.py @@ -2,7 +2,7 @@ __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agp __copyright__ = "Copyright (C) 2022 The OctoPrint Project - Released under terms of the AGPLv3 License" from enum import Enum -from typing import List +from typing import List, Optional from octoprint.schema import BaseModel from octoprint.vendor.with_attrs_docs import with_attrs_docs @@ -18,6 +18,9 @@ class EventSubscription(BaseModel): event: str """The event to subscribe to.""" + name: Optional[str] = None + """The event name to show on the UI""" + command: str """The command to execute when the event is triggered, either a GCODE or a system command."""