You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rz...@apache.org on 2016/04/21 20:36:25 UTC

ambari git commit: AMBARI-16003: JS error on hosts filtering when filter for same field is used twice (rzang)

Repository: ambari
Updated Branches:
  refs/heads/trunk c3a72eb30 -> 04f7d5c3e


AMBARI-16003: JS error on hosts filtering when filter for same field is used twice (rzang)


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

Branch: refs/heads/trunk
Commit: 04f7d5c3efe8af2c43824f32c1ce04d2ddc6cee2
Parents: c3a72eb
Author: Richard Zang <rz...@apache.org>
Authored: Thu Apr 21 11:28:41 2016 -0700
Committer: Richard Zang <rz...@apache.org>
Committed: Thu Apr 21 11:29:27 2016 -0700

----------------------------------------------------------------------
 .../app/views/main/host/combo_search_box.js     | 58 ++++++++++++++------
 1 file changed, 41 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/04f7d5c3/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 d8e5abf..0b8c95b 100644
--- a/ambari-web/app/views/main/host/combo_search_box.js
+++ b/ambari-web/app/views/main/host/combo_search_box.js
@@ -69,9 +69,49 @@ App.MainHostComboSearchBoxView = Em.View.extend({
     return currentComponentFacets;
   },
 
+  getFacetsByName: function(name) {
+    var facets = visualSearch.searchQuery.toJSON().filter(function(facet) {
+      return facet.category === name;
+    });
+    return facets;
+  },
+
+  filterOutOneFacetOnlyOptions: function(options) {
+    var self = this;
+    var oneFacetOnlyLables = ['Cores', 'RAM'];
+    oneFacetOnlyLables.forEach(function(label) {
+      var facets = self.getFacetsByName(label);
+      if (facets.length > 0) {
+        options = options.rejectProperty('label', label);
+      }
+    });
+    return options;
+  },
+
+  setupLabelMap: function() {
+    var map = App.router.get('mainHostController.labelValueMap');
+    map['Host Name'] = 'hostName';
+    map['IP'] = 'ip';
+    map['Host Status'] = 'healthClass';
+    map['Cores'] = 'cpu';
+    map['RAM'] = 'memoryFormatted';
+    map['Stack Version'] = 'version';
+    map['Version State'] = 'versionState';
+    map['Rack'] = 'rack';
+    map['Service'] = 'services';
+
+    map['Inservice'] = 'INSERVICE';
+    map['Decommissioned'] = 'DECOMMISSIONED';
+    map['Decommissioning'] = 'DECOMMISSIONING';
+    map['RS Decommissioned'] = 'RS_DECOMMISSIONED';
+    map['Maintenance Mode On'] = 'ON';
+    map['Maintenance Mode Off'] = 'OFF';
+  },
+
   initVS: function() {
     var self = this;
     var controller = App.router.get('mainHostComboSearchBoxController');
+    this.setupLabelMap();
     window.visualSearch = VS.init({
       container: $('#combo_search_box'),
       query: '',
@@ -101,17 +141,6 @@ App.MainHostComboSearchBoxView = Em.View.extend({
             {label: 'Rack', category: 'Host'},
             {label: 'Service', category: 'Service'}
           ];
-          var map = App.router.get('mainHostController.labelValueMap');
-          map['Host Name'] = 'hostName';
-          map['IP'] = 'ip';
-          map['Host Status'] = 'healthClass';
-          map['Cores'] = 'cpu';
-          map['RAM'] = 'memoryFormatted';
-          map['Stack Version'] = 'version';
-          map['Version State'] = 'versionState';
-          map['Rack'] = 'rack';
-          map['Service'] = 'services';
-
           var hostComponentList = self.getHostComponentList();
           // Add host component facets only when there isn't any component filter
           // with value other than ALL yet
@@ -119,6 +148,7 @@ App.MainHostComboSearchBoxView = Em.View.extend({
           if (currentComponentFacets.length == 0) {
             list = list.concat(hostComponentList);
           }
+          list = self.filterOutOneFacetOnlyOptions(list);
           // Append host components
           callback(list, {preserveOrder: true});
         },
@@ -194,12 +224,6 @@ App.MainHostComboSearchBoxView = Em.View.extend({
                     "Maintenance Mode On",
                     "Maintenance Mode Off"
                 ]);
-                map['Inservice'] = 'INSERVICE';
-                map['Decommissioned'] = 'DECOMMISSIONED';
-                map['Decommissioning'] = 'DECOMMISSIONING';
-                map['RS Decommissioned'] = 'RS_DECOMMISSIONED';
-                map['Maintenance Mode On'] = 'ON';
-                map['Maintenance Mode Off'] = 'OFF';
               }
               callback(list, {preserveOrder: true});
               break;