🚸 ACNotifcations: Clear button in header & sort order button
Implements #3768
This commit is contained in:
1 parent
706210a483
commit
4bafd14bef
4 files changed
+41
-2
No files matched your search
@@ -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()",
|
||||
},
|
||||
|
||||
+28
-1
@@ -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({
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<div class="sidebar_plugin_action_command_notification_entry_message" data-bind="text: message"></div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-block" data-bind="click: clear, visible: loginState.hasPermission(access.permissions.PLUGIN_ACTION_COMMAND_NOTIFICATION_CLEAR)">{{ _('Clear notifications') }}</button>
|
||||
<button class="btn btn-block" data-bind="click: clear, visible: loginState.hasPermission(access.permissions.PLUGIN_ACTION_COMMAND_NOTIFICATION_CLEAR)"><i class="fa fa-trash-o"></i> {{ _('Clear notifications') }}</button>
|
||||
</div>
|
||||
<div style="display: none" data-bind="visible: notifications().length == 0">
|
||||
{{ _('There are currently no notifications from your printer.') }}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<div class="accordion-heading-button btn-group" data-bind="visible: loginState.hasPermission(access.permissions.PLUGIN_ACTION_COMMAND_NOTIFICATION_CLEAR) && notifications().length > 0">
|
||||
<a href="javascript:void(0)" data-bind="click: clear" title="{{ _('Clear notifications')|edq }}">
|
||||
<i class="fa fa-trash-o"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="accordion-heading-button btn-group" data-bind="visible: notifications().length > 0">
|
||||
<a href="javascript:void(0)" data-bind="click: toggleSorting" title="{{ _('Change sorting')|edq }}">
|
||||
<i class="fa" data-bind="css: {'fa-sort-amount-desc': sortDesc, 'fa-sort-amount-asc': !sortDesc()}"></i>
|
||||
</a>
|
||||
</div>
|
||||
Reference in new issue
Block a user