瀏覽代碼

HUE-2642 [spark] Automatically open a new snippet on execute of the last snippet

This automatically adds a new snippet of the last added type after execute of the last snippet. When adding new snippet with an Ace editor it will also put focus on the editor after adding it.
Johan Ahlen 10 年之前
父節點
當前提交
a22fea5726
共有 2 個文件被更改,包括 15 次插入19 次删除
  1. 15 12
      apps/spark/src/spark/static/spark/js/spark.ko.js
  2. 0 7
      apps/spark/src/spark/templates/editor_components.mako

+ 15 - 12
apps/spark/src/spark/static/spark/js/spark.ko.js

@@ -383,6 +383,10 @@ var Snippet = function (vm, notebook, snippet) {
 
         self.result.hasResultset(data.handle.has_result_set);
         self.checkStatus();
+
+        if (notebook.snippets()[notebook.snippets().length - 1] == self) {
+          notebook.newSnippet();
+        }
       } else {
         self._ajaxError(data, self.execute);
       }
@@ -672,6 +676,8 @@ var Notebook = function (vm, notebook) {
       window.setTimeout(function(){
         self.createSession(new Session(vm, {'type': _snippet.type()}));
       }, 200);
+    } else {
+      _snippet.status('ready');
     }
 
     _snippet.init();
@@ -721,24 +727,21 @@ var Notebook = function (vm, notebook) {
   };
 
   self.newSnippet = function () {
-
-    var _snippet = new Snippet(vm, self, {
+    self.addSnippet({
       type: self.selectedSnippet(),
       result: {}
     });
-    self.snippets.push(_snippet);
 
-    if (self.getSession(_snippet.type()) == null) {
-      window.setTimeout(function(){
-        self.createSession(new Session(vm, {'type': _snippet.type()}));
-      }, 200);
-    }
-    else {
-      _snippet.status('ready');
-    }
+    window.setTimeout(function () {
+      var lastSnippet = self.snippets()[self.snippets().length - 1];
+      if (lastSnippet.ace() != null) {
+        lastSnippet.ace().focus();
+      }
+
+      $(".right-panel").scrollTop($(".right-panel").prop('scrollHeight'));
+    }, 100);
 
     logGA('/add_snippet/' + self.selectedSnippet());
-    $(document).trigger("snippetAdded", _snippet);
   };
 
   self.getContext = function() {

+ 0 - 7
apps/spark/src/spark/templates/editor_components.mako

@@ -1265,13 +1265,6 @@ from django.utils.translation import ugettext as _
       }
     }
 
-    $(document).on("snippetAdded", function (e, snippet) {
-      var _handle = $("#snippet_" + snippet.id()).find(".resize-panel a");
-      if (_handle.length > 0) {
-        _handle.draggable(getDraggableOptions(_handle.offset().top));
-      }
-    });
-
     $(document).on("toggleResultSettings", function (e, snippet) {
       $("#snippet_" + snippet.id()).find(".chart").trigger("forceUpdate");
       redrawFixedHeaders();