<commit_before>'use strict';

/* Directives */

angular.module('cycle.directives', [])
.directive('cycleTree', function() {
	return {
		restrict: "A",
		replace: false,
		transclude: false,
		require: '?connector',
		scope: {
			'connector' : "=",
			'selected' : "=",
			'id' : "@"	
		},
		link: function(scope, element, attrs, model) {
			
			require(["dojo/ready", 
			         "dojo/_base/window",
			         "dojo/_base/array",
			         "dojo/store/Memory",
			         "dijit/tree/ObjectStoreModel", 
			         "dijit/Tree",
			         "dojo/store/Observable",
			         "dojo/request",
			         "dijit/registry"], function(ready, window, array, Memory, ObjectStoreModel, Tree, Observable, request, registry) {
				ready(function () {
					
					scope.$watch("connector", function (newValue , oldValue) {
				    	if (newValue != undefined && newValue != oldValue) {
				    		
							request.get(APP_ROOT+"secured/connector/" + newValue.connectorId + "/tree/root", {
					            handleAs: "json"
					        }).then(function(requestData){
								
								var memoryStore = new Memory({
							        data: requestData,
							        getChildren: function(object) {
							        	return request.post(APP_ROOT+"secured/connector/" + newValue.connectorId + "/tree/children", {
								            data : {"parent" : object.name, "parentPath" : object.path},
							        		handleAs: "json"
								        }).then(function(childData){
								        	/**
								        	 * Dojo Tree will behave strange / loop forever without id attribute
								        	 */
								        	array.forEach(childData, function (entry, index) {
								        		entry["id"] = entry["name"];
								        	});
								        	return childData;
								        });
							        }
							    });
								
								var observableStore = new Observable(memoryStore);
								
								// Create the model
							    var treeModel = new ObjectStoreModel({
							        store: observableStore,
							        query: {name: '/'},
							        labelAttr : "label",
							        mayHaveChildren: function(item){
							            return item.type=="FOLDER";
							        }
							    });
							    
							    var treeWidget = registry.byId(attrs.id);
							    if (treeWidget != undefined) {
							    	registry.byId(attrs.id).destroy();
	                                registry.remove(attrs.id);
							    }
							    
							    var tree = new Tree({
							      	id :  attrs.id,
							           model: treeModel,
							           openOnClick: true,
								       onClick: function(item){
								    	   scope.selected = item;
								    	   scope.$digest();
							           }
							       });
							    tree.placeAt(element[0]);
							    tree.startup();
							},
							function(error){
								console.log("An error occurred: " + error);
								alert(error);
							});
				    	}
				    });
				});
			});<commit_msg>don't save state for tree<commit_after>'use strict';

/* Directives */

angular.module('cycle.directives', [])
.directive('cycleTree', function() {
	return {
		restrict: "A",
		replace: false,
		transclude: false,
		require: '?connector',
		scope: {
			'connector' : "=",
			'selected' : "=",
			'id' : "@"	
		},
		link: function(scope, element, attrs, model) {
			
			require(["dojo/ready", 
			         "dojo/_base/window",
			         "dojo/_base/array",
			         "dojo/store/Memory",
			         "dijit/tree/ObjectStoreModel", 
			         "dijit/Tree",
			         "dojo/store/Observable",
			         "dojo/request",
			         "dijit/registry"], function(ready, window, array, Memory, ObjectStoreModel, Tree, Observable, request, registry) {
				ready(function () {
					
					scope.$watch("connector", function (newValue , oldValue) {
				    	if (newValue != undefined && newValue != oldValue) {
				    		
							request.get(APP_ROOT+"secured/connector/" + newValue.connectorId + "/tree/root", {
					            handleAs: "json"
					        }).then(function(requestData){
								
								var memoryStore = new Memory({
							        data: requestData,
							        getChildren: function(object) {
							        	return request.post(APP_ROOT+"secured/connector/" + newValue.connectorId + "/tree/children", {
								            data : {"parent" : object.name, "parentPath" : object.path},
							        		handleAs: "json"
								        }).then(function(childData){
								        	/**
								        	 * Dojo Tree will behave strange / loop forever without id attribute
								        	 */
								        	array.forEach(childData, function (entry, index) {
								        		entry["id"] = entry["name"];
								        	});
								        	return childData;
								        });
							        }
							    });
								
								var observableStore = new Observable(memoryStore);
								
								// Create the model
							    var treeModel = new ObjectStoreModel({
							        store: observableStore,
							        query: {name: '/'},
							        labelAttr : "label",
							        mayHaveChildren: function(item){
							            return item.type=="FOLDER";
							        }
							    });
							    
							    var treeWidget = registry.byId(attrs.id);
							    if (treeWidget != undefined) {
							    	registry.byId(attrs.id).destroy();
	                                registry.remove(attrs.id);
							    }
							    
							    var tree = new Tree({
							      	id :  attrs.id,
							           model: treeModel,
							           openOnClick: true,
								       onClick: function(item){
								    	   scope.selected = item;
								    	   scope.$digest();
							           },
							           showRoot: false,
							           persist: false
							       });
							    tree.placeAt(element[0]);
							    tree.startup();
							},
							function(error){
								console.log("An error occurred: " + error);
								alert(error);
							});
				    	}
				    });
				});
			});
{'fraction_non_alphanumeric': 0.1293060409385921, 'fraction_numerical': 0.0003328340822100183, 'mean_word_length': 1.3953766440813073, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6806342', 'n_tokens_mistral': 2524, 'n_tokens_neox': 1560, 'n_words': 304}