balena-cli/lib/actions/device.coffee

75 lines
2.2 KiB
CoffeeScript
Raw Normal View History

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-22 16:41:14 +00:00
log = require('../log/log')
2014-12-22 16:47:12 +00:00
errors = require('../errors/errors')
permissions = require('../permissions/permissions')
2014-11-19 17:38:15 +00:00
exports.list = permissions.user (params, options) ->
if not options.application?
errors.handle(new Error('You have to specify an application'))
resin.models.device.getAllByApplication options.application, (error, devices) ->
2014-12-22 16:47:12 +00:00
errors.handle(error) if error?
2014-11-19 17:38:15 +00:00
2014-12-22 16:41:14 +00:00
log.out ui.widgets.table.horizontal devices, (device) ->
2014-11-19 17:38:15 +00:00
device.application = device.application[0].app_name
2014-12-22 19:02:52 +00:00
device.device_type = resin.models.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
, [ 'ID', 'Name', 'Device Type', 'Is Online', 'Application', 'Status', 'Last Seen' ]
2014-11-19 17:38:15 +00:00
exports.info = permissions.user (params) ->
resin.models.device.get params.id, (error, device) ->
2014-12-22 16:47:12 +00:00
errors.handle(error) if error?
2014-12-05 15:32:14 +00:00
2014-12-22 16:41:14 +00:00
log.out ui.widgets.table.vertical device, (device) ->
2014-12-22 19:02:52 +00:00
device.device_type = resin.device.models.getDisplayName(device.device_type)
2014-12-05 15:32:14 +00:00
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'
]
exports.remove = permissions.user (params, options) ->
ui.patterns.remove 'device', options.yes, (callback) ->
resin.models.device.remove(params.id, callback)
2014-12-22 16:47:12 +00:00
, errors.handle
2014-11-21 18:21:47 +00:00
exports.identify = permissions.user (params) ->
resin.models.device.identify params.uuid, (error) ->
2014-12-22 16:47:12 +00:00
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) ->
2014-12-22 16:47:12 +00:00
errors.handle(error) if error?