<commit_before>/***
 Hawk Main Script
 ***/
'use strict';

/* Hawk Main Module */
angular
    .module("hawk", [
        "hawk.environmentsManagement",
        "hawk.agentsManagement",
        "hawk.pipelinesManagement",
        "hawk.userManagement",
        "hawk.adminManagement",
        "hawk.profileManagement",
        "hawk.artifactManagement",
        "ui.router",
        'ui.sortable',
        "ui.bootstrap",
        //"oc.lazyLoad",
        //"ngSanitize",
        'luegg.directives',
        'toaster',
        'momentjs',
        'satellizer',
        'ansi_up',
        'ngJsTree'
        //'ngAnimate'
        //'flow'
    ])

    .constant({
        CONSTANTS: {
            'BASE_URL': '/api',
            'SERVER_URL': window.location.origin,
            'HOST': window.location.host,
            'CONFIG': '/config',
            'EXEC': '/exec',
            'STATS': '/stats',
            'PIPELINES': '/pipelines',
            'PIPELINE_GROUPS': "/pipeline_groups",
            'AGENTS': '/agents',
            'STAGES': '/stages',
            'JOBS': '/jobs',
            'TASKS': '/tasks',
            'ARTIFACTS': '/artifacts',
            'MATERIALS': '/materials',
            'SERVER': '/server',
            'ENVIRONMENTS': '/environments',
            'ENVIRONMENTVARS': '/environmentvariables',
            'ACCOUNT': '/Account',
            'USERS': '/Users',
            'DEV': '/dev',

        'MODEL': 'net.hawkengine.model',
        'SERVICES': 'net.hawkengine.services',

        //region agent methods
        'AGENT_GET_BY_ID': 'getAgentById',
        'AGENT_GET_ALL': 'getAllAgents',
        'AGENT_ADD': 'addAgent',
        'AGENT_UPDATE': 'updateAgent',
        'AGENT_DELETE': 'deleteAgent',
        'AGENT_SET_CONFIGSTATE': 'setAgentConfigState',
        //endregion

        //region agent packages
        'AGENT_SERVICE': 'AgentService',
        'AGENT_MODEL': 'Agent',
        //endregion

        //region toaster types
        'TOAST_WARNING': 'WARNING',
        'TOAST_SUCCESS': 'SUCCESS',
        'TOAST_ERROR': 'ERROR'
            //end region toaster types
    }
})



/* Setup global settings */
.factory('settings', ['$rootScope', function($rootScope) {
    // supported languages
    var settings = {
        layout: {

            pageContentWhite: true, // set page content layout
            pageBodySolid: false, // solid body color state
            pageAutoScrollOnLoad: 1000 // auto scroll to top on page load
        },
        assetsPath: '../assets',
        globalPath: '../assets/global',
        layoutPath: '../assets/layouts/layout'
    };

    $rootScope.settings = settings;

    return settings;
}])

/* Setup Routing For All Pages */
.config(['$stateProvider', '$urlRouterProvider', '$animateProvider', '$authProvider', 'CONSTANTS',
    function($stateProvider, $urlRouterProvider, $animateProvider, $authProvider, CONSTANTS) {

        // used for debugging
        $authProvider.baseUrl = CONSTANTS.SERVER_URL;
        $authProvider.github({
            clientId: '<KEY>',
            scope: ['user:email', 'repo']
        });


        // Redirect any unmatched url
        $urlRouterProvider.when('', '/pipelines').when('/', '/pipelines').otherwise("/pipelines");
        //$animateProvider.classNameFilter(/angular-animate/);
        $stateProvider
            .state('auth', {
                url: "/authenticate",
                templateUrl: "app/auth.html",
                data: {
                    pageTitle: 'Authenticate'
                },
                resolve: {
                    auth: function(authDataService, pipeStatsService, agentService, $location) {
                        if (authDataService.authenticationData.IsAuthenticated) {
                            //pipeStatsService.getAgentById();
                            // $location.path('/pipelines');
                        }
                    }
                }
            })

        .state('index', {
            url: "/",
            templateUrl: "app/main.html",
            resolve: {
                auth: function(authDataService, pipeStatsService, agentService, $location,
                    $auth, $rootScope, $timeout) {

                    console.log("isAuthenticated: " + $auth.isAuthenticated());

                    if (!$auth.isAuthenticated()) {
                        $timeout(function() {
                            $location.path('/authenticate');
                            $rootScope.$apply();
                        }, 100);
                    }

                    //$auth.authenticate('github');

                    if (!authDataService.authenticationData.IsAuthenticated) {
                        //pipeStatsService.getAgentById();
                        //$location.path('/authenticate');
                    }
                }
            }
        })

    }
])

/* Init global settings and run the app */
.run(["$rootScope", "settings", "$state", "websocketReceiverService", "agentService", "adminGroupService", "adminService", "adminMaterialService", "pipeConfigService", "pipeExecService", "authenticationService", "toaster", "$auth", "$location", "CONSTANTS", "notificationService", function($rootScope, settings, $state, websocketReceiverService, agentService, adminGroupService, adminService, adminMaterialService, pipeConfigService, pipeExecService, authenticationService, toaster, $auth, $location, CONSTANTS, notificationService) {
    $rootScope.$state = $state; // state to be accessed from view
    $rootScope.$settings = settings; // state to be accessed from view
    $rootScope.$on('$stateChange');

    var wsServerLocation = 'ws://' + CONSTANTS.HOST + '/ws/v1';

    var timerID = 0;


    //TODO: Replace localStorage with $auth.isAuthenitcated()
    $rootScope.startWebsocket = function start(wsServerLocation) {
        $rootScope.socket = new WebSocket(wsServerLocation.concat('?token=' + $auth.getToken()));

        $rootScope.socket.onmessage = function(event) {
            console.log(event.data);
            websocketReceiverService.processEvent(JSON.parse(event.data));
        };

        $rootScope.socket.onopen = function(event) {
            toaster.clear();
            notificationService.notificationDispatcher[CONSTANTS.TOAST_SUCCESS]("Connection to server successful!");
            if (window.timerID) {
                window.clearInterval(window.timerID);
                window.timerID = 0;
            }

            // pipeConfigService.getAllJobDefinitions();
            // pipeConfigService.getAllStageDefinitions();
            //pipeStatsService.getAgentById();

            //adminGroupService.getAllPipelineGroups();
            pipeConfigService.getAllPipelineDefinitions();
            pipeConfigService.getAllPipelineGroupDTOs();
            agentService.getAllAgents();
            pipeExecService.getAllPipelines();
            adminService.getAllUserGroupDTOs();
            adminService.getAllUsers();
            adminMaterialService.getAllMaterialDefinitions();
        };

        $rootScope.socket.onclose = function(event) {
            if (!$auth.isAuthenticated()) {
                $auth.logout();
                $location.path('/authenticate');
                console.log(event);
                toaster.clear();
                notificationService.notificationDispatcher[CONSTANTS.TOAST_WARNING](event.reason);
                $rootScope.$apply();
                return;
            }
            if (!window.timerID) {<commit_msg>UI no longer gets all Pipeline Runs #316<commit_after>/***
 Hawk Main Script
 ***/
'use strict';

/* Hawk Main Module */
angular
    .module("hawk", [
        "hawk.environmentsManagement",
        "hawk.agentsManagement",
        "hawk.pipelinesManagement",
        "hawk.userManagement",
        "hawk.adminManagement",
        "hawk.profileManagement",
        "hawk.artifactManagement",
        "ui.router",
        'ui.sortable',
        "ui.bootstrap",
        //"oc.lazyLoad",
        //"ngSanitize",
        'luegg.directives',
        'toaster',
        'momentjs',
        'satellizer',
        'ansi_up',
        'ngJsTree'
        //'ngAnimate'
        //'flow'
    ])

    .constant({
        CONSTANTS: {
            'BASE_URL': '/api',
            'SERVER_URL': window.location.origin,
            'HOST': window.location.host,
            'CONFIG': '/config',
            'EXEC': '/exec',
            'STATS': '/stats',
            'PIPELINES': '/pipelines',
            'PIPELINE_GROUPS': "/pipeline_groups",
            'AGENTS': '/agents',
            'STAGES': '/stages',
            'JOBS': '/jobs',
            'TASKS': '/tasks',
            'ARTIFACTS': '/artifacts',
            'MATERIALS': '/materials',
            'SERVER': '/server',
            'ENVIRONMENTS': '/environments',
            'ENVIRONMENTVARS': '/environmentvariables',
            'ACCOUNT': '/Account',
            'USERS': '/Users',
            'DEV': '/dev',

        'MODEL': 'net.hawkengine.model',
        'SERVICES': 'net.hawkengine.services',

        //region agent methods
        'AGENT_GET_BY_ID': 'getAgentById',
        'AGENT_GET_ALL': 'getAllAgents',
        'AGENT_ADD': 'addAgent',
        'AGENT_UPDATE': 'updateAgent',
        'AGENT_DELETE': 'deleteAgent',
        'AGENT_SET_CONFIGSTATE': 'setAgentConfigState',
        //endregion

        //region agent packages
        'AGENT_SERVICE': 'AgentService',
        'AGENT_MODEL': 'Agent',
        //endregion

        //region toaster types
        'TOAST_WARNING': 'WARNING',
        'TOAST_SUCCESS': 'SUCCESS',
        'TOAST_ERROR': 'ERROR'
            //end region toaster types
    }
})



/* Setup global settings */
.factory('settings', ['$rootScope', function($rootScope) {
    // supported languages
    var settings = {
        layout: {

            pageContentWhite: true, // set page content layout
            pageBodySolid: false, // solid body color state
            pageAutoScrollOnLoad: 1000 // auto scroll to top on page load
        },
        assetsPath: '../assets',
        globalPath: '../assets/global',
        layoutPath: '../assets/layouts/layout'
    };

    $rootScope.settings = settings;

    return settings;
}])

/* Setup Routing For All Pages */
.config(['$stateProvider', '$urlRouterProvider', '$animateProvider', '$authProvider', 'CONSTANTS',
    function($stateProvider, $urlRouterProvider, $animateProvider, $authProvider, CONSTANTS) {

        // used for debugging
        $authProvider.baseUrl = CONSTANTS.SERVER_URL;
        $authProvider.github({
            clientId: '<KEY>',
            scope: ['user:email', 'repo']
        });


        // Redirect any unmatched url
        $urlRouterProvider.when('', '/pipelines').when('/', '/pipelines').otherwise("/pipelines");
        //$animateProvider.classNameFilter(/angular-animate/);
        $stateProvider
            .state('auth', {
                url: "/authenticate",
                templateUrl: "app/auth.html",
                data: {
                    pageTitle: 'Authenticate'
                },
                resolve: {
                    auth: function(authDataService, pipeStatsService, agentService, $location) {
                        if (authDataService.authenticationData.IsAuthenticated) {
                            //pipeStatsService.getAgentById();
                            // $location.path('/pipelines');
                        }
                    }
                }
            })

        .state('index', {
            url: "/",
            templateUrl: "app/main.html",
            resolve: {
                auth: function(authDataService, pipeStatsService, agentService, $location,
                    $auth, $rootScope, $timeout) {

                    console.log("isAuthenticated: " + $auth.isAuthenticated());

                    if (!$auth.isAuthenticated()) {
                        $timeout(function() {
                            $location.path('/authenticate');
                            $rootScope.$apply();
                        }, 100);
                    }

                    //$auth.authenticate('github');

                    if (!authDataService.authenticationData.IsAuthenticated) {
                        //pipeStatsService.getAgentById();
                        //$location.path('/authenticate');
                    }
                }
            }
        })

    }
])

/* Init global settings and run the app */
.run(["$rootScope", "settings", "$state", "websocketReceiverService", "agentService", "adminGroupService", "adminService", "adminMaterialService", "pipeConfigService", "pipeExecService", "authenticationService", "toaster", "$auth", "$location", "CONSTANTS", "notificationService", function($rootScope, settings, $state, websocketReceiverService, agentService, adminGroupService, adminService, adminMaterialService, pipeConfigService, pipeExecService, authenticationService, toaster, $auth, $location, CONSTANTS, notificationService) {
    $rootScope.$state = $state; // state to be accessed from view
    $rootScope.$settings = settings; // state to be accessed from view
    $rootScope.$on('$stateChange');

    var wsServerLocation = 'ws://' + CONSTANTS.HOST + '/ws/v1';

    var timerID = 0;


    //TODO: Replace localStorage with $auth.isAuthenitcated()
    $rootScope.startWebsocket = function start(wsServerLocation) {
        $rootScope.socket = new WebSocket(wsServerLocation.concat('?token=' + $auth.getToken()));

        $rootScope.socket.onmessage = function(event) {
            // console.log(event.data);
            websocketReceiverService.processEvent(JSON.parse(event.data));
        };

        $rootScope.socket.onopen = function(event) {
            toaster.clear();
            notificationService.notificationDispatcher[CONSTANTS.TOAST_SUCCESS]("Connection to server successful!");
            if (window.timerID) {
                window.clearInterval(window.timerID);
                window.timerID = 0;
            }

            // pipeConfigService.getAllJobDefinitions();
            // pipeConfigService.getAllStageDefinitions();
            //pipeStatsService.getAgentById();

            //adminGroupService.getAllPipelineGroups();
            pipeConfigService.getAllPipelineDefinitions();
            pipeConfigService.getAllPipelineGroupDTOs();
            agentService.getAllAgents();
            adminService.getAllUserGroupDTOs();
            adminService.getAllUsers();
            adminMaterialService.getAllMaterialDefinitions();
        };

        $rootScope.socket.onclose = function(event) {
            if (!$auth.isAuthenticated()) {
                $auth.logout();
                $location.path('/authenticate');
                console.log(event);
                toaster.clear();
                notificationService.notificationDispatcher[CONSTANTS.TOAST_WARNING](event.reason);
                $rootScope.$apply();
                return;
            }
            if (!window.timerID) {
{'fraction_non_alphanumeric': 0.1349730053989202, 'fraction_numerical': 0.0015330267279877357, 'mean_word_length': 1.8959660297239915, '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': '324644', 'n_tokens_mistral': 4076, 'n_tokens_neox': 3875, 'n_words': 708}