Przeglądaj źródła

HUE-2199 [search] Link to original document in gridlayout

Current format is to expect a 'link-meta' json field containing the
information for pointing to the document in another app.

e.g.
{'type': 'link', 'link': 'gethue.com'}
{'type': 'hbase', 'table': 'document_demo', 'row_key': '20150527'}
{'type': 'hdfs', 'location': '/data/hue/1'}
{'type': 'hive', 'database': 'default', 'table': 'sample_07'}

Note that some additional UX could be to add an 'offset' for HDFS and
a WHERE close in Hive.

The format is subject to change.

The new Indexer should fill up this field automatically too.
Romain Rigaux 10 lat temu
rodzic
commit
41f231b

+ 7 - 2
apps/search/src/search/models.py

@@ -28,8 +28,8 @@ from django.db import models
 from django.utils.html import escape
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
-
 from desktop.lib.i18n import smart_unicode, smart_str
+from desktop.models import get_data_link
 
 from libsolr.api import SolrApi
 
@@ -812,7 +812,12 @@ def augment_solr_response(response, collection, query):
       doc[field] = escaped_value
 
     if not query.get('download'):
-      doc['externalLink'] = doc.get('doc-link') in ['hbase', 'hdfs'] and 'doc-link' in doc.keys()
+      link = None
+      if 'link-meta' in doc.keys():
+        meta = json.loads(doc['link-meta'])
+        link = get_data_link(meta)
+
+      doc['externalLink'] = link
       doc['details'] = []
 
   highlighted_fields = response.get('highlighting', {}).keys()

+ 3 - 1
apps/search/src/search/templates/search.mako

@@ -622,7 +622,9 @@ ${ dashboard.layout_skeleton() }
                       <a href="javascript:void(0)" data-bind="click: $root.updateDocument">
                         <i class="fa fa-save" data-bind="visible: showEdit"></i>
                       </a>
-                      <i class="fa fa-external-link" data-bind="visible: externalLink"></i>
+                      <a href="javascript:void(0)" data-bind="attr: { href: externalLink}" target="_blank">
+                        <i class="fa fa-external-link" data-bind="visible: externalLink"></i>
+                      </a>
                       <table>
                         <tbody data-bind="foreach: details">
                           <tr>

+ 21 - 0
desktop/core/src/desktop/models.py

@@ -806,3 +806,24 @@ class Document2(models.Model):
 
   def can_read_or_exception(self, user):
     self.doc.get().can_read_or_exception(user)
+
+
+def get_data_link(meta):
+  link = None
+
+  if not meta.get('type'):
+    pass
+  elif meta['type'] == 'hbase':
+    link = '/hbase/#Cluster/%(table)s/query/%(row_key)s' % meta
+    if 'col' in meta:
+      link += '[%(fam)s:%(col)s]' % meta
+    elif 'fam' in meta:
+      link += '[%(fam)s]' % meta
+  elif meta['type'] == 'hdfs':
+    link = '/filebrowser/view%(path)s' % meta # Could add a byte #
+  elif meta['type'] == 'link':
+    link = meta['link']
+  elif meta['type'] == 'hive':
+    link = '/metastore/table/%(database)s/%(table)s' % meta # Could also add col=val
+
+  return link

+ 15 - 4
desktop/core/src/desktop/tests.py

@@ -21,7 +21,6 @@ import logging
 import os
 import subprocess
 import sys
-import tempfile
 import time
 
 import desktop
@@ -39,9 +38,10 @@ from django.core.urlresolvers import reverse
 from django.http import HttpResponse
 from django.db.models import query, CharField, SmallIntegerField
 
+from beeswax.conf import HIVE_SERVER_HOST
+from pig.models import PigScript
 from useradmin.models import GroupPermission
 
-from beeswax.conf import HIVE_SERVER_HOST
 from desktop.lib import django_mako
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.paginator import Paginator
@@ -49,9 +49,8 @@ from desktop.lib.conf import validate_path
 from desktop.lib.django_util import TruncatingModel
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.test_utils import grant_access
-from desktop.models import Document, Document2
+from desktop.models import Document, Document2, get_data_link
 from desktop.views import check_config, home
-from pig.models import PigScript
 
 
 def setup_test_environment():
@@ -935,3 +934,15 @@ def test_session_secure_cookie():
   finally:
     for reset in resets:
       reset()
+
+
+def test_get_data_link():
+  assert_equal(None, get_data_link({}))
+  assert_equal('gethue.com', get_data_link({'type': 'link', 'link': 'gethue.com'}))
+
+  assert_equal('/hbase/#Cluster/document_demo/query/20150527', get_data_link({'type': 'hbase', 'table': 'document_demo', 'row_key': '20150527'}))
+  assert_equal('/hbase/#Cluster/document_demo/query/20150527[f1]', get_data_link({'type': 'hbase', 'table': 'document_demo', 'row_key': '20150527', 'fam': 'f1'}))
+  assert_equal('/hbase/#Cluster/document_demo/query/20150527[f1:c1]', get_data_link({'type': 'hbase', 'table': 'document_demo', 'row_key': '20150527', 'fam': 'f1', 'col': 'c1'}))
+
+  assert_equal('/filebrowser/view/data/hue/1', get_data_link({'type': 'hdfs', 'path': '/data/hue/1'}))
+  assert_equal('/metastore/table/default/sample_07', get_data_link({'type': 'hive', 'database': 'default', 'table': 'sample_07'}))