Ver código fonte

HUE-2034 [metastore] Enable links in hive table/column comments

created js method to translate text links to working URLs (/desktop/core/static/js/hue.utils.js)
moved in-page styles to /metastore/static/css/metastore.css
moved link to metastore.css higher in template to reduce change of FOUC (/metastore/src/metastore/templates/describe_table.mako)
added call to method in doc ready section (/metastore/src/metastore/templates/describe_table.mako)
Paul McCaughtry 11 anos atrás
pai
commit
02fb1d6

+ 4 - 9
apps/metastore/src/metastore/templates/describe_table.mako

@@ -20,7 +20,6 @@ from desktop.lib.i18n import smart_unicode
 from desktop.views import commonheader, commonfooter
 from django.utils.translation import ugettext as _
 %>
-
 <%namespace name="components" file="components.mako" />
 
 <%
@@ -31,6 +30,7 @@ from django.utils.translation import ugettext as _
 %>
 
 ${ commonheader(_("%s : %s") % (view_or_table_noun, table.name), app_name, user) | n,unicode }
+<link rel="stylesheet" href="/metastore/static/css/metastore.css" type="text/css">
 ${ components.menubar() }
 
 <%def name="column_table(cols)">
@@ -197,14 +197,6 @@ ${ components.menubar() }
 <div id="import-data-modal" class="modal hide fade"></div>
 </div>
 
-<style type="text/css">
-  .sampleTable td, .sampleTable th {
-    white-space: nowrap;
-  }
-</style>
-
-<link rel="stylesheet" href="/metastore/static/css/metastore.css" type="text/css">
-
 <script type="text/javascript" charset="utf-8">
   $(document).ready(function () {
     $(".datatables").dataTable({
@@ -268,6 +260,9 @@ ${ components.menubar() }
         }
       );
     });
+
+    // convert link text to URLs in comment column (Columns tab)
+    hue.text2Url(document.querySelectorAll('.datatables td:last-child'));
   });
 </script>
 

+ 4 - 0
apps/metastore/static/css/metastore.css

@@ -41,4 +41,8 @@
 .card-heading {
   padding-left: 6px !important;
   border-bottom: none !important;
+}
+
+.sampleTable td, .sampleTable th {
+  white-space: nowrap;
 }

+ 39 - 0
desktop/core/static/js/hue.utils.js

@@ -14,6 +14,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Array polyfills for older browsers
 if (!('clean' in Array.prototype)) {
   Array.prototype.clean = function (deleteValue) {
     for (var i = 0; i < this.length; i++) {
@@ -60,3 +61,41 @@ if (!('filter' in Array.prototype)) {
     return other;
   };
 }
+
+/*
+ * Add utility methods to the HUE object
+*/
+(function (hue) {
+  'use strict';
+
+  /*
+   * Convert text to URLs
+   * Selector arg can be jQuery or document.querySelectorAll()
+  */
+  hue.text2Url = function (selectors) {
+    var i = 0,
+      len = selectors.length;
+
+    for (i; i < len; i++) {
+      var arr = [],
+        selector = selectors[i],
+        val = selector.innerHTML.replace(/&nbsp;/g, ' ').split(' ');
+
+      val.forEach(function(word) {
+        var matched = null,
+          re = /(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/gi;
+
+        if (re.test(word)) {
+          matched = word.match(re);
+          word = word.replace(matched, '<a href="' + matched + '">' + matched + '</a>')
+          arr.push(word);
+        } else {
+          arr.push(word);
+        }
+      });
+
+      selector.innerHTML = arr.join(' ');
+    }
+    return this;
+  };
+}(hue = window.hue || {}));