mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
Add convenience flags for knowing if a device is usable, ready, and owned by us.
This commit is contained in:
parent
cc42b7c51f
commit
30b04ab2d2
5 changed files with 47 additions and 12 deletions
|
@ -58,6 +58,7 @@ dbapi.saveDevice = function(serial, device) {
|
|||
, provider: device.provider
|
||||
, owner: null
|
||||
, status: device.status
|
||||
, ready: false
|
||||
, statusChangedAt: r.now()
|
||||
, createdAt: r.now()
|
||||
, lastHeartbeatAt: r.now()
|
||||
|
@ -89,6 +90,7 @@ dbapi.unsetDeviceOwner = function(serial, owner) {
|
|||
dbapi.setDeviceAbsent = function(serial) {
|
||||
return db.run(r.table('devices').get(serial).update({
|
||||
present: false
|
||||
, ready: false
|
||||
, lastHeartbeatAt: null
|
||||
}))
|
||||
}
|
||||
|
@ -101,7 +103,8 @@ dbapi.setDeviceChannel = function(serial, channel) {
|
|||
|
||||
dbapi.saveDeviceIdentity = function(serial, identity) {
|
||||
return db.run(r.table('devices').get(serial).update({
|
||||
platform: identity.platform
|
||||
ready: true
|
||||
, platform: identity.platform
|
||||
, manufacturer: identity.manufacturer
|
||||
, operator: identity.operator
|
||||
, model: identity.model
|
||||
|
|
|
@ -139,7 +139,10 @@ module.exports = function(options) {
|
|||
.then(function(cursor) {
|
||||
return Promise.promisify(cursor.toArray, cursor)()
|
||||
.then(function(list) {
|
||||
list.forEach(datautil.applyData)
|
||||
list.forEach(function(device) {
|
||||
datautil.applyData(device)
|
||||
datautil.applyOwner(device, req.user)
|
||||
})
|
||||
res.json({
|
||||
success: true
|
||||
, devices: list
|
||||
|
@ -158,9 +161,11 @@ module.exports = function(options) {
|
|||
dbapi.loadDevice(req.params.serial)
|
||||
.then(function(device) {
|
||||
if (device) {
|
||||
datautil.applyData(device)
|
||||
datautil.applyOwner(device, req.user)
|
||||
res.json({
|
||||
success: true
|
||||
, device: datautil.applyData(device)
|
||||
, device: device
|
||||
})
|
||||
}
|
||||
else {
|
||||
|
@ -258,22 +263,34 @@ module.exports = function(options) {
|
|||
socket.emit('device.remove', {
|
||||
serial: message.serial
|
||||
, present: false
|
||||
, ready: false
|
||||
, lastHeartbeatAt: null
|
||||
, isOwnedByUser: false
|
||||
})
|
||||
})
|
||||
.on(wire.JoinGroupMessage, function(channel, message) {
|
||||
socket.emit('device.change', message)
|
||||
socket.emit('device.change', datautil.applyOwner({
|
||||
serial: message.serial
|
||||
, owner: message.owner
|
||||
}
|
||||
, user
|
||||
))
|
||||
})
|
||||
.on(wire.LeaveGroupMessage, function(channel, message) {
|
||||
socket.emit('device.change', {
|
||||
socket.emit('device.change', datautil.applyOwner({
|
||||
serial: message.serial
|
||||
, owner: null
|
||||
})
|
||||
}
|
||||
, user
|
||||
))
|
||||
})
|
||||
.on(wire.DeviceStatusMessage, function(channel, message) {
|
||||
socket.emit('device.change', message)
|
||||
})
|
||||
.on(wire.DeviceIdentityMessage, function(channel, message) {
|
||||
socket.emit('device.change', datautil.applyData(message))
|
||||
datautil.applyData(message)
|
||||
message.ready = true
|
||||
socket.emit('device.change', message)
|
||||
})
|
||||
.on(wire.TransactionProgressMessage, function(channel, message) {
|
||||
socket.emit('tx.progress', channel.toString(), message)
|
||||
|
|
|
@ -50,6 +50,11 @@ module.exports.applyData = function(device) {
|
|||
return device
|
||||
}
|
||||
|
||||
module.exports.applyOwner = function(device, user) {
|
||||
device.isOwnedByUser = !!device.owner && device.owner.email === user.email
|
||||
return device
|
||||
}
|
||||
|
||||
module.exports.middleware = function() {
|
||||
return express.static(pathutil.root('node_modules/stf-devices-db/data/small'))
|
||||
}
|
||||
|
|
|
@ -17,17 +17,27 @@ module.exports = function DeviceServiceFactory($rootScope, $http, socket) {
|
|||
}
|
||||
}
|
||||
|
||||
function sync(data) {
|
||||
// usable IF device is physically present AND device is online AND
|
||||
// preparations are ready AND the device has no owner or we are the
|
||||
// owner
|
||||
data.usable = data.present && data.status === 3 && data.ready &&
|
||||
(!data.owner || data.isOwnedByUser)
|
||||
}
|
||||
|
||||
function get(data) {
|
||||
return devices[devicesBySerial[data.serial]]
|
||||
}
|
||||
|
||||
function insert(data) {
|
||||
devicesBySerial[data.serial] = devices.push(data) - 1
|
||||
sync(data)
|
||||
notify()
|
||||
}
|
||||
|
||||
function modify(oldData, newData) {
|
||||
_.assign(oldData, newData)
|
||||
function modify(data, newData) {
|
||||
_.assign(data, newData)
|
||||
sync(data)
|
||||
notify()
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ div
|
|||
|
||||
ul.device-list
|
||||
li(ng-repeat='device in tracker.devices track by device.serial')
|
||||
span {{ device.serial }} {{ device.name || device.model }} {{ device.present ? 'present' : 'absent' }} {{ device.owner.email }}
|
||||
span {{ device.serial }} {{ device.name || device.model }} {{ device.present ? 'present' : 'absent' }} {{ device.usable ? 'usable' : 'unusable' }} {{ device.isOwnedByUser ? 'owned by me' : '' }} {{ device.owner.email }}
|
||||
a(href='#!/devices/{{ device.serial }}') Linky
|
||||
button(ng-click="invite(device)") invite
|
||||
button(ng-click="kick(device)") kick
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue