2015-01-09 15:22:18 +00:00
|
|
|
_ = require('lodash-contrib')
|
2014-11-21 14:12:03 +00:00
|
|
|
async = require('async')
|
2015-01-08 12:04:37 +00:00
|
|
|
resin = require('resin-sdk')
|
2014-12-05 16:00:15 +00:00
|
|
|
ui = require('../ui')
|
2014-12-12 21:20:29 +00:00
|
|
|
permissions = require('../permissions/permissions')
|
2014-11-18 12:41:13 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.create = permissions.user (params, options, done) ->
|
|
|
|
async.waterfall([
|
2014-11-24 14:45:54 +00:00
|
|
|
|
|
|
|
(callback) ->
|
2014-12-12 21:20:29 +00:00
|
|
|
deviceType = options.type
|
2014-11-24 14:56:03 +00:00
|
|
|
|
|
|
|
if deviceType?
|
|
|
|
return callback(null, deviceType)
|
|
|
|
else
|
2014-12-22 19:02:52 +00:00
|
|
|
deviceTypes = resin.models.device.getSupportedDeviceTypes()
|
2014-12-05 16:00:15 +00:00
|
|
|
ui.widgets.select('Select a type', deviceTypes, callback)
|
2014-11-24 14:45:54 +00:00
|
|
|
|
|
|
|
(type, callback) ->
|
2015-01-09 16:16:10 +00:00
|
|
|
resin.models.application.create(params.name, type, callback)
|
2014-11-24 14:45:54 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
], done)
|
2014-11-24 14:45:54 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.list = permissions.user (params, options, done) ->
|
|
|
|
resin.models.application.getAll (error, applications) ->
|
|
|
|
return done(error) if error?
|
2015-01-15 14:36:43 +00:00
|
|
|
console.log ui.widgets.table.horizontal applications, [
|
2015-01-06 17:07:35 +00:00
|
|
|
'ID'
|
|
|
|
'Name'
|
|
|
|
'Device Display Name'
|
|
|
|
'Online Devices'
|
|
|
|
'Devices Length'
|
|
|
|
]
|
2015-01-15 13:47:17 +00:00
|
|
|
return done()
|
2014-11-19 13:23:40 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.info = permissions.user (params, options, done) ->
|
|
|
|
resin.models.application.get params.id, (error, application) ->
|
|
|
|
return done(error) if error?
|
2015-01-15 14:36:43 +00:00
|
|
|
console.log ui.widgets.table.vertical application, [
|
2015-01-06 17:07:35 +00:00
|
|
|
'ID'
|
|
|
|
'Name'
|
|
|
|
'Device Display Name'
|
|
|
|
'Git Repository'
|
|
|
|
'Commit'
|
|
|
|
]
|
2015-01-15 13:47:17 +00:00
|
|
|
return done()
|
2014-11-19 13:23:40 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.restart = permissions.user (params, options, done) ->
|
|
|
|
resin.models.application.restart(params.id, done)
|
2014-11-21 13:43:03 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.remove = permissions.user (params, options, done) ->
|
2014-12-12 21:20:29 +00:00
|
|
|
ui.patterns.remove 'application', options.yes, (callback) ->
|
|
|
|
resin.models.application.remove(params.id, callback)
|
2015-01-15 13:47:17 +00:00
|
|
|
, done
|
2014-12-11 15:31:56 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.init = permissions.user (params, options, done) ->
|
2014-12-11 15:31:56 +00:00
|
|
|
|
2014-12-11 20:00:24 +00:00
|
|
|
currentDirectory = process.cwd()
|
|
|
|
|
2014-12-11 15:31:56 +00:00
|
|
|
async.waterfall [
|
|
|
|
|
2014-12-11 20:00:24 +00:00
|
|
|
(callback) ->
|
2014-12-12 13:19:46 +00:00
|
|
|
resin.vcs.isResinProject(currentDirectory, callback)
|
2014-12-11 20:00:24 +00:00
|
|
|
|
2014-12-12 13:19:46 +00:00
|
|
|
(isResinProject, callback) ->
|
|
|
|
if isResinProject
|
2014-12-11 20:00:24 +00:00
|
|
|
error = new Error('Project is already a resin application.')
|
|
|
|
return callback(error)
|
|
|
|
return callback()
|
|
|
|
|
2014-12-11 15:31:56 +00:00
|
|
|
(callback) ->
|
2014-12-12 21:20:29 +00:00
|
|
|
resin.models.application.get(params.id, callback)
|
2014-12-11 15:31:56 +00:00
|
|
|
|
|
|
|
(application, callback) ->
|
2014-12-12 13:19:46 +00:00
|
|
|
resin.vcs.initProjectWithApplication(application, currentDirectory, callback)
|
2014-12-11 15:31:56 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
], done
|