<commit_before>(function () {
  'use strict';

  angular
    .module('app')
    .controller('StratSectionController', StratSectionController);

  StratSectionController.$inject = ['$ionicHistory', '$ionicLoading', '$ionicModal', '$ionicPopover', '$ionicPopup',
    '$ionicSideMenuDelegate', '$location', '$log', '$rootScope', '$scope', '$state', '$timeout', 'FormFactory',
    'HelpersFactory', 'MapDrawFactory', 'MapFeaturesFactory', 'MapLayerFactory', 'MapSetupFactory', 'MapViewFactory',
    'ProjectFactory', 'SpotFactory', 'StratSectionFactory', 'IS_WEB'];

  function StratSectionController($ionicHistory, $ionicLoading, $ionicModal, $ionicPopover, $ionicPopup,
                                  $ionicSideMenuDelegate, $location, $log, $rootScope, $scope, $state, $timeout,
                                  FormFactory, HelpersFactory, MapDrawFactory, MapFeaturesFactory, MapLayerFactory,
                                  MapSetupFactory, MapViewFactory, ProjectFactory, SpotFactory, StratSectionFactory,
                                  IS_WEB) {
    var vm = this;

    var currentSpot = {};
    var datasetsLayerStates;
    var map;
    var spotsThisMap = [];
    var stratSection = {};
    var tagsToAdd = [];

    vm.addIntervalModal = {};
    vm.allTags = [];
    vm.clickedFeatureId = undefined;
    vm.data = {};
    vm.grainSizeOptions = {};
    vm.isNesting = SpotFactory.getActiveNesting();
    vm.newNestModal = {};
    vm.newNestProperties = {};
    vm.mapView = true;
    vm.popover = {};
    vm.saveEditsText = 'Save Edits';
    vm.showSaveEditsBtn = false;
    vm.stratSectionIntervals = [];
    vm.thisSpotWithStratSection = {};

    vm.addInterval = addInterval;
    vm.addMoreDetail = addMoreDetail;
    vm.closeModal = closeModal;
    vm.createTag = createTag;
    vm.deleteSpot = deleteSpot;
    vm.getTagNames = getTagNames;
    vm.goBack = goBack;
    vm.goToSpot = goToSpot;
    vm.groupSpots = groupSpots;
    vm.hasRelationships = hasRelationships;
    vm.hasTags = hasTags;
    vm.isiOS = isiOS;
    vm.saveEdits = saveEdits;
    vm.saveInterval = saveInterval;
    vm.stereonetSpots = stereonetSpots;
    vm.switchView = switchView;
    vm.toggleNesting = toggleNesting;
    vm.toggleTagChecked = toggleTagChecked;
    vm.zoomToSpotsExtent = zoomToSpotsExtent;

    activate();

    /**
     * Private Functions
     */

    function activate() {
      $ionicLoading.show({
        'template': '<ion-spinner></ion-spinner><br>Loading Strat Section...'
      });
      $log.log('Loading Strat Section ...');

      // Disable dragging back to ionic side menu because this affects drawing tools
      $ionicSideMenuDelegate.canDragContent(false);

      currentSpot = SpotFactory.getCurrentSpot();
      if (currentSpot) vm.clickedFeatureId = currentSpot.properties.id;

      createModals();
      createPopover();
      createMap();
    }

    function createMap() {
      var switcher = new ol.control.LayerSwitcher();

      gatherSpots();
      var blankStratSection = {'height': 3000, 'width': 2000};
      MapViewFactory.setInitialMapView(blankStratSection);
      MapSetupFactory.setMap();
      MapSetupFactory.setImageOverlays(vm.thisSpotWithStratSection).then(function () {
        MapSetupFactory.setOtherLayers();
        MapSetupFactory.setMapControls(switcher);
        MapSetupFactory.setPopupOverlay();

        MapFeaturesFactory.setMappableSpots(spotsThisMap);

        map = MapSetupFactory.getMap();
        datasetsLayerStates = MapFeaturesFactory.getInitialDatasetLayerStates(map);
        MapFeaturesFactory.createDatasetsLayer(datasetsLayerStates, map);
        MapFeaturesFactory.createFeatureLayer(datasetsLayerStates, map);

        // If we have a current feature set the selected symbol
        if (vm.clickedFeatureId && IS_WEB) {
          var feature = MapFeaturesFactory.getFeatureById(vm.clickedFeatureId);
          if (!_.isEmpty(feature)) MapFeaturesFactory.setSelectedSymbol(map, feature.getGeometry());
        }

        createSwitcher(switcher);

        vm.currentZoom = HelpersFactory.roundToDecimalPlaces(map.getView().getZoom(), 2);
        createMapInteractions();
        createPageEvents();

        $ionicLoading.hide();
        $log.log('Done Loading Strat Section');
        $timeout(function () {
          map.updateSize();         // use OpenLayers API to force map to update
        });
        MapViewFactory.zoomToSpotsExtent(map, spotsThisMap);
      });
    }

    function createMapInteractions() {
      // When the map is moved update the zoom control
      map.on('moveend', function (evt) {
        var mapZoom = HelpersFactory.roundToDecimalPlaces(evt.map.getView().getZoom(), 2);
        if (vm.currentZoom !== mapZoom) {
          vm.currentZoom = mapZoom;
          $scope.$apply();
        }
      });

      map.on('touchstart', function (event) {
        $log.log('touch');
        $log.log(event);
      });

      // display popup on click
      map.on('click', function (evt) {
        //$log.log('map clicked at pixel:', evt.pixel, 'mapcoords:', map.getCoordinateFromPixel(evt.pixel));
        MapFeaturesFactory.removeSelectedSymbol(map);

        // are we in draw mode?  If so we dont want to display any popovers during draw mode
        if (!MapDrawFactory.isDrawMode()) {
          var feature = MapFeaturesFactory.getClickedFeature(map, evt);
          var layer = MapFeaturesFactory.getClickedLayer(map, evt);
          if (feature && feature.get('id') && layer && layer.get('name') !== 'geolocationLayer') {
            vm.clickedFeatureId = feature.get('id');
            if (IS_WEB) {
              MapFeaturesFactory.setSelectedSymbol(map, feature.getGeometry());
              $rootScope.$broadcast('clicked-mapped-spot', {'spotId': vm.clickedFeatureId});
            }
            else MapFeaturesFactory.showMapPopup(feature, evt);
          }
          else vm.clickedFeatureId = undefined;
          $scope.$apply();
        }
      });

      // Draw Map Axes
      map.on('precompose', function (event) {
        if ($state.current.name === 'app.strat-section') {
          var ctx = event.context;
          var pixelRatio = event.frameState.pixelRatio;
          StratSectionFactory.drawAxes(ctx, pixelRatio, stratSection);

          var mapSize = map.getSize();
          var mapExtent = map.getView().calculateExtent(map.getSize());
          // $log.log(mapSize, mapExtent);
        }
      });

      var popup = MapSetupFactory.getPopupOverlay();
      popup.getElement().addEventListener('click', function (e) {
        var action = e.target.getAttribute('data-action');
        if (action) {
          if (action === 'more') {
            popup.hide();
            goToSpot(vm.clickedFeatureId, 'sed-lithologies');
            $scope.$apply();
          }
          e.preventDefault();
        }
      }, false);
    }

    function createModals() {
      $ionicModal.fromTemplateUrl('app/maps/map/add-tag-modal.html', {
        'scope': $scope,
        'animation': 'slide-in-up',
        'backdropClickToClose': false,
        'hardwareBackButtonClose': false
      }).then(function (modal) {
        vm.addTagModal = modal;
      });

      $ionicModal.fromTemplateUrl('app/shared/new-nest-modal.html', {
        'scope': $scope,
        'animation': 'slide-in-up',
        'backdropClickToClose': false,
        'hardwareBackButtonClose': false
      }).then(function (modal) {
        vm.newNestModal = modal;
      });
    }<commit_msg>sed - from map popup only open sed lithologies tab for intervals<commit_after>(function () {
  'use strict';

  angular
    .module('app')
    .controller('StratSectionController', StratSectionController);

  StratSectionController.$inject = ['$ionicHistory', '$ionicLoading', '$ionicModal', '$ionicPopover', '$ionicPopup',
    '$ionicSideMenuDelegate', '$location', '$log', '$rootScope', '$scope', '$state', '$timeout', 'FormFactory',
    'HelpersFactory', 'MapDrawFactory', 'MapFeaturesFactory', 'MapLayerFactory', 'MapSetupFactory', 'MapViewFactory',
    'ProjectFactory', 'SpotFactory', 'StratSectionFactory', 'IS_WEB'];

  function StratSectionController($ionicHistory, $ionicLoading, $ionicModal, $ionicPopover, $ionicPopup,
                                  $ionicSideMenuDelegate, $location, $log, $rootScope, $scope, $state, $timeout,
                                  FormFactory, HelpersFactory, MapDrawFactory, MapFeaturesFactory, MapLayerFactory,
                                  MapSetupFactory, MapViewFactory, ProjectFactory, SpotFactory, StratSectionFactory,
                                  IS_WEB) {
    var vm = this;

    var currentSpot = {};
    var datasetsLayerStates;
    var map;
    var spotsThisMap = [];
    var stratSection = {};
    var tagsToAdd = [];

    vm.addIntervalModal = {};
    vm.allTags = [];
    vm.clickedFeatureId = undefined;
    vm.data = {};
    vm.grainSizeOptions = {};
    vm.isNesting = SpotFactory.getActiveNesting();
    vm.newNestModal = {};
    vm.newNestProperties = {};
    vm.mapView = true;
    vm.popover = {};
    vm.saveEditsText = 'Save Edits';
    vm.showSaveEditsBtn = false;
    vm.stratSectionIntervals = [];
    vm.thisSpotWithStratSection = {};

    vm.addInterval = addInterval;
    vm.addMoreDetail = addMoreDetail;
    vm.closeModal = closeModal;
    vm.createTag = createTag;
    vm.deleteSpot = deleteSpot;
    vm.getTagNames = getTagNames;
    vm.goBack = goBack;
    vm.goToSpot = goToSpot;
    vm.groupSpots = groupSpots;
    vm.hasRelationships = hasRelationships;
    vm.hasTags = hasTags;
    vm.isiOS = isiOS;
    vm.saveEdits = saveEdits;
    vm.saveInterval = saveInterval;
    vm.stereonetSpots = stereonetSpots;
    vm.switchView = switchView;
    vm.toggleNesting = toggleNesting;
    vm.toggleTagChecked = toggleTagChecked;
    vm.zoomToSpotsExtent = zoomToSpotsExtent;

    activate();

    /**
     * Private Functions
     */

    function activate() {
      $ionicLoading.show({
        'template': '<ion-spinner></ion-spinner><br>Loading Strat Section...'
      });
      $log.log('Loading Strat Section ...');

      // Disable dragging back to ionic side menu because this affects drawing tools
      $ionicSideMenuDelegate.canDragContent(false);

      currentSpot = SpotFactory.getCurrentSpot();
      if (currentSpot) vm.clickedFeatureId = currentSpot.properties.id;

      createModals();
      createPopover();
      createMap();
    }

    function createMap() {
      var switcher = new ol.control.LayerSwitcher();

      gatherSpots();
      var blankStratSection = {'height': 3000, 'width': 2000};
      MapViewFactory.setInitialMapView(blankStratSection);
      MapSetupFactory.setMap();
      MapSetupFactory.setImageOverlays(vm.thisSpotWithStratSection).then(function () {
        MapSetupFactory.setOtherLayers();
        MapSetupFactory.setMapControls(switcher);
        MapSetupFactory.setPopupOverlay();

        MapFeaturesFactory.setMappableSpots(spotsThisMap);

        map = MapSetupFactory.getMap();
        datasetsLayerStates = MapFeaturesFactory.getInitialDatasetLayerStates(map);
        MapFeaturesFactory.createDatasetsLayer(datasetsLayerStates, map);
        MapFeaturesFactory.createFeatureLayer(datasetsLayerStates, map);

        // If we have a current feature set the selected symbol
        if (vm.clickedFeatureId && IS_WEB) {
          var feature = MapFeaturesFactory.getFeatureById(vm.clickedFeatureId);
          if (!_.isEmpty(feature)) MapFeaturesFactory.setSelectedSymbol(map, feature.getGeometry());
        }

        createSwitcher(switcher);

        vm.currentZoom = HelpersFactory.roundToDecimalPlaces(map.getView().getZoom(), 2);
        createMapInteractions();
        createPageEvents();

        $ionicLoading.hide();
        $log.log('Done Loading Strat Section');
        $timeout(function () {
          map.updateSize();         // use OpenLayers API to force map to update
        });
        MapViewFactory.zoomToSpotsExtent(map, spotsThisMap);
      });
    }

    function createMapInteractions() {
      // When the map is moved update the zoom control
      map.on('moveend', function (evt) {
        var mapZoom = HelpersFactory.roundToDecimalPlaces(evt.map.getView().getZoom(), 2);
        if (vm.currentZoom !== mapZoom) {
          vm.currentZoom = mapZoom;
          $scope.$apply();
        }
      });

      map.on('touchstart', function (event) {
        $log.log('touch');
        $log.log(event);
      });

      // display popup on click
      map.on('click', function (evt) {
        //$log.log('map clicked at pixel:', evt.pixel, 'mapcoords:', map.getCoordinateFromPixel(evt.pixel));
        MapFeaturesFactory.removeSelectedSymbol(map);

        // are we in draw mode?  If so we dont want to display any popovers during draw mode
        if (!MapDrawFactory.isDrawMode()) {
          var feature = MapFeaturesFactory.getClickedFeature(map, evt);
          var layer = MapFeaturesFactory.getClickedLayer(map, evt);
          if (feature && feature.get('id') && layer && layer.get('name') !== 'geolocationLayer') {
            vm.clickedFeatureId = feature.get('id');
            if (IS_WEB) {
              MapFeaturesFactory.setSelectedSymbol(map, feature.getGeometry());
              $rootScope.$broadcast('clicked-mapped-spot', {'spotId': vm.clickedFeatureId});
            }
            else MapFeaturesFactory.showMapPopup(feature, evt);
          }
          else vm.clickedFeatureId = undefined;
          $scope.$apply();
        }
      });

      // Draw Map Axes
      map.on('precompose', function (event) {
        if ($state.current.name === 'app.strat-section') {
          var ctx = event.context;
          var pixelRatio = event.frameState.pixelRatio;
          StratSectionFactory.drawAxes(ctx, pixelRatio, stratSection);

          var mapSize = map.getSize();
          var mapExtent = map.getView().calculateExtent(map.getSize());
          // $log.log(mapSize, mapExtent);
        }
      });

      var popup = MapSetupFactory.getPopupOverlay();
      popup.getElement().addEventListener('click', function (e) {
        var action = e.target.getAttribute('data-action');
        if (action) {
          if (action === 'more') {
            popup.hide();
            var spot = SpotFactory.getSpotById(vm.clickedFeatureId);
            if (spot.properties.surface_feature &&
              spot.properties.surface_feature.surface_feature_type === 'strat_interval') {
              goToSpot(vm.clickedFeatureId, 'sed-lithologies');
            }
            else goToSpot(vm.clickedFeatureId, 'spot');
            $scope.$apply();
          }
          e.preventDefault();
        }
      }, false);
    }

    function createModals() {
      $ionicModal.fromTemplateUrl('app/maps/map/add-tag-modal.html', {
        'scope': $scope,
        'animation': 'slide-in-up',
        'backdropClickToClose': false,
        'hardwareBackButtonClose': false
      }).then(function (modal) {
        vm.addTagModal = modal;
      });

      $ionicModal.fromTemplateUrl('app/shared/new-nest-modal.html', {
        'scope': $scope,
        'animation': 'slide-in-up',
        'backdropClickToClose': false,
        'hardwareBackButtonClose': false
      }).then(function (modal) {
        vm.newNestModal = modal;
      });
    }
{'fraction_non_alphanumeric': 0.12666666666666668, 'fraction_numerical': 0.00130718954248366, 'mean_word_length': 2.6622786022020106, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5827513', 'n_tokens_mistral': 4487, 'n_tokens_neox': 4337, 'n_words': 822}