From ab3d1b66d54c337e3aecef67a7c68d93e4a2b13c Mon Sep 17 00:00:00 2001 From: ntoff Date: Fri, 24 Mar 2017 16:18:17 +1000 Subject: [PATCH] dynamic class, invisible to anon users dynamic class based on state, completely invisible to non logged in users --- octoprint_estop/__init__.py | 9 ++++----- octoprint_estop/static/js/estop.js | 20 +++++++++++++++---- .../templates/estop_sidebar.jinja2 | 4 ++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/octoprint_estop/__init__.py b/octoprint_estop/__init__.py index 38c24d2..70615c3 100644 --- a/octoprint_estop/__init__.py +++ b/octoprint_estop/__init__.py @@ -12,12 +12,11 @@ class EstopPlugin(octoprint.plugin.AssetPlugin, css=["css/estop.css"] ) def get_template_configs(self): - return [dict(type="sidebar", name="Emergency STOP!", icon="fa fa-times")] + return [ + dict(type="sidebar", name="Emergency STOP!", icon="fa fa-times", template="estop_sidebar.jinja2", styles=["display: none"], data_bind="visible: loginState.isUser") + ] __plugin_name__ = "Emergency Stop Button" - -def __plugin_load__(): - global __plugin_implementation__ - __plugin_implementation__ = EstopPlugin() +__plugin_implementation__ = EstopPlugin() \ No newline at end of file diff --git a/octoprint_estop/static/js/estop.js b/octoprint_estop/static/js/estop.js index 5ee27c0..8d0c86f 100644 --- a/octoprint_estop/static/js/estop.js +++ b/octoprint_estop/static/js/estop.js @@ -5,14 +5,26 @@ $(function() { function EstopViewModel(parameters) { var self = this; - //see if we're logged in and the printer is operational (for en/disable of button) + self.loginState = parameters[0]; self.printerState = parameters[1]; - + self.enableEstop = ko.pureComputed(function() { return self.printerState.isOperational() && self.loginState.isUser(); }); - + + self.estopState = ko.pureComputed(function() { + return self.loginState.isUser() > 0 ? "estop_sidebar" : "estop_sidebar_disabled"; + }); + + self.buttonText = ko.pureComputed(function() { + if (self.enableEstop()) { + return gettext("EMERGENCY STOP"); + } else { + return gettext("Offline"); + } + }); + self.sendEstopCommand = function () { if (self.enableEstop()) { OctoPrint.control.sendGcode("M112"); @@ -26,6 +38,6 @@ $(function() { "loginStateViewModel", "printerStateViewModel", ], - elements: ["#sidebar_plugin_estop"] + elements: ["#sidebar_plugin_estop_wrapper"] }); }); diff --git a/octoprint_estop/templates/estop_sidebar.jinja2 b/octoprint_estop/templates/estop_sidebar.jinja2 index 8f6e5a9..3804e23 100644 --- a/octoprint_estop/templates/estop_sidebar.jinja2 +++ b/octoprint_estop/templates/estop_sidebar.jinja2 @@ -1,4 +1,4 @@ -
- +