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 http = require('http')
|
||||
var events = require('events')
|
||||
var path = require('path')
|
||||
|
||||
var express = require('express')
|
||||
var validator = require('express-validator')
|
||||
|
@ -73,13 +74,14 @@ module.exports = function(options) {
|
|||
groupRouter.emit(channel.toString(), channel, data)
|
||||
})
|
||||
|
||||
app.get('/partials/:name', function(req, res) {
|
||||
app.get('/partials/*', function(req, res) {
|
||||
var whitelist = {
|
||||
'deviceList': true
|
||||
'devices/index': true
|
||||
, 'devices/control': true
|
||||
}
|
||||
|
||||
if (whitelist[req.params.name]) {
|
||||
res.render('partials/' + req.params.name)
|
||||
if (whitelist.hasOwnProperty(req.params[0])) {
|
||||
res.render(path.join('partials', req.params[0]))
|
||||
}
|
||||
else {
|
||||
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([
|
||||
'./DeviceListCtrl'
|
||||
, './DeviceControlCtrl'
|
||||
]
|
||||
, function() {
|
||||
}
|
||||
|
|
|
@ -3,14 +3,18 @@ define(['./app'], function(app) {
|
|||
'$routeProvider'
|
||||
, '$locationProvider'
|
||||
, function($routeProvider, $locationProvider) {
|
||||
$locationProvider.html5Mode(true)
|
||||
$locationProvider.hashPrefix('!')
|
||||
$routeProvider
|
||||
.when('/', {
|
||||
templateUrl: 'partials/deviceList'
|
||||
.when('/devices', {
|
||||
templateUrl: 'partials/devices/index'
|
||||
, controller: 'DeviceListCtrl'
|
||||
})
|
||||
.when('/devices/:serial', {
|
||||
templateUrl: 'partials/devices/control'
|
||||
, controller: 'DeviceControlCtrl'
|
||||
})
|
||||
.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) {
|
||||
function DevicesServiceFactory($rootScope, socket) {
|
||||
function DeviceServiceFactory($rootScope, $http, socket) {
|
||||
var deviceService = {
|
||||
devices: []
|
||||
, devicesBySerial: {}
|
||||
|
@ -67,12 +67,20 @@ define(['./module', 'oboe'], function(mod, oboe) {
|
|||
insert(device)
|
||||
})
|
||||
|
||||
deviceService.get = function(serial) {
|
||||
return $http.get('/api/v1/devices/' + serial)
|
||||
.then(function(response) {
|
||||
return response.data.device
|
||||
})
|
||||
}
|
||||
|
||||
return deviceService
|
||||
}
|
||||
|
||||
mod.factory('deviceService'
|
||||
, [ '$rootScope'
|
||||
, '$http'
|
||||
, 'socketService'
|
||||
, DevicesServiceFactory
|
||||
, DeviceServiceFactory
|
||||
])
|
||||
})
|
||||
|
|
|
@ -1,75 +1,45 @@
|
|||
define(['./module', 'lodash'], function(mod, _) {
|
||||
function GroupServiceFactory($rootScope, socket) {
|
||||
function GroupServiceFactory($rootScope, socket, userService) {
|
||||
var groupService = {
|
||||
members: []
|
||||
}
|
||||
|
||||
socket.on('group.join', function(data) {
|
||||
userService.user().then(function(user) {
|
||||
function ownerFilter(listener) {
|
||||
return function(data) {
|
||||
if (data.owner.email === user.email) {
|
||||
listener()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
socket.on('group.join', ownerFilter(function(data) {
|
||||
groupService.members.push(data.serial)
|
||||
console.log('group.join', data)
|
||||
$rootScope.$digest()
|
||||
})
|
||||
}))
|
||||
|
||||
socket.on('group.leave', function(data) {
|
||||
socket.on('group.leave', ownerFilter(function(data) {
|
||||
_.pull(groupService.members, data.serial)
|
||||
console.log('group.leave', data)
|
||||
$rootScope.$digest()
|
||||
})
|
||||
}))
|
||||
|
||||
socket.on('device.absent', function(data) {
|
||||
socket.on('device.absent', /* unfiltered */ 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) {
|
||||
return function(key) {
|
||||
socket.emit(type, {
|
||||
key: key
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
groupService.invite = function(requirements) {
|
||||
userService.user().then(function(user) {
|
||||
socket.emit('group.invite', requirements)
|
||||
})
|
||||
}
|
||||
|
||||
groupService.kick = function(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'
|
||||
, [ '$rootScope'
|
||||
, 'socketService'
|
||||
, 'userService'
|
||||
, GroupServiceFactory
|
||||
])
|
||||
})
|
||||
|
|
|
@ -3,6 +3,7 @@ define([
|
|||
, './deviceService'
|
||||
, './groupService'
|
||||
, './userService'
|
||||
, './controlService'
|
||||
]
|
||||
, function() {
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
define(['./module'], function(mod) {
|
||||
function UserServiceFactory($http) {
|
||||
var userService = {
|
||||
info: {}
|
||||
}
|
||||
|
||||
$http.get('/api/v1/user')
|
||||
.success(function(data) {
|
||||
userService.info = data.user
|
||||
})
|
||||
userService.user = (function() {
|
||||
var userPromise = $http.get('/api/v1/user')
|
||||
return function() {
|
||||
return userPromise
|
||||
}
|
||||
})()
|
||||
|
||||
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
|
||||
li(ng-repeat='device in devices track by device.serial')
|
||||
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="kick(device)") kick
|
Loading…
Add table
Add a link
Reference in a new issue