Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
krimple committed Mar 12, 2013
1 parent fb0ee2e commit b29f461
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 154 deletions.
3 changes: 1 addition & 2 deletions quizzo-app/quizzo-admin-js/app/views/main.html
Expand Up @@ -10,11 +10,10 @@ <h1>Quizzo - Moderator Panel</h1>
<form style="width: 500px; padding: 20px; margin: 10px; border: 1px solid black;">
Select Game: <select name="gameId"
ng-model="gameId"
ng-options="game for game in gamesAvailable"
ng-options="game.gameId as game.title for game in gamesAvailable"
required></select>
<button name="fetchGames" ng-click="fetchGames()">Refresh </button>
<br/>

<p><button name="beginPlay" ng-click="beginPlay(gameId)">Begin GamePlay</button>
<button name="nextQuestion" ng-click="nextQuestion(gameId)">Next Question</button></p>
<p><button name="endQuestion" ng-click="endQuestion(gameId)">End/Score Question</button>
Expand Down
Expand Up @@ -48,8 +48,8 @@ public class PlayerAnswer {
@JsonCreator
public PlayerAnswer(
@JsonProperty("questionNumber") Integer questionNumber,
@JsonProperty("choice") char choice) {
this(null, null, null, questionNumber, choice, null);
@JsonProperty("choice") String choice) {
this(null, null, null, questionNumber, choice.charAt(0), null);
}

@PersistenceConstructor
Expand Down
6 changes: 4 additions & 2 deletions quizzo-app/quizzo-js/app/index.html
Expand Up @@ -21,10 +21,11 @@
<script src='components/es5-shim/es5-shim.js'></script>
<script src='components/json3/lib/json3.min.js'></script>
<![endif]-->

<!-- Add your site or application content here -->
<div class='container' ng-view></div>

<!-- view-less controller to track status -->
<div ng-controller="StatusUpdateCtrl"></div>
<!-- build:js scripts/frameworks.js -->
<script src='components/angular/angular.js'></script>
<script src='components/angular-resource/angular-resource.js'></script>
Expand All @@ -42,11 +43,12 @@
<script src='scripts/controllers/players_pending_controller.js'></script>
<script src='scripts/controllers/question_pending_controller.js'></script>
<script src='scripts/controllers/register_controller.js'></script>

<script src='scripts/controllers/status_update_controller.js'></script>
<script src='scripts/controllers/tally_controller.js'></script>

<script src='scripts/services/game_selection_service.js'></script>
<script src='scripts/services/leaderboard_service.js'></script>
<script src='scripts/services/play_service.js'></script>
<script src='scripts/services/quiz_manager_service.js'></script>
<script src='scripts/services/register_player_service.js'></script>
<script src='scripts/services/server_prefix_value_service.js'></script>
Expand Down
2 changes: 1 addition & 1 deletion quizzo-app/quizzo-js/app/scripts/app.js
Expand Up @@ -8,7 +8,7 @@ angular.module('quizzoApp', []).
when('/join_game/:gameId', {templateUrl: 'views/joining_game.html', controller: 'JoinGameCtrl'}).
when('/players_pending', {templateUrl: 'views/players_pending.html', controller: 'PlayersPendingCtrl'}).
when('/question_pending', {templateUrl: 'views/question_pending.html', controller: 'QuestionPendingCtrl'}).
when('/play', {templateUrl: 'views/playerpanel.html', controller: 'QuestionCtrl'}).
when('/play', {templateUrl: 'views/playerpanel.html', controller: 'PlayCtrl'}).
when('/chat', {templateUrl: 'views/chat.html', controller: 'ChatCtrl'}).
when('/bye', {templateUrl: 'views/bye.html', controller: 'ByeCtrl'}).
when('invalid_game_status', {templateUrl: 'views/invalid_game_status.html'}).
Expand Down
Expand Up @@ -8,4 +8,8 @@ angular.module('quizzoApp').
// run 'em
$scope.findGamesReadyToPlay();

$scope.$on('GamesAvailable', function(event, values) {
console.log('Games are available!', gameSelectionService.getGames());
$scope.gamesAvailable = gameSelectionService.getGames();
});
});
60 changes: 27 additions & 33 deletions quizzo-app/quizzo-js/app/scripts/controllers/play_controller.js
@@ -1,40 +1,34 @@
'use strict';

angular.module('quizzoApp').controller('PlayCtrl',
function ($scope, $location, $timeout, quizManagerService) {
angular.module('quizzoApp').controller('PlayCtrl', function ($scope, $location, $timeout, quizManagerService) {

var timeout;

// define our 'end of question time' event
$scope.$on('WaitingForNextQuestion', function () {
// see definition below
$timeout.cancel(timeout);

$scope.question.destroy();
// show panel waiting for next question and begin polling
$location.path('/question_pending');
});

$scope.castVote = function () {
var selectedChoice = $scope.choices.item().value;
if (selectedChoice) {
// we send along the current question # to make sure we are recording
// the vote on the right question - if it doesn't match the one in
// server state, throw it away
quizManagerService.vote(selectedChoice, $scope.question.questionNumber);
}
};

// our timer loop - check for question timeout or end of game
$scope.onTimeout = function() {
quizManagerService.getStatus();
timeout = $timeout($scope.onTimeout, 1000);
};
var timeout;

// fetch our question
$scope.question = quizManagerService.getCurrentQuestion();
$scope.selectedChoice = { value : '' };

// begin timer
timeout = $timeout($scope.onTimeout, 1000);
$scope.$on('WaitingForAnswer', function () {
console.log('New question arrived.');
$scope.question = quizManagerService.getCurrentQuestion();
});

// define our 'end of question time' event
$scope.$on('WaitingForNextQuestion', function () {
// show panel waiting for next question and begin polling
$location.path('/question_pending');
});

$scope.castVote = function (value) {
var choice = $scope.selectedChoice;
console.log("selected choice is", choice);
if (choice) {
// we send along the current question # to make sure we are recording
// the vote on the right question - if it doesn't match the one in
// server state, throw it away
quizManagerService.vote(choice, $scope.question.questionNumber);
}
};

// fetch our question
$scope.question = quizManagerService.getCurrentQuestion();

});
@@ -1,19 +1,10 @@
'use strict';

angular.module('quizzoApp').controller('PlayersPendingCtrl', function ($scope, $timeout, $location, quizManagerService) {
angular.module('quizzoApp').controller('PlayersPendingCtrl', function ($rootScope, $scope, $location) {

var timeout;
$rootScope.enablePolling();
// our exit condition...
$scope.$on('WaitingForAnswer', function() {
$timeout.cancel(timeout);
$scope.$on('WaitingForAnswer', function () {
$location.path('/play');
});

$scope.onTimeout = function() {
quizManagerService.getStatus();
timeout = $timeout($scope.onTimeout, 1000);
};

timeout = $timeout($scope.onTimeout, 1000);

});
@@ -1,19 +1,10 @@
'use strict';

angular.module('quizzoApp').controller('QuestionPendingCtrl', function ($scope, $timeout, $location, quizManagerService) {
angular.module('quizzoApp').controller('QuestionPendingCtrl', function ($scope, $location) {

var timeout;
// our exit condition...
$scope.$on('WaitingForAnswer', function() {
$timeout.cancel(timeout);
$scope.$on('WaitingForAnswer', function () {
$location.path('/play');
});

$scope.onTimeout = function() {
quizManagerService.getStatus();
timeout = $timeout($scope.onTimeout, 1000);
};

timeout = $timeout($scope.onTimeout, 1000);

});
@@ -1,19 +1,25 @@
'use strict';

angular.module('quizzoApp').
controller('RegisterCtrl', function ($rootScope, $location, registerPlayerService) {
$rootScope.showJoinError = false;
$rootScope.joinError = '';
angular.module('quizzoApp').controller('RegisterCtrl', function ($rootScope, $location, registerPlayerService) {
$rootScope.showJoinError = false;
$rootScope.joinError = '';

$rootScope.$on('BadNick', function (event, values) {
$rootScope.showJoinError = true;
$rootScope.joinError = 'bad nickname -' + values.nickName + ' - please try another';
});

$rootScope.$on('GoodNick', function (event, values) {
console.log('Good nickname', values.nickName);
$rootScope.player = registerPlayerService.getPlayer();
$location.path('/show_games');
});

$rootScope.$on('BadNick', function(args) {
$rootScope.showJoinError = true;
$rootScope.joinError = 'bad nickname -' + args[0] + ' - please try another';
})
$rootScope.join_game = function (nickName) {
registerPlayerService.createNickName(nickName);
};

$rootScope.clear_nick_bad = function() {
$rootScope.clear_nick_bad = function () {
$rootScope.showJoinError = false;
$rootScope.joinError = '';
};
Expand Down
@@ -0,0 +1,28 @@
angular.module('quizzoApp').controller('StatusUpdateCtrl', function ($timeout, $rootScope, quizManagerService) {

var timeout;

$rootScope.pollEnabled = false;

$rootScope.onTimeout = function () {
// only call poller if enabled
if ($rootScope.enablePolling === true) {
console.log('polling enabled - checking status');
quizManagerService.getStatus();
}

console.log('timing out for 1 second...');
timeout = $timeout($rootScope.onTimeout, 1000);
};

$rootScope.enablePolling = function () {
$rootScope.pollEnabled = true;
};

$rootScope.disablePolling = function () {
$rootScope.pollEnabled = true;
};

// begin timing process
timeout = $timeout($rootScope.onTimeout, 1000);
});
Expand Up @@ -9,18 +9,17 @@ angular.module('quizzoApp').

implementation.findGamesReadyToPlay = function () {
var that = this;
$http.get(serverPrefix + 'quizRun/games').success(
function (data, status, headers, config) {
$http.get(serverPrefix + 'quizRun/games').
success(function (data, status, headers, config) {
that.games_ready_to_play = data;
$rootScope.$broadcast('GamesAvailable');
}).error(
function (data, status, headers, config) {
}).error(function (data, status, headers, config) {
delete that.games_ready_to_play;
console.error('no data found.', status);
});
};

implementation.getGames = function() {
implementation.getGames = function () {
return this.games_ready_to_play;
};

Expand All @@ -29,10 +28,8 @@ angular.module('quizzoApp').
$http.post(serverPrefix + 'quizRun/game/' + gameId + '/joinGame').
success(function (data, status, headers, config) {
// response includes category : 'GameJoined' - we're in
if (data.category == 'GameJoined') {
if (data.category === 'GameJoined') {
$rootScope.$broadcast('GameJoined');
} else {
// todo - not sure what to do here... Need a generic error view/controller
}
}).
error(function (data, status, headers, config) {
Expand Down
89 changes: 42 additions & 47 deletions quizzo-app/quizzo-js/app/scripts/services/quiz_manager_service.js
Expand Up @@ -8,55 +8,50 @@ angular.module('quizzoApp').factory('quizManagerService', function ($http, $root
// used as a delta to indicate a state change between polls
implementation.previousStatus = 'NoStatus';

implementation.getStatus = function () {
var that = this;
$http.get(serverPrefix + "status").
success(function (data, status, headers, config) {
if (data.status == 'WaitingToPlay') {
// we just wait... do nothing and return
return;
}
if (data.status == 'WaitingForAnswer' &&
that.previousStatus != 'WaitingForAnswer') {
// we just switched to getting a new question -
// tell the world
that.question = data.question;
$rootScope.$broadcast('WaitingForAnswer');
} else if (data.status == 'WaitingForNextQuestion' &&
that.previousStatus != 'WaitingForNextQuestion') {
$rootScope.$broadcast('WaitingForNextQuestion');
return;
}
if (data.status == 'GameComplete' &&
that.previousStatus != 'GameComplete') {
delete $rootScope.question;
$rootScope.$broadcast('GameComplete');
return;
}
if (data.status == 'InvalidGameStatus') {
$rootScope.$broadcast('InvalidGameStatus');
return;
} else if (data.status == 'GameComplete') {
}
// save off this status as the new previous status...
that.previousStatus = data.status;
}).
error(function (data, status, headers, config) {
$rootScope.$broadcast('InvalidGameStatus');
});
};
implementation.getStatus = function () {
var that = this;
$http.get(serverPrefix + 'status').success(function (data, status, headers, config) {
switch (data.status) {
case 'WaitingToPlay':
break;
case 'WaitingForAnswer':
if (that.previousStatus !== 'WaitingForAnswer') {
that.question = data.question;
$rootScope.$broadcast('WaitingForAnswer');
}
break;
case 'WaitingForNextQuestion':
if (that.previousStatus !== 'WaitingForNextQuestion') {
$rootScope.$broadcast('WaitingForNextQuestion');
}
break;
case 'GameComplete':
if (that.previousState !== 'GameComplete') {
delete $rootScope.question;
$rootScope.$broadcast('GameComplete');
}
break;
case 'InvalidGameStatus':
$rootScope.$broadcast('InvalidGameStatus');
break;
}
that.previousStatus = data.status;
}).error(function (data, status, headers, config) {
console.log('error, not a proper status returned...', data);
$rootScope.$broadcast('InvalidGameStatus');
});
};

implementation.getCurrentQuestion = function () {
return this.question;
};
implementation.getCurrentQuestion = function () {
return this.question;
};

implementation.vote = function (selectedAnswer, sentQuestionNumber) {
var answerPayload = {
questionNumber : sentQuestionNumber,
choice: selectedAnswer
};
$http.post(serverPrefix + 'quizRun/submitAnswer', answerPayload);
implementation.vote = function (selectedAnswer, sentQuestionNumber) {
var answerPayload = {
questionNumber : sentQuestionNumber,
choice: selectedAnswer.value
};

$http.put(serverPrefix + 'quizRun/submitAnswer', answerPayload);
};
return implementation;
});

0 comments on commit b29f461

Please sign in to comment.