Commit 6c5336a41545dfec133fc7689518f65d6ec6f325

Authored by Amrita Vishnoi
1 parent 751cfbcc

1. Refactoring the functions.

2. Proper logging on errors.
3. recursive calls for json on error.
400-SOURCECODE/AIAHTML5.Web/app/controllers/DAController.js
... ... @@ -310,197 +310,244 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
310 310 //da-body-views functions
311 311  
312 312 $scope.openBodyView = function () {
313   - //debugger;
  313 +
  314 + //1.
314 315 $rootScope.isLoading = true;
315 316 $rootScope.voId = localStorage.getItem("currentBodyViewId");;
316 317  
317   - //load bodyRegion data
318   - var brViewdata = DataService.getJson('~/../content/data/json/da/da_dat_brview.json')
  318 + //2. load bodyRegion data
  319 + var bodyRegionjsonPath = '~/../content/data/json/da/da_dat_brview.json';
  320 +
  321 + var brViewdata = DataService.getJson(bodyRegionjsonPath)
  322 +
  323 + var layerJsonPath = null;
  324 +
319 325 brViewdata.then(
320 326 function (result) {
321   - // debugger;
  327 +
322 328 $rootScope.BodyRegionData = result;
323 329 $scope.isBodyRegionDataLoaded = true;
324   - // alert('da_dat_brview= ' + result)
  330 +
  331 + //3.
  332 + $scope.loadLayerDataForCurrentBodyView();
325 333  
326   - var currentBodyViewId = localStorage.getItem("currentBodyViewId");
327   - var layerJsonPath = '';
328   - var bgArtJsonPath = '';
329   - var CommonViewId = 0;
  334 + },
  335 + function (error) {
330 336  
331   - layerJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_layer_' + currentBodyViewId + '.json';
  337 + //1.
  338 + console.log('DATA.NOT.LOADED FOR: ' + bodyRegionjsonPath + ' , ERROR:' + error.statusText);
332 339  
333 340  
  341 + //2.
  342 + $scope.openBodyView();
  343 + }
  344 + );
334 345  
335   - DataService.getAnotherJson(layerJsonPath)
336   - .then(
337   - function (result) {
338   - //debugger;
  346 + // debugger
  347 + $('#daBodyview').css("height", $(window).outerHeight());
339 348  
340   - $rootScope.BodyLayerData = result;
341   - $scope.isBodylayerdataLoaded = true;
  349 + $('#daBodyview').css("width", $(window).outerWidth());
  350 + }
342 351  
343   - //load json for annotations
344   - // $http({ method: 'GET', url: '~/../content/data/json/da_dat_tm_sg_1.json' }).success(function (data) {
345   - $http({ method: 'GET', url: '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json' }).success(function (data) {
346   - $scope.TermNumberData = data;
  352 + angular.element(document).ready(function () {
347 353  
348   - var path = '~/../content/data/json/da/vocab/english/cm_dat_vocabterm_1.json';
349   - $http({ method: 'GET', url: path }).success(function (data) {
350 354  
351   - $scope.VocabTermData = data;
  355 + })
352 356  
353   - var vocabTermTxt = [];
354   - angular.forEach($scope.TermNumberData.TermData.Term, function (value1, key1) {
355   - angular.forEach($scope.VocabTermData.VocabTerms.Term, function (value2, key2) {
356   - //debugger;
357   - if (value1._ActualTermNumber === value2._ActualTermNumber) {
358   - vocabTermTxt.push(
359   - {
360   - "_ActualTermNumber": value2._ActualTermNumber,
361   - "_TermText": value2._TermText,
362   - "_cdId": value2._cdId
363   - }
364   - );
365   - }
366   - })
  357 + $scope.loadLayerDataForCurrentBodyView = function () {
  358 + //1.
  359 + var bgArtJsonPath = '';
  360 + var CommonViewId = 0;
  361 + var currentBodyViewId = localStorage.getItem("currentBodyViewId");
367 362  
368   - })
369 363  
370   - $scope.VocabTermTxt = new jinqJs()
371   - .from(vocabTermTxt)
372   - .distinct('_TermText', '_ActualTermNumber')
373   - .orderBy([{ field: '_TermText', sort: 'asc' }])
374   - .select('_ActualTermNumber', '_TermText', '_cdId');
  364 + //2.
  365 + var layerJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_layer_' + currentBodyViewId + '.json';
  366 + DataService.getAnotherJson(layerJsonPath)
  367 + .then(
  368 + function (result) {
375 369  
376   -
377   - $scope.currentTitleFromJson = localStorage.getItem("currentViewTitleFromJson");
  370 + $rootScope.BodyLayerData = result;
  371 + $scope.isBodylayerdataLoaded = true;
378 372  
379   - })
380   - .error(function (data, status, headers, config) {
381   - console.log(data);
382   - });
383 373  
384   - })
385   - .error(function (data, status, headers, config) {
386   - console.log(data);
387   - });
  374 + //3. load Json for annotation
  375 + $scope.loadTermData();
388 376  
389   -
390 377  
391   - var openViews;
392   -
393   -
394   - // debugger;
395   - if ($rootScope.openViews.length > 0)
396   - {
397   - openViews = new jinqJs()
398   - .from($rootScope.openViews)
399   - .where("BodyViewId==" + currentBodyViewId)
400   - .select();
401   - }
402   - var counter = 1;
403   -
404   - // var tittle = $rootScope.ViewTitle;
405   - var tittle = localStorage.getItem("currentViewTitleFromJson");
406   -
407   - if (openViews != null && openViews!=undefined) {
408   - angular.forEach(openViews, function (value, key) {
409   -
410   - if (value.body - views == tittle) {
411   - tittle = localStorage.getItem("currentViewTitleFromJson") + counter++;
412   - $rootScope.currentActiveViewTitle = tittle;
413   - localStorage.setItem("currentViewTitle", tittle);
414   - }
415   -
416   - });
417   - }
418   - else {
419   - localStorage.setItem("currentViewTitle", tittle);
420   - }
421   -
422   -
423   - $.jsPanel({
424   - id: 'daImagePanel',
425   - selector: '.daBodyView',
426   - theme: 'success',
427   - currentController: 'DAController',
428   - parentSlug: 'da-view-list',
429   - ajax: {
430   - url: 'app/views/da/da-view.html'
431   - },
432   - title: localStorage.getItem("currentViewTitle"),
433   - position: {
434   - top: 70,
435   - left: 1,
436   - },
437   -
438   - size: { width: $(window).outerWidth() - 10, height: $(window).outerHeight() - 110 },
  378 + var openViews;
439 379  
440   - });
441 380  
  381 + if ($rootScope.openViews != null || $rootScope.openViews != undefined) {
  382 + if ($rootScope.openViews.length > 0) {
  383 + openViews = new jinqJs()
  384 + .from($rootScope.openViews)
  385 + .where("BodyViewId==" + currentBodyViewId)
  386 + .select();
  387 + }
  388 + }
  389 + var counter = 1;
442 390  
  391 + //4. getting corresponding body view title
  392 + var tittle = localStorage.getItem("currentViewTitleFromJson");
443 393  
444   - // $rootScope.openViewsDA.push({ "ViewId": 1 });
445   - $rootScope.currentSlug = 'da-body-view';
  394 + if (openViews != null && openViews != undefined) {
  395 + angular.forEach(openViews, function (value, key) {
446 396  
447   - //hide scrollbar
  397 + if (value.body - views == tittle)
  398 + {
  399 + tittle = localStorage.getItem("currentViewTitleFromJson") + counter++;
  400 + $rootScope.currentActiveViewTitle = tittle;
  401 + localStorage.setItem("currentViewTitle", tittle);
  402 + }
448 403  
  404 + });
  405 + }
  406 + else {
  407 + localStorage.setItem("currentViewTitle", tittle);
  408 + }
449 409  
450   - $rootScope.openViews.push(
451   - {
452   - "module": $rootScope.currentActiveModuleTitle, "body-views": tittle, "state": 'max', "BodyViewId": $rootScope.currentBodyViewId,
453   - "slug": $rootScope.currentSlug
454   - }
455   - );
456   - // debugger;
  410 + //5. adding jsPannel on daBodyviewElement.
  411 + $.jsPanel({
  412 + id: 'daImagePanel',
  413 + selector: '.daBodyView',
  414 + theme: 'success',
  415 + currentController: 'DAController',
  416 + parentSlug: 'da-view-list',
  417 + ajax: {
  418 + url: 'app/views/da/da-view.html'
  419 + },
  420 + title: localStorage.getItem("currentViewTitle"),
  421 + position: {
  422 + top: 70,
  423 + left: 1,
  424 + },
  425 +
  426 + size: { width: $(window).outerWidth() - 10, height: $(window).outerHeight() - 110 },
457 427  
458   - var e1 = angular.element(document.getElementById("daBodyview"));
459   - $timeout(function () { $compile(e1.contents())($scope) }, 250);
460   - // $compile(e1.contents())($scope);
  428 + });
461 429  
462   - $('#daBodyview').css("height", $(window).outerHeight());
  430 + //5.1
  431 + $rootScope.currentSlug = 'da-body-view';
463 432  
464   - $('#daBodyview').css("width", $(window).outerWidth());
  433 + //5.2
  434 + $rootScope.openViews.push(
  435 + {
  436 + "module": $rootScope.currentActiveModuleTitle, "body-views": tittle, "state": 'max', "BodyViewId": $rootScope.currentBodyViewId,
  437 + "slug": $rootScope.currentSlug
  438 + }
  439 + );
  440 +
  441 + //5.3
  442 + var daBodyviewElement = angular.element(document.getElementById("daBodyview"));
465 443  
466   - // debugger
467   - if ($scope.isBodylayerdataLoaded) {
468   - $timeout(function () {
  444 + $timeout(function () { $compile(daBodyviewElement.contents())($scope) }, 250);
469 445  
470   - //1.this is for showing termlist on da-view
471   - $scope.isVisibleTermddl = false;
  446 +
  447 + //5.4 added some stylesheets
  448 + $('#daBodyview').css("height", $(window).outerHeight());
472 449  
473   - //2. Load Canvas Image
474   - $scope.LoadDefaultLayerImage();
  450 + $('#daBodyview').css("width", $(window).outerWidth());
475 451  
476   - //3. Load Navigator Image
477   - $scope.LoadBodyViewNavigatorImage();
  452 +
  453 + if ($scope.isBodylayerdataLoaded == true) {
  454 + $timeout(function () {
478 455  
479   - }, 350);
480   - }
481   - },
482   - function (error) {
483   - // handle errors here
484   - console.log(' $rootScope.BodyLayerData= ' + error.statusText);
485   - }
486   - );
487   - },
488   - function (error) {
489   - // handle errors here
490   - console.log(' $rootScope.BodyRegionData = ' + error.statusText);
491   - }
492   - );
  456 + //1.this is for showing termlist on da-view
  457 + $scope.isVisibleTermddl = false;
493 458  
494   - // debugger
495   - $('#daBodyview').css("height", $(window).outerHeight());
  459 + //2. Load Canvas Image
  460 + $scope.LoadDefaultLayerImage();
  461 +
  462 + //3. Load Navigator Image
  463 + $scope.LoadBodyViewNavigatorImage();
  464 +
  465 + }, 350);
  466 + }
  467 + },
  468 + function (error) {
  469 +
  470 + //1.
  471 + console.log('DATA.NOT.LOADED FOR: ' + layerJsonPath +' , ERROR:' + error.statusText);
  472 +
  473 + //2.
  474 + $scope.loadLayerDataForCurrentBodyView();
  475 +
  476 +
  477 + }
  478 + );
496 479  
497   - $('#daBodyview').css("width", $(window).outerWidth());
498 480 }
499 481  
500   - angular.element(document).ready(function () {
501 482  
502 483  
503   - })
  484 + $scope.loadTermData = function () {
  485 + var currentBodyViewId = localStorage.getItem("currentBodyViewId");
  486 +
  487 + var termNoJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json';
  488 + $http({ method: 'GET', url: termNoJsonPath })
  489 + .success(function (data) {
  490 + $scope.TermNumberData = data;
  491 +
  492 + //5.
  493 + $scope.loadTermTextData();
  494 +
  495 + })
  496 + .error(function (data, status, headers, config) {
  497 +
  498 + //1.
  499 + console.log('DATA.NOT.LOADED FOR: ' + termNoJsonPath + ' , ERROR:' + data);
  500 +
  501 + //2.
  502 + $scope.loadTermData();
  503 +
  504 + });
  505 +
  506 + }
  507 +
  508 + $scope.loadTermTextData =function()
  509 + {
  510 + var termTextJsonPath = '~/../content/data/json/da/vocab/english/cm_dat_vocabterm_1.json';
  511 + $http({ method: 'GET', url: termTextJsonPath })
  512 + .success(function (data) {
  513 + $scope.VocabTermData = data;
  514 +
  515 + var vocabTermTxt = [];
  516 + angular.forEach($scope.TermNumberData.TermData.Term, function (value1, key1) {
  517 + angular.forEach($scope.VocabTermData.VocabTerms.Term, function (value2, key2) {
  518 + //debugger;
  519 + if (value1._ActualTermNumber === value2._ActualTermNumber) {
  520 + vocabTermTxt.push(
  521 + {
  522 + "_ActualTermNumber": value2._ActualTermNumber,
  523 + "_TermText": value2._TermText,
  524 + "_cdId": value2._cdId
  525 + }
  526 + );
  527 + }
  528 + })
  529 +
  530 + })
  531 +
  532 + $scope.VocabTermTxt = new jinqJs()
  533 + .from(vocabTermTxt)
  534 + .distinct('_TermText', '_ActualTermNumber')
  535 + .orderBy([{ field: '_TermText', sort: 'asc' }])
  536 + .select('_ActualTermNumber', '_TermText', '_cdId');
  537 +
  538 +
  539 + $scope.currentTitleFromJson = localStorage.getItem("currentViewTitleFromJson");
  540 +
  541 + })
  542 + .error(function (data, status, headers, config) {
  543 +
  544 + //1.
  545 + console.log('DATA.NOT.LOADED FOR:' +termTextJsonPath);
  546 +
  547 + //2.
  548 + $scope.loadTermTextData();
  549 + });
  550 + }
504 551  
505 552 //Code for displaying NavigatorImage for BodyView
506 553 $scope.LoadBodyViewNavigatorImage = function () {
... ... @@ -605,7 +652,9 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
605 652  
606 653  
607 654 //calculate coordinates for body region images
608   - $scope.CalculateImageCordinates = function (viewOrientationId) {
  655 + $scope.CalculateImageCordinates = function (viewOrientationId)
  656 + {
  657 + var drawnBodyRegionCount = [];
609 658  
610 659 if ($rootScope.MaskCanvasData != null || $rootScope.MaskCanvasData != undefined) {
611 660 var n = $rootScope.MaskCanvasData.length;
... ... @@ -4320,7 +4369,7 @@ function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Mo
4320 4369 //2.
4321 4370 $scope.CalculateImageCordinates($scope.viewOrientationId);
4322 4371  
4323   -
  4372 +
4324 4373 }
4325 4374  
4326 4375 //3.
... ...