HDFS-8678. Bring back the feature to view chunks of files in the HDFS file browser. Contributed by Ivo Udelsmann.

This commit is contained in:
Ravi Prakash 2016-11-30 09:11:19 -08:00
parent 51e6c1cc3f
commit 625df87c7b
2 changed files with 43 additions and 7 deletions

View File

@ -57,8 +57,17 @@
<h4 class="modal-title" id="file-info-title">File information</h4>
</div>
<div class="modal-body" id="file-info-body">
<a id="file-info-download">Download</a>
<!--<a id="file-info-preview" style="cursor:pointer">Tail the file (last 32K)</a>-->
<div class=row>
<span class="col-xs-4">
<a id="file-info-download">Download</a>
</span>
<span class="col-xs-4">
<a id="file-info-preview-head" style="cursor:pointer">Head the file (first 32K)</a>
</span>
<span class="col-xs-4">
<a id="file-info-preview-tail" style="cursor:pointer">Tail the file (last 32K)</a>
</span>
</div>
<hr />
<div class="panel panel-success" id="file-info-blockinfo-panel">
<div class="panel-heading">

View File

@ -192,13 +192,40 @@
var download_url = '/webhdfs/v1' + abs_path + '?op=OPEN';
$('#file-info-download').attr('href', download_url);
$('#file-info-preview').click(function() {
var processPreview = function(url) {
url += "&noredirect=true";
$.ajax({
type: 'GET',
url: url,
processData: false,
crossDomain: true
}).done(function(data) {
url = data.Location;
$.ajax({
type: 'GET',
url: url,
processData: false,
crossDomain: true
}).complete(function(data) {
$('#file-info-preview-body').val(data.responseText);
$('#file-info-tail').show();
}).error(function(jqXHR, textStatus, errorThrown) {
show_err_msg("Couldn't preview the file. " + errorThrown);
});
}).error(function(jqXHR, textStatus, errorThrown) {
show_err_msg("Couldn't find datanode to read file from. " + errorThrown);
});
}
$('#file-info-preview-tail').click(function() {
var offset = d.fileLength - TAIL_CHUNK_SIZE;
var url = offset > 0 ? download_url + '&offset=' + offset : download_url;
$.get(url, function(t) {
$('#file-info-preview-body').val(t);
$('#file-info-tail').show();
}, "text").error(network_error_handler(url));
processPreview(url);
});
$('#file-info-preview-head').click(function() {
var url = d.fileLength > TAIL_CHUNK_SIZE ? download_url + '&length=' + TAIL_CHUNK_SIZE : download_url;
processPreview(url);
});
if (d.fileLength > 0) {