MCPcopy Index your code
hub / github.com/aws-samples/eb-java-scorekeep / Session

Function Session

public/app/session-controller.js:3–101  ·  view source on GitHub ↗
($scope, $http, $location, $interval, $routeParams, SessionService, RulesService, GameCollection, UserService, GameService, api)

Source from the content-addressed store, hash-verified

1var module = angular.module('scorekeep');
2module.controller('SessionController', Session);
3function Session($scope, $http, $location, $interval, $routeParams, SessionService, RulesService, GameCollection, UserService, GameService, api) {
4 $scope.games = GameService.query({ sessionid: $routeParams.sessionid });
5 $scope.session = new SessionService;
6 $scope.user = UserService.get({ id: $routeParams.userid });
7 $scope.allrules = RulesService.query();
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 if ( $scope.games == null ) {
17 $scope.games = [];
18 }
19 for (var i = 0; i < $scope.games.length; i++) {
20 // if the game has been removed from the session
21 if ( !$scope.session.games.includes($scope.games[i].id) ) {
22 $scope.games.splice(i, 1);
23 } else {
24 gameids.push($scope.games[i].id);
25 }
26 }
27 if ( $scope.session.games == null ) {
28 $scope.session.games = [];
29 }
30 for (var i = 0; i < $scope.session.games.length; i++) {
31 if ( !gameids.includes($scope.session.games[i]) ) {
32 console.log("new game id: " + $scope.session.games[i]);
33 game = new GameService;
34 game.$get({ id: $scope.session.games[i], sessionid: $routeParams.sessionid });
35 $scope.games.push(game);
36 }
37 }
38 })
39 }
40 $scope.loadSession();
41 $scope.interval = $interval(function(){
42 $scope.loadSession();
43 }, 5000);
44 $scope.createGame = function (gamename, gamerules) {
45 var sessionid = $routeParams.sessionid;
46
47 CreateGame = GameCollection.createGame(sessionid, gamename, gamerules);
48 CreateGame.then(function(game) {
49 $scope.games.push(game);
50 });
51 };
52
53 $scope.setGameRules = function(gameid, rulesid){
54 return GameCollection.setField($scope.session.id, gameid, "rules", rulesid);
55 }
56 $scope.startGame = function(index){
57 // refresh session before setting users?
58 users = $scope.games[index].users = $scope.session.users;
59 gameid = $scope.games[index].id;
60 rulesid = $scope.games[index].rules;

Callers

nothing calls this directly

Calls 5

loadSessionMethod · 0.80
setGameRulesMethod · 0.80
setUsersMethod · 0.45
deleteGameMethod · 0.45
deleteSessionMethod · 0.45

Tested by

no test coverage detected