<commit_before>'use strict';

angular.module ('vcs')

// -------------------------------------------------------------------------
//
// controller for listing vcs
//
// -------------------------------------------------------------------------
.controller ('controllerVcList',
	['$scope', '$rootScope', '$stateParams', 'VcModel', 'NgTableParams', 'PILLARS',
	function ($scope, $rootScope, $stateParams, VcModel, NgTableParams, PILLARS) {

	//console.log ('controllerVcList is running');

	var self = this;

	//
	// map out any supporting data
	//
	self.pillars = PILLARS.map (function (e) {
		return {id:e,title:e};
	});
	self.project = $stateParams.project;

	//
	// set or reset the collection
	//
	var setData = function () {
		VcModel.forProject ($stateParams.project).then (function (data) {
			// console.log ('controllerVcList data received: ', data);
			self.collection = data;
			self.tableParams = new NgTableParams ({count: 10}, {dataset: data});
		});
	};

	//
	// listen for when to reset
	//
	var unbind = $rootScope.$on('refreshVcList', function() {
		setData();
	});
	$scope.$on('$destroy', unbind);

	//
	// finally, set the data
	//
	setData();
}])

.controller ('controllerAddTopicModal',
	['$modalInstance', '$scope', '_', '$stateParams', 'codeFromTitle', 'VcModel', 'TopicModel', 'PILLARS',
	function ($modalInstance, $scope, _, $stateParams, codeFromTitle, VcModel, TopicModel, PILLARS) {

		var self = this;
		self.data = null;
		self.current = [];
		self.currentObjs = [];
		self.project = $stateParams.project;

		TopicModel.forType('Valued Component').then( function (data) {
			self.data = data;
			$scope.$apply();
		});

		this.toggleItem = function (item) {
			// console.log("item:",item);
			var idx = self.current.indexOf(item._id);
			// console.log(idx);
			if (idx === -1) {
				self.currentObjs.push(item);
				self.current.push(item._id);
			} else {
				_.remove(self.currentObjs, {_id: item._id});
				_.remove(self.current, function(n) {return n === item._id;});
			}
		};

		this.ok = function () {
			// console.log("data:",self.currentObjs[0]);
			var savedArray = [];
			// console.log("length: ",self.currentObjs.length);
			_.each( self.currentObjs, function(obj, idx) {
				// console.log("Adding " + obj.description + " to Valued Components");
				VcModel.getNew().then(function (m) {
					m.project = $scope.project;
					m.name = obj.name;
					m.title = obj.name;
					m.type = obj.type;
					VcModel.query({project: $scope.project})
					.then(function(data) {
						// Take the end of the string, assume it's a number,
						// and increment accordingly.
						var suffix = "-1";
						if (data && data.length > 0) {
							// get the last one and slice it
							var existingCode = data[data.length-1].code.slice(-1);
							existingCode++;
							suffix = "-"+existingCode;
						}
						m.code = codeFromTitle(obj.name+"-"+m.project.code+suffix);
						// console.log("saving:",m);
						VcModel.saveCopy(m).then(function (saved) {
							savedArray.push(saved);
							if (idx === self.currentObjs.length-1) {
								// Return the collection back to the caller
								$modalInstance.close(savedArray);
							}
						});
					});
				});
			});
		};
<commit_msg>Create an artifact when a VC is created<commit_after>'use strict';

angular.module ('vcs')

// -------------------------------------------------------------------------
//
// controller for listing vcs
//
// -------------------------------------------------------------------------
.controller ('controllerVcList',
	['$scope', '$rootScope', '$stateParams', 'VcModel', 'NgTableParams', 'PILLARS',
	function ($scope, $rootScope, $stateParams, VcModel, NgTableParams, PILLARS) {

	//console.log ('controllerVcList is running');

	var self = this;

	//
	// map out any supporting data
	//
	self.pillars = PILLARS.map (function (e) {
		return {id:e,title:e};
	});
	self.project = $stateParams.project;

	//
	// set or reset the collection
	//
	var setData = function () {
		VcModel.forProject ($stateParams.project).then (function (data) {
			// console.log ('controllerVcList data received: ', data);
			self.collection = data;
			self.tableParams = new NgTableParams ({count: 10}, {dataset: data});
		});
	};

	//
	// listen for when to reset
	//
	var unbind = $rootScope.$on('refreshVcList', function() {
		setData();
	});
	$scope.$on('$destroy', unbind);

	//
	// finally, set the data
	//
	setData();
}])

.controller ('controllerAddTopicModal',
	['$modalInstance', '$scope', '_', '$stateParams', 'codeFromTitle', 'VcModel', 'TopicModel', 'PILLARS', 'ArtifactModel',
	function ($modalInstance, $scope, _, $stateParams, codeFromTitle, VcModel, TopicModel, PILLARS, ArtifactModel) {

		var self = this;
		self.data = null;
		self.current = [];
		self.currentObjs = [];
		self.project = $stateParams.project;

		TopicModel.forType('Valued Component').then( function (data) {
			self.data = data;
			$scope.$apply();
		});

		this.toggleItem = function (item) {
			// console.log("item:",item);
			var idx = self.current.indexOf(item._id);
			// console.log(idx);
			if (idx === -1) {
				self.currentObjs.push(item);
				self.current.push(item._id);
			} else {
				_.remove(self.currentObjs, {_id: item._id});
				_.remove(self.current, function(n) {return n === item._id;});
			}
		};

		this.ok = function () {
			// console.log("data:",self.currentObjs[0]);
			var savedArray = [];
			// console.log("length: ",self.currentObjs.length);
			_.each( self.currentObjs, function(obj, idx) {
				// console.log("Adding " + obj.description + " to Valued Components");
				VcModel.getNew().then(function (m) {
					m.project = $scope.project;
					m.name = obj.name;
					m.title = obj.name;
					m.type = obj.type;
					VcModel.query({project: $scope.project})
					.then(function(data) {
						// Take the end of the string, assume it's a number,
						// and increment accordingly.
						var suffix = "-1";
						if (data && data.length > 0) {
							// get the last one and slice it
							var existingCode = data[data.length-1].code.slice(-1);
							existingCode++;
							suffix = "-"+existingCode;
						}
						m.code = codeFromTitle(obj.name+"-"+m.project.code+suffix);
						// console.log("saving:",m);
						VcModel.saveCopy(m)
						.then(function (saved) {
							console.log("creating artifact for valued-component");
							ArtifactModel.newFromType('valued-component', $scope.project._id)
							.then( function (art) {
								art.name = obj.name;
								return ArtifactModel.saveModel(art);
							})
							.then( function (art) {
								console.log("created artifact of valued-component",art);
								savedArray.push(saved);
								if (idx === self.currentObjs.length-1) {
									// Return the collection back to the caller
									$modalInstance.close(savedArray);
								}
							})
							;
						});
					});
				});
			});
		};

{'fraction_non_alphanumeric': 0.21253089111789505, 'fraction_numerical': 0.0026166593981683385, 'mean_word_length': 2.4959349593495936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1208117', 'n_tokens_mistral': 2699, 'n_tokens_neox': 2180, 'n_words': 470}