Browse Source

HUE-6830 [editor] Introduce copy to clipboard for results

Enrico Berti 8 years ago
parent
commit
030baab3aa

File diff suppressed because it is too large
+ 6 - 0
desktop/core/src/desktop/static/desktop/ext/js/clipboard.min.js


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

@@ -205,6 +205,11 @@ except ImportError, e:
             <i class="fa fa-fw fa-save"></i> ${ _('Save') }
           </a>
         </li>
+        <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>
       </ul>
     </div>
 
@@ -345,6 +350,34 @@ 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();

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

@@ -50,6 +50,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 <script src="${ static('desktop/js/ko.editable.js') }"></script>
 % endif
 
+<script src="${ static('desktop/ext/js/clipboard.min.js') }"></script>
 <script src="${ static('desktop/ext/js/selectize.min.js') }"></script>
 <script src="${ static('notebook/js/notebook.ko.js') }"></script>
 

Some files were not shown because too many files changed in this diff