<commit_before>angular.module('MyApp').controller(
		'ContributionsCtrl',
		function($scope, $auth, $location, $stateParams, $alert, Contributions,
				ContributionDetail, SaveContribution, CloseContribution,
				Account, Users) {			
			var orgExists;
			
			$scope.currencyFormatting = function(value) { return value.toString() + " $"; };
			$scope.organizationId = 'notintialized';
			$scope.model = {
				title : '',
				file : '',
				owner : '',
				min_reputation_to_close : '',
				users_organizations_id : '',
				contributers : [ {
					contributer_id : '',
					contributer_percentage : '',
					contribution1: ''
				} ],
				intialBid : [ {
					tokens : '',
					reputation : ''
				} ]

			}
			
			// if not authenticated return to splash:
			if (!$auth.isAuthenticated()) {
				$location.path('splash');
			} else {
				$scope.getProfile = function() {
					Account.getProfile().success(function(data) {
						$scope.userId = data.userId;						
						orgExists = data.orgexists;
						if (orgExists == 'true') {
							$scope.users_organizations_id = data.userOrgId;
							$scope.model.users_organizations_id = data.userOrgId;
							$scope.organizationId = data.orgId;
						}
						Account.setUserData(data);

					}).error(function(error) {
						$alert({
							content : error.message,
							animation : 'fadeZoomFadeDown',
							type : 'material',
							duration : 3
						});
					});
				};

				$scope.ifOrgExists = function() {
					if (Account.getUserData() != undefined) {
						$scope.user = Account.getUserData();						
						if (Account.getUserData().orgexists == 'false') {
							orgExists = "false";
							return false;
						} else {
							orgExists = "true";
							return true;
						}
					} 

				};

				userData = Account.getUserData();
				if (userData == undefined) {
					$scope.getProfile();
				} else {
					$scope.userId = userData.userId;
					orgExists = userData.orgexists;
					if (orgExists == 'true') {
						$scope.users_organizations_id = userData.userOrgId;
						$scope.organizationId = userData.orgId;
						$scope.model.users_organizations_id = userData.userOrgId;
					}
					$scope.model.owner = userData.userId;
				}

				$scope.getOrgUsers = function() {
					$scope.data = Users.getOrg.getUsers({
						organizationId : $scope.organizationId
					});
					$scope.data.$promise.then(function(result) {
						Users.setAllOrgUsersData(result)						
						$scope.users = result;
						//$location.path("/contribution/" + result.id);
					});
				};

				allOrgUsersData = Users.getAllOrgUsersData();
				if (orgExists == 'true') {
					if (allOrgUsersData == undefined) {
						$scope.getOrgUsers();
					} else {

						$scope.users = allOrgUsersData;
					}
				}

				$scope.contributionId = $stateParams.contributionId;

				$scope.ContributionModelForView = {
					title : '',
					file : '',
					owner : '',
					min_reputation_to_close : '',
					users_organizations_id : '',
					contributionContributers : [ {
						contributer_id : '',
						contributer_percentage : ''
					} ],
					bids : [ {
						tokens : '',
						reputation : ''
					} ]
				};

				$scope.getContribution = function(entity) {
					var constributionId = 0;
					if (entity) {
						contributionId = entity.id;
					}
					console.log("get Contribution " + contributionId);
					$location.path("/contribution/" + contributionId);

				};
				
				$scope.changeContribution = function() {
					totalContribution = 0;
					allcontributers = $scope.model.contributers
					for(i=0;i<allcontributers.length;i++){
						totalContribution = totalContribution + +allcontributers[i].contribution1;
						
						
					}
					
					for(i=0;i<allcontributers.length;i++){
						allcontributers[i].contributer_percentage = (allcontributers[i].contribution1/totalContribution)*100+'%'
						
						
					}

				};


				// function definition
				$scope.onSubmit = function() {
					console.log("In Submit method");
					console.log($scope.model)
					$scope.data = SaveContribution.save({}, $scope.model);
					$scope.data.$promise.then(function(result) {
						alert('Successfully saved');
						$location.path("/bids/" + result.id);
					});
				};
				
				$scope.removeCollaboratorItem = function(index) {
					$scope.model.contributers.splice(index, 1);
			  };
				$scope.createContribution = function() {
					console.log("Create Contribution");
					console.log($scope.model);<commit_msg>sending a message to contribution_test channel on contribution creation (client side)<commit_after>angular.module('MyApp').controller(
		'ContributionsCtrl',
		function($scope, $auth, $location, $stateParams, $alert, Contributions,
				ContributionDetail, SaveContribution, CloseContribution,
				Account, Users) {			
			var orgExists;
			
			$scope.currencyFormatting = function(value) { return value.toString() + " $"; };
			$scope.organizationId = 'notintialized';
			$scope.model = {
				title : '',
				file : '',
				owner : '',
				min_reputation_to_close : '',
				users_organizations_id : '',
				contributers : [ {
					contributer_id : '',
					contributer_percentage : '',
					contribution1: ''
				} ],
				intialBid : [ {
					tokens : '',
					reputation : ''
				} ]

			}
			
			// if not authenticated return to splash:
			if (!$auth.isAuthenticated()) {
				$location.path('splash');
			} else {
				$scope.getProfile = function() {
					Account.getProfile().success(function(data) {
						$scope.userId = data.userId;						
						orgExists = data.orgexists;
						if (orgExists == 'true') {
							$scope.users_organizations_id = data.userOrgId;
							$scope.model.users_organizations_id = data.userOrgId;
							$scope.organizationId = data.orgId;
							$scope.access_token = data.access_token;
						}
						Account.setUserData(data);

					}).error(function(error) {
						$alert({
							content : error.message,
							animation : 'fadeZoomFadeDown',
							type : 'material',
							duration : 3
						});
					});
				};

				$scope.ifOrgExists = function() {
					if (Account.getUserData() != undefined) {
						$scope.user = Account.getUserData();						
						if (Account.getUserData().orgexists == 'false') {
							orgExists = "false";
							return false;
						} else {
							orgExists = "true";
							return true;
						}
					} 

				};

				userData = Account.getUserData();
				if (userData == undefined) {
					$scope.getProfile();
				} else {
					$scope.userId = userData.userId;
					orgExists = userData.orgexists;
					if (orgExists == 'true') {
						$scope.users_organizations_id = userData.userOrgId;
						$scope.organizationId = userData.orgId;
						$scope.model.users_organizations_id = userData.userOrgId;
					}
					$scope.model.owner = userData.userId;
				}

				$scope.getOrgUsers = function() {
					$scope.data = Users.getOrg.getUsers({
						organizationId : $scope.organizationId
					});
					$scope.data.$promise.then(function(result) {
						Users.setAllOrgUsersData(result)						
						$scope.users = result;
						//$location.path("/contribution/" + result.id);
					});
				};

				allOrgUsersData = Users.getAllOrgUsersData();
				if (orgExists == 'true') {
					if (allOrgUsersData == undefined) {
						$scope.getOrgUsers();
					} else {

						$scope.users = allOrgUsersData;
					}
				}

				$scope.contributionId = $stateParams.contributionId;

				$scope.ContributionModelForView = {
					title : '',
					file : '',
					owner : '',
					min_reputation_to_close : '',
					users_organizations_id : '',
					contributionContributers : [ {
						contributer_id : '',
						contributer_percentage : ''
					} ],
					bids : [ {
						tokens : '',
						reputation : ''
					} ]
				};

				$scope.getContribution = function(entity) {
					var constributionId = 0;
					if (entity) {
						contributionId = entity.id;
					}
					console.log("get Contribution " + contributionId);
					$location.path("/contribution/" + contributionId);

				};
				
				$scope.changeContribution = function() {
					totalContribution = 0;
					allcontributers = $scope.model.contributers
					for(i=0;i<allcontributers.length;i++){
						totalContribution = totalContribution + +allcontributers[i].contribution1;
						
						
					}
					
					for(i=0;i<allcontributers.length;i++){
						allcontributers[i].contributer_percentage = (allcontributers[i].contribution1/totalContribution)*100+'%'
						
						
					}

				};
				
				// ******************************* SLACK PLAY ***********************
				
				$scope.sendTestMessage = function(channelId,message) {
							console.log('sending test message to slack :'+message);

							// 'https://slack.com/api/users.list'

							var url = 'https://slack.com/api/chat.postMessage'
							console.log('url:'+url);

							var token = "<KEY>";
						//	var key = '<KEY>';
							var data = {
								token:token,
								channel:channelId,
								text:message
							}

							// TBD: move to use angularJS instead of Jquery and get rid of need to change  Host when we deploy...
							// TBD: which API ? do we get 'my borads or boards of orgenziation'
							$.ajax({
								type: "GET",
							  url: url,
							  data: data,
							  success: function(){console.log('message posted succesfulyy!')},
								persist:true,
								dataType:'JSON'
							});
				};
				
				
				$scope.gotChannels = function(data) {
					console.log('recieved Channels:');
					console.dir(data);
					
					
					// get specific channel:
					var chnls = data.channels;
					for (chnIndx in chnls){
						var chnl = chnls[chnIndx];
						console.log('chnl.name:'+chnl.name)	
						if(chnl.name == 'contributions_test'){
							console.log('is random sending ...:')	;
							
							channelId = chnl.id
							$scope.sendTestMessage(channelId,'contribution created: '+$scope.currentSavedContribution.title)
						}			
					}
				};
				
				$scope.getChannels = function() {

						console.log('getting channels using access Token:'+$scope.access_token);

						// 'https://slack.com/api/users.list'

						var url = 'https://slack.com/api/channels.list'
						console.log('url:'+url);

						var token = "<KEY>";
					//	var key = '<KEY>';
						var data = {
							token:token
							//,key:key
						}

						// TBD: move to use angularJS instead of Jquery and get rid of need to change  Host when we deploy...
						// TBD: which API ? do we get 'my borads or boards of orgenziation'
						$.ajax({
							type: "GET",
						  url: url,
						  data: data,
						  success: $scope.gotChannels,
							persist:true,
							dataType:'JSON'
						});
					
				  };

					$scope.slackPlay = function(contribution) {
						console.dir(contribution);
						$scope.currentSavedContribution = contribution
			
						console.log('sending to slack, contribution:'+$scope.currentSavedContribution.title);
						$scope.getChannels()
						
				  };
				// *****************************************************
				// function definition
				$scope.onSubmit = function() {
					console.log("In Submit method");
					console.log($scope.model)
					$scope.data = SaveContribution.save({}, $scope.model);
					$scope.data.$promise.then(function(result) {
						
						$scope.slackPlay(result);
						
						alert('Successfully saved:'+result.title);
						$location.path("/bids/" + result.id);
					});
				};
				
				$scope.removeCollaboratorItem = function(index) {
					$scope.model.contributers.splice(index, 1);
			  };
				$scope.createContribution = function() {
					console.log("Create Contribution");
					console.log($scope.model);
{'fraction_non_alphanumeric': 0.14923954372623574, 'fraction_numerical': 0.002073971655720705, 'mean_word_length': 2.4138643067846606, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 4, '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': '3086884', 'n_tokens_mistral': 5337, 'n_tokens_neox': 3553, 'n_words': 589}