diff --git a/lib/roles/app.js b/lib/roles/app.js index be8a56f6..4f5a2aef 100644 --- a/lib/roles/app.js +++ b/lib/roles/app.js @@ -16,6 +16,7 @@ var wire = require('../wire') var wireutil = require('../wire/util') var wirerouter = require('../wire/router') var dbapi = require('../db/api') +var datautil = require('../util/datautil') var auth = require('../middleware/auth') var webpack = require('../middleware/webpack') @@ -42,6 +43,7 @@ module.exports = function(options) { app.use('/static/bower_components', express.static(pathutil.resource('bower_components'))) app.use('/static/data', express.static(pathutil.resource('data'))) + app.use('/static/devices', datautil.middleware()) app.use('/static', express.static(pathutil.resource('app'))) if (!options.disableWatch) { @@ -137,6 +139,7 @@ module.exports = function(options) { .then(function(cursor) { return Promise.promisify(cursor.toArray, cursor)() .then(function(list) { + list.forEach(datautil.applyData) res.json({ success: true , devices: list @@ -157,7 +160,7 @@ module.exports = function(options) { if (device) { res.json({ success: true - , device: device + , device: datautil.applyData(device) }) } else { @@ -267,7 +270,7 @@ module.exports = function(options) { socket.emit('device.change', message) }) .on(wire.DeviceIdentityMessage, function(channel, message) { - socket.emit('device.change', message) + socket.emit('device.change', datautil.applyData(message)) }) .on(wire.TransactionProgressMessage, function(channel, message) { socket.emit('tx.progress', channel.toString(), message) diff --git a/lib/util/datautil.js b/lib/util/datautil.js new file mode 100644 index 00000000..2cf5afe9 --- /dev/null +++ b/lib/util/datautil.js @@ -0,0 +1,54 @@ +var deviceData = require('stf-devices-db') +var express = require('express') + +var pathutil = require('./pathutil') +var logger = require('./logger') + +var log = logger.createLogger('util:datautil') + +var aliases = { + 'KYY22': 'L02' +} + +module.exports.applyData = function(device) { + var model = device.model + var match + + match = deviceData[model] + + if (!match) { + if (aliases[model]) { + match = deviceData[aliases[model]] + } + else { + if (!match) { + model = model.replace(/ /g, '_') + match = deviceData[model] + + if (!match) { + model = model.replace(/_/g, '') + match = deviceData[model] + } + } + } + } + + if (match) { + device.name = match.name.id + device.releasedAt = match.date + device.image = match.image.s.replace(/^small\//, '') + } + else { + log.warn( + 'Device database does not have a match for device "%s" (model "%s")' + , device.serial + , device.model + ) + } + + return device +} + +module.exports.middleware = function() { + return express.static(pathutil.root('node_modules/stf-devices-db/data/small')) +} diff --git a/lib/util/pathutil.js b/lib/util/pathutil.js index ba8d2d46..707dc2d0 100644 --- a/lib/util/pathutil.js +++ b/lib/util/pathutil.js @@ -1,5 +1,10 @@ var path = require('path') +// Export +module.exports.root = function(target) { + return path.resolve(__dirname, '../..', target) +} + // Export module.exports.resource = function(target) { return path.resolve(__dirname, '../../res', target) diff --git a/res/app/device-list/device-list.jade b/res/app/device-list/device-list.jade index 43669b80..b707dc45 100644 --- a/res/app/device-list/device-list.jade +++ b/res/app/device-list/device-list.jade @@ -2,10 +2,11 @@ h2 Devices list ul.device-list li(ng-repeat='device in tracker.devices track by device.serial') - span {{ device.serial }} {{ device.present ? 'present' : 'absent' }} {{ device.owner.email }} + span {{ device.serial }} {{ device.name || device.model }} {{ device.present ? 'present' : 'absent' }} {{ device.owner.email }} a(href='#!/devices/{{ device.serial }}') Linky button(ng-click="invite(device)") invite button(ng-click="kick(device)") kick + img(ng-src='/static/devices/{{ device.image }}', ng-if='device.image') div(ng-controller='ShellCommandCtrl') input(type=text, ng-model='command')