|
1 | 1 | var module = angular.module('scorekeep'); |
2 | 2 | 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) { |
4 | 4 | $scope.games = GameService.query({ sessionid: $routeParams.sessionid }); |
5 | | - $scope.session = SessionService.get({ id: $routeParams.sessionid }); |
| 5 | + $scope.session = new SessionService; |
6 | 6 | $scope.user = UserService.get({ id: $routeParams.userid }); |
7 | 7 | $scope.allrules = RulesService.query(); |
8 | 8 |
|
| 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 | + |
9 | 34 | $scope.createGame = function (gamename, gamerules) { |
10 | 35 | var sessionid = $routeParams.sessionid; |
11 | 36 |
|
|
0 commit comments