basic statistics

This commit is contained in:
Jonas Winkler 2020-10-31 00:56:20 +01:00
parent 69a62fbf64
commit d67eacdd6f
4 changed files with 33 additions and 5 deletions

View File

@ -29,7 +29,8 @@
</div>
<div class="col-lg">
<h4>Statistics</h4>
<p>None yet.</p>
<p>Documents in inbox: {{statistics.documents_inbox}}</p>
<p>Total documents: {{statistics.documents_total}}</p>
<h4>Upload new Document</h4>
<form>
<ngx-file-drop

View File

@ -1,9 +1,16 @@
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { FileSystemDirectoryEntry, FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
import { SavedViewConfig } from 'src/app/data/saved-view-config';
import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
import { Observable } from 'rxjs';
import { DocumentService } from 'src/app/services/rest/document.service';
import { SavedViewConfigService } from 'src/app/services/saved-view-config.service';
import { Toast, ToastService } from 'src/app/services/toast.service';
import { environment } from 'src/environments/environment';
export interface Statistics {
documents_total?: number
documents_inbox?: number
}
@Component({
selector: 'app-dashboard',
@ -13,10 +20,11 @@ import { Toast, ToastService } from 'src/app/services/toast.service';
export class DashboardComponent implements OnInit {
constructor(private documentService: DocumentService, private toastService: ToastService,
public savedViewConfigService: SavedViewConfigService) { }
public savedViewConfigService: SavedViewConfigService, private http: HttpClient) { }
savedDashboardViews = []
statistics: Statistics = {}
ngOnInit(): void {
this.savedViewConfigService.getDashboardConfigs().forEach(config => {
@ -24,8 +32,14 @@ export class DashboardComponent implements OnInit {
this.savedDashboardViews.push({viewConfig: config, documents: result.results})
})
})
this.getStatistics().subscribe(statistics => {
this.statistics = statistics
})
}
getStatistics(): Observable<Statistics> {
return this.http.get(`${environment.apiBaseUrl}statistics/`)
}
public fileOver(event){

View File

@ -194,3 +194,14 @@ class SearchAutoCompleteView(APIView):
return Response(index.autocomplete(self.ix, term, limit))
else:
return Response([])
class StatisticsView(APIView):
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
return Response({
'documents_total': Document.objects.all().count(),
'documents_inbox': Document.objects.filter(tags__is_inbox_tag=True).distinct().count()
})

View File

@ -14,7 +14,8 @@ from documents.views import (
DocumentTypeViewSet,
SearchView,
IndexView,
SearchAutoCompleteView
SearchAutoCompleteView,
StatisticsView
)
api_router = DefaultRouter()
@ -31,6 +32,7 @@ urlpatterns = [
url(r"^api/auth/",include(('rest_framework.urls', 'rest_framework'), namespace="rest_framework")),
url(r"^api/search/autocomplete/", SearchAutoCompleteView.as_view(), name="autocomplete"),
url(r"^api/search/", SearchView.as_view(), name="search"),
url(r"^api/statistics/", StatisticsView.as_view(), name="statistics"),
url(r"^api/token/", views.obtain_auth_token), url(r"^api/", include((api_router.urls, 'drf'), namespace="drf")),
# Favicon