");
$compile(labExerciseHtml)($scope);
}
if ($scope.initialQuestioNo > 0) {
for (var i = $scope.initialQuestioNo - 1; i > 0; i--) {
var labExerciseHtml_1 = $("#resultLabData").prepend("
" + i + "
Incorrect
");
$compile(labExerciseHtml_1)($scope);
}
}
}
$scope.ReportGen = function () {
$("#submitResultHtml").css("display", "block");
$("#questionHtml").css("display", "none");
}
$scope.handleDragStart = function (e) {
this.style.opacity = '0.4';
e.dataTransfer.setData('text/plain', this.innerHTML);
$scope.dragableId = $(this).attr("Id");
// alert($scope.dragableId);
$scope.dragableText = $("#" + $scope.dragableId).text();
// alert($("#" + $scope.dragableId).text());
//if user drag already selected answer from one blankbox to another than it gets id of blank box so need to get answer
if ($scope.dragableId.indexOf('T') != -1) {
var optionText = document.getElementById($scope.dragableId).innerHTML;
var currentQuizData = new jinqJs()
.from($scope.LabExData.LabExercise[0].Questions)
.where('Number == ' + $scope.quiznumber)
.select();
var optionData = new jinqJs()
.from(currentQuizData[0].Options)
.where('OptionTitle == ' + optionText)
.select();
var option = optionData[0].OptionNumber;
$scope.dragableId = optionText + '-' + option;
}
//if user drag already selected answer from one blankbox to another than it gets id of blank box so need to get answer
if ($scope.dragableId.indexOf('T') != -1) {
var optionText = document.getElementById($scope.dragableId).innerHTML;
var currentQuizData = new jinqJs()
.from($scope.LabExData.LabExercise[0].Questions)
.where('Number == ' + $scope.quiznumber)
.select();
var optionData = new jinqJs()
.from(currentQuizData[0].Options)
.where('OptionTitle == ' + optionText)
.select();
var option = optionData[0].OptionNumber;
//$scope.dragableId = optionText + '-' + option;
}
};
$scope.handleDragEnd = function (e) {
this.style.opacity = '1.0';
};
$scope.handleDrop = function (e) {
e.preventDefault();
e.stopPropagation();
var x = $("#droppable").offset();
var id = $(this).attr("id");
// $scope.dragableText = $("#" + $scope.dragableId).text();
//$rootScope.selectedDivArray.push({
// "questionNo": $scope.quiznumber,
// "draggedID": $scope.dragableId,
// "draggedText": $scope.dragableText,
// "droppedID": id
//});
//console.log($rootScope.selectedDivArray);
var keywords = $location.search();
$scope.labExercideIdentifier = (keywords.labexercise.replace('.json', '')).split('dat_')[1];
var dataText = e.dataTransfer.getData('text/plain');
if (id == "divoptions" || id == "divleft" || id == "divright") {
var item = $('#' + $scope.dragableId).html();
var rindex = $scope.DraggedList.indexOf(item);
var labExerciseModulePath = '~/../content/data/json/le/' + keywords.labexercise + '.json';
DataService.getAnotherJson(labExerciseModulePath).then(
function (result) {
$.each(result.LabExercise, function (index, value) {
if (result.LabExercise[index].Slug == keywords.labexercise) {
$.each(result.LabExercise[index].Questions, function (index1, value1) {
if (result.LabExercise[index].Questions[index1].Number == $scope.quiznumber) {
var Options = result.LabExercise[index].Questions[index1].Options;
$.each(Options, function (inx, value2) {
if (Options[inx].OptionTitle == item) {
if ($scope.DraggedList != null) {
$.each($scope.DraggedList, function (inx1, value3) {
$scope.UserAttempt.push({ "BlankBoxName": id.split('-')[1], "OptionName": $scope.dragableId.split('-')[1] });
//var balnkBox=id.split('-')[1];
//$scope.UserAttempt.push({balnkBox :+ $scope.dragableId.split('-')[1] });
if ($scope.DraggedList[inx1].Value == item) {
$scope.DraggedList.splice(inx1, 1);
$('#block-' + Options[inx].OptionNumber).css("display", "block");
$('#blockans-' + Options[inx].OptionNumber).css("background-color", "transparent !important");
}
});
}
}
});
}
});
}
});
},
function (error) {
console.log(error.statusText)
}
)
}
else {
var labExerciseModulePath = '~/../content/data/json/le/' + keywords.labexercise + '.json';
DataService.getAnotherJson(labExerciseModulePath).then(
function (result) {
$.each(result.LabExercise, function (index, value) {
if (result.LabExercise[index].Slug == keywords.labexercise) {
$.each(result.LabExercise[index].Questions, function (index1, value1) {
if (result.LabExercise[index].Questions[index1].Number == $scope.quiznumber) {
var Options = result.LabExercise[index].Questions[index1].OptionBox;
$.each(Options, function (inx, value2) {
if (Options[inx].BoxName == id.split('-')[1]) {
if ($scope.DraggedList != null) {
$.each($scope.DraggedList, function (inx1, value3) {
if ($scope.DraggedList[inx1].Value == dataText) {
$scope.DraggedList.splice(inx1, 1);
}
});
}
// $scope.UserAttempt.push({ "BlankBoxName": id.split('-')[1], "OptionName": $scope.dragableId.split('-')[1] });
//$scope.UserAttempt.push({ balnkBox: +$scope.dragableId.split('-')[1] });
$scope.UserAttempt.push({ "BlankBoxName": id.split('-')[1], "OptionName": $scope.dragableId.split('-')[1] });
$scope.DraggedList.push({ "id": id.split('-')[1], "optionName": id.split('-')[1], "Value": dataText, "topcoord": Options[inx].topcoord, "leftcoord": Options[inx].leftcoord });
$('#' + $scope.dragableId).css("display", "none");
$('#blockans-' + Options[inx].OptionNumber).css("background-color", "transparent !important");
}
});
}
});
}
});
},
function (error) {
console.log(error.statusText)
}
)
}
$scope.$apply();
//alert(JSON.stringify($scope.UserAttempt));
};
$scope.handleDragOver = function (e) {
e.preventDefault(); // Necessary. Allows us to drop.
e.dataTransfer.dropEffect = 'move'; // See the section on the DataTransfer object.
//return false;
};
$scope.OnResetClick = function () {
$scope.isResetClicked = true;
$scope.resetQuiz();
}
$scope.resetQuiz = function () {
$scope.DraggedList = [];
$scope.UserAttempt = [];
$scope.GetQuizByTopic();
};
$scope.ReviewAttempt = function () {
var keywords = $location.search();
var labExerciseModulePath = '~/../content/data/json/le/' + keywords.labexercise + '.json';
DataService.getAnotherJson(labExerciseModulePath).then(
function (result) {
//alert(result)
$.each(result.LabExercise, function (index, value) {
if (result.LabExercise[index].Slug == keywords.labexercise) {
$.each(result.LabExercise[index].Questions, function (index1, value1) {
if (result.LabExercise[index].Questions[index1].Number == $scope.quiznumber) {
var correctResponse = result.LabExercise[index].Questions[index1].correctResponse;
var Options = result.LabExercise[index].Questions[index1].Options;
$.each(correctResponse, function (inx, value2) {
$scope.OptionName = "";
$.each(Options, function (inx1, value3) {
if (Options[inx1].OptionTitle == $('#blockans-' + correctResponse[inx].OptionBox).text()) {
$scope.OptionName = Options[inx1].OptionNumber;
}
});
if (correctResponse[inx].Answer == $scope.OptionName) {
blReviewAttempt = true;
}
else {
blReviewAttempt = false;
$('#blockans-' + correctResponse[inx].OptionBox).css("background", "#ff4e00");
}
});
}
});
}
});
},
function (error) {
console.log(error.statusText)
}
)
};
$scope.ShowHideDiv = function (status) {
if (status == "bottom") {
$("#divright").css("display", "none");
$("#divleft").css("display", "none");
$("#divoptions").css("display", "block");
}
else {
$("#divright").css("display", "block");
$("#divleft").css("display", "block");
$("#divoptions").css("display", "none");
}
};
$scope.SaveAnswer = function () {
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
$scope.CreateLabExerciseDataToSave();
//LabExerciseService.saveLabExerciseAttempt("superadmin", $scope.LabExerciseAttemptedData)
$scope.labExerciseAttempt = [];
$scope.labExerciseAttempt.push({ 'LabExerciseUserData': $scope.LabExerciseUserData, 'userId': $scope.userId, 'labExerciseIdentifier': $scope.labExerciseIdentifier, 'LastQuestion': $scope.LastQuestion, 'TotalQuestions': $scope.TotalQuestions });
$scope.initialQuestioNo = $scope.LastQuestion;
LabExerciseService.saveLabExerciseAttempt($scope.labExerciseAttempt)
.then(
function (result) {
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
//saved successfully.variable name is not correct but errorMessage represnts message
$rootScope.errorMessage = result;
$("#messageModal").modal('show');
},
function (error) {
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
console.log(' Error in saving lab exercise = ' + error.statusText);
// alert(LoginMessageConstants.ERROR_IN_FECTHING_DETAILS);
$rootScope.isVisibleLogin = true;
$rootScope.errorMessage = error;
$("#messageModal").modal('show');
}
)
};
$scope.usersCorrectQuestData = [];
$scope.CreateLabExerciseDataToSave = function () {
$scope.LabExerciseAttemptedData = [];
$scope.lb = [];
//get user answers
$scope.getUserAnswers();
//get correct response
$scope.getCorrectResponse();
// $scope.correctResponseForSavingDatabaseArray = $scope.correctResponseForSavingDatabase.split(',');
//get dragItems
$scope.getDragItems();
//get score
$scope.getScore();
$scope.userId = JSON.parse(localStorage.getItem('loggedInUserDetails')).Id;
$scope.labExerciseIdentifier = $scope.labExercideIdentifier;
$scope.LastQuestion = $scope.quiznumber;
$scope.TotalQuestions = $scope.TotalNumberofQuiz;
$scope.LabExerciseAttemptedData = {
MaxScore: $scope.MaxScore,
UserAnswer: $scope.commaSeperatedUserAnswers,
QuestionNo: $scope.quiznumber,
CorrectAnswer: JSON.stringify($scope.correctResponseForSavingDatabase),
DragItems: $scope.DragItems,
Score: $scope.Score,
title: $scope.activityTitle
}
var thisQuestiondataInLabExerciseUserData = new jinqJs()
.from($scope.LabExerciseUserData)
.where('QuestionNo == ' + $scope.LabExerciseAttemptedData.QuestionNo)
.select();
if (thisQuestiondataInLabExerciseUserData.length>0) {
angular.forEach($scope.LabExerciseUserData, function (value, key) {
if (value.QuestionNo == $scope.LabExerciseAttemptedData.QuestionNo) {
}
else {
$scope.lb.push(value);
}
})
$scope.LabExerciseUserData = [];
$scope.lb.push($scope.LabExerciseAttemptedData);
angular.forEach($scope.lb,function(value1,key1){
$scope.LabExerciseUserData.push(value1);
})
}
else
$scope.LabExerciseUserData.push($scope.LabExerciseAttemptedData);
$scope.usersCorrectQuestData = [];
if ($scope.LabExerciseUserData.length > 0) {
for(var i=0;i<=$scope.LabExerciseUserData.length-1;i++)
{
if ($scope.LabExerciseUserData[i].MaxScore == $scope.LabExerciseUserData[i].Score) {
$scope.usersCorrectQuestData.push({
MaxScore: $scope.LabExerciseUserData[i].MaxScore,
UserAnswer: $scope.LabExerciseUserData[i].UserAnswer,
QuestionNo: $scope.LabExerciseUserData[i].QuestionNo,
CorrectAnswer: JSON.stringify($scope.LabExerciseUserData[i].CorrectAnswer),
DragItems: $scope.LabExerciseUserData[i].DragItems,
Score: $scope.LabExerciseUserData[i].Score,
title: $scope.LabExerciseUserData[i].title,
CorrectStatus: 'Correct'
});
}
else {
$scope.usersCorrectQuestData.push({
MaxScore: $scope.LabExerciseUserData[i].MaxScore,
UserAnswer: $scope.LabExerciseUserData[i].UserAnswer,
QuestionNo: $scope.LabExerciseUserData[i].QuestionNo,
CorrectAnswer: JSON.stringify($scope.LabExerciseUserData[i].CorrectAnswer),
DragItems: $scope.LabExerciseUserData[i].DragItems,
Score: $scope.LabExerciseUserData[i].Score,
title: $scope.LabExerciseUserData[i].title,
CorrectStatus: 'Incorrect'
});
}
}
}
else {
if ($scope.MaxScore == $scope.Score) {
$scope.usersCorrectQuestData.push({
MaxScore: $scope.MaxScore,
UserAnswer: $scope.commaSeperatedUserAnswers,
QuestionNo: $scope.quiznumber,
CorrectAnswer: JSON.stringify($scope.correctResponseForSavingDatabase),
DragItems: $scope.DragItems,
Score: $scope.Score,
title: $scope.activityTitle,
CorrectStatus: 'Correct'
});
}
else {
$scope.usersCorrectQuestData.push({
MaxScore: $scope.MaxScore,
UserAnswer: $scope.commaSeperatedUserAnswers,
QuestionNo: $scope.quiznumber,
CorrectAnswer: JSON.stringify($scope.correctResponseForSavingDatabase),
DragItems: $scope.DragItems,
Score: $scope.Score,
title: $scope.activityTitle,
CorrectStatus: 'Incorrect'
});
}
}
// console.log($scope.usersCorrectQuestData);
// console.log($scope.LabExerciseUserData);
}
$scope.reviewAttemptAnswer = function (evt) {
$scope.isReviewBtnSelected = true;
$("#reviewBtn").css("display", "none");
$("#resetBtn").css("display", "none");
$("#saveBtn").css("display", "none");
$("#submitResultHtml").css("display", "none");
$("#questionHtml").css("display", "block");
$("#reportBtn").css("display", "block");
$("#quizSubmitBtn").css("display", "none");
$scope.quiznumber = evt.target.id;
$scope.CreateLabExerciseDataToSave();
$scope.dragableId = "";
// $scope.resetQuiz();
$scope.GetQuizByTopic();
//$scope.ShowHideDiv();
}
$scope.getUserAnswers = function () {
var userAnswers = [];
var blockBoxes = $("div[id*='blockbox']");
var blockBoxesInTextBlock = $("#textblock").children();
var blockBoxLength = blockBoxes.length - blockBoxesInTextBlock.length;
var blockAnswers = $("div[id*='blockans']");
for (var i = 0; i < blockAnswers.length; i++) {
var id = (blockAnswers[i].id).split('-')[1];
userAnswers[id.replace('T', '')] = blockAnswers[i].innerHTML;
}
$scope.commaSeperatedUserAnswers = '';
for (var i = 1; i <= blockBoxLength; i++) {
var userAns = userAnswers[i];
if (userAns != undefined) {
$scope.commaSeperatedUserAnswers += userAns + ',';
}
else {
$scope.commaSeperatedUserAnswers += '' + ',';
}
}
//remove last comma
$scope.commaSeperatedUserAnswers = $scope.commaSeperatedUserAnswers.replace(/,$/, '');
}
$scope.getCorrectResponse = function () {
$scope.correctResponse = '';
$scope.correctResponseForSavingDatabase = '';
var cr = new jinqJs()
.from($scope.LabExData.LabExercise[0].Questions)
.where('Number == ' + $scope.quiznumber)
.select();
for (var i = 0; i < cr[0].correctResponse.length; i++) {
var blankBox = cr[0].correctResponse[i].OptionBox;
var option = cr[0].correctResponse[i].Answer;
var options = new jinqJs()
.from(cr[0].Options)
.where('OptionNumber == ' + option)
.select();
var optionText = options[0].OptionTitle;
$scope.correctResponse += blankBox + ' ' + option + ',';
$scope.correctResponseForSavingDatabase += parseInt(blankBox.replace('T', '')) - 1 + ':' + optionText + ',';
}
$scope.correctResponse = $scope.correctResponse.replace(/,$/, '');
$scope.correctResonseKeyValue = $scope.correctResponse.split(',');
$scope.correctResponseForSavingDatabase = $scope.correctResponseForSavingDatabase.replace(/,$/, '');
}
$scope.getDragItems = function () {
var OptionBoxes = $("div[id*='block-']");
$scope.DragItems = '';
for (var i = 0; i < OptionBoxes.length; i++) {
$scope.DragItems += OptionBoxes[i].id.replace('block-', '') + ',' + OptionBoxes[i].innerHTML + ';';
}
$scope.DragItems = $scope.DragItems.replace(/;$/, '');
}
$scope.getScore = function () {
var abc = $scope.UserAttempt;
$scope.Score = 0;
angular.forEach($scope.UserAttempt, function (value, key) {
var userOptedAnswer = value.BlankBoxName + ' ' + value.OptionName;
for(var i=0;i<$scope.correctResonseKeyValue.length;i++) {
if (userOptedAnswer == $scope.correctResonseKeyValue[i]) {
$scope.Score += 1;
}
}
})
}
$scope.GetSavedLabExerciseFromDatabase = function () {
var labExerciseInfo = {
userId: 1,
identifier: 'di'
};
LabExerciseService.GetLabExercise(labExerciseInfo)
.then(
function (result) {
if (result != undefined && result != AIAConstants.SAVED_LAB_EXERCISE_NOT_FOUND) {
$scope.SavedLabExercise = result;
$scope.ShowSavedLabExercise();
}
},
function(error){
console.log(' Error in getting LabExercise = ' + error.statusText);
$rootScope.errorMessage = AdminConstants.ERROR_IN_FECTHING_DETAILS;
$("#messageModal").modal('show');
})
}
$scope.ShowSavedLabExercise = function () {
//from database
var lastQuestion = $scope.quiznumber;
var lastQuestionDetails;
var lastQuestionAnswers;
//if user opted this question, it will have entry in LabExerciseUserData
var thisQuestiondataInLabExerciseUserData = new jinqJs()
.from($scope.LabExerciseUserData)
.where('QuestionNo == ' + $scope.quiznumber)
.select();
//if this exists in LabExerciseUserData, show the new opted else show from database
if (thisQuestiondataInLabExerciseUserData.length > 0){
lastQuestionDetails = thisQuestiondataInLabExerciseUserData;
if (lastQuestionDetails != undefined && lastQuestionDetails.length > 0)
lastQuestionAnswers = lastQuestionDetails[0].UserAnswer.split(',');
}
else{
lastQuestionDetails = new jinqJs()
.from($scope.SavedLabExercise.labExercise)
.where('QuestionNo == ' + lastQuestion)
.select();
if (lastQuestionDetails != undefined && lastQuestionDetails.length>0)
lastQuestionAnswers = lastQuestionDetails[0].UserAnswers.split(',');
}
if (lastQuestionDetails != undefined && lastQuestionDetails.length > 0) {
$scope.QustionAnsKeyValue = [];
for (var i = 0; i < lastQuestionAnswers.length; i++) {
var num = i + 1;
$scope.QustionAnsKeyValue.push({ blockbox: 'T' + num, text: lastQuestionAnswers[i] });
if (lastQuestionAnswers[i] != "") {
var blocks = $("div[id*='block-']");
for (var j = 0; j < blocks.length; j++) {
if ((blocks[j].innerHTML).toString() == lastQuestionAnswers[i]) {
$('#' + blocks[j].id).css("display", "none");
};
}
}
}
var labQuestionData = new jinqJs()
.from($scope.LabExData.LabExercise[0].Questions)
.where('Number == ' + lastQuestion)
.select();
angular.forEach($scope.QustionAnsKeyValue, function (value, key) {
var questionOptionBox = new jinqJs()
.from(labQuestionData[0].OptionBox)
.where('BoxName == ' + value.blockbox)
.select();
if (value.text != "") {
$scope.DraggedList.push({ "id": value.blockbox, "optionName": value.blockbox, "Value": value.text, "topcoord": questionOptionBox[0].topcoord, "leftcoord": questionOptionBox[0].leftcoord });
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
}
})
}
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
}
}]
);
AIA.directive('draggable', function () {
return {
link: function ($scope, element, attrs) {
element[0].addEventListener('dragstart', $scope.handleDragStart, false);
element[0].addEventListener('dragend', $scope.handleDragEnd, false);
}
}
});
AIA.directive('droppable', function () {
return {
link: function ($scope, element, attrs) {
element[0].addEventListener('drop', $scope.handleDrop, false);
element[0].addEventListener('dragover', $scope.handleDragOver, false);
}
}
});
AIA.directive('imageonload', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
element.bind('load', function (e) {
$('#imgdiv').css('width', this.naturalWidth + "px");
});
element.bind('error', function () {
//alert('image could not be loaded');
});
}
};
});
//angular.module('app')
//.filter('to_trusted', ['$sce', function ($sce) {
// return function (text) {
// return $sce.trustAsHtml(text);
// };
//}]);