mirror of
https://github.com/openstf/stf
synced 2025-10-05 19:42:01 +02:00
Keep device data up to date on device page.
This commit is contained in:
parent
ee8951e467
commit
238d5d6f4e
3 changed files with 18 additions and 6 deletions
|
@ -10,18 +10,25 @@ module.exports = function DeviceServiceFactory($rootScope, $http, socket) {
|
|||
, devicesBySerial = Object.create(null)
|
||||
, scopedSocket = socket.scoped($scope)
|
||||
|
||||
function notify() {
|
||||
// Not great. Consider something else
|
||||
if (!$scope.$$phase) {
|
||||
$scope.$digest()
|
||||
}
|
||||
}
|
||||
|
||||
function get(data) {
|
||||
return devices[devicesBySerial[data.serial]]
|
||||
}
|
||||
|
||||
function insert(data) {
|
||||
devicesBySerial[data.serial] = devices.push(data) - 1
|
||||
$scope.$digest()
|
||||
notify()
|
||||
}
|
||||
|
||||
function modify(oldData, newData) {
|
||||
_.assign(oldData, newData)
|
||||
$scope.$digest()
|
||||
notify()
|
||||
}
|
||||
|
||||
function remove(data) {
|
||||
|
@ -29,7 +36,7 @@ module.exports = function DeviceServiceFactory($rootScope, $http, socket) {
|
|||
if (index >= 0) {
|
||||
devices.splice(index, 1)
|
||||
delete devicesBySerial[data.serial]
|
||||
$scope.$digest()
|
||||
notify()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,9 +85,14 @@ module.exports = function DeviceServiceFactory($rootScope, $http, socket) {
|
|||
return tracker
|
||||
}
|
||||
|
||||
deviceService.get = function (serial) {
|
||||
deviceService.get = function (serial, $scope) {
|
||||
var tracker = new Tracker($scope, {
|
||||
auto: false
|
||||
})
|
||||
|
||||
return $http.get('/api/v1/devices/' + serial)
|
||||
.then(function (response) {
|
||||
tracker.add(response.data.device)
|
||||
return response.data.device
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module.exports = function DeviceControlCtrl($scope, $routeParams, $location, DeviceService, GroupService, ControlService) {
|
||||
$scope.control = null
|
||||
$scope.device = {
|
||||
promise: DeviceService.get($routeParams.serial)
|
||||
promise: DeviceService.get($routeParams.serial, $scope)
|
||||
.then(function(device) {
|
||||
return GroupService.invite(device)
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
h1 {{ device.value.serial }}
|
||||
h1 {{ device.value.serial }} {{ device.value.present ? 'present' : 'absent' }}
|
||||
|
||||
button(ng-click='showScreen = !showScreen') Show/Hide
|
||||
button(ng-click='control.identify()') Identify
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue