<commit_before>'use strict';

formsAngular.controller('NavCtrl',['$scope', '$location', '$filter', '$locationParse', '$controller', function($scope, $location, $filter, $locationParse, $controller) {

    $scope.items = [];

    function loadMenu(controllerName, level) {
        var locals={}, addThis;

        controllerName += 'Ctrl';
        locals.$scope = $scope.scopes[level] = $scope.$new();
        try {
            $controller(controllerName, locals);
            if ($scope.routing.newRecord) {
                addThis = "creating";
            } else if ($scope.routing.id) {
                addThis = "editing";
            } else {
                addThis = "listing";
            }
            angular.forEach($scope.scopes[level].contextMenu, function(value) {
                if (value[addThis]) {
                    $scope.items.push(value);
                }
            })
        }
        catch(error) {
            if (error.message === "Argument '" + controllerName + "' is not a function, got undefined") {
                // No such controller - don't care
            } else {
                console.log("Unable to instantiate "+controllerName + " - " + error.message);
            }
        }
    }

    $scope.$on('$locationChangeSuccess', function (event, newUrl, oldUrl) {

        $scope.routing = $locationParse($location.$$path);

        $scope.items = [];

        if ($scope.routing.modelName) {

            angular.forEach($scope.scopes, function(value, key){
                value.$destroy();
            });
            $scope.scopes = [];
            // Now load context menu.  For /person/client/:id/edit we need
            // to load PersonCtrl and PersonClientCtrl
            $scope.contextMenu = $filter('titleCase')($scope.routing.modelName, true);
            loadMenu($scope.contextMenu,0);
            if ($scope.routing.formName) {
                loadMenu($scope.contextMenu + $filter('titleCase')($scope.routing.formName, true),1);
            }
        }
    });

    $scope.doClick = function(index) {
        // Performance optimization: http://jsperf.com/apply-vs-call-vs-invoke
        var args = $scope.items[index].args || [],
            fn = $scope.items[index].fn;
        switch (args.length) {
            case  0:
                return fn();
            case  1:
                return fn(args[0]);
            case  2:
                return fn(args[0], args[1]);
            case  3:
                return fn(args[0], args[1], args[2]);
            case  4:
                return fn(args[0], args[1], args[2], args[3]);
        }
    }
}]);<commit_msg>Fix stupid bug in navigation<commit_after>'use strict';

formsAngular.controller('NavCtrl',['$scope', '$location', '$filter', '$locationParse', '$controller', function($scope, $location, $filter, $locationParse, $controller) {

    $scope.items = [];

    function loadMenu(controllerName, level) {
        var locals={}, addThis;

        controllerName += 'Ctrl';
        locals.$scope = $scope.scopes[level] = $scope.$new();
        try {
            $controller(controllerName, locals);
            if ($scope.routing.newRecord) {
                addThis = "creating";
            } else if ($scope.routing.id) {
                addThis = "editing";
            } else {
                addThis = "listing";
            }
            angular.forEach($scope.scopes[level].contextMenu, function(value) {
                if (value[addThis]) {
                    $scope.items.push(value);
                }
            })
        }
        catch(error) {
            if (error.message === "Argument '" + controllerName + "' is not a function, got undefined") {
                // No such controller - don't care
            } else {
                console.log("Unable to instantiate "+controllerName + " - " + error.message);
            }
        }
    }

    $scope.$on('$locationChangeSuccess', function (event, newUrl, oldUrl) {

        $scope.routing = $locationParse($location.$$path);

        $scope.items = [];

        if ($scope.routing.modelName) {

            angular.forEach($scope.scopes, function(value, key){
                value.$destroy();
            });
            $scope.scopes = [];
            // Now load context menu.  For /person/client/:id/edit we need
            // to load PersonCtrl and PersonClientCtrl
            $scope.contextMenu = $filter('titleCase')($scope.routing.modelName, true);
            loadMenu($scope.contextMenu,0);
            if ($scope.routing.formName) {
                loadMenu($scope.contextMenu + $filter('titleCase')($scope.routing.formName, true),1);
            }
        }
    });

    $scope.doClick = function(index) {
        // Performance optimization: http://jsperf.com/apply-vs-call-vs-invoke
        var args = $scope.items[index].args || [],
            fn = $scope.items[index].fn,
            result;
        switch (args.length) {
            case  0:
                result = fn();
                break;
            case  1:
                result =  fn(args[0]);
                break;
            case  2:
                result =  fn(args[0], args[1]);
                break;
            case  3:
                result =  fn(args[0], args[1], args[2]);
                break;
            case  4:
                result =  fn(args[0], args[1], args[2], args[3]);
                break;
        }
    }
}]);
{'fraction_non_alphanumeric': 0.14588712652157876, 'fraction_numerical': 0.006270748801180376, 'mean_word_length': 1.6147540983606556, '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': '3275259', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1461, 'n_words': 292}