diff --git a/ui/src/app/app.component.html b/ui/src/app/app.component.html index 60766bd53..87644b14b 100644 --- a/ui/src/app/app.component.html +++ b/ui/src/app/app.component.html @@ -1,166 +1,175 @@ - - - -
- -
-
- - - - - + + + +
+ +
+
+ + + - {{ page.title }} -
- {{ unreadCount }} -
-
-
-
-
- - - + - Log Out - - - -
+ {{ page.title }} + + {{ unreadCount }} + + + +
+
+ + + + Log Out + + + +
+
+
+ + +
+ + + +
diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index 9910bffed..c2d594202 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -74,9 +74,8 @@ export class AppComponent { private readonly connectionService: ConnectionService, private readonly startupAlertsService: StartupAlertsService, private readonly toastCtrl: ToastController, - private readonly loadingCtrl: LoadingController, private readonly errToast: ErrorToastService, - private readonly patch: PatchDbService, + public readonly patch: PatchDbService, private readonly config: ConfigService, readonly splitPane: SplitPaneTracker, ) { diff --git a/ui/src/app/guards/maintenance.guard.ts b/ui/src/app/guards/maintenance.guard.ts index 2720d0748..72b304855 100644 --- a/ui/src/app/guards/maintenance.guard.ts +++ b/ui/src/app/guards/maintenance.guard.ts @@ -7,11 +7,20 @@ import { PatchDbService } from '../services/patch-db/patch-db.service' providedIn: 'root', }) export class MaintenanceGuard implements CanActivate, CanActivateChild { + serverStatus: ServerStatus + isFullyDownloaded: boolean = false constructor ( private readonly router: Router, private readonly patch: PatchDbService, - ) { } + ) { + this.patch.watch$('server-info', 'status').subscribe(status => { + this.serverStatus = status + }) + this.patch.watch$('server-info', 'update-progress').subscribe(progress => { + this.isFullyDownloaded = !!progress && (progress.size === progress.downloaded) + }) + } canActivate (): boolean { return this.runServerStatusCheck() @@ -22,7 +31,7 @@ export class MaintenanceGuard implements CanActivate, CanActivateChild { } private runServerStatusCheck (): boolean { - if ([ServerStatus.Updating, ServerStatus.BackingUp].includes(this.patch.getData()['server-info']?.status)) { + if (ServerStatus.BackingUp === this.serverStatus || !this.isFullyDownloaded) { this.router.navigate(['/maintenance'], { replaceUrl: true }) return false } else { diff --git a/ui/src/app/guards/unmaintenance.guard.ts b/ui/src/app/guards/unmaintenance.guard.ts index 4724b5767..0b3bbd505 100644 --- a/ui/src/app/guards/unmaintenance.guard.ts +++ b/ui/src/app/guards/unmaintenance.guard.ts @@ -8,6 +8,8 @@ import { PatchDbService } from '../services/patch-db/patch-db.service' }) export class UnmaintenanceGuard implements CanActivate { serverStatus: ServerStatus + isFullyDownloaded: boolean = false + constructor ( private readonly router: Router, @@ -16,14 +18,17 @@ export class UnmaintenanceGuard implements CanActivate { this.patch.watch$('server-info', 'status').subscribe(status => { this.serverStatus = status }) + this.patch.watch$('server-info', 'update-progress').subscribe(progress => { + this.isFullyDownloaded = !!progress && (progress.size === progress.downloaded) + }) } canActivate (): boolean { - if (![ServerStatus.Updating, ServerStatus.BackingUp].includes(this.serverStatus)) { + if (ServerStatus.BackingUp === this.serverStatus || this.isFullyDownloaded) { + return true + } else { this.router.navigate([''], { replaceUrl: true }) return false - } else { - return true } } } \ No newline at end of file diff --git a/ui/src/app/services/api/embassy-mock-api.service.ts b/ui/src/app/services/api/embassy-mock-api.service.ts index 04b788a0b..d92ab1209 100644 --- a/ui/src/app/services/api/embassy-mock-api.service.ts +++ b/ui/src/app/services/api/embassy-mock-api.service.ts @@ -101,14 +101,26 @@ export class MockApiService extends ApiService { async updateServerRaw (params: RR.UpdateServerReq): Promise { await pauseFor(2000) + const initialProgress = { + size: 10000, + downloaded: 0, + } const patch = [ { op: PatchOp.REPLACE, path: '/server-info/status', value: ServerStatus.Updating, }, + { + op: PatchOp.REPLACE, + path: '/server-info/update-progress', + value: initialProgress, + }, ] const res = await this.http.rpcRequest>({ method: 'db.patch', params: { patch } }) + + await this.updateOSProgress(initialProgress.size) + setTimeout(async () => { const patch = [ { @@ -121,6 +133,10 @@ export class MockApiService extends ApiService { path: '/server-info/version', value: '3.1.0', }, + { + op: PatchOp.REMOVE, + path: '/server-info/update-progress', + }, ] await this.http.rpcRequest>({ method: 'db.patch', params: { patch } }) // quickly revert patch to proper version to prevent infinite refresh loop @@ -132,7 +148,7 @@ export class MockApiService extends ApiService { }, ] this.http.rpcRequest>({ method: 'db.patch', params: { patch: patch2 } }) - }, this.revertTime) + }, 10000) return res } @@ -564,4 +580,29 @@ export class MockApiService extends ApiService { this.http.rpcRequest>({ method: 'db.patch', params: { patch } }) }, 1000) } + + private async updateOSProgress (size: number) { + let downloaded = 0 + while (downloaded < size) { + await pauseFor(250) + downloaded += 500 + const patch = [ + { + op: PatchOp.REPLACE, + path: `/server-info/update-progress/downloaded`, + value: downloaded, + }, + ] + await this.http.rpcRequest>({ method: 'db.patch', params: { patch } }) + } + + const patch = [ + { + op: PatchOp.REPLACE, + path: `/server-info/update-progress/downloaded`, + value: size, + }, + ] + await this.http.rpcRequest>({ method: 'db.patch', params: { patch } }) + } } diff --git a/ui/src/app/services/patch-db/data-model.ts b/ui/src/app/services/patch-db/data-model.ts index 9de21e371..8784106fd 100644 --- a/ui/src/app/services/patch-db/data-model.ts +++ b/ui/src/app/services/patch-db/data-model.ts @@ -21,6 +21,10 @@ export interface ServerInfo { 'eos-marketplace': URL 'package-marketplace': URL | null // uses EOS marketplace if null 'unread-notification-count': number + 'update-progress'?: { + size: number + downloaded: number + } specs: { cpu: string disk: string