2014-12-19 14:05:54 +00:00
|
|
|
_ = require('lodash')
|
|
|
|
async = require('async')
|
2014-11-26 16:07:10 +00:00
|
|
|
resin = require('../resin')
|
2014-12-05 16:00:15 +00:00
|
|
|
ui = require('../ui')
|
2014-12-12 21:20:29 +00:00
|
|
|
permissions = require('../permissions/permissions')
|
2014-11-19 17:38:15 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.list = permissions.user (params) ->
|
|
|
|
resin.models.device.getAllByApplication params.id, (error, devices) ->
|
2014-11-26 18:02:59 +00:00
|
|
|
resin.errors.handle(error) if error?
|
2014-11-19 17:38:15 +00:00
|
|
|
|
2014-12-05 16:00:15 +00:00
|
|
|
resin.log.out ui.widgets.table.horizontal devices, (device) ->
|
2014-11-19 17:38:15 +00:00
|
|
|
device.application = device.application[0].app_name
|
2014-11-26 17:12:39 +00:00
|
|
|
device.device_type = resin.device.getDisplayName(device.device_type)
|
2014-11-19 17:38:15 +00:00
|
|
|
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
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.info = permissions.user (params) ->
|
|
|
|
resin.models.device.get params.id, (error, device) ->
|
2014-12-05 15:32:14 +00:00
|
|
|
resin.errors.handle(error) if error?
|
|
|
|
|
2014-12-05 16:00:15 +00:00
|
|
|
resin.log.out ui.widgets.table.vertical device, (device) ->
|
2014-12-05 15:32:14 +00:00
|
|
|
device.device_type = resin.device.getDisplayName(device.device_type)
|
|
|
|
device.application = device.application[0].app_name
|
|
|
|
return device
|
|
|
|
, [
|
|
|
|
'ID'
|
|
|
|
'Name'
|
|
|
|
'Device Type'
|
|
|
|
'Is Online'
|
|
|
|
'IP Address'
|
|
|
|
'Application'
|
|
|
|
'Status'
|
|
|
|
'Last Seen'
|
|
|
|
'UUID'
|
|
|
|
'Commit'
|
|
|
|
'Supervisor Version'
|
|
|
|
'Is Web Accessible'
|
|
|
|
'Note'
|
|
|
|
]
|
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.remove = permissions.user (params, options) ->
|
|
|
|
ui.patterns.remove 'device', options.yes, (callback) ->
|
|
|
|
resin.models.device.remove(params.id, callback)
|
2014-11-26 16:38:02 +00:00
|
|
|
, resin.errors.handle
|
2014-11-21 18:21:47 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.identify = permissions.user (params) ->
|
|
|
|
resin.models.device.identify params.uuid, (error) ->
|
2014-11-26 18:02:59 +00:00
|
|
|
resin.errors.handle(error) if error?
|
2014-12-19 14:05:54 +00:00
|
|
|
|
|
|
|
# TODO: This action doesn't return any error
|
|
|
|
# if trying to rename a device that does not
|
|
|
|
# exists. This is being fixed server side.
|
|
|
|
exports.rename = permissions.user (params) ->
|
|
|
|
async.waterfall [
|
|
|
|
|
|
|
|
(callback) ->
|
|
|
|
if params.name? and not _.isEmpty(params.name)
|
|
|
|
return callback(null, params.name)
|
|
|
|
ui.widgets.ask('How do you want to name this device?', callback)
|
|
|
|
|
|
|
|
(name, callback) ->
|
|
|
|
resin.models.device.rename(params.id, name, callback)
|
|
|
|
|
|
|
|
], (error) ->
|
|
|
|
resin.errors.handle(error) if error?
|