From 4bafd14befc8af9ebed78b2276ee14726e0cb7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 14 Oct 2020 16:49:33 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20ACNotifcations:=20Clear=20button?= =?UTF-8?q?=20in=20header=20&=20sort=20order=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements #3768 --- .../action_command_notification/__init__.py | 1 + .../static/js/action_command_notification.js | 29 ++++++++++++++++++- ...action_command_notification_sidebar.jinja2 | 2 +- ...command_notification_sidebar_header.jinja2 | 11 +++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/octoprint/plugins/action_command_notification/templates/action_command_notification_sidebar_header.jinja2 diff --git a/src/octoprint/plugins/action_command_notification/__init__.py b/src/octoprint/plugins/action_command_notification/__init__.py index a91c80155..e58007004 100644 --- a/src/octoprint/plugins/action_command_notification/__init__.py +++ b/src/octoprint/plugins/action_command_notification/__init__.py @@ -100,6 +100,7 @@ class ActionCommandNotificationPlugin( "name": gettext("Printer Notifications"), "icon": "bell-o", "styles_wrapper": ["display: none"], + "template_header": "action_command_notification_sidebar_header.jinja2", "data_bind": "visible: loginState.hasPermissionKo(access.permissions.PLUGIN_ACTION_COMMAND_NOTIFICATION_SHOW)" " && settings.settings.plugins.action_command_notification.enable()", }, diff --git a/src/octoprint/plugins/action_command_notification/static/js/action_command_notification.js b/src/octoprint/plugins/action_command_notification/static/js/action_command_notification.js index 6410639fd..c9f092d75 100644 --- a/src/octoprint/plugins/action_command_notification/static/js/action_command_notification.js +++ b/src/octoprint/plugins/action_command_notification/static/js/action_command_notification.js @@ -7,6 +7,10 @@ $(function () { self.settings = parameters[2]; self.notifications = ko.observableArray([]); + self.sortDesc = ko.observable(false); + self.sortDesc.subscribe(function () { + self._toLocalStorage(); + }); self.toDateTimeString = function (timestamp) { return formatDate(timestamp); @@ -24,7 +28,11 @@ $(function () { }; self.fromResponse = function (response) { - self.notifications(response.notifications); + var notifications = response.notifications; + if (self.sortDesc()) { + notifications.reverse(); + } + self.notifications(notifications); }; self.clear = function () { @@ -38,6 +46,11 @@ $(function () { OctoPrint.plugins.action_command_notification.clear(); }; + self.toggleSorting = function () { + self.sortDesc(!self.sortDesc()); + self.requestData(); + }; + self.onStartup = self.onUserLoggedIn = self.onUserLoggedOut = function () { self.requestData(); }; @@ -71,6 +84,20 @@ $(function () { }); } }; + + var optionsLocalStorageKey = "core.gcodeviewer.options"; + self._toLocalStorage = function () { + saveToLocalStorage(optionsLocalStorageKey, {sortDesc: self.sortDesc()}); + }; + + self._fromLocalStorage = function () { + var data = loadFromLocalStorage(optionsLocalStorageKey); + if (data["sortDesc"] !== undefined) { + self.sortDesc(!!data["sortDesc"]); + } + }; + + self._fromLocalStorage(); } OCTOPRINT_VIEWMODELS.push({ diff --git a/src/octoprint/plugins/action_command_notification/templates/action_command_notification_sidebar.jinja2 b/src/octoprint/plugins/action_command_notification/templates/action_command_notification_sidebar.jinja2 index 1118af0f3..fb2ed0200 100644 --- a/src/octoprint/plugins/action_command_notification/templates/action_command_notification_sidebar.jinja2 +++ b/src/octoprint/plugins/action_command_notification/templates/action_command_notification_sidebar.jinja2 @@ -5,7 +5,7 @@
- +
{{ _('There are currently no notifications from your printer.') }} diff --git a/src/octoprint/plugins/action_command_notification/templates/action_command_notification_sidebar_header.jinja2 b/src/octoprint/plugins/action_command_notification/templates/action_command_notification_sidebar_header.jinja2 new file mode 100644 index 000000000..237bd9a15 --- /dev/null +++ b/src/octoprint/plugins/action_command_notification/templates/action_command_notification_sidebar_header.jinja2 @@ -0,0 +1,11 @@ + + +