balena-cli/lib/actions/device.coffee

75 lines
1.9 KiB
CoffeeScript
Raw Normal View History

2014-12-24 16:49:49 +00:00
_ = require('lodash-contrib')
2014-12-19 14:05:54 +00:00
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
log.out ui.widgets.table.horizontal devices, _.identity, [
'ID'
'Name'
'Device Display Name'
'Is Online'
'Application Name'
'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
log.out ui.widgets.table.vertical device, _.identity, [
2014-12-05 15:32:14 +00:00
'ID'
'Name'
'Device Display Name'
2014-12-05 15:32:14 +00:00
'Is Online'
'IP Address'
'Application Name'
2014-12-05 15:32:14 +00:00
'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) ->
2015-01-06 16:57:11 +00:00
if not _.isEmpty(params.name)
2014-12-19 14:05:54 +00:00
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?
2014-12-24 16:49:49 +00:00
exports.supported = permissions.user ->
devices = resin.models.device.getSupportedDeviceTypes()
_.each(devices, _.unary(log.out))