<commit_before>angular
    .module('app')
    .controller('applicationController', [
        '$rootScope',
        '$scope',
        '$location',
        '$routeParams',
        'authService',
        'applicationService',
        'vendorService',
        function($rootScope, $scope, $location, $routeParams, Auth, Application, Vendor) {

            var applicationId;
            $scope.application = {};
            $scope.applications = [];


            //////////////////////////////////////////////////////////////////////////////
            /////////////////////////////// Index Action ////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////
            
            $scope.index = function() {
                Auth.canUserDoAction('list-applications');
                $scope.searchBusiness = '';
                $scope.searchVendor = '';

                // Gets all the Applications
                Application.getAll().then(function(response) {
                    $scope.applications = response;

                    // For Each Application Attach a Vendor
                    _.each($scope.applications, function(item) {
                        Vendor.getById(item.vendorId).then(function(response) {
                            item.vendor = response;
                        });
                    });
                });

                // Expose private methods on the scope object in certain controller
                // actions if we want them to be accessible
                $scope.editItem = privates.editItem;
                $scope.deleteItem = privates.deleteItem;

            };

            //////////////////////////////////////////////////////////////////////////////
            //////////////////////////////// Edit Action ////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////
            
            $scope.edit = function() {
                Auth.canUserDoAction('edit-applications');
                $scope.modelObject = Application;

                // empty application object
                $scope.application = {};
                var application = {};
                // empty logo object, or filepicker gets mad :)
                $scope.application.logo = {};

                // filepicker settings
                // @todo move to global config
                filepicker.setKey('<KEY>');

                // pick logo function
                // simple callback assigans to application logo when complete
                $scope.pickImage = function() {
                    filepicker.pick(function(FPFile) {
                        console.log(FPFile.url);
                        $scope.application.logo.original = FPFile.url;
                        $scope.$apply();
                    });
                };

                $scope.cancel = privates.viewApplicationList;
                
                // get application ID for edit pages
                applicationId = $routeParams.id;
                $scope.formAction = 'Add';

                // get and store the application 
                if (applicationId) {
                    // get the application
                    Application.getById(applicationId).then(function(response) {
                        $scope.application = response;
                    });

                    //console.log($scope.application);
                    $scope.formAction = 'Update';
                }

                // activated when user clicks the save button
                $scope.save = privates.save;

                /**
                 * Tab functions.
                 * @todo make into a direct
                 *
                 */
                $scope.activeTab = 0;
                $scope.isActiveTab = privates.isActiveTab;
                $scope.changeTab = privates.changeTab;
                
                
                // define possible statuses for our application
                // note this is not the most robust, and can easily get out of sync with the database
                // but for now it works. 
                $scope.statuses = [{
                    value: 'new',
                    label: 'New'
                }, {
                    value: 'inProgress',
                    label: 'In Progress'
                }, {
                    value: 'complete',
                    label: 'Completed'
                }, {
                    value: 'forApproval',
                    label: 'Submitted For Approval'
                }, {
                    value: 'approved',
                    label: 'Approved'
                }, {
                    value: 'denied',
                    label: 'Denied'
                }];
                
                $scope.setStatus = function(newStatus) {
                    // this is a hack??? or not, for some reason the unsavedChanges directive moves the form
                    // into a child scope, so we need to access it here, or create a function to call
                    // which will set the directive dirty and workaround the scope issues
                    if($scope.$$childTail && $scope.$$childTail.applicationForm) {
                        $scope.$$childTail.applicationForm.$setDirty();
                    }
                    // set our application status
                    $scope.application.status = newStatus;  
                };

            };<commit_msg>Fix scope issues with application controller. Add function to format for display<commit_after>angular
    .module('app')
    .controller('applicationController', [
        '$rootScope',
        '$scope',
        '$location',
        '$routeParams',
        'authService',
        'applicationService',
        'vendorService',
        function($rootScope, $scope, $location, $routeParams, Auth, Application, Vendor) {

            var applicationId;
            $scope.application = {};
            $scope.applications = [];
            
            // define possible statuses for our application
            // note this is not the most robust, and can easily get out of sync with the database
            // but for now it works. 
            var statuses = [{
                value: 'new',
                label: 'New'
            }, {
                value: 'inProgress',
                label: 'In Progress'
            }, {
                value: 'complete',
                label: 'Completed'
            }, {
                value: 'forApproval',
                label: 'Submitted For Approval'
            }, {
                value: 'approved',
                label: 'Approved'
            }, {
                value: 'denied',
                label: 'Denied'
            }];


            //////////////////////////////////////////////////////////////////////////////
            /////////////////////////////// Index Action ////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////
            
            $scope.index = function() {
                Auth.canUserDoAction('list-applications');
                $scope.searchBusiness = '';
                $scope.searchVendor = '';

                // Gets all the Applications
                Application.getAll().then(function(response) {
                    $scope.applications = response;

                    // For Each Application Attach a Vendor
                    _.each($scope.applications, function(item) {
                        Vendor.getById(item.vendorId).then(function(response) {
                            item.vendor = response;
                        });
                    });
                });
                
            
                $scope.formatStatus = function(status) {
                    var display = _.where(statuses, {value : status});
                    return display.length ? display[0].label : '';
                };

                // Expose private methods on the scope object in certain controller
                // actions if we want them to be accessible
                $scope.editItem = privates.editItem;
                $scope.deleteItem = privates.deleteItem;

            };

            //////////////////////////////////////////////////////////////////////////////
            //////////////////////////////// Edit Action ////////////////////////////////
            ////////////////////////////////////////////////////////////////////////////
            
            $scope.edit = function() {
                Auth.canUserDoAction('edit-applications');
                $scope.modelObject = Application;

                $scope.statuses = statuses;

                // empty application object
                $scope.application = {};
                var application = {};
                // empty logo object, or filepicker gets mad :)
                $scope.application.logo = {};

                // filepicker settings
                // @todo move to global config
                filepicker.setKey('<KEY>');

                // pick logo function
                // simple callback assigans to application logo when complete
                $scope.pickImage = function() {
                    filepicker.pick(function(FPFile) {
                        console.log(FPFile.url);
                        $scope.application.logo.original = FPFile.url;
                        $scope.$apply();
                    });
                };

                $scope.cancel = privates.viewApplicationList;
                
                // get application ID for edit pages
                applicationId = $routeParams.id;
                $scope.formAction = 'Add';

                // get and store the application 
                if (applicationId) {
                    // get the application
                    Application.getById(applicationId).then(function(response) {
                        $scope.application = response;
                    });

                    //console.log($scope.application);
                    $scope.formAction = 'Update';
                }

                // activated when user clicks the save button
                $scope.save = privates.save;

                /**
                 * Tab functions.
                 * @todo make into a direct
                 *
                 */
                $scope.activeTab = 0;
                $scope.isActiveTab = privates.isActiveTab;
                $scope.changeTab = privates.changeTab;
                
                
                $scope.setStatus = function(newStatus) {
                    // this is a hack??? or not, for some reason the unsavedChanges directive moves the form
                    // into a child scope, so we need to access it here, or create a function to call
                    // which will set the directive dirty and workaround the scope issues
                    if($scope.$$childTail && $scope.$$childTail.applicationForm) {
                        $scope.$$childTail.applicationForm.$setDirty();
                    }
                    // set our application status
                    $scope.application.status = newStatus;  
                };

            };
            
            
            
{'fraction_non_alphanumeric': 0.15949567977429024, 'fraction_numerical': 0.0002645036148827367, 'mean_word_length': 0.9073482428115016, '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': '2143945', 'n_tokens_mistral': 2398, 'n_tokens_neox': 2165, 'n_words': 574}