<commit_before>var app = angular.module('app', []);

app.factory('urls', function() {

	var baseApiURL = "http://localhost:8080";

	return  {
		baseApiURL: baseApiURL
	};

});

app.factory('api', function($http, urls) {
	return {
		getParentMarketGroups: function() {
			return $http.jsonp(urls.baseApiURL + "/api/inv/marketgroups/parent/null?callback=JSON_CALLBACK").then(function(result) {
				console.log("Parent Market Group Response");
				return result.data;
			});
		},
		getMarketGroupByID: function(mgID) {
			return $http.jsonp(urls.baseApiURL + "/api/inv/marketgroups/parent/" + mgID + "?callback=JSON_CALLBACK").then(function(result) {
				console.log("Market Group by Parent ID response");
				return result.data;
			});
		}
	};
});

var sidebarController = function($scope, api) {
	$scope.data = {};

	var marketGroups = new MarketGroups(api);
	marketGroups.loadParentGroups();

	$scope.data.marketGroups = marketGroups.marketGroups;
};

var MarketGroups = function(api) {
	this.api = api;
	this.marketGroups = [];
};

MarketGroups.prototype.loadParentGroups = function() {
	var self = this;

	self.api.getParentMarketGroups().then(function(result) {
		//Loop through all results creating new
		for (var i = 0; i < result.result.length; i++) {
			self.marketGroups.push(new MarketGroup(self.api, result.result[i]));
		}
	});
};


var MarketGroup = function(api, data) {
	this.api = api;
	this.data = data;
	this.isToggled = false;

	this.name = this.data.marketGroupName;
	this.children = [];

	this.showChildren = false;
	this.childGroups = [];
	this.types = [];
};


MarketGroup.prototype.loadChildren = function() {
	var self = this;

	self.api.getMarketGroupByID(self.data.marketGroupID).then(function(result) {
		for (var i = 0; i < result.result.length; i++) {
			self.children.push(new MarketGroup(self.api, result.result[i]));
		}
	});
};

MarketGroup.prototype.toggle = function() {
	console.log("Toggled");
	this.isToggled = !this.isToggled;
};


app.directive('accordian', function() {
	return {
		restrict: "E",
		replace: true,
		scope: {
			items: '='
		},
		template: "<ul class='accordian'><accordianrow ng-repeat='child in items' member='child'></accordianrow></ul>"
	};
});

app.directive('accordianrow', function($compile) {
	return {
		restrict: "E",
		replace: true,
		scope: {
			member: '='
		},
		template: "<li ng-click='member.loadChildren()'>{{ member.name }} {{ member.children.length }}</li>",
		link: function (scope, element, attrs) {
			console.log("rendering");
			console.log(scope);
			if (angular.isArray(scope.member.children)) {
				element.append("<accordian items='member.children'></accordian>");
				$compile(element.contents())(scope);
			}
		}
	};
});


app.directive('marketgroup', function() {
	return {
		restrict: "E",
		replace: true,
		scope: {
			groups: '='
		},
		template: "<div ng-repeat='mg in groups' ng-click='mg.toggle()'>{{ mg.data.marketGroupName }} <div ng-show='mg.isToggled'></div></div>",
		link: function (scope, element, attrs) {
			console.log("Here");
			if (angular.isArray(scope.groups.children) && (scope.groups.children.length > 0)) {
				console.log("Wat");
				element.append("<marketgroup groups='mg.childGroups'></collection>");
				$compile(element.contents())(scope);
			}
		}
	};
});
<commit_msg>Accordian update<commit_after>var app = angular.module('app', []);

app.factory('urls', function() {

	var baseApiURL = "http://localhost:8080";

	return  {
		baseApiURL: baseApiURL
	};

});

app.factory('api', function($http, urls) {
	return {
		getParentMarketGroups: function() {
			return $http.jsonp(urls.baseApiURL + "/api/inv/marketgroups/parent/null?callback=JSON_CALLBACK").then(function(result) {
				console.log("Parent Market Group Response");
				return result.data;
			});
		},
		getMarketGroupByID: function(mgID) {
			return $http.jsonp(urls.baseApiURL + "/api/inv/marketgroups/parent/" + mgID + "?callback=JSON_CALLBACK").then(function(result) {
				console.log("Market Group by Parent ID response");
				return result.data;
			});
		}
	};
});

var sidebarController = function($scope, api) {
	$scope.data = {};

	var marketGroups = new MarketGroups(api);
	marketGroups.loadParentGroups();

	$scope.data.marketGroups = marketGroups.marketGroups;
};

var MarketGroups = function(api) {
	this.api = api;
	this.marketGroups = [];
};

MarketGroups.prototype.loadParentGroups = function() {
	var self = this;

	self.api.getParentMarketGroups().then(function(result) {
		//Loop through all results creating new
		for (var i = 0; i < result.result.length; i++) {

			var mg = new MarketGroup(self.api, result.result[i]);
			//mg.visible = true;

			self.marketGroups.push(mg);
		}
	});
};


var MarketGroup = function(api, data) {
	this.api = api;
	this.data = data;
	this.visible = false;

	this.name = this.data.marketGroupName;
	this.children = [];
	this.childrenLoaded = false;
};


MarketGroup.prototype.loadChildren = function() {
	var self = this;

	self.api.getMarketGroupByID(self.data.marketGroupID).then(function(result) {
		for (var i = 0; i < result.result.length; i++) {
			self.children.push(new MarketGroup(self.api, result.result[i]));
		}
	});
};

MarketGroup.prototype.toggle = function() {
	console.log("Toggled");

	if (!this.childrenLoaded) {
		this.childrenLoaded = true;
		this.loadChildren();
	}

	this.visible = !this.visible;
};


app.directive('accordian', function() {
	return {
		restrict: "E",
		replace: true,
		scope: {
			items: '='
		},
		template: "<ul class='accordian'><accordianrow ng-repeat='child in items' member='child'></accordianrow></ul>"
	};
});

app.directive('accordianrow', function($compile) {
	return {
		restrict: "E",
		replace: true,
		scope: {
			member: '='
		},
		template: "<li ng-click='member.toggle(); $event.stopPropagation();' >{{ member.name }} {{ member.children.length }}</li>",
		link: function (scope, element, attrs) {
			if (angular.isArray(scope.member.children)) {
				element.append("<accordian ng-show='member.visible' items='member.children'></accordian>");
				$compile(element.contents())(scope);
			}
		}
	};
});

{'fraction_non_alphanumeric': 0.1804005252790545, 'fraction_numerical': 0.002133946158896914, 'mean_word_length': 4.307491289198606, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 26, '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': '7292744', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2051, 'n_words': 365}