Move application field manipulations to the model

This commit is contained in:
Juan Cruz Viotti 2015-01-06 13:22:40 -03:00
parent 45a4f8eda0
commit c311738dd1
2 changed files with 11 additions and 3 deletions

View File

@ -34,9 +34,8 @@ exports.list = permissions.user ->
errors.handle(error) if error? errors.handle(error) if error?
log.out ui.widgets.table.horizontal applications, (application) -> log.out ui.widgets.table.horizontal applications, (application) ->
application.device_type = resin.models.device.getDisplayName(application.device_type) application.device_type = application.device_display_name
application['Online Devices'] = _.where(application.device, is_online: 1).length application.all_devices = application.devices_length
application['All Devices'] = application.device?.length or 0
return application return application
, [ 'ID', 'Name', 'Device Type', 'Online Devices', 'All Devices' ] , [ 'ID', 'Name', 'Device Type', 'Online Devices', 'All Devices' ]

View File

@ -1,5 +1,6 @@
_ = require('lodash-contrib') _ = require('lodash-contrib')
pine = require('./_pine') pine = require('./_pine')
deviceModel = require('./device')
errors = require('../_errors/errors') errors = require('../_errors/errors')
server = require('../_server/server') server = require('../_server/server')
settings = require('../settings') settings = require('../settings')
@ -25,6 +26,14 @@ exports.getAll = (callback) ->
if _.isEmpty(applications) if _.isEmpty(applications)
return callback(new errors.NotAny('applications')) return callback(new errors.NotAny('applications'))
# TODO: It might be worth to do all these handy
# manipulations server side directly.
applications = _.map applications, (application) ->
application.device_display_name = deviceModel.getDisplayName(application.device_type)
application.online_devices = _.where(application.device, is_online: 1).length
application.devices_length = application.device?.length or 0
return application
return callback(null, applications) return callback(null, applications)
.catch (error) -> .catch (error) ->