<commit_before>'use strict';

app.controller('Menu', ['$rootScope', '$routeParams','$scope', '$location', 'Project', 'TestPlan', 'Auth', 'isSafari','$q', 'appConfig',
    function ($rootScope, $routeParams, $scope, $location, Project, TestPlan, Auth, isSafari, $q, appConfig) {
        $scope.isSafari = isSafari;
        $scope.jira = JIRA_INTEGRATION;
        $scope.xmasTree = showXmasTree();

        //hide menu if hideMenu=true
        var scope = $routeParams;
        $scope.$watch(function (){return scope.hideMenu;}, function (value) {
            if(value) {
                $("body").css("padding-top", "0px");
            } else {
                $("body").css("padding-top", "50px");
            }
            $scope.hideMenu = !!value;
        });

        $scope.activeProject = null;
        $scope.activeProjectId = null;
        $scope.logout = function () {
            Auth.api.logout(function () {
                $rootScope.profile = null;
            }, function (result) {
                console.info(result);
            });
        };

        $rootScope.getProfile = function() {
            var deferred = $q.defer();

            if (typeof $rootScope.profile === 'undefined') {
                Auth.api.get_current(function (result) {
                    $rootScope.profile = result;
                    if ($rootScope.profile.settings.default_project !== null && $location.path() === '/dashboard') {
                        $location.path('/dashboard/' + $rootScope.profile.settings.default_project);
                    }
                    deferred.resolve(result);
                }, function () {
                    $rootScope.profile = null;
                    deferred.resolve($rootScope.profile);
                });
            } else {
                deferred.resolve($rootScope.profile);
            }

            return deferred.promise;
        };

        $rootScope.getProfile();

        $rootScope.reloadProjects = function () {
            Project.query(function (result) {

                $rootScope.projects = result.results;
                _.each($rootScope.projects, function(project) {
                    _.each(project.settings, function(setting) {
                        project[setting.key] = setting.value;
                    });
                });

                TestPlan.custom_list({ projectsIds: _.map($rootScope.projects, function (item) { return item.id})}, function (result) {
                    _.each($rootScope.projects, function (project) {
                        project.testplans = _.sortBy(
                            _.filter(result.results, function (testplan) { return testplan.project === project.id }),
                            'name');
                    });
                });
            }, function() {
                $rootScope.api_path = API_PATH;

            });
        };

        $rootScope.reloadProjects();

        $scope.$watch('projects', function () {
            $scope.activeProject = $scope.findProjectById($scope.activeProjectId);
        });

        $scope.$watch('activeProjectId', function () {
            $scope.activeProject = $scope.findProjectById($scope.activeProjectId);
        });

        $scope.findProjectById = function (id) {
            var data = _.filter($rootScope.projects, function (project) { return project.id === parseInt(id)});
            return data[0];
        };

        $rootScope.selectProject = function (id) {
            id = (typeof id === 'undefined') ? null : id;
            if (id !== $scope.activeProjectId) {
                $scope.activeProjectId = id;
            }
        };

        $rootScope.getActiveProject = function() {
            return $scope.activeProjectId;
        };

        $rootScope.getProjectSettings = function(id, setting_name) {<commit_msg>add promise for projects list<commit_after>'use strict';

app.controller('Menu', ['$rootScope', '$routeParams','$scope', '$location', 'Project', 'TestPlan', 'Auth', 'isSafari','$q', 'appConfig',
    function ($rootScope, $routeParams, $scope, $location, Project, TestPlan, Auth, isSafari, $q, appConfig) {
        $scope.isSafari = isSafari;
        $scope.jira = JIRA_INTEGRATION;
        $scope.xmasTree = showXmasTree();

        //hide menu if hideMenu=true
        var scope = $routeParams;
        $scope.$watch(function (){return scope.hideMenu;}, function (value) {
            if(value) {
                $("body").css("padding-top", "0px");
            } else {
                $("body").css("padding-top", "50px");
            }
            $scope.hideMenu = !!value;
        });

        $scope.activeProject = null;
        $scope.activeProjectId = null;
        $scope.logout = function () {
            Auth.api.logout(function () {
                $rootScope.profile = null;
            }, function (result) {
                console.info(result);
            });
        };

        $rootScope.getProfile = function() {
            var deferred = $q.defer();

            if (typeof $rootScope.profile === 'undefined') {
                Auth.api.get_current(function (result) {
                    $rootScope.profile = result;
                    if ($rootScope.profile.settings.default_project !== null && $location.path() === '/dashboard') {
                        $location.path('/dashboard/' + $rootScope.profile.settings.default_project);
                    }
                    deferred.resolve(result);
                }, function () {
                    $rootScope.profile = null;
                    deferred.resolve($rootScope.profile);
                });
            } else {
                deferred.resolve($rootScope.profile);
            }

            return deferred.promise;
        };

        $rootScope.getProjects = function() {
            var deferred = $q.defer();

            Project.query(function (result) {
                deferred.resolve(result.results);
            });

            return deferred.promise;
        };

        $rootScope.getProfile();

        $rootScope.reloadProjects = function () {

            $rootScope.getProjects().then(function(projects) {
                $rootScope.projects = projects;
                _.each($rootScope.projects, function(project) {
                    _.each(project.settings, function(setting) {
                        project[setting.key] = setting.value;
                    });
                });

                TestPlan.custom_list({ projectsIds: _.map($rootScope.projects, function (item) { return item.id})}, function (result) {
                    _.each($rootScope.projects, function (project) {
                        project.testplans = _.sortBy(
                            _.filter(result.results, function (testplan) { return testplan.project === project.id }),
                            'name');
                    });
                });
            });
        };

        $rootScope.reloadProjects();

        $scope.$watch('projects', function () {
            $scope.activeProject = $scope.findProjectById($scope.activeProjectId);
        });

        $scope.$watch('activeProjectId', function () {
            $scope.activeProject = $scope.findProjectById($scope.activeProjectId);
        });

        $scope.findProjectById = function (id) {
            var data = _.filter($rootScope.projects, function (project) { return project.id === parseInt(id)});
            return data[0];
        };

        $rootScope.selectProject = function (id) {
            id = (typeof id === 'undefined') ? null : id;
            if (id !== $scope.activeProjectId) {
                $scope.activeProjectId = id;
            }
        };

        $rootScope.getActiveProject = function() {
            return $scope.activeProjectId;
        };

        $rootScope.getProjectSettings = function(id, setting_name) {
{'fraction_non_alphanumeric': 0.13876876112948358, 'fraction_numerical': 0.0010175527855507504, 'mean_word_length': 1.6537293283833951, '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': '5809666', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1983, 'n_words': 348}