فهرست منبع

HUE-7025 [editor] Move copy to clipboard outside the download dropdown

Enrico Berti 8 سال پیش
والد
کامیت
493facc

+ 16 - 9
desktop/core/src/desktop/templates/common_header_footer_components.mako

@@ -108,7 +108,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
     };
 
     // jHue plugins global configuration
-    jHueFileChooserGlobals = {
+    var jHueFileChooserGlobals = {
       labels: {
         BACK: "${_('Back')}",
         SELECT_FOLDER: "${_('Select this folder')}",
@@ -122,7 +122,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
       user: "${ user.username }"
     };
 
-    jHueHdfsTreeGlobals = {
+    var jHueHdfsTreeGlobals = {
       labels: {
         CREATE_FOLDER: "${_('Create folder')}",
         FOLDER_NAME: "${_('Folder name')}",
@@ -130,7 +130,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
       }
     };
 
-    jHueTableExtenderGlobals = {
+    var jHueTableExtenderGlobals = {
       labels: {
         GO_TO_COLUMN: "${_('Go to column:')}",
         PLACEHOLDER: "${_('column name...')}",
@@ -140,12 +140,12 @@ from metadata.conf import has_optimizer, OPTIMIZER
       }
     };
 
-    LeafletGlobals = {
+    var LeafletGlobals = {
       layer: '${ leaflet['layer'] |n,unicode }',
       attribution: '${ leaflet['attribution'] |n,unicode }'
     };
 
-    ApiHelperGlobals = {
+    var ApiHelperGlobals = {
       i18n: {
         errorLoadingDatabases: '${ _('There was a problem loading the databases') }',
         errorLoadingTablePreview: '${ _('There was a problem loading the preview') }'
@@ -153,7 +153,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
       user: '${ user.username }'
     };
 
-    DropzoneGlobals = {
+    var DropzoneGlobals = {
       homeDir: '${ user.get_home_directory() if not user.is_anonymous() else "" }',
       i18n: {
         cancelUpload: '${ _('Cancel upload') }',
@@ -162,7 +162,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
       }
     };
 
-    MetastoreGlobals = {
+    var MetastoreGlobals = {
       partitionsLimit: ${ hasattr(LIST_PARTITIONS_LIMIT, 'get') and LIST_PARTITIONS_LIMIT.get() or 1000 },
       i18n: {
         errorRefreshingTableStats: '${_('An error occurred refreshing the table stats. Please try again.')}',
@@ -171,7 +171,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
       }
     };
 
-    AutocompleterGlobals = {
+    var AutocompleterGlobals = {
       i18n: {
         category: {
           all: '${ _('All') }',
@@ -206,12 +206,19 @@ from metadata.conf import has_optimizer, OPTIMIZER
       }
     };
 
-    QueryBuilderGlobals = {
+    var QueryBuilderGlobals = {
       i18n: {
         INSERT_VALUE_HERE: "${ _('Insert value here') }",
         QUERY_REQUIRE: "${ _('Query requires a select or aggregate.') }"
       }
     }
+
+    var CopyToClipboardGlobals = {
+      i18n: {
+        ERROR: "${ _('Error while copying results.') }",
+        SUCCESS: "${ _('Results copied successfully to the clipboard') }",
+      }
+    }
   </script>
 
   <!--[if lt IE 9]>

+ 0 - 33
desktop/core/src/desktop/templates/common_notebook_ko_components.mako

@@ -196,11 +196,6 @@ except ImportError, e:
           </a>
         </li>
         % endif
-        <li>
-          <a data-bind="css: clipboardClass" title="${ _('Copy the displayed results in your clipboard') }">
-            <i class="fa fa-fw fa-clipboard"></i> ${ _('Clipboard') }
-          </a>
-        </li>
         <li>
           <a class="download" href="javascript:void(0)" data-bind="click: function() { savePath(''); $('#saveResultsModal').modal('show'); }" title="${ _('Save the result in a file, a new table...') }">
             <i class="fa fa-fw fa-save"></i> ${ _('Save') }
@@ -346,34 +341,6 @@ except ImportError, e:
           return self.savePath() !== '' && (self.saveTarget() != 'hive-table' || /^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]*$/.test(self.savePath()));
         });
 
-        self.clipboardClass = ko.pureComputed(function () {
-          return 'download pointer clipboard' + self.snippet.id().split('-')[0];
-        });
-
-        var clipboard = new Clipboard('.clipboard' + self.snippet.id().split('-')[0], {
-          text: function () {
-            if (self.snippet.result && self.snippet.result.data()) {
-              var data = self.snippet.result.data();
-              var result = '';
-              data.forEach(function (row) {
-                for (var i = 1; i < row.length; i++) { // skip the row number column
-                  result += hueUtils.html2text(row[i]) + '\t';
-                }
-                result += '\n';
-              });
-              return result;
-            }
-            else {
-              return '${_('Error while copying results.') }';
-            }
-          }
-        });
-
-        clipboard.on('success', function (e) {
-          $.jHueNotify.info('${_('Results copied successfully to the clipboard') }')
-          e.clearSelection();
-        });
-
         self.trySaveResults = function () {
           if (self.isValidDestination()) {
             self.saveResults();

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

@@ -456,6 +456,34 @@ var EditorViewModel = (function() {
       }
     };
 
+    self.clipboardClass = ko.pureComputed(function () {
+      return 'snippet-side-btn clipboard' + self.id().split('-')[0];
+    });
+
+    var clipboard = new Clipboard('.clipboard' + self.id().split('-')[0], {
+      text: function () {
+        if (self.result && self.result.data()) {
+          var data = self.result.data();
+          var result = '';
+          data.forEach(function (row) {
+            for (var i = 1; i < row.length; i++) { // skip the row number column
+              result += hueUtils.html2text(row[i]) + '\t';
+            }
+            result += '\n';
+          });
+          return result;
+        }
+        else {
+          return CopyToClipboardGlobals.i18n.ERROR;
+        }
+      }
+    });
+
+    clipboard.on('success', function (e) {
+      $.jHueNotify.info(CopyToClipboardGlobals.i18n.SUCCESS)
+      e.clearSelection();
+    });
+
     self.isSqlDialect.subscribe(updateDatabases);
     updateDatabases();
 

+ 7 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -678,7 +678,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
               (<span data-bind="text: result.rows().toLocaleString() + (type() == 'impala' && result.rows() == 1024 ? '+' : '')" title="${ _('Number of rows') }"></span>)
             <!-- /ko -->
             <!-- ko if: showGrid -->
-            <div class="inline-block inactive-action margin-left-10 pointer" title="${_('Search the results')}" data-bind="click: function(data, e){ $(e.target).parents('.snippet').find('.resultTable').hueDataTable().fnShowSearch() }"><i class="snippet-icon fa fa-search"></i></div>
+            <div class="inline-block inactive-action pointer" title="${_('Search the results')}" data-bind="click: function(data, e){ $(e.target).parents('.snippet').find('.resultTable').hueDataTable().fnShowSearch() }"><i class="snippet-icon fa fa-search"></i></div>
             <!-- /ko -->
             <div class="inline-block inactive-action pointer" title="${_('Expand results')}" rel="tooltip" data-bind="css: { 'margin-left-10': !showGrid()}, visible: !$root.isFullscreenMode() && !$root.isPlayerMode(), click: function(){ $root.isPlayerMode(true); }"><i class="snippet-icon fa fa-expand"></i></div>
             <div class="inline-block inactive-action pointer" title="${_('Collapse results')}" rel="tooltip" data-bind="visible: !$root.isFullscreenMode() && $root.isPlayerMode(), click: function(){ $root.isPlayerMode(false); }"><i class="snippet-icon fa fa-compress"></i></div>
@@ -1768,6 +1768,12 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
       </a>
     </div>
 
+    <div>
+      <a data-bind="css: clipboardClass" title="${ _('Copy the displayed results in your clipboard') }">
+        <i class="fa fa-fw fa-clipboard"></i>
+      </a>
+    </div>
+
     <div data-bind="component: { name: 'downloadSnippetResults', params: { snippet: $data, notebook: $parent } }" style="display:inline-block;"></div>
   </div>
 </script>