فهرست منبع

HUE-6077 [frontend] Support for clearing app subscribers and hook up on Editor

Enrico Berti 8 سال پیش
والد
کامیت
874b4c27a6

+ 7 - 0
desktop/core/src/desktop/static/desktop/js/hue.utils.js

@@ -482,6 +482,13 @@ var huePubSub = (function () {
           });
         });
       }
+    },
+    clearAppSubscribers: function (app) {
+      if (app) {
+        Object.keys(topics).forEach(function (topicName) {
+          topics[topicName] = topics[topicName].filter(function(obj){ return obj.app !== app});
+        });
+      }
     }
   };
 })();

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

@@ -623,6 +623,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           self.isLoadingEmbeddable(true);
           loadedApps.forEach(function (loadedApp) {
             window.pauseAppIntervals(loadedApp);
+            huePubSub.pauseAppSubscribers(loadedApp);
           });
           if (typeof self.embeddable_cache[app] === 'undefined') {
             if (loadedApps.indexOf(app) == -1){
@@ -652,6 +653,8 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
               },
               dataType: 'html',
               success: function (response) {
+                window.clearAppIntervals(app);
+                huePubSub.clearAppSubscribers(app);
                 self.extraEmbeddableURLParams('');
                 var r = self.processHeaders(response);
                 if (SKIP_CACHE.indexOf(app) === -1) {
@@ -668,6 +671,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
             self.isLoadingEmbeddable(false);
           }
           window.resumeAppIntervals(app);
+          huePubSub.resumeAppSubscribers(app);
           $('.embeddable').hide();
           $('#embeddable_' + app).insertBefore($('.embeddable:first')).show();
         };

+ 4 - 4
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -300,7 +300,7 @@ var EditorViewModel = (function() {
       if (self.inFocus() || notebook.snippets().length === 1) {
         huePubSub.publish('set.active.snippet.type', self.type());
       }
-    });
+    }, 'editor');
 
     self.getAceMode = function() {
       return vm.getSnippetViewSettings(self.type()).aceMode;
@@ -345,7 +345,7 @@ var EditorViewModel = (function() {
       if (self.type() == options.sourceType) {
         updateDatabases();
       }
-    });
+    }, 'editor');
 
     huePubSub.subscribe('save.snippet.to.file', function() {
       var data = {
@@ -363,7 +363,7 @@ var EditorViewModel = (function() {
       }
       var apiHelper = ApiHelper.getInstance();
       apiHelper.saveSnippetToFile(data, options);
-    });
+    }, 'editor');
 
     // History is currently in Notebook, same with saved queries by snippets, might be better in assist
     self.currentQueryTab = ko.observable(typeof snippet.currentQueryTab != "undefined" && snippet.currentQueryTab != null ? snippet.currentQueryTab : 'queryHistory');
@@ -373,7 +373,7 @@ var EditorViewModel = (function() {
       contextData.tabId = 'context' + self.pinnedContextTabs().length;
       self.pinnedContextTabs.push(contextData);
       self.currentQueryTab(contextData.tabId);
-    });
+    }, 'editor');
 
     self.removeContextTab = function (context) {
       if (context.tabId === self.currentQueryTab()) {

+ 18 - 18
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1958,7 +1958,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
   var isLeftNavOpen = false;
   huePubSub.subscribe('left.nav.open.toggle', function(val) {
     isLeftNavOpen = val;
-  });
+  }, 'editor');
 
   var showHoverMsg = function (e) {
     var dt = null;
@@ -2815,22 +2815,22 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
       splitDraggableTimeout = window.setTimeout(function () {
         redrawFixedHeaders(100);
       }, 200);
-    });
+    }, 'editor');
 
     huePubSub.subscribe('redraw.fixed.headers', function () {
       hideFixedHeaders();
       redrawFixedHeaders(200);
-    });
+    }, 'editor');
 
     huePubSub.subscribe('show.saveToFile.modal', function () {
       $('#saveToFileModal').modal('show');
-    });
+    }, 'editor');
 
     huePubSub.subscribe('tab.switched', function (tab) {
       if (tab !== 'queryResults') {
         $('.hue-datatable-search').hide();
       }
-    });
+    }, 'editor');
 
     huePubSub.subscribe('detach.scrolls', function (snippet) {
       var scrollElement = $('#snippet_' + snippet.id()).find('.dataTables_wrapper');
@@ -2840,7 +2840,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
       if (scrollElement.data('scrollFnDt')) {
         scrollElement.off('scroll', scrollElement.data('scrollFnDt'));
       }
-    });
+    }, 'editor');
 
     huePubSub.subscribe('table.row.dblclick', function(data){
       var $el = $(data.table);
@@ -2860,7 +2860,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
       $('#detailsModal').modal('show');
 
-    });
+    }, 'editor');
 
     window.redrawFixedHeaders = redrawFixedHeaders;
 
@@ -3118,7 +3118,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
       huePubSub.subscribe('assist.set.manual.visibility', function () {
         wasAssistVisible = viewModel.isLeftPanelVisible();
-      });
+      }, 'editor');
 
       viewModel.isLeftPanelVisible.subscribe(function (value) {
         redrawFixedHeaders(200);
@@ -3143,11 +3143,11 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
       huePubSub.subscribe('show.retry.modal', function (data) {
         $('#retryModal').modal('show');
-      });
+      }, 'editor');
 
       huePubSub.subscribe('hide.retry.modal', function (data) {
         $('#retryModal').modal('hide');
-      });
+      }, 'editor');
 
       // Close the notebook snippets when leaving the page
       window.onbeforeunload = function (e) {
@@ -3174,7 +3174,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         return false;
       });
 
-      huePubSub.subscribe('editor.save', saveKeyHandler);
+      huePubSub.subscribe('editor.save', saveKeyHandler, 'editor');
 
       $(document).bind('keyup', function (e) {
         if (e.keyCode == 191 && e.shiftKey && !$(e.target).is('input') && !$(e.target).is('textarea')) {
@@ -3206,7 +3206,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         return false;
       });
 
-      huePubSub.subscribe('editor.create.new', newKeyHandler);
+      huePubSub.subscribe('editor.create.new', newKeyHandler, 'editor');
 
       var initialResizePosition = 100;
 
@@ -3418,7 +3418,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         $snippet.find(".dataTables_wrapper .fixed-header-row").css({opacity: '0'});
         $snippet.find(".dataTables_wrapper .fixed-first-cell").css({opacity: '0'});
         $snippet.find(".dataTables_wrapper .resultTable").css({opacity: '0.55'});
-      });
+      }, 'editor');
 
       huePubSub.subscribe('editor.snippet.result.normal', function (snippet) {
         var $snippet = $("#snippet_" + snippet.id());
@@ -3426,11 +3426,11 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         $snippet.find(".dataTables_wrapper .fixed-header-row").css({opacity: '1'});
         $snippet.find(".dataTables_wrapper .fixed-first-cell").css({opacity: '1'});
         $snippet.find(".dataTables_wrapper .resultTable").css({opacity: '1'});
-      });
+      }, 'editor');
 
       $(document).on("renderDataError", function (e, options) {
         huePubSub.publish('editor.snippet.result.normal', options.snippet);
-      });
+      }, 'editor');
 
       $(document).on("progress", function (e, options) {
         if (options.data == 100) {
@@ -3455,7 +3455,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         if (typeof renderJqCron !== 'undefined'){
           renderJqCron();
         }
-      });
+      }, 'editor');
 
       huePubSub.subscribe('submit.popup.return', function (data) {
         viewModel.selectedNotebook().viewSchedulerId(data.job_id);
@@ -3463,7 +3463,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         $('.submit-modal').modal('hide');
 
         $('a[href=\'#scheduledJobsTab\']').click();
-      });
+      }, 'editor');
 
       huePubSub.subscribe('jobbrowser.data', function (jobs) {
         if (jobs.length > 0) {
@@ -3485,7 +3485,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
             });
           }
         }
-      });
+      }, 'editor');
 
       $(document).on("gridShown", function (e, snippet) {
         window.setTimeout(function () {