diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index 70619e4eb..574931911 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -84,8 +84,6 @@ export class AppComponent { this.http.authReqEnabled = true this.showMenu = true this.patch.start() - // watch patch DB to display name and unread count - this.watchPatch() this.connectionService.start() // watch connection to display connectivity issues this.watchConnection(auth) @@ -111,13 +109,6 @@ export class AppComponent { }) } - watchPatch (): void { - this.patch.watch$('server-info', 'unread-notification-count') - .subscribe(unread => { - this.unreadCount = unread - }) - } - private watchConnection (auth: AuthState): void { this.connectionService.watchFailure$() .pipe( @@ -194,6 +185,7 @@ export class AppComponent { finalize(() => console.log('FINALIZING!!!')), ) .subscribe(count => { + this.unreadCount = count if (previous !== undefined && count > previous) this.presentToastNotifications() previous = count }) diff --git a/ui/src/app/components/status/status.component.ts b/ui/src/app/components/status/status.component.ts index 22aa9fd78..6e2a2d7a1 100644 --- a/ui/src/app/components/status/status.component.ts +++ b/ui/src/app/components/status/status.component.ts @@ -1,5 +1,7 @@ import { Component, Input } from '@angular/core' -import { PackageDataEntry } from 'src/app/services/patch-db/data-model' +import { BehaviorSubject } from 'rxjs' +import { PackageDataEntry, PackageMainStatus, PackageState } from 'src/app/services/patch-db/data-model' +import { PatchDbModel } from 'src/app/services/patch-db/patch-db.service' import { renderPkgStatus } from 'src/app/services/pkg-status-rendering.service' @Component({ @@ -8,17 +10,35 @@ import { renderPkgStatus } from 'src/app/services/pkg-status-rendering.service' styleUrls: ['./status.component.scss'], }) export class StatusComponent { - @Input() pkg: PackageDataEntry - @Input() connected: boolean + @Input() pkgId: string @Input() size?: 'small' | 'medium' | 'large' = 'large' @Input() style?: string = 'regular' @Input() weight?: string = 'normal' display = '' color = '' showDots = false + subs = [] + pkg: PackageDataEntry - ngOnChanges () { - const { display, color, showDots } = renderPkgStatus(this.pkg) + constructor ( + private readonly patch: PatchDbModel, + ) { } + + ngOnInit () { + this.subs = [ + this.patch.watch$('package-data', this.pkgId, 'installed', 'status', 'main', 'status').subscribe(_ => { + this.pkg = this.patch.data['package-data'][this.pkgId] + this.render(this.pkg) + }), + ] + } + + ngOnDestroy () { + this.subs.forEach(sub => sub.unsubscribe()) + } + + private render (pkg: PackageDataEntry) { + const { display, color, showDots } = renderPkgStatus(pkg.state, pkg.installed.status) this.display = display this.color = color this.showDots = showDots diff --git a/ui/src/app/pages/apps-routes/app-list/app-list.page.html b/ui/src/app/pages/apps-routes/app-list/app-list.page.html index f3e50d01b..e2b6fa975 100644 --- a/ui/src/app/pages/apps-routes/app-list/app-list.page.html +++ b/ui/src/app/pages/apps-routes/app-list/app-list.page.html @@ -33,13 +33,13 @@ icon - - - - + + + + - + {{ (pkg.value | manifest).title }} diff --git a/ui/src/app/pages/apps-routes/app-metrics/app-metrics.page.ts b/ui/src/app/pages/apps-routes/app-metrics/app-metrics.page.ts index a6cad8960..953788227 100644 --- a/ui/src/app/pages/apps-routes/app-metrics/app-metrics.page.ts +++ b/ui/src/app/pages/apps-routes/app-metrics/app-metrics.page.ts @@ -1,7 +1,6 @@ import { Component, ViewChild } from '@angular/core' import { ActivatedRoute } from '@angular/router' import { IonContent } from '@ionic/angular' -import { Subscription } from 'rxjs' import { PackageDataEntry } from 'src/app/services/patch-db/data-model' import { PatchDbModel } from 'src/app/services/patch-db/patch-db.service' @@ -14,7 +13,6 @@ export class AppMetricsPage { pkg: PackageDataEntry @ViewChild(IonContent) content: IonContent - subs: Subscription[] = [] constructor ( private readonly route: ActivatedRoute, @@ -23,23 +21,13 @@ export class AppMetricsPage { ngOnInit () { const pkgId = this.route.snapshot.paramMap.get('pkgId') - - this.subs = [ - this.patch.watch$('package-data', pkgId) - .subscribe(pkg => { - this.pkg = pkg - }), - ] + this.pkg = this.patch.data['package-data'][pkgId] } ngAfterViewInit () { this.content.scrollToPoint(undefined, 1) } - ngOnDestroy () { - this.subs.forEach(sub => sub.unsubscribe()) - } - asIsOrder (a: any, b: any) { return 0 } diff --git a/ui/src/app/pages/apps-routes/app-show/app-show.page.html b/ui/src/app/pages/apps-routes/app-show/app-show.page.html index 5315d6111..3d00a6d18 100644 --- a/ui/src/app/pages/apps-routes/app-show/app-show.page.html +++ b/ui/src/app/pages/apps-routes/app-show/app-show.page.html @@ -11,7 +11,6 @@ - {{ error }} @@ -30,19 +29,19 @@
{{ manifest.version | displayEmver }}
- +
- - + + Configure - + Stop - + Fix - + Start
@@ -68,20 +67,20 @@ - + Dependencies - - + + - + -

{{ localDep ? (localDep | manifest).title : pkg.installed.status['dependency-errors'][dep.key]?.title }}

+

{{ patch.data['package-data'][dep.key] ? (patch.data['package-data'][dep.key] | manifest).title : pkg.installed.status['dependency-errors'][dep.key]?.title }}

{{ manifest.dependencies[dep.key].version | displayEmver }}

{{ pkg.installed.status['dependency-errors'][dep.key] ? pkg.installed.status['dependency-errors'][dep.key].type : 'satisfied' }}

@@ -91,11 +90,11 @@ - + Install - + Start @@ -107,8 +106,8 @@ -
- +
+
diff --git a/ui/src/app/pages/apps-routes/app-show/app-show.page.ts b/ui/src/app/pages/apps-routes/app-show/app-show.page.ts index b906e333b..b899ba5b7 100644 --- a/ui/src/app/pages/apps-routes/app-show/app-show.page.ts +++ b/ui/src/app/pages/apps-routes/app-show/app-show.page.ts @@ -48,11 +48,10 @@ export class AppShowPage { async ngOnInit () { this.pkgId = this.route.snapshot.paramMap.get('pkgId') + this.pkg = this.patch.data['package-data'][this.pkgId] + // @TODO re-fetch manifest if package state changes. + this.manifest = getManifest(this.pkg) this.subs = [ - this.patch.watch$('package-data', this.pkgId).subscribe(pkg => { - this.pkg = pkg - this.manifest = getManifest(this.pkg) - }), this.patch.connected$().subscribe(c => this.connected = c), ] this.setButtons() @@ -62,7 +61,7 @@ export class AppShowPage { this.content.scrollToPoint(undefined, 1) } - async ngOnDestroy () { + ngOnDestroy () { this.subs.forEach(sub => sub.unsubscribe()) } diff --git a/ui/src/app/pipes/display-bulb.pipe.ts b/ui/src/app/pipes/display-bulb.pipe.ts index 003245bc1..3d99d99ac 100644 --- a/ui/src/app/pipes/display-bulb.pipe.ts +++ b/ui/src/app/pipes/display-bulb.pipe.ts @@ -1,5 +1,6 @@ import { Pipe, PipeTransform } from '@angular/core' -import { PackageDataEntry } from '../services/patch-db/data-model' +import { PackageState, Status } from '../services/patch-db/data-model' +import { PatchDbModel } from '../services/patch-db/patch-db.service' import { renderPkgStatus } from '../services/pkg-status-rendering.service' @Pipe({ @@ -7,9 +8,14 @@ import { renderPkgStatus } from '../services/pkg-status-rendering.service' }) export class DisplayBulbPipe implements PipeTransform { - transform (pkg: PackageDataEntry, bulb: DisplayBulb, connected: boolean): boolean { + constructor ( + private readonly patch: PatchDbModel, + ) { } + + transform (pkgId: string, bulb: DisplayBulb, connected: boolean): boolean { + const pkg = this.patch.data['package-data'][pkgId] if (!connected) return bulb === 'off' - const { color } = renderPkgStatus(pkg) + const { color } = renderPkgStatus(pkg.state, pkg.installed.status) switch (color) { case 'danger': return bulb === 'red' case 'success': return bulb === 'green' diff --git a/ui/src/app/pipes/status.pipe.ts b/ui/src/app/pipes/status.pipe.ts index 85ba8b365..0a7826dbf 100644 --- a/ui/src/app/pipes/status.pipe.ts +++ b/ui/src/app/pipes/status.pipe.ts @@ -1,12 +1,19 @@ import { Pipe, PipeTransform } from '@angular/core' -import { PackageDataEntry } from '../services/patch-db/data-model' +import { PatchDbModel } from '../services/patch-db/patch-db.service' import { FEStatus, renderPkgStatus } from '../services/pkg-status-rendering.service' @Pipe({ name: 'status', }) export class StatusPipe implements PipeTransform { - transform (pkg: PackageDataEntry): FEStatus { - return renderPkgStatus(pkg).feStatus + + constructor ( + private readonly patch: PatchDbModel, + ) { } + + transform (pkgId: string): FEStatus { + console.log(pkgId) + const pkg = this.patch.data['package-data'][pkgId] + return renderPkgStatus(pkg.state, pkg.installed.status).feStatus } } \ No newline at end of file diff --git a/ui/src/app/services/api/mock-api.service.ts b/ui/src/app/services/api/mock-api.service.ts index 9da2b921b..d7f452c3d 100644 --- a/ui/src/app/services/api/mock-api.service.ts +++ b/ui/src/app/services/api/mock-api.service.ts @@ -9,7 +9,6 @@ import { parsePropertiesPermissive } from 'src/app/util/properties.util' import { Mock } from './mock-app-fixures' import { HttpService } from '../http.service' import markdown from 'raw-loader!src/assets/markdown/md-sample.md' -import { map } from 'rxjs/operators' @Injectable() export class MockApiService extends ApiService { @@ -22,10 +21,9 @@ export class MockApiService extends ApiService { // every time a patch is returned from the mock, we override its sequence to be 1 more than the last sequence in the patch-db as provided by `o`. watch$ (store: Store): Observable> { - store.watchCache$().pipe(map(cache => cache.sequence)).subscribe(seq => { + store.sequence$.subscribe(seq => { console.log('INCOMING: ', seq) if (this.sequence < seq) { - console.log('hererereree') this.sequence = seq } }) diff --git a/ui/src/app/services/patch-db/local-storage-bootstrap.ts b/ui/src/app/services/patch-db/local-storage-bootstrap.ts index 5cddf1a86..c28a45cc2 100644 --- a/ui/src/app/services/patch-db/local-storage-bootstrap.ts +++ b/ui/src/app/services/patch-db/local-storage-bootstrap.ts @@ -15,7 +15,7 @@ export class LocalStorageBootstrap implements Bootstrapper { async init (): Promise> { const cache: DBCache = await this.storage.get(LocalStorageBootstrap.CONTENT_KEY) - return cache || { sequence: 0, data: { } } + return cache || { sequence: 0, data: { } as DataModel } } async update (cache: DBCache): Promise { diff --git a/ui/src/app/services/patch-db/patch-db.service.ts b/ui/src/app/services/patch-db/patch-db.service.ts index ca66e8dd6..d6f8e4426 100644 --- a/ui/src/app/services/patch-db/patch-db.service.ts +++ b/ui/src/app/services/patch-db/patch-db.service.ts @@ -18,6 +18,7 @@ export enum ConnectionStatus { }) export class PatchDbModel { connectionStatus$ = new BehaviorSubject(ConnectionStatus.Initializing) + data: DataModel private patchDb: PatchDB private patchSub: Subscription @@ -29,6 +30,7 @@ export class PatchDbModel { async init (): Promise { const cache = await this.bootstrapper.init() this.patchDb = new PatchDB(this.sources, cache) + this.data = this.patchDb.store.cache.data } start (): void { @@ -75,7 +77,7 @@ export class PatchDbModel { return this.connectionStatus$.asObservable() } - watch$: Store ['watch$'] = (...args: (string | number)[]): Observable => { + watch$: Store['watch$'] = (...args: (string | number)[]): Observable => { // console.log('WATCHING') return this.patchDb.store.watch$(...(args as [])).pipe( tap(cache => console.log('CHANGE IN STORE', cache)), diff --git a/ui/src/app/services/pkg-status-rendering.service.ts b/ui/src/app/services/pkg-status-rendering.service.ts index fbcf06422..4fba04e29 100644 --- a/ui/src/app/services/pkg-status-rendering.service.ts +++ b/ui/src/app/services/pkg-status-rendering.service.ts @@ -1,11 +1,11 @@ -import { HealthCheckResultLoading, MainStatusRunning, PackageDataEntry, PackageMainStatus, PackageState, Status } from './patch-db/data-model' +import { HealthCheckResultLoading, MainStatusRunning, PackageMainStatus, PackageState, Status } from './patch-db/data-model' -export function renderPkgStatus (pkg: PackageDataEntry): PkgStatusRendering { - switch (pkg.state) { +export function renderPkgStatus (state: PackageState, status: Status): PkgStatusRendering { + switch (state) { case PackageState.Installing: return { display: 'Installing', color: 'primary', showDots: true, feStatus: FEStatus.Installing } case PackageState.Updating: return { display: 'Updating', color: 'primary', showDots: true, feStatus: FEStatus.Updating } case PackageState.Removing: return { display: 'Removing', color: 'warning', showDots: true, feStatus: FEStatus.Removing } - case PackageState.Installed: return handleInstalledState(pkg.installed.status) + case PackageState.Installed: return handleInstalledState(status) } }