From 1801891ddd6fd79f222f5b1b0dd25e619f22a9f5 Mon Sep 17 00:00:00 2001 From: Goran Topic Date: Tue, 24 Oct 2017 17:16:19 +0900 Subject: [PATCH 01/10] Issue #204 (auto-refresh client on server upgrade) --- raidar/static/raidar/script.js | 22 +++++++++++++++++-- .../templates/raidar/info_releasenotes.html | 4 ++++ raidar/views.py | 5 ++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/raidar/static/raidar/script.js b/raidar/static/raidar/script.js index 5948cc78..afcbee1d 100644 --- a/raidar/static/raidar/script.js +++ b/raidar/static/raidar/script.js @@ -64,7 +64,7 @@ }); $(document).ajaxError((evt, xhr, settings, err) => { console.error(err); - error("Error communicating to server") + error("Error communicating to server"); }) function f0X(x) { @@ -1193,6 +1193,21 @@ ${body} handler(notification); } + function upgradeClient() { + notification('Server was upgraded, client will restart in s', { status: 'warning', timeout: 10000 }); + let count = 8; + let cdEl = document.getElementById('upgrade-countdown'); + let loop = () => { + cdEl.textContent = --count; + if (count) { + setTimeout(loop, 1000); + } else { + window.location.reload(true); + } + }; + setTimeout(loop, 1000); + } + const POLL_TIME = 10000; function pollNotifications() { if (r.get('username')) { @@ -1208,7 +1223,10 @@ ${body} lastNotificationId = data.last_id; } data.notifications.forEach(handleNotification); - }).then(() => { + if (data.version != r.get('data.version.id')) { + upgradeClient(); + } + }).always(() => { setTimeout(pollNotifications, POLL_TIME); }); } else { diff --git a/raidar/templates/raidar/info_releasenotes.html b/raidar/templates/raidar/info_releasenotes.html index e3a3594c..e4fe18b2 100644 --- a/raidar/templates/raidar/info_releasenotes.html +++ b/raidar/templates/raidar/info_releasenotes.html @@ -5,6 +5,10 @@

released on [[formatDate(data.version.timestamp)]]

+ +

Version 1.0.1