Files
start-os/web/projects/ui/src/app/pipes/install-progress/install-progress.pipe.ts
Matt Hill ab465a755e default to all category and fix rounding for progress (#2682)
* default to all category and fix rounding for progress

* Update install-progress.pipe.ts
2024-07-24 22:40:13 -06:00

28 lines
878 B
TypeScript

import { Pipe, PipeTransform } from '@angular/core'
import { T } from '@start9labs/start-sdk'
@Pipe({
name: 'installingProgressString',
})
export class InstallingProgressDisplayPipe implements PipeTransform {
transform(progress: T.Progress): string {
if (progress === true) return 'finalizing'
if (progress === false || progress === null || !progress.total)
return 'unknown %'
const percentage = Math.round((100 * progress.done) / progress.total)
return percentage < 99 ? String(percentage) + '%' : 'finalizing'
}
}
@Pipe({
name: 'installingProgress',
})
export class InstallingProgressPipe implements PipeTransform {
transform(progress: T.Progress): number {
if (progress === true) return 100
if (progress === false || progress === null || !progress.total) return 0
return Math.floor((100 * progress.done) / progress.total)
}
}