Path: blob/master/extensions/admin_ui/media/javascript/ui/panel/ModuleSearching.js
1154 views
/*1* Keyword search for command module panel.2* Words in query are searched as separated queries. You can search for exact matching using double qoutes arround query3*/45function search_module(module_tree, query_string) {6if ( query_string.search(/\w/) == -1 )7return tree_array;89// copy module tree w/o ExtJS service properties10var tree_array = new Array();11for ( var i = 0; i < module_tree.length; i++ )12tree_array.push(module_tree[i].attributes);1314var json_object = jQuery.extend(true, [], tree_array);1516// split query string into separate words and exact phrases17query_string = query_string.replace(/"\s*"/g, " ").replace(/\s+/g, " ").match(/"[^"]+"|\S+/g);18query_string.forEach(prepare_query_string);1920var result = json_object.filter(form_new_modules_tree);21result.forEach(recount_modules_and_expand_directories);2223return result;2425// remove quotes from phrases for exact match26function prepare_query_string(string, index, array){27array[index] = string.toLowerCase().replace(/"/g, "");28}2930// True if this.toString() contains str31function check_module_name(str) {32return Boolean(this.toString().toLowerCase().replace(/\s\([0-9]+\)/g,"").indexOf(str) + 1);33}3435// func for JSON filter36// Build a new tree from modules which are appropriate for any part of query37function form_new_modules_tree(element) {38if ( query_string.some(check_module_name, element.text) )39return true;40if ( element.children ) {41element.children = element.children.filter(form_new_modules_tree);42return Boolean(element.children.length);43}44return false;45}4647function recount_modules_and_expand_directories(element) {48if ( element.children ) {49element.expanded = true;50var modules_in_directory = element.children.length;51// visit all52for ( var i = 0; i < element.children.length; i++ )53if ( element.children )54modules_in_directory += recount_modules_and_expand_directories(element.children[i]);55// expand them56element.children.forEach(recount_modules_and_expand_directories);57// and set new number of modules in directory58element.text = element.text.replace(/([-_ 0-9a-zA-Z]+)\(([0-9]+)\)/, "$1(" + modules_in_directory + ")")59return modules_in_directory - 1;60}61return 0;62}63}646566