Explorar o código

HUE-6700 [editor] Use the correct huePubSub ID in the viewmodel

Johan Ahlen %!s(int64=8) %!d(string=hai) anos
pai
achega
bc380e7

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

@@ -305,7 +305,7 @@ var EditorViewModel = (function() {
       if (self.inFocus() || notebook.snippets().length === 1) {
         huePubSub.publish('set.active.snippet.type', self.type());
       }
-    }, 'editor');
+    }, vm.huePubSubId);
 
     self.getAceMode = function() {
       return vm.getSnippetViewSettings(self.type()).aceMode;
@@ -350,13 +350,13 @@ var EditorViewModel = (function() {
       if (['hive', 'impala'].indexOf(self.type()) !== -1) {
         updateDatabases();
       }
-    }, 'editor');
+    }, vm.huePubSubId);
 
     huePubSub.subscribe('save.snippet.to.file', function() {
       var data = {
         path: self.statementPath(),
         contents: self.statement()
-      }
+      };
       var options = {
         successCallback: function(result) {
           if (result && result.exists) {
@@ -365,10 +365,10 @@ var EditorViewModel = (function() {
             self._ajaxError(result);
           }
         }
-      }
+      };
       var apiHelper = ApiHelper.getInstance();
       apiHelper.saveSnippetToFile(data, options);
-    }, 'editor');
+    }, vm.huePubSubId);
 
     // 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');
@@ -378,7 +378,7 @@ var EditorViewModel = (function() {
       contextData.tabId = 'context' + self.pinnedContextTabs().length;
       self.pinnedContextTabs.push(contextData);
       self.currentQueryTab(contextData.tabId);
-    }, 'editor');
+    }, vm.huePubSubId);
 
     self.removeContextTab = function (context) {
       if (context.tabId === self.currentQueryTab()) {
@@ -460,7 +460,7 @@ var EditorViewModel = (function() {
       if (source !== self.type()) {
         huePubSub.publish('assist.set.source', self.type());
       }
-    });
+    }, vm.huePubSubId);
 
     huePubSub.publish('assist.get.source');
 
@@ -470,8 +470,8 @@ var EditorViewModel = (function() {
       }
     };
 
-    huePubSub.subscribe("assist.database.set", handleAssistSelection);
-    huePubSub.subscribe("assist.database.selected", handleAssistSelection);
+    huePubSub.subscribe("assist.database.set", handleAssistSelection, vm.huePubSubId);
+    huePubSub.subscribe("assist.database.selected", handleAssistSelection, vm.huePubSubId);
 
     if (! self.database()) {
       huePubSub.publish("assist.get.database", self.type());
@@ -2413,7 +2413,7 @@ var EditorViewModel = (function() {
         if (!IS_HUE_4) {
           huePubSub.subscribe('hue4.process.headers', function (opts) {
             opts.callback(opts.response);
-          });
+          }, vm.huePubSubId);
         }
 
         getCoordinator();
@@ -2492,7 +2492,7 @@ var EditorViewModel = (function() {
           name: self.snippets()[0].database()
         });
       }
-    });
+    }, vm.huePubSubId);
 
     huePubSub.publish('assist.is.db.panel.ready');
 
@@ -2510,7 +2510,6 @@ var EditorViewModel = (function() {
     }
   };
 
-
   function EditorViewModel(editor_id, notebooks, options, CoordinatorEditorViewModel, RunningCoordinatorModel) {
     var self = this;
 
@@ -2522,6 +2521,7 @@ var EditorViewModel = (function() {
       hue4_notebook: '/hue/notebook'
     };
 
+    self.huePubSubId = options.huePubSubId || 'editor';
     self.user = options.user;
     self.userId = options.userId;
     self.suffix = options.suffix;
@@ -2539,7 +2539,7 @@ var EditorViewModel = (function() {
     self.editorTypeTitle = ko.pureComputed(function () {
       var foundInterpreter = $.grep(options.languages, function (interpreter) {
         return interpreter.type === self.editorType();
-      })
+      });
       return foundInterpreter.length > 0 ? foundInterpreter[0].name : self.editorType();
     });
     self.useNewAutocompleter = options.useNewAutocompleter || false;
@@ -2660,7 +2660,7 @@ var EditorViewModel = (function() {
 
     huePubSub.subscribe('context.panel.visible.editor', function (value) {
       self.isContextPanelVisible(false);
-    });
+    }, self.huePubSubId);
 
     self.availableSnippets = ko.mapping.fromJS(options.languages);
 

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

@@ -1941,18 +1941,17 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 <script type="text/javascript">
   % if is_embeddable:
   var MAIN_SCROLLABLE = '.page-content';
-  var HUE_PUB_SUB_AFFIX = (window.location.getParameter('type') ? '-' + window.location.getParameter('type') : '');
+  var HUE_PUB_SUB_EDITOR_ID = 'editor' + (window.location.getParameter('type') ? '-' + window.location.getParameter('type') : '');
   % else:
   var MAIN_SCROLLABLE = '.content-panel';
-  var HUE_PUB_SUB_AFFIX = '';
+  var HUE_PUB_SUB_EDITOR_ID = 'editor';
   % endif
 
-  var HUE_PUB_SUB_APP = 'editor' + HUE_PUB_SUB_AFFIX;
 
   var isLeftNavOpen = false;
   huePubSub.subscribe('left.nav.open.toggle', function(val) {
     isLeftNavOpen = val;
-  }, HUE_PUB_SUB_APP);
+  }, HUE_PUB_SUB_EDITOR_ID);
 
   var showHoverMsg = function (e) {
     var dt = null;
@@ -2618,6 +2617,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
     ko.options.deferUpdates = true;
 
     var VIEW_MODEL_OPTIONS = $.extend(${ options_json | n,unicode,antixss }, {
+      huePubSubId: HUE_PUB_SUB_EDITOR_ID,
       user: '${ user.username }',
       userId: ${ user.id },
       suffix: '${ suffix }',
@@ -2823,28 +2823,28 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
       splitDraggableTimeout = window.setTimeout(function () {
         redrawFixedHeaders(100);
       }, 200);
-    }, HUE_PUB_SUB_APP);
+    }, HUE_PUB_SUB_EDITOR_ID);
 
     huePubSub.subscribe('redraw.fixed.headers', function () {
       hideFixedHeaders();
       redrawFixedHeaders(200);
-    }, HUE_PUB_SUB_APP);
+    }, HUE_PUB_SUB_EDITOR_ID);
 
     huePubSub.subscribe('app.gained.focus', function (app) {
       if (app === 'editor') {
         huePubSub.publish('redraw.fixed.headers');
       }
-    }, HUE_PUB_SUB_APP);
+    }, HUE_PUB_SUB_EDITOR_ID);
 
     huePubSub.subscribe('show.saveToFile.modal', function () {
       $('#saveToFileModal${ suffix }').modal('show');
-    }, HUE_PUB_SUB_APP);
+    }, HUE_PUB_SUB_EDITOR_ID);
 
     huePubSub.subscribe('tab.switched', function (tab) {
       if (tab !== 'queryResults') {
         $('.hue-datatable-search').hide();
       }
-    }, HUE_PUB_SUB_APP);
+    }, HUE_PUB_SUB_EDITOR_ID);
 
     huePubSub.subscribe('detach.scrolls', function (snippet) {
       var scrollElement = $('#snippet_' + snippet.id()).find('.dataTables_wrapper');
@@ -2854,7 +2854,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
       if (scrollElement.data('scrollFnDt')) {
         scrollElement.off('scroll', scrollElement.data('scrollFnDt'));
       }
-    }, HUE_PUB_SUB_APP);
+    }, HUE_PUB_SUB_EDITOR_ID);
 
     window.redrawFixedHeaders = redrawFixedHeaders;
 
@@ -3067,15 +3067,15 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
       if (viewModel.isOptimizerEnabled()) {
         huePubSub.subscribe('editor.upload.table.stats', function (options) {
           viewModel.selectedNotebook().snippets()[0].uploadTableStats(options);
-        }, HUE_PUB_SUB_APP);
+        }, HUE_PUB_SUB_EDITOR_ID);
 
         huePubSub.subscribe("editor.upload.history", function () {
           viewModel.selectedNotebook().snippets()[0].uploadQueryHistory(5);
-        }, HUE_PUB_SUB_APP);
+        }, HUE_PUB_SUB_EDITOR_ID);
 
         huePubSub.subscribe("editor.upload.query", function (query_id) {
           viewModel.selectedNotebook().snippets()[0].uploadQuery(query_id);
-        }, HUE_PUB_SUB_APP);
+        }, HUE_PUB_SUB_EDITOR_ID);
       }
 
       huePubSub.subscribe('editor.active.statement.changed', function (statementDetails) {
@@ -3089,7 +3089,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
             foundSnippet[0].positionStatement('');
           }
         }
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       viewModel.selectedNotebook.subscribe(function (newVal) {
         huePubSub.publish('selected.notebook.changed', newVal);
@@ -3097,7 +3097,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
       huePubSub.subscribe('get.selected.notebook', function () {
         huePubSub.publish('set.selected.notebook', viewModel.selectedNotebook());
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
 
       var isAssistAvailable = viewModel.assistAvailable();
@@ -3149,7 +3149,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
       huePubSub.subscribe('assist.set.manual.visibility', function () {
         wasLeftPanelVisible = viewModel.isLeftPanelVisible();
         wasRightPanelVisible = viewModel.isRightPanelVisible();
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       viewModel.isLeftPanelVisible.subscribe(function (value) {
         redrawFixedHeaders(200);
@@ -3174,11 +3174,11 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
       huePubSub.subscribe('show.retry.modal', function (data) {
         $('#retryModal${ suffix }').modal('show');
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       huePubSub.subscribe('hide.retry.modal', function (data) {
         $('#retryModal${ suffix }').modal('hide');
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       // Close the notebook snippets when leaving the page
       window.onbeforeunload = function (e) {
@@ -3205,7 +3205,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         return false;
       });
 
-      huePubSub.subscribe('editor.save', saveKeyHandler, HUE_PUB_SUB_APP);
+      huePubSub.subscribe('editor.save', saveKeyHandler, HUE_PUB_SUB_EDITOR_ID);
 
       $(document).bind('keyup', function (e) {
         if (e.keyCode == 191 && e.shiftKey && !$(e.target).is('input') && !$(e.target).is('textarea')) {
@@ -3237,7 +3237,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         return false;
       });
 
-      huePubSub.subscribe('editor.create.new', newKeyHandler, HUE_PUB_SUB_APP);
+      huePubSub.subscribe('editor.create.new', newKeyHandler, HUE_PUB_SUB_EDITOR_ID);
 
       var initialResizePosition = 100;
 
@@ -3449,7 +3449,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'});
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       huePubSub.subscribe('editor.snippet.result.normal', function (snippet) {
         var $snippet = $("#snippet_" + snippet.id());
@@ -3457,7 +3457,7 @@ 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'});
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       $(document).on("renderDataError", function (e, options) {
         huePubSub.publish('editor.snippet.result.normal', options.snippet);
@@ -3480,7 +3480,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         if (typeof renderJqCron !== 'undefined'){
           renderJqCron();
         }
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       huePubSub.subscribe('submit.popup.return', function (data) {
         viewModel.selectedNotebook().viewSchedulerId(data.job_id);
@@ -3488,7 +3488,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
         $('.submit-modal-editor').modal('hide');
 
         $('a[href=\'#scheduledJobsTab\']').click();
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       huePubSub.subscribe('jobbrowser.data', function (jobs) {
         if (jobs.length > 0) {
@@ -3510,7 +3510,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
             });
           }
         }
-      }, HUE_PUB_SUB_APP);
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       $(document).on("gridShown", function (e, snippet) {
         window.setTimeout(function () {