Skip to content

Commit 117461a

Browse files
committed
load new games in session on
1 parent 58c41b5 commit 117461a

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

public/app/sessionController.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
var module = angular.module('scorekeep');
22
module.controller('SessionController', Session);
3-
function Session($scope, $http, $location, $routeParams, SessionService, RulesService, GameCollection, UserService, GameService, api) {
3+
function Session($scope, $http, $location, $interval, $routeParams, SessionService, RulesService, GameCollection, UserService, GameService, api) {
44
$scope.games = GameService.query({ sessionid: $routeParams.sessionid });
5-
$scope.session = SessionService.get({ id: $routeParams.sessionid });
5+
$scope.session = new SessionService;
66
$scope.user = UserService.get({ id: $routeParams.userid });
77
$scope.allrules = RulesService.query();
88

9+
$scope.loadSession = function() {
10+
GetSession = $scope.games.$promise.then(function(result) {
11+
return $scope.session.$get({ id: $routeParams.sessionid });
12+
});
13+
GetSession.then(function() {
14+
// identify new games
15+
gameids = []
16+
for (var i = 0; i < $scope.games.length; i++) {
17+
gameids.push($scope.games[i].id);
18+
}
19+
for (var i = 0; i < $scope.session.games.length; i++) {
20+
if ( !gameids.includes($scope.session.games[i]) ) {
21+
console.log("new game id: " + $scope.session.games[i]);
22+
game = new GameService;
23+
game.$get({ id: $scope.session.games[i], sessionid: $routeParams.sessionid });
24+
$scope.games.push(game);
25+
}
26+
}
27+
})
28+
}
29+
$scope.loadSession();
30+
$scope.interval = $interval(function(){
31+
$scope.loadSession();
32+
}, 5000);
33+
934
$scope.createGame = function (gamename, gamerules) {
1035
var sessionid = $routeParams.sessionid;
1136

0 commit comments

Comments
 (0)