aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Barnett <james.barnett@fivium.co.uk>2018-04-15 20:20:31 +0100
committerGitHub <noreply@github.com>2018-04-15 20:20:31 +0100
commit86cc693f25039b3e149115b9900b31ffd582d8c4 (patch)
tree3f129a89f18086093d4bdf699199ae16b4de6c99
parenteb0185c03f8d5b68949798e8040b42a203b040a2 (diff)
parent6e432e6d3bc4dab0dd32664344636c905e40c7c9 (diff)
downloadtplink-energy-monitor-0.3.tar.xz
tplink-energy-monitor-0.3.zip
Merge pull request #2 from sydeslyde/masterv0.3
Added meaningful page when no devices discovered
-rw-r--r--public/javascripts/dash.js4
-rw-r--r--routes/index.js10
-rw-r--r--views/index.hbs14
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}}
</a>
</li>
+ {{else}}
+ <li>
+ <a href='index.html'>
+ <i class="fa fa-info"></i>
+ no devices discovered yet
+ </a>
+ </li>
{{/each}}
</ul>
</div>
@@ -43,6 +50,13 @@
{{this.alias}}
</a>
</li>
+ {{else}}
+ <li>
+ <a href="index.html">
+ <i class="fa fa-info"></i>
+ no devices discovered yet
+ </a>
+ </li>
{{/each}}
</ul>
</div>