<commit_before>'use strict';

/* Controllers */

function AppCtrl($scope, $location, $rootScope) {
	
	$scope.q = "";
	$rootScope.title = "";
	$rootScope.subtitle = "";
	
	$rootScope.activePlaces = [];
	
	$scope.$watch("q", function() {
		$location.path('/search').search({q:$scope.q, type: "prefix"});
	});
	
	$scope.submit = function() {
		$location.path('/search').search({q:$scope.q, type: ""});
	};
	
}

function SearchCtrl($scope, $rootScope, $location, $routeParams, Place, messages) {
	
	$rootScope.title = messages["ui.search.results"];
	$rootScope.subtitle = "";
	
	$scope.$watch("total", function() {
		$rootScope.subtitle = $scope.total + " " + messages["ui.search.hits"];
	});
	
	$scope.$watch(("places"), function() {
		$rootScope.activePlaces = $scope.places;
	});
	
	$scope.search = {
		offset: ($routeParams.offset) ? parseInt($routeParams.offset) : 0,
		limit: ($routeParams.limit) ? parseInt($routeParams.limit) : 10,
		q: ($routeParams.q) ? ($routeParams.q) : "",
		type: ($routeParams.type) ? ($routeParams.type) : ""
	};
	
	$scope.places = [];
	$scope.total = 0;
	
	$scope.page = function() {
		return $scope.search.offset / $scope.search.limit + 1;
	};
	
	$scope.totalPages = function() {
		return ($scope.total - ($scope.total % $scope.search.limit)) / $scope.search.limit + 1;
	};
	
	$scope.setLimit = function(limit) {
		$scope.search.limit = limit;
		$scope.search.offset = 0;
		$location.search($scope.search);
		$scope.submit();
	};
	
	$scope.prevPage = function() {
		if ($scope.page() > 1) {
			$scope.search.offset = $scope.search.offset - $scope.search.limit;
			$location.search($scope.search);
			$scope.submit();
		}
	};
	
	$scope.nextPage = function() {
		if ($scope.page() < $scope.totalPages()) {
			$scope.search.offset = $scope.search.offset + $scope.search.limit;
			$location.search($scope.search);
			$scope.submit();
		}
	};
	
	$scope.submit = function() {
		Place.query($scope.search, function(result) {
			$scope.places = result.result;
			if ($scope.total != result.total)
				$scope.total = result.total;
		});
	};
	
	// needed because reloadOnSearch is turned off for this controller
	$scope.$watch(
		function(){ 
			return $location.search().q + $location.search().type;
		},
		function() {
			$scope.search.q = $location.search().q;
			$scope.search.type = $location.search().type;
			$scope.search.offset = 0;
			$scope.submit();
		}
	);
	
	$scope.submit();

}


function PlaceCtrl($scope, $rootScope, $routeParams, Place, $http) {
	
	$scope.location = { confidence: 0 };
	$scope.link = { predicate: "owl:sameAs" };
	$scope.success = false;
	$scope.failure = null;
	
	if ($routeParams.id) {
		$scope.place = Place.get({
			id: $routeParams.id
		}, function(result) {
			if (result.parent) {
				$http.get(result.parent).success(function(result) {<commit_msg>fixed history for searches (closes #272)<commit_after>'use strict';

/* Controllers */

function AppCtrl($scope, $location, $rootScope) {
	
	$scope.q = "";
	$rootScope.title = "";
	$rootScope.subtitle = "";
	
	$rootScope.activePlaces = [];
	
	$scope.$watch("q", function() {
		$location.path('/search').search({q:$scope.q, type: "prefix"});
	});
	
	$scope.submit = function() {
		$location.path('/search').search({q:$scope.q, type: ""});
	};
	
	// needed to keep $scope.q and $location.search().q in sync
	$scope.$watch(
		function(){ 
			return $location.search().q;
		},
		function() {
			$scope.q = $location.search().q;
		}
	);
	
}

function SearchCtrl($scope, $rootScope, $location, $routeParams, Place, messages) {
	
	$rootScope.title = messages["ui.search.results"];
	$rootScope.subtitle = "";
	
	$scope.$watch("total", function() {
		$rootScope.subtitle = $scope.total + " " + messages["ui.search.hits"];
	});
	
	$scope.$watch(("places"), function() {
		$rootScope.activePlaces = $scope.places;
	});
	
	$scope.search = {
		offset: ($routeParams.offset) ? parseInt($routeParams.offset) : 0,
		limit: ($routeParams.limit) ? parseInt($routeParams.limit) : 10,
		q: ($routeParams.q) ? ($routeParams.q) : "",
		type: ($routeParams.type) ? ($routeParams.type) : ""
	};
	
	$scope.places = [];
	$scope.total = 0;
	
	$scope.page = function() {
		return $scope.search.offset / $scope.search.limit + 1;
	};
	
	$scope.totalPages = function() {
		return ($scope.total - ($scope.total % $scope.search.limit)) / $scope.search.limit + 1;
	};
	
	$scope.setLimit = function(limit) {
		$scope.search.limit = limit;
		$scope.search.offset = 0;
		$location.search($scope.search);
	};
	
	$scope.prevPage = function() {
		if ($scope.page() > 1) {
			$scope.search.offset = $scope.search.offset - $scope.search.limit;
			$location.search($scope.search);
		}
	};
	
	$scope.nextPage = function() {
		if ($scope.page() < $scope.totalPages()) {
			$scope.search.offset = $scope.search.offset + $scope.search.limit;
			console.log("nextPage",$scope.search);
			$location.search($scope.search);
		}
	};
	
	$scope.submit = function() {
		console.log("submit",$scope.search);
		Place.query($scope.search, function(result) {
			$scope.places = result.result;
			if ($scope.total != result.total)
				$scope.total = result.total;
		});
	};
	
	// needed to keep $scope.search and $location.search() in sync
	// because reloadOnSearch is turned off for this controller
	$scope.$watch(
		function(){ 
			return JSON.stringify($location.search());
		},
		function() {
			$scope.search = {
				offset: ($location.search().offset) ? parseInt($location.search().offset) : 0,
				limit: ($location.search().limit) ? parseInt($location.search().limit) : 10,
				q: ($location.search().q) ? ($location.search().q) : "",
				type: ($location.search().type) ? ($location.search().type) : ""
			};
			$scope.submit();
		}
	);

}


function PlaceCtrl($scope, $rootScope, $routeParams, Place, $http) {
	
	$scope.location = { confidence: 0 };
	$scope.link = { predicate: "owl:sameAs" };
	$scope.success = false;
	$scope.failure = null;
	
	if ($routeParams.id) {
		$scope.place = Place.get({
			id: $routeParams.id
		}, function(result) {
			if (result.parent) {
				$http.get(result.parent).success(function(result) {
{'fraction_non_alphanumeric': 0.20670391061452514, 'fraction_numerical': 0.004107788366743345, 'mean_word_length': 3.770376175548589, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3215254', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2085, 'n_words': 351}