<commit_before>/**
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
define(["app/honest/responsive_video"], function(rv) {


	return ["api", function(api) {

		return {

			restrict: 'A',

			transclude: true,

			templateUrl: "/partials/content/QuestionTabs.html",

			link: function(scope, element, attrs, ctrls, transclude) {

				if (scope.doc.bestAttempt) {
					scope.validationResponse = scope.doc.bestAttempt;
					scope.selectedChoice = scope.validationResponse.answer;
				} else {

					// We have to explicitly initialise to null so that the 
					// validationResponse watcher fires on the question. This
					// can allow it to remove the accordion watcher.

					scope.validationResponse = null;
				}
				scope.validationResponseSet = true;

				scope.activateTab = function(i) {
					scope.activeTab = i;
					rv.updateAll();

					if (i > -1) {
						api.logger.log({
							type : "VIEW_HINT",
							questionId : scope.doc.id,
							hintIndex : i,
						})
					}		
				}

				scope.activateTab(-1); // Activate "Answer now" tab by default.

				scope.state.gameBoardCompletedPassed = false;
				scope.state.gameBoardCompletedPerfect = false;

				scope.checkAnswer = function() {
					if (scope.selectedChoice != null) {

						var s = api.questionValidator.validate({id: scope.doc.id}, scope.selectedChoice);

						s.$promise.then(function foo(r) {
							scope.validationResponse = r;

							// Check the gameboard progress 
							if (scope.gameBoard) {
								// Re-load the game board to check for updated progress
								var initialGameBoardPercent = scope.gameBoard.percentageCompleted;
								var gameBoardCompletedPassed =  true;
								var gameBoardCompletedPerfect =  true;

								api.gameBoards.get({id: scope.gameBoard.id}).$promise.then(function(board) {
									scope.state.gameBoardPercentComplete = board.percentageCompleted;

									//We want to know if they have (a) completed the gameboard, (b) passed the gameboard
									for(var i = 0; i < board.questions.length; i++){
										if(board.questions[i].state != "PERFECT" ){<commit_msg>Fixes #505<commit_after>/**
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
define(["app/honest/responsive_video"], function(rv) {


	return ["api", function(api) {

		return {

			restrict: 'A',

			transclude: true,

			templateUrl: "/partials/content/QuestionTabs.html",

			link: function(scope, element, attrs, ctrls, transclude) {

				if (scope.doc.bestAttempt) {
					scope.validationResponse = scope.doc.bestAttempt;
					scope.selectedChoice = scope.validationResponse.answer;
				} else {

					// We have to explicitly initialise to null so that the 
					// validationResponse watcher fires on the question. This
					// can allow it to remove the accordion watcher.

					scope.validationResponse = null;
				}
				scope.validationResponseSet = true;

				scope.activateTab = function(i) {
					scope.activeTab = i;
					rv.updateAll();

					if (i > -1) {
						api.logger.log({
							type : "VIEW_HINT",
							questionId : scope.doc.id,
							hintIndex : i,
						})
					}		
				}

				scope.activateTab(-1); // Activate "Answer now" tab by default.

				// prevent undefined errors when we don't know which gameboard a person is working on.
				if(scope.gameBoard){
					scope.state.gameBoardCompletedPassed = false;
					scope.state.gameBoardCompletedPerfect = false;					
				}

				scope.checkAnswer = function() {
					if (scope.selectedChoice != null) {

						var s = api.questionValidator.validate({id: scope.doc.id}, scope.selectedChoice);

						s.$promise.then(function foo(r) {
							scope.validationResponse = r;

							// Check the gameboard progress 
							if (scope.gameBoard) {
								// Re-load the game board to check for updated progress
								var initialGameBoardPercent = scope.gameBoard.percentageCompleted;
								var gameBoardCompletedPassed =  true;
								var gameBoardCompletedPerfect =  true;

								api.gameBoards.get({id: scope.gameBoard.id}).$promise.then(function(board) {
									scope.state.gameBoardPercentComplete = board.percentageCompleted;

									//We want to know if they have (a) completed the gameboard, (b) passed the gameboard
									for(var i = 0; i < board.questions.length; i++){
										if(board.questions[i].state != "PERFECT" ){
{'fraction_non_alphanumeric': 0.10367892976588629, 'fraction_numerical': 0.004645113340765515, 'mean_word_length': 2.889450867052023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5891097', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1504, 'n_words': 470}