<commit_before>Collect.NodeTree = function(treeDiv, survey, disabledFilterFunction, visibleFilterFunction, startFromEntityId, hiddenFieldName, creationCompleteHandler) {
	this.treeDiv = treeDiv;
	this.survey = survey;
	this.disabledFilterFunction = disabledFilterFunction;
	this.visibleFilterFunction = visibleFilterFunction;
	this.startFromEntityId = startFromEntityId;
	this.hiddenFieldName = hiddenFieldName;
	this.creationCompleteHandler = creationCompleteHandler;
	
	this.init();
};

Collect.NodeTree.prototype.init = function() {
	var $this = this;
	$this.buildTreeNodes();
	if (this.creationCompleteHandler) {
		setTimeout(function() {
			$this.jstree.open_all();
			$this.creationCompleteHandler();
		}, 100);
	}
};

Collect.NodeTree.prototype.buildTreeNodes = function() {
	var $this = this;
	var createTreeNode = function(node) {
		var text = "[" + node.name + "]";
		if (node.label != null) {
			text += " - " + node.label;
		}
		var treeNode = {
			id: 	node.id,
			text: 	text, 
			state: 	{disabled: $this.disabledFilterFunction ? $this.disabledFilterFunction(node) : false}
		};
		if (node.type == "ENTITY") {
			var children = new Array();
			for (var idx = 0; idx < node.children.length; idx++) {
				var child = node.children[idx];
				if ($this.visibleFilterFunction == null || $this.visibleFilterFunction(child)) {
					var childTreeNode = createTreeNode(child);
					children.push(childTreeNode);
				}
			}
			treeNode.children = children;
		}
		return treeNode;
	};
	var rootNodes;
	if (this.startFromEntityId) {
		var startFromEntity = this.survey.getDefinition(this.startFromEntityId);
		rootNodes = startFromEntity.children;
	} else {
		rootNodes = this.survey.rootEntities;
	}
	var rootTreeNodes = new Array();
	for (var idx = 0; idx < rootNodes.length; idx++) {
		var rootEntity = rootNodes[idx];
		if ($this.visibleFilterFunction == null || $this.visibleFilterFunction(rootEntity)) {
			rootTreeNodes.push(createTreeNode(rootEntity));
		}
	}
	var jstree = this.treeDiv.jstree({<commit_msg>Show icon in node tree<commit_after>Collect.NodeTree = function(treeDiv, survey, disabledFilterFunction, visibleFilterFunction, startFromEntityId, hiddenFieldName, creationCompleteHandler) {
	this.treeDiv = treeDiv;
	this.survey = survey;
	this.disabledFilterFunction = disabledFilterFunction;
	this.visibleFilterFunction = visibleFilterFunction;
	this.startFromEntityId = startFromEntityId;
	this.hiddenFieldName = hiddenFieldName;
	this.creationCompleteHandler = creationCompleteHandler;
	
	this.init();
};

Collect.NodeTree.prototype.init = function() {
	var $this = this;
	$this.buildTreeNodes();
	if (this.creationCompleteHandler) {
		setTimeout(function() {
			$this.jstree.open_all();
			$this.creationCompleteHandler();
		}, 100);
	}
};

Collect.NodeTree.prototype.buildTreeNodes = function() {
	var $this = this;
	var createTreeNode = function(node) {
		var text = "[" + node.name + "]";
		if (node.label != null) {
			text += " - " + node.label;
		}
		var imagesFolder = "assets/images/node_types/";
		var treeNode = {
			id: 	node.id,
			text: 	text, 
			state: 	{disabled: $this.disabledFilterFunction ? $this.disabledFilterFunction(node) : false},
			icon: imagesFolder + (node.type == "ENTITY" ? "form" : node.attributeType.toLocaleLowerCase()) + "-small.png"
		};
		if (node.type == "ENTITY") {
			var children = new Array();
			for (var idx = 0; idx < node.children.length; idx++) {
				var child = node.children[idx];
				if ($this.visibleFilterFunction == null || $this.visibleFilterFunction(child)) {
					var childTreeNode = createTreeNode(child);
					children.push(childTreeNode);
				}
			}
			treeNode.children = children;
		}
		return treeNode;
	};
	var rootNodes;
	if (this.startFromEntityId) {
		var startFromEntity = this.survey.getDefinition(this.startFromEntityId);
		rootNodes = startFromEntity.children;
	} else {
		rootNodes = this.survey.rootEntities;
	}
	var rootTreeNodes = new Array();
	for (var idx = 0; idx < rootNodes.length; idx++) {
		var rootEntity = rootNodes[idx];
		if ($this.visibleFilterFunction == null || $this.visibleFilterFunction(rootEntity)) {
			rootTreeNodes.push(createTreeNode(rootEntity));
		}
	}
	var jstree = this.treeDiv.jstree({
{'fraction_non_alphanumeric': 0.13399857448325017, 'fraction_numerical': 0.0023758612497030173, 'mean_word_length': 4.510471204188482, 'pattern_counts': {'":': 0, '<': 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': '4044471', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1345, 'n_words': 263}