浏览代码

HUE-7876 [presentation] Persist isHidingCode setting

Romain Rigaux 7 年之前
父节点
当前提交
04ca6db

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

@@ -2084,6 +2084,7 @@ var EditorViewModel = (function() {
     });
     self.isPresentationMode(self.isPresentationModeDefault());
     self.presentationSnippets = ko.observable({});
+    self.isHidingCode = ko.observable(typeof notebook.isHidingCode != "undefined" && notebook.isHidingCode != null ? notebook.isHidingCode : false);
 
     self.snippets = ko.observableArray();
     self.selectedSnippet = ko.observable(vm.editorType()); // Aka selectedSnippetType
@@ -2860,8 +2861,10 @@ var EditorViewModel = (function() {
     self.isResultFullScreenMode = ko.observable(false);
     self.isPresentationMode = ko.computed(function() {
       return self.selectedNotebook() && self.selectedNotebook().isPresentationMode();
+    });
+    self.isHidingCode = ko.computed(function() {
+      return self.selectedNotebook() && self.selectedNotebook().isHidingCode();
     })
-    self.isHidingCode = ko.observable(false);
     self.successUrl = ko.observable(options.success_url); // Deprecated
     self.isOptimizerEnabled = ko.observable(options.is_optimizer_enabled);
     self.isNavigatorEnabled = ko.observable(options.is_navigator_enabled);

+ 20 - 15
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -256,7 +256,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
           <i class="fa fa-line-chart"></i>
         </a>
 
-        <!-- ko if: $root.isPresentationMode() && $root.canSave() -->
+        <!-- ko if: $root.canSave() -->
         <a class="btn dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
         <ul class="dropdown-menu">
           <li>
@@ -894,7 +894,12 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
 <script type="text/html" id="notebook-snippet-header${ suffix }">
   <!-- ko if: $root.isPresentationMode() || $root.isResultFullScreenMode() -->
   <div class="inline">
-    <span data-bind="text: name"></span>
+    <!-- ko if: name() -->
+      <span data-bind="text: name"></span>
+    <!-- /ko -->
+    <!-- ko if: !name() && !$root.isHidingCode() -->
+      <span>${ _("Add -- comments on top of the SQL statement to display a title") }</span>
+    <!-- /ko -->
   </div>
   <!-- /ko -->
 
@@ -1195,17 +1200,17 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
     </a>
     <ul class="dropdown-menu">
       <li>
-        <a class="pointer" data-bind="click: function() { $root.selectedNotebook().clearResults() }">
-          <i class="fa fa-fw fa-eraser"></i> ${ _('Clear results') }
-        </a>
-      </li>
-      <li>
-        <a class="pointer" rel="tooltip" data-placement="bottom" data-bind="click: function() { $root.isHidingCode(! $root.isHidingCode()); }, attr: { 'title': $root.isHidingCode() ? '${ _ko('Show code') }' : '${ _ko('Hide code') }' }">
+        <a class="pointer" rel="tooltip" data-placement="bottom" data-bind="click: function() { $root.selectedNotebook().isHidingCode(! $root.isHidingCode()); }, attr: { 'title': $root.isHidingCode() ? '${ _ko('Show the logic') }' : '${ _ko('Hide the logic') }' }">
           <i class="fa fa-fw" data-bind="css: { 'fa-expand': $root.isHidingCode(), 'fa-compress': ! $root.isHidingCode() }"></i>
           <span data-bind="visible: $root.isHidingCode">${ _('Show the code') }</span>
           <span data-bind="visible: ! $root.isHidingCode()">${ _('Hide the code') }</span>
         </a>
       </li>
+      <li>
+        <a class="pointer" data-bind="click: function() { $root.selectedNotebook().clearResults() }">
+          <i class="fa fa-fw fa-eraser"></i> ${ _('Clear results') }
+        </a>
+      </li>
       <li>
         <a href="javascript:void(0)" data-bind="click: displayCombinedContent, visible: ! $root.isPresentationMode() ">
           <i class="fa fa-fw fa-file-text-o"></i> ${ _('Show all content') }
@@ -3199,7 +3204,7 @@ function togglePresentation(value) {};
               worker.postMessage(message);
             }
           };
-  
+
           // For syntax checking
           var aceSqlSyntaxWorker = new Worker('/desktop/workers/aceSqlSyntaxWorker.js?v=' + HUE_VERSION);
           aceSqlSyntaxWorker.onmessage = function (e) {
@@ -3209,11 +3214,11 @@ function togglePresentation(value) {};
               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) {
@@ -3223,7 +3228,7 @@ function togglePresentation(value) {};
               huePubSub.publish('ace.sql.location.worker.message', e);
             }
           };
-  
+
           huePubSub.subscribe('ace.sql.location.worker.post', function (message) {
             whenWorkerIsReady(aceSqlLocationWorker, message);
           });
@@ -3234,7 +3239,7 @@ function togglePresentation(value) {};
         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 });
@@ -3243,11 +3248,11 @@ function togglePresentation(value) {};
             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 }, '*')
         });