From ac00a967289b1420143e9dcd2ca9056565ff6793 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 6 Jan 2015 13:35:38 -0300 Subject: [PATCH] Move device manipulation logic to device model --- lib/actions/device.coffee | 24 ++++++++++++------------ lib/resin/models/device.coffee | 10 ++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index b4a9c8bf..672bb5b7 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -13,27 +13,27 @@ exports.list = permissions.user (params, options) -> resin.models.device.getAllByApplication options.application, (error, devices) -> errors.handle(error) if error? - log.out ui.widgets.table.horizontal devices, (device) -> - device.application = device.application[0].app_name - device.device_type = resin.models.device.getDisplayName(device.device_type) - return device - , [ 'ID', 'Name', 'Device Type', 'Is Online', 'Application', 'Status', 'Last Seen' ] + log.out ui.widgets.table.horizontal devices, _.identity, [ + 'ID' + 'Name' + 'Device Display Name' + 'Is Online' + 'Application Name' + 'Status' + 'Last Seen' + ] exports.info = permissions.user (params) -> resin.models.device.get params.id, (error, device) -> errors.handle(error) if error? - log.out ui.widgets.table.vertical device, (device) -> - device.device_type = resin.models.device.getDisplayName(device.device_type) - device.application = device.application[0].app_name - return device - , [ + log.out ui.widgets.table.vertical device, _.identity, [ 'ID' 'Name' - 'Device Type' + 'Device Display Name' 'Is Online' 'IP Address' - 'Application' + 'Application Name' 'Status' 'Last Seen' 'UUID' diff --git a/lib/resin/models/device.coffee b/lib/resin/models/device.coffee index 537d4b9b..85e8a5ab 100644 --- a/lib/resin/models/device.coffee +++ b/lib/resin/models/device.coffee @@ -55,6 +55,12 @@ exports.getAllByApplication = (applicationId, callback) -> if _.isEmpty(devices) return callback(new errors.NotAny('devices')) + # TODO: Move to server + devices = _.map devices, (device) -> + device.application_name = device.application[0].app_name + device.device_display_name = exports.getDisplayName(device.device_type) + return device + return callback(null, devices) .catch (error) -> @@ -83,6 +89,10 @@ exports.get = (deviceId, callback) -> if not device? return callback(new errors.NotFound("device #{id}")) + # TODO: Move to server + device.application_name = device.application[0].app_name + device.device_display_name = exports.getDisplayName(device.device_type) + return callback(null, device) .catch (error) ->