From bc50d52f4dafdc31e0e6f16d7d7554e3d3e6603c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 20 Jul 2018 09:24:28 +0200 Subject: [PATCH] Implement state recovery, make ask before reload opt-in --- src/app/app.component.ts | 12 +++++++----- src/app/config.ts | 2 ++ src/app/dashboard/dashboard.component.ts | 7 +++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 0216d27..7472321 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -17,10 +17,12 @@ export class AppComponent implements OnInit { ngOnInit() { this.titleService.setTitle(this.documentTitle); - window.addEventListener('beforeunload', (event) => { - const confirmationMessage = 'Refreshing this page may mess up your challenge/tutorial state. Are you sure?'; - event.returnValue = confirmationMessage; - return confirmationMessage; - }); + if (config.dashboard.askReloadSite) { + window.addEventListener('beforeunload', (event) => { + const confirmationMessage = 'Refreshing this page may mess up your challenge/tutorial state. Are you sure?'; + event.returnValue = confirmationMessage; + return confirmationMessage; + }); + } } } diff --git a/src/app/config.ts b/src/app/config.ts index ee07ebc..38d631c 100644 --- a/src/app/config.ts +++ b/src/app/config.ts @@ -6,6 +6,8 @@ export const config = { dashboard: { route: 'dashboard', triggerFirstFSMStep: 'step_1', + askReloadSite: false, + recoverAfterPageReload: true, terminalOrConsole: 'terminal', currentLayout: 'terminal-ide-web', enabledLayouts: [ diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts index 71136d5..d817e82 100644 --- a/src/app/dashboard/dashboard.component.ts +++ b/src/app/dashboard/dashboard.component.ts @@ -44,6 +44,7 @@ export class DashboardComponent implements OnInit, OnDestroy { this.initCommandHandling(); this.initDeploymentNotifications(); this.triggerFirstFSMStepIfNeeded(); + this.recoverIfNeeded(); } initCommandHandling() { @@ -74,6 +75,12 @@ export class DashboardComponent implements OnInit, OnDestroy { } } + recoverIfNeeded() { + if (config.dashboard.recoverAfterPageReload) { + setTimeout(() => this.webSocketService.sendJSON({'key': 'recover'})); + } + } + layoutHandler(data: LayoutCommand) { if (config.dashboard.enabledLayouts.includes(data.value)) { this.setLayout(data.value);