2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Notification fix (#3939)

* Fix docstring for NotificationMessage class

* Fix for 'refresh' button in notification table

* Simplify API for marking notifications as 'read'

- Simply update the detail serializer
- No requirement for extra API endpoints
- Same updates for news feed entry
- Hide 'read' news on the home page
- Add ability to mark news items as read via table

* Bug fix for build.js

* Fix for part category template
This commit is contained in:
Oliver
2022-11-17 08:26:19 +11:00
committed by GitHub
parent 54e7dd28e5
commit 95645c7b14
7 changed files with 72 additions and 87 deletions

View File

@ -2679,7 +2679,7 @@ function loadBuildTable(table, options) {
treeColumn: 1,
});
table.treegrid('expandAll');
$(table).treegrid('expandAll');
} else if (display_mode == 'calendar') {
if (!loaded_calendar) {

View File

@ -17,6 +17,7 @@ function loadNewsFeedTable(table, options={}, enableDelete=false) {
groupBy: false,
queryParams: {
ordering: 'published',
read: false,
},
paginationVAlign: 'bottom',
formatNoMatches: function() {
@ -49,10 +50,31 @@ function loadNewsFeedTable(table, options={}, enableDelete=false) {
field: 'published',
title: '{% trans "Published" %}',
sortable: 'true',
formatter: function(value) {
return renderDate(value);
formatter: function(value, row) {
var html = renderDate(value);
var buttons = getReadEditButton(row.pk, row.read);
html += `<div class='btn-group float-right' role='group'>${buttons}</div>`;
return html;
}
},
]
});
$(table).on('click', '.notification-read', function() {
var pk = $(this).attr('pk');
var url = `/api/news/${pk}/`;
inventreePut(url,
{
read: true,
},
{
method: 'PATCH',
success: function() {
$(table).bootstrapTable('refresh');
}
}
);
});
}

View File

@ -17,7 +17,7 @@ function loadNotificationTable(table, options={}, enableDelete=false) {
var params = options.params || {};
var read = typeof(params.read) === 'undefined' ? true : params.read;
setupFilterList(`notifications-${options.name}`, table);
setupFilterList(`notifications-${options.name}`, $(table));
$(table).inventreeTable({
url: options.url,
@ -157,38 +157,50 @@ function notificationCheck(force = false) {
* - panel_caller: this button was clicked in the notification panel
**/
function updateNotificationReadState(btn, panel_caller=false) {
var url = `/api/notifications/${btn.attr('pk')}/${btn.attr('target')}/`;
inventreePut(url, {}, {
method: 'POST',
success: function() {
// update the notification tables if they were declared
if (window.updateNotifications) {
window.updateNotifications();
}
// Determine 'read' status of the notification
var status = btn.attr('target') == 'read';
var pk = btn.attr('pk');
// update current notification count
var count = parseInt($('#notification-counter').html());
if (btn.attr('target') == 'read') {
count = count - 1;
} else {
count = count + 1;
}
var url = `/api/notifications/${pk}/`;
// Prevent negative notification count
if (count < 0) {
count = 0;
}
inventreePut(
url,
{
read: status,
},
{
method: 'PATCH',
success: function() {
// update the notification tables if they were declared
if (window.updateNotifications) {
window.updateNotifications();
}
// update notification indicator now
updateNotificationIndicator(count);
// update current notification count
var count = parseInt($('#notification-counter').html());
// remove notification if called from notification panel
if (panel_caller) {
btn.parent().parent().remove();
if (status) {
count = count - 1;
} else {
count = count + 1;
}
// Prevent negative notification count
if (count < 0) {
count = 0;
}
// update notification indicator now
updateNotificationIndicator(count);
// remove notification if called from notification panel
if (panel_caller) {
btn.parent().parent().remove();
}
}
}
});
);
};
/**