mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Implement isNumber pipe
This commit is contained in:
parent
0b4e8141b0
commit
3dda02660c
@ -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,
|
||||
|
@ -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>
|
||||
|
@ -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: [
|
||||
|
@ -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>
|
||||
|
@ -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: [
|
||||
|
@ -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,
|
||||
|
13
src-ui/src/app/pipes/is-number.pipe.spec.ts
Normal file
13
src-ui/src/app/pipes/is-number.pipe.spec.ts
Normal 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()
|
||||
})
|
||||
})
|
10
src-ui/src/app/pipes/is-number.pipe.ts
Normal file
10
src-ui/src/app/pipes/is-number.pipe.ts
Normal 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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user