Browse Source

[security] Role path autocomplete for Hive

Enrico Berti 11 years ago
parent
commit
1232557c08

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

@@ -47,7 +47,7 @@ ${ layout.menubar(section='hive') }
       <a class="pointer" style="margin-right: 4px" data-bind="click: remove"><i class="fa fa-times"></i></a>
     </div>
     <input name="db" data-bind="attr: { name: 'privilege-' + $index() }" type="radio" checked/>
-    <input type="text" data-bind="value: $data.path, valueUpdate: 'afterkeydown'" placeholder="dbName.tableName">
+    <input type="text" data-bind="hivechooser: $data.path" placeholder="dbName.tableName">
 
     <input name="uri" data-bind="attr: { name: 'privilege-' + $index() }" type="radio"/>
     <input type="text" data-bind="filechooser: $data.URI" placeholder="URI">
@@ -436,6 +436,7 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
       }
 
       $("#path").jHueHiveAutocomplete({
+        skipColumns: true,
         home: viewModel.assist.path(),
         onPathChange: function (path) {
           setPathFromAutocomplete(path);

+ 19 - 0
apps/security/static/js/common.ko.js

@@ -98,6 +98,25 @@ ko.bindingHandlers.select2 = {
   }
 };
 
+ko.bindingHandlers.hivechooser = {
+  init: function(element, valueAccessor, allBindingsAccessor, vm) {
+    var self = $(element);
+    function setPathFromAutocomplete(path){
+      self.val(path);
+      self.change();
+    }
+    self.jHueHiveAutocomplete({
+      skipColumns: true,
+      home: "/",
+      onPathChange: function (path) {
+        setPathFromAutocomplete(path);
+      },
+      onEnter: function (el) {
+        setPathFromAutocomplete(el.val());
+      }
+    });
+  }
+}
 
 ko.bindingHandlers.filechooser = {
   init: function(element, valueAccessor, allBindingsAccessor, vm) {

+ 24 - 11
desktop/core/static/js/jquery.hiveautocomplete.js

@@ -22,6 +22,7 @@
   var pluginName = "jHueHiveAutocomplete",
       defaults = {
         home: "/",
+        skipColumns: false,
         onEnter: function () {
         },
         onBlur: function () {
@@ -208,6 +209,7 @@
 
           var _ico = "";
           var _iterable = [];
+          var _isSkipColumns = false;
 
           if (data.databases != null){ // it's a db
             _iterable = data.databases;
@@ -218,14 +220,19 @@
             _ico = "fa-table";
           }
           else {
-            _iterable = data.columns;
-            _ico = "fa-columns";
+            if (! _this.options.skipColumns) {
+              _iterable = data.columns;
+              _ico = "fa-columns";
+            }
+            else {
+              _isSkipColumns = true;
+            }
           }
 
-
-          $(_iterable).each(function (cnt, item) {
-            _currentFiles.push('<li class="hiveAutocompleteItem" data-value="' + item + '"><i class="fa '+ _ico +'"></i> ' + item + '</li>');
-          });
+          if (! _isSkipColumns){
+            $(_iterable).each(function (cnt, item) {
+              _currentFiles.push('<li class="hiveAutocompleteItem" data-value="' + item + '"><i class="fa '+ _ico +'"></i> ' + item + '</li>');
+            });
 
             $("#jHueHiveAutocomplete").css("top", _el.offset().top + _el.outerHeight() - 1).css("left", _el.offset().left).width(_el.outerWidth() - 4);
             $("#jHueHiveAutocomplete").find("ul").empty().html(_currentFiles.join(""));
@@ -237,24 +244,29 @@
 
               if ($(this).html().indexOf("database") > -1){
                 _el.val(item + ".");
-                _this.options.onPathChange(item);
+                _this.options.onPathChange(_el.val());
                 showHiveAutocomplete();
               }
 
               if ($(this).html().indexOf("table") > -1){
                 if (_el.val().indexOf(".") > -1){
                   if (_el.val().match(/\./gi).length == 1){
-                    _el.val(_el.val().substring(0, _el.val().lastIndexOf(".") + 1) + item + ".");
+                    _el.val(_el.val().substring(0, _el.val().lastIndexOf(".") + 1) + item);
                   }
                   else {
-                    _el.val(_el.val().substring(0, _el.val().indexOf(".") + 1) + item + ".");
+                    _el.val(_el.val().substring(0, _el.val().indexOf(".") + 1) + item);
                   }
                 }
                 else {
-                  _el.val(_el.val() + item + ".");
+                  _el.val(_el.val() + item);
+                }
+                if (! _this.options.skipColumns){
+                  _el.val(_el.val() + ".");
                 }
                 _this.options.onPathChange(_el.val());
-                showHiveAutocomplete();
+                if (! _this.options.skipColumns) {
+                  showHiveAutocomplete();
+                }
               }
 
               if ($(this).html().indexOf("columns") > -1){
@@ -277,6 +289,7 @@
             if ("undefined" != typeof callback) {
               callback();
             }
+          }
         }
       });
     }