<commit_before>//used for the media picker dialog
angular.module("umbraco").controller("Umbraco.Dialogs.TreePickerController",
	function ($scope, entityResource, eventsService, $log, searchService, angularHelper, $timeout, localizationService) {

	    var dialogOptions = $scope.dialogOptions;
	    $scope.dialogTreeEventHandler = $({});
	    $scope.section = dialogOptions.section;
	    $scope.treeAlias = dialogOptions.treeAlias;
	    $scope.multiPicker = dialogOptions.multiPicker;
	    $scope.hideHeader = true; 	    
	    localizationService.localize("general_typeToSearch").then(function (value) {
	        $scope.searchPlaceholderText = value;
	    });
        $scope.searchInfo = {
            selectedSearchResults: [],
            searchFrom: null,
            searchFromName: null,
            showSearch: false,
            term: null,
            oldTerm: null,
            results: []
        }

	    //create the custom query string param for this tree
	    $scope.customTreeParams = dialogOptions.startNodeId ? "startNodeId=" + dialogOptions.startNodeId : "";
	    $scope.customTreeParams += dialogOptions.customTreeParams ? "&" + dialogOptions.customTreeParams : "";

	    //search defaults
	    var searcher = searchService.searchContent;
	    var entityType = "Document";
	    

	    //min / max values
	    if (dialogOptions.minNumber) {
	        dialogOptions.minNumber = parseInt(dialogOptions.minNumber, 10);
	    }
	    if (dialogOptions.maxNumber) {
	        dialogOptions.maxNumber = parseInt(dialogOptions.maxNumber, 10);
	    }

	    //search
	    if (dialogOptions.section === "member") {
	        searcher = searchService.searchMembers;
	        entityType = "Member";            
	    }
	    else if (dialogOptions.section === "media") {
	        searcher = searchService.searchMedia;
	        entityType = "Media";
	    }

	    //Configures filtering
	    if (dialogOptions.filter) {

	        dialogOptions.filterExclude = false;
	        dialogOptions.filterAdvanced = false;

	        if (dialogOptions.filter[0] === "!") {
	            dialogOptions.filterExclude = true;
	            dialogOptions.filter = dialogOptions.filter.substring(1);
	        }

	        //used advanced filtering
	        if (dialogOptions.filter[0] === "{") {
	            dialogOptions.filterAdvanced = true;
	        }
	    }

	    function nodeSearchHandler(ev, args) {
            if (args.node.metaData.isContainer === true) {
                $scope.searchInfo.showSearch = true;
                $scope.searchInfo.searchFromName = args.node.name;
                $scope.searchInfo.searchFrom = args.node.id;
            }
        }

	    function nodeExpandedHandler(ev, args) {            
	        if (angular.isArray(args.children)) {

	            //TODO: Not only this but we need to ensure that any currently displayed nodes that get selected
                // from the search get updated to have a check box!
	            ////now we need to look in the already selected search results and 
	            //// toggle the check boxes for those ones that are listed
	            //_.each($scope.searchInfo.results, function (result) {
	            //    var exists = _.find($scope.searchInfo.selectedSearchResults, function (selectedId) {
	            //        return result.id == selectedId;
	            //    });
	            //    if (exists) {
	            //        result.selected = true;
	            //    }
	            //});

	            //check filter
	            if (dialogOptions.filter) {	             
	                performFiltering(args.children);	             
	            }
	        }
	    }

	    //wires up selection
	    function nodeSelectHandler(ev, args) {
	        args.event.preventDefault();
	        args.event.stopPropagation();

	        eventsService.emit("dialogs.treePickerController.select", args);

	        if (args.node.filtered) {
	            return;
	        }

	        //This is a tree node, so we don't have an entity to pass in, it will need to be looked up
	        //from the server in this method.
	        select(args.node.name, args.node.id);

            //toggle checked state
	        args.node.selected = args.node.selected === true ? false : true;
	    }

	    /** Method used for selecting a node */
	    function select(text, id, entity) {
	        //if we get the root, we just return a constructed entity, no need for server data
	        if (id < 0) {
	            if ($scope.multiPicker) {
	                $scope.select(id);
	            }
	            else {
	                var node = {
	                    alias: null,
	                    icon: "icon-folder",
	                    id: id,
	                    name: text
	                };
	                $scope.submit(node);
	            }
	        }
	        else {
	            
	            if ($scope.multiPicker) {
	                $scope.select(id);
	            }
	            else {
                    
	                $scope.hideSearch();

	                //if an entity has been passed in, use it
	                if (entity) {
	                    $scope.submit(entity);<commit_msg>Ensures that new nodes that are shown in the tree that have already been selected via the search results are shown as selected<commit_after>//used for the media picker dialog
angular.module("umbraco").controller("Umbraco.Dialogs.TreePickerController",
	function ($scope, entityResource, eventsService, $log, searchService, angularHelper, $timeout, localizationService) {

	    var dialogOptions = $scope.dialogOptions;
	    $scope.dialogTreeEventHandler = $({});
	    $scope.section = dialogOptions.section;
	    $scope.treeAlias = dialogOptions.treeAlias;
	    $scope.multiPicker = dialogOptions.multiPicker;
	    $scope.hideHeader = true; 	    
	    localizationService.localize("general_typeToSearch").then(function (value) {
	        $scope.searchPlaceholderText = value;
	    });
        $scope.searchInfo = {
            selectedSearchResults: [],
            searchFrom: null,
            searchFromName: null,
            showSearch: false,
            term: null,
            oldTerm: null,
            results: []
        }

	    //create the custom query string param for this tree
	    $scope.customTreeParams = dialogOptions.startNodeId ? "startNodeId=" + dialogOptions.startNodeId : "";
	    $scope.customTreeParams += dialogOptions.customTreeParams ? "&" + dialogOptions.customTreeParams : "";

	    //search defaults
	    var searcher = searchService.searchContent;
	    var entityType = "Document";
	    

	    //min / max values
	    if (dialogOptions.minNumber) {
	        dialogOptions.minNumber = parseInt(dialogOptions.minNumber, 10);
	    }
	    if (dialogOptions.maxNumber) {
	        dialogOptions.maxNumber = parseInt(dialogOptions.maxNumber, 10);
	    }

	    //search
	    if (dialogOptions.section === "member") {
	        searcher = searchService.searchMembers;
	        entityType = "Member";            
	    }
	    else if (dialogOptions.section === "media") {
	        searcher = searchService.searchMedia;
	        entityType = "Media";
	    }

	    //Configures filtering
	    if (dialogOptions.filter) {

	        dialogOptions.filterExclude = false;
	        dialogOptions.filterAdvanced = false;

	        if (dialogOptions.filter[0] === "!") {
	            dialogOptions.filterExclude = true;
	            dialogOptions.filter = dialogOptions.filter.substring(1);
	        }

	        //used advanced filtering
	        if (dialogOptions.filter[0] === "{") {
	            dialogOptions.filterAdvanced = true;
	        }
	    } 

	    function nodeSearchHandler(ev, args) {
            if (args.node.metaData.isContainer === true) {
                $scope.searchInfo.showSearch = true;
                $scope.searchInfo.searchFromName = args.node.name;
                $scope.searchInfo.searchFrom = args.node.id;
            }
        }

	    function nodeExpandedHandler(ev, args) {            
	        if (angular.isArray(args.children)) {

	            //TODO: Not only this but we need to ensure that any currently displayed nodes that get selected
                // from the search get updated to have a check box!

	            //now we need to look in the already selected search results and 
	            // toggle the check boxes for those ones that are listed
	            _.each(args.children, function (result) {
	                var exists = _.find($scope.searchInfo.selectedSearchResults, function (selectedId) {
	                    return result.id == selectedId;
	                });
	                if (exists) {
	                    result.selected = true;
	                }
	            });

	            //check filter
	            if (dialogOptions.filter) {	             
	                performFiltering(args.children);	             
	            }
	        }
	    }

	    //wires up selection
	    function nodeSelectHandler(ev, args) {
	        args.event.preventDefault();
	        args.event.stopPropagation();

	        eventsService.emit("dialogs.treePickerController.select", args);

	        if (args.node.filtered) {
	            return;
	        }

	        //This is a tree node, so we don't have an entity to pass in, it will need to be looked up
	        //from the server in this method.
	        select(args.node.name, args.node.id);

            //toggle checked state
	        args.node.selected = args.node.selected === true ? false : true;
	    }

	    /** Method used for selecting a node */
	    function select(text, id, entity) {
	        //if we get the root, we just return a constructed entity, no need for server data
	        if (id < 0) {
	            if ($scope.multiPicker) {
	                $scope.select(id);
	            }
	            else {
	                var node = {
	                    alias: null,
	                    icon: "icon-folder",
	                    id: id,
	                    name: text
	                };
	                $scope.submit(node);
	            }
	        }
	        else {
	            
	            if ($scope.multiPicker) {
	                $scope.select(Number(id));
	            }
	            else {
                    
	                $scope.hideSearch();

	                //if an entity has been passed in, use it
	                if (entity) {
	                    $scope.submit(entity);
{'fraction_non_alphanumeric': 0.09896986617887744, 'fraction_numerical': 0.0015403870222393376, 'mean_word_length': 1.6446028513238289, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6891690', 'n_tokens_mistral': 2852, 'n_tokens_neox': 2540, 'n_words': 655}