Bläddra i källkod

[beeswax] Double click on Assist with an empty editor creates an automagic SELECT LIMIT

Enrico Berti 10 år sedan
förälder
incheckning
ef9a53a

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

@@ -1610,8 +1610,18 @@ $(document).ready(function () {
     }
   });
 
-  huePubSub.subscribe('assist.dblClickItem', function(value) {
-    codeMirror.replaceSelection(value);
+  huePubSub.subscribe('assist.dblClickItem', function(assistEntry) {
+    var text = assistEntry.editorText();
+    if (codeMirror.getValue() == queryPlaceholder) {
+      codeMirror.setValue("");
+      if (assistEntry.definition.isTable) {
+        text = "SELECT * FROM " + assistEntry.editorText() + " LIMIT 100";
+      }
+      else if (assistEntry.definition.isColumn) {
+        text = "SELECT " + assistEntry.editorText().split(",")[0] + " FROM " + assistEntry.parent.editorText() + " LIMIT 100";
+      }
+    }
+    codeMirror.replaceSelection(text);
     codeMirror.setSelection(codeMirror.getCursor());
     codeMirror.focus();
   });

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

@@ -2085,9 +2085,18 @@
         }
       });
 
-      huePubSub.subscribe("assist.dblClickItem", function(value) {
+      huePubSub.subscribe("assist.dblClickItem", function(assistEntry) {
         if ($el.data("last-active-editor")) {
-          editor.session.insert(editor.getCursorPosition(), value);
+          var text = assistEntry.editorText();
+          if (editor.getValue() == "") {
+            if (assistEntry.definition.isTable) {
+              text = "SELECT * FROM " + assistEntry.editorText() + " LIMIT 100";
+            }
+            else if (assistEntry.definition.isColumn) {
+              text = "SELECT " + assistEntry.editorText().split(",")[0] + " FROM " + assistEntry.parent.editorText() + " LIMIT 100";
+            }
+          }
+          editor.session.insert(editor.getCursorPosition(), text);
         }
       });
 

+ 1 - 1
desktop/core/src/desktop/templates/ko_components.mako

@@ -466,7 +466,7 @@ from desktop.views import _ko
 
       AssistEntry.prototype.dblClick = function (data, event) {
         var self = this;
-        huePubSub.publish('assist.dblClickItem', self.editorText());
+        huePubSub.publish('assist.dblClickItem', self);
       };
 
       AssistEntry.prototype.toggleOpen = function () {