aboutsummaryrefslogtreecommitdiff
path: root/routes/index.js
diff options
context:
space:
mode:
authorJames Barnett <james.barnett@fivium.co.uk>2018-04-08 17:25:47 +0100
committerGitHub <noreply@github.com>2018-04-08 17:25:47 +0100
commiteb0185c03f8d5b68949798e8040b42a203b040a2 (patch)
tree86da8449b0c92ec29a15baffe3e7bd8ebd34488e /routes/index.js
parent954aff49707738e660e92e0418c31b1ec78a85a8 (diff)
parent4ec37af74fc77f7381d7c5c3b2560c8726f75ffa (diff)
downloadtplink-energy-monitor-eb0185c03f8d5b68949798e8040b42a203b040a2.tar.xz
tplink-energy-monitor-eb0185c03f8d5b68949798e8040b42a203b040a2.zip
Merge pull request #1 from jamesbarnett91/websocketsv0.2
Switch from http polling to websockets
Diffstat (limited to 'routes/index.js')
-rw-r--r--routes/index.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/routes/index.js b/routes/index.js
index 4909ff8..12c62cd 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -5,11 +5,27 @@ const deviceManager = require('../services/device-manager');
router.get('/', function(req, res, next) {
+ let deviceId = sortDevices(deviceManager.getAllDevices())[0].deviceId;
+
+ res.redirect('/' + deviceId);
+
+});
+
+router.get('/:deviceId', function(req, res, next) {
+
+ let deviceId = req.params.deviceId;
+
res.render('index', {
- device: deviceManager.getDevice(),
- devices: deviceManager.getAllDevices()
+ device: deviceManager.getDevice(deviceId),
+ devices: sortDevices(deviceManager.getAllDevices())
});
});
+function sortDevices(devices) {
+ return devices.slice().sort((a, b) => {
+ return a.alias.toLowerCase().localeCompare(b.alias.toLowerCase())
+ })
+}
+
module.exports = router;