diff --git a/lib/roles/app.js b/lib/roles/app.js index aa76c9eb..ca3249e2 100644 --- a/lib/roles/app.js +++ b/lib/roles/app.js @@ -97,12 +97,17 @@ module.exports = function(options) { .then(function(cursor) { return Promise.promisify(cursor.toArray, cursor)() .then(function(list) { - res.json(list) + res.json({ + success: true + , devices: list + }) }) }) .catch(function(err) { log.error('Failed to load device list: ', err.stack) - res.send(500) + res.json(500, { + success: false + }) }) }) @@ -110,15 +115,22 @@ module.exports = function(options) { dbapi.loadDevice(req.params.serial) .then(function(device) { if (device) { - res.json(device) + res.json({ + success: true + , device: device + }) } else { - res.send(404) + res.json(404, { + success: false + }) } }) .catch(function(err) { log.error('Failed to load device "%s": ', req.params.serial, err.stack) - res.send(500) + res.json(500, { + success: false + }) }) }) diff --git a/res/app/scripts/controllers/DeviceListCtrl.js b/res/app/scripts/controllers/DeviceListCtrl.js index 56fa1b4b..37992632 100644 --- a/res/app/scripts/controllers/DeviceListCtrl.js +++ b/res/app/scripts/controllers/DeviceListCtrl.js @@ -1,5 +1,12 @@ -define(['./module'], function(mod) { - mod.controller('DeviceListCtrl', ['$scope', '$http', 'devices', function($scope, $http) { +define(['./module', 'oboe'], function(mod, oboe) { + mod.controller('DeviceListCtrl', ['$scope', function($scope) { + $scope.devices = [] + oboe('/api/v1/devices') + .node('$devices[*]', function(devicesLoadedSoFar) { + $scope.$apply(function() { + $scope.devices = devicesLoadedSoFar + }) + }) }]) }) diff --git a/res/app/views/partials/deviceList.jade b/res/app/views/partials/deviceList.jade index 7d9121cd..613b743f 100644 --- a/res/app/views/partials/deviceList.jade +++ b/res/app/views/partials/deviceList.jade @@ -1 +1,5 @@ h1 Devices + +ul + li(ng-repeat='device in devices track by device.serial') + span {{ device.serial }}