mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-10 12:49:53 +00:00
Refactor table to get rid of map feature
This commit is contained in:
parent
57c86f920c
commit
07c57d335b
@ -33,7 +33,7 @@ exports.list = permissions.user ->
|
||||
resin.models.application.getAll (error, applications) ->
|
||||
errors.handle(error) if error?
|
||||
|
||||
log.out ui.widgets.table.horizontal applications, _.identity, [
|
||||
log.out ui.widgets.table.horizontal applications, [
|
||||
'ID'
|
||||
'Name'
|
||||
'Device Display Name'
|
||||
@ -45,7 +45,7 @@ exports.info = permissions.user (params) ->
|
||||
resin.models.application.get params.id, (error, application) ->
|
||||
errors.handle(error) if error?
|
||||
|
||||
log.out ui.widgets.table.vertical application, _.identity, [
|
||||
log.out ui.widgets.table.vertical application, [
|
||||
'ID'
|
||||
'Name'
|
||||
'Device Display Name'
|
||||
|
@ -13,7 +13,7 @@ exports.list = permissions.user (params, options) ->
|
||||
resin.models.device.getAllByApplication options.application, (error, devices) ->
|
||||
errors.handle(error) if error?
|
||||
|
||||
log.out ui.widgets.table.horizontal devices, _.identity, [
|
||||
log.out ui.widgets.table.horizontal devices, [
|
||||
'ID'
|
||||
'Name'
|
||||
'Device Display Name'
|
||||
@ -27,7 +27,7 @@ exports.info = permissions.user (params) ->
|
||||
resin.models.device.get params.id, (error, device) ->
|
||||
errors.handle(error) if error?
|
||||
|
||||
log.out ui.widgets.table.vertical device, _.identity, [
|
||||
log.out ui.widgets.table.vertical device, [
|
||||
'ID'
|
||||
'Name'
|
||||
'Device Display Name'
|
||||
|
@ -20,7 +20,7 @@ exports.list = permissions.user ->
|
||||
example.author ?= 'Unknown'
|
||||
return example
|
||||
|
||||
log.out ui.widgets.table.horizontal examplesData, _.identity, [
|
||||
log.out ui.widgets.table.horizontal examplesData, [
|
||||
'ID'
|
||||
'Display Name'
|
||||
'Repository'
|
||||
@ -38,7 +38,7 @@ exports.info = permissions.user (params) ->
|
||||
example.id = id
|
||||
example.author ?= 'Unknown'
|
||||
|
||||
log.out ui.widgets.table.vertical example, _.identity, [
|
||||
log.out ui.widgets.table.vertical example, [
|
||||
'ID'
|
||||
'Display Name'
|
||||
'Description'
|
||||
|
@ -13,14 +13,14 @@ exports.list = permissions.user ->
|
||||
resin.models.key.getAll (error, keys) ->
|
||||
errors.handle(error) if error?
|
||||
|
||||
log.out ui.widgets.table.horizontal keys, _.identity, [ 'ID', 'Title' ]
|
||||
log.out ui.widgets.table.horizontal keys, [ 'ID', 'Title' ]
|
||||
|
||||
exports.info = permissions.user (params) ->
|
||||
resin.models.key.get params.id, (error, key) ->
|
||||
errors.handle(error) if error?
|
||||
|
||||
key.public_key = '\n' + _.str.chop(key.public_key, resin.settings.get('sshKeyWidth')).join('\n')
|
||||
log.out(ui.widgets.table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
|
||||
log.out(ui.widgets.table.vertical(key, [ 'ID', 'Title', 'Public Key' ]))
|
||||
|
||||
exports.remove = permissions.user (params, options) ->
|
||||
ui.patterns.remove 'key', options.yes, (callback) ->
|
||||
|
@ -62,7 +62,7 @@ describe 'Errors:', ->
|
||||
expect(logErrorStub).to.have.been.calledWith(error.stack)
|
||||
delete process.env.DEBUG
|
||||
|
||||
it.only 'should handle EISDIR', ->
|
||||
it 'should handle EISDIR', ->
|
||||
error = new Error()
|
||||
error.code = 'EISDIR'
|
||||
error.path = 'hello'
|
||||
@ -70,7 +70,7 @@ describe 'Errors:', ->
|
||||
expect(logErrorStub).to.have.been.calledOnce
|
||||
expect(logErrorStub).to.have.been.calledWith('File is a directory: hello')
|
||||
|
||||
it.only 'should handle ENOENT', ->
|
||||
it 'should handle ENOENT', ->
|
||||
error = new Error()
|
||||
error.code = 'ENOENT'
|
||||
error.path = 'hello'
|
||||
|
@ -57,7 +57,7 @@ exports.prepareObject = (object) ->
|
||||
|
||||
return object
|
||||
|
||||
exports.processTableContents = (contents, map) ->
|
||||
exports.processTableContents = (contents) ->
|
||||
return if not contents?
|
||||
|
||||
# Allows us to simplify the algorithm by not
|
||||
@ -65,9 +65,7 @@ exports.processTableContents = (contents, map) ->
|
||||
if not _.isArray(contents)
|
||||
contents = [ contents ]
|
||||
|
||||
contents = _.map(contents, map or _.identity)
|
||||
contents = _.map(contents, exports.prepareObject)
|
||||
return contents
|
||||
return _.map(contents, exports.prepareObject)
|
||||
|
||||
isRealObject = (object) ->
|
||||
return false if _.isArray(object) or _.isFunction(object)
|
||||
|
@ -97,19 +97,6 @@ describe 'Table Helpers:', ->
|
||||
checkIfArray([ OBJECTS.basic ])
|
||||
checkIfArray([ 'contents' ])
|
||||
|
||||
it 'should be able to manipulate the contents', ->
|
||||
result = tableHelpers.processTableContents { hey: 'there' }, (item) ->
|
||||
item.hey = 'yo'
|
||||
return item
|
||||
|
||||
expect(result).to.deep.equal([ Hey: 'yo' ])
|
||||
|
||||
it 'should not call map if contents does not exist', ->
|
||||
map = sinon.spy()
|
||||
tableHelpers.processTableContents(null, map)
|
||||
tableHelpers.processTableContents(undefined, map)
|
||||
expect(map).to.not.have.been.called
|
||||
|
||||
it 'should get rid of keys not starting with letters', ->
|
||||
result = tableHelpers.processTableContents(OBJECTS.basic, _.identity)
|
||||
expect(result).to.deep.equal [
|
||||
|
@ -3,15 +3,15 @@ tableHelpers = require('./table-helpers')
|
||||
|
||||
# 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) ->
|
||||
exports.horizontal = (contents, ordering, colours) ->
|
||||
return if not contents?
|
||||
contents = tableHelpers.processTableContents(contents, map)
|
||||
contents = tableHelpers.processTableContents(contents)
|
||||
ordering = tableHelpers.normaliseOrdering(ordering, contents)
|
||||
return cliff.stringifyObjectRows(contents, ordering, colours)
|
||||
|
||||
exports.vertical = (contents, map, ordering) ->
|
||||
exports.vertical = (contents, ordering) ->
|
||||
return if not contents?
|
||||
contents = tableHelpers.processTableContents(contents, map)
|
||||
contents = tableHelpers.processTableContents(contents)
|
||||
ordering = tableHelpers.normaliseOrdering(ordering, contents)
|
||||
|
||||
# TODO: Add some kind of separator to make clear
|
||||
|
Loading…
x
Reference in New Issue
Block a user