<commit_before>app.controller(
    'MainController',
    ['$scope', '$modal', 'ModelService',
        function ($scope, $modal, ModelService) {
            $scope.projects = ModelService.getProjects();

            $scope.$on('projects:updated', function () {
                $scope.projects = ModelService.getProjects();
            });

            $scope.user = ModelService.user;

            $scope.$on('current_project:updated', function () {
                $scope.current_project = ModelService.current_project;
            });

            $scope.init_form = function(instance, form_type) {
                var proposed_instance = angular.copy(instance);
                $scope.errors = [];

                // launch form modal
                var modalInstance = $modal.open({
                    templateUrl: MODAL_URLS[form_type],
                    controller: 'ModalFormCtrl',
                    resolve: {
                        instance: function() {
                            return proposed_instance;
                        }
                    }
                });
            };
        }
    ]
);

app.controller(
    'ProjectDetailController',
    [
        '$scope',
        '$stateParams',
        '$modal',
        'ModelService',
        function ($scope, $stateParams, $modal, ModelService) {
            if (!$scope.current_project && $stateParams.hasOwnProperty('projectId')) {
                ModelService.setCurrentProjectById($stateParams.projectId);
            }
        }
    ]
);

app.controller(
    'SubjectGroupController',
    [
        '$scope',
        '$controller',
        'ModelService',
        function ($scope, $controller, ModelService) {
            // Inherit ProjectDetail scope to ensure current project is set via
            // $stateParams, important for browser refreshes & bookmarked URLs
            $controller('ProjectDetailController', {$scope: $scope});

            if ($scope.current_project) {
                $scope.subject_groups = ModelService.getSubjectGroups(
                    $scope.current_project.id
                );
            }

            $scope.$on('current_project:updated', function () {
                $scope.subject_groups = ModelService.getSubjectGroups(
                    $scope.current_project.id
                );
            });

            $scope.$on('subject_groups:updated', function () {
                $scope.subject_groups = ModelService.getSubjectGroups(
                    $scope.current_project.id
                );
            });
        }
    ]
);

app.controller(
    'SubjectController',
    [
        '$scope',
        '$controller',
        'ModelService',
        function ($scope, $controller, ModelService) {
            // Inherit ProjectDetail scope to ensure current project is set via
            // $stateParams, important for browser refreshes & bookmarked URLs
            $controller('ProjectDetailController', {$scope: $scope});

            if ($scope.current_project) {
                $scope.subjects = ModelService.getSubjects(
                    $scope.current_project.id
                );
            }

            $scope.$on('current_project:updated', function () {
                $scope.subjects = ModelService.getSubjects(
                    $scope.current_project.id
                );
            });

            $scope.$on('subjects:updated', function () {
                $scope.subjects = ModelService.getSubjects(
                    $scope.current_project.id
                );
            });
        }
    ]
);

app.controller(
    'SiteController',
    [
        '$scope',
        '$controller',
        'ModelService',
        function ($scope, $controller, ModelService) {
            // Inherit ProjectDetail scope to ensure current project is set via
            // $stateParams, important for browser refreshes & bookmarked URLs
            $controller('ProjectDetailController', {$scope: $scope});

            if ($scope.current_project) {
                $scope.sites = ModelService.getSites(
                    $scope.current_project.id
                );
            }

            $scope.$on('current_project:updated', function () {
                $scope.sites = ModelService.getSites(
                    $scope.current_project.id
                );
            });

            $scope.$on('sites:updated', function () {
                $scope.sites = ModelService.getSites(
                    $scope.current_project.id
                );
            });
        }
    ]
);

app.controller(
    'CytometerController',
    [
        '$scope',
        '$q',
        '$controller',
        'ModelService',
        function ($scope, $q, $controller, ModelService) {
            // Inherits ProjectDetailController $scope
            $controller('ProjectDetailController', {$scope: $scope});

            function populate_cytometers() {
                var sites = ModelService.getProjectSitesWithAddPermission(
                    $scope.current_project.id
                ).$promise;

                var cytometers = ModelService.getCytometers(
                    {
                        'project': $scope.current_project.id
                    }
                ).$promise;

                $q.all([sites, cytometers]).then(function (objects) {
                    $scope.cytometers = objects[1];

                    // user has add privileges on at least one site
                    if (objects[0].length > 0) {
                        $scope.can_add_data = true;
                    }

                    $scope.cytometers.forEach(function (c) {
                        c.can_modify = false;

                        for (var i=0; i<objects[0].length; i++) {
                            if (c.site == objects[0][i].id) {
                                c.can_modify = true;
                                break;
                            }
                        }

                    });
                });
            }

            if ($scope.current_project != undefined) {
                populate_cytometers();
            }
            $scope.$on('current_project:updated', function () {
                populate_cytometers();
            });

            $scope.$on('updateCytometers', function () {
                populate_cytometers();
            });
        }
    ]
);

app.controller(
    'VisitTypeController',<commit_msg>separate sites with add vs modify privileges for CytometerController<commit_after>app.controller(
    'MainController',
    ['$scope', '$modal', 'ModelService',
        function ($scope, $modal, ModelService) {
            $scope.projects = ModelService.getProjects();

            $scope.$on('projects:updated', function () {
                $scope.projects = ModelService.getProjects();
            });

            $scope.user = ModelService.user;

            $scope.$on('current_project:updated', function () {
                $scope.current_project = ModelService.current_project;
            });

            $scope.init_form = function(instance, form_type) {
                var proposed_instance = angular.copy(instance);
                $scope.errors = [];

                // launch form modal
                var modalInstance = $modal.open({
                    templateUrl: MODAL_URLS[form_type],
                    controller: 'ModalFormCtrl',
                    resolve: {
                        instance: function() {
                            return proposed_instance;
                        }
                    }
                });
            };
        }
    ]
);

app.controller(
    'ProjectDetailController',
    [
        '$scope',
        '$stateParams',
        '$modal',
        'ModelService',
        function ($scope, $stateParams, $modal, ModelService) {
            if (!$scope.current_project && $stateParams.hasOwnProperty('projectId')) {
                ModelService.setCurrentProjectById($stateParams.projectId);
            }
        }
    ]
);

app.controller(
    'SubjectGroupController',
    [
        '$scope',
        '$controller',
        'ModelService',
        function ($scope, $controller, ModelService) {
            // Inherit ProjectDetail scope to ensure current project is set via
            // $stateParams, important for browser refreshes & bookmarked URLs
            $controller('ProjectDetailController', {$scope: $scope});

            if ($scope.current_project) {
                $scope.subject_groups = ModelService.getSubjectGroups(
                    $scope.current_project.id
                );
            }

            $scope.$on('current_project:updated', function () {
                $scope.subject_groups = ModelService.getSubjectGroups(
                    $scope.current_project.id
                );
            });

            $scope.$on('subject_groups:updated', function () {
                $scope.subject_groups = ModelService.getSubjectGroups(
                    $scope.current_project.id
                );
            });
        }
    ]
);

app.controller(
    'SubjectController',
    [
        '$scope',
        '$controller',
        'ModelService',
        function ($scope, $controller, ModelService) {
            // Inherit ProjectDetail scope to ensure current project is set via
            // $stateParams, important for browser refreshes & bookmarked URLs
            $controller('ProjectDetailController', {$scope: $scope});

            if ($scope.current_project) {
                $scope.subjects = ModelService.getSubjects(
                    $scope.current_project.id
                );
            }

            $scope.$on('current_project:updated', function () {
                $scope.subjects = ModelService.getSubjects(
                    $scope.current_project.id
                );
            });

            $scope.$on('subjects:updated', function () {
                $scope.subjects = ModelService.getSubjects(
                    $scope.current_project.id
                );
            });
        }
    ]
);

app.controller(
    'SiteController',
    [
        '$scope',
        '$controller',
        'ModelService',
        function ($scope, $controller, ModelService) {
            // Inherit ProjectDetail scope to ensure current project is set via
            // $stateParams, important for browser refreshes & bookmarked URLs
            $controller('ProjectDetailController', {$scope: $scope});

            if ($scope.current_project) {
                $scope.sites = ModelService.getSites(
                    $scope.current_project.id
                );
            }

            $scope.$on('current_project:updated', function () {
                $scope.sites = ModelService.getSites(
                    $scope.current_project.id
                );
            });

            $scope.$on('sites:updated', function () {
                $scope.sites = ModelService.getSites(
                    $scope.current_project.id
                );
            });
        }
    ]
);

app.controller(
    'CytometerController',
    [
        '$scope',
        '$q',
        '$controller',
        'ModelService',
        function ($scope, $q, $controller, ModelService) {
            // Inherits ProjectDetailController $scope
            $controller('ProjectDetailController', {$scope: $scope});

            function populate_cytometers() {
                var sites_can_add = ModelService.getProjectSitesWithAddPermission(
                    $scope.current_project.id
                ).$promise;

                var sites_can_modify = ModelService.getProjectSitesWithModifyPermission(
                    $scope.current_project.id
                ).$promise;

                var cytometers = ModelService.getCytometers(
                    {
                        'project': $scope.current_project.id
                    }
                ).$promise;

                $q.all([sites_can_add, sites_can_modify, cytometers]).then(function (objects) {
                    $scope.cytometers = objects[2];

                    // user has add privileges on at least one site
                    if (objects[0].length > 0) {
                        $scope.can_add_data = true;
                    }

                    $scope.cytometers.forEach(function (c) {
                        c.can_modify = false;

                        // check if cytometer's site is in modify list
                        for (var i=0; i<objects[1].length; i++) {
                            if (c.site == objects[1][i].id) {
                                c.can_modify = true;
                                break;
                            }
                        }
                    });
                });
            }

            if ($scope.current_project != undefined) {
                populate_cytometers();
            }
            $scope.$on('current_project:updated', function () {
                populate_cytometers();
            });

            $scope.$on('updateCytometers', function () {
                populate_cytometers();
            });
        }
    ]
);

app.controller(
    'VisitTypeController',
{'fraction_non_alphanumeric': 0.110580204778157, 'fraction_numerical': 0.0009101251422070534, 'mean_word_length': 1.3669000179500987, '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': '968137', 'n_tokens_mistral': 3299, 'n_tokens_neox': 3059, 'n_words': 553}