Implement isNumber pipe

This commit is contained in:
shamoon 2023-08-12 08:31:42 -07:00
parent 0b4e8141b0
commit 3dda02660c
8 changed files with 33 additions and 3 deletions

View 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 { PermissionsFilterDropdownComponent } from './components/common/permissions-filter-dropdown/permissions-filter-dropdown.component'
import { UsernamePipe } from './pipes/username.pipe' import { UsernamePipe } from './pipes/username.pipe'
import { LogoComponent } from './components/common/logo/logo.component' import { LogoComponent } from './components/common/logo/logo.component'
import { IsNumberPipe } from './pipes/is-number.pipe'
import localeAr from '@angular/common/locales/ar' import localeAr from '@angular/common/locales/ar'
import localeBe from '@angular/common/locales/be' import localeBe from '@angular/common/locales/be'
@ -223,6 +224,7 @@ function initializeApp(settings: SettingsService) {
PermissionsFilterDropdownComponent, PermissionsFilterDropdownComponent,
UsernamePipe, UsernamePipe,
LogoComponent, LogoComponent,
IsNumberPipe,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View File

@ -87,7 +87,7 @@
</svg> </svg>
<small>{{(document.storage_path$ | async)?.name}}</small> <small>{{(document.storage_path$ | async)?.name}}</small>
</button> </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"> <svg class="metadata-icon me-2 text-muted" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#upc-scan"/> <use xlink:href="assets/bootstrap-icons.svg#upc-scan"/>
</svg> </svg>

View File

@ -18,6 +18,7 @@ import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe' import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe' import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
import { DocumentCardLargeComponent } from './document-card-large.component' import { DocumentCardLargeComponent } from './document-card-large.component'
import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
const doc = { const doc = {
id: 10, id: 10,
@ -48,6 +49,7 @@ describe('DocumentCardLargeComponent', () => {
CustomDatePipe, CustomDatePipe,
IfPermissionsDirective, IfPermissionsDirective,
SafeUrlPipe, SafeUrlPipe,
IsNumberPipe,
], ],
providers: [DatePipe], providers: [DatePipe],
imports: [ imports: [

View File

@ -65,7 +65,7 @@
<small>{{document.created_date | customDate:'mediumDate'}}</small> <small>{{document.created_date | customDate:'mediumDate'}}</small>
</div> </div>
</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"> <svg class="metadata-icon me-2 text-muted" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#upc-scan"/> <use xlink:href="assets/bootstrap-icons.svg#upc-scan"/>
</svg> </svg>

View File

@ -21,6 +21,7 @@ import { of } from 'rxjs'
import { By } from '@angular/platform-browser' import { By } from '@angular/platform-browser'
import { TagComponent } from '../../common/tag/tag.component' import { TagComponent } from '../../common/tag/tag.component'
import { PaperlessTag } from 'src/app/data/paperless-tag' import { PaperlessTag } from 'src/app/data/paperless-tag'
import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
const doc = { const doc = {
id: 10, id: 10,
@ -62,6 +63,7 @@ describe('DocumentCardSmallComponent', () => {
IfPermissionsDirective, IfPermissionsDirective,
SafeUrlPipe, SafeUrlPipe,
TagComponent, TagComponent,
IsNumberPipe,
], ],
providers: [DatePipe], providers: [DatePipe],
imports: [ imports: [

View File

@ -17,7 +17,6 @@ import {
NgbDropdownModule, NgbDropdownModule,
NgbModal, NgbModal,
NgbModalRef, NgbModalRef,
NgbPagination,
NgbPopoverModule, NgbPopoverModule,
NgbTooltipModule, NgbTooltipModule,
} from '@ng-bootstrap/ng-bootstrap' } from '@ng-bootstrap/ng-bootstrap'
@ -63,6 +62,7 @@ import { HttpErrorResponse } from '@angular/common/http'
import { PermissionsGuard } from 'src/app/guards/permissions.guard' import { PermissionsGuard } from 'src/app/guards/permissions.guard'
import { SettingsService } from 'src/app/services/settings.service' import { SettingsService } from 'src/app/services/settings.service'
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings' import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
const docs: PaperlessDocument[] = [ const docs: PaperlessDocument[] = [
{ {
@ -126,6 +126,7 @@ describe('DocumentListComponent', () => {
DocumentTitlePipe, DocumentTitlePipe,
UsernamePipe, UsernamePipe,
SafeHtmlPipe, SafeHtmlPipe,
IsNumberPipe,
], ],
providers: [ providers: [
FilterPipe, FilterPipe,

View File

@ -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()
})
})

View File

@ -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)
}
}