mirror of
https://github.com/openstf/stf
synced 2025-10-05 19:42:01 +02:00
All services added back.
This commit is contained in:
parent
347d9e9a55
commit
ffce3d5beb
6 changed files with 204 additions and 0 deletions
63
res/app/components/stf/user/group/group-service.js
Normal file
63
res/app/components/stf/user/group/group-service.js
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue