1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 10:39:25 +02:00

All services added back.

This commit is contained in:
Gunther Brunner 2014-02-18 20:43:46 +09:00
parent 347d9e9a55
commit ffce3d5beb
6 changed files with 204 additions and 0 deletions

View file

@ -0,0 +1,2 @@
module.exports = angular.module('stf/scaling', [])
.factory('ScalingService', require('./scaling-service'))

View file

@ -0,0 +1,119 @@
module.exports = function ScalingServiceFactory() {
var scalingService = {
}
scalingService.coordinator = function (realWidth, realHeight) {
var realRatio = realWidth / realHeight
return {
coords: function (width, height, x, y) {
var ratio = width / height
, scaledValue
if (realRatio > ratio) {
// covers the area horizontally
scaledValue = width / realRatio;
// adjust y to start from the scaled top edge
y -= (height - scaledValue) / 2
// not touching the screen, but we want to trigger certain events
// (like touchup) anyway, so let's do it on the edges.
if (y < 0) {
y = 0
}
else if (y > scaledValue) {
y = scaledValue
}
// make sure x is within bounds too
if (x < 0) {
x = 0
}
else if (x > width) {
x = width
}
height = scaledValue
}
else {
// covers the area vertically
scaledValue = height * realRatio
// adjust x to start from the scaled left edge
x -= (width - scaledValue) / 2
// not touching the screen, but we want to trigger certain events
// (like touchup) anyway, so let's do it on the edges.
if (x < 0) {
x = 0
}
else if (x > scaledValue) {
x = scaledValue
}
// make sure y is within bounds too
if (y < 0) {
y = 0
}
else if (y > height) {
y = height
}
width = scaledValue
}
return {
xP: x / width, yP: y / height
}
}, size: function (width, height) {
var ratio = width / height
if (realRatio > ratio) {
// covers the area horizontally
if (width >= realWidth) {
// don't go over max size
width = realWidth
height = realHeight
}
else {
height = Math.floor(width / realRatio)
}
}
else {
// covers the area vertically
if (height >= realHeight) {
// don't go over max size
height = realHeight
width = realWidth
}
else {
width = Math.floor(height * realRatio)
}
}
return {
width: width, height: height
}
}, projectedSize: function (width, height) {
var ratio = width / height
if (realRatio > ratio) {
// covers the area horizontally
height = Math.floor(width / realRatio)
}
else {
width = Math.floor(height * realRatio)
}
return {
width: width, height: height
}
}
}
}
return scalingService
}

View file

@ -0,0 +1,63 @@
var _ = require('lodash')
module.exports = function GroupServiceFactory($rootScope, $http, socket, UserService) {
var groupService = {
}
groupService.group = (function () {
var groupPromise = $http.get('/api/v1/group')
.then(function (response) {
return response.data.group
})
return function () {
return groupPromise
}
})()
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.group().then(function (group) {
group.members.push(data.serial)
console.log('group.join', data)
$rootScope.$digest()
})
}))
socket.on('group.leave', ownerFilter(function (data) {
groupService.group().then(function (group) {
_.pull(group.members, data.serial)
console.log('group.leave', data)
$rootScope.$digest()
})
}))
socket.on('device.absent', /* unfiltered */ function (data) {
groupService.group().then(function (group) {
_.pull(group.members, data.serial)
$rootScope.$digest()
})
})
})
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)
})
}
return groupService
}

View file

@ -0,0 +1,5 @@
module.exports = angular.module('stf/group', [
require('stf/socket').name,
require('stf/user').name
])
.factory('GroupService', require('./group-service'))

View file

@ -0,0 +1,2 @@
module.exports = angular.module('stf/user', [])
.factory('UserService', require('./user-service'))

View file

@ -0,0 +1,13 @@
module.exports = function UserServiceFactory($http) {
var userService = {
}
userService.user = (function () {
var userPromise = $http.get('/api/v1/user')
return function () {
return userPromise
}
})()
return userService
}