<commit_before>'use strict';

/* Controllers */

angular.module('myApp.controllers', []);

var geneHiveControllers = angular.module('geneHiveControllers', []); 
geneHiveControllers.controller('JobRunListCtrl', ['$scope','$http', function($scope,$http) {
    $scope.cachedServerData = null;
    $scope.refreshData=function() {
	$scope.cachedServerData = null;
       if (!$scope.$$phase) {
            $scope.$apply();
        }
	$http.get('/GeneHive/api/v2/JobRuns/').success(function (data) {
	    $scope.cachedServerData = data;
	    $scope.setPagingData($scope.pagingOptions.currentPage,$scope.pagingOptions.pageSize);
	})};
    $scope.totalServerItems = 0;
    $scope.pagingOptions = {
        pageSizes: [250, 500, 1000],
        pageSize: 250,
        currentPage: 1
    };	
    $scope.setPagingData = function(page, pageSize){	
        var pagedData = $scope.cachedServerData.slice((page - 1) * pageSize, page * pageSize);
        $scope.myData = pagedData;
        $scope.totalServerItems = data.length;
        if (!$scope.$$phase) {
            $scope.$apply();
        }
    };
    $scope.$watch('pagingOptions', function (newVal, oldVal) {
        if (newVal !== oldVal) {
          $scope.setPagingData($scope.pagingOptions.currentPage, $scope.pagingOptions.pageSize);
        }
    }, true);

$scope.selectedJobRun = [];	
    $scope.gridOptions = {
        data: 'myData',
        enablePaging: true,
		showFooter: true,
        totalServerItems: 'totalServerItems',
        pagingOptions: $scope.pagingOptions,
        filterOptions: $scope.filterOptions,
        columnDefs: [{field:'id', displayName:'ID',width: 30},
        {field:"inputs.name[0]", displayName:'Name'},
        			  {field:'creator', displayName:'Creator'},
        			  {field:'jobType', displayName:'Job Type'},
                     {field:'runDatetime',displayName:'Run Date'}, 
                     {field:'status',displayName:'Status',cellTemplate: '<div ng-class="{green: row.getProperty(col.field) ==\'COMPLETE\'}"><div class="ngCellText">{{row.getProperty(col.field)}}</div></div>'}],
        <commit_msg>Sort is now called external to grid so it takes priority over slice<commit_after>'use strict';

/* Controllers */

angular.module('myApp.controllers', []);

var geneHiveControllers = angular.module('geneHiveControllers', []); 
geneHiveControllers.controller('JobRunListCtrl', ['$scope','$http','$sortService', function($scope,$http,$sortService) {
    $scope.cachedServerData = null;
    $scope.refreshData=function() {
	$scope.cachedServerData = null;
       if (!$scope.$$phase) {
            $scope.$apply();
        }
	$http.get('/GeneHive/api/v2/JobRuns/').success(function (data) {
	    $scope.cachedServerData = data;
	    $scope.setPagingData();
	})};
    $scope.totalServerItems = 0;
    $scope.pagingOptions = {
        pageSizes: [250, 500, 1000],
        pageSize: 250,
        currentPage: 1
    };	
    $scope.sortInfo = { fields: [], columns: [], directions: [] }
    $scope.setPagingData = function(page, pageSize){
	if($scope.cachedServerData==null)
	{
	    return;
	}
	var page = $scope.pagingOptions.currentPage;
	var pageSize = $scope.pagingOptions.pageSize;
	$sortService.Sort($scope.sortInfo,$scope.cachedServerData);
        var pagedData = $scope.cachedServerData.slice((page - 1) * pageSize, page * pageSize);
        $scope.myData = pagedData;
        $scope.totalServerItems = $scope.cachedServerData.length;
        if (!$scope.$$phase) {
            $scope.$apply();
        }
    };
    $scope.$watch('pagingOptions', function (newVal, oldVal) {
        $scope.setPagingData();
    }, true);
    $scope.$watch('sortInfo', function(newVal, oldVal) {
	console.log("sortInfo watch fired");
	$scope.setPagingData();
    }, true);
    $scope.$on('ngGridEventSorted', function(newSort) {
	console.log("grid sort event fired");
    });

$scope.selectedJobRun = [];	
    $scope.gridOptions = {
        data: 'myData',
        enablePaging: true,
		showFooter: true,
	useExternalSorting: true,
        totalServerItems: 'totalServerItems',
	sortInfo: $scope.sortInfo,
        pagingOptions: $scope.pagingOptions,
        filterOptions: $scope.filterOptions,
        columnDefs: [{field:'id', displayName:'ID',width: 30},
        {field:"inputs.name[0]", displayName:'Name'},
        			  {field:'creator', displayName:'Creator'},
        			  {field:'jobType', displayName:'Job Type'},
                     {field:'runDatetime',displayName:'Run Date'}, 
                     {field:'status',displayName:'Status',cellTemplate: '<div ng-class="{green: row.getProperty(col.field) ==\'COMPLETE\'}"><div class="ngCellText">{{row.getProperty(col.field)}}</div></div>'}],
{'fraction_non_alphanumeric': 0.16890881913303438, 'fraction_numerical': 0.008541533205210335, 'mean_word_length': 3.3011937557392104, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1639649', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1461, 'n_words': 227}