<commit_before>var app = angular.module('ideaBin.resourceCommentControllers', ['ngResource']);

app.controller("ResourceCommentIndexController", ['$scope', '$localStorage', 'ResourceComment', 'User', '$http',
	function($scope, $localStorage, ResourceComment, User, $http) {
		$scope.$storage = $localStorage;
		$scope.resourceComments = {};

		/**
		*	Loads all comments for a given repo. 
		*/
		$scope.$on('loadResourceComments', function(event, name){
			ResourceComment.query({path: $localStorage.repo.path + $localStorage.dir_path + name}).$promise
				.then(function(response){
						$scope.resourceComments = response;
						var users = [];
						for(var key in $scope.resourceComments){
							if(typeof $scope.resourceComments[key].id != 'undefined' && users.indexOf($scope.resourceComments[key].user_id) == -1){
								users.push($scope.resourceComments[key].user_id)
							}
						}
						
						$http.get('/users.json',
						{ params: {
								user_ids: JSON.stringify(users) // ids is [1, 2, 3, 4]
						}}
						)
					 },function(response){
								alert("there was a problem loading users for resources");
					 });
			
		});
		
		/**
		* Adds a comment to the current index of resource comments
		*/
		$scope.$on('addResourceCommentToIndex', function(event, comment){
			console.log("comment :: " + comment);
			$scope.resourceComments.push(comment);
		});
		
		/**
		*	Deletes a comment with a given comment id.
		*/
  	$scope.deleteResourceComment =  function(resource_comment_id){
			$localStorage.repo.path + $localStorage.dir_path + commentName;
			ResourceComment.delete({id: resource_comment_id});
			
			var index = $scope.resourceComments.indexOf(resource_comment_id);
			$scope.resourceComments.splice(index, 1);
		}
}]);

app.controller('ResourceCommentDetailController', ['$scope', '$localStorage', 'ResourceComment',
	function($scope, $localStorage, ResourceComment){
		$scope.updateComment = function (message){
			$scope.resourceComment.comment = message;
			if($scope.resourceComment){
				ResourceComment.update($scope.resourceComment);
			}
		}
	}
]);

app.controller('ResourceCommentCreationController', ['$scope', '$localStorage', '$rootScope', 'ResourceComment',
	function($scope, $localStorage, $rootScope, ResourceComment){
		$scope.createResourceComment = function(){
			if($localStorage.resource){
				var resourceComment = ResourceComment.create({path: $localStorage.repo.path + $localStorage.dir_path + $localStorage.resource, repo_id: $localStorage.repo.id, message: $scope.resource_comment.message});
				$rootScope.$broadcast('addResourceCommentToIndex', resourceComment);
			}
			else{
				alert("Pssst. No resource is loaded, so there is nothing to comment on");
			}
		}
		
	}
]);<commit_msg>made resource comments disapear after creation<commit_after>var app = angular.module('ideaBin.resourceCommentControllers', ['ngResource']);

app.controller("ResourceCommentIndexController", ['$scope', '$localStorage', 'ResourceComment', 'User', '$http',
	function($scope, $localStorage, ResourceComment, User, $http) {
		$scope.$storage = $localStorage;
		$scope.resourceComments = {};

		/**
		*	Loads all comments for a given repo. 
		*/
		$scope.$on('loadResourceComments', function(event, name){
			ResourceComment.query({path: $localStorage.repo.path + $localStorage.dir_path + name}).$promise
				.then(function(response){
						$scope.resourceComments = response;
						var users = [];
						for(var key in $scope.resourceComments){
							if(typeof $scope.resourceComments[key].id != 'undefined' && users.indexOf($scope.resourceComments[key].user_id) == -1){
								users.push($scope.resourceComments[key].user_id)
							}
						}
						
						$http.get('/users.json',
						{ params: {
								user_ids: JSON.stringify(users) // ids is [1, 2, 3, 4]
						}}
						)
					 },function(response){
								alert("there was a problem loading users for resources");
					 });
			
		});
		
		/**
		* Adds a comment to the current index of resource comments
		*/
		$scope.$on('addResourceCommentToIndex', function(event, comment){
			console.log("comment :: " + comment);
			$scope.resourceComments.push(comment);
		});
		
		/**
		*	Deletes a comment with a given comment id.
		*/
  	$scope.deleteResourceComment =  function(resource_comment_id){
			$localStorage.repo.path + $localStorage.dir_path + commentName;
			ResourceComment.delete({id: resource_comment_id});
			
			var index = $scope.resourceComments.indexOf(resource_comment_id);
			$scope.resourceComments.splice(index, 1);
		}
}]);

app.controller('ResourceCommentDetailController', ['$scope', '$localStorage', 'ResourceComment',
	function($scope, $localStorage, ResourceComment){
		$scope.updateComment = function (message){
			$scope.resourceComment.comment = message;
			if($scope.resourceComment){
				ResourceComment.update($scope.resourceComment);
			}
		}
	}
]);

app.controller('ResourceCommentCreationController', ['$scope', '$localStorage', '$rootScope', 'ResourceComment',
	function($scope, $localStorage, $rootScope, ResourceComment){
		$scope.createResourceComment = function(){
			if($localStorage.resource){
				var resourceComment = ResourceComment.create({path: $localStorage.repo.path + $localStorage.dir_path + $localStorage.resource, repo_id: $localStorage.repo.id, message: $scope.resource_comment.message});
				$rootScope.$broadcast('addResourceCommentToIndex', resourceComment);
				$scope.resource_comment.message = '';
			}
			else{
				alert("Pssst. No resource is loaded, so there is nothing to comment on");
			}
		}
		
	}
]);
{'fraction_non_alphanumeric': 0.15035027842644152, 'fraction_numerical': 0.002155559547332495, 'mean_word_length': 4.30791229742612, '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': '7152873', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1595, 'n_words': 312}