Make sure we've invited the device when we go to the control page. Refuse to show the control page on failure.

This commit is contained in:
Simo Kinnunen
2014-02-26 19:18:25 +09:00
parent be9d1c9579
commit b9cec82941
2 changed files with 15 additions and 3 deletions

View File

@@ -1,11 +1,17 @@
module.exports = function DeviceControlCtrl($scope, $routeParams, DeviceService, ControlService) {
module.exports = function DeviceControlCtrl($scope, $routeParams, $location, DeviceService, GroupService, ControlService) {
$scope.control = null
$scope.device = {
promise: DeviceService.get($routeParams.serial)
.then(function(device) {
return GroupService.invite(device)
})
.then(function(device) {
$scope.device.value = device
$scope.control = ControlService.forOne(device, device.channel)
return device
})
.catch(function(err) {
$location.path('/')
})
}
}