2014-11-18 14:39:26 -04:00
|
|
|
_ = require('lodash')
|
2014-11-21 10:12:03 -04:00
|
|
|
async = require('async')
|
2014-11-26 12:07:10 -04:00
|
|
|
resin = require('../resin')
|
2014-11-18 08:41:13 -04:00
|
|
|
|
2014-11-27 11:22:48 -04:00
|
|
|
exports.create = (name) ->
|
2014-11-24 10:45:54 -04:00
|
|
|
async.waterfall [
|
|
|
|
|
|
|
|
(callback) ->
|
2014-11-27 11:22:48 -04:00
|
|
|
deviceType = resin.cli.getArgument('type')
|
2014-11-24 10:56:03 -04:00
|
|
|
|
|
|
|
if deviceType?
|
|
|
|
return callback(null, deviceType)
|
|
|
|
else
|
2014-11-26 13:12:39 -04:00
|
|
|
deviceTypes = resin.device.getSupportedDevices()
|
2014-11-26 13:26:01 -04:00
|
|
|
resin.ui.widgets.select('Select a type', deviceTypes, callback)
|
2014-11-24 10:45:54 -04:00
|
|
|
|
|
|
|
(type, callback) ->
|
2014-11-24 10:56:03 -04:00
|
|
|
|
|
|
|
# TODO: Currently returns 'unknown'.
|
|
|
|
# Maybe we should break or handle better?
|
2014-11-26 13:12:39 -04:00
|
|
|
slugifiedType = resin.device.getDeviceSlug(type)
|
2014-11-24 10:56:03 -04:00
|
|
|
|
2014-11-26 13:54:05 -04:00
|
|
|
resin.models.application.create(name, slugifiedType, callback)
|
2014-11-24 10:45:54 -04:00
|
|
|
|
2014-11-26 12:38:02 -04:00
|
|
|
], resin.errors.handle
|
2014-11-24 10:45:54 -04:00
|
|
|
|
2014-11-27 10:06:11 -04:00
|
|
|
exports.list = ->
|
2014-11-26 13:54:05 -04:00
|
|
|
resin.models.application.getAll (error, applications) ->
|
|
|
|
resin.errors.handle(error) if error?
|
2014-11-18 14:39:26 -04:00
|
|
|
|
2014-11-26 13:26:01 -04:00
|
|
|
resin.log.out resin.ui.widgets.table.horizontal applications, (application) ->
|
2014-11-26 13:12:39 -04:00
|
|
|
application.device_type = resin.device.getDisplayName(application.device_type)
|
2014-11-19 10:42:18 -04:00
|
|
|
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' ]
|
2014-11-19 09:23:40 -04:00
|
|
|
|
2014-11-27 10:06:11 -04:00
|
|
|
exports.info = (id) ->
|
2014-11-26 13:54:05 -04:00
|
|
|
resin.models.application.get id, (error, application) ->
|
|
|
|
resin.errors.handle(error) if error?
|
2014-11-19 09:23:40 -04:00
|
|
|
|
2014-11-26 13:26:01 -04:00
|
|
|
resin.log.out resin.ui.widgets.table.vertical application, (application) ->
|
2014-11-26 13:12:39 -04:00
|
|
|
application.device_type = resin.device.getDisplayName(application.device_type)
|
2014-11-19 12:12:08 -04:00
|
|
|
delete application.device
|
|
|
|
return application
|
|
|
|
, [ 'ID', 'Name', 'Device Type', 'Git Repository', 'Commit' ]
|
2014-11-19 09:23:40 -04:00
|
|
|
|
2014-11-27 10:06:11 -04:00
|
|
|
exports.restart = (id) ->
|
2014-11-20 12:54:43 -04:00
|
|
|
|
2014-11-26 13:54:05 -04:00
|
|
|
resin.models.application.restart id, (error) ->
|
|
|
|
resin.errors.handle(error) if error?
|
2014-11-21 09:43:03 -04:00
|
|
|
|
2014-11-27 11:22:48 -04:00
|
|
|
exports.remove = (id) ->
|
|
|
|
confirmArgument = resin.cli.getArgument('yes')
|
|
|
|
resin.ui.patterns.remove 'application', confirmArgument, (callback) ->
|
2014-11-26 13:54:05 -04:00
|
|
|
resin.models.application.remove(id, callback)
|
2014-11-26 12:38:02 -04:00
|
|
|
, resin.errors.handle
|