瀏覽代碼

HUE-6173 [assist] Make sure the right assistant is loaded when opening saved editors

Johan Ahlen 8 年之前
父節點
當前提交
44021828a8

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

@@ -3419,7 +3419,7 @@
           huePubSub.publish('editor.active.locations', lastKnownLocations);
 
           huePubSub.subscribe('get.active.editor.locations', function () {
-            huePubSub.publish('editor.active.cursor.location', lastKnownLocations);
+            huePubSub.publish('editor.active.locations', lastKnownLocations);
           });
 
 
@@ -3619,7 +3619,7 @@
         }, 100);
       });
 
-      huePubSub.subscribe('get.active.editor.locations', function () {
+      huePubSub.subscribe('get.active.editor.cursor.location', function () {
         huePubSub.publish('editor.active.cursor.location', { id: $el.attr("id"), position: editor.getCursorPosition() });
       });
 

+ 14 - 2
desktop/core/src/desktop/templates/assist.mako

@@ -1689,6 +1689,9 @@ from notebook.conf import get_ordered_interpreters
   </script>
 
   <script type="text/html" id="assistant-panel-template">
+    <!-- ko if: statementCount() > 1 -->
+    ${ _('Statement') } <span data-bind="text: activeStatementIndex() + '/' + statementCount()"></span><br/>
+    <!-- /ko -->
     ${ _('Tables') }
     <br/>
     <ul data-bind="foreach: activeTables">
@@ -1742,7 +1745,9 @@ from notebook.conf import get_ordered_interpreters
         self.activeSourceType = ko.observable();
         self.activeTables = ko.observableArray();
         self.activeColumns = ko.observableArray();
-        self.activeRisks = ko.observableArray();
+        self.activeRisks = ko.observableArray()
+        self.statementCount = ko.observable(0);
+        self.activeStatementIndex = ko.observable(0);
 
         var isPointInside = function (location, row, col) {
           return (location.first_line < row && row < location.last_line) ||
@@ -1758,6 +1763,9 @@ from notebook.conf import get_ordered_interpreters
         };
 
         var initActive = function () {
+          if (_.isUndefined(self.activeCursorLocation())) {
+            huePubSub.publish('get.active.editor.cursor.location');
+          }
           if (typeof self.activeCursorLocation() !== 'undefined' && typeof self.locationIndex()[self.activeCursorLocation().id] !== 'undefined') {
             var locations = self.locationIndex()[self.activeCursorLocation().id].locations;
             self.activeSourceType(self.locationIndex()[self.activeCursorLocation().id].type);
@@ -1778,23 +1786,27 @@ from notebook.conf import get_ordered_interpreters
             if (currentStatement.length > 0) {
               statements.push(currentStatement);
             }
+            self.statementCount(statements.length);
 
             if (statements.length > 0) {
               // Pick the last statement by default (only one or cursor after last ';')
+              var statementIndex = statements.length;
               var activeStatement = _.last(statements);
               if (statements.length > 1) {
                 var cursorPos = self.activeCursorLocation().position;
-                var index = 0;
+                var index = 1;
                 statements.every(function (statement) {
                   // First is the actual statement
                   if (isPointInside(statement[0].location, cursorPos.row+1, cursorPos.column+1)) {
                     activeStatement = statement;
+                    statementIndex = index;
                     return false;
                   }
                   index++;
                   return true;
                 })
               }
+              self.activeStatementIndex(statementIndex);
             }
 
             var tableIndex = {};

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

@@ -2653,6 +2653,7 @@ var EditorViewModel = (function() {
           if (typeof skipUrlChange === 'undefined' && ! self.isNotificationManager()){
             if (self.editorMode()) {
               self.editorType(data.document.type.substring('query-'.length));
+              huePubSub.publish('active.snippet.type.changed', self.editorType());
               if (self.isHue4()){
                 self.changeURL(self.URLS.hue4 + '?editor=' + data.document.id);
               } else {
@@ -2689,6 +2690,7 @@ var EditorViewModel = (function() {
           if (window.location.getParameter('type') === '') {
             hueUtils.changeURLParameter('type', self.editorType());
           }
+          huePubSub.publish('active.snippet.type.changed', editorType);
         }
 
         if (typeof callback !== 'undefined'){