diff options
| author | James Barnett <james.barnett@fivium.co.uk> | 2018-04-08 17:25:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-08 17:25:47 +0100 |
| commit | eb0185c03f8d5b68949798e8040b42a203b040a2 (patch) | |
| tree | 86da8449b0c92ec29a15baffe3e7bd8ebd34488e /routes/index.js | |
| parent | 954aff49707738e660e92e0418c31b1ec78a85a8 (diff) | |
| parent | 4ec37af74fc77f7381d7c5c3b2560c8726f75ffa (diff) | |
| download | tplink-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.js | 20 |
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; |