<commit_before>'use strict';

angular.module('mean.icu').controller('IcuController',
    function ($rootScope,
        $scope,
        me,
        $state,
        projects,
        discussions,
        people,
        context) {
    $scope.menu = {
        isHidden: false
    };

    $scope.projects = projects;
    $scope.discussions = discussions;
    $scope.people = people;

    var entityMap = {
        'project': 'projects',
        'discussion': 'discussions',
        'user': 'people'
    };

    function initializeContext(state) {
        if (state.name.indexOf('main') === 0) {
            var restoredContext = context.getContextFromState(state);
            if (restoredContext.entityName !== 'all') {
                var currentEntity = _($scope[entityMap[restoredContext.entityName]]).find(function(e) {
                    return e._id === restoredContext.entityId;
                });

                restoredContext.entity = currentEntity;

                context.setMain(restoredContext.main);

                if (restoredContext.entityName) {
                    context.entityName = restoredContext.entityName;
                    context.entity = restoredContext.entity;
                    context.entityId = restoredContext.entityId;
                } else if ($scope.projects[0] && restoredContext.main !== 'project') {
                    context.entityName = 'project';
                    context.entity = $scope.projects[0];
                    context.entityId = $scope.projects[0]._id;
                } else if ($scope.discussions[0] && restoredContext.main === 'project') {
                    context.entityName = 'discussion';
                    context.entity = $scope.discussions[0];
                    context.entityId = $scope.discussions[0]._id;
                } else {
                    context.entityName = 'all';
                    context.entity = undefined;
                    context.entityId = undefined;
                }
            } else {
                context.setMain(restoredContext.main);
                context.entityName = restoredContext.entityName;
                context.entity = undefined;
                context.entityId = undefined;
            }
        }
    }

    var state = $state.current;
    state.params = $state.params;

    initializeContext(state);
    $scope.currentContext = context;

    $rootScope.$on('$stateChangeError', function () {
        console.log(arguments);
    });

    $rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
        var state = toState;
        state.params = toParams;

        initializeContext(state);
    });

    $rootScope.$on('$stateChangeSuccess', function (event, toState) {
        console.log(arguments);
    });
});

angular.module('mean.icu').run(function($rootScope, $location, $state) {
    $rootScope.$on('$stateChangeError', function (a, b, c, d, f, error) {
        if (error === null) {
            $state.go('login', null, { reload: true });
        }
    });
});
<commit_msg>Fix blank page on toggling main menu items<commit_after>'use strict';

angular.module('mean.icu').controller('IcuController',
    function ($rootScope,
        $scope,
        me,
        $state,
        projects,
        discussions,
        people,
        context) {
    $scope.menu = {
        isHidden: false
    };

    $scope.projects = projects.data || projects;
    $scope.discussions = discussions.data || discussions;
    $scope.people = people.data || people;

    var entityMap = {
        'project': 'projects',
        'discussion': 'discussions',
        'user': 'people'
    };

    function initializeContext(state) {
        if (state.name.indexOf('main') === 0) {
            var restoredContext = context.getContextFromState(state);
            if (restoredContext.entityName !== 'all') {
                var currentEntity = _($scope[entityMap[restoredContext.entityName]]).find(function(e) {
                    return e._id === restoredContext.entityId;
                });

                restoredContext.entity = currentEntity;

                context.setMain(restoredContext.main);

                if (restoredContext.entityName) {
                    context.entityName = restoredContext.entityName;
                    context.entity = restoredContext.entity;
                    context.entityId = restoredContext.entityId;
                } else if ($scope.projects[0] && restoredContext.main !== 'project') {
                    context.entityName = 'project';
                    context.entity = $scope.projects[0];
                    context.entityId = $scope.projects[0]._id;
                } else if ($scope.discussions[0] && restoredContext.main === 'project') {
                    context.entityName = 'discussion';
                    context.entity = $scope.discussions[0];
                    context.entityId = $scope.discussions[0]._id;
                } else {
                    context.entityName = 'all';
                    context.entity = undefined;
                    context.entityId = undefined;
                }
            } else {
                context.setMain(restoredContext.main);
                context.entityName = restoredContext.entityName;
                context.entity = undefined;
                context.entityId = undefined;
            }
        }
    }

    var state = $state.current;
    state.params = $state.params;

    initializeContext(state);
    $scope.currentContext = context;

    $rootScope.$on('$stateChangeError', function () {
        console.log(arguments);
    });

    $rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
        var state = toState;
        state.params = toParams;

        initializeContext(state);
    });

    $rootScope.$on('$stateChangeSuccess', function (event, toState) {
        console.log(arguments);
    });
});

angular.module('mean.icu').run(function($rootScope, $location, $state) {
    $rootScope.$on('$stateChangeError', function (a, b, c, d, f, error) {
        if (error === null) {
            $state.go('login', null, { reload: true });
        }
    });
});

{'fraction_non_alphanumeric': 0.12773900340853758, 'fraction_numerical': 0.0022723583833793217, 'mean_word_length': 1.8593967517401393, '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': '2883471', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1571, 'n_words': 288}