AMBARI-15327 Combo Search: Query for multiple <Component:Any> facets and 
display label instead of value in search box (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/c0d07416
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c0d07416
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c0d07416

Branch: refs/heads/AMBARI-13364
Commit: c0d07416e2f75912cacbd3f4a3adb0b918729892
Parents: eb6b0da
Author: Richard Zang <rz...@apache.org>
Authored: Wed Mar 9 11:42:24 2016 -0800
Committer: Richard Zang <rz...@apache.org>
Committed: Wed Mar 9 11:42:24 2016 -0800

----------------------------------------------------------------------
 ambari-web/app/controllers/main/host.js         | 26 +++++--
 .../controllers/main/host/combo_search_box.js   |  2 +-
 .../mixins/common/table_server_view_mixin.js    | 13 ++--
 .../app/views/main/host/combo_search_box.js     | 79 +++++++++++++-------
 ambari-web/test/controllers/main/host_test.js   |  6 +-
 5 files changed, 82 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c0d07416/ambari-web/app/controllers/main/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host.js 
b/ambari-web/app/controllers/main/host.js
index b473c59..5d7e268 100644
--- a/ambari-web/app/controllers/main/host.js
+++ b/ambari-web/app/controllers/main/host.js
@@ -494,23 +494,29 @@ App.MainHostController = 
Em.ArrayController.extend(App.TableServerMixin, {
     return result;
   },
 
+  labelValueMap: {},
+
   /**
    * Filter hosts by componentName of <code>component</code>
    * @param {App.HostComponent} component
    */
   filterByComponent: function (component) {
     if (!component) return;
-    var id = component.get('componentName');
-    var column = 6;
+    var componentName = component.get('componentName');
+    var displayName = App.format.role(componentName);
     var colPropAssoc = this.get('colPropAssoc');
+    var map = this.get('labelValueMap');
 
     var filterForComponent = {
-      iColumn: column,
-      value: [id],
-      type: 'multiple'
+      iColumn: 15,
+      value: componentName + ':ALL',
+      type: 'string'
     };
+    map[displayName] = componentName;
+    map['All'] = 'ALL';
+    var filterStr = '"' + displayName + '"' + ': "All"';
     App.db.setFilterConditions(this.get('name'), [filterForComponent]);
-    App.db.setComboSearchQuery(this.get('name'), colPropAssoc[column] + ': ' + 
'"' + id + '"');
+    App.db.setComboSearchQuery(this.get('name'), filterStr);
   },
 
   /**
@@ -521,6 +527,7 @@ App.MainHostController = 
Em.ArrayController.extend(App.TableServerMixin, {
   filterByStack: function (displayName, state) {
     if (!displayName || !state) return;
     var colPropAssoc = this.get('colPropAssoc');
+    var map = this.get('labelValueMap');
 
     var versionFilter = {
       iColumn: 16,
@@ -532,8 +539,11 @@ App.MainHostController = 
Em.ArrayController.extend(App.TableServerMixin, {
       value: state.toUpperCase(),
       type: 'string'
     };
-    var versionFilterStr = colPropAssoc[versionFilter.iColumn] + ': ' + '"' + 
versionFilter.value + '"';
-    var stateFilterStr = colPropAssoc[stateFilter.iColumn] + ': ' + '"' + 
stateFilter.value + '"';
+    map["Stack Version"] = colPropAssoc[versionFilter.iColumn];
+    map["Version State"] = colPropAssoc[stateFilter.iColumn];
+    map[App.HostStackVersion.formatStatus(stateFilter.value)] = 
stateFilter.value;
+    var versionFilterStr = '"Stack Version": "' + versionFilter.value + '"';
+    var stateFilterStr = '"Version State": "' + 
App.HostStackVersion.formatStatus(stateFilter.value) + '"';
     App.db.setFilterConditions(this.get('name'), [versionFilter, stateFilter]);
     App.db.setComboSearchQuery(this.get('name'), [versionFilterStr, 
stateFilterStr].join(' '));
   },

http://git-wip-us.apache.org/repos/asf/ambari/blob/c0d07416/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 9fa6851..6f64170 100644
--- a/ambari-web/app/controllers/main/host/combo_search_box.js
+++ b/ambari-web/app/controllers/main/host/combo_search_box.js
@@ -92,7 +92,7 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({
         ex = ex.replace('{1}', v);
         result += ex;
       }
-      result += '&';
+      result += '|';
     }
 
     return result.substring(0, result.length - 1);

http://git-wip-us.apache.org/repos/asf/ambari/blob/c0d07416/ambari-web/app/mixins/common/table_server_view_mixin.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/table_server_view_mixin.js 
b/ambari-web/app/mixins/common/table_server_view_mixin.js
index eca17d6..66f886a 100644
--- a/ambari-web/app/mixins/common/table_server_view_mixin.js
+++ b/ambari-web/app/mixins/common/table_server_view_mixin.js
@@ -95,10 +95,13 @@ App.TableServerViewMixin = Em.Mixin.create({
     this.set('filterConditions', []);
     searchCollection.models.forEach(function (model) {
       var tag = model.attributes;
-      var isComponentState = 
comboController.isComponentStateFacet(tag.category);
-      var iColumn = 
App.router.get('mainHostController').get('colPropAssoc').indexOf(isComponentState?
 'componentState' : tag.category);
+      var map = App.router.get('mainHostController.labelValueMap');
+      var category = map[tag.category] || tag.category;
+      var value = map[tag.value] || tag.value;
+      var isComponentState = comboController.isComponentStateFacet(category);
+      var iColumn = 
App.router.get('mainHostController').get('colPropAssoc').indexOf(isComponentState?
 'componentState' : category);
       var filterCondition = 
self.get('filterConditions').findProperty('iColumn', iColumn);
-      var filterValue = isComponentState? (tag.category + ':' + tag.value) : 
tag.value;
+      var filterValue = isComponentState? (category + ':' + value) : value;
       if (filterCondition) {
         if (typeof filterCondition.value == 'string') {
           filterCondition.value = [filterCondition.value, filterValue];
@@ -107,10 +110,10 @@ App.TableServerViewMixin = Em.Mixin.create({
         }
       } else {
         var type = 'string';
-        if (tag.category === 'cpu') {
+        if (category === 'cpu') {
           type = 'number';
         }
-        if (tag.category === 'memoryFormatted') {
+        if (category === 'memoryFormatted') {
           type = 'ambari-bandwidth';
         }
         filterCondition = {

http://git-wip-us.apache.org/repos/asf/ambari/blob/c0d07416/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 17c0a6d..3ccacf2 100644
--- a/ambari-web/app/views/main/host/combo_search_box.js
+++ b/ambari-web/app/views/main/host/combo_search_box.js
@@ -39,7 +39,8 @@ App.MainHostComboSearchBoxView = Em.View.extend({
       var displayName = component.get('displayName');
       var name = component.get('componentName');
       if (displayName != null && !controller.isClientComponent(name)) {
-        hostComponentList.push({label: displayName, value: name, category: 
'Component'});
+        hostComponentList.push({label: displayName, category: 'Component'});
+        App.router.get('mainHostController.labelValueMap')[displayName] = name;
       }
     });
     return hostComponentList;
@@ -50,9 +51,9 @@ App.MainHostComboSearchBoxView = Em.View.extend({
       hostComponentList = this.getHostComponentList();
     }
     var currentComponentFacets = 
visualSearch.searchQuery.toJSON().filter(function (facet) {
-      var result = !!(hostComponentList.findProperty('value', facet.category) 
&& facet.value);
+      var result = !!(hostComponentList.findProperty('label', facet.category) 
&& facet.value);
       if (!includeAllValue) {
-        result &= (facet.value != 'ALL');
+        result &= (facet.value != 'All');
       }
       return result;
     });
@@ -79,16 +80,27 @@ App.MainHostComboSearchBoxView = Em.View.extend({
 
         facetMatches: function (callback) {
           var list = [
-            {label: 'Host Name', value: 'hostName', category: 'Host'},
-            {label: 'IP', value: 'ip', category: 'Host'},
-            {label: 'Heath Status', value: 'healthClass', category: 'Host'},
-            {label: 'Cores', value: 'cpu', category: 'Host'},
-            {label: 'RAM', value: 'memoryFormatted', category: 'Host'},
-            {label: 'Stack Version', value: 'version', category: 'Host'},
-            {label: 'Version State', value: 'versionState', category: 'Host'},
-            {label: 'Rack', value: 'rack', category: 'Host'},
-            {label: 'Service', value: 'services', category: 'Service'},
+            {label: 'Host Name', category: 'Host'},
+            {label: 'IP', category: 'Host'},
+            {label: 'Heath Status', category: 'Host'},
+            {label: 'Cores', category: 'Host'},
+            {label: 'RAM', category: 'Host'},
+            {label: 'Stack Version', category: 'Host'},
+            {label: 'Version State', category: 'Host'},
+            {label: 'Rack', category: 'Host'},
+            {label: 'Service', category: 'Service'}
           ];
+          var map = App.router.get('mainHostController.labelValueMap');
+          map['Host Name'] = 'hostName';
+          map['IP'] = 'ip';
+          map['Heath 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
@@ -101,13 +113,15 @@ App.MainHostComboSearchBoxView = Em.View.extend({
         },
 
         valueMatches: function (facet, searchTerm, callback) {
-          if (controller.isComponentStateFacet(facet)) {
-            facet = 'componentState'
+          var map = App.router.get('mainHostController.labelValueMap');
+          var facetValue = map[facet] || facet;
+          if (controller.isComponentStateFacet(facetValue)) {
+            facetValue = 'componentState'
           }
-          switch (facet) {
+          switch (facetValue) {
             case 'hostName':
             case 'ip':
-              controller.getPropertySuggestions(facet, 
searchTerm).done(function() {
+              controller.getPropertySuggestions(facetValue, 
searchTerm).done(function() {
                 callback(controller.get('currentSuggestion').reject(function 
(item) {
                   return visualSearch.searchQuery.values(facet).indexOf(item) 
>= 0; // reject the ones already in search
                 }), {preserveMatches: true});
@@ -126,7 +140,8 @@ App.MainHostComboSearchBoxView = Em.View.extend({
               break;
             case 'versionState':
               callback(App.HostStackVersion.statusDefinition.map(function 
(status) {
-                return {label: App.HostStackVersion.formatStatus(status), 
value: status};
+                map[App.HostStackVersion.formatStatus(status)] = status;
+                return App.HostStackVersion.formatStatus(status);
               }).reject(function (item) {
                 return 
visualSearch.searchQuery.values(facet).indexOf(item.value) >= 0;
               }));
@@ -134,32 +149,42 @@ App.MainHostComboSearchBoxView = Em.View.extend({
             case 'healthClass':
               var category_mocks = require('data/host/categories');
               callback(category_mocks.slice(1).map(function (category) {
-                return {label: category.value, value: category.healthStatus}
+                map[category.value] = category.healthStatus;
+                return category.value;
               }).reject(function (item) {
                 return 
visualSearch.searchQuery.values(facet).indexOf(item.value) >= 0;
               }), {preserveOrder: true});
               break;
             case 'services':
               callback(App.Service.find().toArray().map(function (service) {
-                return {label: App.format.role(service.get('serviceName')), 
value: service.get('serviceName')};
+                map[App.format.role(service.get('serviceName'))] = 
service.get('serviceName');
+                return App.format.role(service.get('serviceName'));
               }).reject(function (item) {
                 return 
visualSearch.searchQuery.values(facet).indexOf(item.value) >= 0;
               }), {preserveOrder: true});
               break;
             case 'componentState':
-              var list = [{label: "All", value: "ALL"}];
+              var list = [ "All" ];
+              map['All'] = 'ALL';
               var currentComponentFacets = self.getComponentStateFacets(null, 
true);
               if (currentComponentFacets.length == 0) {
                 list = 
list.concat(App.HostComponentStatus.getStatusesList().map(function (status) {
-                  return {label: 
App.HostComponentStatus.getTextStatus(status), value: status};
+                  map[App.HostComponentStatus.getTextStatus(status)] = status;
+                  return App.HostComponentStatus.getTextStatus(status);
                 })).concat([
-                    {label: "Inservice", value: "INSERVICE"},
-                    {label: "Decommissioned", value: "DECOMMISSIONED"},
-                    {label: "Decommissioning", value: "DECOMMISSIONING"},
-                    {label: "RS Decommissioned", value: "RS_DECOMMISSIONED"},
-                    {label: "Maintenance Mode On", value: "ON"},
-                    {label: "Maintenance Mode Off", value: "OFF"}
+                    "Inservice",
+                    "Decommissioned",
+                    "Decommissioning",
+                    "RS Decommissioned",
+                    "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;

http://git-wip-us.apache.org/repos/asf/ambari/blob/c0d07416/ambari-web/test/controllers/main/host_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/host_test.js 
b/ambari-web/test/controllers/main/host_test.js
index 06a4813..e2041f3 100644
--- a/ambari-web/test/controllers/main/host_test.js
+++ b/ambari-web/test/controllers/main/host_test.js
@@ -370,9 +370,9 @@ describe('MainHostController', function () {
         componentName: 'C1'
       }));
       expect(App.db.setFilterConditions.calledWith('ctrl1', [{
-        iColumn: 6,
-        value: ['C1'],
-        type: 'multiple'
+        iColumn: 15,
+        value: 'C1:ALL',
+        type: 'string'
       }])).to.be.true;
     });
   });

Reply via email to