Ver Fonte

HUE-1566 [impala] Auto complete not wide enough

The autocomplete window will be now limited by its content
Items are selectable on click
Improved autocomplete usability (spinner) and backend calls (10 minutes of metastore data validity)
Enrico Berti há 12 anos atrás
pai
commit
2a4e19d

+ 4 - 2
apps/beeswax/src/beeswax/templates/execute.mako

@@ -421,8 +421,6 @@ ${layout.menubar(section='query')}
 % endif
 <script src="/static/js/codemirror-show-hint.js"></script>
 
-<link rel="stylesheet" href="/static/ext/css/codemirror-show-hint.css">
-
 <link href="/static/ext/css/bootstrap-editable.css" rel="stylesheet">
 <script src="/static/ext/js/bootstrap-editable.min.js"></script>
 
@@ -774,6 +772,10 @@ ${layout.menubar(section='query')}
         $(document.body).on("contextmenu", function (e) {
           e.preventDefault(); // prevents native menu on FF for Mac from being shown
         });
+
+        var pos = cm.cursorCoords();
+        $("<i class='icon-spinner icon-spin CodeMirror-spinner'></i>").css("top", pos.top + "px").css("left", (pos.left - 4) + "px").appendTo($("body"));
+
         if ($.totalStorage('tables_' + $("#id_query-database").val()) == null) {
           CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
           hac_getTables($("#id_query-database").val(), function () {}); // if preload didn't work, tries again

+ 39 - 26
apps/beeswax/static/js/autocomplete.utils.js

@@ -37,6 +37,11 @@ function hac_jsoncalls(options) {
   }
 }
 
+function hac_hasExpired(timestamp){
+  var TIME_TO_LIVE_IN_MILLIS = 600000; // 10 minutes
+  return (new Date()).getTime() - timestamp > TIME_TO_LIVE_IN_MILLIS;
+}
+
 function hac_getTableAliases(textScanned) {
   var _aliases = {};
   var _val = textScanned; //codeMirror.getValue();
@@ -70,21 +75,24 @@ function hac_getTableColumns(databaseName, tableName, textScanned, callback) {
 
   if ($.totalStorage('columns_' + databaseName + '_' + tableName) != null && $.totalStorage('extended_columns_' + databaseName + '_' + tableName) != null) {
     callback($.totalStorage('columns_' + databaseName + '_' + tableName), $.totalStorage('extended_columns_' + databaseName + '_' + tableName));
-    hac_jsoncalls({
-      database: databaseName,
-      table: tableName,
-      onDataReceived: function (data) {
-        if (data.error) {
-          if (typeof HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON == undefined || data.code == null || HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON.indexOf(data.code) == -1){
-            $(document).trigger('error', data.error);
+    if ($.totalStorage('timestamp_columns_' + databaseName + '_' + tableName) == null || hac_hasExpired($.totalStorage('timestamp_columns_' + databaseName + '_' + tableName))){
+      hac_jsoncalls({
+        database: databaseName,
+        table: tableName,
+        onDataReceived: function (data) {
+          if (data.error) {
+            if (typeof HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON == "undefined" || data.code == null || HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON.indexOf(data.code) == -1){
+              $(document).trigger('error', data.error);
+            }
+          }
+          else {
+            $.totalStorage('columns_' + databaseName + '_' + tableName, (data.columns ? data.columns.join(" ") : ""));
+            $.totalStorage('extended_columns_' + databaseName + '_' + tableName, (data.extended_columns ? data.extended_columns : []));
+            $.totalStorage('timestamp_columns_' + databaseName + '_' + tableName, (new Date()).getTime());
           }
         }
-        else {
-          $.totalStorage('columns_' + databaseName + '_' + tableName, (data.columns ? data.columns.join(" ") : ""));
-          $.totalStorage('extended_columns_' + databaseName + '_' + tableName, (data.extended_columns ? data.extended_columns : []));
-        }
-      }
-    });
+      });
+    }
   }
   else {
     hac_jsoncalls({
@@ -92,13 +100,14 @@ function hac_getTableColumns(databaseName, tableName, textScanned, callback) {
       table: tableName,
       onDataReceived: function (data) {
         if (data.error) {
-          if (typeof HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON == undefined || data.code == null || HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON.indexOf(data.code) == -1){
+          if (typeof HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON == "undefined" || data.code == null || HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON.indexOf(data.code) == -1){
             $(document).trigger('error', data.error);
           }
         }
         else {
           $.totalStorage('columns_' + databaseName + '_' + tableName, (data.columns ? data.columns.join(" ") : ""));
           $.totalStorage('extended_columns_' + databaseName + '_' + tableName, (data.extended_columns ? data.extended_columns : []));
+          $.totalStorage('timestamp_columns_' + databaseName + '_' + tableName, (new Date()).getTime());
           callback($.totalStorage('columns_' + databaseName + '_' + tableName), $.totalStorage('extended_columns_' + databaseName + '_' + tableName));
         }
       }
@@ -119,31 +128,35 @@ function hac_tableHasAlias(tableName, textScanned) {
 function hac_getTables(databaseName, callback) {
   if ($.totalStorage('tables_' + databaseName) != null) {
     callback($.totalStorage('tables_' + databaseName));
-    hac_jsoncalls({
-      database: databaseName,
-      onDataReceived: function (data) {
-        if (data.error) {
-          if (typeof HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON == undefined || data.code == null || HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON.indexOf(data.code) == -1){
-            $(document).trigger('error', data.error);
+    if ($.totalStorage('timestamp_tables_' + databaseName) == null || hac_hasExpired($.totalStorage('timestamp_tables_' + databaseName))){
+      hac_jsoncalls({
+        database: databaseName,
+        onDataReceived: function (data) {
+          if (data.error) {
+            if (typeof HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON == "undefined" || data.code == null || HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON.indexOf(data.code) == -1){
+              $(document).trigger('error', data.error);
+            }
+          }
+          else {
+            $.totalStorage('tables_' + databaseName, data.tables.join(" "));
+            $.totalStorage('timestamp_tables_' + databaseName, (new Date()).getTime());
           }
         }
-        else {
-          $.totalStorage('tables_' + databaseName, data.tables.join(" "));
-        }
-      }
-    });
+      });
+    }
   }
   else {
     hac_jsoncalls({
       database: databaseName,
       onDataReceived: function (data) {
         if (data.error) {
-          if (typeof HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON == undefined || data.code == null || HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON.indexOf(data.code) == -1){
+          if (typeof HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON == "undefined" || data.code == null || HIVE_AUTOCOMPLETE_FAILS_SILENTLY_ON.indexOf(data.code) == -1){
             $(document).trigger('error', data.error);
           }
         }
         else {
           $.totalStorage('tables_' + databaseName, data.tables.join(" "));
+          $.totalStorage('timestamp_tables_' + databaseName, (new Date()).getTime());
           callback($.totalStorage('tables_' + databaseName));
         }
       }

+ 0 - 1
apps/pig/src/pig/templates/app.mako

@@ -589,7 +589,6 @@ ${ commonheader(None, "pig", user) | n,unicode }
 
 <link rel="stylesheet" href="/pig/static/css/pig.css">
 <link rel="stylesheet" href="/static/ext/css/codemirror.css">
-<link rel="stylesheet" href="/static/ext/css/codemirror-show-hint.css">
 
 <style type="text/css">
   .fileChooserBtn {

+ 40 - 0
desktop/core/static/css/hue3.css

@@ -1200,9 +1200,49 @@ a#advanced-btn:hover {
 }
 
 .CodeMirror-hints {
+  position: absolute;
   z-index: 10000 !important;
+  overflow: hidden;
+  list-style: none;
+
+  margin: 0;
+  padding: 2px;
+
+  -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+  -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+  box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+  border-radius: 3px;
+  border: 1px solid silver;
+
+  background: white;
+  font-size: 90%;
+  font-family: monospace;
+
+  max-height: 20em;
+  overflow-y: auto;
+}
+
+.CodeMirror-hint {
+  margin: 0;
+  padding: 0 4px;
+  border-radius: 2px;
+  overflow: hidden;
+  white-space: pre;
+  color: black;
+  cursor: pointer;
+}
+
+.CodeMirror-hint-active, .CodeMirror-hint:hover {
+  background: #08f;
+  color: white;
 }
 
+.CodeMirror-spinner {
+  position: absolute;
+  z-index: 9999;
+}
+
+
 .card table {
   padding-left: 10px;
   padding-right: 10px;

+ 0 - 38
desktop/core/static/ext/css/codemirror-show-hint.css

@@ -1,38 +0,0 @@
-.CodeMirror-hints {
-  position: absolute;
-  z-index: 10;
-  overflow: hidden;
-  list-style: none;
-
-  margin: 0;
-  padding: 2px;
-
-  -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
-  -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
-  box-shadow: 2px 3px 5px rgba(0,0,0,.2);
-  border-radius: 3px;
-  border: 1px solid silver;
-
-  background: white;
-  font-size: 90%;
-  font-family: monospace;
-
-  max-height: 20em;
-  overflow-y: auto;
-}
-
-.CodeMirror-hint {
-  margin: 0;
-  padding: 0 4px;
-  border-radius: 2px;
-  max-width: 19em;
-  overflow: hidden;
-  white-space: pre;
-  color: black;
-  cursor: pointer;
-}
-
-.CodeMirror-hint-active {
-  background: #08f;
-  color: white;
-}

+ 3 - 1
desktop/core/static/js/codemirror-show-hint.js

@@ -37,6 +37,8 @@ CodeMirror.showHint = function(cm, getHints, options) {
     hints.style.top = top + "px";
     document.body.appendChild(hints);
 
+    $(".CodeMirror-spinner").remove();
+
     // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
     var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
     var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
@@ -118,7 +120,7 @@ CodeMirror.showHint = function(cm, getHints, options) {
     });
     CodeMirror.on(hints, "click", function(e) {
       var t = e.target || e.srcElement;
-      if (t.hintId != null) changeActive(t.hintId);
+      if (t.hintId != null) {selectedHint = t.hintId; pick();}
       setTimeout(function(){cm.focus();}, 20);
     });