mirror of
https://github.com/openstf/stf
synced 2025-10-04 10:19:30 +02:00
Integrate device database.
This commit is contained in:
parent
7a2cdaf071
commit
d1b724ada0
4 changed files with 66 additions and 3 deletions
|
@ -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)
|
||||
|
|
54
lib/util/datautil.js
Normal file
54
lib/util/datautil.js
Normal file
|
@ -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'))
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue