Commit f63480a5a45d2a881aa9fdfc9b177597d075947c
1 parent
fa9a03ff
Getting saved data and showing first question as per saved data,
Need to jump to the last opted questionan and show as per saved data
Showing
8 changed files
with
226 additions
and
15 deletions
400-SOURCECODE/AIAHTML5.API/Constants/AIAConstants.cs
... | ... | @@ -43,6 +43,6 @@ namespace AIAHTML5.API.Constants |
43 | 43 | public const string UNBLOCK_USER_EMAIL_SUBJECT = "Unblock user request mail for:"; |
44 | 44 | public const string LAB_EXERCISE_SAVE_SUCCESS = "Your lab exercise attempt is saved successfully."; |
45 | 45 | public const string LAB_EXERCISE_SAVE_FAILURE = "We are unable to save your lab exercise attempt, please try again."; |
46 | - | |
46 | + public const string SAVED_LAB_EXERCISE_NOT_FOUND = "Saved Lab Exercise not found."; | |
47 | 47 | } |
48 | 48 | } |
49 | 49 | \ No newline at end of file | ... | ... |
400-SOURCECODE/AIAHTML5.API/Constants/DBConstants.cs
... | ... | @@ -28,5 +28,7 @@ namespace AIAHTML5.API.Constants |
28 | 28 | public const string GET_BLOCKED_USER_BY_USER_ID = "GetBlockedUserByUserId"; |
29 | 29 | public const string GET_BLOCKED_USERS_BY_USER_TYPE = "GetBlockedUserByUserType"; |
30 | 30 | public const string SAVE_LAB_EXERCISE_ATTEMPT = "usp_SaveLabExerciseAttempts"; |
31 | + public const string GET_LAB_EXERCISE = "GetLabExcerciseByUserId"; | |
32 | + | |
31 | 33 | } |
32 | 34 | } |
33 | 35 | \ No newline at end of file | ... | ... |
400-SOURCECODE/AIAHTML5.API/Controllers/LabExerciseController.cs
... | ... | @@ -19,15 +19,54 @@ namespace AIAHTML5.API.Controllers |
19 | 19 | public class LabExerciseController : ApiController |
20 | 20 | { |
21 | 21 | // GET api/LabExercise |
22 | - public IEnumerable<string> Get() | |
23 | - { | |
24 | - return new string[] { "value1", "value2" }; | |
25 | - } | |
22 | + //public IEnumerable<string> Get() | |
23 | + //{ | |
24 | + // return new string[] { "value1", "value2" }; | |
25 | + //} | |
26 | 26 | |
27 | 27 | // GET api/LabExercise/5 |
28 | - public string Get(int id) | |
28 | + public HttpResponseMessage Get([FromUri] int userId, string labExerciseIdentifier) | |
29 | 29 | { |
30 | - return "value"; | |
30 | + ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)); | |
31 | + logger.Debug("inside Get LabExerciseController"); | |
32 | + | |
33 | + try | |
34 | + { | |
35 | + DBModel db = new DBModel(); | |
36 | + LabExercise labEx = db.GetLabExercise(userId, labExerciseIdentifier); | |
37 | + | |
38 | + if (labEx!=null) | |
39 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(labEx)) }; | |
40 | + else | |
41 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.SAVED_LAB_EXERCISE_NOT_FOUND) }; | |
42 | + | |
43 | + } | |
44 | + | |
45 | + catch (SqlException ex) | |
46 | + { | |
47 | + logger.Fatal("SqlException occured for UserId =" + userId.ToString() + " and LabExerciseIdentifier= " + labExerciseIdentifier + "Exception= " + ex.Message + ", STACKTRACE: " + ex.StackTrace); | |
48 | + | |
49 | + ArrayList supportMailList = UserUtility.GetSupportMailList(); | |
50 | + string mailSubject = AIAConstants.SQL_CONNECTION_ERROR_MAIL_SUBJECT; | |
51 | + string mailBody = "MESSAGE: " + ex.Message + ", STACKTRACE: " + ex.StackTrace; | |
52 | + UserUtility.SendEmailForException(userId, supportMailList, "", mailSubject, mailBody); | |
53 | + | |
54 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) }; | |
55 | + | |
56 | + } | |
57 | + catch (Exception e) | |
58 | + { | |
59 | + logger.Fatal("SqlException occured for UserId =" + userId.ToString() + " and LabExerciseIdentifier= " + labExerciseIdentifier + "Exception= " + e.Message + ", STACKTRACE: " + e.StackTrace); | |
60 | + | |
61 | + ArrayList supportMailList = UserUtility.GetSupportMailList(); | |
62 | + string mailSubject = AIAConstants.SQL_CONNECTION_ERROR_MAIL_SUBJECT; | |
63 | + string mailBody = "MESSAGE: " + e.Message + ", STACKTRACE: " + e.StackTrace; | |
64 | + UserUtility.SendEmailForException(userId, supportMailList, "", mailSubject, mailBody); | |
65 | + | |
66 | + return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(AIAConstants.SQL_CONNECTION_ERROR) }; | |
67 | + | |
68 | + } | |
69 | + | |
31 | 70 | } |
32 | 71 | |
33 | 72 | // POST api/LabExercise |
... | ... | @@ -96,6 +135,7 @@ namespace AIAHTML5.API.Controllers |
96 | 135 | |
97 | 136 | DataTable labExerciseDetailsDataTable = new UserUtility().ToDataTable(le.labExercise); |
98 | 137 | int result = le.insertLabExerciseAttempt(le, labExerciseDetailsDataTable); |
138 | + | |
99 | 139 | if (result == -1) |
100 | 140 | { |
101 | 141 | return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(AIAConstants.LAB_EXERCISE_SAVE_SUCCESS) }; | ... | ... |
400-SOURCECODE/AIAHTML5.API/Models/DBModel.cs
... | ... | @@ -862,10 +862,8 @@ namespace AIAHTML5.API.Models |
862 | 862 | return result; |
863 | 863 | } |
864 | 864 | |
865 | - // internal int SaveLabExerciseAttempt(int userId, string labExerciseIdentifier, int lastQusetion, int totalQuestions, DataTable labExeciseQuizAttemptedData ) | |
866 | 865 | internal int SaveLabExerciseAttempt(LabExercise le, DataTable labExeciseQuizAttemptedData) |
867 | - | |
868 | - { | |
866 | + { | |
869 | 867 | |
870 | 868 | logger.Debug(" inside InsertUserLoginLog for userId= " + le.userId + ", labExerciseIdentifier= " + le.labExerciseIdentifier + ",lastQusetion= " + le.lastQuestion + ",totalQuestions=" + le.totalQuestions); |
871 | 869 | |
... | ... | @@ -900,7 +898,68 @@ namespace AIAHTML5.API.Models |
900 | 898 | |
901 | 899 | } |
902 | 900 | |
903 | - | |
901 | + internal LabExercise GetLabExercise(int userId, string labIdentifier) | |
902 | + { | |
903 | + | |
904 | + | |
905 | + logger.Debug(" Inside GetUserDetailsByEmailId for userId = " + userId + "and labIdentifier= " + labIdentifier); | |
906 | + | |
907 | + LabExercise le = new LabExercise(); | |
908 | + le.labExercise = new List<LabEcerciseDetails>(); | |
909 | + DBModel objModel = new DBModel(); | |
910 | + | |
911 | + SqlConnection conn = new SqlConnection(dbConnectionString); | |
912 | + SqlCommand cmd = new SqlCommand(); | |
913 | + SqlDataAdapter adapter; | |
914 | + SqlParameter param; | |
915 | + DataSet ds = new DataSet(); | |
916 | + | |
917 | + cmd.Connection = conn; | |
918 | + cmd.CommandText = DBConstants.GET_LAB_EXERCISE; | |
919 | + cmd.CommandType = CommandType.StoredProcedure; | |
920 | + | |
921 | + //cmd.Parameters.AddWithValue("@UserId", userId); | |
922 | + //cmd.Parameters.AddWithValue("@Identifier", labIdentifier); | |
923 | + cmd.Parameters.Add("@UserId", SqlDbType.Int).Value = userId; | |
924 | + cmd.Parameters.Add("@Identifier", SqlDbType.NVarChar).Value = labIdentifier; | |
925 | + | |
926 | + | |
927 | + adapter = new SqlDataAdapter(cmd); | |
928 | + adapter.Fill(ds); | |
929 | + | |
930 | + | |
931 | + if (ds != null && ds.Tables.Count > 0) | |
932 | + { | |
933 | + DataTable dt = ds.Tables[0]; | |
934 | + | |
935 | + if (dt.Rows.Count > 0) | |
936 | + { | |
937 | + foreach (DataRow dr in dt.Rows) | |
938 | + { | |
939 | + le.userId = Convert.ToInt32(dr["UserId"]); | |
940 | + le.labExerciseIdentifier = dr["labExerciseIdentifier"].ToString(); | |
941 | + | |
942 | + le.lastQuestion = Convert.ToInt32(dr["LastQuestion"]); | |
943 | + le.totalQuestions = Convert.ToInt32(dr["TotalQuestions"]); | |
944 | + | |
945 | + LabEcerciseDetails led = new LabEcerciseDetails(); | |
946 | + led.StateObject = dr["StateObject"].ToString(); | |
947 | + led.UserAnswers = dr["UserAnswers"].ToString(); | |
948 | + led.Score = Convert.ToInt32(dr["Score"]); | |
949 | + led.MaxScore = Convert.ToInt32(dr["MaxScore"]); | |
950 | + led.QuestionNo = Convert.ToInt32(dr["QuestionNo"]); | |
951 | + led.CorrectAnswers = dr["CorrectAnswers"].ToString(); | |
952 | + led.DragItems = dr["DragItems"].ToString(); | |
953 | + le.labExercise.Add(led); | |
954 | + } | |
955 | + } | |
956 | + } | |
957 | + | |
958 | + return le; | |
959 | + | |
960 | + | |
961 | + | |
962 | + } | |
904 | 963 | //internal int InsertLabExerciseDetails(int userId, string labExerciseIdentifier, int lastQusetion, int totalQuestions, List<> labExDetails ) |
905 | 964 | //{ |
906 | 965 | // return 1; | ... | ... |
400-SOURCECODE/AIAHTML5.API/Models/LabExercise.cs
... | ... | @@ -32,6 +32,16 @@ namespace AIAHTML5.API.Models |
32 | 32 | return result; |
33 | 33 | } |
34 | 34 | |
35 | + internal LabExercise GetLabExercise(int userId, string labExIdentifier) | |
36 | + { | |
37 | + DBModel objModel = new DBModel(); | |
38 | + | |
39 | + LabExercise le = objModel.GetLabExercise(userId, labExIdentifier); | |
40 | + | |
41 | + return le; | |
42 | + | |
43 | + } | |
44 | + | |
35 | 45 | |
36 | 46 | } |
37 | 47 | |
... | ... | @@ -44,5 +54,6 @@ namespace AIAHTML5.API.Models |
44 | 54 | public string CorrectAnswers { get; set; } |
45 | 55 | public string DragItems { get; set; } |
46 | 56 | public int Score { get; set; } |
57 | + public string StateObject { get; set; } | |
47 | 58 | } |
48 | 59 | } |
49 | 60 | \ No newline at end of file | ... | ... |
400-SOURCECODE/AIAHTML5.Web/app/controllers/LabExercController.js
1 | 1 | ๏ปฟ/// <reference path="../../content/data/json/le/LabExercise.js" /> |
2 | -AIA.controller("LabExercController", ["$scope", "$rootScope", "pages", "$log", '$http', 'DataService', '$filter', '$location', '$document', '$sce', "$compile", "$location", "LabExerciseService", | |
3 | -function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location, $document, $sce, $compile, $location, LabExerciseService) { | |
2 | +AIA.controller("LabExercController", ["$scope", "$rootScope", "pages", "$log", '$http', 'DataService', '$filter', '$location', '$document', '$sce', "$compile", "$location", "LabExerciseService","AIAConstants", | |
3 | +function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location, $document, $sce, $compile, $location, LabExerciseService,AIAConstants) { | |
4 | 4 | $scope.$sce = $sce; |
5 | 5 | $scope.LabExerciseName; |
6 | 6 | $scope.LabExerciseQuiz = null; |
... | ... | @@ -138,6 +138,8 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
138 | 138 | $scope.Imagepath = keywords.labexercise + "/" + result.LabExercise[index].Questions[index1].ImagePath; |
139 | 139 | } |
140 | 140 | $scope.ShowHideDiv(result.LabExercise[index].Questions[index1].Options[0].textalign); |
141 | + | |
142 | + $scope.GetSavedLabExerciseFromDatabase(); | |
141 | 143 | } |
142 | 144 | }); |
143 | 145 | //$scope.quiznumber++; |
... | ... | @@ -220,7 +222,6 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
220 | 222 | e.preventDefault(); |
221 | 223 | e.stopPropagation(); |
222 | 224 | var x = $("#droppable").offset(); |
223 | - //alert(x.left + "," + $("#droppable").clientWidth + "," + x.top); | |
224 | 225 | |
225 | 226 | var id = $(this).attr("id"); |
226 | 227 | |
... | ... | @@ -229,6 +230,8 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
229 | 230 | |
230 | 231 | var dataText = e.dataTransfer.getData('text/plain'); |
231 | 232 | if (id == "divoptions" || id == "divleft" || id == "divright") { |
233 | + alert('if') | |
234 | + | |
232 | 235 | var item = $('#' + $scope.dragableId).html(); |
233 | 236 | var rindex = $scope.DraggedList.indexOf(item); |
234 | 237 | var labExerciseModulePath = '~/../content/data/json/le/' + keywords.labexercise + '.json'; |
... | ... | @@ -271,7 +274,7 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
271 | 274 | ) |
272 | 275 | } |
273 | 276 | else { |
274 | - | |
277 | + alert('else') | |
275 | 278 | var labExerciseModulePath = '~/../content/data/json/le/' + keywords.labexercise + '.json'; |
276 | 279 | DataService.getAnotherJson(labExerciseModulePath).then( |
277 | 280 | function (result) { |
... | ... | @@ -555,6 +558,76 @@ function ($scope, $rootScope, pages, log, $http, DataService, $filter, $location |
555 | 558 | |
556 | 559 | }) |
557 | 560 | } |
561 | + | |
562 | + $scope.GetSavedLabExerciseFromDatabase = function () { | |
563 | + | |
564 | + var labExerciseInfo = { | |
565 | + userId: 1, | |
566 | + identifier: 'di' | |
567 | + }; | |
568 | + | |
569 | + LabExerciseService.GetLabExercise(labExerciseInfo) | |
570 | + .then( | |
571 | + | |
572 | + function (result) { | |
573 | + if (result != undefined && result != AIAConstants.SAVED_LAB_EXERCISE_NOT_FOUND) { | |
574 | + $scope.SavedLabExercise = result; | |
575 | + | |
576 | + $scope.ShowSavedLabExercise(); | |
577 | + } | |
578 | + }, | |
579 | + function(error){ | |
580 | + console.log(' Error in getting LabExercise = ' + error.statusText); | |
581 | + $rootScope.errorMessage = AdminConstants.ERROR_IN_FECTHING_DETAILS; | |
582 | + $("#messageModal").modal('show'); | |
583 | + }) | |
584 | + | |
585 | + } | |
586 | + | |
587 | + $scope.ShowSavedLabExercise = function () { | |
588 | + | |
589 | + var lastQuestion = 1;//$scope.SavedLabExercise.lastQuestion; | |
590 | + var lastQuestionDetails = new jinqJs() | |
591 | + .from($scope.SavedLabExercise.labExercise) | |
592 | + .where('QuestionNo == ' + lastQuestion) | |
593 | + .select(); | |
594 | + | |
595 | + $scope.QustionAnsKeyValue =[]; | |
596 | + var lastQuestionAnswers = lastQuestionDetails[0].UserAnswers.split(','); | |
597 | + for (var i = 0; i < lastQuestionAnswers.length; i++) { | |
598 | + var num = i + 1; | |
599 | + $scope.QustionAnsKeyValue.push({ blockbox: 'T' + num, text: lastQuestionAnswers[i] }); | |
600 | + | |
601 | + if (lastQuestionAnswers[i] != "") { | |
602 | + var blocks = $("div[id*='block-']"); | |
603 | + for (var j = 0; j < blocks.length; j++) { | |
604 | + | |
605 | + if ((blocks[j].innerHTML).toString() == lastQuestionAnswers[i]) { | |
606 | + $('#' + blocks[j].id).css("display", "none"); | |
607 | + }; | |
608 | + // userAnswers[id.replace('T', '')] = blockAnswers[i].innerHTML; | |
609 | + } | |
610 | + | |
611 | + } | |
612 | + } | |
613 | + | |
614 | + | |
615 | + var labQuestionData = new jinqJs() | |
616 | + .from($scope.LabExData.LabExercise[0].Questions) | |
617 | + .where('Number == ' + lastQuestion) | |
618 | + .select(); | |
619 | + | |
620 | + angular.forEach($scope.QustionAnsKeyValue,function(value,key){ | |
621 | + var questionOptionBox = new jinqJs() | |
622 | + .from(labQuestionData[0].OptionBox) | |
623 | + .where('BoxName == ' + value.blockbox) | |
624 | + .select(); | |
625 | + | |
626 | + $scope.DraggedList.push({ "id": 'blockbox-' + value.blockbox, "optionName": value.blockbox, "Value": value.text, "topcoord": questionOptionBox[0].topcoord, "leftcoord": questionOptionBox[0].leftcoord }); | |
627 | + | |
628 | + }) | |
629 | + | |
630 | + } | |
558 | 631 | }] |
559 | 632 | |
560 | 633 | ); | ... | ... |
400-SOURCECODE/AIAHTML5.Web/app/main/AIA.js
... | ... | @@ -497,6 +497,8 @@ AIA.constant("AIAConstants", { |
497 | 497 | "NO_BODY_SYSTEM_AVAILABLE": "Selected body system is not available on this layer.", |
498 | 498 | "COOKIES_MESSAGE": "You need to enable your browser's cookies to run this application.", |
499 | 499 | "current_year": 2018, |
500 | + "SAVED_LAB_EXERCISE_NOT_FOUND": "Saved Lab Exercise not found.", | |
501 | + "ERROR_IN_FECTHING_DETAILS": "Error in fecthing details.", | |
500 | 502 | }) |
501 | 503 | |
502 | 504 | ... | ... |
400-SOURCECODE/AIAHTML5.Web/app/services/LabExerciseService.js
... | ... | @@ -25,5 +25,29 @@ |
25 | 25 | }); |
26 | 26 | return deferred.promise; |
27 | 27 | }, |
28 | + | |
29 | + GetLabExercise: function (labExerciseInfo) { | |
30 | + var deferred = $q.defer(); | |
31 | + | |
32 | + | |
33 | + $http({ | |
34 | + url: "/API/api/LabExercise", | |
35 | + method: "GET", | |
36 | + params: {userId:1, labExerciseIdentifier:'di'} | |
37 | + }) | |
38 | + | |
39 | + .success(function (data, status, headers, config) { | |
40 | + console.log('success') | |
41 | + deferred.resolve(data); | |
42 | + }).error(function (data, status, headers, config) { | |
43 | + console.log('error') | |
44 | + deferred.reject(data); | |
45 | + $rootScope.isVisibleLogin = true; | |
46 | + $rootScope.errorMessage = data; | |
47 | + $("#messageModal").modal('show'); | |
48 | + | |
49 | + }); | |
50 | + return deferred.promise; | |
51 | + }, | |
28 | 52 | } |
29 | 53 | }) |
30 | 54 | \ No newline at end of file | ... | ... |