mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 05:26:45 +00:00
add read all endpoint
This commit is contained in:
parent
0fa8af6cd8
commit
a4c9dfdd6f
@ -14,6 +14,7 @@ from django.views.decorators.csrf import csrf_exempt
|
|||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
|
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.response import Response
|
||||||
from rest_framework.exceptions import NotAcceptable, NotFound
|
from rest_framework.exceptions import NotAcceptable, NotFound
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
from rest_framework import filters, generics, permissions
|
from rest_framework import filters, generics, permissions
|
||||||
@ -314,6 +315,25 @@ class NotificationUnread(NotificationReadEdit):
|
|||||||
target = False
|
target = False
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationReadAll(generics.RetrieveAPIView):
|
||||||
|
"""
|
||||||
|
API endpoint to mark all notifications as read.
|
||||||
|
"""
|
||||||
|
|
||||||
|
queryset = common.models.NotificationMessage.objects.all()
|
||||||
|
|
||||||
|
permission_classes = [
|
||||||
|
UserSettingsPermissions,
|
||||||
|
]
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
self.queryset.filter(user=request.user, read=False).update(read=True)
|
||||||
|
return Response({'status': 'ok'})
|
||||||
|
except Exception as exc:
|
||||||
|
raise serializers.ValidationError(detail=serializers.as_serializer_error(exc))
|
||||||
|
|
||||||
|
|
||||||
settings_api_urls = [
|
settings_api_urls = [
|
||||||
# User settings
|
# User settings
|
||||||
url(r'^user/', include([
|
url(r'^user/', include([
|
||||||
@ -346,6 +366,8 @@ common_api_urls = [
|
|||||||
url(r'^unread/', NotificationUnread.as_view(), name='api-notifications-unread'),
|
url(r'^unread/', NotificationUnread.as_view(), name='api-notifications-unread'),
|
||||||
url(r'.*$', NotificationDetail.as_view(), name='api-notifications-detail'),
|
url(r'.*$', NotificationDetail.as_view(), name='api-notifications-detail'),
|
||||||
])),
|
])),
|
||||||
|
# Read all
|
||||||
|
url(r'^readall/', NotificationReadAll.as_view(), name='api-notifications-readall'),
|
||||||
|
|
||||||
# Notification messages list
|
# Notification messages list
|
||||||
url(r'^.*$', NotificationList.as_view(), name='api-notifications-list'),
|
url(r'^.*$', NotificationList.as_view(), name='api-notifications-list'),
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
<div class='btn btn-secondary' type='button' id='inbox-refresh' title='{% trans "Refresh Pending Notifications" %}'>
|
<div class='btn btn-secondary' type='button' id='inbox-refresh' title='{% trans "Refresh Pending Notifications" %}'>
|
||||||
<span class='fa fa-sync'></span> {% trans "Refresh Pending Notifications" %}
|
<span class='fa fa-sync'></span> {% trans "Refresh Pending Notifications" %}
|
||||||
</div>
|
</div>
|
||||||
|
<div class='btn btn-secondary' type='button' id='mark-all' title='{% trans "Mark all as read" %}'>
|
||||||
|
<span class='fa fa-sync'></span> {% trans "Mark all as read" %}
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -120,6 +120,15 @@ $("#inbox-refresh").on('click', function() {
|
|||||||
$("#inbox-table").bootstrapTable('refresh');
|
$("#inbox-table").bootstrapTable('refresh');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#mark-all").on('click', function() {
|
||||||
|
inventreeGet(
|
||||||
|
'{% url "api-notifications-readall" %}',
|
||||||
|
{
|
||||||
|
read: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
updateNotificationTables();
|
||||||
|
});
|
||||||
|
|
||||||
loadNotificationTable("#history-table", {
|
loadNotificationTable("#history-table", {
|
||||||
name: 'history',
|
name: 'history',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user