You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/02/01 16:41:55 UTC

[18/39] ambari git commit: AMBARI-14822 Combo Search: Create auto suggest for Host attribute filters (Joe Wang via rzang)

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


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b037ef5c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b037ef5c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b037ef5c

Branch: refs/heads/branch-dev-patch-upgrade
Commit: b037ef5cfc9cfd72126818cf8c5c5e7c3525dc52
Parents: cad69e6
Author: Richard Zang <rz...@apache.org>
Authored: Fri Jan 29 08:58:08 2016 +0800
Committer: Richard Zang <rz...@apache.org>
Committed: Fri Jan 29 08:58:08 2016 +0800

----------------------------------------------------------------------
 .../controllers/main/host/combo_search_box.js   | 30 +++++++++++---------
 ambari-web/app/utils/ajax/ajax.js               | 15 ++++++++++
 .../app/views/main/host/combo_search_box.js     |  1 +
 ambari-web/vendor/scripts/visualsearch.js       |  2 +-
 4 files changed, 34 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b037ef5c/ambari-web/app/controllers/main/host/combo_search_box.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host/combo_search_box.js b/ambari-web/app/controllers/main/host/combo_search_box.js
index 3832611..1c2a87f 100644
--- a/ambari-web/app/controllers/main/host/combo_search_box.js
+++ b/ambari-web/app/controllers/main/host/combo_search_box.js
@@ -21,6 +21,7 @@ var App = require('app');
 App.MainHostComboSearchBoxController = Em.Controller.extend({
   name: 'mainHostComboSearchBoxController',
   currentSuggestion: [],
+  page_size: 10,
 
   VSCallbacks : {
     search: function (query, searchCollection) {
@@ -42,12 +43,12 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({
     },
 
     facetMatches: function (callback) {
-      console.log('called');
       callback([
-        {label: 'name', category: 'Host'},
+        {label: 'host_name', category: 'Host'},
         {label: 'ip', category: 'Host'},
         {label: 'version', category: 'Host'},
         {label: 'health', category: 'Host'},
+        {label: 'rack', category: 'Host'},
         {label: 'service', category: 'Service'},
         {label: 'component', category: 'Service'},
         {label: 'state', category: 'Service'}
@@ -57,13 +58,11 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({
     valueMatches: function (facet, searchTerm, callback) {
       var controller = App.router.get('mainHostComboSearchBoxController');
       switch (facet) {
-        case 'name':
-          controller.getHostPropertySuggestions('name', searchTerm).done(function() {
-            callback(controller.get('currentSuggestion'));
-          });
-          break;
+        case 'host_name':
         case 'ip':
-          callback(App.Host.find().toArray().mapProperty('ip'));
+          controller.getPropertySuggestions(facet, searchTerm).done(function() {
+            callback(controller.get('currentSuggestion'), {preserveMatches: true});
+          });
           break;
         case 'rack':
           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({
-      name: 'hosts.all.install',
+      name: 'hosts.with_searchTerm',
       sender: this,
-      success: 'updateHostNameSuggestion',
+      data: {
+        facet: facet,
+        searchTerm: searchTerm,
+        page_size: this.get('page_size')
+      },
+      success: 'getPropertySuggestionsSuccess',
       error: 'commonSuggestionErrorCallback'
     });
   },
 
-  updateHostNameSuggestion: function(data) {
+  getPropertySuggestionsSuccess: function(data, opt, params) {
     this.updateSuggestion(data.items.map(function(item) {
-      return item.Hosts.host_name;
+      return item.Hosts[params.facet];
     }));
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b037ef5c/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js
index df3782f..4d8d195 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/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',
     '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': {
     'real': '/clusters/{clusterName}/host_components?fields=HostRoles/host_name&minimal_response=true',
     'mock': ''

http://git-wip-us.apache.org/repos/asf/ambari/blob/b037ef5c/ambari-web/app/views/main/host/combo_search_box.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/combo_search_box.js b/ambari-web/app/views/main/host/combo_search_box.js
index 36af44d..0ab6029 100644
--- a/ambari-web/app/views/main/host/combo_search_box.js
+++ b/ambari-web/app/views/main/host/combo_search_box.js
@@ -29,6 +29,7 @@ App.MainHostComboSearchBoxView = Em.View.extend({
       container: $('#combo_search_box'),
       query: '',
       showFacets: true,
+      delay: 1000,
       unquotable: [
         'text'
       ],

http://git-wip-us.apache.org/repos/asf/ambari/blob/b037ef5c/ambari-web/vendor/scripts/visualsearch.js
----------------------------------------------------------------------
diff --git a/ambari-web/vendor/scripts/visualsearch.js b/ambari-web/vendor/scripts/visualsearch.js
index 044977c..ef07680 100644
--- a/ambari-web/vendor/scripts/visualsearch.js
+++ b/ambari-web/vendor/scripts/visualsearch.js
@@ -612,7 +612,7 @@
             this.box.autocomplete({
                 source    : _.bind(this.autocompleteValues, this),
                 minLength : 0,
-                delay     : 0,
+                delay     : this.app.options.delay,
                 autoFocus : true,
                 position  : {offset : "0 5"},
                 create    : _.bind(function(e, ui) {