From cb9a99fc7bd10fd18b35af739d7faf5f967de1df Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 27 Jul 2016 13:41:26 -0700 Subject: [PATCH] Change user events tutorial Redis error to be an inline box Fixes #1653 --- endpoints/realtime.py | 2 ++ static/directives/angular-tour-ui.html | 5 +++++ static/js/tour.js | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/endpoints/realtime.py b/endpoints/realtime.py index c8c1c1c6f..23d41ee28 100644 --- a/endpoints/realtime.py +++ b/endpoints/realtime.py @@ -99,6 +99,8 @@ def user_test(): @require_session_login def user_subscribe(): def wrapper(listener): + yield 'data: %s\n\n' % json.dumps({}) + for event_id, data in listener.event_stream(): message = {'event': event_id, 'data': data} json_string = json.dumps(message) diff --git a/static/directives/angular-tour-ui.html b/static/directives/angular-tour-ui.html index a9aaca27c..5305f44b6 100644 --- a/static/directives/angular-tour-ui.html +++ b/static/directives/angular-tour-ui.html @@ -5,6 +5,11 @@ Your browser does not support features required for this tour. Please upgrade and try again. +
+ There was an error registering to listen for server side events. Steps of the tutorial may not be + possible. If this problem persists, please contact support. +
+
{{ step.title }}
diff --git a/static/js/tour.js b/static/js/tour.js index 783bc3078..5651bcf39 100644 --- a/static/js/tour.js +++ b/static/js/tour.js @@ -284,11 +284,20 @@ angular.module("angular-tour", []) var fullUrl = tourScope._replaceData(url); checker.$source = new EventSource(fullUrl); checker.$source.onmessage = function(e) { - checker.$message = JSON.parse(e.data); + var parsed = JSON.parse(e.data); + if (!parsed['data']) { + return; + } + + checker.$message = parsed; }; + + checker.$source.onopen = function(e) { + checker.$hasError = false; + }; + checker.$source.onerror = function(e) { - bootbox.alert('Could not read user events from server due to a Redis issue. ' + - ' Please contact support.') + checker.$hasError = true; }; };