mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +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 wireutil = require('../wire/util')
|
||||||
var wirerouter = require('../wire/router')
|
var wirerouter = require('../wire/router')
|
||||||
var dbapi = require('../db/api')
|
var dbapi = require('../db/api')
|
||||||
|
var datautil = require('../util/datautil')
|
||||||
|
|
||||||
var auth = require('../middleware/auth')
|
var auth = require('../middleware/auth')
|
||||||
var webpack = require('../middleware/webpack')
|
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/bower_components', express.static(pathutil.resource('bower_components')))
|
||||||
app.use('/static/data', express.static(pathutil.resource('data')))
|
app.use('/static/data', express.static(pathutil.resource('data')))
|
||||||
|
app.use('/static/devices', datautil.middleware())
|
||||||
app.use('/static', express.static(pathutil.resource('app')))
|
app.use('/static', express.static(pathutil.resource('app')))
|
||||||
|
|
||||||
if (!options.disableWatch) {
|
if (!options.disableWatch) {
|
||||||
|
@ -137,6 +139,7 @@ module.exports = function(options) {
|
||||||
.then(function(cursor) {
|
.then(function(cursor) {
|
||||||
return Promise.promisify(cursor.toArray, cursor)()
|
return Promise.promisify(cursor.toArray, cursor)()
|
||||||
.then(function(list) {
|
.then(function(list) {
|
||||||
|
list.forEach(datautil.applyData)
|
||||||
res.json({
|
res.json({
|
||||||
success: true
|
success: true
|
||||||
, devices: list
|
, devices: list
|
||||||
|
@ -157,7 +160,7 @@ module.exports = function(options) {
|
||||||
if (device) {
|
if (device) {
|
||||||
res.json({
|
res.json({
|
||||||
success: true
|
success: true
|
||||||
, device: device
|
, device: datautil.applyData(device)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -267,7 +270,7 @@ module.exports = function(options) {
|
||||||
socket.emit('device.change', message)
|
socket.emit('device.change', message)
|
||||||
})
|
})
|
||||||
.on(wire.DeviceIdentityMessage, function(channel, 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) {
|
.on(wire.TransactionProgressMessage, function(channel, message) {
|
||||||
socket.emit('tx.progress', channel.toString(), 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')
|
var path = require('path')
|
||||||
|
|
||||||
|
// Export
|
||||||
|
module.exports.root = function(target) {
|
||||||
|
return path.resolve(__dirname, '../..', target)
|
||||||
|
}
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
module.exports.resource = function(target) {
|
module.exports.resource = function(target) {
|
||||||
return path.resolve(__dirname, '../../res', target)
|
return path.resolve(__dirname, '../../res', target)
|
||||||
|
|
|
@ -2,10 +2,11 @@ h2 Devices list
|
||||||
|
|
||||||
ul.device-list
|
ul.device-list
|
||||||
li(ng-repeat='device in tracker.devices track by device.serial')
|
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
|
a(href='#!/devices/{{ device.serial }}') Linky
|
||||||
button(ng-click="invite(device)") invite
|
button(ng-click="invite(device)") invite
|
||||||
button(ng-click="kick(device)") kick
|
button(ng-click="kick(device)") kick
|
||||||
|
img(ng-src='/static/devices/{{ device.image }}', ng-if='device.image')
|
||||||
|
|
||||||
div(ng-controller='ShellCommandCtrl')
|
div(ng-controller='ShellCommandCtrl')
|
||||||
input(type=text, ng-model='command')
|
input(type=text, ng-model='command')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue