Browse Source

HUE-8449 [report] Enable save a query after clicking on Report on the editor

Enrico Berti 7 years ago
parent
commit
376878e43d

+ 7 - 3
desktop/core/src/desktop/templates/common_notebook_ko_components.mako

@@ -213,8 +213,8 @@ except ImportError, e:
         </li>
         % if ENABLE_SQL_INDEXER.get():
         <li>
-          <a class="download" href="javascript:void(0)" data-bind="click: function() { saveTarget('dashboard'); trySaveResults(); }" title="${ _('Visually explore the result') }">
-            <!-- ko template: { name: 'app-icon-template', data: { icon: 'dashboard' } } --><!-- /ko --> ${ _('Dashboard') }
+          <a class="download" href="javascript:void(0)" data-bind="click: function() { saveTarget('dashboard'); if (notebook.canSave() ) { notebook.save() } else { $('#saveAsModaleditor').modal('show');} }" title="${ _('Visually explore the result') }">
+            <!-- ko template: { name: 'app-icon-template', data: { icon: 'report' } } --><!-- /ko --> ${ _('Report') }
           </a>
         </li>
         % endif
@@ -368,6 +368,10 @@ except ImportError, e:
 
         self.checkDownloadInterval = -1;
 
+        if (!self.snippet.downloadResultViewModel) {
+          self.snippet.downloadResultViewModel = ko.observable(self);
+        }
+
         self.saveResultsModalId = '#saveResultsModal' + self.snippet.id();
         self.downloadProgressModalId = '#downloadProgressModal' + self.snippet.id();
 
@@ -445,7 +449,7 @@ except ImportError, e:
                   $(self.saveResultsModalId).modal('hide');
                   huePubSub.publish('open.importer.query', resp);
                 } else if (self.saveTarget() == 'dashboard') {
-                  $(self.saveResultsModalId).modal('hide');
+                   $(self.saveResultsModalId).modal('hide');
                   huePubSub.publish('open.link', resp.watch_url);
                 } else if (resp.history_uuid) {
                   $(self.saveResultsModalId).modal('hide');

+ 24 - 24
desktop/core/src/desktop/templates/hue_icons.mako

@@ -334,41 +334,41 @@
 
   <script type="text/html" id="app-icon-template">
     <!-- ko switch: icon -->
-    <!-- ko case: 'dashboard' --><svg class="hi"><use xlink:href="#hi-dashboard"></use></svg><!-- /ko -->
-    <!-- ko case: 'documents' --><svg class="hi"><use xlink:href="#hi-documents"></use></svg><!-- /ko -->
+    <!-- ko case: 'dashboard' --><svg class="hi hi-fw"><use xlink:href="#hi-dashboard"></use></svg><!-- /ko -->
+    <!-- ko case: 'documents' --><svg class="hi hi-fw"><use xlink:href="#hi-documents"></use></svg><!-- /ko -->
     <!-- ko case: 'report' --><i class="fa fa-fw fa-area-chart"></i><!-- /ko -->
     <!-- ko case: 'dist-cp' --><i class="fa fa-fw fa-files-o"></i><!-- /ko -->
-    <!-- ko case: 'editor' --><svg class="hi"><use xlink:href="#hi-editor"></use></svg><!-- /ko -->
-    <!-- ko case: 'hbase' --><svg class="hi"><use xlink:href="#hi-hbase"></use></svg><!-- /ko -->
+    <!-- ko case: 'editor' --><svg class="hi hi-fw"><use xlink:href="#hi-editor"></use></svg><!-- /ko -->
+    <!-- ko case: 'hbase' --><svg class="hi hi-fw"><use xlink:href="#hi-hbase"></use></svg><!-- /ko -->
     <!-- ko case: 'hdfs' --><i class="fa fa-fw fa-folder-o"></i><!-- /ko -->
-    <!-- ko case: 'hive' --><svg class="hi"><use xlink:href="#hi-hive"></use></svg><!-- /ko -->
-    <!-- ko case: 'impala' --><svg class="hi"><use xlink:href="#hi-impala"></use></svg><!-- /ko -->
+    <!-- ko case: 'hive' --><svg class="hi hi-fw"><use xlink:href="#hi-hive"></use></svg><!-- /ko -->
+    <!-- ko case: 'impala' --><svg class="hi hi-fw"><use xlink:href="#hi-impala"></use></svg><!-- /ko -->
     <!-- ko case: 'indexes' --><i class="fa fa-fw fa-search-plus"></i><!-- /ko -->
-    <!-- ko case: 'jar' --><svg class="hi"><use xlink:href="#hi-spark"></use></svg><!-- /ko -->
+    <!-- ko case: 'jar' --><svg class="hi hi-fw"><use xlink:href="#hi-spark"></use></svg><!-- /ko -->
     <!-- ko case: 'java' --><i class="fa fa-fw fa-file-code-o"></i><!-- /ko -->
-    <!-- ko case: 'job-designer' --><svg class="hi"><use xlink:href="#hi-job-designer"></use></svg><!-- /ko -->
+    <!-- ko case: 'job-designer' --><svg class="hi hi-fw"><use xlink:href="#hi-job-designer"></use></svg><!-- /ko -->
     <!-- ko case: 'mapreduce' --><i class="fa fa-fw fa-file-archive-o"></i><!-- /ko -->
-    <!-- ko case: 'markdown' --><svg class="hi"><use xlink:href="#hi-markdown"></use></svg><!-- /ko -->
-    <!-- ko case: 'notebook' --><svg class="hi"><use xlink:href="#hi-file-notebook"></use></svg><!-- /ko -->
-    <!-- ko case: 'oozie' --><svg class="hi"><use xlink:href="#hi-oozie"></use></svg><!-- /ko -->
-    <!-- ko case: 'oozie-bundle' --><svg class="hi"><use xlink:href="#hi-oozie-bundle"></use></svg><!-- /ko -->
-    <!-- ko case: 'oozie-coordinator' --><svg class="hi"><use xlink:href="#hi-oozie-coordinator"></use></svg><!-- /ko -->
-    <!-- ko case: 'oozie-workflow' --><svg class="hi"><use xlink:href="#hi-oozie-workflow"></use></svg><!-- /ko -->
-    <!-- ko case: 'pig' --><svg class="hi"><use xlink:href="#hi-pig"></use></svg><!-- /ko -->
-    <!-- ko case: 'py' --><svg class="hi"><use xlink:href="#hi-py"></use></svg><!-- /ko -->
-    <!-- ko case: 'pyspark' --><svg class="hi"><use xlink:href="#hi-spark"></use></svg><!-- /ko -->
-    <!-- ko case: 'r' --><svg class="hi"><use xlink:href="#hi-r"></use></svg><!-- /ko -->
-    <!-- ko case: 'scala' --><svg class="hi"><use xlink:href="#hi-scala"></use></svg><!-- /ko -->
+    <!-- ko case: 'markdown' --><svg class="hi hi-fw"><use xlink:href="#hi-markdown"></use></svg><!-- /ko -->
+    <!-- ko case: 'notebook' --><svg class="hi hi-fw"><use xlink:href="#hi-file-notebook"></use></svg><!-- /ko -->
+    <!-- ko case: 'oozie' --><svg class="hi hi-fw"><use xlink:href="#hi-oozie"></use></svg><!-- /ko -->
+    <!-- ko case: 'oozie-bundle' --><svg class="hi hi-fw"><use xlink:href="#hi-oozie-bundle"></use></svg><!-- /ko -->
+    <!-- ko case: 'oozie-coordinator' --><svg class="hi hi-fw"><use xlink:href="#hi-oozie-coordinator"></use></svg><!-- /ko -->
+    <!-- ko case: 'oozie-workflow' --><svg class="hi hi-fw"><use xlink:href="#hi-oozie-workflow"></use></svg><!-- /ko -->
+    <!-- ko case: 'pig' --><svg class="hi hi-fw"><use xlink:href="#hi-pig"></use></svg><!-- /ko -->
+    <!-- ko case: 'py' --><svg class="hi hi-fw"><use xlink:href="#hi-py"></use></svg><!-- /ko -->
+    <!-- ko case: 'pyspark' --><svg class="hi hi-fw"><use xlink:href="#hi-spark"></use></svg><!-- /ko -->
+    <!-- ko case: 'r' --><svg class="hi hi-fw"><use xlink:href="#hi-r"></use></svg><!-- /ko -->
+    <!-- ko case: 'scala' --><svg class="hi hi-fw"><use xlink:href="#hi-scala"></use></svg><!-- /ko -->
     <!-- ko case: 'solr' --><i class="fa fa-fw fa-search-plus"></i><!-- /ko -->
-    <!-- ko case: 'scheduler' --><svg class="hi"><use xlink:href="#hi-oozie"></use></svg><!-- /ko -->
+    <!-- ko case: 'scheduler' --><svg class="hi hi-fw"><use xlink:href="#hi-oozie"></use></svg><!-- /ko -->
     <!-- ko case: 'security' --><i class="fa fa-fw fa-lock"></i><!-- /ko -->
     <!-- ko case: 'shell' --><i class="fa fa-fw fa-terminal"></i><!-- /ko -->
-    <!-- ko case: 'spark' --><svg class="hi"><use xlink:href="#hi-spark"></use></svg><!-- /ko -->
-    <!-- ko case: 'sqoop' --><svg class="hi"><use xlink:href="#hi-sqoop"></use></svg><!-- /ko -->
-    <!-- ko case: 'sqoop1' --><svg class="hi"><use xlink:href="#hi-sqoop"></use></svg><!-- /ko -->
+    <!-- ko case: 'spark' --><svg class="hi hi-fw"><use xlink:href="#hi-spark"></use></svg><!-- /ko -->
+    <!-- ko case: 'sqoop' --><svg class="hi hi-fw"><use xlink:href="#hi-sqoop"></use></svg><!-- /ko -->
+    <!-- ko case: 'sqoop1' --><svg class="hi hi-fw"><use xlink:href="#hi-sqoop"></use></svg><!-- /ko -->
     <!-- ko case: 'tables' --><i class="fa fa-fw fa-table"></i><!-- /ko -->
     <!-- ko case: 'text' --><i class="fa fa-fw fa-i-cursor"></i><!-- /ko -->
-    <!-- ko case: 'yarn' --><svg class="hi"><use xlink:href="#hi-job-designer"></use></svg><!-- /ko -->
+    <!-- ko case: 'yarn' --><svg class="hi hi-fw"><use xlink:href="#hi-job-designer"></use></svg><!-- /ko -->
     <!-- ko case: $else --><i class="fa fa-fw fa-database"></i><!-- /ko -->
     <!-- /ko -->
   </script>

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

@@ -21,7 +21,7 @@ var EditorViewModel = (function() {
       'ace', 'aceMode', 'autocompleter', 'availableDatabases', 'availableSnippets', 'avoidClosing', 'canWrite',
       'cleanedDateTimeMeta', 'cleanedMeta', 'cleanedNumericMeta', 'cleanedStringMeta', 'dependents', 'errorLoadingQueries',
       'hasProperties', 'history', 'images', 'inFocus', 'queries', 'saveResultsModalVisible', 'selectedStatement',
-      'snippetImage', 'user', 'positionStatement', 'lastExecutedStatement'
+      'snippetImage', 'user', 'positionStatement', 'lastExecutedStatement', 'downloadResultViewModel'
     ]
   };
 
@@ -2443,6 +2443,8 @@ var EditorViewModel = (function() {
 
     self.avoidClosing = false;
 
+    self.canSave = vm.canSave;
+
 
     self.getSession = function (session_type) {
       var _s = null;
@@ -2692,10 +2694,15 @@ var EditorViewModel = (function() {
               self.loadScheduler();
             }
 
-            if (vm.isHue4()){
-              vm.changeURL(vm.URLS.hue4 + '?editor=' + data.id);
-            } else {
-              vm.changeURL('/notebook/editor' + (vm.isMobile() ? '_m' : '') + '?editor=' + data.id);
+            if (self.snippets()[0].downloadResultViewModel && self.snippets()[0].downloadResultViewModel().saveTarget() === 'dashboard') {
+              huePubSub.publish('open.link', vm.URLS.report + '&uuid=' + data.uuid + '&statement=' + self.snippets()[0].result.handle().statement_id);
+            }
+            else {
+              if (vm.isHue4()){
+                vm.changeURL(vm.URLS.hue4 + '?editor=' + data.id);
+              } else {
+                vm.changeURL('/notebook/editor' + (vm.isMobile() ? '_m' : '') + '?editor=' + data.id);
+              }
             }
           } else {
             if (vm.isHue4()){
@@ -3089,7 +3096,8 @@ var EditorViewModel = (function() {
       editorMobile: '/notebook/editor_m',
       notebook: '/notebook/notebook',
       hue4: '/hue/editor',
-      hue4_notebook: '/hue/notebook'
+      hue4_notebook: '/hue/notebook',
+      report: '/hue/dashboard/new_search?engine=report'
     };
 
     self.huePubSubId = options.huePubSubId || 'editor';