From 9b51db376fdca051218b8548e8ea5ed9d649a607 Mon Sep 17 00:00:00 2001
From: thelastWallE <12502210+thelastWallE@users.noreply.github.com>
Date: Wed, 17 Nov 2021 22:27:43 +0100
Subject: [PATCH] :children_crossing: add option to hide PopUps for errors
---
octoprint_klipper/__init__.py | 3 +-
octoprint_klipper/static/js/klipper.js | 51 ++++++++++++++++---
.../templates/klipper_settings.jinja2 | 7 +++
3 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/octoprint_klipper/__init__.py b/octoprint_klipper/__init__.py
index 4315455..3d1a66f 100644
--- a/octoprint_klipper/__init__.py
+++ b/octoprint_klipper/__init__.py
@@ -140,7 +140,8 @@ class KlipperPlugin(
shortStatus_navbar=True,
shortStatus_sidebar=True,
parse_check=False,
- fontsize=12
+ fontsize=12,
+ hide_error_popups=False
)
)
diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js
index 9c41b64..de85840 100644
--- a/octoprint_klipper/static/js/klipper.js
+++ b/octoprint_klipper/static/js/klipper.js
@@ -37,19 +37,54 @@ $(function () {
self.shortStatus_sidebar = ko.observable();
self.logMessages = ko.observableArray();
+ self.popup = undefined;
+
+ self._showPopup = function (options) {
+ self._closePopup();
+ self.popup = new PNotify(options);
+ };
+
+ self._updatePopup = function (options) {
+ if (self.popup === undefined) {
+ self._showPopup(options);
+ } else {
+ self.popup.update(options);
+ }
+ };
+
+ self._closePopup = function () {
+ if (self.popup !== undefined) {
+ self.popup.remove();
+ }
+ };
+
self.showPopUp = function (popupType, popupTitle, message) {
var title = "OctoKlipper:
" + popupTitle + "
";
- var hide = false;
- if (popupType == "success") {
- hide = true
- }
- new PNotify({
+ var options = undefined;
+ var errorOpts = {};
+
+ options = {
title: title,
text: message,
type: popupType,
- hide: hide,
+ hide: true,
icon: true
- });
+ };
+
+ if (popupType == "error") {
+
+ errorOpts = {
+ mouse_reset: true,
+ delay: 5000,
+ animation: "none"
+ };
+ FullOptions = Object.assign(options, errorOpts);
+ self._showPopup(FullOptions);
+ } else {
+ if (options !== undefined) {
+ new PNotify(options);
+ }
+ }
};
self.showEditorDialog = function () {
@@ -191,7 +226,7 @@ $(function () {
today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
}
- if (type == "error") {
+ if (type == "error" && self.settings.settings.plugins.klipper.configuration.hide_error_popups() !== true) {
self.showPopUp(type, "Error:", message);
}
diff --git a/octoprint_klipper/templates/klipper_settings.jinja2 b/octoprint_klipper/templates/klipper_settings.jinja2
index 3209946..7947258 100644
--- a/octoprint_klipper/templates/klipper_settings.jinja2
+++ b/octoprint_klipper/templates/klipper_settings.jinja2
@@ -37,6 +37,13 @@
data-bind="checked: settings.settings.plugins.klipper.configuration.debug_logging" />
+