浏览代码

HUE-5724 [assist] Format the view SQL in the context popover and add copy and insert actions

Johan Ahlen 8 年之前
父节点
当前提交
2efeec1

+ 21 - 1
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -79,6 +79,16 @@
     return ko.observableArray(typeof prop != "undefined" && prop != null ? prop : defvalue);
   };
 
+  ko.bindingHandlers.clickToCopy = {
+    init: function (element, valueAccessor) {
+      $(element).click(function () {
+        var $input = $('<input>').css({ opacity: 0 }).val(valueAccessor()).appendTo('body').select();
+        document.execCommand('copy');
+        $input.remove()
+      });
+    }
+  };
+
   ko.bindingHandlers.autocomplete = {
     init: function (element, valueAccessor) {
       var options = valueAccessor();
@@ -3835,6 +3845,13 @@
         }
       });
 
+      huePubSub.subscribe("editor.insert.at.cursor", function(value) {
+        if ($el.data("last-active-editor")) {
+          editor.session.insert(editor.getCursorPosition(), value);
+          editor.renderer.scrollCursorIntoView(editor.getCursorPosition(), 0.5)
+        }
+      });
+
       huePubSub.subscribe("assist.dblClickHdfsItem", function(assistHdfsEntry) {
         if ($el.data("last-active-editor")) {
           editor.session.insert(editor.getCursorPosition(), "'" + assistHdfsEntry.path + "'");
@@ -4893,6 +4910,9 @@
 
 
   ko.bindingHandlers.highlight = {
+    init: function (element) {
+      $(element).addClass('ace-highlight');
+    },
     update: function (element, valueAccessor, allBindingsAccessor) {
       var value = ko.unwrap(valueAccessor());
       var options = ko.unwrap(allBindingsAccessor());
@@ -4912,7 +4932,7 @@
 
           var Tokenizer = tokenizer.Tokenizer;
           var Rules = hiveRules.HiveHighlightRules;
-          if (options.flavor && options.flavor() == 'impala') {
+          if (options.flavor && ko.unwrap(options.flavor) == 'impala') {
             Rules = impalaRules.ImpalaHighlightRules;
           }
 

+ 1 - 1
desktop/core/src/desktop/templates/responsive.mako

@@ -271,7 +271,7 @@ ${ hueIcons.symbols() }
                     </div>
                     <div class="clearfix"></div>
                     <strong data-bind="text: name, attr: { title: uuid }"></strong>
-                    <div data-bind="highlight: 'statement'" class="history-item"></div>
+                    <div data-bind="highlight: 'statement'"></div>
                   </li>
                 <!-- /ko -->
               </ul>

+ 9 - 4
desktop/core/src/desktop/templates/sql_context_popover.mako

@@ -193,10 +193,6 @@ from metadata.conf import has_navigator
         </span>
       </div>
       <!-- /ko -->
-      <!-- ko if: typeof viewSql !== 'undefined' -->
-      <div style="margin: 10px; font-size: 15px; font-weight: 300;">${ _("View SQL") }</div>
-      <div style="margin-left: 15px;" data-bind="text: viewSql"></div>
-      <!-- /ko -->
       <!-- ko if: typeof comment !== 'undefined' && comment !== '' && comment !== null -->
       <div style="margin: 10px; font-size: 15px; font-weight: 300;">${ _("Comment") }</div>
       <div style="margin-left: 15px; font-style: italic;" data-bind="text: comment"></div>
@@ -207,6 +203,10 @@ from metadata.conf import has_navigator
         <div style="margin-left: 15px;" data-bind="component: { name: 'nav-tags', params: $parent } "></div>
         <!-- /ko -->
       %endif
+      <!-- ko if: typeof viewSql !== 'undefined' -->
+      <div style="margin: 10px; font-size: 15px; font-weight: 300;">${ _("View SQL") } <a href="javascript:void(0);" title="${ _("Copy") }" class="inactive-action" data-bind="clickToCopy: viewSql"><i class="fa fa-fw fa-clipboard"></i></a> <a href="javascript:void(0);" title="${ _("Insert at cursor") }" data-bind="click: function () { $parent.insertAtCursor(viewSql) }" class="inactive-action"><i class="fa fa-fw fa-terminal"></i></a></div>
+      <div style="margin: 0 10px;" class="pointer" title="${ _("Insert at cursor") }" data-bind="click: function () { $parent.insertAtCursor(viewSql) }, highlight: viewSql, flavor: $parent.sourceType"></div>
+      <!-- /ko -->
     </div>
     <!-- /ko -->
   </script>
@@ -472,6 +472,11 @@ from metadata.conf import has_navigator
         self.hasErrors = ko.observable(false);
       }
 
+      GenericTabContents.prototype.insertAtCursor = function (value) {
+        huePubSub.publish('editor.insert.at.cursor', value);
+        huePubSub.publish('sql.context.popover.hide');
+      };
+
       GenericTabContents.prototype.formatAnalysisValue = function (type, val) {
         if (type === 'last_modified_time' || type === 'transient_lastDdlTime') {
           return localeFormat(val * 1000);

文件差异内容过多而无法显示
+ 0 - 0
desktop/libs/notebook/src/notebook/static/notebook/css/notebook.css


+ 3 - 3
desktop/libs/notebook/src/notebook/static/notebook/less/notebook.less

@@ -905,15 +905,15 @@ h4.header {
   border-right: 2px solid #CCC;
 }
 
-.history-item .ace-hue {
+.ace-highlight .ace-hue {
   background-color: transparent !important;
 }
 
-.history-item .ace_invalid {
+.ace-highlight .ace_invalid {
   display: none;
 }
 
-.history-item .ace_line {
+.ace-highlight .ace_line {
   white-space: normal;
 }
 

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

@@ -802,7 +802,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
                     <!-- /ko -->
                   </td>
                   <td style="width: 25px" class="muted" data-bind="ellipsis: {data: name(), length: 30}, style: {'border-top-width': $index() == 0 ? '0' : ''}"></td>
-                  <td data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}"><div data-bind="highlight: query(), flavor: $parent.type" class="history-item"></div></td>
+                  <td data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}"><div data-bind="highlight: query(), flavor: $parent.type"></div></td>
                 </tr>
               </tbody>
             </table>

+ 1 - 1
desktop/libs/notebook/src/notebook/templates/editor_m.mako

@@ -151,7 +151,7 @@ ${ commonheader_m(editor_type, editor_type, user, request, "68px") | n,unicode }
           <!-- /ko -->
         </td>
         <td class="muted" data-bind="ellipsis: {data: name(), length: 30}, style: {'border-top-width': $index() == 0 ? '0' : ''}"></td>
-        <td data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}"><div data-bind="highlight: query(), flavor: $parent.type" class="history-item"></div></td>
+        <td data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}"><div data-bind="highlight: query(), flavor: $parent.type"></div></td>
       </tr>
     <!-- /ko -->
     </tbody>

部分文件因为文件数量过多而无法显示