Explorar o código

HUE-5125 [editor] Show file tree on context popup

Enrico Berti %!s(int64=9) %!d(string=hai) anos
pai
achega
06b82cb

+ 4 - 1
desktop/core/src/desktop/static/desktop/js/jquery.hdfstree.js

@@ -33,6 +33,7 @@
         home: "",
         initialPath: "/",
         isS3: false,
+        withTopPadding: true,
         onPathChange: function () {
         },
         createFolder: true,
@@ -108,7 +109,9 @@
     }
 
     var _tree = $("<ul>").addClass("content unstyled").html('<li><a class="pointer"><i class="fa fa-folder-open-o"></i> /</a></li>');
-    _tree.css("padding-top", "30px");
+    if (_this.options.withTopPadding) {
+      _tree.css("padding-top", "30px");
+    }
 
     if (_this.options.home != "") {
       _homeLink.appendTo(_el);

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

@@ -3291,6 +3291,12 @@
         }
       });
 
+      huePubSub.subscribe('ace.replace', function (data) {
+        var Range = ace.require('ace/range').Range;
+        var range = new Range(data.location.first_line - 1, data.location.first_column - 1, data.location.last_line - 1, data.location.last_column - 1);
+        editor.getSession().getDocument().replace(range, data.text);
+      });
+
       editor.on("click", function (e) {
         editor.clearErrors();
       });
@@ -4556,5 +4562,27 @@
     init: function (el, valueAccessor, allBindingsAccessor, viewModel) {
       $(el).data('__ko_vm', viewModel);
     }
-  }
+  };
+
+  ko.bindingHandlers.hdfsTree = {
+    update: function (element, valueAccessor) {
+      var options = ko.unwrap(valueAccessor());
+      var $element = $(element);
+
+      $element.empty();
+
+      var value = typeof options.data === 'function' ? options.data() : options.data;
+      $element.jHueHdfsTree({
+        home: '',
+        isS3: false,
+        initialPath: options.path,
+        withTopPadding: false,
+        onPathChange: function (path) {
+          options.selectedPath(path);
+        }
+      });
+
+    }
+  };
+
 })();

+ 12 - 2
desktop/core/src/desktop/templates/sql_context_popover.mako

@@ -278,6 +278,7 @@ from metadata.conf import has_navigator
       <div class="sql-context-link-row">
         <a class="inactive-action pointer" data-bind="visible: isTable || isColumn, click: function() { huePubSub.publish('sql.context.popover.show.in.assist') }"><i style="font-size: 11px;" title="${ _("Show in Assist...") }" class="fa fa-search"></i> ${ _("Assist") }</a>
         <a class="inactive-action pointer" data-bind="visible: isTable, click: function() { huePubSub.publish('sql.context.popover.open.in.metastore') }"><i style="font-size: 11px;" title="${ _("Open in Metastore...") }" class="fa fa-external-link"></i> ${ _("Metastore") }</a>
+        <a class="inactive-action pointer" data-bind="visible: isHdfs, click: function() { huePubSub.publish('sql.context.popover.replace.in.editor') }"><i style="font-size: 11px;" title="${ _("Replace the editor content...") }" class="fa fa-pencil"></i> ${ _("Insert in the editor") }</a>
         <a class="inactive-action pointer" data-bind="visible: isHdfs, click: function() { huePubSub.publish('sql.context.popover.open.in.file.browser') }"><i style="font-size: 11px;" title="${ _("Open in File Browser...") }" class="fa fa-external-link"></i> ${ _("File Browser") }</a>
       </div>
     </div>
@@ -386,7 +387,9 @@ from metadata.conf import has_navigator
   <script type="text/html" id="sql-context-hdfs-details">
     <div class="sql-context-flex-fill" data-bind="with: details, niceScroll">
       <div style="padding: 8px">
-        <div style="margin: 10px 10px 18px 10px;"><pre data-bind="text: ko.mapping.toJSON($data)"></pre></div>
+        <div style="margin: 10px 10px 18px 10px;">
+          <div data-bind="hdfsTree: { path: $data.path, selectedPath: $parent.selectedPath }"></div>
+        </div>
       </div>
     </div>
   </script>
@@ -827,13 +830,20 @@ from metadata.conf import has_navigator
         self.data = ko.observable({
           details: data,
           loading: ko.observable(false),
-          hasErrors: ko.observable(false)
+          hasErrors: ko.observable(false),
+          selectedPath: ko.observable(data.path)
         });
 
         pubSubs.push(huePubSub.subscribe('sql.context.popover.open.in.file.browser', function () {
           window.open((data.path.indexOf('/') === 0 ? '/filebrowser/#' : '/filebrowser/#/') + data.path, '_blank');
         }));
 
+        pubSubs.push(huePubSub.subscribe('sql.context.popover.replace.in.editor', function () {
+          huePubSub.publish('ace.replace', {
+            location: data.location,
+            text: self.data().selectedPath()
+          });
+        }));
 
         self.tabs = [
           { id: 'details', label: '${ _("Details") }', template: 'sql-context-hdfs-details', templateData: self.data }

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

@@ -65,6 +65,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 <script src="${ static('desktop/js/autocompleter.js') }"></script>
 <script src="${ static('desktop/js/hue.json.js') }"></script>
 <script src="${ static('desktop/js/jquery.huedatatable.js') }"></script>
+<script src="${ static('desktop/js/jquery.hdfstree.js') }"></script>
 <script src="${ static('desktop/ext/js/markdown.min.js') }"></script>
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery.hotkeys.js') }"></script>
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery.mousewheel.min.js') }"></script>