浏览代码

HUE-5893 [core] Hide hive chooser autocomplete when empty

Also added skipTables configuration
Enrico Berti 8 年之前
父节点
当前提交
d969463e7a

+ 27 - 7
desktop/core/src/desktop/static/desktop/js/jquery.hiveautocomplete.js

@@ -24,6 +24,7 @@
       serverType: "HIVE",
       home: "/",
       skipColumns: false,
+      skipTables: false,
       onEnter: function () {
       },
       onBlur: function () {
@@ -148,6 +149,7 @@
           if (path.indexOf(".") > -1) {
             path = path.substr(path.lastIndexOf(".") + 1);
           }
+          $("#jHueGenericAutocomplete").show();
           $("#jHueGenericAutocomplete ul li").show();
           if (path != "") {
             $("#jHueGenericAutocomplete ul li").each(function () {
@@ -162,6 +164,9 @@
                 }
               }
             });
+            if ($("#jHueGenericAutocomplete ul li:visible").length === 0){
+              $("#jHueGenericAutocomplete").hide();
+            }
           }
         }, 500);
       }
@@ -266,6 +271,7 @@
         var _ico = "";
         var _iterable = [];
         var _isSkipColumns = false;
+        var _isSkipTables = false;
 
         if (self.options.serverType == "SOLR") {
           _iterable = data.collections;
@@ -277,10 +283,15 @@
             _ico = "fa-database";
           }
           else if (data.tables_meta != null) { // it's a table
-            _iterable = $.map(data.tables_meta, function (tablesMeta) {
-              return tablesMeta.name;
-            });
-            _ico = "fa-table";
+            if (!self.options.skipTables) {
+              _iterable = $.map(data.tables_meta, function (tablesMeta) {
+                return tablesMeta.name;
+              });
+              _ico = "fa-table";
+            }
+            else {
+              _isSkipTables = true;
+            }
           }
           else {
             if (!self.options.skipColumns) {
@@ -296,7 +307,7 @@
         var firstSolrCollection = false;
         var firstSolrConfig = false;
 
-        if (!_isSkipColumns) {
+        if (!_isSkipColumns && !_isSkipTables) {
           $(_iterable).each(function (cnt, item) {
             if (self.options.serverType == "SOLR") {
               if (item.isCollection && !firstSolrCollection) {
@@ -317,6 +328,8 @@
             }
           });
 
+
+
           $("#jHueGenericAutocomplete").css("top", $el.offset().top + $el.outerHeight() - 1).css("left", $el.offset().left).width($el.outerWidth() - 4);
           $("#jHueGenericAutocomplete").find("ul").empty().html(_currentFiles.join(""));
           $("#jHueGenericAutocomplete").find("li").on("click", function (e) {
@@ -342,9 +355,16 @@
             }
 
             if ($(this).html().indexOf("database") > -1) {
-              $el.val(item + ".");
+              if (self.options.skipTables) {
+                $el.val(item);
+              }
+              else {
+                $el.val(item + ".");
+              }
               self.options.onPathChange($el.val());
-              showAutocomplete();
+              if (!self.options.skipTables) {
+                showAutocomplete();
+              }
             }
 
             if ($(this).html().indexOf("table") > -1) {

+ 2 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -2768,6 +2768,7 @@
         self.jHueGenericAutocomplete({
           showOnFocus: true,
           skipColumns: ko.unwrap(options.skipColumns),
+          skipTables: ko.unwrap(options.skipTables),
           startingPath: options.database + '.',
           rewriteVal: true,
           onPathChange: options.onChange,
@@ -2795,6 +2796,7 @@
           showOnFocus: true,
           home: "/",
           skipColumns: ko.unwrap(options.skipColumns) || false,
+          skipTables: ko.unwrap(options.skipTables) || false,
           apiHelperUser: ko.unwrap(options.apiHelperUser) || '',
           apiHelperType: ko.unwrap(options.apiHelperType) || '',
           onPathChange: function (path) {

+ 3 - 1
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -499,7 +499,7 @@ ${ assist.assistPanel() }
             <!-- /ko -->
 
             <!-- ko if: outputFormat() == 'table' || outputFormat() == 'database' -->
-              <input type="text" data-bind="value: name, hivechooser: name, skipColumns: true, valueUpdate: 'afterkeydown'" pattern="^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]*$" title="${ _('Only alphanumeric and underscore characters') }" placeholder="${ _('Table name or <database>.<table>') }">
+              <input type="text" data-bind="value: name, hivechooser: name, skipColumns: true, skipTables: outputFormat() == 'database', valueUpdate: 'afterkeydown', apiHelperUser: '${ user }', apiHelperType: apiHelperType" pattern="^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]*$" title="${ _('Only alphanumeric and underscore characters') }" placeholder="${ _('Table name or <database>.<table>') }">
             <!-- /ko -->
 
             <span class="help-inline muted" data-bind="visible: ! isTargetExisting()">
@@ -1262,6 +1262,8 @@ ${ assist.assistPanel() }
         resizeElements();
       });
 
+      self.apiHelperType = ko.observable('hive');
+
       self.description = ko.observable('');
       self.outputFormat = ko.observable('table');
       self.outputFormat.subscribe(function (newValue) {