<commit_before>'use strict';

ords.controller('databaseController', function ($rootScope, $scope, $q, $location, $routeParams, AuthService, Project, ProjectDatabase, User, growl, gettextCatalog) {
	
	//
	// This page doesn't make sense to view
	// without being logged in, so redirect
	// back to the home view
	//
	AuthService.check();

	//
	// Get the current Project
	//
	$scope.project = Project.get({ id: $routeParams.id });
	
	//
	// Get the Project Database
	//	
	$scope.getDatabase = function(){
		ProjectDatabase.get(
			{id:$routeParams.id, databaseId: $routeParams.databaseId },
			function(response){	
				$scope.database = response;
				//
				// Physical Databases
				//					
				for (var i = 0; i < $scope.database.databaseVersions.length; i++){
				
					//
					// MAIN
					//
					if ($scope.database.databaseVersions[i].databaseType === "MAIN"){
						$scope.main = $scope.database.databaseVersions[i];
					}
	
					//
					// MILESTONE
					//
					if ($scope.database.databaseVersions[i].databaseType === "MILESTONE"){
						$scope.milestone = $scope.database.databaseVersions[i];
					}
	
					//
					// TEST
					//
					if ($scope.database.databaseVersions[i].databaseType === "TEST"){
						$scope.test = $scope.database.databaseVersions[i];
					}
				}
			
			
				//
				// Indicate everything is now loaded
				//
				$q.all([
				    $scope.database.$promise,
				    $scope.project.$promise,
				]).then(function() { 
				    $scope.allLoaded = true;
				});
			}
		);
	}
	
	$scope.submitDatabaseForm = function(){
		$scope.database.databaseProjectId = $scope.project.projectId;
		$scope.database.databaseType = "relational";
		$scope.database.numberOfPhysicalDatabases = 0;
		
		//
		// Create or Update?
		//
		if ($routeParams.databaseId){
			$scope.updateDatabase();
		} else {
			$scope.createDatabase();
			
		}
	}
	
	$scope.updateDatabase = function(){
		ProjectDatabase.update(
			{
				id:$scope.project.projectId, 
				databaseId: $routeParams.databaseId
			},
			$scope.database, 
			function(response){
				growl.success( gettextCatalog.getString("ProDbPut200") );
				$location.path("#/project/"+$scope.project.projectId);
			},
			function(response){
				
				if (response.status === 400) { growl.error( gettextCatalog.getString("ProDbPut400") ) };
				if (response.status === 403) { growl.error( gettextCatalog.getString("Gen403") ) };
				if (response.status === 404) { growl.error( gettextCatalog.getString("ProDbPut404") ) };
				if (response.status === 410) { growl.error( gettextCatalog.getString("Gen410") ) };
				if (response.status === 500) { growl.error( gettextCatalog.getString("Gen500") ) };
				
				$location.path("#/project/"+$scope.project.projectId);
			}
		);
	}
	
	$scope.createDatabase = function(){
		ProjectDatabase.save(
			{
				id:$scope.project.projectId
			},
			$scope.database, 
			function(response){
				growl.success( gettextCatalog.getString("ProDbPost201") );
				$location.path("#/project/"+$scope.project.projectId);
			},
			function(response){
				
				if (response.status === 400) { growl.error( gettextCatalog.getString("ProDbPost400") ) };
				if (response.status === 403) { growl.error( gettextCatalog.getString("Gen403") ) };
				if (response.status === 404) { growl.error( gettextCatalog.getString("ProDbPost404") ) };
				if (response.status === 410) { growl.error( gettextCatalog.getString("Gen410") ) };
				if (response.status === 500) { growl.error( gettextCatalog.getString("Gen500") ) };
				
				$location.path("#/project/"+$scope.project.projectId);
			}
		);
	}
	
	
	//
	// Delete logical DB
	//
	$scope.deleteDatabase = function(){
		
		//
		// Delete the ProjectDatabase
		//
		ProjectDatabase.delete(
			{id:$routeParams.id, databaseId: $routeParams.databaseId },
			function(){
				growl.success( gettextCatalog.getString("ProDbDelete200") );
				
				//
				// Delete database versions
				// 
				$scope.deleteMainDatabase();
				$scope.deleteMilestoneDatabase ();
				$scope.deleteTestDatabase();
				
				//
				// Show project view
				//
				$location.path("/project/"+$scope.project.projectId);<commit_msg>corrected the redirect path<commit_after>'use strict';

ords.controller('databaseController', function ($rootScope, $scope, $q, $location, $routeParams, AuthService, Project, ProjectDatabase, User, growl, gettextCatalog) {
	
	//
	// This page doesn't make sense to view
	// without being logged in, so redirect
	// back to the home view
	//
	AuthService.check();

	//
	// Get the current Project
	//
	$scope.project = Project.get({ id: $routeParams.id });
	
	//
	// Get the Project Database
	//	
	$scope.getDatabase = function(){
		ProjectDatabase.get(
			{id:$routeParams.id, databaseId: $routeParams.databaseId },
			function(response){	
				$scope.database = response;
				//
				// Physical Databases
				//					
				for (var i = 0; i < $scope.database.databaseVersions.length; i++){
				
					//
					// MAIN
					//
					if ($scope.database.databaseVersions[i].databaseType === "MAIN"){
						$scope.main = $scope.database.databaseVersions[i];
					}
	
					//
					// MILESTONE
					//
					if ($scope.database.databaseVersions[i].databaseType === "MILESTONE"){
						$scope.milestone = $scope.database.databaseVersions[i];
					}
	
					//
					// TEST
					//
					if ($scope.database.databaseVersions[i].databaseType === "TEST"){
						$scope.test = $scope.database.databaseVersions[i];
					}
				}
			
			
				//
				// Indicate everything is now loaded
				//
				$q.all([
				    $scope.database.$promise,
				    $scope.project.$promise,
				]).then(function() { 
				    $scope.allLoaded = true;
				});
			}
		);
	}
	
	$scope.submitDatabaseForm = function(){
		$scope.database.databaseProjectId = $scope.project.projectId;
		$scope.database.databaseType = "relational";
		$scope.database.numberOfPhysicalDatabases = 0;
		
		//
		// Create or Update?
		//
		if ($routeParams.databaseId){
			$scope.updateDatabase();
		} else {
			$scope.createDatabase();
			
		}
	}
	
	$scope.updateDatabase = function(){
		ProjectDatabase.update(
			{
				id:$scope.project.projectId, 
				databaseId: $routeParams.databaseId
			},
			$scope.database, 
			function(response){
				growl.success( gettextCatalog.getString("ProDbPut200") );
				$location.path("#/project/"+$scope.project.projectId);
			},
			function(response){
				
				if (response.status === 400) { growl.error( gettextCatalog.getString("ProDbPut400") ) };
				if (response.status === 403) { growl.error( gettextCatalog.getString("Gen403") ) };
				if (response.status === 404) { growl.error( gettextCatalog.getString("ProDbPut404") ) };
				if (response.status === 410) { growl.error( gettextCatalog.getString("Gen410") ) };
				if (response.status === 500) { growl.error( gettextCatalog.getString("Gen500") ) };
				
				$location.path("/project/"+$scope.project.projectId);
			}
		);
	}
	
	$scope.createDatabase = function(){
		ProjectDatabase.save(
			{
				id:$scope.project.projectId
			},
			$scope.database, 
			function(response){
				growl.success( gettextCatalog.getString("ProDbPost201") );
				$location.path("/project/"+$scope.project.projectId);
			},
			function(response){
				
				if (response.status === 400) { growl.error( gettextCatalog.getString("ProDbPost400") ) };
				if (response.status === 403) { growl.error( gettextCatalog.getString("Gen403") ) };
				if (response.status === 404) { growl.error( gettextCatalog.getString("ProDbPost404") ) };
				if (response.status === 410) { growl.error( gettextCatalog.getString("Gen410") ) };
				if (response.status === 500) { growl.error( gettextCatalog.getString("Gen500") ) };
				
				$location.path("/project/"+$scope.project.projectId);
			}
		);
	}
	
	
	//
	// Delete logical DB
	//
	$scope.deleteDatabase = function(){
		
		//
		// Delete the ProjectDatabase
		//
		ProjectDatabase.delete(
			{id:$routeParams.id, databaseId: $routeParams.databaseId },
			function(){
				growl.success( gettextCatalog.getString("ProDbDelete200") );
				
				//
				// Delete database versions
				// 
				$scope.deleteMainDatabase();
				$scope.deleteMilestoneDatabase ();
				$scope.deleteTestDatabase();
				
				//
				// Show project view
				//
				$location.path("/project/"+$scope.project.projectId);
{'fraction_non_alphanumeric': 0.16535433070866143, 'fraction_numerical': 0.01720169594185342, 'mean_word_length': 2.9351763584366064, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1789432', 'n_tokens_mistral': 3379, 'n_tokens_neox': 2586, 'n_words': 418}