<commit_before>'use strict';

angular.module('admin').controller('applicationController', ['$scope', 'ngTableParams', '$http', 'eventSelector', '$filter', '$window', '$location', 'usSpinnerService', '$timeout', '$sce', '$modal', 'Authentication',
	function($scope, ngTableParams, $http, eventSelector, $filter, $window, $location, usSpinnerService, $timeout, $sce, $modal, Authentication) {
		if(!Authentication.user || _.intersection(Authentication.user.roles, ['admin']).length === 0) {
			if(!Authentication.user) {
				$location.path('/signin');
			} else {
				$location.path('/');
			}
		} else {
			$scope.newCandidateEvents = [];
			$scope.candidates = [];
			$scope.selectEvents = [];
			$scope.statusIsOpen = false;		//Whether the dropdown menu for the status is open.
			$scope.candidateStatuses = ['volunteer', 'invited', 'accepted'];

			var rowUpdated = false;				//Keep track of whether data was actually changed.

			/**
			* Since the name field has multiple fields, ng-blur will not suffice.  This allows
			* the user to edit both the first name and last name before changing back to just
			* displaying the first and last name.
			*/
			$scope.$edit = {};
			$scope.$edit.lName = false;
			$scope.$edit.fName = false;
			$scope.$edit.row = -1;
			$scope.$watch('$edit.lName', function() {
				$timeout(function() {
					if(!$scope.$edit.lName && !$scope.$edit.fName && $scope.$edit.row >= 0) {
						$scope.$data[$scope.$edit.row].$edit.name = false;
						$scope.updateCandidate($scope.$data[$scope.$edit.row]._id, 'name');
					}
				}, 100);
			});
			$scope.$watch('$edit.fName', function() {
				$timeout(function() {
					if(!$scope.$edit.lName && !$scope.$edit.fName && $scope.$edit.row >= 0) {
						$scope.$data[$scope.$edit.row].$edit.name = false;
						$scope.updateCandidate($scope.$data[$scope.$edit.row]._id, 'name');
					}
				}, 100);
			});
			
			//settings for the multi select directive in form to create new candidate
			$scope.selectSettings = {
				smartButtonMaxItems: 3,
				//the name of the object field sent to the newCanidateEvents array
				externalIdProp: 'event_id',
				idProp: 'event_id',
				displayProp: 'label'
			};

			//Settings for multiselect directive in the table of candidates
			$scope.tableMsSettings = {
				smartButtonMaxItems: 1,
				externalIdProp: 'label',
				idProp: 'label',
				displayProp: 'label'
			};

			//updated the selected event from the event selector service
			$scope.$watch(
				function() {
					return eventSelector.selectedEvent;
				},
				function(selectedEvent) {
					$scope.isEventSelected = eventSelector.postEventId ? true : false;

					if($scope.isEventSelected) {
						$scope.selectedEvent = eventSelector.selectedEvent;
						$scope.selectedEvent = selectedEvent;
						$scope.getCandidates();
					}
				}
			);

			$http.get('/events/enumerateAll').success(function(data) {
				//formats the event data for the multiselect directive
				for (var i=0;i<data.length;i++) {
					$scope.selectEvents.push({label:data[i].name, event_id:data[i]._id});
				}
			}).error(function(data) {
				$scope.selectEvents = [];
				$scope.selectEvents[0] = {label : "Error", event_id : "error"};
			});

			$scope.getCandidates = function() {
				$http.post('/candidate/getCandidatesByEvent', {event_id:eventSelector.postEventId}).success(function(data) {
					for(var i = 0; i < data.length; i++) {
						data[i].displayName = data[i].lName + ", " + data[i].fName;
					}
					
					$scope.candidates = [];
					$scope.candidates = data;

					rowUpdated = false;
				}).error(function(error, status) {
					/**
					* If the error was not an authentication problem, try reloading the data.  If the problem
					* was related to authentication, the interceptor will take care of routing the user.
					* Problems related to no events existing will be treated the same way for now from here.
					*/
					if(status !== 401 && $location.path()=== "/leaderboard") {
						$timeout(function() {
							$scope.getCandidates();
						}, 5000);
					}
				});
			};

			$scope.addCandidate = function(newCandidate) {
				if($scope.newCandidateEvents.length > 0) {
					newCandidate.events = [];
					for (var i = 0; i < $scope.newCandidateEvents.length; i++) {
						newCandidate.events.push($scope.newCandidateEvents[i].event_id);
					}

					$http.post('/candidate/setCandidate',newCandidate).success(function() {
						//Refresh table view
						$scope.getCandidates();

						//Reset the form
						$scope.candidateForm.$setPristine(true);
						$scope.newCandidate = {};
						$scope.newCanidateEvents = [];
					}).error(function(res, status) {
						//Warn the user iff there wasn't an authentication issue (window.alert will keep the page from redirecting immediately).
						if(status !== 401) {<commit_msg>Fixed issues that kept applications table from updating properly.<commit_after>'use strict';

angular.module('admin').controller('applicationController', ['$scope', 'ngTableParams', '$http', 'eventSelector', '$filter', '$window', '$location', 'usSpinnerService', '$timeout', '$sce', '$modal', 'Authentication',
	function($scope, ngTableParams, $http, eventSelector, $filter, $window, $location, usSpinnerService, $timeout, $sce, $modal, Authentication) {
		if(!Authentication.user || _.intersection(Authentication.user.roles, ['admin']).length === 0) {
			if(!Authentication.user) {
				$location.path('/signin');
			} else {
				$location.path('/');
			}
		} else {
			$scope.newCandidateEvents = [];
			$scope.candidates = [];
			$scope.selectEvents = [];
			$scope.statusIsOpen = false;		//Whether the dropdown menu for the status is open.
			$scope.candidateStatuses = ['volunteer', 'invited', 'accepted'];

			var rowUpdated = false;				//Keep track of whether data was actually changed.

			/**
			* Since the name field has multiple fields, ng-blur will not suffice.  This allows
			* the user to edit both the first name and last name before changing back to just
			* displaying the first and last name.
			*/
			$scope.$edit = {};
			$scope.$edit.lName = false;
			$scope.$edit.fName = false;
			$scope.$edit.row = -1;
			$scope.$watch('$edit.lName', function() {
				$timeout(function() {
					if(!$scope.$edit.lName && !$scope.$edit.fName && $scope.$edit.row >= 0) {
						$scope.$data[$scope.$edit.row].$edit.name = false;
						$scope.updateCandidate($scope.$data[$scope.$edit.row]._id, 'name');
					}
				}, 100);
			});
			$scope.$watch('$edit.fName', function() {
				$timeout(function() {
					if(!$scope.$edit.lName && !$scope.$edit.fName && $scope.$edit.row >= 0) {
						$scope.$data[$scope.$edit.row].$edit.name = false;
						$scope.updateCandidate($scope.$data[$scope.$edit.row]._id, 'name');
					}
				}, 100);
			});
			
			//settings for the multi select directive in form to create new candidate
			$scope.selectSettings = {
				smartButtonMaxItems: 3,
				//the name of the object field sent to the newCanidateEvents array
				externalIdProp: 'event_id',
				idProp: 'event_id',
				displayProp: 'label'
			};

			//Settings for multiselect directive in the table of candidates
			$scope.tableMsSettings = {
				smartButtonMaxItems: 1,
				externalIdProp: 'label',
				idProp: 'label',
				displayProp: 'label'
			};

			//updated the selected event from the event selector service
			$scope.$watch(
				function() {
					return eventSelector.selectedEvent;
				},
				function(selectedEvent) {
					$scope.isEventSelected = eventSelector.postEventId ? true : false;

					if($scope.isEventSelected) {
						$scope.selectedEvent = eventSelector.selectedEvent;
						$scope.selectedEvent = selectedEvent;
						$scope.getCandidates(true);
					}
				}
			);

			$http.get('/events/enumerateAll').success(function(data) {
				//formats the event data for the multiselect directive
				for (var i=0;i<data.length;i++) {
					$scope.selectEvents.push({label:data[i].name, event_id:data[i]._id});
				}
			}).error(function(data) {
				$scope.selectEvents = [];
				$scope.selectEvents[0] = {label : "Error", event_id : "error"};
			});

			$scope.getCandidates = function(eventChanged) {
				$http.post('/candidate/getCandidatesByEvent', {event_id:eventSelector.postEventId}).success(function(data) {
					for(var i = 0; i < data.length; i++) {
						data[i].displayName = data[i].lName + ", " + data[i].fName;
					}
					
					$scope.candidates = [];
					$scope.candidates = data;

					rowUpdated = false;
				}).error(function(error, status) {
					if(eventChanged || error.message === "No candidates found.") {
						$scope.candidates = [];
					}
					
					/**
					* If the error was not an authentication problem, try reloading the data.  If the problem
					* was related to authentication, the interceptor will take care of routing the user.
					* Problems related to no events existing will be treated the same way for now from here.
					*/
					if(status !== 401 && $location.path()=== "/leaderboard") {
						$timeout(function() {
							$scope.getCandidates();
						}, 5000);
					}
				});
			};

			$scope.addCandidate = function(newCandidate) {
				if($scope.newCandidateEvents.length > 0) {
					newCandidate.events = [];
					for (var i = 0; i < $scope.newCandidateEvents.length; i++) {
						newCandidate.events.push($scope.newCandidateEvents[i].event_id);
					}

					$http.post('/candidate/setCandidate',newCandidate).success(function() {
						//Refresh table view
						$scope.getCandidates();

						//Reset the form
						$scope.candidateForm.$setPristine(true);
						$scope.newCandidate = {};
						$scope.newCanidateEvents = [];
					}).error(function(res, status) {
						//Warn the user iff there wasn't an authentication issue (window.alert will keep the page from redirecting immediately).
						if(status !== 401) {
{'fraction_non_alphanumeric': 0.15779253960143075, 'fraction_numerical': 0.005518650996423097, 'mean_word_length': 3.252933507170795, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5044038', 'n_tokens_mistral': 3839, 'n_tokens_neox': 2969, 'n_words': 698}