Implement devices command

This commit is contained in:
Juan Cruz Viotti 2014-11-19 13:38:15 -04:00
parent e0032c090f
commit 55fa8435bb
3 changed files with 39 additions and 0 deletions

20
lib/actions/device.coffee Normal file
View File

@ -0,0 +1,20 @@
_ = require('lodash')
deviceModel = require('../models/device')
getDeviceDisplayName = require('../device/device').getDisplayName
table = require('../table/table')
authHooks = require('../hooks/auth')
exports.list = authHooks.failIfNotLoggedIn (applicationId) ->
deviceModel.getAll(applicationId).then (devices) ->
console.log table.horizontal devices, (device) ->
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
.catch (error) ->
throw error

View File

@ -38,6 +38,15 @@ program
.description('Show an application')
.action(app.info)
# ---------- Device Module ----------
device = require('./actions/device')
program
.command('devices <id>')
.description('Show devices for an application')
.action(device.list)
# ---------- Preferences Module ----------
preferences = require('./actions/preferences')

10
lib/models/device.coffee Normal file
View File

@ -0,0 +1,10 @@
canvas = require('./_canvas')
exports.getAll = (applicationId) ->
return canvas.get
resource: 'device'
options:
filter:
application: applicationId
expand: 'application'
orderby: 'name asc'