Ver Fonte

[sentry] Link roles to the browse section in Hive

Added smart external linking too
Added deep linking to column on Metastore
Added subscribeOnce to huePubSub
Enrico Berti há 10 anos atrás
pai
commit
590a8a1f59

+ 15 - 3
apps/metastore/src/metastore/templates/describe_table.mako

@@ -256,17 +256,29 @@ ${ components.menubar() }
 
   $(document).ready(function () {
 
-    $(".column-selector").on("click", function () {
+    function selectColumn(col) {
       var _t = $("#sample");
-      var _text = $.trim($(this).text().split("(")[0]);
       var _col = _t.find("th").filter(function() {
-        return $.trim($(this).text()) == _text;
+        return $.trim($(this).text()) == col;
       });
       _t.find(".columnSelected").removeClass("columnSelected");
       _t.find("tr td:nth-child(" + (_col.index() + 1) + ")").addClass("columnSelected");
       $("a[href='#sample']").click();
+
+    }
+
+    $(".column-selector").on("click", function () {
+      selectColumn($.trim($(this).text().split("(")[0]));
     });
 
+    if (window.location.hash != "") {
+      if (window.location.hash.indexOf("col=") > -1) {
+        window.setTimeout(function(){
+          selectColumn(window.location.hash.split("=")[1]);
+        }, 200)
+      }
+    }
+
     % if has_write_access:
         $.getJSON("${ url('metastore:drop_table', database=database) }", function (data) {
           $("#dropTableMessage").text(data.title);

+ 52 - 2
apps/security/src/security/static/security/js/hive.ko.js

@@ -98,7 +98,20 @@ var Privilege = function (vm, privilege) {
     },
     owner: self
   });
-  self.privilegeScope = ko.computed(function () {
+
+  self.metastorePath = ko.computed(function(){
+    if (self.columnName().length > 0) {
+      return '/metastore/table/' + self.dbName() + "/" + self.tableName() + "#col=" + self.columnName();
+    } else if (self.tableName().length > 0) {
+      return '/metastore/table/' + self.dbName() + "/" + self.tableName();
+    } else if (self.dbName().length > 0) {
+      return '/metastore/tables/' + self.dbName();
+    } else {
+      return '';
+    }
+  });
+
+  function getPrivilegeScope() {
     if (self.privilegeType() == 'uri') {
       return 'URI';
     } else if (self.columnName().length > 0) {
@@ -110,6 +123,24 @@ var Privilege = function (vm, privilege) {
     } else {
       return 'SERVER';
     }
+  }
+
+  self.privilegeScope = ko.observable(typeof privilege.privilegeScope != "undefined" ? privilege.privilegeScope : getPrivilegeScope());
+
+  self.privilegeType.subscribe(function(newVal){
+    self.privilegeScope(getPrivilegeScope());
+  });
+
+  self.columnName.subscribe(function(newVal){
+    self.privilegeScope(getPrivilegeScope());
+  });
+
+  self.tableName.subscribe(function(newVal){
+    self.privilegeScope(getPrivilegeScope());
+  });
+
+  self.dbName.subscribe(function(newVal){
+    self.privilegeScope(getPrivilegeScope());
   });
 
   self.remove = function (privilege) {
@@ -345,6 +376,17 @@ var Assist = function (vm, initial) {
     var column = self.path().split(/[.]/)[2];
     return column ? column : null;
   });
+  self.metastorePath = ko.computed(function(){
+    if (self.column()) {
+      return '/metastore/table/' + self.db() + "/" + self.table() + "#col=" + self.column();
+    } else if (self.table()) {
+      return '/metastore/table/' + self.db() + "/" + self.table();
+    } else if (self.db()) {
+      return '/metastore/tables/' + self.db();
+    } else {
+      return '/metastore/databases';
+    }
+  });
   self.privileges = ko.observableArray();
   self.roles = ko.observableArray();
   self.isDiffMode = ko.observable(false);
@@ -703,7 +745,7 @@ var Assist = function (vm, initial) {
   self.fetchHivePath = function (optionalPath, loadCallback) {
     var _originalPath = typeof optionalPath != "undefined" ? optionalPath : self.path();
 
-    if (_originalPath.split(".").length < 3) {
+    if (_originalPath.split(".").length < 4) {
       self.isLoadingTree(true);
 
       var _path = _originalPath.replace('.', '/');
@@ -1256,6 +1298,14 @@ var HiveViewModel = function (initial) {
     }
     return "edit";
   }
+
+  self.linkToBrowse = function (path) {
+    self.assist.path(path);
+    $(document).trigger("changed.path");
+    self.assist.loadParents();
+    self.updateSectionHash("edit");
+    $(document).trigger("show.mainSection");
+  }
 };
 
 function logGA(page) {

+ 12 - 5
apps/security/src/security/templates/hive.mako

@@ -95,19 +95,22 @@ ${ layout.menubar(section='hive') }
     <!-- ko if: grantOption -->
       <i class="fa fa-unlock muted" title="${ _('With grant option') }"></i>
     <!-- /ko -->
+    <span data-bind="visible: metastorePath() != '' && privilegeType() == 'db'">
+      <a data-bind="attr: { href: metastorePath() }" class="muted" target="_blank" style="margin-left: 4px"><i class="fa fa-external-link"></i></a>
+    </span>
     <br/>
 
     server=<span data-bind="text: serverName"></span>
 
     <!-- ko if: privilegeType() == 'db' -->
       <span data-bind="visible: dbName">
-        <i class="fa fa-long-arrow-right"></i> db=<a data-bind="attr: { href: '/metastore/tables/' + dbName() }" target="_blank"><span data-bind="text: dbName"></span></a>
+        <i class="fa fa-long-arrow-right"></i> db=<a class="pointer" data-bind="click: function(){ $root.linkToBrowse(dbName()) }"><span data-bind="text: dbName"></span></a>
       </span>
       <span data-bind="visible: tableName">
-        <i class="fa fa-long-arrow-right"></i> table=<a data-bind="attr: { href: '/metastore/table/' + dbName() + '/' + tableName() }" target="_blank"><span data-bind="text: tableName"></span></a>
+        <i class="fa fa-long-arrow-right"></i> table=<a class="pointer" data-bind="click: function(){ $root.linkToBrowse(dbName() + '.' + tableName()) }"><span data-bind="text: tableName"></span></a>
       </span>
       <span data-bind="visible: columnName">
-        <i class="fa fa-long-arrow-right"></i> column=<span data-bind="text: columnName"></span>
+        <i class="fa fa-long-arrow-right"></i> column=<a class="pointer" data-bind="click: function(){ $root.linkToBrowse(dbName() + '.' + tableName() + '.' + columnName()) }"><span data-bind="text: columnName"></span></a>
       </span>
     <!-- /ko -->
 
@@ -163,7 +166,7 @@ ${ layout.menubar(section='hive') }
               <div class="path-container">
                 <div class="input-append span12">
                   <input id="path" class="path" type="text" autocomplete="off" />
-                  <a data-bind="attr: { href: '/metastore/table/' + $root.assist.path().replace('.', '/') }" target="_blank" title="${ _('Open in Metastore Browser') }" class="btn btn-inverse">
+                  <a data-bind="attr: { href: $root.assist.metastorePath() }" target="_blank" title="${ _('Open in Metastore Browser') }" class="btn btn-inverse">
                     <i class="fa fa-external-link"></i>
                   </a>
                 </div>
@@ -670,7 +673,11 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
 
       showMainSection(viewModel.getSectionHash());
 
-      $(document).on("show.role", function(e, role) {
+      $(document).on("show.mainSection", function(){
+        showMainSection(viewModel.getSectionHash());
+      });
+
+      $(document).on("show.role", function(role) {
         if (typeof role != "undefined" && role.name != null){
           $("#bulkActionsModal").modal("hide");
           showMainSection("roles");

+ 7 - 0
desktop/core/src/desktop/static/desktop/js/hue.utils.js

@@ -189,6 +189,13 @@ var huePubSub = (function () {
         }
       };
     },
+    subscribeOnce: function (topic, listener) {
+      var ephemeral = this.subscribe(topic, function(){
+        listener.apply(arguments);
+        ephemeral.remove();
+      });
+
+    },
     publish: function (topic, info) {
       if (! hOP.call(topics, topic)) {
         return;