only show inbox statistics if inbox tags are defined

This commit is contained in:
jonaswinkler 2021-02-15 23:14:54 +01:00
parent 3f03d51b24
commit cb308fae7b
3 changed files with 18 additions and 5 deletions

View File

@ -1,6 +1,6 @@
<app-widget-frame title="Statistics" i18n-title> <app-widget-frame title="Statistics" i18n-title>
<ng-container content> <ng-container content>
<p class="card-text" i18n>Documents in inbox: {{statistics.documents_inbox}}</p> <p class="card-text" i18n *ngIf="statistics?.documents_inbox != null">Documents in inbox: {{statistics?.documents_inbox}}</p>
<p class="card-text" i18n>Total documents: {{statistics.documents_total}}</p> <p class="card-text" i18n>Total documents: {{statistics?.documents_total}}</p>
</ng-container> </ng-container>
</app-widget-frame> </app-widget-frame>

View File

@ -442,6 +442,13 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
self.assertEqual(response.data['documents_total'], 3) self.assertEqual(response.data['documents_total'], 3)
self.assertEqual(response.data['documents_inbox'], 1) self.assertEqual(response.data['documents_inbox'], 1)
def test_statistics_no_inbox_tag(self):
Document.objects.create(title="none1", checksum="A")
response = self.client.get("/api/statistics/")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['documents_inbox'], None)
@mock.patch("documents.views.async_task") @mock.patch("documents.views.async_task")
def test_upload(self, m): def test_upload(self, m):

View File

@ -595,8 +595,14 @@ class StatisticsView(APIView):
permission_classes = (IsAuthenticated,) permission_classes = (IsAuthenticated,)
def get(self, request, format=None): def get(self, request, format=None):
return Response({ documents_total = Document.objects.all().count()
'documents_total': Document.objects.all().count(), if Tag.objects.filter(is_inbox_tag=True).exists():
'documents_inbox': Document.objects.filter( documents_inbox = Document.objects.filter(
tags__is_inbox_tag=True).distinct().count() tags__is_inbox_tag=True).distinct().count()
else:
documents_inbox = None
return Response({
'documents_total': documents_total,
'documents_inbox': documents_inbox,
}) })