2014-11-18 18:39:26 +00:00
|
|
|
_ = require('lodash')
|
2014-11-21 14:12:03 +00:00
|
|
|
async = require('async')
|
2014-12-11 15:31:56 +00:00
|
|
|
gitCli = require('git-cli')
|
2014-11-26 16:07:10 +00:00
|
|
|
resin = require('../resin')
|
2014-12-05 16:00:15 +00:00
|
|
|
ui = require('../ui')
|
2014-12-22 16:41:14 +00:00
|
|
|
log = require('../log/log')
|
2014-12-22 16:47:12 +00:00
|
|
|
errors = require('../errors/errors')
|
2014-12-12 21:20:29 +00:00
|
|
|
permissions = require('../permissions/permissions')
|
2014-11-18 12:41:13 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.create = permissions.user (params, options) ->
|
2014-11-24 14:45:54 +00:00
|
|
|
async.waterfall [
|
|
|
|
|
|
|
|
(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) ->
|
2014-11-24 14:56:03 +00:00
|
|
|
|
|
|
|
# TODO: Currently returns 'unknown'.
|
|
|
|
# Maybe we should break or handle better?
|
2014-12-22 19:02:52 +00:00
|
|
|
slugifiedType = resin.models.device.getDeviceSlug(type)
|
2014-11-24 14:56:03 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
resin.models.application.create(params.name, slugifiedType, callback)
|
2014-11-24 14:45:54 +00:00
|
|
|
|
2014-12-22 16:47:12 +00:00
|
|
|
], errors.handle
|
2014-11-24 14:45:54 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.list = permissions.user ->
|
2014-11-26 17:54:05 +00:00
|
|
|
resin.models.application.getAll (error, applications) ->
|
2014-12-22 16:47:12 +00:00
|
|
|
errors.handle(error) if error?
|
2014-11-18 18:39:26 +00:00
|
|
|
|
2014-12-22 16:41:14 +00:00
|
|
|
log.out ui.widgets.table.horizontal applications, (application) ->
|
2015-01-06 16:22:40 +00:00
|
|
|
application.device_type = application.device_display_name
|
|
|
|
application.all_devices = application.devices_length
|
2014-11-19 14:42:18 +00:00
|
|
|
return application
|
|
|
|
, [ 'ID', 'Name', 'Device Type', 'Online Devices', 'All Devices' ]
|
2014-11-19 13:23:40 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.info = permissions.user (params) ->
|
|
|
|
resin.models.application.get params.id, (error, application) ->
|
2014-12-22 16:47:12 +00:00
|
|
|
errors.handle(error) if error?
|
2014-11-19 13:23:40 +00:00
|
|
|
|
2014-12-22 16:41:14 +00:00
|
|
|
log.out ui.widgets.table.vertical application, (application) ->
|
2015-01-06 16:24:11 +00:00
|
|
|
application.device_type = application.device_display_name
|
2014-11-19 16:12:08 +00:00
|
|
|
return application
|
|
|
|
, [ 'ID', 'Name', 'Device Type', 'Git Repository', 'Commit' ]
|
2014-11-19 13:23:40 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.restart = permissions.user (params) ->
|
|
|
|
resin.models.application.restart params.id, (error) ->
|
2014-12-22 16:47:12 +00:00
|
|
|
errors.handle(error) if error?
|
2014-11-21 13:43:03 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.remove = permissions.user (params, options) ->
|
|
|
|
ui.patterns.remove 'application', options.yes, (callback) ->
|
|
|
|
resin.models.application.remove(params.id, callback)
|
2014-12-22 16:47:12 +00:00
|
|
|
, errors.handle
|
2014-12-11 15:31:56 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.init = permissions.user (params) ->
|
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
|
|
|
|
|
|
|
], (error) ->
|
2014-12-22 16:47:12 +00:00
|
|
|
errors.handle(error) if error?
|