Browse Source

HUE-4536 [editor] Load query generates JS error

Enrico Berti 9 years ago
parent
commit
78ca1b7

+ 4 - 2
desktop/core/src/desktop/static/desktop/js/jquery.huedatatable.js

@@ -390,10 +390,12 @@
         var drawTimeout = -1;
         if (self.$table.data('oInit')['scrollable'] && !self.$table.data('isScrollAttached')) {
           self.$table.data('isScrollAttached', true);
-          self.$table.parents(oInit['scrollable']).on('scroll', function () {
+          var scrollFn = function(){
             window.clearTimeout(drawTimeout);
             drawTimeout = window.setTimeout(self.fnDraw, Math.max(100, Math.min(self.$table.data('aoColumns').length, 500)));
-          });
+          }
+          self.$table.parents(oInit['scrollable']).data('scrollFnDt', scrollFn);
+          self.$table.parents(oInit['scrollable']).on('scroll', scrollFn);
         }
       }
       self.$table.addClass('table-huedatatable');

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

@@ -2027,6 +2027,7 @@
       var notebook = new Notebook(self, notebook);
 
       if (notebook.snippets().length > 0) {
+        huePubSub.publish('detach.scrolls', notebook.snippets()[0]);
         notebook.selectedSnippet(notebook.snippets()[notebook.snippets().length - 1].type());
         if (currentQueries != null) {
           notebook.snippets()[0].queries(currentQueries);
@@ -2100,6 +2101,7 @@
         self.loadNotebook(data.notebook);
         if (self.editorMode()) {
           self.selectedNotebook().newSnippet();
+          huePubSub.publish('detach.scrolls', self.selectedNotebook().snippets()[0]);
           if (window.location.getParameter('new') == '') {
             self.selectedNotebook().snippets()[0].statement_raw($.totalStorage('hue.notebook.lastWrittenSnippet.' + self.user + '.' + window.location.getParameter('type')));
             $.totalStorage('hue.notebook.lastWrittenSnippet.' + self.user +  '.' + window.location.getParameter('type'), '');

+ 21 - 5
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -2342,8 +2342,12 @@ ${ hueIcons.symbols() }
       scrollElement = $('.right-panel');
     }
 
+    if (scrollElement.data('scrollFnDtCreation')) {
+      scrollElement.off('scroll', scrollElement.data('scrollFnDtCreation'));
+    }
+
     var resultFollowTimeout = -1;
-    scrollElement.on('scroll', function () {
+    var dataScroll = function () {
       if (vm.editorMode()) {
         var snippetEl = $('#snippet_' + snippet.id());
         if (snippetEl.find('.dataTables_wrapper').length > 0 && snippet.showGrid()) {
@@ -2379,7 +2383,9 @@ ${ hueIcons.symbols() }
           }
         }, 100);
       }
-    });
+    }
+    scrollElement.data('scrollFnDtCreation', dataScroll);
+    scrollElement.on('scroll', dataScroll);
 
     return _dt;
   }
@@ -2857,18 +2863,28 @@ ${ hueIcons.symbols() }
     };
 
     var splitDraggableTimeout = -1;
-    huePubSub.subscribe('split.draggable.position', function(){
+    huePubSub.subscribe('split.draggable.position', function () {
       window.clearTimeout(splitDraggableTimeout);
-      splitDraggableTimeout = window.setTimeout(function(){
+      splitDraggableTimeout = window.setTimeout(function () {
         redrawFixedHeaders(100);
       }, 200);
     });
 
-    huePubSub.subscribe('redraw.fixed.headers', function(){
+    huePubSub.subscribe('redraw.fixed.headers', function () {
       hideFixedHeaders();
       redrawFixedHeaders(200);
     });
 
+    huePubSub.subscribe('detach.scrolls', function (snippet) {
+      var scrollElement = $('#snippet_' + snippet.id()).find('.dataTables_wrapper');
+      if (viewModel.editorMode()) {
+        scrollElement = $('.right-panel');
+      }
+      if (scrollElement.data('scrollFnDt')) {
+        scrollElement.off('scroll', scrollElement.data('scrollFnDt'));
+      }
+    });
+
     window.redrawFixedHeaders = redrawFixedHeaders;
 
     function addAce(content, snippetType) {