Bladeren bron

HUE-7876 [editor] Move isPresentation subscription to the Notebook

Note: might create a redraw issue on header of full result screen mode (sync issue with pubsub instead of direct function call).
Romain Rigaux 7 jaren geleden
bovenliggende
commit
f8114cc

+ 3 - 3
apps/beeswax/src/beeswax/server/dbms.py

@@ -839,10 +839,10 @@ class HiveServer2Dbms(object):
     else:
       table = self.get_table(db_name, table_name)
       partitions = self.get_partitions(db_name, table, partition_spec=partition_spec)
-  
+
       if len(partitions) != 1:
         raise QueryServerException(_("Query did not return exactly one partition result: %s") % partitions)
-  
+
       partition = partitions[0]
       partition_query = " AND ".join(partition.partition_spec.split(','))
 
@@ -954,7 +954,7 @@ class SubQueryTable:
 
   def __init__(self, db, query):
     self.query = query
-    # Table Properties            
+    # Table Properties
     self.name = 'Test'
     cols = db.get_query_metadata(query).data_table.cols()
     for col in cols:

+ 2 - 3
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -54,13 +54,12 @@ try:
   from beeswax.server.dbms import get_query_server_config, QueryServerException
   from beeswax.views import parse_out_jobs
 except ImportError, e:
-  LOG.warn('Hive and HiveServer2 interfaces are not enabled')
+  LOG.warn('Hive and HiveServer2 interfaces are not enabled: %s' % e)
   hive_settings = None
 
 try:
   from impala import api   # Force checking if Impala is enabled
-  from impala.conf import CONFIG_WHITELIST as impala_settings, SSL as impala_ssl_conf
-  from impala.impala_flags import get_webserver_certificate_file
+  from impala.conf import CONFIG_WHITELIST as impala_settings
   from impala.server import get_api as get_impalad_api, ImpalaDaemonApiException, _get_impala_server_url
 except ImportError, e:
   LOG.warn("Impala app is not enabled")

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

@@ -2070,6 +2070,17 @@ var EditorViewModel = (function() {
     self.onSuccessUrl = ko.observable(typeof notebook.onSuccessUrl != "undefined" && notebook.onSuccessUrl != null ? notebook.onSuccessUrl : null);
     self.pubSubUrl = ko.observable(typeof notebook.pubSubUrl != "undefined" && notebook.pubSubUrl != null ? notebook.pubSubUrl : null);
     self.isPresentationMode = ko.observable(typeof notebook.isPresentationMode != "undefined" && notebook.isPresentationMode != null ? notebook.isPresentationMode : false);
+    self.isPresentationMode.subscribe(function(newValue) {
+        wasResultFullScreenMode = false;
+        if (! newValue) {
+          self.cancelExecutingAll();
+        }
+        huePubSub.publish('editor.presentation.operate.toggle', newValue); // Problem with headers / row numbers redraw on full screen results
+        vm.togglePresentationMode();
+        if (newValue) {
+          hueAnalytics.convert('editor', 'presentation');
+        }
+      });
     self.presentationSnippets = ko.observable({});
 
     self.snippets = ko.observableArray();
@@ -2844,6 +2855,9 @@ var EditorViewModel = (function() {
       return self.selectedNotebook() && self.selectedNotebook().snippets().length === 1 && self.selectedNotebook().snippets()[0].isSqlDialect()
     });
     self.isResultFullScreenMode = ko.observable(false);
+    self.isPresentationMode = ko.computed(function() {
+      return self.selectedNotebook() && self.selectedNotebook().isPresentationMode();
+    })
     self.isHidingCode = ko.observable(false);
     self.successUrl = ko.observable(options.success_url); // Deprecated
     self.isOptimizerEnabled = ko.observable(options.is_optimizer_enabled);

+ 74 - 88
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -250,12 +250,12 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
   <div class="pull-right margin-right-10">
   % if ENABLE_PRESENTATION.get():
     <div class="btn-group" data-bind="visible: $root.isPresentationMode()">
-      <a class="btn" title="${ _ko('Open document as presentation by default') }" data-bind="click: function() { $root.isPresentationMode(true); }">
+      <a class="btn" title="${ _ko('Open document as presentation by default') }" data-bind="click: function() { $root.selectedNotebook().isPresentationMode(true); }">
         <i class="fa" data-bind="css: {'fa-toggle-off': $root.isPresentationMode()}"></i>
       </a>
     </div>
     <div class="btn-group">
-      <a class="btn" title="${ _ko('View as a presentation') }" data-bind="click: function() { $root.isPresentationMode(true); },
+      <a class="btn" title="${ _ko('View as a presentation') }" data-bind="click: function() { $root.selectedNotebook().isPresentationMode(true); },
         css: {'btn-inverse': $root.isPresentationMode()}">
         <i class="fa fa-line-chart"></i>
       </a>
@@ -350,7 +350,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
 <!-- /ko -->
 
 <!-- ko if: $root.isPresentationMode() -->
-<a class="hueAnchor collapse-results" href="javascript:void(0)" title="${ _('Exit presentation') }" data-bind="click: function(){ $root.isPresentationMode(false); }">
+<a class="hueAnchor collapse-results" href="javascript:void(0)" title="${ _('Exit presentation') }" data-bind="click: function(){ $root.selectedNotebook().isPresentationMode(false); }">
   <i class="fa fa-times fa-fw"></i>
 </a>
 <!-- /ko -->
@@ -1181,7 +1181,6 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
       </a>
       <!-- /ko -->
     <!-- /ko -->
-    <!-- /ko -->
 
     <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
       <span class="caret"></span>
@@ -1205,6 +1204,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
         </a>
       </li>
     </ul>
+    <!-- /ko -->
   </div>
 </script>
 
@@ -1522,7 +1522,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
 
 
 <script type="text/html" id="text-snippet-body${ suffix }">
-  <div data-bind="attr:{'id': 'editor_' + id()}, html: statement_raw, value: statement_raw, medium: {}" data-placeHolder="${ _('Type your text here, select some text to format it') }" class="text-snippet"></div>
+  <div data-bind="attr: {'id': 'editor_' + id()}, html: statement_raw, value: statement_raw, medium: {}" data-placeHolder="${ _('Type your text here, select some text to format it') }" class="text-snippet"></div>
 </script>
 
 
@@ -1536,7 +1536,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
       }"></div>
     </div>
     <div class="span6">
-      <div data-bind="html: renderMarkdown(statement_raw(), id()), attr: {'id': 'liveMD'+id()}"></div>
+      <div data-bind="html: renderMarkdown(statement_raw(), id()), attr: {'id': 'liveMD' + id()}"></div>
     </div>
   </div>
   <!-- /ko -->
@@ -2049,7 +2049,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
   var shareViewModel = initSharing("#documentShareModal");
   % endif
 
-
+function togglePresentation(value) {};
 
   var isLeftNavOpen = false;
   huePubSub.subscribe('left.nav.open.toggle', function (val) {
@@ -3177,75 +3177,73 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
       viewModel.init();
 
 
-  % if not IS_EMBEDDED.get():
-      if (window.Worker) {
-        // It can take a while before the worker is active
-        var whenWorkerIsReady = function (worker, message) {
-          if (!worker.isReady) {
-            window.clearTimeout(worker.pingTimeout);
-            worker.postMessage({ ping: true });
-            worker.pingTimeout = window.setTimeout(function () {
-              whenWorkerIsReady(worker, message);
-            }, 500);
-          } else {
-            worker.postMessage(message);
-          }
-        };
-
-        // For syntax checking
-        var aceSqlSyntaxWorker = new Worker('/desktop/workers/aceSqlSyntaxWorker.js?v=' + HUE_VERSION);
-        aceSqlSyntaxWorker.onmessage = function (e) {
-          if (e.data.ping) {
-            aceSqlSyntaxWorker.isReady = true;
-          } else {
-            huePubSub.publish('ace.sql.syntax.worker.message', e);
+      % if not IS_EMBEDDED.get():
+        if (window.Worker) {
+          // It can take a while before the worker is active
+          var whenWorkerIsReady = function (worker, message) {
+            if (!worker.isReady) {
+              window.clearTimeout(worker.pingTimeout);
+              worker.postMessage({ ping: true });
+              worker.pingTimeout = window.setTimeout(function () {
+                whenWorkerIsReady(worker, message);
+              }, 500);
+            } else {
+              worker.postMessage(message);
+            }
+          };
+  
+          // For syntax checking
+          var aceSqlSyntaxWorker = new Worker('/desktop/workers/aceSqlSyntaxWorker.js?v=' + HUE_VERSION);
+          aceSqlSyntaxWorker.onmessage = function (e) {
+            if (e.data.ping) {
+              aceSqlSyntaxWorker.isReady = true;
+            } else {
+              huePubSub.publish('ace.sql.syntax.worker.message', e);
+            }
+          };
+  
+          huePubSub.subscribe('ace.sql.syntax.worker.post', function (message) {
+            whenWorkerIsReady(aceSqlSyntaxWorker, message);
+          });
+  
+          // For location marking
+          var aceSqlLocationWorker = new Worker('/desktop/workers/aceSqlLocationWorker.js?v=' + HUE_VERSION);
+          aceSqlLocationWorker.onmessage = function (e) {
+            if (e.data.ping) {
+              aceSqlLocationWorker.isReady = true;
+            } else {
+              huePubSub.publish('ace.sql.location.worker.message', e);
+            }
+          };
+  
+          huePubSub.subscribe('ace.sql.location.worker.post', function (message) {
+            whenWorkerIsReady(aceSqlLocationWorker, message);
+          });
+        }
+      % else:
+        var iframe = document.createElement("iframe");
+        iframe.src = (typeof adaptHueEmbeddedUrls !== 'undefined' ? adaptHueEmbeddedUrls('/notebook/workers_embedded?v=') : '/notebook/workers_embedded?v=') + HUE_VERSION;
+        iframe.name = "workerFrame";
+        iframe.setAttribute('style', 'display: none;');
+        document.body.appendChild(iframe);
+    
+        window.addEventListener("message", function (event) {
+          if (event.data.locationWorkerResponse) {
+            huePubSub.publish('ace.sql.location.worker.message', { data: event.data.locationWorkerResponse });
           }
-        };
-
-        huePubSub.subscribe('ace.sql.syntax.worker.post', function (message) {
-          whenWorkerIsReady(aceSqlSyntaxWorker, message);
-        });
-
-        // For location marking
-        var aceSqlLocationWorker = new Worker('/desktop/workers/aceSqlLocationWorker.js?v=' + HUE_VERSION);
-        aceSqlLocationWorker.onmessage = function (e) {
-          if (e.data.ping) {
-            aceSqlLocationWorker.isReady = true;
-          } else {
-            huePubSub.publish('ace.sql.location.worker.message', e);
+          if (event.data.syntaxWorkerResponse) {
+            huePubSub.publish('ace.sql.syntax.worker.message', { data: event.data.syntaxWorkerResponse });
           }
-        };
-
+        }, false);
+    
         huePubSub.subscribe('ace.sql.location.worker.post', function (message) {
-          whenWorkerIsReady(aceSqlLocationWorker, message);
+          iframe.contentWindow.postMessage({ locationWorkerRequest: message }, '*')
         });
-      }
-  % else:
-    var iframe = document.createElement("iframe");
-    iframe.src = (typeof adaptHueEmbeddedUrls !== 'undefined' ? adaptHueEmbeddedUrls('/notebook/workers_embedded?v=') : '/notebook/workers_embedded?v=') + HUE_VERSION;
-    iframe.name = "workerFrame";
-    iframe.setAttribute('style', 'display: none;');
-    document.body.appendChild(iframe);
-
-    window.addEventListener("message", function (event) {
-      if (event.data.locationWorkerResponse) {
-        huePubSub.publish('ace.sql.location.worker.message', { data: event.data.locationWorkerResponse });
-      }
-      if (event.data.syntaxWorkerResponse) {
-        huePubSub.publish('ace.sql.syntax.worker.message', { data: event.data.syntaxWorkerResponse });
-      }
-    }, false);
-
-    huePubSub.subscribe('ace.sql.location.worker.post', function (message) {
-      iframe.contentWindow.postMessage({ locationWorkerRequest: message }, '*')
-    });
-
-    huePubSub.subscribe('ace.sql.syntax.worker.post', function (message) {
-      iframe.contentWindow.postMessage({ syntaxWorkerRequest: message }, '*')
-    });
-
-  % endif
-
+    
+        huePubSub.subscribe('ace.sql.syntax.worker.post', function (message) {
+          iframe.contentWindow.postMessage({ syntaxWorkerRequest: message }, '*')
+        });
+      % endif
 
       if (viewModel.isOptimizerEnabled()) {
         % if OPTIMIZER.AUTO_UPLOAD_QUERIES.get():
@@ -3288,19 +3286,18 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
 
       function exitPlayerMode() {
         if (! wasResultFullScreenMode) {
-          viewModel.isPresentationMode(false);
+          viewModel.selectedNotebook().isPresentationMode(false);
         } else {
           viewModel.isResultFullScreenMode(false);
         }
       }
 
-      function togglePresentation(value) {
+       huePubSub.subscribe('editor.presentation.operate.toggle', function (value) {
         viewModel.isEditing(! viewModel.isEditing());
         if (value) {
           $(".jHueNotify").remove();
           isAssistAvailable = viewModel.assistAvailable();
           wasLeftPanelVisible = viewModel.isLeftPanelVisible();
-          console.log(viewModel.isPresentationMode());
           wasRightPanelVisible = viewModel.isRightPanelVisible();
 
           if (wasResultFullScreenMode) {
@@ -3345,23 +3342,12 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
           redrawFixedHeaders(200);
           $(window).unbind("keydown", exitPlayerMode);
         }
-      }
+      }, HUE_PUB_SUB_EDITOR_ID);
 
       viewModel.isResultFullScreenMode.subscribe(function(newValue) {
         wasResultFullScreenMode = true;
         togglePresentation(newValue);
       });
-      viewModel.isPresentationMode.subscribe(function(newValue) {
-        wasResultFullScreenMode = false;
-        if (! newValue) {
-          viewModel.selectedNotebook().cancelExecutingAll();
-        }
-        togglePresentation(newValue);
-        viewModel.togglePresentationMode();
-        if (newValue) {
-          hueAnalytics.convert('editor', 'presentation');
-        }
-      });
 
       huePubSub.subscribe('assist.set.manual.visibility', function () {
         wasLeftPanelVisible = viewModel.isLeftPanelVisible();
@@ -3423,7 +3409,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
       });
 
       huePubSub.subscribe('editor.presentation.toggle', function () {
-        viewModel.isPresentationMode(!viewModel.isPresentationMode());
+        viewModel.selectedNotebook().isPresentationMode(!viewModel.isPresentationMode());
       }, HUE_PUB_SUB_EDITOR_ID);
 
       $(window).bind("keydown", "ctrl+shift+p alt+shift+p meta+shift+p", function (e) {