mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Attempting to make it easier to work with a single device. Still not bound to the new controlService.
This commit is contained in:
parent
37303c5d92
commit
36d0af71b5
11 changed files with 141 additions and 75 deletions
|
@ -1,6 +1,7 @@
|
||||||
var url = require('url')
|
var url = require('url')
|
||||||
var http = require('http')
|
var http = require('http')
|
||||||
var events = require('events')
|
var events = require('events')
|
||||||
|
var path = require('path')
|
||||||
|
|
||||||
var express = require('express')
|
var express = require('express')
|
||||||
var validator = require('express-validator')
|
var validator = require('express-validator')
|
||||||
|
@ -73,13 +74,14 @@ module.exports = function(options) {
|
||||||
groupRouter.emit(channel.toString(), channel, data)
|
groupRouter.emit(channel.toString(), channel, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/partials/:name', function(req, res) {
|
app.get('/partials/*', function(req, res) {
|
||||||
var whitelist = {
|
var whitelist = {
|
||||||
'deviceList': true
|
'devices/index': true
|
||||||
|
, 'devices/control': true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whitelist[req.params.name]) {
|
if (whitelist.hasOwnProperty(req.params[0])) {
|
||||||
res.render('partials/' + req.params.name)
|
res.render(path.join('partials', req.params[0]))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.send(404)
|
res.send(404)
|
||||||
|
|
17
res/app/scripts/controllers/DeviceControlCtrl.js
Normal file
17
res/app/scripts/controllers/DeviceControlCtrl.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
define(['./module'], function(mod) {
|
||||||
|
function DeviceControlCtrl($scope, $routeParams, deviceService) {
|
||||||
|
$scope.device = null
|
||||||
|
|
||||||
|
deviceService.get($routeParams.serial)
|
||||||
|
.then(function(device) {
|
||||||
|
$scope.device = device
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
mod.controller('DeviceControlCtrl'
|
||||||
|
, [ '$scope'
|
||||||
|
, '$routeParams'
|
||||||
|
, 'deviceService'
|
||||||
|
, DeviceControlCtrl
|
||||||
|
])
|
||||||
|
})
|
|
@ -1,5 +1,6 @@
|
||||||
define([
|
define([
|
||||||
'./DeviceListCtrl'
|
'./DeviceListCtrl'
|
||||||
|
, './DeviceControlCtrl'
|
||||||
]
|
]
|
||||||
, function() {
|
, function() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,18 @@ define(['./app'], function(app) {
|
||||||
'$routeProvider'
|
'$routeProvider'
|
||||||
, '$locationProvider'
|
, '$locationProvider'
|
||||||
, function($routeProvider, $locationProvider) {
|
, function($routeProvider, $locationProvider) {
|
||||||
$locationProvider.html5Mode(true)
|
$locationProvider.hashPrefix('!')
|
||||||
$routeProvider
|
$routeProvider
|
||||||
.when('/', {
|
.when('/devices', {
|
||||||
templateUrl: 'partials/deviceList'
|
templateUrl: 'partials/devices/index'
|
||||||
, controller: 'DeviceListCtrl'
|
, controller: 'DeviceListCtrl'
|
||||||
})
|
})
|
||||||
|
.when('/devices/:serial', {
|
||||||
|
templateUrl: 'partials/devices/control'
|
||||||
|
, controller: 'DeviceControlCtrl'
|
||||||
|
})
|
||||||
.otherwise({
|
.otherwise({
|
||||||
redirectTo: '/'
|
redirectTo: '/devices'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
59
res/app/scripts/services/controlService.js
Normal file
59
res/app/scripts/services/controlService.js
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
define(['./module', 'lodash'], function(mod, _) {
|
||||||
|
function ControlServiceFactory($rootScope, socket) {
|
||||||
|
var controlService = {
|
||||||
|
members: []
|
||||||
|
}
|
||||||
|
|
||||||
|
function touchSender(type) {
|
||||||
|
return function(x, y) {
|
||||||
|
socket.emit(type, {
|
||||||
|
x: x
|
||||||
|
, y: y
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function keySender(type) {
|
||||||
|
return function(key) {
|
||||||
|
socket.emit(type, {
|
||||||
|
key: key
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
controlService.touchDown = touchSender('input.touchDown')
|
||||||
|
controlService.touchMove = touchSender('input.touchMove')
|
||||||
|
controlService.touchUp = touchSender('input.touchUp')
|
||||||
|
controlService.tap = touchSender('input.tap')
|
||||||
|
|
||||||
|
controlService.keyDown = keySender('input.keyDown')
|
||||||
|
controlService.keyUp = keySender('input.keyUp')
|
||||||
|
controlService.keyPress = keySender('input.keyPress')
|
||||||
|
|
||||||
|
controlService.home = function() {
|
||||||
|
socket.emit('input.home')
|
||||||
|
}
|
||||||
|
|
||||||
|
controlService.menu = function() {
|
||||||
|
socket.emit('input.menu')
|
||||||
|
}
|
||||||
|
|
||||||
|
controlService.back = function() {
|
||||||
|
socket.emit('input.back')
|
||||||
|
}
|
||||||
|
|
||||||
|
controlService.type = function(text) {
|
||||||
|
socket.emit('input.type', {
|
||||||
|
text: text
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return controlService
|
||||||
|
}
|
||||||
|
|
||||||
|
mod.factory('controlService'
|
||||||
|
, [ '$rootScope'
|
||||||
|
, 'socketService'
|
||||||
|
, ControlServiceFactory
|
||||||
|
])
|
||||||
|
})
|
|
@ -1,5 +1,5 @@
|
||||||
define(['./module', 'oboe'], function(mod, oboe) {
|
define(['./module', 'oboe'], function(mod, oboe) {
|
||||||
function DevicesServiceFactory($rootScope, socket) {
|
function DeviceServiceFactory($rootScope, $http, socket) {
|
||||||
var deviceService = {
|
var deviceService = {
|
||||||
devices: []
|
devices: []
|
||||||
, devicesBySerial: {}
|
, devicesBySerial: {}
|
||||||
|
@ -67,12 +67,20 @@ define(['./module', 'oboe'], function(mod, oboe) {
|
||||||
insert(device)
|
insert(device)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
deviceService.get = function(serial) {
|
||||||
|
return $http.get('/api/v1/devices/' + serial)
|
||||||
|
.then(function(response) {
|
||||||
|
return response.data.device
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return deviceService
|
return deviceService
|
||||||
}
|
}
|
||||||
|
|
||||||
mod.factory('deviceService'
|
mod.factory('deviceService'
|
||||||
, [ '$rootScope'
|
, [ '$rootScope'
|
||||||
|
, '$http'
|
||||||
, 'socketService'
|
, 'socketService'
|
||||||
, DevicesServiceFactory
|
, DeviceServiceFactory
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,75 +1,45 @@
|
||||||
define(['./module', 'lodash'], function(mod, _) {
|
define(['./module', 'lodash'], function(mod, _) {
|
||||||
function GroupServiceFactory($rootScope, socket) {
|
function GroupServiceFactory($rootScope, socket, userService) {
|
||||||
var groupService = {
|
var groupService = {
|
||||||
members: []
|
members: []
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on('group.join', function(data) {
|
userService.user().then(function(user) {
|
||||||
groupService.members.push(data.serial)
|
function ownerFilter(listener) {
|
||||||
console.log('group.join', data)
|
return function(data) {
|
||||||
$rootScope.$digest()
|
if (data.owner.email === user.email) {
|
||||||
})
|
listener()
|
||||||
|
}
|
||||||
socket.on('group.leave', function(data) {
|
}
|
||||||
_.pull(groupService.members, data.serial)
|
|
||||||
console.log('group.leave', data)
|
|
||||||
$rootScope.$digest()
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('device.absent', function(data) {
|
|
||||||
_.pull(groupService.members, data.serial)
|
|
||||||
$rootScope.$digest()
|
|
||||||
})
|
|
||||||
|
|
||||||
function touchSender(type) {
|
|
||||||
return function(x, y) {
|
|
||||||
socket.emit(type, {
|
|
||||||
x: x
|
|
||||||
, y: y
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function keySender(type) {
|
socket.on('group.join', ownerFilter(function(data) {
|
||||||
return function(key) {
|
groupService.members.push(data.serial)
|
||||||
socket.emit(type, {
|
console.log('group.join', data)
|
||||||
key: key
|
$rootScope.$digest()
|
||||||
})
|
}))
|
||||||
}
|
|
||||||
}
|
socket.on('group.leave', ownerFilter(function(data) {
|
||||||
|
_.pull(groupService.members, data.serial)
|
||||||
|
console.log('group.leave', data)
|
||||||
|
$rootScope.$digest()
|
||||||
|
}))
|
||||||
|
|
||||||
|
socket.on('device.absent', /* unfiltered */ function(data) {
|
||||||
|
_.pull(groupService.members, data.serial)
|
||||||
|
$rootScope.$digest()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
groupService.invite = function(requirements) {
|
groupService.invite = function(requirements) {
|
||||||
socket.emit('group.invite', requirements)
|
userService.user().then(function(user) {
|
||||||
|
socket.emit('group.invite', requirements)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
groupService.kick = function(requirements) {
|
groupService.kick = function(requirements) {
|
||||||
socket.emit('group.kick', requirements)
|
userService.user().then(function(user) {
|
||||||
}
|
socket.emit('group.kick', requirements)
|
||||||
|
|
||||||
groupService.touchDown = touchSender('input.touchDown')
|
|
||||||
groupService.touchMove = touchSender('input.touchMove')
|
|
||||||
groupService.touchUp = touchSender('input.touchUp')
|
|
||||||
groupService.tap = touchSender('input.tap')
|
|
||||||
|
|
||||||
groupService.keyDown = keySender('input.keyDown')
|
|
||||||
groupService.keyUp = keySender('input.keyUp')
|
|
||||||
groupService.keyPress = keySender('input.keyPress')
|
|
||||||
|
|
||||||
groupService.home = function() {
|
|
||||||
socket.emit('input.home')
|
|
||||||
}
|
|
||||||
|
|
||||||
groupService.menu = function() {
|
|
||||||
socket.emit('input.menu')
|
|
||||||
}
|
|
||||||
|
|
||||||
groupService.back = function() {
|
|
||||||
socket.emit('input.back')
|
|
||||||
}
|
|
||||||
|
|
||||||
groupService.type = function(text) {
|
|
||||||
socket.emit('input.type', {
|
|
||||||
text: text
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +49,7 @@ define(['./module', 'lodash'], function(mod, _) {
|
||||||
mod.factory('groupService'
|
mod.factory('groupService'
|
||||||
, [ '$rootScope'
|
, [ '$rootScope'
|
||||||
, 'socketService'
|
, 'socketService'
|
||||||
|
, 'userService'
|
||||||
, GroupServiceFactory
|
, GroupServiceFactory
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,6 +3,7 @@ define([
|
||||||
, './deviceService'
|
, './deviceService'
|
||||||
, './groupService'
|
, './groupService'
|
||||||
, './userService'
|
, './userService'
|
||||||
|
, './controlService'
|
||||||
]
|
]
|
||||||
, function() {
|
, function() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
define(['./module'], function(mod) {
|
define(['./module'], function(mod) {
|
||||||
function UserServiceFactory($http) {
|
function UserServiceFactory($http) {
|
||||||
var userService = {
|
var userService = {
|
||||||
info: {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$http.get('/api/v1/user')
|
userService.user = (function() {
|
||||||
.success(function(data) {
|
var userPromise = $http.get('/api/v1/user')
|
||||||
userService.info = data.user
|
return function() {
|
||||||
})
|
return userPromise
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
return userService
|
return userService
|
||||||
}
|
}
|
||||||
|
|
1
res/app/views/partials/devices/control.jade
Normal file
1
res/app/views/partials/devices/control.jade
Normal file
|
@ -0,0 +1 @@
|
||||||
|
h1 {{ device.serial }}
|
|
@ -3,5 +3,6 @@ h1 Devices
|
||||||
ul
|
ul
|
||||||
li(ng-repeat='device in devices track by device.serial')
|
li(ng-repeat='device in devices track by device.serial')
|
||||||
span {{ device.serial }} {{ device.present ? 'present' : 'absent' }} {{ device.owner.email }}
|
span {{ device.serial }} {{ device.present ? 'present' : 'absent' }} {{ device.owner.email }}
|
||||||
|
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
|
Loading…
Add table
Add a link
Reference in a new issue