From c6a34713f0a111a19c1ed54f2cde9674fae2d057 Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Tue, 8 Apr 2014 17:59:08 +0900 Subject: [PATCH] Handling of about to be kicked devices improved. --- .../device-control-controller.js | 36 +++++++++++++++---- .../device-control/device-control.css | 2 +- .../device-control/device-control.jade | 15 ++++---- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/res/app/control-panes/device-control/device-control-controller.js b/res/app/control-panes/device-control/device-control-controller.js index 3c47601a..04657c0b 100644 --- a/res/app/control-panes/device-control/device-control-controller.js +++ b/res/app/control-panes/device-control/device-control-controller.js @@ -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) { diff --git a/res/app/control-panes/device-control/device-control.css b/res/app/control-panes/device-control/device-control.css index 634a300f..c59de8f9 100644 --- a/res/app/control-panes/device-control/device-control.css +++ b/res/app/control-panes/device-control/device-control.css @@ -98,7 +98,7 @@ device-screen textarea { min-width: 37px; } -.stf-vnc-device-name { +.stf-device-control .stf-vnc-device-name { /*padding: 6px 2px 6px 15px;*/ /*float: left;*/ font-size: 16px; diff --git a/res/app/control-panes/device-control/device-control.jade b/res/app/control-panes/device-control/device-control.jade index a428c9af..b8d61300 100644 --- a/res/app/control-panes/device-control/device-control.jade +++ b/res/app/control-panes/device-control/device-control.jade @@ -19,16 +19,17 @@ i(ng-show='!showScreen', tooltip-html-unsafe='{{"View device"|translate}}
⌘-⇧-O', tooltip-placement='left').fa.fa-eye-slash div - - - a.stf-vnc-device-name.pointer.unselectable.dropdown-toggle(ng-class='{"pointer": groupDevices.length > 1, "cursor": groupDevices.length <= 1}') - p {{ $root.device.name }} - span.caret(ng-show='groupDevices.length > 1') + a.stf-vnc-device-name.pointer.unselectable.dropdown-toggle + p + .device-small-image + img(ng-src='{{$root.device.image ? "/static/devices/" + $root.device.image : "/static/bower_components/stf-graphics/devices/small/default.jpg" }}') + span {{ $root.device.name }} + span.caret(ng-show='groupDevices.length > 0') span(ng-show='$root.device && !$root.device.present', translate) (Absent) - ul.dropdown-menu.pointer.unselectable(ng-show='groupDevices.length > 1') + ul.dropdown-menu.pointer.unselectable(ng-show='groupDevices.length > 0') li(ng-repeat='groupDevice in groupDevices') - a(ng-click='controlDevice(groupDevice); $event.stopPropagation();') + a(ng-click='controlDevice(groupDevice); $event.stopPropagation()') .device-small-image img(ng-src='{{groupDevice.image ? "/static/devices/" + groupDevice.image : "/static/bower_components/stf-graphics/devices/small/default.jpg" }}') span {{ groupDevice.name }}