]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Enhancement: display current ASN in statistics (#6692)
authorDaniel <dstatzne@gmail.com>
Sun, 12 May 2024 23:58:04 +0000 (01:58 +0200)
committerGitHub <noreply@github.com>
Sun, 12 May 2024 23:58:04 +0000 (16:58 -0700)
src-ui/messages.xlf
src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html
src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.spec.ts
src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.ts
src/documents/views.py

index 3432faa57f99a106518927e9b0c0538d35ceaa6b..4be198d69a1bb7e0ec3a14c90aad09da6b5d2b63 100644 (file)
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html</context>
-          <context context-type="linenumber">66</context>
+          <context context-type="linenumber">72</context>
         </context-group>
       </trans-unit>
       <trans-unit id="7886570921510760899" datatype="html">
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html</context>
-          <context context-type="linenumber">58</context>
+          <context context-type="linenumber">64</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.html</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html</context>
-          <context context-type="linenumber">74</context>
+          <context context-type="linenumber">80</context>
         </context-group>
       </trans-unit>
       <trans-unit id="5421255270838137624" datatype="html">
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html</context>
-          <context context-type="linenumber">82</context>
+          <context context-type="linenumber">88</context>
         </context-group>
       </trans-unit>
       <trans-unit id="3188389494264426470" datatype="html">
           <context context-type="linenumber">15</context>
         </context-group>
       </trans-unit>
+      <trans-unit id="3047655754312785383" datatype="html">
+        <source>Current ASN</source>
+        <context-group purpose="location">
+          <context context-type="sourcefile">src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html</context>
+          <context context-type="linenumber">20</context>
+        </context-group>
+      </trans-unit>
       <trans-unit id="8693603235657020323" datatype="html">
         <source>Other</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.ts</context>
-          <context context-type="linenumber">65</context>
+          <context context-type="linenumber">66</context>
         </context-group>
       </trans-unit>
       <trans-unit id="8187573012244728580" datatype="html">
index 49ebc5ae50fb304a9f2c88c4180cb296923ff2cd..18f28ddfc5cb4f20a0d03c04e3fc4766c861d4b3 100644 (file)
         <ng-container i18n>Total characters</ng-container>:
         <span class="badge bg-secondary text-light rounded-pill">{{statistics?.character_count | number}}</span>
       </div>
+      @if (statistics?.current_asn) {
+        <div class="list-group-item d-flex justify-content-between align-items-center" routerLink="/documents/">
+          <ng-container i18n>Current ASN</ng-container>:
+          <span class="badge bg-secondary text-light rounded-pill">{{statistics?.current_asn | number}}</span>
+        </div>
+      }
       @if (statistics?.document_file_type_counts?.length > 1) {
         <div class="list-group-item filetypes">
           <div class="d-flex justify-content-between align-items-center my-2">
index 43ab4d248544a5ffe76ef55ae2a8f7e2d5f37c98..7d14af6ade87a2937d0d8873aa61351457e16e30 100644 (file)
@@ -189,4 +189,38 @@ describe('StatisticsWidgetComponent', () => {
       'Other(0.9%)'
     )
   })
+
+  it('should display the current ASN', () => {
+    const mockStats = {
+      current_asn: 122,
+    }
+
+    const req = httpTestingController.expectOne(
+      `${environment.apiBaseUrl}statistics/`
+    )
+
+    req.flush(mockStats)
+    fixture.detectChanges()
+
+    expect(fixture.nativeElement.textContent.replace(/\s/g, '')).toContain(
+      'CurrentASN:122'
+    )
+  })
+
+  it('should not display the current ASN if it is not available', () => {
+    const mockStats = {
+      current_asn: 0,
+    }
+
+    const req = httpTestingController.expectOne(
+      `${environment.apiBaseUrl}statistics/`
+    )
+
+    req.flush(mockStats)
+    fixture.detectChanges()
+
+    expect(fixture.nativeElement.textContent.replace(/\s/g, '')).not.toContain(
+      'CurrentASN:'
+    )
+  })
 })
index 01799e9ac1c1caba80106f9e7ab0107b4d5c67c3..e52a9b69c7b435784c2dabc9384824d1a2d9a81f 100644 (file)
@@ -18,6 +18,7 @@ export interface Statistics {
   correspondent_count?: number
   document_type_count?: number
   storage_path_count?: number
+  current_asn?: number
 }
 
 interface DocumentFileType {
index 6005b19384844e88d469b0c5223cdcfcc482383d..89a4a90111ab696637e64a2aaab642ff2edb118c 100644 (file)
@@ -1414,6 +1414,12 @@ class StatisticsView(APIView):
             .get("characters__sum")
         )
 
+        current_asn = Document.objects.aggregate(
+            Max("archive_serial_number", default=0),
+        ).get(
+            "archive_serial_number__max",
+        )
+
         return Response(
             {
                 "documents_total": documents_total,
@@ -1425,6 +1431,7 @@ class StatisticsView(APIView):
                 "correspondent_count": correspondent_count,
                 "document_type_count": document_type_count,
                 "storage_path_count": storage_path_count,
+                "current_asn": current_asn,
             },
         )