<commit_before>﻿// Includes shared functions for ExploreController, SearchController, and
// ContextPanelController - handles thumbnail click, right-click, and paging
// behavior

// ToursController does not use this factory

wwt.app.factory('ThumbList', ['$rootScope', 'Util', 'Places', '$timeout', function ($rootScope, util, places, $timeout) {
  var api = {
    init: init,
    clickThumb: clickThumb,
    calcPageSize: calcPageSize,
    spliceOnePage: spliceOnePage,
    goFwd: goFwd,
    goBack: goBack
  };

  // Each controller calls init and passes in the controller
  // scope
  function init(scope, name) {
    scope.pageCount = 1;
    scope.pageSize = 1;
    scope.currentPage = 0;

    scope.preventClickBubble = function (event) {
      event.stopImmediatePropagation();
    };
    scope.goBack = function () {
      goBack(scope);
    };
    scope.goFwd = function () {
      goFwd(scope);
    };
    scope.showMenu = function (i) {
      var item = scope.collectionPage[i];
      item.contextMenuEvent = true;
      $('.popover-content .close-btn').click();
      if (!item.get_isFolder() && item.get_name() !== 'Up Level') {
        var menuContainer = $((name === 'context' ? '.nearby-objects ' : '.top-panel ') + '#menuContainer' + i);
        if (util.isMobile) {
          menuContainer = $('#' + name + 'Container #menuContainer' + i);
        }
        menuContainer.append($('#researchMenu'));
        setTimeout(function () {
          $('.popover-content .close-btn').click();
          menuContainer.find('#researchMenu')
            .addClass('open')
            .off('click')
            .on('click', function (event) {
              event.stopPropagation();
            });
          menuContainer.find('.drop-toggle').click();
          $timeout(function () {
            if (!util.isMobile) {
              $('.dropdown-backdrop').off('contextmenu');
              $('.dropdown-backdrop').on('contextmenu', function (event) {
                $(this).click();
                event.preventDefault();
              });
            }
            scope.setMenuContextItem(item, true);
            item.contextMenuEvent = false;
          }, 10);

        }, 10);
      }
    };

    // toggles the expanded thumbnail view to show 1 or 5 rows of thumbs
    scope.expandThumbnails = function (flag) {
      $('body').append($('#researchMenu'));
      scope.currentPage = 0;
      scope.expanded = flag != undefined ? flag : !scope.expanded;
      scope.expandTop(scope.expanded, name);
      calcPageSize(scope, name === 'context');
    };
    scope.dropdownClass = name === 'context' && !util.isMobile ? 'dropup menu-container' : 'dropdown menu-container';
    scope.popupPosition = name === 'context' && !util.isMobile ? 'top' : 'bottom';
  }

  function clickThumb(item, scope, outParams, callback) {
    if (item.contextMenuEvent) {
      return outParams;
    }
    if (!outParams) {
      outParams = {};
    }
    scope.activeItem = item.get_thumbnailUrl() + item.get_name();
    scope.setActiveItem(item);
    wwt.wc.clearAnnotations();
    if (item.get_name() === 'Up Level') {
      $('body').append($('#researchMenu'));
      scope.currentPage = 0;
      outParams.depth--;
      outParams.breadCrumb.pop();
      scope.breadCrumb = outParams.breadCrumb;
      outParams.cache.pop();
      scope.collection = outParams.cache[outParams.cache.length - 1];
      calcPageSize(scope, false);
      return outParams;
    }
    if (item.get_url && item.get_url() && item.get_url().indexOf('?wwtfull') !== -1) {
      window.open(item.get_url());
      return outParams;
    }
    if (item.get_isFolder()) {
      $('#folderLoadingModal').modal('show');
      $('body').append($('#researchMenu'));
      scope.currentPage = 0;
      outParams.depth++;
      outParams.breadCrumb.push(item.get_name());
      scope.breadCrumb = outParams.breadCrumb;
      places.getChildren(item).then(function (result) {
        $('#folderLoadingModal').modal('hide');
        if ($.isArray(result[0])) {
          result = result[0];
        }
        var unique = [];
        $.each(result, function (index, el) {
          if ($.inArray(el, unique) === -1) unique.push(el);
        });
        scope.collection = unique;
        calcPageSize(scope, false);
        outParams.cache.push(result);
        if (outParams.openCollection) {
          if (outParams.newCollectionUrl) {
            var i = 0;
            while (result[i].url && result[i].url.indexOf(outParams.newCollectionUrl) === -1) i++;

            scope.clickThumb(result[i]);
            outParams.newCollectionUrl = null;
          } else if (result.length) {
            scope.clickThumb(result[0]);
          }
        }

        if (callback) {
          callback();
        }
      });
      return outParams;
    } else if (outParams.openCollection) {
      outParams.openCollection = false;
    } else if (scope.$hide) {
      scope.$hide();
      $rootScope.searchModal = false;
    } else if (util.isMobile) {
      $('#explorerModal').modal('hide');
    }

    if ((item.isFGImage && item.imageSet && scope.lookAt !== 'Sky') || item.isSurvey) {
      if (item.guid && item.guid.toLowerCase().indexOf('mars.') == -1) {
        scope.setLookAt('Sky', item.get_name(), true, item.isSurvey);
      }
      if (item.isSurvey) {
        scope.setSurveyBg(item.get_name(), item);
      } else {
        scope.setForegroundImage(item);
      }
      if (scope.$hide) {
        scope.$hide();
        $rootScope.searchModal = false;
      }
      return outParams;
    }
    else if (item.isPanorama) {
      scope.setLookAt('Panorama', item.get_name());
    } else if (item.isEarth) {
      scope.setLookAt('Earth', item.get_name());
    } else if (util.getIsPlanet(item)) {

      if (scope.lookAt === 'Sky') {
        item._camParams.zoom = 0.1;

        wwtlib.WWTControl.singleton.gotoTarget3(item._camParams);
        if (!item.isPlanet) {
          return outParams;
        }
      } else {
        item._camParam.zoom = 360;
        //c.angle = 360;
      }
      if (scope.lookAt !== 'SolarSystem') {

        scope.setLookAt('Planet', item._name || '');
      }
    }
    if ((ss.canCast(item, wwtlib.Place) || item.isEarth) && !item.isSurvey) {
      scope.setForegroundImage(item);
    }
    if (ss.canCast(item, wwtlib.Tour)) {
      scope.playTour(item.get_tourUrl());
    }<commit_msg>Planet/Skymode fixes<commit_after>﻿// Includes shared functions for ExploreController, SearchController, and
// ContextPanelController - handles thumbnail click, right-click, and paging
// behavior

// ToursController does not use this factory

wwt.app.factory('ThumbList', ['$rootScope', 'Util', 'Places', '$timeout', function ($rootScope, util, places, $timeout) {
  var api = {
    init: init,
    clickThumb: clickThumb,
    calcPageSize: calcPageSize,
    spliceOnePage: spliceOnePage,
    goFwd: goFwd,
    goBack: goBack
  };

  // Each controller calls init and passes in the controller
  // scope
  function init(scope, name) {
    scope.pageCount = 1;
    scope.pageSize = 1;
    scope.currentPage = 0;

    scope.preventClickBubble = function (event) {
      event.stopImmediatePropagation();
    };
    scope.goBack = function () {
      goBack(scope);
    };
    scope.goFwd = function () {
      goFwd(scope);
    };
    scope.showMenu = function (i) {
      var item = scope.collectionPage[i];
      item.contextMenuEvent = true;
      $('.popover-content .close-btn').click();
      if (!item.get_isFolder() && item.get_name() !== 'Up Level') {
        var menuContainer = $((name === 'context' ? '.nearby-objects ' : '.top-panel ') + '#menuContainer' + i);
        if (util.isMobile) {
          menuContainer = $('#' + name + 'Container #menuContainer' + i);
        }
        menuContainer.append($('#researchMenu'));
        setTimeout(function () {
          $('.popover-content .close-btn').click();
          menuContainer.find('#researchMenu')
            .addClass('open')
            .off('click')
            .on('click', function (event) {
              event.stopPropagation();
            });
          menuContainer.find('.drop-toggle').click();
          $timeout(function () {
            if (!util.isMobile) {
              $('.dropdown-backdrop').off('contextmenu');
              $('.dropdown-backdrop').on('contextmenu', function (event) {
                $(this).click();
                event.preventDefault();
              });
            }
            scope.setMenuContextItem(item, true);
            item.contextMenuEvent = false;
          }, 10);

        }, 10);
      }
    };

    // toggles the expanded thumbnail view to show 1 or 5 rows of thumbs
    scope.expandThumbnails = function (flag) {
      $('body').append($('#researchMenu'));
      scope.currentPage = 0;
      scope.expanded = flag != undefined ? flag : !scope.expanded;
      scope.expandTop(scope.expanded, name);
      calcPageSize(scope, name === 'context');
    };
    scope.dropdownClass = name === 'context' && !util.isMobile ? 'dropup menu-container' : 'dropdown menu-container';
    scope.popupPosition = name === 'context' && !util.isMobile ? 'top' : 'bottom';
  }

  function clickThumb(item, scope, outParams, callback) {
    if (item.contextMenuEvent) {
      return outParams;
    }
    if (!outParams) {
      outParams = {};
    }
    scope.activeItem = item.get_thumbnailUrl() + item.get_name();
    scope.setActiveItem(item);
    wwt.wc.clearAnnotations();
    if (item.get_name() === 'Up Level') {
      $('body').append($('#researchMenu'));
      scope.currentPage = 0;
      outParams.depth--;
      outParams.breadCrumb.pop();
      scope.breadCrumb = outParams.breadCrumb;
      outParams.cache.pop();
      scope.collection = outParams.cache[outParams.cache.length - 1];
      calcPageSize(scope, false);
      return outParams;
    }
    if (item.get_url && item.get_url() && item.get_url().indexOf('?wwtfull') !== -1) {
      window.open(item.get_url());
      return outParams;
    }
    if (item.get_isFolder()) {
      $('#folderLoadingModal').modal('show');
      $('body').append($('#researchMenu'));
      scope.currentPage = 0;
      outParams.depth++;
      outParams.breadCrumb.push(item.get_name());
      scope.breadCrumb = outParams.breadCrumb;
      places.getChildren(item).then(function (result) {
        $('#folderLoadingModal').modal('hide');
        if ($.isArray(result[0])) {
          result = result[0];
        }
        var unique = [];
        $.each(result, function (index, el) {
          if ($.inArray(el, unique) === -1) unique.push(el);
        });
        scope.collection = unique;
        calcPageSize(scope, false);
        outParams.cache.push(result);
        if (outParams.openCollection) {
          if (outParams.newCollectionUrl) {
            var i = 0;
            while (result[i].url && result[i].url.indexOf(outParams.newCollectionUrl) === -1) i++;

            scope.clickThumb(result[i]);
            outParams.newCollectionUrl = null;
          } else if (result.length) {
            scope.clickThumb(result[0]);
          }
        }

        if (callback) {
          callback();
        }
      });
      return outParams;
    } else if (outParams.openCollection) {
      outParams.openCollection = false;
    } else if (scope.$hide) {
      scope.$hide();
      $rootScope.searchModal = false;
    } else if (util.isMobile) {
      $('#explorerModal').modal('hide');
    }

    if ((item.isFGImage && item.imageSet && scope.lookAt !== 'Sky') || item.isSurvey) {
      if (item.guid && item.guid.toLowerCase().indexOf('mars.') == -1) {
        scope.setLookAt('Sky', item.get_name(), true, item.isSurvey);
      }
      if (item.isSurvey) {
        scope.setSurveyBg(item.get_name(), item);
      } else {
        scope.setForegroundImage(item);
      }
      if (scope.$hide) {
        scope.$hide();
        $rootScope.searchModal = false;
      }
      return outParams;
    }
    else if (item.isPanorama) {
      scope.setLookAt('Panorama', item.get_name());
    } else if (item.isEarth) {
      scope.setLookAt('Earth', item.get_name());
    } else if (util.getIsPlanet(item)) {

      if (scope.lookAt === 'Sky') {
        item._camParams.zoom = 0.1;

        wwtlib.WWTControl.singleton.gotoTarget3(item._camParams);
        return outParams;

      } else {
        item._camParam.zoom = 360;
        //c.angle = 360;
      }
      if (scope.lookAt !== 'SolarSystem') {

        scope.setLookAt('Planet', item._name || '');
      }
    }
    if ((ss.canCast(item, wwtlib.Place) || item.isEarth) && !item.isSurvey) {
      scope.setForegroundImage(item);
    }
    if (ss.canCast(item, wwtlib.Tour)) {
      scope.playTour(item.get_tourUrl());
    }
{'fraction_non_alphanumeric': 0.16038624587847386, 'fraction_numerical': 0.004710315591144607, 'mean_word_length': 2.330457516339869, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2321289', 'n_tokens_mistral': 3973, 'n_tokens_neox': 3883, 'n_words': 721}