<commit_before>angular.module('dcs.directives').directive('cleanSidebarEditColumn', ['session', '$timeout', function(session, $timeout) {
	return {
		restrict: 'E',
		scope: 
			{
				'tableSelection': '=',
				'onColumnChange': '&',
				showToast: '&',
				showLoadingDialog: '&',
				hideToast: '&',
				hideDialog: '&'
			},
		templateUrl: "directives/clean.sidebar.editColumn.html",
		link: function(scope, element, attr) {
			var self = this;

			scope.$watch('tableSelection', function(selection, oldSelection)
			{
				scope.shouldShow = typeof selection === 'object' && selection.columns.length == 1;
				if( scope.shouldShow && selection.columns[0] != scope.columnName )
				{
					scope.columnName = selection.columns[0];
					scope.reset();
				}
			}, true);

			self.init = function()
				{
					self.allowedAlternativeDataTypesDictionary =
					   {'int64': ['float64', 'str'],
						'float64': ['int64', 'str'],
						'object': ['datetime64', 'float64', 'int64'],
						'datetime64': ['str']};
					self.unsubscribe = session.subscribeToMetadata({}, 
						function(dataSize, columns, columnInfo)
						{
							$timeout(
								function()
								{
									scope.columns = columns;
									scope.$digest();
								}, 0, false);
						});
				};

			scope.save = function()
				{
					scope.userSetNewName();
					if(scope.validNewDataType)
						scope.requestChangeColumnDataType();
					if(scope.validNewName)
						scope.requestRenameColumn();
					scope.reset();
				};

			scope.reset = 
				function()
				{
					scope.columnDataType = session.columnInfo[scope.columnName].dataType;
					scope.allowedAlternativeDataTypes = self.allowedAlternativeDataTypesDictionary[scope.columnDataType];
					scope.newName = "";
					scope.newDataType = "";
					scope.editColumnForm.$setPristine();
				};

			scope.requestRenameColumn = 
				function()
				{
					scope.showToast({message: "Renaming column..."});
					scope.showLoadingDialog();
					session.renameColumn(scope.columnName, scope.newName, 
						function(success)
						{
							scope.hideDialog();
							if(!success)
								scope.showToast({message: "Renaming column failed.", delay: 3000});
							else
								scope.showToast({message: "Successfully renamed column. Loading changes...", delay: 3000});

							scope.columnName = scope.newName;
						}); <commit_msg>Fix bug where edit column cannot change column name<commit_after>angular.module('dcs.directives').directive('cleanSidebarEditColumn', ['session', '$timeout', function(session, $timeout) {
	return {
		restrict: 'E',
		scope: 
			{
				'tableSelection': '=',
				'onColumnChange': '&',
				showToast: '&',
				showLoadingDialog: '&',
				hideToast: '&',
				hideDialog: '&'
			},
		templateUrl: "directives/clean.sidebar.editColumn.html",
		link: function(scope, element, attr) {
			var self = this;

			scope.$watch('tableSelection', function(selection, oldSelection)
			{
				scope.shouldShow = typeof selection === 'object' && selection.columns.length == 1;
				if( scope.shouldShow && selection.columns[0] != scope.columnName )
				{
					scope.columnName = selection.columns[0];
					scope.reset();
				}
			}, true);

			self.init = function()
				{
					self.allowedAlternativeDataTypesDictionary =
					   {'int64': ['float64', 'str'],
						'float64': ['int64', 'str'],
						'object': ['datetime64', 'float64', 'int64'],
						'datetime64': ['str']};
					self.unsubscribe = session.subscribeToMetadata({}, 
						function(dataSize, columns, columnInfo)
						{
							$timeout(
								function()
								{
									scope.columns = columns;
									scope.$digest();
								}, 0, false);
						});
				};

			scope.save = function()
				{
					if(scope.validNewDataType)
						scope.requestChangeColumnDataType();
					if(scope.validNewName)
						scope.requestRenameColumn();
					scope.reset();
				};

			scope.reset = 
				function()
				{
					scope.columnDataType = session.columnInfo[scope.columnName].dataType;
					scope.allowedAlternativeDataTypes = self.allowedAlternativeDataTypesDictionary[scope.columnDataType];
					scope.newName = "";
					scope.newDataType = "";
					scope.validNewName = scope.validNewDataType = scope.canSave = false;
					scope.editColumnForm.$setPristine();
				};

			scope.requestRenameColumn = 
				function()
				{
					scope.showToast({message: "Renaming column..."});
					scope.showLoadingDialog();
					session.renameColumn(scope.columnName, scope.newName, 
						function(success)
						{
							scope.hideDialog();
							if(!success)
								scope.showToast({message: "Renaming column failed.", delay: 3000});
							else
								scope.showToast({message: "Successfully renamed column. Loading changes...", delay: 3000});

							scope.columnName = scope.newName;
						}); 
{'fraction_non_alphanumeric': 0.15199665481915117, 'fraction_numerical': 0.011708132970938742, 'mean_word_length': 2.9439406430338004, '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': '526680', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1422, 'n_words': 238}