<commit_before>/* global _, angular, i18n */
'use strict';

var controllers = angular.module('acs.controllers', []);

controllers.controller('root', ['$scope', '$location', '$q', 'user', function($scope, $location, $q, user) {

    $scope.loaded = false;
    $scope.user = user;
    $scope.permissions = {};
    $scope.waiting = false;

    $scope.init = function() {
        if (!user.loggedIn()) {
            $scope.loaded = true;
            return;
        }

        var promises = [];

        promises.push(user.permissions('administrator')
        .then(function(permissions) {
            $scope.permissions.administrator = permissions;
        }));
    
        promises.push(user.permissions('user')
        .then(function(permissions) {
            $scope.permissions.users = permissions;
        }));
    
        promises.push(user.permissions('role')
        .then(function(permissions) {
            $scope.permissions.roles = permissions;
        }));
        
        $q.all(promises)
        .then(function() {
            $scope.loaded = true;
        }, function() {
            $scope.loaded = true;
        });
    };

    $scope.active = function(path) {
        return $location.path().match(new RegExp(path + '.*', 'i')) != null;
    };

    $scope.logout = function() {
        $scope.user.clear();
        //window.location.reload();
    };
    
}]);

controllers.controller('navigation', ['$scope', '$location', 'user', function($scope, $location, user) {

    $scope.user = user;

    $scope.navigation = function() {
        if ($scope.active('/administrator') && user.loggedIn()) {
            return 'partials/navigation-administrator.html';
        } else {
            return 'partials/navigation.html';
        }
    };
    
}]);

controllers.controller('login', ['$scope', '$location', '$http', '$window', 'alerts', 'user', function($scope, $location, $http, $window, alerts, user) {

    $scope.alerts = alerts;
    $scope.input = {};

    $scope.login = function() {
        $scope.waiting = true;
        $http.post('api/user/login', {
            email: $scope.input.email,
            password: $<PASSWORD>
        }).success(function(data) {
            $scope.waiting = false;
            if (data.status) {
                user.setEmail(data.email);
                user.setToken(data.token);
                $location.path('home');
                //$window.location.reload();
            } else {<commit_msg>Update controllers.js<commit_after>/* global _, angular, i18n */
'use strict';

var controllers = angular.module('acs.controllers', []);

controllers.controller('root', ['$scope', '$location', '$q', 'user', function($scope, $location, $q, user) {

    $scope.loaded = false;
    $scope.user = user;
    $scope.permissions = {};
    $scope.waiting = false;

    $scope.init = function() {
        if (!user.loggedIn()) {
            $scope.loaded = true;
            return;
        }

        var promises = [];

        promises.push(user.permissions('administrator')
        .then(function(permissions) {
            $scope.permissions.administrator = permissions;
        }));
    
        promises.push(user.permissions('user')
        .then(function(permissions) {
            $scope.permissions.users = permissions;
        }));
    
        promises.push(user.permissions('role')
        .then(function(permissions) {
            $scope.permissions.roles = permissions;
        }));
        
        $q.all(promises)
        .then(function() {
            $scope.loaded = true;
        }, function() {
            $scope.loaded = true;
        });
    };

    $scope.active = function(path) {
        return $location.path().match(new RegExp(path + '.*', 'i')) != null;
    };

    $scope.logout = function() {
        $scope.user.clear();
        $location.path('navigation');
        //window.location.reload();
    };
    
}]);

controllers.controller('navigation', ['$scope', '$location', 'user', function($scope, $location, user) {

    $scope.user = user;

    $scope.navigation = function() {
        if ($scope.active('/administrator') && user.loggedIn()) {
            return 'partials/navigation-administrator.html';
        } else {
            return 'partials/navigation.html';
        }
    };
    
}]);

controllers.controller('login', ['$scope', '$location', '$http', '$window', 'alerts', 'user', function($scope, $location, $http, $window, alerts, user) {

    $scope.alerts = alerts;
    $scope.input = {};

    $scope.login = function() {
        $scope.waiting = true;
        $http.post('api/user/login', {
            email: $scope.input.email,
            password: $<PASSWORD>
        }).success(function(data) {
            $scope.waiting = false;
            if (data.status) {
                user.setEmail(data.email);
                user.setToken(data.token);
                $location.path('navigation');
                //$window.location.reload();
            } else {
{'fraction_non_alphanumeric': 0.17324738114423852, 'fraction_numerical': 0.0008058017727639, 'mean_word_length': 2.0857675574891235, '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': '2923803', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1434, 'n_words': 238}