From 57f1ac811ddfbbc72d76cd5a4e3b3e56e0f8463d Mon Sep 17 00:00:00 2001 From: sydeslyde <34600077+sydeslyde@users.noreply.github.com> Date: Sat, 14 Apr 2018 11:54:54 +0200 Subject: [PATCH] added meaningful page when no devices discovered --- public/javascripts/dash.js | 4 +++- routes/index.js | 10 ++++++++-- views/index.hbs | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/public/javascripts/dash.js b/public/javascripts/dash.js index 821e9c1..e52992f 100644 --- a/public/javascripts/dash.js +++ b/public/javascripts/dash.js @@ -11,7 +11,9 @@ var dash = { init: function(deviceId) { this.deviceId = deviceId; - $('.' + deviceId).addClass('active'); + if (this.deviceId) { + $('.' + deviceId).addClass('active'); + } this.initRealtimeGauge(); this.initRealtimeTrendChart(); diff --git a/routes/index.js b/routes/index.js index 12c62cd..b8d9917 100644 --- a/routes/index.js +++ b/routes/index.js @@ -5,9 +5,15 @@ const deviceManager = require('../services/device-manager'); router.get('/', function(req, res, next) { - let deviceId = sortDevices(deviceManager.getAllDevices())[0].deviceId; + let devices = sortDevices(deviceManager.getAllDevices()); - res.redirect('/' + deviceId); + if (devices && devices.length > 0) { + let deviceId = devices[0].deviceId; + + res.redirect('/' + deviceId); + } else { + res.render('index', {}); + } }); diff --git a/views/index.hbs b/views/index.hbs index 5fe03c4..7c6a039 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -21,6 +21,13 @@ {{this.alias}} + {{else}} +