From 4966c8ebead210f034dae802c8bbdd4cc53c1837 Mon Sep 17 00:00:00 2001 From: amrita.vishnoi Date: Thu, 4 Aug 2016 14:23:25 +0530 Subject: [PATCH] 1. Modified search worker process, now it is working for all browsers. 2. Terminate worker process after getting data so now endless callbacks are not comming. --- 400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js | 106 ++++++++++++++++++++++++++++------------------------------------------------------------------------------ 400-SOURCECODE/AIAHTML5.Web/search-wp.js | 68 ++++++++++++++++++++++++++++++++++++++------------------------------ 2 files changed, 66 insertions(+), 108 deletions(-) diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js index 380b8d0..0e09223 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js @@ -55,6 +55,7 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo $scope.previousSelectedTermList = []; $scope.runningWorkers = []; + $scope.runningSearchWorkers = []; // This variable is used for unhighlight previously highlighted body portion, if multiAnnotation is false. $scope.machedIcolorInBodyRegion = []; @@ -397,26 +398,47 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo var searchWorker = new Worker('search-wp.js'); //push workers in array to further used the refernece to delete the workers - $scope.runningWorkers.push({ 'workerName': searchWorker }) + $scope.runningSearchWorkers.push({ 'workerName': searchWorker }) - // console.log('for bodyRegionId = ' + bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")) + //console.log('for bodyRegionId = ' + bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")) searchWorker.postMessage({ 'currentBodyViewId': currentBodyViewId, }) searchWorker.onmessage = function (e) { - console.log('callback searchWorker '); + //console.log('callback searchWorker , time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); + + $scope.TermNumberData = e.data.TermNumberData, $scope.VocabTermData = e.data.VocabTermData, $scope.vocabTermTxt = e.data.vocabTermTxt + $scope.VocabTermTxt = new jinqJs() .from($scope.vocabTermTxt) .distinct('_TermText', '_ActualTermNumber') .orderBy([{ field: '_TermText', sort: 'asc' }]) .select('_ActualTermNumber', '_TermText', '_cdId'); + + console.log('JlinqActivity , time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); + + if ($scope.runningSearchWorkers != null || $scope.runningSearchWorkers != undefined) { + + var workerCount = $scope.runningSearchWorkers.length; + if (workerCount > 0) { + for (var i = workerCount - 1; i >= 0; i--) { + + + + var runningWorker = $scope.runningSearchWorkers[i].workerName; + runningWorker.terminate(); + $scope.runningSearchWorkers.splice(i, 1); + // workerCount--; + } + } + } } //2. load bodyRegion data @@ -460,6 +482,7 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo }) + $scope.loadLayerDataForCurrentBodyView = function () { //1. var bgArtJsonPath = ''; @@ -482,7 +505,8 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo //4. $scope.isVisibleTermddl = false; //4. load Json for annotation - $scope.loadTermData(); + + //$scope.loadTermData(); //if ($scope.isBodylayerdataLoaded == true) { @@ -513,80 +537,6 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo } - - - $scope.loadTermData = function () { - var currentBodyViewId = localStorage.getItem("currentBodyViewId"); - - var termNoJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json'; - $http({ method: 'GET', url: termNoJsonPath }) - .success(function (data) { - $scope.TermNumberData = data; - - //1. - $scope.loadTermTextData(); - - - }) - .error(function (data, status, headers, config) { - - //1. - console.log('DATA.NOT.LOADED FOR: ' + termNoJsonPath + ' , ERROR:' + data); - - //2. - $scope.loadTermData(); - - }); - - } - - $scope.loadTermTextData =function() - { - //1. - var termTextJsonPath = '~/../content/data/json/da/vocab/english/cm_dat_vocabterm_1.json'; - $http({ method: 'GET', url: termTextJsonPath }) - .success(function (data) { - $scope.VocabTermData = data; - - var vocabTermTxt = []; - angular.forEach($scope.TermNumberData.TermData.Term, function (value1, key1) { - angular.forEach($scope.VocabTermData.VocabTerms.Term, function (value2, key2) { - - if (value1._ActualTermNumber === value2._ActualTermNumber) { - vocabTermTxt.push( - { - "_ActualTermNumber": value2._ActualTermNumber, - "_TermText": value2._TermText, - "_cdId": value2._cdId - } - ); - } - }) - - }) - - $scope.VocabTermTxt = new jinqJs() - .from(vocabTermTxt) - .distinct('_TermText', '_ActualTermNumber') - .orderBy([{ field: '_TermText', sort: 'asc' }]) - .select('_ActualTermNumber', '_TermText', '_cdId'); - - - $scope.currentTitleFromJson = localStorage.getItem("currentViewTitleFromJson"); - - - - }) - .error(function (data, status, headers, config) { - - //1. - console.log('DATA.NOT.LOADED FOR:' + termTextJsonPath + ', ERROR: ' + data); - - //2. - $scope.loadTermTextData(); - }); - } - //Code for displaying NavigatorImage for BodyView $scope.LoadBodyViewNavigatorImage = function () { diff --git a/400-SOURCECODE/AIAHTML5.Web/search-wp.js b/400-SOURCECODE/AIAHTML5.Web/search-wp.js index 4a87284..e54c49e 100644 --- a/400-SOURCECODE/AIAHTML5.Web/search-wp.js +++ b/400-SOURCECODE/AIAHTML5.Web/search-wp.js @@ -1,46 +1,52 @@  + loadTermData = function (currentBodyViewId) { - console.log('search-wp, loadTermData') + console.log('search-wp, loadTermData, time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); var termNoJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json'; - readTextFile(termNoJsonPath, function (text) { - var TermNumberData = JSON.parse(text); - console.log(TermNumberData); - loadTermTextData(TermNumberData); - }); - + var TermNumberData; + var AJAX_req = new XMLHttpRequest(); + AJAX_req.open("GET", termNoJsonPath, true); + AJAX_req.setRequestHeader("Content-type", "application/json"); -} + AJAX_req.onreadystatechange = function () { + if (AJAX_req.readyState == 4 && AJAX_req.status == 200) { + TermNumberData = JSON.parse(AJAX_req.responseText); + console.log("data returned: " + TermNumberData); - -function readTextFile(file, callback) { - var rawFile = new XMLHttpRequest(); - rawFile.overrideMimeType("application/json"); - rawFile.open("GET", file, true); - rawFile.onreadystatechange = function () { - if (rawFile.readyState === 4 && rawFile.status == "200") { - callback(rawFile.responseText); + loadTermTextData(TermNumberData); + } } - } - rawFile.send(null); + AJAX_req.send(); + + } + loadTermTextData = function (TermNumberData) { + + //1. var termTextJsonPath = '~/../content/data/json/da/vocab/english/cm_dat_vocabterm_1.json'; - readTextFile(termTextJsonPath, function (text) { - var VocabTermData = JSON.parse(text); - console.log(TermNumberData); - loadTermTextData(TermNumberData); - - + // readTextFile(termTextJsonPath, function (text) { + + var VocabTermData; + var AJAX_req = new XMLHttpRequest(); + AJAX_req.open("GET", termTextJsonPath, true); + AJAX_req.setRequestHeader("Content-type", "application/json"); + + AJAX_req.onreadystatechange = function () { + if (AJAX_req.readyState == 4 && AJAX_req.status == 200) { + VocabTermData = JSON.parse(AJAX_req.responseText); + console.log("data returned FOR VocabTermData: " + VocabTermData); + var vocabTermTxt = []; TermNumberData.TermData.Term.forEach(function (value1, key1) { - + VocabTermData.VocabTerms.Term.forEach(function (value2, key2) { if (value1._ActualTermNumber === value2._ActualTermNumber) { @@ -56,9 +62,6 @@ loadTermTextData = function (TermNumberData) { }) - - - self.postMessage({ 'vocabTermTxt': vocabTermTxt, 'TermNumberData': TermNumberData, @@ -66,13 +69,18 @@ loadTermTextData = function (TermNumberData) { }); - }) + } + } + AJAX_req.send(); + + + //}) } self.onmessage = function (e) { - console.log('search-wp onmessage') + //console.log('search-wp onmessage time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); loadTermData(e.data.currentBodyViewId); } -- libgit2 0.21.4