Add convenience flags for knowing if a device is usable, ready, and owned by us.

This commit is contained in:
Simo Kinnunen
2014-03-18 15:06:02 +09:00
parent cc42b7c51f
commit 30b04ab2d2
5 changed files with 47 additions and 12 deletions

View File

@@ -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()
}