<commit_before>/**
 * Copyright 2017 <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([], function() {
	return ["$state", "$location", function($state, $location) {
		var MAX_LABEL_LENGTH = 17;
		var defaultAction = {
			disabled: false
		}

		this.checkMyAnswer = function(scope, api) { // TODO refactor so that less is passed to this function
			var checkAnswer = function() {
				if (scope.question.selectedChoice != null && scope.canSubmit) {
					scope.canSubmit = false;

					if (scope.doc.type == "isaacSymbolicQuestion" || scope.doc.type == "isaacSymbolicChemistryQuestion") {
						var symbols = JSON.parse(scope.question.selectedChoice.value).symbols;
						if (Object.keys(symbols).length == 0) {
							return;
						}
					}

					var s = api.questionValidator.validate({id: scope.doc.id}, scope.question.selectedChoice);
					s.$promise.then(function foo(validationResponse) {
						scope.question.validationResponse = validationResponse;
					}, function bar(e) {
						console.error("Error validating answer:", e);
						var eMessage = e.data.errorMessage;
						var eTitle = "Can't Submit Answer";
						if (eMessage != null && eMessage.indexOf("ValidatorUnavailableException:") == 0) {
							eTitle = "Error Checking Answer"
							eMessage = eMessage.replace("ValidatorUnavailableException:", "");
						}
						scope.showToast(scope.toastTypes.Failure, eTitle, eMessage != undefined ? eMessage : "");
						// If an error, after a little while allow them to submit the same answer again.
						setTimeout(function() { scope.canSubmit = true; }, 5000);
					});
				}
			};

			return {
				prototype: defaultAction,
				label: "Check my answer",
				disabled: !scope.canSubmit,
				onClick: checkAnswer,
				title: "Submit answer for marking",
			};
		};

		this.tryEasierQuestion = function(easierQuestion, currentQuestionId, pageCompleted, questionHistory, gameboardId) {			
			var fullLabel = easierQuestion.level == '2' ? 'Revise' : 'Practice';
			fullLabel += " " + easierQuestion.title.toLowerCase();
			var abbreviatedLabel = easierQuestion.level == '2' ? 'Revise' : 'Practice';
			abbreviatedLabel += " this concept";
			if (fullLabel.length <= MAX_LABEL_LENGTH) {
				abbreviatedLabel = fullLabel;
			}

			if (!pageCompleted) {
				questionHistory.push(currentQuestionId);
			}
			commaSeparatedQuestionHistory = questionHistory.join(',');

			return {
				prototype: defaultAction,
				title: fullLabel,
				label: abbreviatedLabel,
				onClick: function() {
					$state.go('question', {id:easierQuestion.id, questionHistory:commaSeparatedQuestionHistory, board:gameboardId});
				}
			};
		};

		this.trySupportingQuestion = function(supportingQuestion, currentQuestionId, pageCompleted, questionHistory, gameboardId) {
			var fullLabel = "Try more " + supportingQuestion.title.toLowerCase() + " ";
			fullLabel += supportingQuestion.level == '2' ? 'revision' : 'practice';
			var abbreviatedLabel = "Try more concept ";
			abbreviatedLabel += supportingQuestion.level == '2' ? 'revision' : 'practice';
			if (fullLabel.length <= MAX_LABEL_LENGTH) {
				abbreviatedLabel = fullLabel;
			}

			if (!pageCompleted) {
				questionHistory.push(currentQuestionId);
			}<commit_msg>Make revision suggesiton button's label less forceful<commit_after>/**
 * Copyright 2017 <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([], function() {
	return ["$state", "$location", function($state, $location) {
		var MAX_LABEL_LENGTH = 17;
		var defaultAction = {
			disabled: false
		}

		this.checkMyAnswer = function(scope, api) { // TODO refactor so that less is passed to this function
			var checkAnswer = function() {
				if (scope.question.selectedChoice != null && scope.canSubmit) {
					scope.canSubmit = false;

					if (scope.doc.type == "isaacSymbolicQuestion" || scope.doc.type == "isaacSymbolicChemistryQuestion") {
						var symbols = JSON.parse(scope.question.selectedChoice.value).symbols;
						if (Object.keys(symbols).length == 0) {
							return;
						}
					}

					var s = api.questionValidator.validate({id: scope.doc.id}, scope.question.selectedChoice);
					s.$promise.then(function foo(validationResponse) {
						scope.question.validationResponse = validationResponse;
					}, function bar(e) {
						console.error("Error validating answer:", e);
						var eMessage = e.data.errorMessage;
						var eTitle = "Can't Submit Answer";
						if (eMessage != null && eMessage.indexOf("ValidatorUnavailableException:") == 0) {
							eTitle = "Error Checking Answer"
							eMessage = eMessage.replace("ValidatorUnavailableException:", "");
						}
						scope.showToast(scope.toastTypes.Failure, eTitle, eMessage != undefined ? eMessage : "");
						// If an error, after a little while allow them to submit the same answer again.
						setTimeout(function() { scope.canSubmit = true; }, 5000);
					});
				}
			};

			return {
				prototype: defaultAction,
				label: "Check my answer",
				disabled: !scope.canSubmit,
				onClick: checkAnswer,
				title: "Submit answer for marking",
			};
		};

		this.tryEasierQuestion = function(easierQuestion, currentQuestionId, pageCompleted, questionHistory, gameboardId) {			
			var fullLabel = easierQuestion.level == '2' ? 'Revise' : 'Practice';
			fullLabel += " " + easierQuestion.title.toLowerCase();
			var abbreviatedLabel = easierQuestion.level == '2' ? 'Revise' : 'Practice';
			abbreviatedLabel += " this concept";
			if (fullLabel.length <= MAX_LABEL_LENGTH) {
				abbreviatedLabel = fullLabel;
			}

			if (!pageCompleted) {
				questionHistory.push(currentQuestionId);
			}
			commaSeparatedQuestionHistory = questionHistory.join(',');

			return {
				prototype: defaultAction,
				title: fullLabel,
				label: abbreviatedLabel,
				onClick: function() {
					$state.go('question', {id:easierQuestion.id, questionHistory:commaSeparatedQuestionHistory, board:gameboardId});
				}
			};
		};

		this.trySupportingQuestion = function(supportingQuestion, currentQuestionId, pageCompleted, questionHistory, gameboardId) {
			var fullLabel = "Try more " + supportingQuestion.title.toLowerCase() + " ";
			fullLabel += supportingQuestion.level == '2' ? 'revision?' : 'practice?';
			var abbreviatedLabel = "Try more concept ";
			abbreviatedLabel += supportingQuestion.level == '2' ? 'revision?' : 'practice?';
			if (fullLabel.length <= MAX_LABEL_LENGTH) {
				abbreviatedLabel = fullLabel;
			}

			if (!pageCompleted) {
				questionHistory.push(currentQuestionId);
			}
{'fraction_non_alphanumeric': 0.12044184189512909, 'fraction_numerical': 0.005323396326856534, 'mean_word_length': 3.7473152242577386, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '115020', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2109, 'n_words': 574}