فهرست منبع

HUE-3492 [editor] HDFS and table autocomplete in save result popup

Enrico Berti 9 سال پیش
والد
کامیت
f12bb20

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

@@ -2189,8 +2189,7 @@
       self.attr("autocomplete", "off");
       self.jHueHdfsAutocomplete({
         skipKeydownEvents: true,
-        skipScrollEvent: true,
-        zIndex: 990
+        skipScrollEvent: true
       });
     }
   };
@@ -2232,12 +2231,12 @@
         });
       }
 
-      self.after(getFileBrowseButton(self, true, valueAccessor, true, allBindingsAccessor, valueAccessor().isAddon));
+      self.after(getFileBrowseButton(self, true, valueAccessor, true, allBindingsAccessor, valueAccessor().isAddon, valueAccessor().isNestedModal));
     }
   };
 
 
-  function getFileBrowseButton(inputElement, selectFolder, valueAccessor, stripHdfsPrefix, allBindingsAccessor, isAddon) {
+  function getFileBrowseButton(inputElement, selectFolder, valueAccessor, stripHdfsPrefix, allBindingsAccessor, isAddon, isNestedModal) {
     var _btn;
     if (isAddon) {
       _btn = $("<span>").addClass("add-on muted pointer").text("..");
@@ -2246,16 +2245,18 @@
     }
     _btn.click(function (e) {
       e.preventDefault();
-      $("html").addClass("modal-open");
+      if (!isNestedModal) {
+        $("body").addClass("modal-open");
+      }
       // check if it's a relative path
       callFileChooser();
 
       function callFileChooser() {
         var _initialPath = $.trim(inputElement.val()) != "" ? inputElement.val() : "/";
-        if ((allBindingsAccessor && allBindingsAccessor().filechooserOptions && allBindingsAccessor().filechooserOptions.skipInitialPathIfEmpty && inputElement.val() == "") || (allBindingsAccessor && allBindingsAccessor().filechooserPrefixSeparator)){
+        if ((allBindingsAccessor && allBindingsAccessor().filechooserOptions && allBindingsAccessor().filechooserOptions.skipInitialPathIfEmpty && inputElement.val() == "") || (allBindingsAccessor && allBindingsAccessor().filechooserPrefixSeparator)) {
           _initialPath = "";
         }
-        if (inputElement.data("fullPath")){
+        if (inputElement.data("fullPath")) {
           _initialPath = inputElement.data("fullPath");
         }
         if (_initialPath.indexOf("hdfs://") > -1) {
@@ -2268,13 +2269,17 @@
             handleChoice(filePath, stripHdfsPrefix);
             if (selectFolder) {
               $("#chooseFile").modal("hide");
-              $(".modal-backdrop").remove();
+              if (!isNestedModal) {
+                $(".modal-backdrop").remove();
+              }
             }
           },
           onFileChoose: function (filePath) {
             handleChoice(filePath, stripHdfsPrefix);
             $("#chooseFile").modal("hide");
-            $(".modal-backdrop").remove();
+            if (!isNestedModal) {
+              $(".modal-backdrop").remove();
+            }
           },
           createFolder: allBindingsAccessor && allBindingsAccessor().filechooserOptions && allBindingsAccessor().filechooserOptions.createFolder,
           uploadFile: allBindingsAccessor && allBindingsAccessor().filechooserOptions && allBindingsAccessor().filechooserOptions.uploadFile,
@@ -2286,35 +2291,37 @@
           filterExtensions: allBindingsAccessor && allBindingsAccessor().filechooserFilter ? allBindingsAccessor().filechooserFilter : ""
         });
         $("#chooseFile").modal("show");
-        $("#chooseFile").on("hidden", function(){
-          $("html").removeClass("modal-open");
-          $(".modal-backdrop").remove();
-        });
+        if (!isNestedModal) {
+          $("#chooseFile").on("hidden", function () {
+            $("body").removeClass("modal-open");
+            $(".modal-backdrop").remove();
+          });
+        }
       }
 
       function handleChoice(filePath, stripHdfsPrefix) {
-        if (allBindingsAccessor && allBindingsAccessor().filechooserPrefixSeparator){
+        if (allBindingsAccessor && allBindingsAccessor().filechooserPrefixSeparator) {
           filePath = inputElement.val().split(allBindingsAccessor().filechooserPrefixSeparator)[0] + '=' + filePath;
         }
-        if (allBindingsAccessor && allBindingsAccessor().filechooserOptions && allBindingsAccessor().filechooserOptions.deploymentDir){
+        if (allBindingsAccessor && allBindingsAccessor().filechooserOptions && allBindingsAccessor().filechooserOptions.deploymentDir) {
           inputElement.data("fullPath", filePath);
           inputElement.attr("data-original-title", filePath);
-          if (filePath.indexOf(allBindingsAccessor().filechooserOptions.deploymentDir) == 0){
+          if (filePath.indexOf(allBindingsAccessor().filechooserOptions.deploymentDir) == 0) {
             filePath = filePath.substr(allBindingsAccessor().filechooserOptions.deploymentDir.length + 1);
           }
         }
-        if (stripHdfsPrefix){
+        if (stripHdfsPrefix) {
           inputElement.val(filePath);
         }
         else {
           inputElement.val("hdfs://" + filePath);
         }
         inputElement.change();
-        if (valueAccessor){
+        if (valueAccessor) {
           if (typeof valueAccessor() == "function" || typeof valueAccessor().value == "function") {
-            if (valueAccessor().value){
+            if (valueAccessor().value) {
               valueAccessor().value(inputElement.val());
-              if (valueAccessor().displayJustLastBit){
+              if (valueAccessor().displayJustLastBit) {
                 inputElement.data("fullPath", inputElement.val());
                 inputElement.attr("data-original-title", inputElement.val());
                 var _val = inputElement.val();
@@ -2331,7 +2338,7 @@
         }
       }
     });
-    if (allBindingsAccessor && allBindingsAccessor().filechooserDisabled){
+    if (allBindingsAccessor && allBindingsAccessor().filechooserDisabled) {
       _btn.addClass("disabled").attr("disabled", "disabled");
     }
     return _btn;

+ 14 - 13
desktop/core/src/desktop/templates/ko_components.mako

@@ -551,39 +551,40 @@ from desktop.views import _ko
                   <input data-bind="checked: saveTarget" type="radio" name="save-results-type" value="hdfs-file">
                   &nbsp;${ _('In HDFS (small csv)') }
                 </label>
-                <span data-bind="visible: saveTarget() == 'hdfs-file'">
-                  <input data-bind="value: savePath" type="text" name="target_file" placeholder="${_('Path to CSV file')}" class="pathChooser">
-                </span>
+                <div data-bind="visible: saveTarget() == 'hdfs-file'" class="inline">
+                  <input data-bind="value: savePath, filechooser: { value: savePath, isNestedModal: true }, filechooserOptions: { uploadFile: false }, hdfsAutocomplete: savePath" type="text" name="target_file" placeholder="${_('Path to CSV file')}" class="pathChooser margin-left-10">
+                </div>
                 <label class="radio" data-bind="visible: saveTarget() == 'hdfs-file'">
                   <input data-bind="checked: saveOverwrite" type="checkbox" name="overwrite">
                   ${ _('Overwrite') }
                 </label>
               </div>
+            </div>
+            <div class="control-group">
               <div class="controls" data-bind="visible: snippet.type() == 'hive'">
                 <label class="radio">
                   <input data-bind="checked: saveTarget" type="radio" name="save-results-type" value="hdfs-directory">
                   &nbsp;${ _('In HDFS (large file)') }
                 </label>
-                <span data-bind="visible: saveTarget() == 'hdfs-directory'">
-                  <input data-bind="value: savePath" type="text" name="target_dir" placeholder="${_('Path to directory')}" class="folderChooser">
-                  <i class="fa fa-question-circle" id="hdfs-directory-help"></i>
-                </span>
+                <div data-bind="visible: saveTarget() == 'hdfs-directory'" class="inline">
+                  <input data-bind="value: savePath, filechooser: { value: savePath, isNestedModal: true }, filechooserOptions: { uploadFile: false }, hdfsAutocomplete: savePath" type="text" name="target_dir" placeholder="${_('Path to directory')}" class="pathChooser margin-left-10">
+                  <i class="fa fa-question-circle muted" title="${ _("Use this option if you have a large result. It will rerun the entire query and save the results to the chosen HDFS directory.") }"></i>
+                </div>
               </div>
+            </div>
+            <div class="control-group">
               <div class="controls">
                 <label class="radio">
                   <input data-bind="checked: saveTarget" type="radio" name="save-results-type" value="hive-table">
                   &nbsp;${ _('A new table') }
                 </label>
-                <span data-bind="visible: saveTarget() == 'hive-table'">
-                  <input data-bind="value: savePath" type="text" name="target_table" class="input-xlarge" placeholder="${_('Table name or <database>.<table>')}">
-                </span>
+                <div data-bind="visible: saveTarget() == 'hive-table'" class="inline">
+                  <input data-bind="hivechooser: savePath" type="text" name="target_table" class="input-xlarge margin-left-10" placeholder="${_('Table name or <database>.<table>')}">
+                </div>
               </div>
             </div>
           </fieldset>
         </form>
-        <div id="hdfs-directory-help-content" class="hide">
-          <p>${ _("Use this option if you have a large result. It will rerun the entire query and save the results to the chosen HDFS directory.") }</p>
-        </div>
       </div>
       <div class="modal-footer">
         <button class="btn" data-dismiss="modal">${_('Cancel')}</button>

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

@@ -95,6 +95,9 @@ from desktop.views import _ko
 <script src="${ static('desktop/js/ace/ext-language_tools.js') }"></script>
 <script src="${ static('desktop/js/ace.extended.js') }"></script>
 
+<script src="${ static('desktop/js/jquery.hiveautocomplete.js') }" type="text/javascript" charset="utf-8"></script>
+<script src="${ static('desktop/js/jquery.hdfsautocomplete.js') }" type="text/javascript" charset="utf-8"></script>
+
 <script type="text/x-mathjax-config">
   MathJax.Hub.Config({
     showProcessingMessages: false,