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

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

  SpotController.$inject = ['$document', '$ionicModal', '$ionicPopover', '$ionicPopup', '$location', '$log', '$scope',
    '$state', 'FormFactory', 'HelpersFactory', 'MapViewFactory', 'ProjectFactory', 'SpotFactory', 'TagFactory'];

  // This scope is the parent scope for the SpotController that all child SpotController will inherit
  function SpotController($document, $ionicModal, $ionicPopover, $ionicPopup, $location, $log, $scope, $state,
                          FormFactory, HelpersFactory, MapViewFactory, ProjectFactory, SpotFactory, TagFactory) {
    var vm = this;

    // Tags Variables
    vm.addTagModal = {};
    vm.addTagModalTitle = undefined;
    vm.allTags = [];
    vm.allTagsToDisplay = [];
    vm.featureId = undefined;
    vm.featureLevelTags = [];
    vm.featureLevelTagsToDisplay = [];
    vm.selectedType = 'all';
    vm.spotLevelTags = [];
    vm.spotLevelTagsToDisplay = [];
    vm.tags = [];

    // Tags Functions
    vm.addTag = addTag;
    vm.filterTagType = filterTagType;
    vm.filterAllTagsType = filterAllTagsType;
    vm.getNumTaggedFeatures = getNumTaggedFeatures;
    vm.getTagNames = getTagNames;
    vm.getTagTypeLabel = getTagTypeLabel;
    vm.isTagChecked = isTagChecked;
    vm.loadTags = loadTags;
    vm.toggleTagChecked = toggleTagChecked;

    vm.choices = undefined;
    vm.closeModal = closeModal;
    vm.copyThisSpot = copyThisSpot;
    vm.createTag = createTag;
    vm.data = {};
    vm.deleteSpot = deleteSpot;
    vm.getMax = getMax;
    vm.getMin = getMin;
    vm.goBack = goBack;
    vm.goToTag = goToTag;
    vm.isOptionChecked = isOptionChecked;
    vm.loadTab = loadTab;
    vm.popover = {};
    vm.setSelMultClass = setSelMultClass;
    vm.showField = showField;
    vm.showRadius = true;
    vm.showGeologicUnit = true;
    vm.showSurfaceFeature = false;
    vm.showTab = showTab;
    vm.showTrace = false;
    vm.spot = {};
    vm.stateName = $state.current.name;
    vm.submit = submit;
    vm.survey = undefined;
    vm.toggleAcknowledgeChecked = toggleAcknowledgeChecked;
    vm.toggleChecked = toggleChecked;
    vm.validateForm = validateForm;
    vm.viewMap = viewMap;

    activate();

    /**
     * Private Functions
     */

    function activate() {
      $log.log('In SpotController');
      createPopover();

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

      // Cleanup the modal when we're done with it!
      $scope.$on('$destroy', function () {
        vm.addTagModal.remove();
        vm.popover.remove();
      });
    }

    function copyTags(id) {
      _.each(vm.spotLevelTags, function (tag) {
        tag.spots.push(id);
        ProjectFactory.saveTag(tag);
      });

      _.each(vm.featureLevelTags, function (tag) {
        var features = tag.features[vm.spot.properties.id];
        _.each(features, function (featureId) {
          // Samples are omitted from the copy process so don't copy any tags from samples
          var found = _.find(vm.spot.properties.samples, function (sample) {
            return sample.id === featureId;
          });
          if (!found) {
            if (!tag.features[id]) tag.features[id] = [];
            tag.features[id].push(featureId);
          }
        });
        ProjectFactory.saveTag(tag);
      });
    }

    function createPopover() {
      $ionicPopover.fromTemplateUrl('app/spot/spot-popover.html', {
        'scope': $scope
      }).then(function (popover) {
        vm.popover = popover;
      });
    }

    // Set the current spot
    function setSpot(id) {
      SpotFactory.setCurrentSpotById(id);
      vm.spot = SpotFactory.getCurrentSpot();

      if (TagFactory.getActiveTagging()) TagFactory.addToActiveTags(vm.spot.properties.id);
      if (SpotFactory.getActiveNesting()) SpotFactory.addSpotToActiveNest(vm.spot);

      // Convert date string to Date type
      vm.spot.properties.date = new Date(vm.spot.properties.date);
      vm.spot.properties.time = new Date(vm.spot.properties.time);

      vm.spotTitle = vm.spot.properties.name;
      vm.spots = SpotFactory.getActiveSpots();

      if (vm.stateName === 'app.spotTab.spot') vm.data = vm.spot.properties;

      $log.log('Spot loaded: ', vm.spot);
    }

    /**
     * Public Functions
     */

    function addTag(feature) {
      vm.featureId = (feature) ? feature.id : undefined;
      filterAllTagsType();
      vm.addTagModal.show();
    }

    // Create a new spot with the details from this spot
    function copyThisSpot() {
      vm.popover.hide();
      var newSpot = {'type': 'Feature'};
      newSpot.properties = _.omit(vm.spot.properties,
        ['name', 'id', 'date', 'time', 'modified_timestamp', 'images', 'samples', 'inferences']);
      SpotFactory.setNewSpot(newSpot).then(function (id) {
        submit('/app/spotTab/' + id + '/spot');
        copyTags(id);
      });
    }

    function closeModal(modal) {
      vm[modal].hide();
    }

    function createTag() {
      vm.addTagModal.hide();
      var id = HelpersFactory.getNewId();
      vm.submit('/app/tags/' + id);
    }

    // Delete the spot
    function deleteSpot() {
      if (SpotFactory.isSafeDelete(vm.spot)) {
        var confirmPopup = $ionicPopup.confirm({
          'title': 'Delete Spot',
          'template': 'Are you sure you want to delete this spot?'
        });
        confirmPopup.then(function (res) {
          if (res) {<commit_msg>don't copy strike, dip_direction, dip, trend, plunge, rake, or rake_calculated when copying a spot with orientation data or associated orientations<commit_after>(function () {
  'use strict';

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

  SpotController.$inject = ['$document', '$ionicModal', '$ionicPopover', '$ionicPopup', '$location', '$log', '$scope',
    '$state', 'FormFactory', 'HelpersFactory', 'MapViewFactory', 'ProjectFactory', 'SpotFactory', 'TagFactory'];

  // This scope is the parent scope for the SpotController that all child SpotController will inherit
  function SpotController($document, $ionicModal, $ionicPopover, $ionicPopup, $location, $log, $scope, $state,
                          FormFactory, HelpersFactory, MapViewFactory, ProjectFactory, SpotFactory, TagFactory) {
    var vm = this;

    // Tags Variables
    vm.addTagModal = {};
    vm.addTagModalTitle = undefined;
    vm.allTags = [];
    vm.allTagsToDisplay = [];
    vm.featureId = undefined;
    vm.featureLevelTags = [];
    vm.featureLevelTagsToDisplay = [];
    vm.selectedType = 'all';
    vm.spotLevelTags = [];
    vm.spotLevelTagsToDisplay = [];
    vm.tags = [];

    // Tags Functions
    vm.addTag = addTag;
    vm.filterTagType = filterTagType;
    vm.filterAllTagsType = filterAllTagsType;
    vm.getNumTaggedFeatures = getNumTaggedFeatures;
    vm.getTagNames = getTagNames;
    vm.getTagTypeLabel = getTagTypeLabel;
    vm.isTagChecked = isTagChecked;
    vm.loadTags = loadTags;
    vm.toggleTagChecked = toggleTagChecked;

    vm.choices = undefined;
    vm.closeModal = closeModal;
    vm.copyThisSpot = copyThisSpot;
    vm.createTag = createTag;
    vm.data = {};
    vm.deleteSpot = deleteSpot;
    vm.getMax = getMax;
    vm.getMin = getMin;
    vm.goBack = goBack;
    vm.goToTag = goToTag;
    vm.isOptionChecked = isOptionChecked;
    vm.loadTab = loadTab;
    vm.popover = {};
    vm.setSelMultClass = setSelMultClass;
    vm.showField = showField;
    vm.showRadius = true;
    vm.showGeologicUnit = true;
    vm.showSurfaceFeature = false;
    vm.showTab = showTab;
    vm.showTrace = false;
    vm.spot = {};
    vm.stateName = $state.current.name;
    vm.submit = submit;
    vm.survey = undefined;
    vm.toggleAcknowledgeChecked = toggleAcknowledgeChecked;
    vm.toggleChecked = toggleChecked;
    vm.validateForm = validateForm;
    vm.viewMap = viewMap;

    activate();

    /**
     * Private Functions
     */

    function activate() {
      $log.log('In SpotController');
      createPopover();

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

      // Cleanup the modal when we're done with it!
      $scope.$on('$destroy', function () {
        vm.addTagModal.remove();
        vm.popover.remove();
      });
    }

    function copyTags(id) {
      _.each(vm.spotLevelTags, function (tag) {
        tag.spots.push(id);
        ProjectFactory.saveTag(tag);
      });

      _.each(vm.featureLevelTags, function (tag) {
        var features = tag.features[vm.spot.properties.id];
        _.each(features, function (featureId) {
          // Samples are omitted from the copy process so don't copy any tags from samples
          var found = _.find(vm.spot.properties.samples, function (sample) {
            return sample.id === featureId;
          });
          if (!found) {
            if (!tag.features[id]) tag.features[id] = [];
            tag.features[id].push(featureId);
          }
        });
        ProjectFactory.saveTag(tag);
      });
    }

    function createPopover() {
      $ionicPopover.fromTemplateUrl('app/spot/spot-popover.html', {
        'scope': $scope
      }).then(function (popover) {
        vm.popover = popover;
      });
    }

    // Set the current spot
    function setSpot(id) {
      SpotFactory.setCurrentSpotById(id);
      vm.spot = SpotFactory.getCurrentSpot();

      if (TagFactory.getActiveTagging()) TagFactory.addToActiveTags(vm.spot.properties.id);
      if (SpotFactory.getActiveNesting()) SpotFactory.addSpotToActiveNest(vm.spot);

      // Convert date string to Date type
      vm.spot.properties.date = new Date(vm.spot.properties.date);
      vm.spot.properties.time = new Date(vm.spot.properties.time);

      vm.spotTitle = vm.spot.properties.name;
      vm.spots = SpotFactory.getActiveSpots();

      if (vm.stateName === 'app.spotTab.spot') vm.data = vm.spot.properties;

      $log.log('Spot loaded: ', vm.spot);
    }

    /**
     * Public Functions
     */

    function addTag(feature) {
      vm.featureId = (feature) ? feature.id : undefined;
      filterAllTagsType();
      vm.addTagModal.show();
    }

    // Create a new spot with the details from this spot
    function copyThisSpot() {
      vm.popover.hide();
      var newSpot = {'type': 'Feature'};
      newSpot.properties = _.omit(vm.spot.properties,
        ['name', 'id', 'date', 'time', 'modified_timestamp', 'images', 'samples', 'inferences']);
      _.each(newSpot.properties.orientation_data, function (orientation, i) {
        newSpot.properties.orientation_data[i] = _.omit(orientation,
          ['strike', 'dip_direction', 'dip', 'trend', 'plunge', 'rake', 'rake_calculated']);
        _.each(orientation.associated_orientation, function (associatedOrientation, j) {
          newSpot.properties.orientation_data[i].associated_orientation[j] = _.omit(associatedOrientation,
            ['strike', 'dip_direction', 'dip', 'trend', 'plunge', 'rake', 'rake_calculated']);
        });
      });

      SpotFactory.setNewSpot(newSpot).then(function (id) {
        submit('/app/spotTab/' + id + '/spot');
        copyTags(id);
      });
    }

    function closeModal(modal) {
      vm[modal].hide();
    }

    function createTag() {
      vm.addTagModal.hide();
      var id = HelpersFactory.getNewId();
      vm.submit('/app/tags/' + id);
    }

    // Delete the spot
    function deleteSpot() {
      if (SpotFactory.isSafeDelete(vm.spot)) {
        var confirmPopup = $ionicPopup.confirm({
          'title': 'Delete Spot',
          'template': 'Are you sure you want to delete this spot?'
        });
        confirmPopup.then(function (res) {
          if (res) {
{'fraction_non_alphanumeric': 0.1378194490540989, 'fraction_numerical': 0.0, 'mean_word_length': 2.6624126405347917, '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': '499104', 'n_tokens_mistral': 3760, 'n_tokens_neox': 3610, 'n_words': 743}