Browse Source

AMBARI-14822 Combo Search: Create auto suggest for Host attribute filters (Joe Wang via rzang)

Richard Zang 9 years ago
parent
commit
b037ef5cfc

+ 17 - 13
ambari-web/app/controllers/main/host/combo_search_box.js

@@ -21,6 +21,7 @@ var App = require('app');
 App.MainHostComboSearchBoxController = Em.Controller.extend({
 App.MainHostComboSearchBoxController = Em.Controller.extend({
   name: 'mainHostComboSearchBoxController',
   name: 'mainHostComboSearchBoxController',
   currentSuggestion: [],
   currentSuggestion: [],
+  page_size: 10,
 
 
   VSCallbacks : {
   VSCallbacks : {
     search: function (query, searchCollection) {
     search: function (query, searchCollection) {
@@ -42,12 +43,12 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({
     },
     },
 
 
     facetMatches: function (callback) {
     facetMatches: function (callback) {
-      console.log('called');
       callback([
       callback([
-        {label: 'name', category: 'Host'},
+        {label: 'host_name', category: 'Host'},
         {label: 'ip', category: 'Host'},
         {label: 'ip', category: 'Host'},
         {label: 'version', category: 'Host'},
         {label: 'version', category: 'Host'},
         {label: 'health', category: 'Host'},
         {label: 'health', category: 'Host'},
+        {label: 'rack', category: 'Host'},
         {label: 'service', category: 'Service'},
         {label: 'service', category: 'Service'},
         {label: 'component', category: 'Service'},
         {label: 'component', category: 'Service'},
         {label: 'state', category: 'Service'}
         {label: 'state', category: 'Service'}
@@ -57,13 +58,11 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({
     valueMatches: function (facet, searchTerm, callback) {
     valueMatches: function (facet, searchTerm, callback) {
       var controller = App.router.get('mainHostComboSearchBoxController');
       var controller = App.router.get('mainHostComboSearchBoxController');
       switch (facet) {
       switch (facet) {
-        case 'name':
-          controller.getHostPropertySuggestions('name', searchTerm).done(function() {
-            callback(controller.get('currentSuggestion'));
-          });
-          break;
+        case 'host_name':
         case 'ip':
         case 'ip':
-          callback(App.Host.find().toArray().mapProperty('ip'));
+          controller.getPropertySuggestions(facet, searchTerm).done(function() {
+            callback(controller.get('currentSuggestion'), {preserveMatches: true});
+          });
           break;
           break;
         case 'rack':
         case 'rack':
           callback(App.Host.find().toArray().mapProperty('rack').uniq());
           callback(App.Host.find().toArray().mapProperty('rack').uniq());
@@ -104,18 +103,23 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({
     }
     }
   },
   },
 
 
-  getHostPropertySuggestions: function(facet, searchTerm) {
+  getPropertySuggestions: function(facet, searchTerm) {
     return App.ajax.send({
     return App.ajax.send({
-      name: 'hosts.all.install',
+      name: 'hosts.with_searchTerm',
       sender: this,
       sender: this,
-      success: 'updateHostNameSuggestion',
+      data: {
+        facet: facet,
+        searchTerm: searchTerm,
+        page_size: this.get('page_size')
+      },
+      success: 'getPropertySuggestionsSuccess',
       error: 'commonSuggestionErrorCallback'
       error: 'commonSuggestionErrorCallback'
     });
     });
   },
   },
 
 
-  updateHostNameSuggestion: function(data) {
+  getPropertySuggestionsSuccess: function(data, opt, params) {
     this.updateSuggestion(data.items.map(function(item) {
     this.updateSuggestion(data.items.map(function(item) {
-      return item.Hosts.host_name;
+      return item.Hosts[params.facet];
     }));
     }));
   },
   },
 
 

+ 15 - 0
ambari-web/app/utils/ajax/ajax.js

@@ -2358,6 +2358,21 @@ var urls = {
     'real': '/clusters/{clusterName}/hosts?fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem,Hosts/os_type,Hosts/os_arch,Hosts/ip,host_components/HostRoles/state&minimal_response=true',
     'real': '/clusters/{clusterName}/hosts?fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem,Hosts/os_type,Hosts/os_arch,Hosts/ip,host_components/HostRoles/state&minimal_response=true',
     'mock': '/data/hosts/HDP2/hosts.json'
     'mock': '/data/hosts/HDP2/hosts.json'
   },
   },
+  'hosts.with_searchTerm': {
+    'real': '/clusters/{clusterName}/hosts?fields=Hosts/{facet}&minimal_response=true&page_size={page_size}',
+    'mock': '',
+    format: function (data) {
+      return {
+        headers: {
+          'X-Http-Method-Override': 'GET'
+        },
+        type: 'POST',
+        data: JSON.stringify({
+          "RequestInfo": {"query": (data.searchTerm ? "Hosts/"+ data.facet +".matches(.*" + data.searchTerm + ".*)" : "")}
+        })
+      };
+    }
+  },
   'host_components.all': {
   'host_components.all': {
     'real': '/clusters/{clusterName}/host_components?fields=HostRoles/host_name&minimal_response=true',
     'real': '/clusters/{clusterName}/host_components?fields=HostRoles/host_name&minimal_response=true',
     'mock': ''
     'mock': ''

+ 1 - 0
ambari-web/app/views/main/host/combo_search_box.js

@@ -29,6 +29,7 @@ App.MainHostComboSearchBoxView = Em.View.extend({
       container: $('#combo_search_box'),
       container: $('#combo_search_box'),
       query: '',
       query: '',
       showFacets: true,
       showFacets: true,
+      delay: 1000,
       unquotable: [
       unquotable: [
         'text'
         'text'
       ],
       ],

+ 1 - 1
ambari-web/vendor/scripts/visualsearch.js

@@ -612,7 +612,7 @@
             this.box.autocomplete({
             this.box.autocomplete({
                 source    : _.bind(this.autocompleteValues, this),
                 source    : _.bind(this.autocompleteValues, this),
                 minLength : 0,
                 minLength : 0,
-                delay     : 0,
+                delay     : this.app.options.delay,
                 autoFocus : true,
                 autoFocus : true,
                 position  : {offset : "0 5"},
                 position  : {offset : "0 5"},
                 create    : _.bind(function(e, ui) {
                 create    : _.bind(function(e, ui) {