<commit_before>import './index.module';
import { setupRoutes } from './routes.js';
import { MCAppController } from './mc-app.controller';
import './global.services/index.module';
import './global.filters/index.module';
import './global.components/index.module';
import './login/index.module';
import './join/index.module';
import './model/index.module';
import './project/index.module';
import './projects/index.module';
import './user/index.module';
import './releasenotes/mc-release-notes.component';
import './util/util';

angular.module('materialscommons')
    .constant('mcglobals', setupMCGlobals())
    .config(appConfig)
    .run(appRun)
    .controller('MCAppController', MCAppController);

appConfig.$inject = ['$stateProvider', '$urlRouterProvider', '$mdThemingProvider', '$ariaProvider', '$compileProvider', 'hljsServiceProvider'];
function appConfig($stateProvider, $urlRouterProvider, $mdThemingProvider, $ariaProvider, $compileProvider, hljsServiceProvider) {
    setupMaterialsTheme($mdThemingProvider);
    setupRoutes($stateProvider, $urlRouterProvider);
    $ariaProvider.config({ariaChecked: false, ariaInvalid: false});
    $compileProvider.debugInfoEnabled(false);
    hljsServiceProvider.setOptions({
        // replace tab with 4 spaces
        tabReplace: '    '
    });
}

/*
 myApp.config(function (hljsServiceProvider) {
 hljsServiceProvider.setOptions({
 // replace tab with 4 spaces
 tabReplace: '    '
 });
 });
 */

appRun.$inject = ['$rootScope', 'User', 'Restangular', '$state', 'mcglobals', 'searchQueryText'];
function appRun($rootScope, User, Restangular, $state, mcglobals, searchQueryText) {
    Restangular.setBaseUrl(mcglobals.apihost);

    // appRun will run when the application starts up and before any controllers have run.
    // This means it will run on a refresh. We check if the user is already authenticated
    // during the run. If they are then the browser has been refreshed and we need to
    // set the apikey param for Restangular. This param is set in the login-controller.
    // However on a refresh the login-controller isn't run so we need to explicitly set
    // the apikey param in Restangular.
    if (User.isAuthenticated()) {
        Restangular.setDefaultRequestParams({apikey: User.apikey()});
    }

    var unregister = $rootScope.$on('$stateChangeStart', function(event, toState) {
        $rootScope.navbarSearchText = toState.name.startsWith('projects') ? 'SEARCH PROJECTS...' : 'SEARCH PROJECT...';
        if (!User.isAuthenticated() && isStateRequiringALogin(toState.name)) {
            event.preventDefault();
            $state.go('login');
        }

        if (!toState.name.startsWith('project.search')) {
            searchQueryText.set("");
        }
    });

    $rootScope.$on('$destroy', function() { unregister(); });
}

function isStateRequiringALogin(stateName) {
    switch (stateName) {
        case 'login':
        case 'join':
        case 'reset':
        case 'validate':
        case 'rvalidate':
        case 'releasenotes':
            return false;
        default:
            return true;
    }
}

function setupMCGlobals() {
    var mcglobals = {};<commit_msg>Add mc$ value (for now).<commit_after>import './index.module';
import { setupRoutes } from './routes.js';
import { MCAppController } from './mc-app.controller';
import './global.services/index.module';
import './global.filters/index.module';
import './global.components/index.module';
import './login/index.module';
import './join/index.module';
import './model/index.module';
import './project/index.module';
import './projects/index.module';
import './user/index.module';
import './releasenotes/mc-release-notes.component';
import './util/util';

angular.module('materialscommons')
    .constant('mcglobals', setupMCGlobals())
    .value('mc$', {
        project: null,
        experiment: null,
        process: null,
        sample: null
    })
    .config(appConfig)
    .run(appRun)
    .controller('MCAppController', MCAppController);

appConfig.$inject = ['$stateProvider', '$urlRouterProvider', '$mdThemingProvider', '$ariaProvider', '$compileProvider', 'hljsServiceProvider'];
function appConfig($stateProvider, $urlRouterProvider, $mdThemingProvider, $ariaProvider, $compileProvider, hljsServiceProvider) {
    setupMaterialsTheme($mdThemingProvider);
    setupRoutes($stateProvider, $urlRouterProvider);
    $ariaProvider.config({ariaChecked: false, ariaInvalid: false});
    $compileProvider.debugInfoEnabled(false);
    hljsServiceProvider.setOptions({
        // replace tab with 4 spaces
        tabReplace: '    '
    });
}

/*
 myApp.config(function (hljsServiceProvider) {
 hljsServiceProvider.setOptions({
 // replace tab with 4 spaces
 tabReplace: '    '
 });
 });
 */

appRun.$inject = ['$rootScope', 'User', 'Restangular', '$state', 'mcglobals', 'searchQueryText'];
function appRun($rootScope, User, Restangular, $state, mcglobals, searchQueryText) {
    Restangular.setBaseUrl(mcglobals.apihost);

    // appRun will run when the application starts up and before any controllers have run.
    // This means it will run on a refresh. We check if the user is already authenticated
    // during the run. If they are then the browser has been refreshed and we need to
    // set the apikey param for Restangular. This param is set in the login-controller.
    // However on a refresh the login-controller isn't run so we need to explicitly set
    // the apikey param in Restangular.
    if (User.isAuthenticated()) {
        Restangular.setDefaultRequestParams({apikey: User.apikey()});
    }

    const unregister = $rootScope.$on('$stateChangeStart', function(event, toState) {
        $rootScope.navbarSearchText = toState.name.startsWith('projects') ? 'SEARCH PROJECTS...' : 'SEARCH PROJECT...';
        if (!User.isAuthenticated() && isStateRequiringALogin(toState.name)) {
            event.preventDefault();
            $state.go('login');
        }

        if (!toState.name.startsWith('project.search')) {
            searchQueryText.set("");
        }
    });

    $rootScope.$on('$destroy', function() { unregister(); });
}

function isStateRequiringALogin(stateName) {
    switch (stateName) {
        case 'login':
        case 'join':
        case 'reset':
        case 'validate':
        case 'rvalidate':
        case 'releasenotes':
            return false;
        default:
            return true;
    }
}

function setupMCGlobals() {
    const mcglobals = {};
{'fraction_non_alphanumeric': 0.14089293990421753, 'fraction_numerical': 0.0006179514908079716, 'mean_word_length': 3.4833795013850417, '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': '7304807', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1828, 'n_words': 455}