Sfoglia il codice sorgente

[security] Fixed refresh on Hive tree

Enrico Berti 11 anni fa
parent
commit
c069f9d

+ 4 - 4
apps/security/src/security/templates/hdfs.mako

@@ -119,7 +119,7 @@ ${ layout.menubar(section='hdfs') }
                 </div>
               </div>
 
-              ${ tree.render(id='hdfsTree', data='$root.assist.treeData', afterRender='$root.assist.afterRender') }
+              ${ tree.render(id='expandableTree', data='$root.assist.treeData', afterRender='$root.assist.afterRender') }
             </div>
             <div class="span4">
               <div class="acl-panel" data-bind="visible: ! $root.assist.isLoadingAcls()">
@@ -245,7 +245,7 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
 
     function resizeComponents () {
       $("#path").width($(".tree-toolbar").width() - 64);
-      $("#hdfsTree").height($(window).height() - 260);
+      $("#expandableTree").height($(window).height() - 260);
       $(".acl-panel-content").height($(window).height() - 260);
     }
 
@@ -257,8 +257,8 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
         _path = _path.substr(0, _path.length - 1);
       }
       if ($("a.anchor[href^='"+_path+"']").length > 0){
-        $("#hdfsTree").animate({
-          scrollTop: ($("a.anchor[href^='"+_path+"']:first").position().top + $("#hdfsTree").scrollTop() - $("#hdfsTree").position().top - 4)+"px"
+        $("#expandableTree").animate({
+          scrollTop: ($("a.anchor[href^='"+_path+"']:first").position().top + $("#expandableTree").scrollTop() - $("#expandableTree").position().top - 4)+"px"
         });
       }
     });

+ 16 - 3
apps/security/src/security/templates/hive.mako

@@ -140,7 +140,7 @@ ${ layout.menubar(section='hive') }
                 </div>
               </div>
 
-              ${ tree.render(id='hdfsTree', data='$root.assist.treeData', afterRender='$root.assist.afterRender') }
+              ${ tree.render(id='expandableTree', data='$root.assist.treeData', afterRender='$root.assist.afterRender') }
 
             </div>
             <div class="span4">
@@ -269,7 +269,7 @@ ${ layout.menubar(section='hive') }
   'fa-columns': isColumn()
 </%def>
 
-${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assist.togglePath', itemSelected='$root.assist.path() == path()',iconModifier=treeIcons) }
+${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assist.togglePath', itemSelected='$root.assist.path() == path()', iconModifier=treeIcons, anchorProperty='path') }
 
 ##${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assist.togglePath', itemSelected='$root.assist.path() == path()', iconModifier=treeIcons, styleModifier='aclBit', styleModifierPullRight=aclBitPullRight, anchorProperty='path', showMore='$root.assist.loadMore', strikedProperty='striked') }
 
@@ -295,12 +295,25 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
 
       function resizeComponents() {
         $("#path").width($(".tree-toolbar").width() - 64);
-        $("#hdfsTree").height($(window).height() - 260);
+        $("#expandableTree").height($(window).height() - 260);
         $(".acl-panel-content").height($(window).height() - 260);
       }
 
       resizeComponents();
 
+      $(document).on("rendered.tree", function() {
+        var _path = viewModel.assist.path();
+        if (_path[_path.length-1] == "/"){
+          _path = _path.substr(0, _path.length - 1);
+        }
+        if ($("a.anchor[href^='"+_path+"']").length > 0){
+          $("#expandableTree").animate({
+            scrollTop: ($("a.anchor[href^='"+_path+"']:first").position().top + $("#expandableTree").scrollTop() - $("#expandableTree").position().top - 4)+"px"
+          });
+        }
+      });
+
+
       function showMainSection(mainSection) {
         console.log("show", mainSection)
         if ($("#" + mainSection).is(":hidden")) {

+ 1 - 1
apps/security/static/js/hdfs.ko.js

@@ -454,7 +454,7 @@ var HdfsViewModel = function (initial) {
 
   self.doAs = ko.observable(initial.user);
   self.doAs.subscribe(function () {
-	self.assist.refreshTree();
+	  self.assist.refreshTree();
   });
   self.availableHadoopUsers = ko.observableArray();
   self.availableHadoopGroups = ko.observableArray();

+ 44 - 22
apps/security/static/js/hive.ko.js

@@ -358,27 +358,30 @@ var Assist = function (vm) {
 
   self.refreshTree = function (force) {
     self.growingTree(jQuery.extend(true, {}, self.initialGrowingTree));
-    Object.keys(self.treeAdditionalData).forEach(function (path) {
-      if (typeof force == "boolean" && force) {
-        self.fetchPath(path);
-      } else {
-        if (self.treeAdditionalData[path].loaded) {
-          self.fetchPath(path);
+    // load root first
+    self.fetchHivePath("", function(){
+      Object.keys(self.treeAdditionalData).forEach(function (path) {
+        if (path.indexOf(".") == -1 && path != ""){
+          if (typeof force == "boolean" && force) {
+            self.fetchHivePath(path);
+          }
+          else {
+            if (self.treeAdditionalData[path].loaded) {
+              self.fetchHivePath(path, function(){
+                Object.keys(self.treeAdditionalData).forEach(function (ipath) {
+                  if (ipath.split(".").length == 2 && ipath.split(".")[0] == path){
+                    self.fetchHivePath(ipath, function(){
+                      self.updateTreeProperty(self.growingTree(), "isExpanded", true);
+                    });
+                  }
+                });
+              });
+            }
+          }
         }
-      }
+      });
     });
-  }
 
-  self.rebuildTree = function (leaf, paths) {
-    paths.push(leaf.path);
-    if (leaf.nodes.length > 0) {
-      leaf.nodes.forEach(function (node) {
-        if (node.isDir){
-          self.rebuildTree(node, paths);
-        }
-      });
-    }
-    return paths;
   }
 
   self.setPath = function (obj, toggle) {
@@ -432,19 +435,35 @@ var Assist = function (vm) {
     return leaf;
   }
 
-  self.loadParents = function () {
+  self.loadParents = function (callback) {
     self.fetchHivePath("", function(){
+      self.updatePathProperty(self.growingTree(), "", "isExpanded", true);
       var _crumbs = self.path().split(".");
       self.fetchHivePath(_crumbs[0], function(){
+        self.updatePathProperty(self.growingTree(), _crumbs[0], "isExpanded", true);
         if (_crumbs.length > 1){
           self.fetchHivePath(_crumbs[0] + "." + _crumbs[1], function(){
+            self.updatePathProperty(self.growingTree(), _crumbs[0] + "." + _crumbs[1], "isExpanded", true);
             self.loadData(self.growingTree());
-            self.collapseOthers();
+            if (typeof callback != "undefined"){
+              callback();
+            }
+            else {
+              self.collapseOthers();
+            }
           });
         }
+        else {
+          self.loadData(self.growingTree());
+          if (typeof callback != "undefined"){
+            callback();
+          }
+          else {
+            self.collapseOthers();
+          }
+        }
       });
     });
-
   }
 
   self.fetchHivePath = function (optionalPath, loadCallback) {
@@ -458,6 +477,10 @@ var Assist = function (vm) {
         type: 'GET',
         success: function (data) {
           var _hasCallback = typeof loadCallback != "undefined";
+
+          //self.getTreeAdditionalDataForPath(self.path()).loaded = true;
+          self.getTreeAdditionalDataForPath(_originalPath).loaded = true;
+
           if (data.databases) {
             self.addDatabases(_originalPath, data.databases, _hasCallback);
           }
@@ -468,7 +491,6 @@ var Assist = function (vm) {
             self.addColumns(_originalPath, data.columns, _hasCallback);
           }
 
-          self.getTreeAdditionalDataForPath(self.path()).loaded = true;
 
           if (_hasCallback){
             loadCallback(data);