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/02/24 20:30:30 UTC

ambari git commit: AMBARI-15152. Combo Search: Implement "service component" related filters (rzang)

Repository: ambari
Updated Branches:
  refs/heads/trunk c83bcbd9e -> 3cee3de48


AMBARI-15152. Combo Search: Implement "service component" related filters (rzang)


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

Branch: refs/heads/trunk
Commit: 3cee3de489821c9482309363ead40c74dfa457d8
Parents: c83bcbd
Author: Richard Zang <rz...@apache.org>
Authored: Wed Feb 24 11:29:20 2016 -0800
Committer: Richard Zang <rz...@apache.org>
Committed: Wed Feb 24 11:29:20 2016 -0800

----------------------------------------------------------------------
 .../app/controllers/global/update_controller.js |  17 ++-
 ambari-web/app/controllers/main/host.js         |  16 +--
 .../controllers/main/host/combo_search_box.js   |  58 ++--------
 .../mixins/common/table_server_view_mixin.js    |  31 ++++++
 .../app/views/main/host/combo_search_box.js     | 105 +++++++++----------
 5 files changed, 117 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3cee3de4/ambari-web/app/controllers/global/update_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/update_controller.js b/ambari-web/app/controllers/global/update_controller.js
index 92a4f7d..ebefd0f 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -122,7 +122,11 @@ App.UpdateController = Em.Controller.extend({
 
       switch (param.type) {
         case 'EQUAL':
-          params += param.key + '=' + param.value;
+          if (Em.isArray(param.value)) {
+            params += param.key + '.in(' + param.value.join(',') + ')';
+          } else {
+            params += param.key + '=' + param.value;
+          }
           break;
         case 'LESS':
           params += param.key + '<' + param.value;
@@ -131,7 +135,16 @@ App.UpdateController = Em.Controller.extend({
           params += param.key + '>' + param.value;
           break;
         case 'MATCH':
-          params += param.key + '.matches(' + param.value + ')';
+          if (Em.isArray(param.value)) {
+            params += '(';
+            param.value.forEach(function(v) {
+              params += param.key + '.matches(' + v + ')' + '|';
+            });
+            params = params.substring(0, params.length - 1);
+            params += ')';
+          } else {
+            params += param.key + '.matches(' + param.value + ')';
+          }
           break;
         case 'MULTIPLE':
           params += param.key + '.in(' + param.value.join(',') + ')';

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cee3de4/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 91b4df2..f1a3afb 100644
--- a/ambari-web/app/controllers/main/host.js
+++ b/ambari-web/app/controllers/main/host.js
@@ -97,12 +97,7 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
     {
       name: 'hostComponents',
       key: 'host_components/HostRoles/component_name',
-      type: 'MULTIPLE'
-    },
-    {
-      name: 'hostComponents2',
-      key: 'host_components/HostRoles/component_name',
-      type: 'MATCH'
+      type: 'EQUAL'
     },
     {
       name: 'services',
@@ -238,7 +233,13 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
           isFilter: true
         };
         if (filter.type === 'string' && sortProperties.someProperty('name', colPropAssoc[filter.iColumn])) {
-          result.value = this.getRegExp(filter.value);
+          if (Em.isArray(filter.value)) {
+            for(var i = 0; i < filter.value.length; i++) {
+              filter.value[i] = this.getRegExp(filter.value[i]);
+            }
+          } else {
+            result.value = this.getRegExp(filter.value);
+          }
         }
         if (filter.type === 'number' || filter.type === 'ambari-bandwidth') {
           result.type = this.getComparisonType(filter.value);
@@ -559,7 +560,6 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
     associations[12] = 'rack';
     associations[13] = 'services';
     associations[14] = 'state';
-    associations[15] = 'hostComponents2';
     return associations;
   }.property()
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cee3de4/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 0aeb31b..3cbb602 100644
--- a/ambari-web/app/controllers/main/host/combo_search_box.js
+++ b/ambari-web/app/controllers/main/host/combo_search_box.js
@@ -22,54 +22,18 @@ App.MainHostComboSearchBoxController = Em.Controller.extend({
   name: 'mainHostComboSearchBoxController',
   currentSuggestion: [],
   page_size: 10,
-
-  VSCallbacks : {
-
-    facetMatches: function (callback) {
-      callback([
-        {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'}
-      ]);
-    },
-
-    valueMatches: function (facet, searchTerm, callback) {
-      var controller = App.router.get('mainHostComboSearchBoxController');
-      var category_mocks = require('data/host/categories');
-      switch (facet) {
-        case 'host_name':
-        case 'ip':
-          controller.getPropertySuggestions(facet, searchTerm).done(function() {
-            callback(controller.get('currentSuggestion'), {preserveMatches: true});
-          });
-          break;
-        case 'rack':
-          callback(App.Host.find().toArray().mapProperty('rack').uniq());
-          break;
-        case 'version':
-          callback(App.StackVersion.find().toArray().mapProperty('name'));
-          break;
-        case 'health':
-          callback(category_mocks.slice(1).mapProperty('healthStatus'), {preserveOrder: true});
-          break;
-        case 'service':
-          callback(App.Service.find().toArray().mapProperty('serviceName'), {preserveOrder: true});
-          break;
-        case 'component':
-          callback(App.HostComponent.find().toArray().mapProperty('componentName').uniq(), {preserveOrder: true});
-          break;
-        case 'state':
-          callback(App.HostComponentStatus.getStatusesList(), {preserveOrder: true});
-          break;
-      }
-    }
+  nameColumnMap: {
+    'Host Name': 'hostName',
+    'IP': 'ip',
+    'Health Status': 'hostName',
+    'Host Name': 'healthClass',
+    'Rack': 'rack',
+    'Cores': 'cpu',
+    'RAM': 'memoryFormatted',
+    'Service': 'service',
+    'Has Component': 'hostComponents',
+    'State': 'state'
   },
-
   getPropertySuggestions: function(facet, searchTerm) {
     return App.ajax.send({
       name: 'hosts.with_searchTerm',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cee3de4/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 674042f..0f84633 100644
--- a/ambari-web/app/mixins/common/table_server_view_mixin.js
+++ b/ambari-web/app/mixins/common/table_server_view_mixin.js
@@ -84,6 +84,37 @@ App.TableServerViewMixin = Em.Mixin.create({
       this.saveFilterConditions(iColumn, value, type, false);
       this.refresh();
     }
+    return true;
+  },
+
+  updateComboFilter: function(searchCollection) {
+    var self = this;
+    clearTimeout(this.get('timeOut'));
+    this.set('controller.resetStartIndex', true);
+    this.set('filterConditions', []);
+    this.clearFilterConditionsFromLocalStorage();
+    searchCollection.models.forEach(function (model) {
+      var tag = model.attributes;
+      var iColumn = App.router.get('mainHostController').get('colPropAssoc').indexOf(tag.category);
+      var filterCondition = self.get('filterConditions').findProperty('iColumn', iColumn);
+      if (filterCondition) {
+        if (typeof filterCondition.value == 'string') {
+          filterCondition.value = [filterCondition.value, tag.value];
+        } else if (Em.isArray(filterCondition.value) && filterCondition.value.indexOf(tag.value) == -1) {
+          filterCondition.value.push(tag.value);
+        }
+      } else {
+        filterCondition = {
+          skipFilter: false,
+          iColumn: iColumn,
+          value: tag.value,
+          type: 'string'
+        };
+        self.get('filterConditions').push(filterCondition);
+      }
+    });
+    this.saveAllFilterConditions();
+    this.refresh();
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cee3de4/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 93c2b9b..73dd347 100644
--- a/ambari-web/app/views/main/host/combo_search_box.js
+++ b/ambari-web/app/views/main/host/combo_search_box.js
@@ -26,58 +26,7 @@ App.MainHostComboSearchBoxView = Em.View.extend({
 
   initVS: function() {
     var self = this;
-
-    var callbacks = this.get('controller').VSCallbacks;
-    callbacks.search = function (query, searchCollection) {
-
-      searchCollection.models.forEach(function (data) {
-        var query = data.attributes;
-
-        switch (query.category) {
-          case 'health':
-            self.get('parentView').get('parentView').updateFilter(0, query.value, 'string');
-            break;
-          case 'host_name':
-            self.get('parentView').get('parentView').updateFilter(1, query.value, 'string');
-            break;
-          case 'ip':
-            self.get('parentView').get('parentView').updateFilter(2, query.value, 'string');
-            break;
-          case 'rack':
-            self.get('parentView').get('parentView').updateFilter(12, query.value, 'string');
-            break;
-          case 'version':
-            self.get('parentView').get('parentView').updateFilter(11, query.value, 'string');
-            break;
-          case 'component':
-            self.get('parentView').get('parentView').updateFilter(15, query.value, 'string');
-            break;
-          case 'service':
-            self.get('parentView').get('parentView').updateFilter(13, query.value, 'string');
-            break;
-          case 'state':
-            self.get('parentView').get('parentView').updateFilter(14, query.value, 'string');
-            break;
-        }
-      });
-
-      var $query = $('#search_query');
-      var count = searchCollection.size();
-      $query.stop().animate({opacity: 1}, {duration: 300, queue: false});
-      $query.html('<span class="raquo">&raquo;</span> You searched for: ' +
-          '<b>' + (query || '<i>nothing</i>') + '</b>. ' +
-          '(' + count + ' facet' + (count == 1 ? '' : 's') + ')');
-      clearTimeout(window.queryHideDelay);
-      window.queryHideDelay = setTimeout(function () {
-        $query.animate({
-          opacity: 0
-        }, {
-          duration: 1000,
-          queue: false
-        });
-      }, 2000);
-    };
-
+    var controller = App.router.get('mainHostComboSearchBoxController');
     window.visualSearch = VS.init({
       container: $('#combo_search_box'),
       query: '',
@@ -86,7 +35,57 @@ App.MainHostComboSearchBoxView = Em.View.extend({
       unquotable: [
         'text'
       ],
-      callbacks: callbacks
+      callbacks: {
+        search: function (query, searchCollection) {
+          console.error('query: ' + query);
+          var tableView = self.get('parentView').get('parentView');
+          tableView.updateComboFilter(searchCollection);
+        },
+
+        facetMatches: function (callback) {
+          callback([
+            {label: 'hostName', category: 'Host'},
+            {label: 'ip', category: 'Host'},
+            // {label: 'version', category: 'Host'},
+            {label: 'healthClass', category: 'Host'},
+            {label: 'rack', category: 'Host'},
+            {label: 'services', category: 'Service'},
+            {label: 'hostComponents', category: 'Service'},
+            // {label: 'state', category: 'Service'}
+          ]);
+        },
+
+        valueMatches: function (facet, searchTerm, callback) {
+          var category_mocks = require('data/host/categories');
+          switch (facet) {
+            case 'hostName':
+            case 'ip':
+              facet = (facet == 'hostName')? 'host_name' : facet;
+              controller.getPropertySuggestions(facet, searchTerm).done(function() {
+                callback(controller.get('currentSuggestion'), {preserveMatches: true});
+              });
+              break;
+            case 'rack':
+              callback(App.Host.find().toArray().mapProperty('rack').uniq());
+              break;
+            case 'version':
+              callback(App.StackVersion.find().toArray().mapProperty('name'));
+              break;
+            case 'healthClass':
+              callback(category_mocks.slice(1).mapProperty('healthStatus'), {preserveOrder: true});
+              break;
+            case 'services':
+              callback(App.Service.find().toArray().mapProperty('serviceName'), {preserveOrder: true});
+              break;
+            case 'hostComponents':
+              callback(App.HostComponent.find().toArray().mapProperty('componentName').uniq(), {preserveOrder: true});
+              break;
+            case 'state':
+              callback(App.HostComponentStatus.getStatusesList(), {preserveOrder: true});
+              break;
+          }
+        }
+      }
     });
   }
 });
\ No newline at end of file