<commit_before>'use strict';

// Declare app level module which depends on filters, and services
angular.module('myApp', [
        'ngRoute',
        'btford.socket-io'
    ])

    .config(['$routeProvider', function($routeProvider) {
        $routeProvider.when('/list', {templateUrl: 'templates/list.html', controller: 'ListController'});
        $routeProvider.when('/new', {templateUrl: 'templates/detail.html', controller: 'CreateController'});
        $routeProvider.when('/edit/:userId', {templateUrl: 'templates/detail.html', controller: 'EditController'});
        $routeProvider.otherwise({redirectTo: '/list'});
    }])

    .value('app-version', '0.1')

    // create and register a uuid service
    .service ( 'uuid', [ function () {

        return {

            newUUID: function () {

                function _p8(s) {
                    var p = (Math.random().toString(16)+"000000000").substr(2,8);
                    return s ? "-" + p.substr(0,4) + "-" + p.substr(4,4) : p ;
                }

                return _p8() + _p8(true) + _p8(true) + _p8();
            }
        }
    }])

    .controller ( 'mainController', [ '$scope', 'app-version', function ( $scope,  app_version ) {

        var Cntrl = {};
        $scope.Cntrl = Cntrl;
        Cntrl.appVersion = app_version;
    }])

    .controller ( 'ListController', [ '$scope', 'socket', function ( $scope, socket ) {

        var Cntrl = {};
        $scope.Cntrl = Cntrl;

        // get users list from the server
        socket.emit ( 'getAllUsers', function ( err, data ) {

            if ( err ) {

                console.log ( err );
            }

            else {

                console.log ( "getAllUsers callback: ", data );

                Cntrl.users = data;
            }
        });

        socket.on ( 'userDeleted', function ( data ) {

            console.log ( "userDeleted: ", data );

            // update $scope.users
            Cntrl.users = window._.filter ( Cntrl.users, function ( user ) {

                return user._id !== data._id;
            });
        });

        socket.on ( 'newUserAdded', function ( data ) {

            console.log ( "newUserAdded: ", data );

            // update $scope.users
            Cntrl.users.push ( data );
        });

        socket.on ( 'userUpdated', function ( data ) {

            console.log ( "userUpdated: ", data );

            // update $scope.users
            var ix = window._.findIndex ( Cntrl.users, function ( user ) {

                return user._id === data._id;
            });

            if ( ix === -1 ) {

                Cntrl.users [ Cntrl.users.length ] = data;
            }

            else {

                Cntrl.users [ ix ] = data;
            }
        });

        $scope.$on ( '$destroy', function () {

            socket.removeListener ( 'newUserAdded' );
            socket.removeListener ( 'userUpdated' );
            socket.removeListener ( 'userDeleted' );
        })
    }])

    .controller ( 'CreateController', [ '$scope', '$location', 'socket', 'uuid', function ( $scope, $location, socket ) {

        var Cntrl = {};
        $scope.Cntrl = Cntrl;

        Cntrl.save = function () {

            // send the new user details to the server to add
            socket.emit ( 'addNewUser', Cntrl.user,  function ( err ) {

                if ( err ) {

                    console.log ( err );
                }

                else {

                    console.log ( "addNewUser callback" );
                    $location.path('/');
                }
            });
        };
    }])

    .controller ( 'EditController', [ '$scope', '$location', '$routeParams', 'socket', function ( $scope, $location, $routeParams, socket ) {

        var Cntrl = {};
        $scope.Cntrl = Cntrl;<commit_msg>Modified list controller. It now registers for updates from server only after getting a list of users from the server.<commit_after>'use strict';

// Declare app level module which depends on filters, and services
angular.module('myApp', [
        'ngRoute',
        'btford.socket-io'
    ])

    .config(['$routeProvider', function($routeProvider) {
        $routeProvider.when('/list', {templateUrl: 'templates/list.html', controller: 'ListController'});
        $routeProvider.when('/new', {templateUrl: 'templates/detail.html', controller: 'CreateController'});
        $routeProvider.when('/edit/:userId', {templateUrl: 'templates/detail.html', controller: 'EditController'});
        $routeProvider.otherwise({redirectTo: '/list'});
    }])

    .value('app-version', '0.1')

    // create and register a uuid service
    .service ( 'uuid', [ function () {

        return {

            newUUID: function () {

                function _p8(s) {
                    var p = (Math.random().toString(16)+"000000000").substr(2,8);
                    return s ? "-" + p.substr(0,4) + "-" + p.substr(4,4) : p ;
                }

                return _p8() + _p8(true) + _p8(true) + _p8();
            }
        }
    }])

    .controller ( 'mainController', [ '$scope', 'app-version', function ( $scope,  app_version ) {

        var Cntrl = {};
        $scope.Cntrl = Cntrl;
        Cntrl.appVersion = app_version;
    }])

    .controller ( 'ListController', [ '$scope', 'socket', function ( $scope, socket ) {

        var Cntrl = {};
        $scope.Cntrl = Cntrl;

        // get users list from the server
        socket.emit ( 'getAllUsers', function ( err, data ) {

            if ( err ) {

                console.log ( err );
            }

            else {

                console.log ( "getAllUsers callback: ", data );

                Cntrl.users = data;

                socket.on ( 'userDeleted', function ( data ) {

                    console.log ( "userDeleted: ", data );

                    // update $scope.users
                    Cntrl.users = window._.filter ( Cntrl.users, function ( user ) {

                        return user._id !== data._id;
                    });
                });

                socket.on ( 'newUserAdded', function ( data ) {

                    console.log ( "newUserAdded: ", data );

                    // update $scope.users
                    Cntrl.users.push ( data );
                });

                socket.on ( 'userUpdated', function ( data ) {

                    console.log ( "userUpdated: ", data );

                    // update $scope.users
                    var ix = window._.findIndex ( Cntrl.users, function ( user ) {

                        return user._id === data._id;
                    });

                    if ( ix === -1 ) {

                        Cntrl.users [ Cntrl.users.length ] = data;
                    }

                    else {

                        Cntrl.users [ ix ] = data;
                    }
                });

                $scope.$on ( '$destroy', function () {

                    socket.removeListener ( 'newUserAdded' );
                    socket.removeListener ( 'userUpdated' );
                    socket.removeListener ( 'userDeleted' );
                })
            }
        });
    }])

    .controller ( 'CreateController', [ '$scope', '$location', 'socket', 'uuid', function ( $scope, $location, socket ) {

        var Cntrl = {};
        $scope.Cntrl = Cntrl;

        Cntrl.save = function () {

            // send the new user details to the server to add
            socket.emit ( 'addNewUser', Cntrl.user,  function ( err ) {

                if ( err ) {

                    console.log ( err );
                }

                else {

                    console.log ( "addNewUser callback" );
                    $location.path('/');
                }
            });
        };
    }])

    .controller ( 'EditController', [ '$scope', '$location', '$routeParams', 'socket', function ( $scope, $location, $routeParams, socket ) {

        var Cntrl = {};
        $scope.Cntrl = Cntrl;
{'fraction_non_alphanumeric': 0.14527662777568687, 'fraction_numerical': 0.006272738677706687, 'mean_word_length': 1.4665841584158417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4173416', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2127, 'n_words': 476}