2014-11-18 18:39:26 +00:00
|
|
|
_ = require('lodash')
|
2014-11-19 12:51:42 +00:00
|
|
|
device = require('../device/device')
|
2014-11-19 14:42:18 +00:00
|
|
|
table = require('../table/table')
|
2014-11-20 16:24:39 +00:00
|
|
|
server = require('../server/server')
|
2014-11-21 13:43:03 +00:00
|
|
|
widgets = require('../widgets/widgets')
|
2014-11-18 14:11:43 +00:00
|
|
|
applicationModel = require('../models/application')
|
2014-11-18 16:37:01 +00:00
|
|
|
authHooks = require('../hooks/auth')
|
2014-11-20 16:54:43 +00:00
|
|
|
config = require('../config')
|
2014-11-18 12:41:13 +00:00
|
|
|
|
2014-11-18 16:37:01 +00:00
|
|
|
exports.list = authHooks.failIfNotLoggedIn ->
|
2014-11-18 14:11:43 +00:00
|
|
|
applicationModel.getAll().then (applications) ->
|
2014-11-18 18:39:26 +00:00
|
|
|
|
2014-11-19 14:42:18 +00:00
|
|
|
console.log table.horizontal applications, (application) ->
|
|
|
|
application.device_type = device.getDisplayName(application.device_type)
|
|
|
|
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 13:23:40 +00:00
|
|
|
|
2014-11-19 16:15:39 +00:00
|
|
|
.catch (error) ->
|
|
|
|
throw error
|
|
|
|
|
2014-11-19 13:23:40 +00:00
|
|
|
exports.info = authHooks.failIfNotLoggedIn (id) ->
|
|
|
|
applicationModel.get(id).then (application) ->
|
|
|
|
|
2014-11-19 16:12:08 +00:00
|
|
|
console.log table.vertical application, (application) ->
|
|
|
|
application.device_type = device.getDisplayName(application.device_type)
|
|
|
|
delete application.device
|
|
|
|
return application
|
|
|
|
, [ 'ID', 'Name', 'Device Type', 'Git Repository', 'Commit' ]
|
2014-11-19 13:23:40 +00:00
|
|
|
|
|
|
|
.catch (error) ->
|
|
|
|
throw error
|
2014-11-20 16:24:39 +00:00
|
|
|
|
|
|
|
exports.restart = authHooks.failIfNotLoggedIn (id) ->
|
2014-11-20 16:54:43 +00:00
|
|
|
|
|
|
|
# TODO: Move this URL to config
|
2014-11-20 16:24:39 +00:00
|
|
|
server.post "/application/#{id}/restart", (error) ->
|
|
|
|
throw error if error?
|
2014-11-21 13:43:03 +00:00
|
|
|
|
|
|
|
exports.remove = authHooks.failIfNotLoggedIn (id) ->
|
|
|
|
widgets.confirmRemoval 'application', (error, confirmed) ->
|
|
|
|
return if not confirmed
|
|
|
|
applicationModel.remove(id).catch (error) ->
|
|
|
|
throw error if error?
|