mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
0.2.5 initial commit
Makefile incomplete
This commit is contained in:
33
ui/src/app/pipes/annotation-status.pipe.ts
Normal file
33
ui/src/app/pipes/annotation-status.pipe.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { Annotation } from '../app-config/config-utilities'
|
||||
|
||||
@Pipe({
|
||||
name: 'annotationStatus',
|
||||
})
|
||||
export class AnnotationStatusPipe implements PipeTransform {
|
||||
transform (a: Annotation, target: FieldStatus): boolean {
|
||||
return target === getStatus(a)
|
||||
}
|
||||
}
|
||||
|
||||
function getStatus (a: Annotation): FieldStatus {
|
||||
if (isInvalid(a)) return 'Invalid'
|
||||
if (isEdited(a)) return 'Edited'
|
||||
if (isAdded(a)) return 'Added'
|
||||
return 'NoChange'
|
||||
}
|
||||
|
||||
function isInvalid (a: Annotation): boolean {
|
||||
return !!a.invalid
|
||||
}
|
||||
|
||||
// edited only registers if its a valid edit
|
||||
function isEdited (a: Annotation): boolean {
|
||||
return a.edited && !a.invalid
|
||||
}
|
||||
|
||||
function isAdded (a: Annotation): boolean {
|
||||
return a.added && !a.edited && !a.invalid
|
||||
}
|
||||
|
||||
type FieldStatus = 'Edited' | 'Added' | 'Invalid' | 'NoChange'
|
||||
21
ui/src/app/pipes/display-bulb.pipe.ts
Normal file
21
ui/src/app/pipes/display-bulb.pipe.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { AppStatus } from '../models/app-model'
|
||||
import { AppStatusRendering } from '../util/status-rendering'
|
||||
|
||||
@Pipe({
|
||||
name: 'displayBulb',
|
||||
})
|
||||
export class DisplayBulbPipe implements PipeTransform {
|
||||
|
||||
transform (status: AppStatus, d: DisplayBulb): boolean {
|
||||
switch (AppStatusRendering[status].color) {
|
||||
case 'danger': return d === 'red'
|
||||
case 'success': return d === 'green'
|
||||
case 'warning': return d === 'yellow'
|
||||
default: return d === 'off'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type DisplayBulb = 'off' | 'red' | 'green' | 'yellow'
|
||||
64
ui/src/app/pipes/emver.pipe.ts
Normal file
64
ui/src/app/pipes/emver.pipe.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { Emver } from '../services/emver.service'
|
||||
@Pipe({
|
||||
name: 'satisfiesEmver',
|
||||
})
|
||||
export class EmverSatisfiesPipe implements PipeTransform {
|
||||
constructor (private readonly emver: Emver) { }
|
||||
|
||||
transform (versionUnderTest: string, range: string): boolean {
|
||||
return this.emver.satisfies(versionUnderTest, range)
|
||||
}
|
||||
}
|
||||
|
||||
@Pipe({
|
||||
name: 'compareEmver',
|
||||
})
|
||||
export class EmverComparesPipe implements PipeTransform {
|
||||
constructor (private readonly emver: Emver) { }
|
||||
|
||||
transform (first: string, second: string): SemverResult {
|
||||
try {
|
||||
return this.emver.compare(first, second) as SemverResult
|
||||
} catch (e) {
|
||||
console.warn(`emver comparison failed`, e, first, second)
|
||||
return 'comparison-impossible'
|
||||
}
|
||||
}
|
||||
}
|
||||
type SemverResult = 0 | 1 | -1 | 'comparison-impossible'
|
||||
|
||||
@Pipe({
|
||||
name: 'displayEmver',
|
||||
})
|
||||
export class EmverDisplayPipe implements PipeTransform {
|
||||
constructor () { }
|
||||
|
||||
transform (version: string): string {
|
||||
return displayEmver(version)
|
||||
}
|
||||
}
|
||||
|
||||
@Pipe({
|
||||
name: 'isValidEmver',
|
||||
})
|
||||
export class EmverIsValidPipe implements PipeTransform {
|
||||
constructor () { }
|
||||
|
||||
transform (version: string): boolean {
|
||||
return isValidEmver(version)
|
||||
}
|
||||
}
|
||||
|
||||
export function isValidEmver (version: string): boolean {
|
||||
const vs = version.split('.')
|
||||
if (vs.length < 3 || vs.length > 5) return false
|
||||
if (!vs.every(v => !isNaN(parseFloat(v)))) return false
|
||||
return true
|
||||
}
|
||||
|
||||
export function displayEmver (version: string): string {
|
||||
const vs = version.split('.')
|
||||
if (vs.length === 4) return `${vs[0]}.${vs[1]}.${vs[2]}~${vs[3]}`
|
||||
return version
|
||||
}
|
||||
11
ui/src/app/pipes/icon.pipe.ts
Normal file
11
ui/src/app/pipes/icon.pipe.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'iconParse',
|
||||
})
|
||||
export class IconPipe implements PipeTransform {
|
||||
transform (iconUrl: string): string {
|
||||
if (iconUrl.startsWith('/')) return '/api' + iconUrl
|
||||
return iconUrl
|
||||
}
|
||||
}
|
||||
10
ui/src/app/pipes/includes.pipe.ts
Normal file
10
ui/src/app/pipes/includes.pipe.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'includes',
|
||||
})
|
||||
export class IncludesPipe implements PipeTransform {
|
||||
transform<T> (set: T[], val: T): boolean {
|
||||
return set.includes(val)
|
||||
}
|
||||
}
|
||||
46
ui/src/app/pipes/installed-latest-comparison.pipe.ts
Normal file
46
ui/src/app/pipes/installed-latest-comparison.pipe.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import { combineLatest, Observable } from 'rxjs'
|
||||
import { map } from 'rxjs/operators'
|
||||
import { AppAvailableFull, AppAvailablePreview } from 'src/app/models/app-types'
|
||||
import { Emver } from '../services/emver.service'
|
||||
import { PropertySubject } from '../util/property-subject.util'
|
||||
|
||||
@Pipe({
|
||||
name: 'compareInstalledAndLatest',
|
||||
})
|
||||
export class InstalledLatestComparisonPipe implements PipeTransform {
|
||||
constructor (private readonly emver: Emver) { }
|
||||
|
||||
transform (app: PropertySubject<AppAvailablePreview>): Observable<'not-installed' | 'installed-below' | 'installed-above' | 'installed-equal'> {
|
||||
return combineLatest([app.versionInstalled, app.versionLatest]).pipe(
|
||||
map(([i, l]) => {
|
||||
if (!i) return 'not-installed'
|
||||
switch (this.emver.compare(i, l)){
|
||||
case 0: return 'installed-equal'
|
||||
case 1: return 'installed-above'
|
||||
case -1: return 'installed-below'
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Pipe({
|
||||
name: 'compareInstalledAndViewing',
|
||||
})
|
||||
export class InstalledViewingComparisonPipe implements PipeTransform {
|
||||
constructor (private readonly emver: Emver) { }
|
||||
|
||||
transform (app: PropertySubject<AppAvailableFull>): Observable<'not-installed' | 'installed-below' | 'installed-above' | 'installed-equal'> {
|
||||
return combineLatest([app.versionInstalled, app.versionViewing]).pipe(
|
||||
map(([i, l]) => {
|
||||
if (!i) return 'not-installed'
|
||||
switch (this.emver.compare(i, l)){
|
||||
case 0: return 'installed-equal'
|
||||
case 1: return 'installed-above'
|
||||
case -1: return 'installed-below'
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
14
ui/src/app/pipes/markdown.pipe.ts
Normal file
14
ui/src/app/pipes/markdown.pipe.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
import * as marked from 'marked'
|
||||
|
||||
@Pipe({
|
||||
name: 'markdown',
|
||||
})
|
||||
export class MarkdownPipe implements PipeTransform {
|
||||
transform (value: any): any {
|
||||
if (value && value.length > 0) {
|
||||
return marked(value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
12
ui/src/app/pipes/mask.pipe.ts
Normal file
12
ui/src/app/pipes/mask.pipe.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'mask',
|
||||
})
|
||||
export class MaskPipe implements PipeTransform {
|
||||
transform (val: string, max = 16): string {
|
||||
if (!val) return val
|
||||
const times = val.length <= max ? val.length : max
|
||||
return '●'.repeat(times)
|
||||
}
|
||||
}
|
||||
11
ui/src/app/pipes/peek-properties.pipe.ts
Normal file
11
ui/src/app/pipes/peek-properties.pipe.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { peekProperties, PropertySubject } from '../util/property-subject.util'
|
||||
|
||||
@Pipe({
|
||||
name: 'peekProperties',
|
||||
})
|
||||
export class PeekPropertiesPipe implements PipeTransform {
|
||||
transform<T> (value: PropertySubject<T>): T {
|
||||
return peekProperties(value)
|
||||
}
|
||||
}
|
||||
32
ui/src/app/pipes/truncate.pipe.ts
Normal file
32
ui/src/app/pipes/truncate.pipe.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'truncateCenter',
|
||||
})
|
||||
export class TruncateCenterPipe implements PipeTransform {
|
||||
transform (value: string, front: number, back: number, fullOnDesktop: boolean = false): unknown {
|
||||
if (value.length <= front + back + 3) return value
|
||||
if (fullOnDesktop && screen.width > 500) return value
|
||||
return value.slice(0, front) + '...' + value.slice(value.length - back, value.length)
|
||||
}
|
||||
}
|
||||
|
||||
@Pipe({
|
||||
name: 'truncateEnd',
|
||||
})
|
||||
export class TruncateEndPipe implements PipeTransform {
|
||||
transform (val: string, length: number): unknown {
|
||||
if (val.length <= length) return val
|
||||
return val.slice(0, length) + '...'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 4 and 4
|
||||
|
||||
// 12345678 => 12345678
|
||||
// 123456789 => 123456789
|
||||
// 1234567890 => 1234567890
|
||||
// 12345678901 => 12345678901
|
||||
// 1234...9012 => 1234...9012
|
||||
// 1234...0123 => 1234...0123
|
||||
10
ui/src/app/pipes/typeof.pipe.ts
Normal file
10
ui/src/app/pipes/typeof.pipe.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core'
|
||||
|
||||
@Pipe({
|
||||
name: 'typeof',
|
||||
})
|
||||
export class TypeofPipe implements PipeTransform {
|
||||
transform (value: any): any {
|
||||
return typeof value
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user