]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Implement isNumber pipe 3988/head
authorshamoon <4887959+shamoon@users.noreply.github.com>
Sat, 12 Aug 2023 15:31:42 +0000 (08:31 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Sat, 12 Aug 2023 15:31:42 +0000 (08:31 -0700)
src-ui/src/app/app.module.ts
src-ui/src/app/components/document-list/document-card-large/document-card-large.component.html
src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts
src-ui/src/app/components/document-list/document-card-small/document-card-small.component.html
src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts
src-ui/src/app/components/document-list/document-list.component.spec.ts
src-ui/src/app/pipes/is-number.pipe.spec.ts [new file with mode: 0644]
src-ui/src/app/pipes/is-number.pipe.ts [new file with mode: 0644]

index 7a94f4316a6d23cd251d5438208b645f1c763837..f5b30467c817fe15e84a28027d7732bd320066aa 100644 (file)
@@ -93,6 +93,7 @@ import { PermissionsFormComponent } from './components/common/input/permissions/
 import { PermissionsFilterDropdownComponent } from './components/common/permissions-filter-dropdown/permissions-filter-dropdown.component'
 import { UsernamePipe } from './pipes/username.pipe'
 import { LogoComponent } from './components/common/logo/logo.component'
+import { IsNumberPipe } from './pipes/is-number.pipe'
 
 import localeAr from '@angular/common/locales/ar'
 import localeBe from '@angular/common/locales/be'
@@ -223,6 +224,7 @@ function initializeApp(settings: SettingsService) {
     PermissionsFilterDropdownComponent,
     UsernamePipe,
     LogoComponent,
+    IsNumberPipe,
   ],
   imports: [
     BrowserModule,
index 296f5af0638e697d18872ab344fe871b5f93a87a..5bc27c8a14103afd325b9a39149e0225b9aa2ad2 100644 (file)
@@ -87,7 +87,7 @@
               </svg>
               <small>{{(document.storage_path$ | async)?.name}}</small>
             </button>
-            <div *ngIf="document.archive_serial_number" class="list-group-item me-2 bg-light text-dark p-1 border-0">
+            <div *ngIf="document.archive_serial_number | isNumber" class="list-group-item me-2 bg-light text-dark p-1 border-0">
               <svg class="metadata-icon me-2 text-muted" fill="currentColor">
                 <use xlink:href="assets/bootstrap-icons.svg#upc-scan"/>
               </svg>
index 407bb01c42a8beb0088e61f0b81e804446789ef4..7b3d0a5bb6dc4e92281f6df56965076ef14e9264 100644 (file)
@@ -18,6 +18,7 @@ import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
 import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
 import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
 import { DocumentCardLargeComponent } from './document-card-large.component'
+import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
 
 const doc = {
   id: 10,
@@ -48,6 +49,7 @@ describe('DocumentCardLargeComponent', () => {
         CustomDatePipe,
         IfPermissionsDirective,
         SafeUrlPipe,
+        IsNumberPipe,
       ],
       providers: [DatePipe],
       imports: [
index d1b8aff95ac43fab4cc8cd44d23b0128410b6488..98d8e2770e6505f662ef410631dee465da324d14 100644 (file)
@@ -65,7 +65,7 @@
             <small>{{document.created_date | customDate:'mediumDate'}}</small>
           </div>
         </div>
-        <div *ngIf="document.archive_serial_number" class="ps-0 p-1">
+        <div *ngIf="document.archive_serial_number | isNumber" class="ps-0 p-1">
           <svg class="metadata-icon me-2 text-muted" fill="currentColor">
             <use xlink:href="assets/bootstrap-icons.svg#upc-scan"/>
           </svg>
index 67081cbd505d5a53ac3e46f5dccb91aa915eef25..b4b5efe11eaf78befd2869c5c6f5ef57a4381c8b 100644 (file)
@@ -21,6 +21,7 @@ import { of } from 'rxjs'
 import { By } from '@angular/platform-browser'
 import { TagComponent } from '../../common/tag/tag.component'
 import { PaperlessTag } from 'src/app/data/paperless-tag'
+import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
 
 const doc = {
   id: 10,
@@ -62,6 +63,7 @@ describe('DocumentCardSmallComponent', () => {
         IfPermissionsDirective,
         SafeUrlPipe,
         TagComponent,
+        IsNumberPipe,
       ],
       providers: [DatePipe],
       imports: [
index 6e6dd8f6c3c6f712bdbb13a4280f4bf294595bbc..525ac50b25d2b395c09b749d4c797009b2ea3aea 100644 (file)
@@ -17,7 +17,6 @@ import {
   NgbDropdownModule,
   NgbModal,
   NgbModalRef,
-  NgbPagination,
   NgbPopoverModule,
   NgbTooltipModule,
 } from '@ng-bootstrap/ng-bootstrap'
@@ -63,6 +62,7 @@ import { HttpErrorResponse } from '@angular/common/http'
 import { PermissionsGuard } from 'src/app/guards/permissions.guard'
 import { SettingsService } from 'src/app/services/settings.service'
 import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
+import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
 
 const docs: PaperlessDocument[] = [
   {
@@ -126,6 +126,7 @@ describe('DocumentListComponent', () => {
         DocumentTitlePipe,
         UsernamePipe,
         SafeHtmlPipe,
+        IsNumberPipe,
       ],
       providers: [
         FilterPipe,
diff --git a/src-ui/src/app/pipes/is-number.pipe.spec.ts b/src-ui/src/app/pipes/is-number.pipe.spec.ts
new file mode 100644 (file)
index 0000000..227ea55
--- /dev/null
@@ -0,0 +1,13 @@
+import { IsNumberPipe } from './is-number.pipe'
+
+describe('IsNumberPipe', () => {
+  it('should detect numbers', () => {
+    const pipe = new IsNumberPipe()
+    expect(pipe.transform(0)).toBeTruthy()
+    expect(pipe.transform(123)).toBeTruthy()
+    expect(pipe.transform('123')).toBeFalsy()
+    expect(pipe.transform(null)).toBeFalsy()
+    expect(pipe.transform(undefined)).toBeFalsy()
+    expect(pipe.transform(NaN)).toBeFalsy()
+  })
+})
diff --git a/src-ui/src/app/pipes/is-number.pipe.ts b/src-ui/src/app/pipes/is-number.pipe.ts
new file mode 100644 (file)
index 0000000..2e1014a
--- /dev/null
@@ -0,0 +1,10 @@
+import { Pipe, PipeTransform } from '@angular/core'
+
+@Pipe({
+  name: 'isNumber',
+})
+export class IsNumberPipe implements PipeTransform {
+  transform(value: any): boolean {
+    return typeof value === 'number' && !isNaN(value)
+  }
+}