diff --git a/src/octoprint/plugins/events/__init__.py b/src/octoprint/plugins/events/__init__.py new file mode 100644 index 000000000..1e8ff3b4a --- /dev/null +++ b/src/octoprint/plugins/events/__init__.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +from flask_babel import gettext + +import octoprint.events +import octoprint.plugin +from octoprint.access import ADMIN_GROUP + + +class eventsPlugin( + octoprint.plugin.SettingsPlugin, + octoprint.plugin.AssetPlugin, + octoprint.plugin.TemplatePlugin, +): + def on_settings_load(self): + my_settings = { + "availableEvents": octoprint.events.all_events(), + "subscriptions": [], + } + events = self._settings.global_get(["events"]) + if events: + my_settings["subscriptions"] = events["subscriptions"] + return my_settings + + def on_settings_save(self, data): + if type(data.get("subscriptions")) == list: + self._settings.global_set( + ["events", "subscriptions"], data.get("subscriptions", []) + ) + + def get_assets(self): + return {"js": ["js/events.js"]} + + def get_template_configs(self): + return [{"type": "settings", "custom_bindings": True}] + + def get_additional_permissions(self): + return [ + { + "key": "MANAGE", + "name": "Event management", + "description": gettext( + "Allows for the management of event subscriptions." + ), + "default_groups": [ADMIN_GROUP], + "roles": ["manage"], + } + ] + + +__plugin_name__ = "Events" +__plugin_pythoncompat__ = ">=2.7,<4" +__plugin_author__ = "jneilliii" +__plugin_license__ = "AGPLv3" +__plugin_description__ = ( + "Plugin to configure event subscriptions available in config.yaml." +) +__plugin_implementation__ = eventsPlugin() diff --git a/src/octoprint/plugins/events/static/js/events.js b/src/octoprint/plugins/events/static/js/events.js new file mode 100644 index 000000000..7013789a7 --- /dev/null +++ b/src/octoprint/plugins/events/static/js/events.js @@ -0,0 +1,57 @@ +/* + * View model for OctoPrint-EventCoordinator + * + * Author: jneilliii + * License: MIT + */ +$(function () { + function EventcoordinatorViewModel(parameters) { + var self = this; + + self.settingsViewModel = parameters[0]; + self.selected_command = ko.observable(); + + self.event_details = function (data) { + if (data === false) { + return { + event: ko.observable(""), + command: ko.observable(""), + type: ko.observable(""), + enabled: ko.observable(true), + debug: ko.observable(false) + }; + } else { + if (!data.hasOwnProperty("enabled")) { + data["enabled"] = ko.observable(true); + } + if (!data.hasOwnProperty("debug")) { + data["debug"] = ko.observable(false); + } + return data; + } + }; + + self.addEvent = function () { + self.selected_command(self.event_details(false)); + self.settingsViewModel.settings.plugins.events.subscriptions.push( + self.selected_command() + ); + $("#EventCoordinatorEditor").modal("show"); + }; + + self.editEvent = function (data) { + self.selected_command(self.event_details(data)); + $("#EventCoordinatorEditor").modal("show"); + }; + + self.removeEvent = function (data) { + self.settingsViewModel.settings.plugins.events.subscriptions.remove(data); + }; + } + + OCTOPRINT_VIEWMODELS.push({ + construct: EventcoordinatorViewModel, + dependencies: ["settingsViewModel"], + elements: ["#settings_plugin_events"] + }); +}); diff --git a/src/octoprint/plugins/events/templates/events_settings.jinja2 b/src/octoprint/plugins/events/templates/events_settings.jinja2 new file mode 100644 index 000000000..68cf4ffab --- /dev/null +++ b/src/octoprint/plugins/events/templates/events_settings.jinja2 @@ -0,0 +1,65 @@ +
For additional information on OctoPrint events please see the official documentation here.
+Warning: For changes to take effect you must restart OctoPrint after saving.
+