Browse Source

HUE-4963 [metastore] Convert partition file browsing to the new editor

Romain Rigaux 8 years ago
parent
commit
1a1b1ea

+ 22 - 1
apps/metastore/src/metastore/templates/metastore.mako

@@ -202,7 +202,14 @@ ${ components.menubar() }
         <td data-bind="text: partitionSpec"></td>
         <td>
           <a data-bind="attr: {'href': readUrl }"><i class="fa fa-th"></i> ${_('Data')}</a>
-          <a data-bind="attr: {'href': browseUrl }"><i class="fa fa-file-o"></i> ${_('Files')}</a>
+          <!-- ko if: IS_HUE_4 -->
+            <a data-bind="click: function () { browsePartitionFiles(browseUrl); }" href="javascript:void(0)" title="${_('Browse partition files')}">
+              <i class="fa fa-file-o"></i> ${_('Files')}
+            </a>
+          <!-- /ko -->
+          <!-- ko if: ! IS_HUE_4 -->
+            <a data-bind="attr: {'href': browseUrl }" title="${_('Browse partition files')}"><i class="fa fa-file-o"></i> ${_('Files')}</a>
+          <!-- /ko -->
         </td>
       </tr>
       <!-- /ko -->
@@ -1157,6 +1164,20 @@ ${ components.menubar() }
     });
   }
 
+  function browsePartitionFiles(url) {
+    $.get(url, {
+      format: "json"
+    },function(resp) {
+      if (resp.uri_path) {
+        huePubSub.publish('open.fb.folder', resp.uri_path.replace(/\/filebrowser\/view=/g, '') );
+      } else if (resp.message) {
+        $(document).trigger("error", resp.message);
+      }
+    }).fail(function (xhr) {
+      $(document).trigger("error", xhr.responseText);
+    });
+  }
+
 
   (function () {
 

+ 4 - 1
apps/metastore/src/metastore/views.py

@@ -542,7 +542,10 @@ def browse_partition(request, database, table, partition_spec):
     decoded_spec = urllib.unquote(partition_spec)
     partition_table = db.describe_partition(database, table, decoded_spec)
     uri_path = location_to_url(partition_table.path_location)
-    return redirect(uri_path)
+    if request.REQUEST.get("format", "html") == "json":
+      return JsonResponse({'uri_path': uri_path})
+    else:
+      return redirect(uri_path)
   except Exception, e:
     raise PopupException(_('Cannot browse partition'), detail=e.message)