From 75263b72e1623600d56e435e6d41c76fccb55b83 Mon Sep 17 00:00:00 2001 From: nikita Date: Sat, 17 Feb 2018 17:25:26 +0530 Subject: [PATCH] prepared object for save . need to get score and move code in functions. --- 400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj | 19 ++++++++++--------- 400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 400-SOURCECODE/AIAHTML5.API/Controllers/LabExercises.cs | 37 +++++++++++++++++++++++++++++++++++++ 400-SOURCECODE/AIAHTML5.API/packages.config | 5 +++++ 400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ 400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js | 25 +++++++++++++++++++++++++ 400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html | 10 +++++----- 400-SOURCECODE/AIAHTML5.Web/index.html | 2 +- 8 files changed, 245 insertions(+), 33 deletions(-) create mode 100644 400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs create mode 100644 400-SOURCECODE/AIAHTML5.API/Controllers/LabExercises.cs create mode 100644 400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js diff --git a/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj b/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj index efe73a1..759758a 100644 --- a/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj +++ b/400-SOURCECODE/AIAHTML5.API/AIAHTML5.API.csproj @@ -60,17 +60,17 @@ ..\packages\MongoDB.Driver.Core.2.5.0\lib\net45\MongoDB.Driver.Core.dll True - - False - ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll + True ..\packages\System.Buffers.4.3.0\lib\netstandard1.1\System.Buffers.dll True - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.0.0\lib\net45\System.Net.Http.Formatting.dll True @@ -86,12 +86,12 @@ - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.0.0\lib\net45\System.Web.Http.dll True - - ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.0.0\lib\net45\System.Web.Http.WebHost.dll True @@ -121,6 +121,7 @@ + diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs new file mode 100644 index 0000000..d6a697a --- /dev/null +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs @@ -0,0 +1,40 @@ +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Web.Http; + +namespace AIAHTML5.API.Controllers +{ + public class LabExerciseController : ApiController + { + // GET api/ + public IEnumerable Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api//5 + public string Get(int id) + { + return "value"; + } + + // POST api/ + public void Post([FromBody]JObject labExerciseUserAttemptData) + { + } + + // PUT api//5 + public void Put(int id, [FromBody]string value) + { + } + + // DELETE api//5 + public void Delete(int id) + { + } + } +} \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/Controllers/LabExercises.cs b/400-SOURCECODE/AIAHTML5.API/Controllers/LabExercises.cs new file mode 100644 index 0000000..a8551dc --- /dev/null +++ b/400-SOURCECODE/AIAHTML5.API/Controllers/LabExercises.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System; +using System.Threading.Tasks; +using MongoDB.Bson; +using MongoDB.Driver; +using AIAHTML5.API.Properties; +using MongoDB.Driver.Builders; + +namespace AIAHTML5.API.Models +{ + public class LabExercises + { + public int Attemptnumber { get; set; } + public string labExerciseCode { get; set; } + public string Answer { get; set; } + public int Question { get; set; } + public int Score { get; set; } + + + public void UpdateUserLabExercise(Users objUser) + { + var client = new MongoClient(); + var db = client.GetDatabase(Settings.Default.database); + + var collection = db.GetCollection("Users"); + + collection.UpdateOne( + Builders.Filter.Eq("loginId", objUser.loginId), + Builders.Update.Set("LabExerciseAttempt", objUser.labExerciseAttempt)); + + + } + } +} \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.API/packages.config b/400-SOURCECODE/AIAHTML5.API/packages.config index d8d11b7..886d057 100644 --- a/400-SOURCECODE/AIAHTML5.API/packages.config +++ b/400-SOURCECODE/AIAHTML5.API/packages.config @@ -1,9 +1,14 @@  + + + + + \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js index 1831c0f..e38facd 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js @@ -1,6 +1,6 @@ /// -AIA.controller("LabExercController", ["$scope", "$rootScope", "pages", "$log", '$http', 'DataService', '$filter', '$location', '$document', '$sce',"$compile","$location", -function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location, $document, $sce, $compile, $location) { +AIA.controller("LabExercController", ["$scope", "$rootScope", "pages", "$log", '$http', 'DataService', '$filter', '$location', '$document', '$sce', "$compile", "$location", "LabExerciseService", +function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location, $document, $sce, $compile, $location, LabExerciseService) { $scope.$sce = $sce; $scope.LabExerciseName; $scope.LabExerciseQuiz = null; @@ -10,13 +10,12 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location $scope.Title = ""; $scope.Imagepath = ""; $scope.DraggedList = []; + $scope.AnswerList = []; + $scope.UserAnswersForAllQuestions = []; + $scope.LabExercise = []; $scope.dragableId = ""; $scope.blReviewAttempt = false; $scope.$on('$viewContentLoaded', function (event) { - - if ($rootScope.refreshcheck == null) { - $location.path('/'); - } // code that will be executed ... // every time this view is loaded @@ -31,7 +30,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location $rootScope.currentActiveModuleTitle = selectedModuleName; }) - $scope.showTabButton = false; + $scope.showme = false; $rootScope.currentActiveModuleTitle = pages[8].name; $scope.getLabExerciseModules(); @@ -47,7 +46,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location }); - // $scope.showTabButton = false; + // $scope.showme = false; $scope.IsVisible = function () { // $scope.scroll(); @@ -92,19 +91,16 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location $scope.GetQuizByTopic = function () { - - if ($rootScope.refreshcheck == null) { - $location.path('/'); - } var keywords = $location.search(); $scope.LabExerciseName = keywords.labexercise; $scope.LabExerciseModules = null; $scope.LabExerciseBoxes = null; + //alert($scope.LabExerciseName) var labExerciseModulePath = '~/../content/data/json/le/' + $scope.LabExerciseName + '.json'; DataService.getAnotherJson(labExerciseModulePath).then( function (result) { - //debugger; + $scope.LabExData = result; // alert(JSON.stringify(result.LabExercise)); $.each(result.LabExercise, function (index, value) { $scope.LabExerciseName = result.LabExercise[index].Topic; @@ -115,12 +111,13 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location if (result.LabExercise[index].Questions[index1].Number == $scope.quiznumber) { if (result.LabExercise[index].Questions[index1].ImagePath == "") { $("#imgblock").css("display", "none"); + //$("#imgblock").remove(); $scope.IsVisible = false; $("#textblock").css("display", "block"); $scope.LabExerciseModules = result.LabExercise[index].Questions[index1]; $scope.deliberatelyTrustDangerousSnippet = function (html) { - //var htmltag= $compile(html)($scope); - return $sce.trustAsHtml(html); + //var htmltag= $compile(html)($scope); + return $sce.trustAsHtml(html); }; $scope.activityTitle = result.LabExercise[index].Questions[index1].activityTitle; $scope.Title = result.LabExercise[index].Questions[index1].Title; @@ -129,6 +126,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location $("#imgblock").css("display", "block"); $scope.IsVisible = true; $("#textblock").css("display", "none"); + // $("#textblock").remove(); $scope.LabExerciseModules = result.LabExercise[index].Questions[index1]; $scope.activityTitle = result.LabExercise[index].Questions[index1].activityTitle; $scope.Title = result.LabExercise[index].Questions[index1].Title; @@ -151,6 +149,16 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location } $scope.nextQuiz = function () { + //need to save all questions till the current question number when user clicks on save + if ($scope.dragableId!="") { + $scope.UserAnswersForAllQuestions.push({'QuestionNo':$scope.quiznumber,'UserAnswer':$scope.AnswerList}) + + } + else { + //need to anattampted question means user ahs not dragged, dropped options so save blank + $scope.UserAnswersForAllQuestions.push({ 'QuestionNo': $scope.quiznumber, 'UserAnswer': "" }) + } + $scope.dragableId = ""; if ($scope.quiznumber == $scope.TotalNumberofQuiz) return; else @@ -160,6 +168,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location } $scope.prevQuiz = function () { + $scope.dragableId = ""; if ($scope.quiznumber == 1) return; else @@ -188,7 +197,10 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location //alert(x.left + "," + $("#droppable").clientWidth + "," + x.top); var id = $(this).attr("id"); + 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(); @@ -196,17 +208,21 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location 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; + $scope.maxScore = Options.length; + $.each(Options, function (inx, value2) { if (Options[inx].OptionTitle == item) { if ($scope.DraggedList != null) { $.each($scope.DraggedList, function (inx1, value3) { - + // $scope.AnswerList.push({ "optionName": id.split('-')[1], "AnswerName": $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"); @@ -249,6 +265,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location }); } + $scope.AnswerList.push({ "optionName": id.split('-')[1], "AnswerName": $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).remove(); $('#' + $scope.dragableId).css("display", "none"); @@ -274,6 +291,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location //{ // $("#divoptions").html("



") //} + //alert(JSON.stringify($scope.AnswerList)); }; $scope.handleDragOver = function (e) { @@ -342,7 +360,93 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location } }; - + + $scope.SaveAnswer = function () { + + //get user answers + 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; + } + + var commaSeperatedUserAnswers = ''; + for (var i = 1; i <=blockBoxLength; i++) { + + var userAns = userAnswers[i]; + if(userAns!=undefined){ + commaSeperatedUserAnswers +=userAns + ','; + } + else{ + commaSeperatedUserAnswers +=''+','; + } + } + //remove last comma + commaSeperatedUserAnswers = commaSeperatedUserAnswers.replace(/,$/, ''); + + + //get correct response + $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 options = cr[0].correctResponse[i].Answer; + $scope.correctResponse += blankBox + ' ' + options + ','; + $scope.correctResponseForSavingDatabase += parseInt(blankBox.replace('T',''))-1 + ':' + options + ','; + } + + $scope.correctResponse = $scope.correctResponse.replace(/,$/, ''); + $scope.correctResonseKeyValue = $scope.correctResponse.split(','); + + $scope.correctResponseForSavingDatabase = $scope.correctResponseForSavingDatabase.replace(/,$/, ''); + // $scope.correctResponseForSavingDatabaseArray = $scope.correctResponseForSavingDatabase.split(','); + + //get dragItems + 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 = DragItems.replace(/;$/, ''); + + + //get score + + $scope.LabExerciseAttemptedData = { + userId: localStorage.getItem('loggedInUserDetails').id, + //Attemptnumber: 1, + labExerciseIdentifier: $scope.labExercideIdentifier, + LastQuestion: $scope.quiznumber, + TotalQuestions: $scope.TotalNumberofQuiz, + MaxScore: $scope.maxScore, + UserAnswer: commaSeperatedUserAnswers, + QuestionNo: $scope.quiznumber, + CorrectAnswer: JSON.stringify($scope.correctResponseForSavingDatabase), + DragItems: $scope.DragItems, + Score: 1 + } + var abc = $scope.AnswerList; + //LabExerciseService.saveLabExerciseAttempt("superadmin", $scope.LabExerciseAttemptedData) + LabExerciseService.saveLabExerciseAttempt($scope.LabExerciseAttemptedData) + .then( + function (result) { + alert("Successfully updated"); + }, + function (error) { + console.log(' Error in authentication = ' + error.statusText); + alert("Error"); + }); + }; }] ); diff --git a/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js b/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js new file mode 100644 index 0000000..1e5f2cf --- /dev/null +++ b/400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js @@ -0,0 +1,25 @@ +AIA.factory('LabExerciseService', function ($http, $q) { + return { + saveLabExerciseAttempt: function (username, labExercieObj) { + var deferred = $q.defer(); + + $http.post('/API/api/Authenticate', JSON.stringify(userInfo), { + headers: { + 'Content-Type': 'application/json' + } + }) + .success(function (data, status, headers, config) { + console.log('success') + deferred.resolve(data); + }).error(function (data, status, headers, config) { + console.log('error') + deferred.reject(data); + $rootScope.isVisibleLogin = true; + $rootScope.errorMessage = data; + $("#messageModal").modal('show'); + + }); + return deferred.promise; + }, + } +}) \ No newline at end of file diff --git a/400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html b/400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html index 5457003..b4fcb52 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html +++ b/400-SOURCECODE/AIAHTML5.Web/app/views/LabExerc/lab-exercises-detail.html @@ -26,7 +26,7 @@
-
+
{{option.OptionTitle}}
@@ -64,7 +64,7 @@
- +
diff --git a/400-SOURCECODE/AIAHTML5.Web/index.html b/400-SOURCECODE/AIAHTML5.Web/index.html index 52a42f2..1e7da13 100644 --- a/400-SOURCECODE/AIAHTML5.Web/index.html +++ b/400-SOURCECODE/AIAHTML5.Web/index.html @@ -1435,7 +1435,7 @@ - + -- libgit2 0.21.4