<commit_before>'use strict';

/* Controllers */

function makeDataController(tableName) {
	return function($scope, $http, jsonRpc) {

		$scope.vars = {
			selectedIndex: -1,
			recordType: tableName,
		};

		$scope.fetchRecordList = function() {
			jsonRpc.connect("/api/sf");
			var promise = jsonRpc.call($scope.vars.recordType + "_list", {}, function(result) {
				if (result.ok) {
					$scope.data = result.data;
				} else {
					$scope.data = {};
				};
			});
			return promise;
		};
		$scope.fetchRecordList();  // And run it right away to fetch the data for our list.

		$scope.selectRow = function(index, record) {
			console.log("Called selectRow(", index, ", ", record, ")");
			$scope.vars.selectedIndex = index;
			if (index < 0) {
				$scope.vars.record = {};
			} else {
				$scope.vars.record = record;
			}
		};

		$scope.addRecord = function() {
			$scope.selectRow(-1); // Make a blank entry in the "User data" area
			// TODO: Signal the user somehow that he should type in the user data area and hit Save
			// Right now this is not intuitive, so we need some kind of visual signal
		};

		$scope.updateRecord = function(record) {
			console.log("updateRecord() called with ", record);
			if (record === undefined || record === {}) {
				// Avoid adding blank records to the database
				return null; // TODO: Or maybe just return a promise object that will do nothing...?
			}
			jsonRpc.connect("/api/sf");
			var promise = jsonRpc.call($scope.vars.recordType + "_update", {"params": record}, function(result) {
				$scope.fetchRecordList();
			});
			if (record.id === undefined) {
				// We just added a record... so clear the user data area so we can add a new one later
				$scope.record = {};
			}
			return promise;
		};

		$scope.deleteRecord = function(record) {
			console.log("deleteRecord() called with ", record);
			if ($scope.vars.selectedIndex < 0) {
				// TODO: It would be better to really disable the button, but this quick hack will work for now
				console.log("Deleting nothing since nothing is really selected");
				return null;
			}
			jsonRpc.connect("/api/sf");
			var promise = jsonRpc.call($scope.vars.recordType + "_delete", {"id": record.id}, function(result) {
				$scope.fetchRecordList();
				$scope.selectRow(-1);
			});
			return promise;
		};

	};
}

var app = angular.module('myApp', ['jsonRpc', 'myApp.directives']).
	controller('AdminCtrl', makeDataController('user'))
	.controller('MyCtrl2', [function() {
		
	}]);<commit_msg>Refactor: Add explicit dependencies to controller<commit_after>'use strict';

/* Controllers */

function makeDataController(tableName) {
	return function($scope, $http, jsonRpc) {

		$scope.vars = {
			selectedIndex: -1,
			recordType: tableName,
		};

		$scope.fetchRecordList = function() {
			jsonRpc.connect("/api/sf");
			var promise = jsonRpc.call($scope.vars.recordType + "_list", {}, function(result) {
				if (result.ok) {
					$scope.data = result.data;
				} else {
					$scope.data = {};
				};
			});
			return promise;
		};
		$scope.fetchRecordList();  // And run it right away to fetch the data for our list.

		$scope.selectRow = function(index, record) {
			console.log("Called selectRow(", index, ", ", record, ")");
			$scope.vars.selectedIndex = index;
			if (index < 0) {
				$scope.vars.record = {};
			} else {
				$scope.vars.record = record;
			}
		};

		$scope.addRecord = function() {
			$scope.selectRow(-1); // Make a blank entry in the "User data" area
			// TODO: Signal the user somehow that he should type in the user data area and hit Save
			// Right now this is not intuitive, so we need some kind of visual signal
		};

		$scope.updateRecord = function(record) {
			console.log("updateRecord() called with ", record);
			if (record === undefined || record === {}) {
				// Avoid adding blank records to the database
				return null; // TODO: Or maybe just return a promise object that will do nothing...?
			}
			jsonRpc.connect("/api/sf");
			var promise = jsonRpc.call($scope.vars.recordType + "_update", {"params": record}, function(result) {
				$scope.fetchRecordList();
			});
			if (record.id === undefined) {
				// We just added a record... so clear the user data area so we can add a new one later
				$scope.record = {};
			}
			return promise;
		};

		$scope.deleteRecord = function(record) {
			console.log("deleteRecord() called with ", record);
			if ($scope.vars.selectedIndex < 0) {
				// TODO: It would be better to really disable the button, but this quick hack will work for now
				console.log("Deleting nothing since nothing is really selected");
				return null;
			}
			jsonRpc.connect("/api/sf");
			var promise = jsonRpc.call($scope.vars.recordType + "_delete", {"id": record.id}, function(result) {
				$scope.fetchRecordList();
				$scope.selectRow(-1);
			});
			return promise;
		};

	};
}

var app = angular.module('myApp', ['jsonRpc', 'myApp.directives']).
	controller('AdminCtrl', ['$scope', '$http', 'jsonRpc', makeDataController('user')])
	.controller('MyCtrl2', [function() {
		
	}]);
{'fraction_non_alphanumeric': 0.15485148514851485, 'fraction_numerical': 0.002376237623762376, 'mean_word_length': 3.240973971452561, 'pattern_counts': {'":': 4, '<': 7, '<?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': '4028090', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1544, 'n_words': 456}