Bladeren bron

[security] Added HDFS picker to Hive

Enrico Berti 11 jaren geleden
bovenliggende
commit
a4df3d6

+ 18 - 2
apps/security/src/security/templates/hive.mako

@@ -50,11 +50,11 @@ ${ layout.menubar(section='hive') }
     <input type="text" data-bind="value: $data.path, valueUpdate: 'afterkeydown'" placeholder="dbName.tableName">
 
     <input name="uri" data-bind="attr: { name: 'privilege-' + $index() }" type="radio"/>
-    <input type="text" data-bind="value: $data.URI" placeholder="URI">
+    <input type="text" data-bind="filechooser: $data.URI" placeholder="URI">
 
     <select data-bind="options: $root.availableActions, select2: { update: $data.action, type: 'action'}" style="width: 100px"></select>
 
-    &nbsp;&nbsp;<a class="pointer showAdvanced" data-bind="click: function(){ showAdvanced(true); }, visible: ! showAdvanced()"><i class="fa fa-cog"></i> ${ _('Show advanced') }</a>
+    <span class="showAdvancedSpace">&nbsp;&nbsp;</span><a class="pointer showAdvanced" data-bind="click: function(){ showAdvanced(true); }, visible: ! showAdvanced()"><i class="fa fa-cog"></i> ${ _('Show advanced') }</a>
 
     <div class="acl-block-section" data-bind="visible: showAdvanced">
       <input type="text" data-bind="value: serverName" placeholder="serverName">
@@ -383,6 +383,20 @@ ${ layout.menubar(section='hive') }
   </div>
 </div>
 
+<div id="chooseFile" class="modal hide fade">
+  <div class="modal-header">
+      <a href="#" class="close" data-dismiss="modal">&times;</a>
+      <h3>${_('Choose a file')}</h3>
+  </div>
+  <div class="modal-body">
+      <div id="filechooser">
+      </div>
+  </div>
+  <div class="modal-footer">
+  </div>
+</div>
+
+
 <%def name="treeIcons()">
   'fa-database': isDb(),
   'fa-table': isTable(),
@@ -400,6 +414,8 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
 
 <script src="/static/ext/js/moment.min.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/js/jquery.hiveautocomplete.js" type="text/javascript" charset="utf-8"></script>
+<script src="/static/js/jquery.filechooser.js" type="text/javascript" charset="utf-8"></script>
+
 
   <script type="text/javascript" charset="utf-8">
     var viewModel = new HiveViewModel(${ initial | n,unicode });

+ 8 - 0
apps/security/static/css/security.css

@@ -119,6 +119,9 @@
   display: block;
   margin-top: 4px;
 }
+.span6 .acl-block .showAdvancedSpacer {
+  display: none;
+}
 
 .acl-actions {
   padding: 5px;
@@ -267,4 +270,9 @@ h1.emptyMessage {
 .modal-panel {
   max-height: 120px;
   overflow-y: scroll;
+}
+
+.fileChooserBtn {
+  height: 31px;
+  border-left: 0;
 }

+ 49 - 1
apps/security/static/js/common.ko.js

@@ -96,4 +96,52 @@ ko.bindingHandlers.select2 = {
       $(element).select2("val", valueAccessor().update());
     }
   }
-};
+};
+
+
+ko.bindingHandlers.filechooser = {
+  init: function(element, valueAccessor, allBindingsAccessor, vm) {
+    var self = $(element);
+    self.after(getFileBrowseButton(self, true));
+  }
+};
+
+function getFileBrowseButton(inputElement, selectFolder) {
+  return $("<button>").addClass("btn").addClass("fileChooserBtn").text("..").click(function (e) {
+    e.preventDefault();
+    // check if it's a relative path
+    callFileChooser();
+
+    function callFileChooser() {
+      var _initialPath = $.trim(inputElement.val()) != "" ? inputElement.val() : "/";
+      if (_initialPath.indexOf("hdfs://") > -1){
+        _initialPath = _initialPath.substring(7);
+      }
+      $("#filechooser").jHueFileChooser({
+        suppressErrors: true,
+        selectFolder: (selectFolder) ? true : false,
+        onFolderChoose: function (filePath) {
+          handleChoice(filePath);
+          if (selectFolder) {
+            $("#chooseFile").modal("hide");
+          }
+        },
+        onFileChoose: function (filePath) {
+          handleChoice(filePath);
+          $("#chooseFile").modal("hide");
+        },
+        createFolder: false,
+        uploadFile: false,
+        initialPath: _initialPath,
+        errorRedirectPath: "",
+        forceRefresh: true
+      });
+      $("#chooseFile").modal("show");
+    }
+
+    function handleChoice(filePath) {
+      inputElement.val("hdfs://" + filePath);
+      inputElement.change();
+    }
+  });
+}

+ 5 - 2
desktop/core/static/js/jquery.filechooser.js

@@ -29,6 +29,7 @@
             createFolder:true,
             uploadFile:true,
             selectFolder:false,
+            suppressErrors:false,
             labels: {
                 BACK: "Back",
                 SELECT_FOLDER: "Select this folder",
@@ -261,9 +262,11 @@
                 }, 100);
             }
         }).error(function(){
-            $(document).trigger("info", _parent.options.labels.FILE_NOT_FOUND);
+            if (! _parent.options.suppressErrors) {
+              $(document).trigger("info", _parent.options.labels.FILE_NOT_FOUND);
+              _parent.options.onError();
+            }
             _parent.navigateTo(_parent.options.errorRedirectPath != "" ? _parent.options.errorRedirectPath : "/?default_to_home");
-            _parent.options.onError();
         });
     };