<commit_before>/* global document */
define(['angular', 'jQuery', 'i18n', 'restangular', 'angular-ui-router', 'angular-ui', 'twitter-bootstrap', 'modules/base/base', 'modules/trackr/trackr', 'modules/invoices/invoicesModule',
    'modules/shared/shared', 'flatify'
], function(angular, $, i18n) {
    'use strict';
    var configFn = ['ui.router', 'ui.bootstrap', 'base', 'trackr', 'restangular', 'invoices', 'shared', 'app.directives'];
    var app = angular.module('app', configFn);

    var trackrUser;
    /*
     Load the current user and its authorities before the app starts.
     After the user is loaded the trackr app gets bootstrapped manually.
     */
    angular.element(document).ready(function() {
        $.get('api/principal', function(data) {
            trackrUser = data;
            i18n.init(app, trackrUser);
            angular.bootstrap(document, ['app']);
        });
    });

    app.config(['RestangularProvider', '$locationProvider', 'paginationConfig', function(RestangularProvider, $locationProvider, paginationConfig) {
        $locationProvider.html5Mode(false);
        RestangularProvider.setBaseUrl('api');
        /**  Restangularify the Spring Data Rest response
         Spring Data Rest returns lists like this:
         <code>
         {
            "_embedded": {
                "companies": [
                    ...
                ]
            }
         }
         </code>
         **/
        RestangularProvider.addResponseInterceptor(function(data, operation, route) {
            var returnData;
            if(operation === 'getList' && data._embedded) {
                returnData = data._embedded[route];
                /*
                Fallback: if the returned data does not contain the route key take the first one.
                Example: data = { _embedded: { travelExpenses: [] } } but route = 'expenses'.
                 */
                if(!returnData) {
                    returnData = data._embedded[Object.keys(data._embedded)[0]];
                }
                //if there is pagination info make it one-based.
                if(data.page) {
                    returnData.page = data.page;
                    returnData.page.number = returnData.page.number + 1;
                }
            } else if(operation === 'getList' && !data._embedded) {
                returnData = [];
                returnData.page = data.page;
            } else {
                returnData = data;
            }
            return returnData;
        });

        /*
         Global pagination configuration
         */
        paginationConfig.previousText = '<';
        paginationConfig.nextText = '>';
    }]);

    /**
     * Implement state authorization
     */
    app.run(['$rootScope', '$log', 'base.services.user', '$http', function($rootScope, $log, UserService) {
        UserService.setUser(trackrUser);
        $rootScope.$on('$stateChangeStart', function(event, toState) {<commit_msg>TRACKR-113 - Redirect user to login page after automatic logout<commit_after>/* global document, window */
define(['angular', 'jQuery', 'i18n', 'restangular', 'angular-ui-router', 'angular-ui', 'twitter-bootstrap', 'modules/base/base', 'modules/trackr/trackr', 'modules/invoices/invoicesModule',
    'modules/shared/shared', 'flatify'
], function(angular, $, i18n) {
    'use strict';
    var configFn = ['ui.router', 'ui.bootstrap', 'base', 'trackr', 'restangular', 'invoices', 'shared', 'app.directives'];
    var app = angular.module('app', configFn);

    var trackrUser;
    /*
     Load the current user and its authorities before the app starts.
     After the user is loaded the trackr app gets bootstrapped manually.
     */
    angular.element(document).ready(function() {
        $.get('api/principal', function(data) {
            trackrUser = data;
            i18n.init(app, trackrUser);
            angular.bootstrap(document, ['app']);
        });
    });

    app.config(['RestangularProvider', '$locationProvider', 'paginationConfig', '$httpProvider', function(RestangularProvider, $locationProvider, paginationConfig, $httpProvider) {
        $locationProvider.html5Mode(false);
        RestangularProvider.setBaseUrl('api');
        /**  Restangularify the Spring Data Rest response
         Spring Data Rest returns lists like this:
         <code>
         {
            "_embedded": {
                "companies": [
                    ...
                ]
            }
         }
         </code>
         **/
        RestangularProvider.addResponseInterceptor(function(data, operation, route) {
            var returnData;
            if(operation === 'getList' && data._embedded) {
                returnData = data._embedded[route];
                /*
                Fallback: if the returned data does not contain the route key take the first one.
                Example: data = { _embedded: { travelExpenses: [] } } but route = 'expenses'.
                 */
                if(!returnData) {
                    returnData = data._embedded[Object.keys(data._embedded)[0]];
                }
                //if there is pagination info make it one-based.
                if(data.page) {
                    returnData.page = data.page;
                    returnData.page.number = returnData.page.number + 1;
                }
            } else if(operation === 'getList' && !data._embedded) {
                returnData = [];
                returnData.page = data.page;
            } else {
                returnData = data;
            }
            return returnData;
        });

        /*
         Global pagination configuration
         */
        paginationConfig.previousText = '<';
        paginationConfig.nextText = '>';

        //This interceptor checks if a request returns the login page and redirects to it if so.
        $httpProvider.interceptors.push(['$q', '$log', function($q, $log) {
            return {
                'response': function(response) {
                    var loginPageHeader = response.headers('trackr-login-page');
                    if(loginPageHeader === 'true') {
                        var redirectUrl = window.location.pathname + '/login';
                        $log.debug('Request returned login page ', redirectUrl);
                        window.location = redirectUrl;
                        return $q.reject('Not logged in');
                    }
                    return response;
                }
            };
        }]);
    }]);

    /**
     * Implement state authorization
     */
    app.run(['$rootScope', '$log', 'base.services.user', '$http', function($rootScope, $log, UserService) {
        UserService.setUser(trackrUser);
        $rootScope.$on('$stateChangeStart', function(event, toState) {
{'fraction_non_alphanumeric': 0.12778515567360188, 'fraction_numerical': 0.003098716246126605, 'mean_word_length': 1.8659619450317124, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, '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': '5056468', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1713, 'n_words': 398}