Browse Source

HUE-4866 [editor] Operation to open up an external query file

use e.g.:
huePubSub.publish('open.editor.query.external', {'statementType': 'file', 'statementPath': '/user/romain/test.sql'});
Romain Rigaux 8 years ago
parent
commit
3921884665

+ 10 - 0
desktop/core/src/desktop/templates/hue.mako

@@ -603,6 +603,16 @@ ${ assist.assistPanel() }
           })
         });
 
+        huePubSub.subscribe('open.editor.query.external', function (statementOptions) {
+          self.currentApp('editor');
+          self.getActiveAppViewModel(function (viewModel) {
+            viewModel.newNotebook(function() { // Uses default type of Editor
+              viewModel.selectedNotebook().snippets()[0].statementType(statementOptions['statementType']);
+              viewModel.selectedNotebook().snippets()[0].statementPath(statementOptions['statementPath']);
+            });
+          })
+        });
+
         huePubSub.subscribe('open.link', function (href) {
           if (href.startsWith('/notebook/editor')){
             if (hueUtils.getSearchParameter(href, 'editor') !== '') {

+ 6 - 2
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -480,7 +480,7 @@ var EditorViewModel = (function() {
       }
       else {
         self.statement_raw('');
-          self.ace().setValue('', 1);
+        self.ace().setValue('', 1);
       }
     });
     self.statement_raw = ko.observable(typeof snippet.statement_raw != "undefined" && snippet.statement_raw != null ? snippet.statement_raw : '');
@@ -2603,7 +2603,7 @@ var EditorViewModel = (function() {
       });
     };
 
-    self.newNotebook = function () {
+    self.newNotebook = function (callback) {
       $.post("/notebook/api/create_notebook", {
         type: options.editor_type,
         directory_uuid: window.location.getParameter('directory_uuid')
@@ -2640,6 +2640,10 @@ var EditorViewModel = (function() {
             self.changeURL('/notebook/notebook');
           }
         }
+
+        if (typeof callback !== 'undefined'){
+          callback();
+        }
       });
     };