Commit 4966c8ebead210f034dae802c8bbdd4cc53c1837
1 parent
d74d09f3
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.
Showing
2 changed files
with
66 additions
and
108 deletions
400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js
... | ... | @@ -55,6 +55,7 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
55 | 55 | |
56 | 56 | $scope.previousSelectedTermList = []; |
57 | 57 | $scope.runningWorkers = []; |
58 | + $scope.runningSearchWorkers = []; | |
58 | 59 | |
59 | 60 | // This variable is used for unhighlight previously highlighted body portion, if multiAnnotation is false. |
60 | 61 | $scope.machedIcolorInBodyRegion = []; |
... | ... | @@ -397,26 +398,47 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
397 | 398 | var searchWorker = new Worker('search-wp.js'); |
398 | 399 | |
399 | 400 | //push workers in array to further used the refernece to delete the workers |
400 | - $scope.runningWorkers.push({ 'workerName': searchWorker }) | |
401 | + $scope.runningSearchWorkers.push({ 'workerName': searchWorker }) | |
401 | 402 | |
402 | - // console.log('for bodyRegionId = ' + bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")) | |
403 | + //console.log('for bodyRegionId = ' + bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")) | |
403 | 404 | |
404 | 405 | searchWorker.postMessage({ |
405 | 406 | 'currentBodyViewId': currentBodyViewId, |
406 | 407 | }) |
407 | 408 | |
408 | 409 | searchWorker.onmessage = function (e) { |
409 | - console.log('callback searchWorker '); | |
410 | + //console.log('callback searchWorker , time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
411 | + | |
412 | + | |
410 | 413 | |
411 | 414 | $scope.TermNumberData = e.data.TermNumberData, |
412 | 415 | $scope.VocabTermData = e.data.VocabTermData, |
413 | 416 | $scope.vocabTermTxt = e.data.vocabTermTxt |
414 | 417 | |
418 | + | |
415 | 419 | $scope.VocabTermTxt = new jinqJs() |
416 | 420 | .from($scope.vocabTermTxt) |
417 | 421 | .distinct('_TermText', '_ActualTermNumber') |
418 | 422 | .orderBy([{ field: '_TermText', sort: 'asc' }]) |
419 | 423 | .select('_ActualTermNumber', '_TermText', '_cdId'); |
424 | + | |
425 | + console.log('JlinqActivity , time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
426 | + | |
427 | + if ($scope.runningSearchWorkers != null || $scope.runningSearchWorkers != undefined) { | |
428 | + | |
429 | + var workerCount = $scope.runningSearchWorkers.length; | |
430 | + if (workerCount > 0) { | |
431 | + for (var i = workerCount - 1; i >= 0; i--) { | |
432 | + | |
433 | + | |
434 | + | |
435 | + var runningWorker = $scope.runningSearchWorkers[i].workerName; | |
436 | + runningWorker.terminate(); | |
437 | + $scope.runningSearchWorkers.splice(i, 1); | |
438 | + // workerCount--; | |
439 | + } | |
440 | + } | |
441 | + } | |
420 | 442 | } |
421 | 443 | |
422 | 444 | //2. load bodyRegion data |
... | ... | @@ -460,6 +482,7 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
460 | 482 | |
461 | 483 | }) |
462 | 484 | |
485 | + | |
463 | 486 | $scope.loadLayerDataForCurrentBodyView = function () { |
464 | 487 | //1. |
465 | 488 | var bgArtJsonPath = ''; |
... | ... | @@ -482,7 +505,8 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
482 | 505 | //4. |
483 | 506 | $scope.isVisibleTermddl = false; |
484 | 507 | //4. load Json for annotation |
485 | - $scope.loadTermData(); | |
508 | + | |
509 | + //$scope.loadTermData(); | |
486 | 510 | |
487 | 511 | |
488 | 512 | //if ($scope.isBodylayerdataLoaded == true) { |
... | ... | @@ -513,80 +537,6 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo |
513 | 537 | |
514 | 538 | } |
515 | 539 | |
516 | - | |
517 | - | |
518 | - $scope.loadTermData = function () { | |
519 | - var currentBodyViewId = localStorage.getItem("currentBodyViewId"); | |
520 | - | |
521 | - var termNoJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json'; | |
522 | - $http({ method: 'GET', url: termNoJsonPath }) | |
523 | - .success(function (data) { | |
524 | - $scope.TermNumberData = data; | |
525 | - | |
526 | - //1. | |
527 | - $scope.loadTermTextData(); | |
528 | - | |
529 | - | |
530 | - }) | |
531 | - .error(function (data, status, headers, config) { | |
532 | - | |
533 | - //1. | |
534 | - console.log('DATA.NOT.LOADED FOR: ' + termNoJsonPath + ' , ERROR:' + data); | |
535 | - | |
536 | - //2. | |
537 | - $scope.loadTermData(); | |
538 | - | |
539 | - }); | |
540 | - | |
541 | - } | |
542 | - | |
543 | - $scope.loadTermTextData =function() | |
544 | - { | |
545 | - //1. | |
546 | - var termTextJsonPath = '~/../content/data/json/da/vocab/english/cm_dat_vocabterm_1.json'; | |
547 | - $http({ method: 'GET', url: termTextJsonPath }) | |
548 | - .success(function (data) { | |
549 | - $scope.VocabTermData = data; | |
550 | - | |
551 | - var vocabTermTxt = []; | |
552 | - angular.forEach($scope.TermNumberData.TermData.Term, function (value1, key1) { | |
553 | - angular.forEach($scope.VocabTermData.VocabTerms.Term, function (value2, key2) { | |
554 | - | |
555 | - if (value1._ActualTermNumber === value2._ActualTermNumber) { | |
556 | - vocabTermTxt.push( | |
557 | - { | |
558 | - "_ActualTermNumber": value2._ActualTermNumber, | |
559 | - "_TermText": value2._TermText, | |
560 | - "_cdId": value2._cdId | |
561 | - } | |
562 | - ); | |
563 | - } | |
564 | - }) | |
565 | - | |
566 | - }) | |
567 | - | |
568 | - $scope.VocabTermTxt = new jinqJs() | |
569 | - .from(vocabTermTxt) | |
570 | - .distinct('_TermText', '_ActualTermNumber') | |
571 | - .orderBy([{ field: '_TermText', sort: 'asc' }]) | |
572 | - .select('_ActualTermNumber', '_TermText', '_cdId'); | |
573 | - | |
574 | - | |
575 | - $scope.currentTitleFromJson = localStorage.getItem("currentViewTitleFromJson"); | |
576 | - | |
577 | - | |
578 | - | |
579 | - }) | |
580 | - .error(function (data, status, headers, config) { | |
581 | - | |
582 | - //1. | |
583 | - console.log('DATA.NOT.LOADED FOR:' + termTextJsonPath + ', ERROR: ' + data); | |
584 | - | |
585 | - //2. | |
586 | - $scope.loadTermTextData(); | |
587 | - }); | |
588 | - } | |
589 | - | |
590 | 540 | //Code for displaying NavigatorImage for BodyView |
591 | 541 | $scope.LoadBodyViewNavigatorImage = function () |
592 | 542 | { | ... | ... |
400-SOURCECODE/AIAHTML5.Web/search-wp.js
1 | 1 | |
2 | + | |
2 | 3 | loadTermData = function (currentBodyViewId) |
3 | 4 | { |
4 | - console.log('search-wp, loadTermData') | |
5 | + console.log('search-wp, loadTermData, time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
5 | 6 | |
6 | 7 | var termNoJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json'; |
7 | 8 | |
8 | - readTextFile(termNoJsonPath, function (text) { | |
9 | - var TermNumberData = JSON.parse(text); | |
10 | - console.log(TermNumberData); | |
11 | - loadTermTextData(TermNumberData); | |
12 | - }); | |
13 | - | |
9 | + var TermNumberData; | |
10 | + var AJAX_req = new XMLHttpRequest(); | |
11 | + AJAX_req.open("GET", termNoJsonPath, true); | |
12 | + AJAX_req.setRequestHeader("Content-type", "application/json"); | |
14 | 13 | |
15 | -} | |
14 | + AJAX_req.onreadystatechange = function () { | |
15 | + if (AJAX_req.readyState == 4 && AJAX_req.status == 200) { | |
16 | + TermNumberData = JSON.parse(AJAX_req.responseText); | |
17 | + console.log("data returned: " + TermNumberData); | |
16 | 18 | |
17 | - | |
18 | -function readTextFile(file, callback) { | |
19 | - var rawFile = new XMLHttpRequest(); | |
20 | - rawFile.overrideMimeType("application/json"); | |
21 | - rawFile.open("GET", file, true); | |
22 | - rawFile.onreadystatechange = function () { | |
23 | - if (rawFile.readyState === 4 && rawFile.status == "200") { | |
24 | - callback(rawFile.responseText); | |
19 | + loadTermTextData(TermNumberData); | |
20 | + } | |
25 | 21 | } |
26 | - } | |
27 | - rawFile.send(null); | |
22 | + AJAX_req.send(); | |
23 | + | |
24 | + | |
28 | 25 | } |
29 | 26 | |
27 | + | |
30 | 28 | loadTermTextData = function (TermNumberData) { |
29 | + | |
30 | + | |
31 | 31 | //1. |
32 | 32 | var termTextJsonPath = '~/../content/data/json/da/vocab/english/cm_dat_vocabterm_1.json'; |
33 | - readTextFile(termTextJsonPath, function (text) { | |
34 | - var VocabTermData = JSON.parse(text); | |
35 | - console.log(TermNumberData); | |
36 | - loadTermTextData(TermNumberData); | |
37 | - | |
38 | 33 | |
39 | - | |
34 | + // readTextFile(termTextJsonPath, function (text) { | |
35 | + | |
36 | + var VocabTermData; | |
37 | + var AJAX_req = new XMLHttpRequest(); | |
38 | + AJAX_req.open("GET", termTextJsonPath, true); | |
39 | + AJAX_req.setRequestHeader("Content-type", "application/json"); | |
40 | + | |
41 | + AJAX_req.onreadystatechange = function () { | |
42 | + if (AJAX_req.readyState == 4 && AJAX_req.status == 200) { | |
43 | + VocabTermData = JSON.parse(AJAX_req.responseText); | |
44 | + console.log("data returned FOR VocabTermData: " + VocabTermData); | |
45 | + | |
40 | 46 | var vocabTermTxt = []; |
41 | 47 | |
42 | 48 | TermNumberData.TermData.Term.forEach(function (value1, key1) { |
43 | - | |
49 | + | |
44 | 50 | VocabTermData.VocabTerms.Term.forEach(function (value2, key2) { |
45 | 51 | |
46 | 52 | if (value1._ActualTermNumber === value2._ActualTermNumber) { |
... | ... | @@ -56,9 +62,6 @@ loadTermTextData = function (TermNumberData) { |
56 | 62 | |
57 | 63 | }) |
58 | 64 | |
59 | - | |
60 | - | |
61 | - | |
62 | 65 | self.postMessage({ |
63 | 66 | 'vocabTermTxt': vocabTermTxt, |
64 | 67 | 'TermNumberData': TermNumberData, |
... | ... | @@ -66,13 +69,18 @@ loadTermTextData = function (TermNumberData) { |
66 | 69 | |
67 | 70 | }); |
68 | 71 | |
69 | - }) | |
72 | + } | |
73 | + } | |
74 | + AJAX_req.send(); | |
75 | + | |
76 | + | |
77 | + //}) | |
70 | 78 | |
71 | 79 | } |
72 | 80 | |
73 | 81 | |
74 | 82 | self.onmessage = function (e) { |
75 | - console.log('search-wp onmessage') | |
83 | + //console.log('search-wp onmessage time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")); | |
76 | 84 | loadTermData(e.data.currentBodyViewId); |
77 | 85 | |
78 | 86 | } | ... | ... |