<commit_before>"use strict";
var environmentsApp = soajsApp.components;
environmentsApp.controller('environmentCtrl', ['$scope', '$timeout', '$modal', 'ngDataApi', function($scope, $timeout, $modal, ngDataApi) {
	$scope.$parent.isUserLoggedIn();

	$scope.listEnvironments = function() {
		getSendDataFromServer(ngDataApi, {
			"method": "get",
			"routeName": "/dashboard/environment/list"
		}, function(error, response) {
			if(error) {
				$scope.$parent.displayAlert('danger', error.message);
			}
			else {
				var options = {
					grid: environmentConfig.grid,
					data: response,
					defaultSortField: 'code',
					left: [{
						'label': 'Edit',
						'icon': 'edit',
						'handler': 'editEnvironment'
					},
						//{
						//	'label': 'Analytics',
						//	'icon': 'analytics',
						//	'handler': 'openAnalyticsPage'
						//},
						{
							'label': 'Remove',
							'icon': 'remove',
							'msg': "Are you sure you want to remove this environment?",
							'handler': 'removeEnvironment'
						}],
					top: [{
						'label': 'Remove',
						'msg': "Are you sure you want to remove the selected environment(s)?",
						'handler': 'removeMultipleEnvironments'
					}]
				};

				buildGrid($scope, options);
			}
		});
	};

	$scope.addEnvironment = function() {
		var options = {
			timeout: $timeout,
			form: environmentConfig.form,
			name: 'addEnvironment',
			label: 'Add New Environment',
			actions: [
				{
					'type': 'submit',
					'label': 'Submit',
					'btn': 'primary',
					'action': function(formData) {
						formData.ips = formData.ips.replace(/ /g, '');
						var postData = {
							'code': formData.code,
							'description': formData.description,
							'ips': formData.ips.split(",")
						};

						getSendDataFromServer(ngDataApi, {
							"method": "send",
							"routeName": "/dashboard/environment/add",
							"data": postData
						}, function(error, response) {
							if(error) {
								$scope.form.displayAlert('danger', error.message);
							}
							else {
								$scope.$parent.displayAlert('success', 'Environment Added Successfully.');
								$scope.modalInstance.close();
								$scope.form.formData = {};
								$scope.listEnvironments();
							}
						});
					}
				},
				{
					'type': 'reset',
					'label': 'Cancel',
					'btn': 'danger',
					'action': function() {
						$scope.modalInstance.dismiss('cancel');
						$scope.form.formData = {};
					}
				}
			]
		};

		buildFormWithModal($scope, $modal, options);
	};

	$scope.editEnvironment = function(data) {
		data.ips = data.ips.join(",");
		var options = {
			timeout: $timeout,
			form: environmentConfig.form,
			'name': 'editEnvironment',
			'label': 'Edit Environment',
			'data': data,
			'actions': [
				{
					'type': 'submit',
					'label': 'Submit',
					'btn': 'primary',
					'action': function(formData) {
						formData.ips = formData.ips.replace(/ /g, '');
						var postData = {
							'code': formData.code,
							'description': formData.description,
							'ips': formData.ips.split(",")
						};

						getSendDataFromServer(ngDataApi, {
							"method": "send",
							"routeName": "/dashboard/environment/update",
							"params": {"id": data['_id']},
							"data": postData
						}, function(error, response) {
							if(error) {
								$scope.form.displayAlert('danger', error.message);
							}
							else {
								$scope.$parent.displayAlert('success', 'Environment Updated Successfully.');
								$scope.modalInstance.close();
								$scope.form.formData = {};
								$scope.listEnvironments();
							}
						});
					}
				},
				{
					'type': 'cancel',
					'label': 'Cancel',
					'btn': 'danger',
					'action': function() {
						$scope.modalInstance.dismiss('cancel');
						$scope.form.formData = {};
					}
				}]<commit_msg>fixed a bug in edit environments<commit_after>"use strict";
var environmentsApp = soajsApp.components;
environmentsApp.controller('environmentCtrl', ['$scope', '$timeout', '$modal', 'ngDataApi', function($scope, $timeout, $modal, ngDataApi) {
	$scope.$parent.isUserLoggedIn();

	$scope.listEnvironments = function() {
		getSendDataFromServer(ngDataApi, {
			"method": "get",
			"routeName": "/dashboard/environment/list"
		}, function(error, response) {
			if(error) {
				$scope.$parent.displayAlert('danger', error.message);
			}
			else {
				var options = {
					grid: environmentConfig.grid,
					data: response,
					defaultSortField: 'code',
					left: [{
						'label': 'Edit',
						'icon': 'edit',
						'handler': 'editEnvironment'
					},
						//{
						//	'label': 'Analytics',
						//	'icon': 'analytics',
						//	'handler': 'openAnalyticsPage'
						//},
						{
							'label': 'Remove',
							'icon': 'remove',
							'msg': "Are you sure you want to remove this environment?",
							'handler': 'removeEnvironment'
						}],
					top: [{
						'label': 'Remove',
						'msg': "Are you sure you want to remove the selected environment(s)?",
						'handler': 'removeMultipleEnvironments'
					}]
				};

				buildGrid($scope, options);
			}
		});
	};

	$scope.addEnvironment = function() {
		var options = {
			timeout: $timeout,
			form: environmentConfig.form,
			name: 'addEnvironment',
			label: 'Add New Environment',
			actions: [
				{
					'type': 'submit',
					'label': 'Submit',
					'btn': 'primary',
					'action': function(formData) {
						formData.ips = formData.ips.replace(/ /g, '');
						var postData = {
							'code': formData.code,
							'description': formData.description,
							'ips': formData.ips.split(",")
						};

						getSendDataFromServer(ngDataApi, {
							"method": "send",
							"routeName": "/dashboard/environment/add",
							"data": postData
						}, function(error, response) {
							if(error) {
								$scope.form.displayAlert('danger', error.message);
							}
							else {
								$scope.$parent.displayAlert('success', 'Environment Added Successfully.');
								$scope.modalInstance.close();
								$scope.form.formData = {};
								$scope.listEnvironments();
							}
						});
					}
				},
				{
					'type': 'reset',
					'label': 'Cancel',
					'btn': 'danger',
					'action': function() {
						$scope.modalInstance.dismiss('cancel');
						$scope.form.formData = {};
					}
				}
			]
		};

		buildFormWithModal($scope, $modal, options);
	};

	$scope.editEnvironment = function(data) {
		var formConfig = angular.copy(environmentConfig.form);
		formConfig.entries[0].type = 'readonly';
		var myData = angular.copy(data);
		myData.ips = myData.ips.join(",");
		var options = {
			timeout: $timeout,
			form: formConfig,
			'name': 'editEnvironment',
			'label': 'Edit Environment',
			'data': myData,
			'actions': [
				{
					'type': 'submit',
					'label': 'Submit',
					'btn': 'primary',
					'action': function(formData) {
						formData.ips = formData.ips.replace(/ /g, '');
						var postData = {
							'description': formData.description,
							'ips': formData.ips.split(",")
						};

						getSendDataFromServer(ngDataApi, {
							"method": "send",
							"routeName": "/dashboard/environment/update",
							"params": {"id": data['_id']},
							"data": postData
						}, function(error, response) {
							if(error) {
								$scope.form.displayAlert('danger', error.message);
							}
							else {
								$scope.$parent.displayAlert('success', 'Environment Updated Successfully.');
								$scope.modalInstance.close();
								$scope.form.formData = {};
								$scope.listEnvironments();
							}
						});
					}
				},
				{
					'type': 'cancel',
					'label': 'Cancel',
					'btn': 'danger',
					'action': function() {
						$scope.modalInstance.dismiss('cancel');
						$scope.form.formData = {};
					}
				}]
{'fraction_non_alphanumeric': 0.1778497409326425, 'fraction_numerical': 0.00012953367875647668, 'mean_word_length': 2.5207478340173277, 'pattern_counts': {'":': 20, '<': 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': '234303', 'n_tokens_mistral': 3512, 'n_tokens_neox': 2391, 'n_words': 451}