<commit_before>(function(app) {

app.controller('TransportationListController', ['$scope', '$http', '$location', function($scope, $http, $location) {

  $scope.provinces = undefined;
  $scope.transportations = undefined;
  $scope.loading = 0;

  $scope.init = function() {
  }

  $scope.$watch('panel', function(value, old) {
    if (value !== 'transportation-list') return;
    $scope.reload();
    $scope.map.editable = false;
    $scope.map.reset();
    $location.path('/');
  });

  $scope.reload = function() {
    $scope.loading++;
    var url = jQuery('body').data('url-transportation-list');
    $http.get(url)
      .success(function(data) {
        $scope.provinces = data.provinces;
        $scope.transportations = data.transportations;
        $scope.loading--;
      });
  };

  var groupByProvince = function(data) {
    var groups = {};
    angular.forEach(data, function(item) {
      if (!groups[item.province]) {
        groups[item.province] = {
          province: item.province,
          transportations: []
        }
      }

      item._label = (item.company ? item.company + ' ' : '') + item.number;
      groups[item.province].transportations.push(item);
    });

    var res = [];
    angular.forEach(groups, function(item, province) {
      res.push(item);
    });

    res = res.sort(function(a, b) {
      return b.transportations.length - a.transportations.length;
    });

    return res;
  }

  $scope.$watch('provinces', function(value) {
    var names = {};
    angular.forEach(value, function(item) {
      names[item[0]] = item[1];
    })
    $scope.provinceName = names;
  });

  $scope.$watch('transportations', function(value) {
    $scope.groups = groupByProvince(value);
  });

  $scope.showTransportation = function(t) {
    // TODO show loading
    var url = jQuery('body').data('url-transportation-data').replace('0', t.id);
    $http.get(url)
      .success(function(data) {
        $scope.data = data;
        $scope.map.info = data.geojson;
        $scope.map.editable = false;
        $scope.map.fitRoutesToBounds = true;
        $scope.map.routes = data.geojson.geometry.coordinates;
      });
  }

  $scope.$on('route-edit-click', function() {
    if ($scope.panel !== 'transportation-list') return;
    $scope.$apply(function() {
      $scope.editTransportation($scope.data.id);
    });
  });

}]);

})(window.angkot.app);
<commit_msg>Login before editing a transportation<commit_after>(function(app) {

app.controller('TransportationListController', ['$scope', '$http', '$location', function($scope, $http, $location) {

  $scope.provinces = undefined;
  $scope.transportations = undefined;
  $scope.loading = 0;

  $scope.init = function() {
  }

  $scope.$watch('panel', function(value, old) {
    if (value !== 'transportation-list') return;
    $scope.reload();
    $scope.map.editable = false;
    $scope.map.reset();
    $location.path('/');
  });

  $scope.reload = function() {
    $scope.loading++;
    var url = jQuery('body').data('url-transportation-list');
    $http.get(url)
      .success(function(data) {
        $scope.provinces = data.provinces;
        $scope.transportations = data.transportations;
        $scope.loading--;
      });
  };

  var groupByProvince = function(data) {
    var groups = {};
    angular.forEach(data, function(item) {
      if (!groups[item.province]) {
        groups[item.province] = {
          province: item.province,
          transportations: []
        }
      }

      item._label = (item.company ? item.company + ' ' : '') + item.number;
      groups[item.province].transportations.push(item);
    });

    var res = [];
    angular.forEach(groups, function(item, province) {
      res.push(item);
    });

    res = res.sort(function(a, b) {
      return b.transportations.length - a.transportations.length;
    });

    return res;
  }

  $scope.$watch('provinces', function(value) {
    var names = {};
    angular.forEach(value, function(item) {
      names[item[0]] = item[1];
    })
    $scope.provinceName = names;
  });

  $scope.$watch('transportations', function(value) {
    $scope.groups = groupByProvince(value);
  });

  $scope.showTransportation = function(t) {
    // TODO show loading
    var url = jQuery('body').data('url-transportation-data').replace('0', t.id);
    $http.get(url)
      .success(function(data) {
        $scope.data = data;
        $scope.map.info = data.geojson;
        $scope.map.editable = false;
        $scope.map.fitRoutesToBounds = true;
        $scope.map.routes = data.geojson.geometry.coordinates;
      });
  }

  $scope.$on('route-edit-click', function() {
    if ($scope.panel !== 'transportation-list') return;
    $scope.$apply(function() {
      $scope.showLogin(function() {
        $scope.editTransportation($scope.data.id);
      });
    });
  });

}]);

})(window.angkot.app);

{'fraction_non_alphanumeric': 0.17883663366336633, 'fraction_numerical': 0.0016501650165016502, 'mean_word_length': 2.845360824742268, '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': '5006410', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1544, 'n_words': 239}