2014-11-19 17:38:15 +00:00
|
|
|
deviceModel = require('../models/device')
|
|
|
|
getDeviceDisplayName = require('../device/device').getDisplayName
|
2014-11-21 15:40:37 +00:00
|
|
|
log = require('../log/log')
|
2014-11-19 17:38:15 +00:00
|
|
|
table = require('../table/table')
|
2014-11-21 18:21:47 +00:00
|
|
|
server = require('../server/server')
|
2014-11-21 17:23:29 +00:00
|
|
|
widgets = require('../widgets/widgets')
|
|
|
|
patterns = require('../patterns/patterns')
|
2014-11-19 17:38:15 +00:00
|
|
|
authHooks = require('../hooks/auth')
|
|
|
|
|
|
|
|
exports.list = authHooks.failIfNotLoggedIn (applicationId) ->
|
|
|
|
deviceModel.getAll(applicationId).then (devices) ->
|
|
|
|
|
2014-11-21 15:40:37 +00:00
|
|
|
log.out table.horizontal devices, (device) ->
|
2014-11-19 17:38:15 +00:00
|
|
|
device.application = device.application[0].app_name
|
|
|
|
device.device_type = getDeviceDisplayName(device.device_type)
|
|
|
|
delete device.note
|
|
|
|
delete device.supervisor_version
|
|
|
|
delete device.uuid
|
|
|
|
delete device.download_progress
|
|
|
|
return device
|
2014-11-19 19:18:15 +00:00
|
|
|
, [ 'ID', 'Name', 'Device Type', 'Is Online', 'IP Address', 'Application', 'Status', 'Last Seen' ]
|
2014-11-19 17:38:15 +00:00
|
|
|
|
|
|
|
.catch (error) ->
|
|
|
|
throw error
|
2014-11-21 17:23:29 +00:00
|
|
|
|
|
|
|
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
|
|
|
patterns.remove 'device', program.parent.yes, (callback) ->
|
|
|
|
deviceModel.remove(id).then ->
|
|
|
|
return callback()
|
|
|
|
.catch(callback)
|
|
|
|
, (error) ->
|
|
|
|
throw error if error?
|
2014-11-21 18:21:47 +00:00
|
|
|
|
|
|
|
exports.identify = authHooks.failIfNotLoggedIn (uuid) ->
|
|
|
|
server.post '/blink', { uuid }, (error) ->
|
|
|
|
throw error if error?
|