Handling of about to be kicked devices improved.

This commit is contained in:
Gunther Brunner
2014-04-08 17:59:08 +09:00
parent 0bce25cabf
commit c6a34713f0
3 changed files with 38 additions and 15 deletions

View File

@@ -1,17 +1,39 @@
module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService, $location) {
module.exports = function DeviceControlCtrl($scope, $rootScope, DeviceService, GroupService, $location) {
$scope.groupTracker = DeviceService.trackGroup($scope)
$scope.groupDevices = $scope.groupTracker.devices
$scope.kickDevice = function (device) {
// if current device
// no more: go to devices
// more: go to first
return GroupService.kick(device).then(function () {
$scope.$digest()
})
// If we're trying to kick current device
if (device.serial === $rootScope.device.serial) {
// If there is more than one device left
if ($scope.groupDevices.length > 1) {
// Control first free device first
var firstFreeDevice = _.find($scope.groupDevices, function (dev) {
return dev.serial !== $rootScope.device.serial
})
$scope.controlDevice(firstFreeDevice)
// Then kick the old device
GroupService.kick(device).then(function () {
$scope.$digest()
})
} else {
// Kick the device
GroupService.kick(device).then(function () {
$scope.$digest()
})
$location.path('/devices/')
}
} else {
GroupService.kick(device).then(function () {
$scope.$digest()
})
}
}
$scope.controlDevice = function (device) {