diff --git a/res/app/components/stf/control/scaling/index.js b/res/app/components/stf/control/scaling/index.js new file mode 100644 index 00000000..da99b086 --- /dev/null +++ b/res/app/components/stf/control/scaling/index.js @@ -0,0 +1,2 @@ +module.exports = angular.module('stf/scaling', []) + .factory('ScalingService', require('./scaling-service')) \ No newline at end of file diff --git a/res/app/components/stf/control/scaling/scaling-service.js b/res/app/components/stf/control/scaling/scaling-service.js new file mode 100644 index 00000000..ed5fcaf1 --- /dev/null +++ b/res/app/components/stf/control/scaling/scaling-service.js @@ -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 +} \ No newline at end of file diff --git a/res/app/components/stf/user/group/group-service.js b/res/app/components/stf/user/group/group-service.js new file mode 100644 index 00000000..f34fa4d8 --- /dev/null +++ b/res/app/components/stf/user/group/group-service.js @@ -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 +} \ No newline at end of file diff --git a/res/app/components/stf/user/group/index.js b/res/app/components/stf/user/group/index.js new file mode 100644 index 00000000..a68a400c --- /dev/null +++ b/res/app/components/stf/user/group/index.js @@ -0,0 +1,5 @@ +module.exports = angular.module('stf/group', [ + require('stf/socket').name, + require('stf/user').name +]) + .factory('GroupService', require('./group-service')) \ No newline at end of file diff --git a/res/app/components/stf/user/index.js b/res/app/components/stf/user/index.js new file mode 100644 index 00000000..608db06c --- /dev/null +++ b/res/app/components/stf/user/index.js @@ -0,0 +1,2 @@ +module.exports = angular.module('stf/user', []) + .factory('UserService', require('./user-service')) \ No newline at end of file diff --git a/res/app/components/stf/user/user-service.js b/res/app/components/stf/user/user-service.js new file mode 100644 index 00000000..5037ac47 --- /dev/null +++ b/res/app/components/stf/user/user-service.js @@ -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 +}