<commit_before>app.controller('FilterCtrl', [
  '$scope',
  '$modal',
  '$http',
  'Filter',
  FilterCtrl]);

function FilterCtrl($scope, $modal, $http, Filter) {
  $scope.filter = Filter;

  // Find a type's corresponding data
  function get_type_data(type) {
    var res = null;
    angular.forEach($scope.filter.types_map, function(val, key) {
      if( type === key ) {
        res = val;
        return;
      }
    });
    return res;
  }

  $scope.open = function(type) {
    // Get the filter data
    var data = get_type_data(type);
    console.debug('open("' + type + '")', data);
    if( data === null ) {
      console.error('Received bad filter type');
      return;
    }
    // Re-inject the name of the filter
    data.name = type;
    // Inject the global filter value
    data.model = $scope.filter.filters[data.name];
    // Set up the $modal parameters
    var modalInstance = $modal.open({
      // Use a general template
      templateUrl: 'enrollment-filter',
      // Pass in parameters to the modal
      resolve: {
        data: function(){ return data; },
        Filter: function() { return Filter; }
      },
      // Modal controller
      controller: function($scope, $modalInstance, data, Filter) {
        $scope.data = data;
        $scope.filters = Filter.filters;
        // OK, accept button callback (store state)
        $scope.ok = function() {
          console.debug('Modal closed', $scope.data);
          $modalInstance.close($scope.data);
        };
        // Cancel, exit button callback (no action)
        $scope.cancel = function() {
          console.debug('Modal cancelled', $scope.data);
          $scope.filters[$scope.data.name] = null;
          $modalInstance.dismiss('cancel');
        };
      }
    });
    // Modal close callback
    modalInstance.result.then(function(data) {
      console.debug('Modal closed callback', data);
      $scope.filter.filters[data.name] = data.model;

      $http.get('https://maps.googleapis.com/maps/api/geocode/json?' +
                'key=<KEY>' +
                'address=' + data.model.zip
      ).then(function(res) {
        $scope.filter.filters[data.name].position = [
          res.data.results[0].geometry.location.lat,
          res.data.results[0].geometry.location.lng
        ];
      }, function(res) {
        console.error('Error getting coordinates for Zip code', res);
      });


    });
  };
}<commit_msg>Generalizing iface<commit_after>app.controller('FilterCtrl', [
  '$scope',
  '$modal',
  '$http',
  'Filter',
  FilterCtrl]);

function FilterCtrl($scope, $modal, $http, Filter) {
  $scope.filter = Filter;

  // Find a type's corresponding data
  function get_type_data(type) {
    var res = null;
    angular.forEach($scope.filter.types_map, function(val, key) {
      if( type === key ) {
        res = val;
        return;
      }
    });
    return res;
  }

  $scope.open = function(type) {
    // Get the filter data
    var data = get_type_data(type);
    console.debug('open("' + type + '")', data);
    if( data === null ) {
      console.error('Received bad filter type');
      return;
    }
    // Re-inject the name of the filter
    data.name = type;
    // Inject the global filter value
    data.model = $scope.filter.filters[data.name];
    // Set up the $modal parameters
    var modalInstance = $modal.open({
      // Use a general template
      templateUrl: 'enrollment-filter',
      // Pass in parameters to the modal
      resolve: {
        data: function(){ return data; },
        Filter: function() { return Filter; }
      },
      // Modal controller
      controller: function($scope, $modalInstance, data, Filter) {
        $scope.data = data;
        $scope.filters = Filter.filters;
        // OK, accept button callback (store state)
        $scope.ok = function() {
          console.debug('Modal closed', $scope.data);
          $modalInstance.close($scope.data);
        };
        // Cancel, exit button callback (no action)
        $scope.cancel = function() {
          console.debug('Modal cancelled', $scope.data);
          $scope.filters[$scope.data.name] = null;
          $modalInstance.dismiss('cancel');
        };
      }
    });
    // Modal close callback
    modalInstance.result.then(function(data) {
      console.debug('Modal closed callback', data);
      $scope.filter.filters[data.name] = data.model;

      if( data.type === 'location' && data.model && data.model.zip ) {
        $http.get('https://maps.googleapis.com/maps/api/geocode/json?' +
                  'key=<KEY>&' +
                  'address=' + data.model.zip
        ).then(function(res) {
          $scope.filter.filters[data.name].position = [
            res.data.results[0].geometry.location.lat,
            res.data.results[0].geometry.location.lng
          ];
        }, function(res) {
          console.error('Error getting coordinates for Zip code', res);
        });
      }
    });
  };
}
{'fraction_non_alphanumeric': 0.14958560743885183, 'fraction_numerical': 0.0008085708510208206, 'mean_word_length': 2.1943189154293092, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5222337', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1439, 'n_words': 328}