Browse Source

HUE-1619 [beeswax] Autocomplete should include 'star' in field list

Added * to field list
Moved array utils to external JS file
Fixed problem with empty columns
Fixed problem with 'FROM' special column name
Enrico Berti 12 years ago
parent
commit
3512002d58

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

@@ -792,7 +792,7 @@ ${layout.menubar(section='query')}
             }
             CodeMirror.possibleSoloField = false;
             if (_before.toUpperCase().indexOf("SELECT ") > -1 && _before.toUpperCase().indexOf(" FROM ") == -1 && !CodeMirror.fromDot) {
-              if (codeMirror.getValue().toUpperCase().indexOf("FROM") > -1) {
+              if (codeMirror.getValue().toUpperCase().indexOf("FROM ") > -1) {
                 fieldsAutocomplete(cm);
               }
               else {
@@ -815,7 +815,7 @@ ${layout.menubar(section='query')}
       function fieldsAutocomplete(cm) {
         CodeMirror.possibleSoloField = true;
         try {
-          var _possibleTables = $.trim(codeMirror.getValue().substr(codeMirror.getValue().toUpperCase().indexOf("FROM") + 4)).split(" ");
+          var _possibleTables = $.trim(codeMirror.getValue().substr(codeMirror.getValue().toUpperCase().indexOf("FROM ") + 4)).split(" ");
           var _foundTable = "";
           for (var i = 0; i < _possibleTables.length; i++) {
             if ($.trim(_possibleTables[i]) != "" && _foundTable == "") {

+ 3 - 3
apps/beeswax/static/js/autocomplete.utils.js

@@ -45,7 +45,7 @@ function hac_hasExpired(timestamp){
 function hac_getTableAliases(textScanned) {
   var _aliases = {};
   var _val = textScanned; //codeMirror.getValue();
-  var _from = _val.toUpperCase().indexOf("FROM");
+  var _from = _val.toUpperCase().indexOf("FROM ");
   if (_from > -1) {
     var _match = _val.toUpperCase().substring(_from).match(/ON|WHERE|GROUP|SORT/);
     var _to = _val.length;
@@ -86,7 +86,7 @@ function hac_getTableColumns(databaseName, tableName, textScanned, callback) {
             }
           }
           else {
-            $.totalStorage('columns_' + databaseName + '_' + tableName, (data.columns ? data.columns.join(" ") : ""));
+            $.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());
           }
@@ -105,7 +105,7 @@ function hac_getTableColumns(databaseName, tableName, textScanned, callback) {
           }
         }
         else {
-          $.totalStorage('columns_' + databaseName + '_' + tableName, (data.columns ? data.columns.join(" ") : ""));
+          $.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));

+ 0 - 10
apps/jobbrowser/static/js/utils.js

@@ -62,16 +62,6 @@ function getQueryStringParameter(name) {
 }
 
 function getStatusClass(status, prefix) {
-  if (!Array.prototype.indexOf) {
-    Array.prototype.indexOf = function (needle) {
-      for (var i = 0; i < this.length; i++) {
-        if (this[i] === needle) {
-          return i;
-        }
-      }
-      return -1;
-    };
-  }
   if (prefix == null) {
     prefix = "label-";
   }

+ 0 - 10
apps/oozie/static/js/bundles.utils.js

@@ -15,16 +15,6 @@
 // limitations under the License.
 
 function getStatusClass(status, prefix){
-  if(!Array.prototype.indexOf) {
-    Array.prototype.indexOf = function(needle) {
-      for(var i = 0; i < this.length; i++) {
-        if(this[i] === needle) {
-          return i;
-        }
-      }
-      return -1;
-    };
-  }
   if (prefix == null){
     prefix = "label-";
   }

+ 0 - 11
apps/oozie/static/js/workflow.utils.js

@@ -14,17 +14,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// adding missing .filter for IE8
-if (!('filter' in Array.prototype)) {
-  Array.prototype.filter= function(filter, that /*opt*/) {
-    var other= [], v;
-    for (var i=0, n= this.length; i<n; i++)
-      if (i in this && filter.call(that, v= this[i], i, this))
-        other.push(v);
-    return other;
-  };
-}
-
 // open a modal window for editing a node
 function edit_node_modal(modal, workflow, node, save, cancel, template) {
   var backup = ko.mapping.toJS(node);

+ 0 - 11
apps/pig/static/js/utils.js

@@ -14,17 +14,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-if (!Array.prototype.indexOf) {
-  Array.prototype.indexOf = function (needle) {
-    for (var i = 0; i < this.length; i++) {
-      if (this[i] === needle) {
-        return i;
-      }
-    }
-    return -1;
-  };
-}
-
 function getStatusClass(status, prefix) {
   if (prefix == null) {
     prefix = "label-";

+ 1 - 0
desktop/core/src/desktop/templates/common_header.mako

@@ -107,6 +107,7 @@ from django.utils.translation import ugettext as _
 
   </script>
 
+  <script src="/static/js/hue.utils.js"></script>
   <script src="/static/ext/js/jquery/jquery-2.0.2.min.js"></script>
   <script src="/static/js/jquery.migration.js"></script>
   <script src="/static/js/jquery.filechooser.js"></script>

+ 2 - 2
desktop/core/static/js/codemirror-show-hint.js

@@ -13,6 +13,8 @@ CodeMirror.showHint = function(cm, getHints, options) {
   }
 
   function showHints(data) {
+    data.list.clean("");
+    $(".CodeMirror-spinner").remove();
     if (!data || !data.list.length) return;
     var completions = data.list;
     // When there is only one completion, use it directly.
@@ -37,8 +39,6 @@ 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);

+ 62 - 0
desktop/core/static/js/hue.utils.js

@@ -0,0 +1,62 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. 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.
+
+if (!('clean' in Array.prototype)) {
+  Array.prototype.clean = function (deleteValue) {
+    for (var i = 0; i < this.length; i++) {
+      if (this[i] == deleteValue) {
+        this.splice(i, 1);
+        i--;
+      }
+    }
+    return this;
+  };
+}
+
+if (!('move' in Array.prototype)) {
+  Array.prototype.move = function (old_index, new_index) {
+    if (new_index >= this.length) {
+      var k = new_index - this.length;
+      while ((k--) + 1) {
+        this.push(undefined);
+      }
+    }
+    this.splice(new_index, 0, this.splice(old_index, 1)[0]);
+    return this;
+  };
+}
+
+if (!('indexOf' in Array.prototype)) {
+  Array.prototype.indexOf = function (needle) {
+    for (var i = 0; i < this.length; i++) {
+      if (this[i] === needle) {
+        return i;
+      }
+    }
+    return -1;
+  };
+}
+
+// adding missing .filter for IE8
+if (!('filter' in Array.prototype)) {
+  Array.prototype.filter = function (filter, that /*opt*/) {
+    var other = [], v;
+    for (var i = 0, n = this.length; i < n; i++)
+      if (i in this && filter.call(that, v = this[i], i, this))
+        other.push(v);
+    return other;
+  };
+}