mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 17:33:18 +00:00
Implement table.horizontal()
This commit is contained in:
parent
26c69d183d
commit
e0448357df
@ -2,22 +2,21 @@ _ = require('lodash')
|
||||
cliff = require('cliff')
|
||||
server = require('../server/server')
|
||||
device = require('../device/device')
|
||||
table = require('../table/table')
|
||||
applicationModel = require('../models/application')
|
||||
authHooks = require('../hooks/auth')
|
||||
|
||||
exports.list = authHooks.failIfNotLoggedIn ->
|
||||
applicationModel.getAll().then (applications) ->
|
||||
|
||||
applications = _.map applications, (application) ->
|
||||
return {
|
||||
ID: application.id
|
||||
Name: application.app_name
|
||||
'Device Type': device.getDisplayName(application.device_type)
|
||||
'Online Devices': _.where(application.device, is_online: 1).length
|
||||
'All Devices': application.device?.length or 0
|
||||
}
|
||||
|
||||
console.log cliff.stringifyObjectRows(applications, _.keys _.first applications)
|
||||
console.log table.horizontal applications, (application) ->
|
||||
application.device_type = device.getDisplayName(application.device_type)
|
||||
application['Online Devices'] = _.where(application.device, is_online: 1).length
|
||||
application['All Devices'] = application.device?.length or 0
|
||||
delete application.git_repository
|
||||
delete application.device
|
||||
return application
|
||||
, [ 'ID', 'Name', 'Device Type', 'Online Devices', 'All Devices' ]
|
||||
|
||||
exports.info = authHooks.failIfNotLoggedIn (id) ->
|
||||
applicationModel.get(id).then (application) ->
|
||||
|
@ -1,4 +1,5 @@
|
||||
_ = require('lodash')
|
||||
cliff = require('cliff')
|
||||
|
||||
KEY_DISPLAY_MAP =
|
||||
commit: 'Commit'
|
||||
@ -33,3 +34,11 @@ exports.prepareObject = (object) ->
|
||||
return _.isEmpty(value) and not _.isNumber(value)
|
||||
|
||||
return object
|
||||
|
||||
# TODO: Maybe there is a (sane) way to test this, given
|
||||
# that the result is not automatically printed by cliff?
|
||||
exports.horizontal = (contents, map, ordering, colours) ->
|
||||
contents = _.map(contents, map or _.noop)
|
||||
contents = _.map(contents, exports.prepareObject)
|
||||
ordering ?= _.keys(_.first(contents))
|
||||
return cliff.stringifyObjectRows(contents, ordering, colours)
|
||||
|
Loading…
x
Reference in New Issue
Block a user