Repository: ambari
Updated Branches:
  refs/heads/trunk 77ea2eba0 -> 8f7576f20


AMBARI-14700. Combo Search: Implement on-demand value list on top of 
visualsearch.js (rzang)


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

Branch: refs/heads/trunk
Commit: 8f7576f20d60da75b06f16e7e3dee1cf1089f94c
Parents: 77ea2eb
Author: Richard Zang <rz...@apache.org>
Authored: Fri Jan 22 05:27:13 2016 +0800
Committer: Richard Zang <rz...@apache.org>
Committed: Fri Jan 22 05:27:13 2016 +0800

----------------------------------------------------------------------
 ambari-web/app/controllers.js                   |   1 +
 .../controllers/main/host/combo_search_box.js   | 130 +++++++++++++++++++
 ambari-web/app/routes/main.js                   |   1 +
 ambari-web/app/templates/main/host.hbs          |   2 +-
 .../app/views/main/host/combo_search_box.js     | 107 +--------------
 5 files changed, 138 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8f7576f2/ambari-web/app/controllers.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers.js b/ambari-web/app/controllers.js
index 5f3f841..330beb5 100644
--- a/ambari-web/app/controllers.js
+++ b/ambari-web/app/controllers.js
@@ -109,6 +109,7 @@ require('controllers/main/host/bulk_operations_controller');
 require('controllers/main/host/details');
 require('controllers/main/host/configs_service');
 require('controllers/main/host/add_controller');
+require('controllers/main/host/combo_search_box');
 require('controllers/main/host/addHost/step4_controller');
 require('controllers/main/host/host_alerts_controller');
 require('controllers/main/charts');

http://git-wip-us.apache.org/repos/asf/ambari/blob/8f7576f2/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
new file mode 100644
index 0000000..3832611
--- /dev/null
+++ b/ambari-web/app/controllers/main/host/combo_search_box.js
@@ -0,0 +1,130 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+App.MainHostComboSearchBoxController = Em.Controller.extend({
+  name: 'mainHostComboSearchBoxController',
+  currentSuggestion: [],
+
+  VSCallbacks : {
+    search: function (query, searchCollection) {
+      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);
+    },
+
+    facetMatches: function (callback) {
+      console.log('called');
+      callback([
+        {label: 'name', category: 'Host'},
+        {label: 'ip', category: 'Host'},
+        {label: 'version', category: 'Host'},
+        {label: 'health', 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');
+      switch (facet) {
+        case 'name':
+          controller.getHostPropertySuggestions('name', 
searchTerm).done(function() {
+            callback(controller.get('currentSuggestion'));
+          });
+          break;
+        case 'ip':
+          callback(App.Host.find().toArray().mapProperty('ip'));
+          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([
+            Em.I18n.t('hosts.host.healthStatusCategory.green'),
+            Em.I18n.t('hosts.host.healthStatusCategory.red'),
+            Em.I18n.t('hosts.host.healthStatusCategory.orange'),
+            Em.I18n.t('hosts.host.healthStatusCategory.yellow'),
+            Em.I18n.t('hosts.host.alerts.label'),
+            Em.I18n.t('common.restart'),
+            Em.I18n.t('common.passive_state')
+          ]);
+          break;
+        case 'service':
+          callback(App.Service.find().toArray().mapProperty('serviceName'));
+          break;
+        case 'component':
+          
callback(App.MasterComponent.find().toArray().mapProperty('componentName')
+              
.concat(App.SlaveComponent.find().toArray().mapProperty('componentName'))
+              
.concat(App.ClientComponent.find().toArray().mapProperty('componentName'))
+            ,{preserveOrder: true});
+          break;
+        case 'state':
+          callback([
+            Em.I18n.t('common.started'),
+            Em.I18n.t('common.stopped'),
+            Em.I18n.t('hosts.host.stackVersions.status.install_failed'),
+            Em.I18n.t('hosts.host.decommissioning'),
+            Em.I18n.t('hosts.host.decommissioned')
+          ], {preserveOrder: true});
+          break;
+      }
+    }
+  },
+
+  getHostPropertySuggestions: function(facet, searchTerm) {
+    return App.ajax.send({
+      name: 'hosts.all.install',
+      sender: this,
+      success: 'updateHostNameSuggestion',
+      error: 'commonSuggestionErrorCallback'
+    });
+  },
+
+  updateHostNameSuggestion: function(data) {
+    this.updateSuggestion(data.items.map(function(item) {
+      return item.Hosts.host_name;
+    }));
+  },
+
+  updateSuggestion: function(data) {
+    var controller = App.router.get('mainHostComboSearchBoxController');
+    controller.set('currentSuggestion', data);
+  },
+
+  commonSuggestionErrorCallback:function() {
+    // handle suggestion error
+  }
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/8f7576f2/ambari-web/app/routes/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index 70714b9..1166194 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -193,6 +193,7 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
       connectOutlets: function (router, context) {
         App.loadTimer.start('Hosts Page');
         router.get('mainController').connectOutlet('mainHost');
+        
router.get('mainHostController').connectOutlet('mainHostComboSearchBox');
       }
     }),
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/8f7576f2/ambari-web/app/templates/main/host.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host.hbs 
b/ambari-web/app/templates/main/host.hbs
index 1c575a9..508448c 100644
--- a/ambari-web/app/templates/main/host.hbs
+++ b/ambari-web/app/templates/main/host.hbs
@@ -54,7 +54,7 @@
       {{/view}}
     </div>
   </div>
-  {{view App.MainHostComboSearchBoxView}}
+  {{outlet}}
   <table class="table advanced-header-table table-bordered table-striped" 
id="hosts-table">
     <thead>
       {{#view view.sortView classNames="label-row" 
contentBinding="view.filteredContent"}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/8f7576f2/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 927a540..36af44d 100644
--- a/ambari-web/app/views/main/host/combo_search_box.js
+++ b/ambari-web/app/views/main/host/combo_search_box.js
@@ -21,6 +21,10 @@ var App = require('app');
 App.MainHostComboSearchBoxView = Em.View.extend({
   templateName: require('templates/main/host/combo_search_box'),
   didInsertElement: function () {
+    this.initVS();
+  },
+
+  initVS: function() {
     window.visualSearch = VS.init({
       container: $('#combo_search_box'),
       query: '',
@@ -28,108 +32,7 @@ App.MainHostComboSearchBoxView = Em.View.extend({
       unquotable: [
         'text'
       ],
-      callbacks: {
-        search: function (query, searchCollection) {
-          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);
-        },
-        facetMatches: function (callback) {
-          console.log('called');
-          callback([
-            {label: 'name', category: 'Host'},
-            {label: 'ip', category: 'Host'},
-            {label: 'version', category: 'Host'},
-            {label: 'health', category: 'Host'},
-            {label: 'service', category: 'Service'},
-            {label: 'component', category: 'Service'},
-            {label: 'state', category: 'Service'}
-          ]);
-        },
-        valueMatches: function (facet, searchTerm, callback) {
-          switch (facet) {
-            case 'name':
-              callback([
-                {value: 'c6401.ambari.apache.org', label: 
'c6401.ambari.apache.org'},
-                {value: 'c6402.ambari.apache.org', label: 
'c6402.ambari.apache.org'},
-                {value: 'c6403.ambari.apache.org', label: 
'c6403.ambari.apache.org'}
-              ]);
-              break;
-            case 'ip':
-              callback(['192.168.64.101', '192.168.64.102', '192.168.64.103']);
-              break;
-            case 'rack':
-              callback(['/default-rack', '/default-rack-1', 
'/default-rack-2']);
-              break;
-            case 'version':
-              callback([
-                'HDP-2.0.0.0-1587',
-                'HDP-2.1.2.2-1576',
-                'HDP-2.2.4.0-2252',
-                'HDP-2.3.4.0-3485'
-              ]);
-              break;
-            case 'health':
-              callback([
-                'Healthy',
-                'Master Down',
-                'Slave Down',
-                'Lost Heartbeat',
-                'Alerts',
-                'Restart',
-                'Maintainance Mode'
-              ]);
-              break;
-            case 'service':
-              callback([
-                'HDFS',
-                'YARN',
-                'HIVE',
-                'HBASE',
-                'Storm',
-                'Oozie',
-                'Falcon',
-                'Pig',
-                'Spark',
-                'Zookeeper',
-                'AMS',
-                'Ranger'
-              ]);
-              break;
-            case 'component':
-              callback([
-                'NameNode',
-                'SNameNode',
-                'ZooKeeper Server',
-                'DataNode',
-                'HDFS Client',
-                'Zookeeper Client'
-              ], {preserveOrder: true});
-              break;
-            case 'state':
-              callback([
-                'Started',
-                'Stopped',
-                'Install Failed',
-                'Decommissioning',
-                'Decommissioned'
-              ], {preserveOrder: true});
-              break;
-          }
-        }
-      }
+      callbacks: this.get('controller').VSCallbacks
     });
   }
 });
\ No newline at end of file

Reply via email to