added an events bundled plugin for managing event settings
This commit is contained in:
1 parent
52e105416d
commit
17c3d6e57a
3 files changed
+180
No files matched your search
@@ -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()
|
||||
@@ -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"]
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
<div class="alert alert-block">
|
||||
<p>For additional information on OctoPrint events please see the official documentation <a href="https://docs.octoprint.org/en/master/events/index.html" target="_blank">here</a>.</p>
|
||||
<p><strong>Warning:</strong> For changes to take effect you must restart OctoPrint after saving.</p>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span4">Event</div>
|
||||
<div class="span6">Command</div>
|
||||
<div class="span2 btn-group">
|
||||
<button class="btn btn-mini" data-bind="click: addEvent"><i class="fa fa-plus"></i> Add</button>
|
||||
</div>
|
||||
</div>
|
||||
<div data-bind="foreach: settingsViewModel.settings.plugins.events.subscriptions" class="row-fluid">
|
||||
<div class="row-fluid">
|
||||
<div class="span4" data-bind="text: event"></div>
|
||||
<div class="span6" data-bind="text: command"></div>
|
||||
<div class="span2 btn-group">
|
||||
<button class="btn btn-mini" data-bind="click: $root.editEvent"><i class="fa fa-pencil"></i></button>
|
||||
<button class="btn btn-mini btn-danger" data-bind="click: $root.removeEvent"><i class="fa fa-trash-alt"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="EventCoordinatorEditor" data-bind="with: selected_command" class="modal hide fade">
|
||||
<div class="modal-header">
|
||||
<a href="#" class="close" data-dismiss="modal" aria-hidden="true">×</a>
|
||||
<h3>Command Editor</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="control-group">
|
||||
<label class="control-label">Event</label>
|
||||
<div class="controls">
|
||||
<select class="input-block-level" data-bind="value: event, options: $root.settingsViewModel.settings.plugins.events.availableEvents().sort(), optionsCaption: 'Select Event', valueAllowUnset: true"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Command</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: command" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Type</label>
|
||||
<div class="controls">
|
||||
<select data-bind="value: type, options: ['gcode', 'system'], optionsCaption: 'Select Event Type', valueAllowUnset: true"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Enabled</label>
|
||||
<div class="controls">
|
||||
<input type="checkbox" data-bind="checked: enabled" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Debug</label>
|
||||
<div class="controls">
|
||||
<input type="checkbox" data-bind="checked: debug" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="row-fluid">
|
||||
Don't forget to save in main settings. <button type="button" class="btn" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in new issue
Block a user