diff --git a/quizzo-app/quizzo-admin-js/app/views/main.html b/quizzo-app/quizzo-admin-js/app/views/main.html index 24cf447..8d37a02 100644 --- a/quizzo-app/quizzo-admin-js/app/views/main.html +++ b/quizzo-app/quizzo-admin-js/app/views/main.html @@ -10,11 +10,10 @@

Quizzo - Moderator Panel

Select Game:
-

diff --git a/quizzo-app/quizzo-data-access/src/main/java/org/springframework/data/examples/quizzo/domain/PlayerAnswer.java b/quizzo-app/quizzo-data-access/src/main/java/org/springframework/data/examples/quizzo/domain/PlayerAnswer.java index e1513da..950427c 100644 --- a/quizzo-app/quizzo-data-access/src/main/java/org/springframework/data/examples/quizzo/domain/PlayerAnswer.java +++ b/quizzo-app/quizzo-data-access/src/main/java/org/springframework/data/examples/quizzo/domain/PlayerAnswer.java @@ -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 diff --git a/quizzo-app/quizzo-js/app/index.html b/quizzo-app/quizzo-js/app/index.html index 071784c..2c26d46 100644 --- a/quizzo-app/quizzo-js/app/index.html +++ b/quizzo-app/quizzo-js/app/index.html @@ -21,10 +21,11 @@ -

+ +
@@ -42,11 +43,12 @@ + + - diff --git a/quizzo-app/quizzo-js/app/scripts/app.js b/quizzo-app/quizzo-js/app/scripts/app.js index e8d4a41..f5ab5eb 100644 --- a/quizzo-app/quizzo-js/app/scripts/app.js +++ b/quizzo-app/quizzo-js/app/scripts/app.js @@ -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'}). diff --git a/quizzo-app/quizzo-js/app/scripts/controllers/game_selection_controller.js b/quizzo-app/quizzo-js/app/scripts/controllers/game_selection_controller.js index 136699b..11b9e56 100644 --- a/quizzo-app/quizzo-js/app/scripts/controllers/game_selection_controller.js +++ b/quizzo-app/quizzo-js/app/scripts/controllers/game_selection_controller.js @@ -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(); + }); }); diff --git a/quizzo-app/quizzo-js/app/scripts/controllers/play_controller.js b/quizzo-app/quizzo-js/app/scripts/controllers/play_controller.js index 3ff1562..1886b3f 100644 --- a/quizzo-app/quizzo-js/app/scripts/controllers/play_controller.js +++ b/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(); + +}); diff --git a/quizzo-app/quizzo-js/app/scripts/controllers/players_pending_controller.js b/quizzo-app/quizzo-js/app/scripts/controllers/players_pending_controller.js index fc19d3d..7fb2828 100644 --- a/quizzo-app/quizzo-js/app/scripts/controllers/players_pending_controller.js +++ b/quizzo-app/quizzo-js/app/scripts/controllers/players_pending_controller.js @@ -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); - }); diff --git a/quizzo-app/quizzo-js/app/scripts/controllers/question_pending_controller.js b/quizzo-app/quizzo-js/app/scripts/controllers/question_pending_controller.js index d5670b8..640accd 100644 --- a/quizzo-app/quizzo-js/app/scripts/controllers/question_pending_controller.js +++ b/quizzo-app/quizzo-js/app/scripts/controllers/question_pending_controller.js @@ -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); - }); diff --git a/quizzo-app/quizzo-js/app/scripts/controllers/register_controller.js b/quizzo-app/quizzo-js/app/scripts/controllers/register_controller.js index 702e094..7bf2e51 100644 --- a/quizzo-app/quizzo-js/app/scripts/controllers/register_controller.js +++ b/quizzo-app/quizzo-js/app/scripts/controllers/register_controller.js @@ -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 = ''; }; diff --git a/quizzo-app/quizzo-js/app/scripts/controllers/status_update_controller.js b/quizzo-app/quizzo-js/app/scripts/controllers/status_update_controller.js new file mode 100644 index 0000000..0b9ee17 --- /dev/null +++ b/quizzo-app/quizzo-js/app/scripts/controllers/status_update_controller.js @@ -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); +}); diff --git a/quizzo-app/quizzo-js/app/scripts/services/game_selection_service.js b/quizzo-app/quizzo-js/app/scripts/services/game_selection_service.js index 3143576..7857fe7 100644 --- a/quizzo-app/quizzo-js/app/scripts/services/game_selection_service.js +++ b/quizzo-app/quizzo-js/app/scripts/services/game_selection_service.js @@ -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; }; @@ -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) { diff --git a/quizzo-app/quizzo-js/app/scripts/services/quiz_manager_service.js b/quizzo-app/quizzo-js/app/scripts/services/quiz_manager_service.js index 762d01d..8cb7e71 100644 --- a/quizzo-app/quizzo-js/app/scripts/services/quiz_manager_service.js +++ b/quizzo-app/quizzo-js/app/scripts/services/quiz_manager_service.js @@ -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; }); diff --git a/quizzo-app/quizzo-js/app/scripts/services/register_player_service.js b/quizzo-app/quizzo-js/app/scripts/services/register_player_service.js index 947c7c2..c1d67f7 100644 --- a/quizzo-app/quizzo-js/app/scripts/services/register_player_service.js +++ b/quizzo-app/quizzo-js/app/scripts/services/register_player_service.js @@ -9,19 +9,20 @@ angular.module('quizzoApp').factory('registerPlayerService', function (serverPre implementation.currentPlayer = ''; implementation.createNickName = function (nickName) { + var that = this; this.createPending = true; $http.defaults.withCredentials = true; - var that = this; $http.post(serverPrefix + 'player/register/' + nickName). success(function (data, status, headers, config) { - if (status == 201) { + if (status === 201) { $rootScope.badNick = false; that.currentPlayer = nickName; that.createPending = false; - } else if (status == 204) { + $rootScope.$broadcast('GoodNick', { nickName: nickName }); + } else if (status === 204) { that.createPending = false; that.currentPlayer = ''; - $rootScope.$broadcast('BadNick', nickName); + $rootScope.$broadcast('BadNick', { nickName : nickName }); } }); }; diff --git a/quizzo-app/quizzo-js/app/views/playerpanel.html b/quizzo-app/quizzo-js/app/views/playerpanel.html index 1d612d4..49cec4b 100644 --- a/quizzo-app/quizzo-js/app/views/playerpanel.html +++ b/quizzo-app/quizzo-js/app/views/playerpanel.html @@ -20,16 +20,15 @@

Choose an answer...

- + value='{{answer_choice.letter}}'> + + ng-show='voteForm.$valid' + ng-click='castVote()'>Vote
diff --git a/quizzo-app/quizzo-js/app/views/show_games.html b/quizzo-app/quizzo-js/app/views/show_games.html index 1ce9023..5131106 100644 --- a/quizzo-app/quizzo-js/app/views/show_games.html +++ b/quizzo-app/quizzo-js/app/views/show_games.html @@ -4,16 +4,16 @@ -
-

Join a Game

- Select a game to play... The following games are awaiting players... - -
+
+

Join a Game

+ Select a game to play... The following games are awaiting players... + +
-
- - + + + diff --git a/quizzo-app/quizzo-web/pom.xml b/quizzo-app/quizzo-web/pom.xml index d6f9089..2507489 100644 --- a/quizzo-app/quizzo-web/pom.xml +++ b/quizzo-app/quizzo-web/pom.xml @@ -141,13 +141,26 @@ UTF-8 + + org.eclipse.jetty + jetty-maven-plugin + 9.0.0.v20130308 + + + /quizzo + + manual + + org.apache.tomcat.maven tomcat7-maven-plugin 2.0 local_tomcat + target/quizzo.war http://localhost:8080/manager/text + /quizzo-web diff --git a/quizzo-app/quizzo-web/src/main/resources/log4j.properties b/quizzo-app/quizzo-web/src/main/resources/log4j.properties index 50aa5dc..19557c3 100644 --- a/quizzo-app/quizzo-web/src/main/resources/log4j.properties +++ b/quizzo-app/quizzo-web/src/main/resources/log4j.properties @@ -1,9 +1,6 @@ -log4j.rootCategory=WARN, stdout +log4j.rootCategory=TRACE, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n -#log4j.category.org.springframework.data.examples=DEBUG -#log4j.category.org.springframework.samples=DEBUG -#log4j.category.org.springframework.web=TRACE \ No newline at end of file diff --git a/quizzo-app/quizzo-web/src/main/webapp/META-INF/context.xml b/quizzo-app/quizzo-web/src/main/webapp/META-INF/context.xml new file mode 100644 index 0000000..418718c --- /dev/null +++ b/quizzo-app/quizzo-web/src/main/webapp/META-INF/context.xml @@ -0,0 +1,35 @@ + + + + + + + WEB-INF/web.xml + + + + + + + +