Move widgets to resin/ui module

This commit is contained in:
Juan Cruz Viotti 2014-11-26 13:26:01 -04:00
parent ce8b11004c
commit 67ade4bf12
13 changed files with 13 additions and 15 deletions

View File

@ -1,7 +1,6 @@
_ = require('lodash') _ = require('lodash')
async = require('async') async = require('async')
resin = require('../resin') resin = require('../resin')
widgets = require('../widgets/widgets')
patterns = require('../patterns/patterns') patterns = require('../patterns/patterns')
authHooks = require('../hooks/auth') authHooks = require('../hooks/auth')
config = require('../config') config = require('../config')
@ -16,7 +15,7 @@ exports.create = authHooks.failIfNotLoggedIn (name, program) ->
return callback(null, deviceType) return callback(null, deviceType)
else else
deviceTypes = resin.device.getSupportedDevices() deviceTypes = resin.device.getSupportedDevices()
widgets.select('Select a type', deviceTypes, callback) resin.ui.widgets.select('Select a type', deviceTypes, callback)
(type, callback) -> (type, callback) ->
@ -33,7 +32,7 @@ exports.create = authHooks.failIfNotLoggedIn (name, program) ->
exports.list = authHooks.failIfNotLoggedIn -> exports.list = authHooks.failIfNotLoggedIn ->
resin.models.application.getAll().then (applications) -> resin.models.application.getAll().then (applications) ->
resin.log.out widgets.table.horizontal applications, (application) -> resin.log.out resin.ui.widgets.table.horizontal applications, (application) ->
application.device_type = resin.device.getDisplayName(application.device_type) application.device_type = resin.device.getDisplayName(application.device_type)
application['Online Devices'] = _.where(application.device, is_online: 1).length application['Online Devices'] = _.where(application.device, is_online: 1).length
application['All Devices'] = application.device?.length or 0 application['All Devices'] = application.device?.length or 0
@ -47,7 +46,7 @@ exports.list = authHooks.failIfNotLoggedIn ->
exports.info = authHooks.failIfNotLoggedIn (id) -> exports.info = authHooks.failIfNotLoggedIn (id) ->
resin.models.application.get(id).then (application) -> resin.models.application.get(id).then (application) ->
resin.log.out widgets.table.vertical application, (application) -> resin.log.out resin.ui.widgets.table.vertical application, (application) ->
application.device_type = resin.device.getDisplayName(application.device_type) application.device_type = resin.device.getDisplayName(application.device_type)
delete application.device delete application.device
return application return application

View File

@ -2,7 +2,6 @@ open = require('open')
async = require('async') async = require('async')
resin = require('../resin') resin = require('../resin')
authHooks = require('../hooks/auth') authHooks = require('../hooks/auth')
widgets = require('../widgets/widgets')
config = require('../config') config = require('../config')
exports.login = (credentials) -> exports.login = (credentials) ->
@ -12,7 +11,7 @@ exports.login = (credentials) ->
if credentials? if credentials?
return resin.auth.parseCredentials(credentials, callback) return resin.auth.parseCredentials(credentials, callback)
else else
return widgets.login(callback) return resin.ui.widgets.login(callback)
(credentials, callback) -> (credentials, callback) ->
resin.auth.login(credentials, callback) resin.auth.login(credentials, callback)

View File

@ -1,5 +1,4 @@
resin = require('../resin') resin = require('../resin')
widgets = require('../widgets/widgets')
patterns = require('../patterns/patterns') patterns = require('../patterns/patterns')
authHooks = require('../hooks/auth') authHooks = require('../hooks/auth')
config = require('../config') config = require('../config')
@ -7,7 +6,7 @@ config = require('../config')
exports.list = authHooks.failIfNotLoggedIn (applicationId) -> exports.list = authHooks.failIfNotLoggedIn (applicationId) ->
resin.models.device.getAll(applicationId).then (devices) -> resin.models.device.getAll(applicationId).then (devices) ->
resin.log.out widgets.table.horizontal devices, (device) -> resin.log.out resin.ui.widgets.table.horizontal devices, (device) ->
device.application = device.application[0].app_name device.application = device.application[0].app_name
device.device_type = resin.device.getDisplayName(device.device_type) device.device_type = resin.device.getDisplayName(device.device_type)
delete device.note delete device.note

View File

@ -1,5 +1,4 @@
_ = require('lodash') _ = require('lodash')
widgets = require('../widgets/widgets')
patterns = require('../patterns/patterns') patterns = require('../patterns/patterns')
resin = require('../resin') resin = require('../resin')
authHooks = require('../hooks/auth') authHooks = require('../hooks/auth')
@ -20,7 +19,7 @@ exports.list = authHooks.failIfNotLoggedIn (program) ->
if not program.parent.verbose? if not program.parent.verbose?
environmentVariables = _.reject(environmentVariables, isSystemVariable) environmentVariables = _.reject(environmentVariables, isSystemVariable)
resin.log.out(widgets.table.horizontal(environmentVariables)) resin.log.out(resin.ui.widgets.table.horizontal(environmentVariables))
.catch(resin.errors.handle) .catch(resin.errors.handle)
exports.remove = authHooks.failIfNotLoggedIn (id, program) -> exports.remove = authHooks.failIfNotLoggedIn (id, program) ->

View File

@ -2,14 +2,13 @@ _ = require('lodash')
resin = require('../resin') resin = require('../resin')
authHooks = require('../hooks/auth') authHooks = require('../hooks/auth')
patterns = require('../patterns/patterns') patterns = require('../patterns/patterns')
widgets = require('../widgets/widgets')
helpers = require('../helpers/helpers') helpers = require('../helpers/helpers')
config = require('../config') config = require('../config')
exports.list = authHooks.failIfNotLoggedIn -> exports.list = authHooks.failIfNotLoggedIn ->
resin.server.get config.urls.keys, (error, response, keys) -> resin.server.get config.urls.keys, (error, response, keys) ->
resin.errors.handle(error) if error? resin.errors.handle(error) if error?
resin.log.out widgets.table.horizontal keys, (key) -> resin.log.out resin.ui.widgets.table.horizontal keys, (key) ->
delete key.public_key delete key.public_key
return key return key
, [ 'ID', 'Title' ] , [ 'ID', 'Title' ]
@ -27,7 +26,7 @@ exports.info = authHooks.failIfNotLoggedIn (id) ->
resin.errors.handle(new resin.errors.NotFound("key #{id}")) resin.errors.handle(new resin.errors.NotFound("key #{id}"))
key.public_key = '\n' + helpers.formatLongString(key.public_key, config.sshKeyWidth) key.public_key = '\n' + helpers.formatLongString(key.public_key, config.sshKeyWidth)
resin.log.out(widgets.table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ])) resin.log.out(resin.ui.widgets.table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
exports.remove = authHooks.failIfNotLoggedIn (id, program) -> exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
patterns.remove 'key', program.parent.yes, (callback) -> patterns.remove 'key', program.parent.yes, (callback) ->

View File

@ -1,5 +1,5 @@
async = require('async') async = require('async')
widgets = require('../widgets/widgets') resin = require('../resin')
exports.remove = (name, confirmAttribute, deleteFunction, outerCallback) -> exports.remove = (name, confirmAttribute, deleteFunction, outerCallback) ->
async.waterfall([ async.waterfall([
@ -8,7 +8,7 @@ exports.remove = (name, confirmAttribute, deleteFunction, outerCallback) ->
if confirmAttribute if confirmAttribute
return callback(null, true) return callback(null, true)
widgets.confirmRemoval(name, callback) resin.ui.widgets.confirmRemoval(name, callback)
(confirmed, callback) -> (confirmed, callback) ->
return callback() if not confirmed return callback() if not confirmed

View File

@ -7,3 +7,4 @@ module.exports =
data: require('./data/data') data: require('./data/data')
auth: require('./auth/auth') auth: require('./auth/auth')
device: require('./device/device') device: require('./device/device')
ui: require('./ui')

View File

@ -0,0 +1,2 @@
module.exports =
widgets: require('./widgets/widgets')