<commit_before>'use strict';
angular.module('app').controller('LayoutController', ['$scope', '$uibModal', 'ngTableParams', 'CrimeService', 'VacantService', function($scope, $uibModal, NgTableParams, CrimeService, VacantService) {

	var defaultPageNumber = 0;
	var defaultPerPage = 0;
	
    var vacantsComplete = false;
    var crimesComplete = false;
	$scope.overlayClass = 'overlay';
	
	$scope.crimes = [];
	$scope.vacants = [];

	// Set dashboard controls
	$scope.availableDashboardSelections = ['Frequency Chart', 'Adjacency Matrix'];
	$scope.dashboardSelection = $scope.availableDashboardSelections[0];
	
	// Set table controls
	$scope.availableTableSelections = ['crimes', 'vacants'];
	$scope.tableSelection = $scope.availableTableSelections[0];
	$scope.isGridTableOpen = true;
	
	// Pre-populate Crimes and Vacants from database
	listCrimes(defaultPageNumber, defaultPerPage);
	listVacants(defaultPageNumber, defaultPerPage);
	
	// Parameters for table
	$scope.tableParams = {
			crimes: new NgTableParams({}, {}),
			vacants: new NgTableParams({}, {})
	}
	
	$scope.collapsed = { dataset: false, dashboard: false };
	/*
	 * Visualization Specific Properties
	 */
	$scope.bubblechartKeys = {
			crimes: ['description', 'weapon', 'district', 'neighborhood'],
			vacants: ['neighborhood', 'policeDistrict']
	};

	// Initialize visualization scope variables
	$scope.currentBubbleChartKey = { crimes: $scope.bubblechartKeys.crimes[0], vacants: $scope.bubblechartKeys.vacants[0] };	
	$scope.adjacencyKeyX = { crimes: $scope.bubblechartKeys.crimes[0], vacants: $scope.bubblechartKeys.vacants[0] };
	$scope.adjacencyKeyY = { crimes: $scope.bubblechartKeys.crimes[1], vacants: $scope.bubblechartKeys.vacants[1] };
	
    function listCrimes(pageNumber, perPage){
        CrimeService.listCrimes(pageNumber, perPage)
            .then(
            function(d) {
            	$scope.crimes = d;
            	$scope.tableParams.crimes = new NgTableParams({}, { dataset: $scope.crimes });
            	crimesComplete = true;
            	removeOverlayWhenComplete();
            },
            function(errResponse){
                console.error('Error while fetching Crimes');
            }
        );
    }
 
    function listVacants(pageNumber, perPage){
        VacantService.listVacants(pageNumber, perPage)
            .then(
            function(d) {
            	$scope.vacants = d;
            	$scope.tableParams.vacants = new NgTableParams({}, { dataset: $scope.vacants });
            	vacantsComplete = true;
            	removeOverlayWhenComplete();
            },
            function(errResponse){
                console.error('Error while fetching Vacants');
            }
        );
    }
    
    function updateTableParams(){
    	$scope.tableParams = new NgTableParams({}, { dataset: $scope.crimes });
    }
    
    // When vacants and crimes are complete, remove overlay
    function removeOverlayWhenComplete(){
    	if(vacantsComplete && crimesComplete){
    		$scope.overlayClass = '';
    	}
    }
    
    $scope.openDataModal = function(){
        var modalInstance = $uibModal.open({
            ariaLabelledBy: 'modal-title',
            ariaDescribedBy: 'modal-body',
            templateUrl: './resources/static/partials/data_table.html',
            controller: 'LayoutController',
            size: 'lg'
          });
    }
    
    $scope.openAboutModal = function(){
        var modalInstance = $uibModal.open({
            ariaLabelledBy: 'modal-title',
            ariaDescribedBy: 'modal-body',
            templateUrl: './resources/static/partials/about.html',
            controller: 'LayoutController',
            controller: function($scope, $uibModalInstance) {
                $scope.ok = function () {
                	$uibModalInstance.dismiss('cancel');
                }
            }
          });
    }
}]);<commit_msg>Data is now loaded via Angular promise<commit_after>'use strict';
angular.module('app').controller('LayoutController', ['$scope', '$q', '$uibModal', 'ngTableParams', 'CrimeService', 'VacantService', function($scope, $q, $uibModal, NgTableParams, CrimeService, VacantService) {

	var defaultPageNumber = 0;
	var defaultPerPage = 0;
	
    var vacantsComplete = false;
    var crimesComplete = false;
	$scope.overlayClass = 'overlay';
	
	$scope.crimes = [];
	$scope.vacants = [];

	// Set dashboard controls
	$scope.availableDashboardSelections = ['Frequency Chart', 'Adjacency Matrix'];
	$scope.dashboardSelection = $scope.availableDashboardSelections[0];
	
	// Set table controls
	$scope.availableTableSelections = ['crimes', 'vacants'];
	$scope.tableSelection = $scope.availableTableSelections[0];
	$scope.isGridTableOpen = true;
	
	// Parameters for table
	$scope.tableParams = {
			crimes: new NgTableParams({}, {}),
			vacants: new NgTableParams({}, {})
	}
	
	$scope.collapsed = { dataset: false, dashboard: false };
	/*
	 * Visualization Specific Properties
	 */
	$scope.bubblechartKeys = {
			crimes: ['description', 'weapon', 'district', 'neighborhood'],
			vacants: ['neighborhood', 'policeDistrict']
	};

	// Initialize visualization scope variables
	$scope.currentBubbleChartKey = { crimes: $scope.bubblechartKeys.crimes[0], vacants: $scope.bubblechartKeys.vacants[0] };	
	$scope.adjacencyKeyX = { crimes: $scope.bubblechartKeys.crimes[0], vacants: $scope.bubblechartKeys.vacants[0] };
	$scope.adjacencyKeyY = { crimes: $scope.bubblechartKeys.crimes[1], vacants: $scope.bubblechartKeys.vacants[1] };
	
    function listAllData(pageNumber, perPage){
    	$q.all([
    	        VacantService.listVacants(pageNumber, perPage), 
    	        CrimeService.listCrimes(pageNumber, perPage)])
    	.then(function(results){
    		$scope.vacants = results[0];
    		$scope.crimes = results[1];
    		removeOverlayWhenComplete();
    	});
    }
    
    function updateTableParams(){
    	$scope.tableParams = new NgTableParams({}, { dataset: $scope.crimes });
    }
    
    // Remove loading overlay
    function removeOverlayWhenComplete(){
    	$scope.overlayClass = '';
    }
    
    $scope.openDataModal = function(){
        var modalInstance = $uibModal.open({
            ariaLabelledBy: 'modal-title',
            ariaDescribedBy: 'modal-body',
            templateUrl: './resources/static/partials/data_table.html',
            controller: 'LayoutController',
            size: 'lg'
          });
    }
    
    $scope.openAboutModal = function(){
        var modalInstance = $uibModal.open({
            ariaLabelledBy: 'modal-title',
            ariaDescribedBy: 'modal-body',
            templateUrl: './resources/static/partials/about.html',
            controller: 'LayoutController',
            controller: function($scope, $uibModalInstance) {
                $scope.ok = function () {
                	$uibModalInstance.dismiss('cancel');
                }
            }
          });
    }
    
	// Pre-populate data from database
	listAllData(defaultPageNumber, defaultPerPage);
}]);
{'fraction_non_alphanumeric': 0.1340028694404591, 'fraction_numerical': 0.0031563845050215206, 'mean_word_length': 2.91849353569421, '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': '7060031', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2033, 'n_words': 373}