<commit_before>define([
    'angular',
    'utils/sha512',
],
function(angular, sha) {
    'use strict';

    return function($scope, $q, User, UserDetailLoader, RoleListLoader) {
        
        $scope.initialize = function() {
            $scope.enabled = false;

            $scope.roleList = RoleListLoader();

            $scope.$on('userDetail', function(event, userId, tab) {
                if (tab === undefined) {
                    tab = 'overview';
                }

                if (userId === 0) {
                    $scope.newUser = {roles: {}};
                    for (var i in $scope.roleList) {
                        $scope.newUser.roles[$scope.roleList[i].Id] = false;
                    }
                    $scope.enabled = true;
                } else {
                    $scope.loadUser(userId);
                }

                if (tab === 'overview') {
                    $('#overview-button').tab('show');
                } else if (tab === 'profile') {
                    $('#profile-button').tab('show');
                } else if (tab === 'editProfile') {
                    $('#edit-profile-button').tab('show');
                }
            });

            $scope.$watch('user', function(user){
                if (user !== undefined) {
                    user.roles = {};
                    for (var i in $scope.roleList) {
                        user.roles[$scope.roleList[i].Id] = false;
                        var status = false;
                        for (var j in user.roleList) {
                            if (user.roleList[j].Id === $scope.roleList[i].Id) {
                                status = true;
                                break;
                            }
                        }
                        if (status === true) {
                            user.roles[$scope.roleList[i].Id] = true;
                        }
                    }
                    $scope.user = user;
                }
            });
            
            $scope.$watch('roleList', function(roleList){
                if (roleList !== undefined) {
                    $scope.roleList = roleList;
                }
            });
        };

        $scope.loadUser = function(userId) {
            $scope.user = UserDetailLoader(userId);
            $scope.enabled = true;
            $('#overview-button').tab('show');
        };

        $scope.unloadUser = function() {
            $scope.$parent.selectedUserId = null;
            $scope.user = undefined;
            $scope.enabled = false;
        };

        $scope.saveUser = function() {
            var user = {};
            var fields = ['Id', 'FirstName', 'LastName', 'Name', 'Password', 'EMail', 'PhoneNumber', 'Address'];
            for (var i = 0; i < fields.length; i = i + 1) {
                user[fields[i]] = $scope.user[fields[i]];
            }
            if (user.Password !== undefined) {
                user.Password = (new sha(user.Password, 'ASCII')).getHash('SHA-512', 'HEX');
            }
            
            if (user.Id === undefined) {
                var result = User.save(user);
                user.Id = result.Id;
            } else {
                User.update(user);
            }

            if (user.Password !== undefined) {
                User.update({Id: user.Id, Action: 'Password', NewPassword: <PASSWORD>});
            }

            if ($scope.user !== undefined) {
                for (var i in $scope.user.roles) {
                    if ($scope.user.roles[i] === true) {<commit_msg>LB-958: Modifying, Deleting, Viewing permissions, etc.-> user is being landed on a default page<commit_after>define([
    'angular',
    'utils/sha512',
],
function(angular, sha) {
    'use strict';

    return function($scope, $q, User, UserDetailLoader, RoleListLoader) {
        
        $scope.initialize = function() {
            $scope.enabled = false;

            $scope.roleList = RoleListLoader();

            $scope.$on('userDetail', function(event, userId, tab) {
                if (tab === undefined) {
                    tab = 'overview';
                }

                if (userId === 0) {
                    $scope.newUser = {roles: {}};
                    for (var i in $scope.roleList) {
                        $scope.newUser.roles[$scope.roleList[i].Id] = false;
                    }
                    $scope.enabled = true;
                } else {
                    $scope.loadUser(userId);
                }

                if (tab === 'overview') {
                    $('#overview-button').tab('show');
                } else if (tab === 'profile') {
                    $('#profile-button').tab('show');
                } else if (tab === 'editProfile') {
                    $('#edit-profile-button').tab('show');
                }
            });

            $scope.$watch('user', function(user){
                if (user !== undefined) {
                    user.roles = {};
                    for (var i in $scope.roleList) {
                        user.roles[$scope.roleList[i].Id] = false;
                        var status = false;
                        for (var j in user.roleList) {
                            if (user.roleList[j].Id === $scope.roleList[i].Id) {
                                status = true;
                                break;
                            }
                        }
                        if (status === true) {
                            user.roles[$scope.roleList[i].Id] = true;
                        }
                    }
                    $scope.user = user;
                }
            });
            
            $scope.$watch('roleList', function(roleList){
                if (roleList !== undefined) {
                    $scope.roleList = roleList;
                }
            });
        };

        $scope.loadUser = function(userId) {
            $scope.user = UserDetailLoader(userId);
            $scope.enabled = true;
            $('#overview-button').tab('show');
        };

        $scope.unloadUser = function() {
            $scope.$parent.selectedUserId = null;
            $scope.user = undefined;
            $scope.enabled = false;
        };

        $scope.saveUser = function() {
            var user = {};
            var fields = ['Id', 'FirstName', 'LastName', 'Name', 'Password', 'EMail', 'PhoneNumber', 'Address'];
            for (var i = 0; i < fields.length; i = i + 1) {
                user[fields[i]] = $scope.user[fields[i]];
            }
            if (user.Password !== undefined) {
                user.Password = (new sha(user.Password, 'ASCII')).getHash('SHA-512', 'HEX');
            }
            
            if (user.Id === undefined) {
                var result = User.save(user);
                user.Id = result.Id;
            } else {
                User.update(user);
            }

            if (user.Password !== undefined) {
                //User.update({Id: user.Id, Action: 'Password', NewPassword: <PASSWORD>.Password});
                // we have to do it without resource, because api returns error if there is unneeded data
                $http.put('/resources/HR/User/' + user.Id + '/Password', {NewPassword: <PASSWORD>.Password}).success(function(data, status, headers, config) {
                    
                });
            }

            if ($scope.user !== undefined) {
                for (var i in $scope.user.roles) {
                    if ($scope.user.roles[i] === true) {
{'fraction_non_alphanumeric': 0.1418157720344599, 'fraction_numerical': 0.002783300198807157, 'mean_word_length': 1.1238390092879258, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '2499389', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1889, 'n_words': 391}