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

HUe-3294 [notebook] Retrieve content of document snippet

Romain Rigaux пре 9 година
родитељ
комит
b4974a6

+ 1 - 0
desktop/core/src/desktop/static/desktop/js/document/documentChooser.js

@@ -35,6 +35,7 @@ var DocumentChooser = (function () {
       if (this.options && typeof this.options.type === 'function') {
         type = TYPE_MAP[this.options.type()] ? TYPE_MAP[this.options.type()] : this.options.type();
       }
+      // Todo: multi types
 
       $.get('/desktop/api2/docs/', {
         type: type,

+ 2 - 2
desktop/libs/notebook/src/notebook/api.py

@@ -746,10 +746,10 @@ def get_external_statement(request):
   snippet = json.loads(request.POST.get('snippet', '{}'))
 
   if snippet.get('statementType') == 'file':
-    snippet['statement'] = _get_statement_from_file(request.user, request.fs, snippet)
+    response['statement'] = _get_statement_from_file(request.user, request.fs, snippet)
   elif snippet.get('statementType') == 'document':
     notebook = Notebook(Document2.objects.get_by_uuid(user=request.user, uuid=snippet['associatedDocumentUuid'], perm_type='read'))
-    snippet['statement'] = notebook.get_str()
+    response['statement'] = notebook.get_str()
 
   response['status'] = 0
 

+ 16 - 14
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -426,20 +426,21 @@ var EditorViewModel = (function() {
     }
     self.statementPath = ko.observable(typeof snippet.statementPath != "undefined" && snippet.statementPath != null ? snippet.statementPath : '');
     self.statementPath.subscribe(function(newVal) {
-      if (self.statementType() == 'file') { //aaaa
-        $.post("/notebook/api/get_external_statement", {
-          notebook: ko.mapping.toJSON(notebook.getContext()),
-          snippet: ko.mapping.toJSON(self.getContext())
-        }, function(data) {
-          if (data.status == 0) {
-            self.statement_raw(data.statement);
-            self.ace().setValue(self.statement_raw(), 1);
-          } else {
-            self._ajaxError(data);
-          }
-        });
-      }
+      self.getExternalStatement();
     });
+    self.getExternalStatement = function() {
+      $.post("/notebook/api/get_external_statement", {
+        notebook: ko.mapping.toJSON(notebook.getContext()),
+        snippet: ko.mapping.toJSON(self.getContext())
+      }, function(data) {
+        if (data.status == 0) {
+          self.statement_raw(data.statement);
+          self.ace().setValue(self.statement_raw(), 1);
+        } else {
+          self._ajaxError(data);
+        }
+      });
+    }
     self.associatedDocument = ko.observable();
     self.associatedDocumentUuid = ko.observable(typeof snippet.associatedDocumentUuid != "undefined" && snippet.associatedDocumentUuid != null ? snippet.associatedDocumentUuid : null);
     if (self.associatedDocumentUuid()){
@@ -447,6 +448,7 @@ var EditorViewModel = (function() {
     }
     self.associatedDocumentUuid.subscribe(function(val){
       vm.documentChooser.setAssociatedDocument(val, self.associatedDocument);
+      self.getExternalStatement();
     });
     self.statement_raw = ko.observable(typeof snippet.statement_raw != "undefined" && snippet.statement_raw != null ? snippet.statement_raw : '');
     self.selectedStatement = ko.observable('');
@@ -551,7 +553,7 @@ var EditorViewModel = (function() {
     if (vm.isOptimizerEnabled()) {
       self.delayedStatement = ko.pureComputed(self.statement).extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 5000 } });
       self.delayedStatement.subscribe(function (val) {
-        self.getComplexity();
+        //self.getComplexity();
         self.hasSuggestion(false);
       }, self);
     }

+ 3 - 11
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1639,23 +1639,15 @@ ${ hueIcons.symbols() }
               type: 'query-hive',
               create: function (event, ui) {
                 if (associatedDocument()) {
-                  this.value = ko.dataFor(event.target).associatedDocument().name();
-                } else if (associatedDocumentUuid()) {
-      $.get('/desktop/api2/doc/', {
-        uuid: associatedDocumentUuid()
-      }, function(data){
-        if (data && data.document){
-          this.value = data.document.name;
-        }
-      });
+                  this.value = associatedDocument().name();
                 }
                 return false;
                },
-              select: function (event, ui) { ko.dataFor(event.target).associatedDocumentUuid(ui.item.value); this.value = ui.item.label; return false;},
+              select: function (event, ui) { associatedDocumentUuid(ui.item.value); this.value = ui.item.label; return false;},
               focus: function (event, ui) { this.value = ui.item.label; return false; },
               change: function (event, ui) {
                 if (associatedDocument()) {
-                  this.value = ko.dataFor(event.target).associatedDocument().name();
+                  this.value = associatedDocument().name();
                 }
                 return false;
               },