Преглед изворни кода

HUE-1376 [beeswax] Autocomplete doesn't work after the 'where' keyword

Added where autocompletion for simple statements involving just one table
Enrico Berti пре 12 година
родитељ
комит
683ced1
1 измењених фајлова са 35 додато и 27 уклоњено
  1. 35 27
      apps/beeswax/src/beeswax/templates/execute.mako

+ 35 - 27
apps/beeswax/src/beeswax/templates/execute.mako

@@ -743,7 +743,6 @@ ${layout.menubar(section='query')}
       };
 
       CodeMirror.commands.autocomplete = function (cm) {
-        tableMagic = false;
         if ($.totalStorage('tables_' + $("#id_query-database").val()) == null) {
           CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
           getTables(function () {}); // if preload didn't work, tries again
@@ -761,31 +760,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) {
-                CodeMirror.possibleSoloField = true;
-                try {
-                  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 == "") {
-                      _foundTable = _possibleTables[i];
-                    }
-                  }
-                  if (_foundTable != "") {
-                    if (tableHasAlias(_foundTable)) {
-                      CodeMirror.possibleSoloField = false;
-                      CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
-                    }
-                    else {
-                      getTableColumns(_foundTable,
-                              function (columns) {
-                                CodeMirror.catalogFields = columns;
-                                CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
-                              });
-                    }
-                  }
-                }
-                catch (e) {
-                }
+                fieldsAutocomplete(cm);
               }
               else {
                 CodeMirror.tableFieldMagic = true;
@@ -793,12 +768,45 @@ ${layout.menubar(section='query')}
               }
             }
             else {
-              CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
+              if (_before.toUpperCase().indexOf("WHERE ") > -1 && !CodeMirror.fromDot && _before.match(/ON|GROUP|SORT/) == null) {
+                fieldsAutocomplete(cm);
+              }
+              else {
+                CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
+              }
             }
           });
         }
       }
 
+      function fieldsAutocomplete(cm) {
+        CodeMirror.possibleSoloField = true;
+        try {
+          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 == "") {
+              _foundTable = _possibleTables[i];
+            }
+          }
+          if (_foundTable != "") {
+            if (tableHasAlias(_foundTable)) {
+              CodeMirror.possibleSoloField = false;
+              CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
+            }
+            else {
+              getTableColumns(_foundTable,
+                  function (columns) {
+                    CodeMirror.catalogFields = columns;
+                    CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
+                  });
+            }
+          }
+        }
+        catch (e) {
+        }
+      }
+
       CodeMirror.fromDot = false;
 
       var codeMirror = CodeMirror(function (elt) {