<commit_before>'use strict';

app.controller('PermitsCtrl', function ($scope, RequestFactory, $routeParams, $http, $rootScope) {

  $scope.permits = RequestFactory.query();

  $scope.permitInfo = function(field) {
    var perm_ids = {}, permits = [], permit;
    for(var i = 0, l = $scope.permits.length; i < l; ++i){
      permit = $scope.permits[i][field];
      if(!perm_ids.hasOwnProperty(permit)) {
        permits.push(permit);
        perm_ids[permit] = 1;
      }
    }
    return permits;
  };

  var permitId = ($routeParams.permitId || $scope.permits[0]);
  $scope.permitId = permitId;
  $scope.selectObs = function(id) {
    var marker = $scope.markers[id];
    if (marker) {
        $scope.center.lat = marker.lat;
        $scope.center.lng = marker.lng;
        $scope.center.zoom = 8;
    }
  };
  $scope.observations = RequestFactory.query(
    {'query': '{"general/perm_num": "' + permitId + '"}'},
    function(res) {
        for (var i = res.length - 1; i >= 0; i--) {
            var point = res[i];
            var lat = parseFloat(point._geolocation[0]);
            var lng = parseFloat(point._geolocation[1]);
            if (lat && lng) {
                $scope.markers[point._id] = {
                    lat: lat,
                    lng: lng,
                    message: point["general/perm_num"] + "<br>" + point["general/obs_date"],
                    focus: false,
                    draggable: false
                };
            }
        }
    }
  );

  $scope.permits = RequestFactory.query(
    {},
    function(response) {
      $scope.permit_attrs = {};
      $scope.permit_attr_list = [];
      for (var i = 0; i < response.length; i++) {
        if (response[i]['general/perm_num'] == permitId) {
          $scope.permit_attrs = response[i];
          // var obj = response[i];
          for (var key in $scope.permit_attrs) {
            if ($scope.permit_attrs.hasOwnProperty(key)){
              $scope.permit_attr_list.push([key, $scope.permit_attrs[key]]);
            }
          }
          break;
        }
      }
    }
  );


  $scope.getForm = function () {
      $http.get($rootScope.baseUrl + '/' + $rootScope.userId + '/forms/' + $rootScope.formId + '/form.json').success(function (data) {
          return JSON.parse(data);
      }).error(function (data) {
          if (console) { console.log('Error getting the survey form.'); }  
      });
  };

  $scope.form = $scope.getForm();

  $scope.center = {
    lat: 60.095,
    lng: -153.823,
    zoom: 3
  };
  
  $scope.markers = {};
  
  $scope.tiles = {
    url: "http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}",<commit_msg>fixing JSON form request handling<commit_after>'use strict';

app.controller('PermitsCtrl', function ($scope, RequestFactory, $routeParams, $http, $rootScope) {

  $scope.permits = RequestFactory.query();

  $scope.permitInfo = function(field) {
    var perm_ids = {}, permits = [], permit;
    for(var i = 0, l = $scope.permits.length; i < l; ++i){
      permit = $scope.permits[i][field];
      if(!perm_ids.hasOwnProperty(permit)) {
        permits.push(permit);
        perm_ids[permit] = 1;
      }
    }
    return permits;
  };

  var permitId = ($routeParams.permitId || $scope.permits[0]);
  $scope.permitId = permitId;
  $scope.selectObs = function(id) {
    var marker = $scope.markers[id];
    if (marker) {
        $scope.center.lat = marker.lat;
        $scope.center.lng = marker.lng;
        $scope.center.zoom = 8;
    }
  };
  $scope.observations = RequestFactory.query(
    {'query': '{"general/perm_num": "' + permitId + '"}'},
    function(res) {
        for (var i = res.length - 1; i >= 0; i--) {
            var point = res[i];
            var lat = parseFloat(point._geolocation[0]);
            var lng = parseFloat(point._geolocation[1]);
            if (lat && lng) {
                $scope.markers[point._id] = {
                    lat: lat,
                    lng: lng,
                    message: point["general/perm_num"] + "<br>" + point["general/obs_date"],
                    focus: false,
                    draggable: false
                };
            }
        }
    }
  );

  $scope.permits = RequestFactory.query(
    {},
    function(response) {
      $scope.permit_attrs = {};
      $scope.permit_attr_list = [];
      for (var i = 0; i < response.length; i++) {
        if (response[i]['general/perm_num'] == permitId) {
          $scope.permit_attrs = response[i];
          // var obj = response[i];
          for (var key in $scope.permit_attrs) {
            if ($scope.permit_attrs.hasOwnProperty(key)){
              $scope.permit_attr_list.push([key, $scope.permit_attrs[key]]);
            }
          }
          break;
        }
      }
    }
  );


  $scope.getForm = function () {
      $http.get($rootScope.baseUrl + '/' + $rootScope.userId + '/forms/' + $rootScope.formId + '/form.json').success(function (data) {
          return data;
      }).error(function (data) {
          if (console) { console.log('Error getting the survey form.'); }  
      });
  };

  $scope.form = $scope.getForm();

  $scope.center = {
    lat: 60.095,
    lng: -153.823,
    zoom: 3
  };
  
  $scope.markers = {};
  
  $scope.tiles = {
    url: "http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}",
{'fraction_non_alphanumeric': 0.16685267857142858, 'fraction_numerical': 0.0078125, 'mean_word_length': 2.017396184062851, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 7, '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': '7052992', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1773, 'n_words': 309}